void rxdstring_decomposition (unsigned char rxdstring[])? Splitting a packet into multiple commands { ? unsigned char *TEMPRXDP; ? unsigned char i=0,j; ? TEMPRXDP = rxdstring;? Rxdstring for received command packets ? Quantity_commands = 0;? Record the number of commands in a packet ? for (i=0;i<30;i++) ? { A command length of 14 bits. The start and end bits are "ZZ" and "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++);//Save a command to Commands[i]. ??? quantity_commands++; ??} ?? Else ?? { Here you can enter some functions to handle the command data exceptions. ??? Break ??} ?? TEMPRXDP = TEMPRXDP + 2; ?} //=================================================================? void Commands_control ()??// explain every command . { ? 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 (); } |