⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kkem.c

📁 非常重要的嵌入式单片机开发语言 是美国德州仪器的MSP430系列的系统语言4
💻 C
📖 第 1 页 / 共 4 页
字号:
                            /***** close CNC program *****/
static void close_CNC_file()
{    int hfile;
     goto_label(0,NULL,0);          /* reset label-table */
     if (CNC_level<0) return;
     hfile = CNC_stack[CNC_level].hfile;
     if ((--CNC_stack[CNC_level].nloop)<=0)
     {    nCycle   =CNC_stack[CNC_level].ncycle;
          nMacro   =CNC_stack[CNC_level].nmacro;
          nData    =CNC_stack[CNC_level].ndata;
          PLC_flag =CNC_stack[CNC_level].nflag;
          CNC_Ocode=CNC_stack[CNC_level].name;
          CNC_Ncode=CNC_stack[CNC_level].ncode;
          if (hfile) _lclose(hfile);
          pop_stack(0);
          if ((--CNC_level)<0) return;
          hfile = CNC_stack[CNC_level].hfile;
     } else
     {    CNC_stack[CNC_level].pfile=0L;
          CNC_Ncode=0;
     }
     if (hfile)
          _llseek(hfile, CNC_stack[CNC_level].pfile, SEEK_SET);
}
                        /***** close all CNC program *****/
static void clear_CNC_file()
{    int hfile;
     goto_label(0,NULL,0);          /* reset label-table */
     for ( ; CNC_level>=0; CNC_level--)
     {    hfile = CNC_stack[CNC_level].hfile;
          if (hfile) _lclose(hfile);
     }
     CNC_level=-1;
}

/*=========================================================
  function about coordinate transformation

  absolute_to_local()   : absolute to local coordinate
  local_to_absolute()   : local to absolute coordinate
  local_to_machine()    : local to machine coordinate
  machine_to_local()    : machine to local coordinate
  absolute_to_machine() : absolute to machine coordinate
  machine_to_absolute() : machine to absolute coordinate
=========================================================*/
                 /***** absolute to local coordinate *****/
static void absolute_to_local(s,d)
LPAXIS s,d;      /* source and destination */
{    *d=*s;
     if (nPolar)  polar_effect(s,d,&CNC_polar);
     if (nUnit)   scaling_effect(s,d,&CNC_unit0,&CNC_unitf);
     if (nRotate) rotate_effect(s,d,&CNC_rotate);
     if (nScale)  scaling_effect(s,d,&CNC_scale0,&CNC_scalef);
}
                 /***** local to absolute coordinate *****/
static void local_to_absolute(s,d)
LPAXIS s,d;      /* source and destination */
{    *d=*s;
     if (nScale)   scaling_backward(s,d,&CNC_scale0,&CNC_scalef);
     if (nRotate)  rotate_backward(s,d,&CNC_rotate);
     if (nUnit)    scaling_backward(s,d,&CNC_unit0,&CNC_unitf);
     if (nPolar)   polar_backward(s,d,&CNC_polar);
}
                  /***** local to machine coordinate *****/
static void local_to_machine(s,d)
LPAXIS s,d;       /* source and destination */
{    shift_effect(s,d,&CNC_local);
     shift_effect(s,d,&(CNC_working[nWork]));
     shift_effect(s,d,&(CNC_working[0]));
}
                  /***** machine to local coordinate *****/
static void machine_to_local(s,d)
LPAXIS s,d;       /* source and destination */
{    shift_backward(s,d,&(CNC_working[0]));
     shift_backward(s,d,&(CNC_working[nWork]));
     shift_backward(s,d,&CNC_local);
}
               /***** absolute to machine coordinate *****/
static void absolute_to_machine(s,d)
LPAXIS s,d;    /* source and destination */
{    absolute_to_local(s,d);
     local_to_machine(d,d);
}
               /***** machine to absolute coordinate *****/
static void machine_to_absolute(s,d)
LPAXIS s,d;    /* source and destination */
{    machine_to_local(s,d);
     local_to_absolute(d,d);
}

/*=========================================================
  functions about input data in absuolut coordinate

  get_axis_absolute()   : get axis   in absolute coordinate
  get_center_absolute() : get center in absolute coordinate
=========================================================*/
                        /***** get filled input axis *****/
static void get_axis_absolute(a)
LPAXIS a;     /* decoded data */
{    int i,n; char c;
     for (i=0; i<6; i++)
     {    if (i>=PLC_axis) { a->v[i]=0; continue; }
          c = CNC_Amap[i];
          n = (c > 'G') ? (c-'A'-1) : (c-'A');
          a->v[i] = CNC_last.v[i];
          if (lpCmd->f[n])
          {    if (nInc) a->v[i] += get_value_input(c,nDot);
               else      a->v[i]  = get_value_input(c,nDot);
          }
     }
}
                      /***** get filled input center *****/
