@@ -23,6 +23,73 @@ static rt_sem_t rx_sem = RT_NULL;
2323// ABOUT COMMAND
2424static void * ano_target ;
2525
26+ static rt_err_t ano_sender_send (rt_int16_t cmd , void * param , rt_uint16_t size )
27+ {
28+ switch (cmd )
29+ {
30+ case COMMAND_SEND_PID :
31+ if (size == 3 * sizeof (struct cmd_dt_pid ))
32+ {
33+ struct cmd_dt_pid * pid_info = (struct cmd_dt_pid * )param ;
34+ int group = (int )((pid_info [0 ].id + pid_info [1 ].id + pid_info [2 ].id ) / 9 ) + 1 ;
35+
36+ if (group > 6 )
37+ {
38+ group = 6 ;
39+ }
40+ if (group < 1 )
41+ {
42+ group = 1 ;
43+ }
44+ ano_send_pid (group , pid_info [0 ].kp , pid_info [0 ].ki , pid_info [0 ].kd ,
45+ pid_info [1 ].kp , pid_info [1 ].ki , pid_info [1 ].kd ,
46+ pid_info [2 ].kp , pid_info [2 ].ki , pid_info [2 ].kd );
47+ }
48+ else
49+ {
50+ LOG_D ("You need send three groups pid paramter at once when use COMMAND_SEND_PID" );
51+ return RT_ERROR ;
52+ }
53+
54+ break ;
55+ case COMMAND_SEND_SENSOR :
56+ if (size == sizeof (struct cmd_dt_sensor ))
57+ {
58+ struct cmd_dt_sensor * sensor_info = (struct cmd_dt_sensor * )param ;
59+ ano_send_senser (sensor_info -> acc_x , sensor_info -> acc_y , sensor_info -> acc_z ,
60+ sensor_info -> gyro_x , sensor_info -> gyro_y , sensor_info -> gyro_z ,
61+ sensor_info -> mag_x , sensor_info -> mag_y , sensor_info -> mag_z , 0 );
62+ }
63+ else
64+ {
65+ return RT_ERROR ;
66+ }
67+
68+ break ;
69+ case COMMAND_SEND_RPY :
70+ if (size == sizeof (struct cmd_dt_rpy ))
71+ {
72+ struct cmd_dt_rpy * rpy_info = (struct cmd_dt_rpy * )param ;
73+ ano_send_status (rpy_info -> roll , rpy_info -> pitch , rpy_info -> yaw , 0 ,0 ,0 );
74+ }
75+ else
76+ {
77+ return RT_ERROR ;
78+ }
79+
80+ break ;
81+ default :
82+ break ;
83+ }
84+
85+ return RT_EOK ;
86+ }
87+
88+ static struct command_sender ano_sender = {
89+ .name = "ano" ,
90+ .send = ano_sender_send
91+ };
92+
2693static int _send_data (uint8_t * buffer , uint8_t length )
2794{
2895 if (dev_ano != RT_NULL )
@@ -94,38 +161,38 @@ static void ano_parse_frame(uint8_t *buffer, uint8_t length)
94161 {
95162 if (* (buffer + 4 ) == 0X01 )
96163 {
97- command_handle (COMMAND_REQUEST_PID , RT_NULL , 0 , ano_target );
164+ command_handle (COMMAND_REQUEST_PID , RT_NULL , 0 , & ano_sender , ano_target );
98165 }
99166 else if (* (buffer + 4 ) == 0XA0 )
100167 {
101168 // request version info
102169 }
103170 else if (* (buffer + 4 ) == 0XA1 )
104171 {
105- command_handle (COMMAND_RESET_PID , RT_NULL , 0 , ano_target );
172+ command_handle (COMMAND_RESET_PID , RT_NULL , 0 , & ano_sender , ano_target );
106173 }
107174 }
108175 else if (* (buffer + 2 ) == 0X10 ) //PID1
109176 {
110177 struct cmd_dt_pid pid ;
111178 float kpid [9 ];
112179 _get_pid_param (buffer , kpid );
113-
180+
114181 pid .id = PID_ID_WHEEL_0 ;
115182 pid .kp = kpid [0 ];
116183 pid .ki = kpid [1 ];
117184 pid .kd = kpid [2 ];
118- command_handle (COMMAND_SET_PID , & pid , sizeof (struct cmd_dt_pid ), ano_target );
185+ command_handle (COMMAND_SET_PID , & pid , sizeof (struct cmd_dt_pid ), & ano_sender , ano_target );
119186 pid .id = PID_ID_WHEEL_1 ;
120187 pid .kp = kpid [3 ];
121188 pid .ki = kpid [4 ];
122189 pid .kd = kpid [5 ];
123- command_handle (COMMAND_SET_PID , & pid , sizeof (struct cmd_dt_pid ), ano_target );
190+ command_handle (COMMAND_SET_PID , & pid , sizeof (struct cmd_dt_pid ), & ano_sender , ano_target );
124191 pid .id = PID_ID_WHEEL_2 ;
125192 pid .kp = kpid [6 ];
126193 pid .ki = kpid [7 ];
127194 pid .kd = kpid [8 ];
128- command_handle (COMMAND_SET_PID , & pid , sizeof (struct cmd_dt_pid ), ano_target );
195+ command_handle (COMMAND_SET_PID , & pid , sizeof (struct cmd_dt_pid ), & ano_sender , ano_target );
129196
130197 ano_send_check (* (buffer + 2 ), sum );
131198 }
@@ -139,7 +206,7 @@ static void ano_parse_frame(uint8_t *buffer, uint8_t length)
139206 pid .kp = kpid [0 ];
140207 pid .ki = kpid [1 ];
141208 pid .kd = kpid [2 ];
142- command_handle (COMMAND_SET_PID , & pid , sizeof (struct cmd_dt_pid ), ano_target );
209+ command_handle (COMMAND_SET_PID , & pid , sizeof (struct cmd_dt_pid ), & ano_sender , ano_target );
143210 // pid.id = 5;
144211 // pid.kp = kpid[3];
145212 // pid.ki = kpid[4];
@@ -683,73 +750,6 @@ int ano_set_device(const char *device_name)
683750 return RT_EOK ;
684751}
685752
686- static rt_err_t ano_sender_send (rt_int16_t cmd , void * param , rt_uint16_t size )
687- {
688- switch (cmd )
689- {
690- case COMMAND_SEND_PID :
691- if (size == 3 * sizeof (struct cmd_dt_pid ))
692- {
693- struct cmd_dt_pid * pid_info = (struct cmd_dt_pid * )param ;
694- int group = (int )((pid_info [0 ].id + pid_info [1 ].id + pid_info [2 ].id ) / 9 ) + 1 ;
695-
696- if (group > 6 )
697- {
698- group = 6 ;
699- }
700- if (group < 1 )
701- {
702- group = 1 ;
703- }
704- ano_send_pid (group , pid_info [0 ].kp , pid_info [0 ].ki , pid_info [0 ].kd ,
705- pid_info [1 ].kp , pid_info [1 ].ki , pid_info [1 ].kd ,
706- pid_info [2 ].kp , pid_info [2 ].ki , pid_info [2 ].kd );
707- }
708- else
709- {
710- LOG_D ("You need send three groups pid paramter at once when use COMMAND_SEND_PID" );
711- return RT_ERROR ;
712- }
713-
714- break ;
715- case COMMAND_SEND_SENSOR :
716- if (size == sizeof (struct cmd_dt_sensor ))
717- {
718- struct cmd_dt_sensor * sensor_info = (struct cmd_dt_sensor * )param ;
719- ano_send_senser (sensor_info -> acc_x , sensor_info -> acc_y , sensor_info -> acc_z ,
720- sensor_info -> gyro_x , sensor_info -> gyro_y , sensor_info -> gyro_z ,
721- sensor_info -> mag_x , sensor_info -> mag_y , sensor_info -> mag_z , 0 );
722- }
723- else
724- {
725- return RT_ERROR ;
726- }
727-
728- break ;
729- case COMMAND_SEND_RPY :
730- if (size == sizeof (struct cmd_dt_rpy ))
731- {
732- struct cmd_dt_rpy * rpy_info = (struct cmd_dt_rpy * )param ;
733- ano_send_status (rpy_info -> roll , rpy_info -> pitch , rpy_info -> yaw , 0 ,0 ,0 );
734- }
735- else
736- {
737- return RT_ERROR ;
738- }
739-
740- break ;
741- default :
742- break ;
743- }
744-
745- return RT_EOK ;
746- }
747-
748- static struct command_sender ano_sender = {
749- .name = "ano" ,
750- .send = ano_sender_send
751- };
752-
753753command_sender_t ano_get_sender (void )
754754{
755755 return & ano_sender ;
0 commit comments