简单命令数据包的拆解

void rxdString_decomposition(unsigned char rxdString[])  //拆解数据包为多个命令
{
  unsigned char *temprxdP;
  unsigned char i=0,j;
  temprxdP = rxdString;  //rxdString为接收到的命令数据包
  quantity_Commands = 0;  //记录数据包里的命令数量

  for(i=0;i<30;i++)
  {

//一个命令长度为14位。开始位和结束位为"zz"和"cc"。
  if((*temprxdP=='z')&&(*(temprxdP+1)=='z')&&(*(temprxdP+12)=='c')&&(*(temprxdP+13)=='c'))
  {
    temprxdP = temprxdP + 2;
   for(j=0;j<10;j++)
    commands[i][j]=*(temprxdP++);//将一个命令保存到commands[i]中。
   quantity_Commands++;
  }
  else
  {

//这里可进入一些处理命令数据异常的函数。

   break;
  }
  temprxdP = temprxdP + 2;
 }

//================================================================= 

void commands_Control()   //解释每一条命令
{
 volatile unsigned char i = 0,j=0;
 //volatile unsigned char j=1;

 //float th = 1000;
 j=quantity_Commands;
 for(;i
  {
      switch(commands[i][0])
   {
    case '0': function_1st=1;
       switch(commands[i][1])
       {
       case 'a': ini_flag=23;continue;

       case 'b': ini_flag=29;continue;

       case 'c': ini_flag=28;continue;

       case 'd': ini_flag=26;continue;

       case 'e': ini_flag=38;continue;

       case 'f': ini_flag=60;continue;

       case 'g': ini_flag=69;continue;

       case 'h': ini_flag=78;continue;

       default: 
          continue;
       }break;

    case 'a': p_function[i]=BigRAZ_test;break;

    case 'b': p_function[i]=SmallRAZ_test;break;

    case 'c': switch(commands[i][1])
       {
       case '0': p_function[0]=Demo_2x7x;
          quantity_Commands=1;
          //demo_flag=1;
          curve_init_flag=1;
          i=i+3;
          continue;
       case 's': speed_angle_flag=1;
          p_function[0]=Demo_2x7x;
          quantity_Commands=1;
          continue;
       case 'b': stopDemo_flag=1;p_function[0]=Demo_2x7x;quantity_Commands=1;
          continue;
       case 'a': startDemo_flag=1;
          demo_flag=1;
          p_function[0]=Demo_2x7x;
          quantity_Commands=1;
          continue;
       case 'z': reset_flag_27x=1;
          p_function[0]=Demo_2x7x;
          quantity_Commands=1;
          switch (commands[i][2])
           {
           case '0':motortype = 38;break;
           case '1':motortype = 29;break;
           case '2':motortype = 78;break;
           default:break;
           }
          continue;
       default: continue;
       }break;


    case 'd': p_function[i]=Startup_speed;break;

    case 'e': p_function[i]=Scram_speed;break;

    case 'f': p_function[i]=oneustep;break;

    case 'g': p_function[i]=Partial_Step;break;

    case 'h': switch(commands[i][1])
       {
        case '0': p_function[i]=onedegree;break;

        case 'a': p_function[i]=onestep;break;

        default: break;
       }break;

    case 'j': break_flag=1;function_1st=0;break;

    case 'l': switch(commands[i][1])
       {
        case '1': p_function[0]=Light_and_Relay;
           //quantity_Commands=1;
           light_on_flag=1;
           break;
        case '0': p_function[0]=Light_and_Relay;
           light_off_flag=1;
           break;
        case '3': p_function[0]=Light_and_Relay;
           relay_on_flag=1;
           break;
        case '2': p_function[0]=Light_and_Relay;
           relay_off_flag=1;
           break;
        default: break;
       }

    default: break;//continue;
   }

   parameter1[i]= Character_to_Data(commands[i][2])*1000+
       Character_to_Data(commands[i][3])*100+
       Character_to_Data(commands[i][4])*10+
       Character_to_Data(commands[i][5]);
   paremeter2[i]= Character_to_Data(commands[i][6])*1000+
       Character_to_Data(commands[i][7])*100+
       Character_to_Data(commands[i][8])*10+
       Character_to_Data(commands[i][9]); 
  }
  if(curve_init_flag==1)
  v_ustep_set();
  if(speed_angle_flag==1)
  speed_angle_set();
}

你可能感兴趣的:(命令)