static void get_center_absolute(a)
LPAXIS a;     /* decoded data */
{    int i,n; char c;
     for (i=0; i<6; i++)
     {    if (i>=PLC_axis) { a->v[i]=0; continue; }
          c = CNC_Cmap[i];
          n = (c > 'G') ? (c-'A'-1) : (c-'A');
          a->v[i] = CNC_last.v[i];
          if (lpCmd->f[n]) a->v[i] += get_value_input(c,nDot);
     }
}

/*=========================================================
  functions about input reading

  get_axis_input()   : get input axis   coordinate
  get_center_input() : get input center coordinate
  get_value_input()  : get one field of input value
  get_axis_number()  : get no. of axis sequence
=========================================================*/
                    /***** get input axis coordinate *****/
static void get_axis_input(a)
LPAXIS a;     /* decoded data */
{    int i;
     for (i=0;i<PLC_axis;i++) a->v[i]=get_value_input(CNC_Amap[i],nDot);
     for (   ;i<6;       i++) a->v[i]=0;
}
                  /***** get input center coordinate *****/
static void get_center_input(a)
LPAXIS a;     /* decoded data */
{    int i;
     for (i=0;i<PLC_axis;i++) a->v[i]=get_value_input(CNC_Cmap[i],nDot);
     for (   ;i<6;       i++) a->v[i]=0;
}
                              /***** get input value *****/
static double get_value_input(c,d)
char c;     /* control code */
int  d;     /* decimal no. */
{    int n; LPPATH lp;
     if (c<'A' || c>'Z') return(0.L);
     n = (c > 'G') ? (c-'A'-1) : (c-'A');
     if (lpCmd->f[n]==0) return(0.L);
     if (lpCmd->f[n]<10)
     {    switch (d)
          {
          case 1 : return(lpCmd->v[n]/10.L);
          case 2 : return(lpCmd->v[n]/100.L);
          case 3 : return(lpCmd->v[n]/1000.L);
          case 4 : return(lpCmd->v[n]/10000.L);
          case 5 : return(lpCmd->v[n]/100000.L);
          case 6 : return(lpCmd->v[n]/1000000.L);
          }
     }
     return((double)(lpCmd->v[n]));
}
                     /***** get no. of axis sequence *****/
static int get_axis_number(c)
char c;    /* control code */
{    int i;
     for (i=0; i<6; i++) { if (c==CNC_Amap[i]) return(i); }
     return(0);
}

/*=========================================================
  functions about input value check

  is_axis_exist()       : is n'th axis exist ??
  is_any_axis_exist()   : is  any axis exist ??
  is_all_axis_exist()   : are all axes exist ??
  is_center_exist()     : is n'th center exist ??
  is_any_center_exist() : is  any center exist ??
  is_all_center_exist() : are all center exist ??
  is_input_exist()      : is input value exist ??
=========================================================*/
                             /***** check input axes *****/
static BOOL is_axis_exist(n)
int n;     /* n'th axis */
{    return(is_input_exist(CNC_Amap[n]));
}
                   /***** is any axis field exist ?? *****/
static BOOL is_any_axis_exist()
{    int i;
     for (i=0; i<PLC_axis; i++) { if (is_axis_exist(i))  return(TRUE); }
     return(FALSE);
}
                  /***** are any axis field exist ?? *****/
static BOOL is_all_axis_exist()
{    int i;
     for (i=0; i<PLC_axis; i++) { if (!is_axis_exist(i)) return(FALSE); }
     return(TRUE);
}
                           /***** check input center *****/
static BOOL is_center_exist(n)
int n;     /* n'th axis */
{    return(is_input_exist(CNC_Cmap[n]));
}
                 /***** is any center field exist ?? *****/
static BOOL is_any_center_exist()
{    int i;
     for (i=0; i<PLC_axis; i++) { if (is_center_exist(i))  return(TRUE); }
     return(FALSE);
}
                /***** are all center field exist ?? *****/
static BOOL is_all_center_exist()
{    int i;
     for (i=0; i<PLC_axis; i++) { if (!is_center_exist(i)) return(FALSE); }
     return(TRUE);
}
                  /***** is the input field exist ?? *****/
static BOOL is_input_exist(c)
char c;       /* control code */
{    if (c<'A' || c>'Z') return(FALSE);
     c = (c>'G') ? (c-'A'-1) : (c-'A');
     if (lpCmd->f[c])       return(TRUE);
     return(FALSE);
}

/*=========================================================
  CNC_command_decoding()
        decoding one line of CNC command,
=========================================================*/
static void CNC_command_decoding()
{    if (skip_command())     return;         /* group 24 */

     if (plane_command())    return;         /* group 02 */
     if (absolute_command()) return;         /* group 03 */
     if (limit_command())    return;         /* group 04 */
     if (feed_command())     return;         /* group 05 */
     if (unit_command())     return;         /* group 06 */
     if (cutter_command())   return;         /* group 07 */
     if (tool_command())     return;         /* group 08 */
     if (return_command())   return;         /* group 10 */
     if (scaling_command())  return;         /* group 11 */
     if (speed_command())    return;         /* group 13 */
     if (working_command())  return;         /* group 14 */
     if (stop_command())     return;         /* group 15 */
     if (rotate_command())   return;         /* group 16 */
     if (polar_command())    return;         /* group 17 */
     if (offset_command())   return;         /* group 18 */

     if (cycle_command())    return;         /* group 09 */
     if (macro_command())    return;         /* group 12 */
     if (data_command())     return;         /* group 19 */
     if (special_command())  return;         /* group 00 */
     if (calling_command())  return;         /* calling  */

     if (motion_command())   return;         /* group 01 */
     if (MST_command())      return;         /* MST code */
     preset_calculation();
}

/*=========================================================
  CNC_collect_command()
          collect one line of CNC command

  command.g[n]  : G-code Group #n
  command.g[24] : skip number
  command.f[k]  : digit length of 'A'--'Z' code (except 'G')
                  =0xff for floating data
  command.v[k]  : digit value  of 'A'--'Z' code (except 'G')
=========================================================*/
static BOOL collect_CNC_command()
{    int i,flag; char code; static char buffer[250];
     static float value; static data_t d; static int n;
                                 /* clear command buffer */
     for (i=0; i<25; i++) { lpCmd->g[i]=lpCmd->f[i]=0; lpCmd->v[i]=0.; }
                                       /* get parameters */
     for (i=0,flag=FALSE; i<50; i++)
     {    if (i==0) code=get_first_CNC_field(buffer);
          else      code=get_next_CNC_field(buffer);
          if (code==0)   return(flag);
          if (code==255) return(FALSE);
          flag=TRUE;
          if (code=='/')              /* skip command ?? */
          {    gSkip='/';
          } else if (code!='G')       /* general data ?? */
          {    n = (code>'G') ? (code-'A'-1) : (code-'A');
               if (buffer[1]!='(')    /* digital data ?? */
               {    if (strchr(buffer,'.')) lpCmd->f[n]=0xff;
                    else                    lpCmd->f[n]=strlen(buffer)-1;
                    sscanf(buffer+1, "%g", &value);
                    lpCmd->v[n] = value;
               } else                /* equation data ?? */
               {    lpCmd->f[n]=0xff;
                    if (!data_calculation(buffer+1,&d)) return(FALSE);
                    switch (d.type & 0x7)
                    {
                    case BIT : lpCmd->v[n]=*(char  *)d.value; break;
                    case CHR : lpCmd->v[n]=*(char  *)d.value; break;
                    case INT : lpCmd->v[n]=*(int   *)d.value; break;
                    case LNG : lpCmd->v[n]=*(long  *)d.value; break;
                    case FLT : lpCmd->v[n]=*(float *)d.value; break;
                    }
               }
          } else                         /* G command !! */
          {    sscanf(buffer+1, "%d", &n);
               switch (n)
               {
               case 4 :  case 9 :
               case 27 : case 28 : case 29 : case 30 : case 33 :
               case 52 : case 53 : case 60 : case 92 :
                                     lpCmd->g[0]=n;   break;
               case 0 :  case 1 :  case 2 :  case 3 :
                                     lpCmd->g[1]=n+1; break;
               case 17 : case 18 : case 19 :
                                     lpCmd->g[2]=n;   break;
               case 90 : case 91 :
                                     lpCmd->g[3]=n;   break;
               case 22 : case 23 :
                                     lpCmd->g[4]=n;   break;
               case 94 : case 95 :
                                     lpCmd->g[5]=n;   break;
               case 20 : case 21 :
                                     lpCmd->g[6]=n;   break;
               case 40 : case 41 : case 42 :
                                     lpCmd->g[7]=n;   break;
               case 43 : case 44 : case 49 :
                                     lpCmd->g[8]=n;   break;
               case 80 : case 81 : case 82 : case 83 : case 84 :
               case 85 : case 86 : case 87 : case 88 : case 89 :
                                     lpCmd->g[9]=n;   break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -