process_result.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. #include "process_result.h"
  2. int time_stamp = 0;
  3. float gyr[3];
  4. float acc[3];
  5. int16_t h_pos[3];
  6. int16_t h_att[3];
  7. int16_t h_zupt;
  8. int16_t jump_send_count;
  9. int16_t down_send_count;
  10. int16_t is_jump;
  11. int16_t is_down;
  12. extern int16_t s_pos[3];
  13. extern int16_t s_att[3];
  14. extern int8_t s_rssi;
  15. extern int16_t s_zupt;
  16. int left_press_buff[4];
  17. int32_t left_press = 0;
  18. int32_t right_press = 0;
  19. void sen_data_acc(void)
  20. {
  21. uint8_t buf[256];
  22. uint8_t L=0;
  23. buf[L++] = (uint8_t)(accel[0]>>8);
  24. buf[L++] = (uint8_t)(accel[0]>>0);
  25. buf[L++] = (uint8_t)(accel[1]>>8);
  26. buf[L++] = (uint8_t)(accel[1]>>0);
  27. buf[L++] = (uint8_t)(accel[2]>>8);
  28. buf[L++] = (uint8_t)(accel[2]>>0);
  29. send_protocol(DEX_NUM,CMD_HEART,buf,L);
  30. }
  31. void sen_data_pos(void)
  32. {
  33. uint8_t buf[256];
  34. uint8_t L=0;
  35. static short count = 0;
  36. // buf[L++] = (uint8_t)(h_pos[0]>>8);
  37. // buf[L++] = (uint8_t)(h_pos[0]>>0);
  38. //
  39. // buf[L++] = (uint8_t)(h_pos[1]>>8);
  40. // buf[L++] = (uint8_t)(h_pos[1]>>0);
  41. buf[L++] = (uint8_t)(h_pos[2]>>8);
  42. buf[L++] = (uint8_t)(h_pos[2]>>0);
  43. buf[L++] = (uint8_t)(s_pos[2]>>8);
  44. buf[L++] = (uint8_t)(s_pos[2]>>0);
  45. buf[L++] = (uint8_t)(count>>8);
  46. buf[L++] = (uint8_t)(count>>0);
  47. count ++;
  48. send_protocol(DEX_NUM,CMD_HEART,buf,L);
  49. }
  50. void send_data_press_gyr(void)
  51. {
  52. uint8_t buf[256];
  53. uint8_t L=0;
  54. buf[L++] = (uint8_t)(gyro[0]>>8);
  55. buf[L++] = (uint8_t)(gyro[0]>>0);
  56. buf[L++] = (uint8_t)(gyro[1]>>8);
  57. buf[L++] = (uint8_t)(gyro[1]>>0);
  58. buf[L++] = (uint8_t)(gyro[2]>>8);
  59. buf[L++] = (uint8_t)(gyro[2]>>0);
  60. buf[L++] = (uint8_t)(h_press>>8);
  61. buf[L++] = (uint8_t)(h_press>>0);
  62. send_protocol(DEX_NUM,CMD_HEART,buf,L);
  63. }
  64. //void send_data_pos_angle(void)
  65. //{
  66. // uint8_t buf[256];
  67. // uint8_t L=0;
  68. //
  69. // buf[L++] = (uint8_t)(h_pos[0]>>8);
  70. // buf[L++] = (uint8_t)(h_pos[0]>>0);
  71. //
  72. // buf[L++] = (uint8_t)(h_pos[1]>>8);
  73. // buf[L++] = (uint8_t)(h_pos[1]>>0);
  74. //
  75. // buf[L++] = (uint8_t)(h_pos[2]>>8);
  76. // buf[L++] = (uint8_t)(h_pos[2]>>0);
  77. //
  78. // buf[L++] = (uint8_t)(angle[0]>>8);
  79. // buf[L++] = (uint8_t)(angle[0]>>0);
  80. //
  81. // buf[L++] = (uint8_t)(angle[1]>>8);
  82. // buf[L++] = (uint8_t)(angle[1]>>0);
  83. //
  84. // buf[L++] = (uint8_t)(angle[2]>>8);
  85. // buf[L++] = (uint8_t)(angle[2]>>0);
  86. //
  87. // send_protocol(DEX_NUM,CMD_HEART,buf,L);
  88. //}
  89. void send_data_acc(void)
  90. {
  91. uint8_t buf[256];
  92. uint8_t L=0;
  93. buf[L++] = (uint8_t)(accel[0]>>8);
  94. buf[L++] = (uint8_t)(accel[0]>>0);
  95. buf[L++] = (uint8_t)(accel[1]>>8);
  96. buf[L++] = (uint8_t)(accel[1]>>0);
  97. buf[L++] = (uint8_t)(accel[2]>>8);
  98. buf[L++] = (uint8_t)(accel[2]>>0);
  99. buf[L++] = (uint8_t)(h_press>>8);
  100. buf[L++] = (uint8_t)(h_press>>0);
  101. send_protocol(DEX_NUM,CMD_HEART,buf,L);
  102. }
  103. void sen_data_press(void)
  104. {
  105. uint8_t buf[256];
  106. uint8_t L=0;
  107. buf[L++] = (uint8_t)(h_press>>8);
  108. buf[L++] = (uint8_t)(h_press>>0);
  109. buf[L++] = (uint8_t)(s_press>>8);
  110. buf[L++] = (uint8_t)(s_press>>0);
  111. send_protocol(DEX_NUM,CMD_HEART,buf,L);
  112. }
  113. void sen_data_left_press(void)
  114. {
  115. uint8_t buf[256];
  116. uint8_t L=0;
  117. buf[L++] = (uint8_t)(left_press>>24);
  118. buf[L++] = (uint8_t)(left_press>>16);
  119. buf[L++] = (uint8_t)(left_press>>8);
  120. buf[L++] = (uint8_t)(left_press>>0);
  121. send_protocol(DEX_NUM,CMD_HEART,buf,L);
  122. }
  123. void send_package_data(uint16_t package_num, int16_t right_shoes_data[3], int16_t left_shoes_data[3],
  124. int16_t s_zupt, int16_t h_zupt,int16_t is_down, int16_t is_jump, int8_t s_rssi, uint8_t time_stamp)
  125. {
  126. uint8_t buf[256];
  127. uint8_t L=0;
  128. buf[L++] = (uint8_t)(right_shoes_data[0]>>8);
  129. buf[L++] = (uint8_t)(right_shoes_data[0]>>0);
  130. buf[L++] = (uint8_t)(right_shoes_data[1]>>8);
  131. buf[L++] = (uint8_t)(right_shoes_data[1]>>0);
  132. buf[L++] = (uint8_t)(right_shoes_data[2]>>8);
  133. buf[L++] = (uint8_t)(right_shoes_data[2]>>0);
  134. buf[L++] = (uint8_t)(left_shoes_data[0]>>8);
  135. buf[L++] = (uint8_t)(left_shoes_data[0]>>0);
  136. buf[L++] = (uint8_t)(left_shoes_data[1]>>8);
  137. buf[L++] = (uint8_t)(left_shoes_data[1]>>0);
  138. buf[L++] = (uint8_t)(left_shoes_data[2]>>8);
  139. buf[L++] = (uint8_t)(left_shoes_data[2]>>0);
  140. buf[L++] = (uint8_t)(s_zupt * 8 + h_zupt * 4 + is_down * 2 + is_jump * 1);
  141. buf[L++] = (uint8_t)(s_rssi >> 0);
  142. buf[L++] = (uint8_t)(time_stamp);
  143. send_protocol(DEX_NUM,package_num,buf,L);
  144. }
  145. void send_dual_foot_data(void)
  146. {
  147. static uint8_t time_stamp = 0;
  148. send_package_data( 0x03, s_att, h_att, s_zupt, h_zupt, is_down, is_jump, s_rssi, time_stamp);
  149. send_package_data( 0x04, s_pos, h_pos, s_zupt, h_zupt, is_down, is_jump, s_rssi, time_stamp);
  150. time_stamp ++;
  151. }
  152. /*
  153. void send_dual_foot_data(void)
  154. {
  155. uint8_t buf[256];
  156. uint8_t L=0;
  157. buf[L++] = (uint8_t)(h_press>>8);
  158. buf[L++] = (uint8_t)(h_press>>0);
  159. buf[L++] = (uint8_t)(s_press>>8);
  160. buf[L++] = (uint8_t)(s_press>>0);
  161. buf[L++] = (uint8_t)(s_pos[2]>>8);
  162. buf[L++] = (uint8_t)(s_pos[2]>>0);
  163. buf[L++] = (uint8_t)(s_att[0]>>8);
  164. buf[L++] = (uint8_t)(s_att[0]>>0);
  165. buf[L++] = (uint8_t)(s_att[1]>>8);
  166. buf[L++] = (uint8_t)(s_att[1]>>0);
  167. buf[L++] = (uint8_t)(s_att[2]>>8);
  168. buf[L++] = (uint8_t)(s_att[2]>>0);
  169. buf[L++] = (uint8_t)(h_pos[0]>>8);
  170. buf[L++] = (uint8_t)(h_pos[0]>>0);
  171. buf[L++] = (uint8_t)(h_pos[1]>>8);
  172. buf[L++] = (uint8_t)(h_pos[1]>>0);
  173. buf[L++] = (uint8_t)(h_pos[2]>>8);
  174. buf[L++] = (uint8_t)(h_pos[2]>>0);
  175. buf[L++] = (uint8_t)(h_att[0]>>8);
  176. buf[L++] = (uint8_t)(h_att[0]>>0);
  177. buf[L++] = (uint8_t)(h_att[1]>>8);
  178. buf[L++] = (uint8_t)(h_att[1]>>0);
  179. buf[L++] = (uint8_t)(h_att[2]>>8);
  180. buf[L++] = (uint8_t)(h_att[2]>>0);
  181. buf[L++] = (uint8_t)(s_zupt>>0);
  182. buf[L++] = (uint8_t)(h_zupt>>0);
  183. buf[L++] = (uint8_t)(is_down>>0);
  184. buf[L++] = (uint8_t)(is_jump>>0);
  185. buf[L++] = (uint8_t)(s_rssi>>0);
  186. send_protocol(DEX_NUM,0x02,0x03,buf,L);
  187. }
  188. */
  189. void send_data_to_pc(void)
  190. {
  191. static uint8_t wait_time = 0;
  192. if(wait_time == 5)
  193. {
  194. send_dual_foot_data();
  195. wait_time = 0;
  196. }
  197. wait_time ++;
  198. }
  199. //void send_motion_to_phone(uint8_t motion,uint16_t ts)
  200. //{
  201. // uint8_t buf[16];
  202. // uint8_t L=0;
  203. // buf[L++] = motion;
  204. //
  205. // buf[L++] = (uint8_t)(ts>>8);
  206. // buf[L++] = (uint8_t)(ts>>0);
  207. //
  208. // for(int i = 0; i <5; i++)
  209. // send_protocol(DEX_NUM,CMD_MOTION,buf,L);
  210. //}
  211. void process_motion()
  212. {
  213. time_stamp = time_stamp + 1;
  214. left_press = (((int32_t)h_press & 0x0000ffff)<<8);
  215. right_press = (((int32_t)s_press & 0x0000ffff)<<8);
  216. // press_minimum_eval(((int32_t)h_press & 0x0000ffff), ((int32_t)s_press & 0x0000ffff), h_pos[2], s_pos[2]);
  217. short down_tag = 0;
  218. down_tag = press_down_detect_new(time_stamp, left_press, right_press);
  219. if (down_tag)
  220. {
  221. // send_motion_to_phone(MOTION_DOWN, time_stamp);
  222. gpio_mt_run(20);
  223. down_send_count = 20;
  224. }
  225. if(down_send_count > 0)
  226. {
  227. is_down = 1;
  228. down_send_count --;
  229. }
  230. else
  231. {
  232. is_down = 0;
  233. }
  234. short jump_tag = 0;
  235. jump_tag = press_jump_detect(h_pos , s_pos);
  236. if (jump_tag)
  237. {
  238. // send_motion_to_phone(MOTION_JUMP, time_stamp);
  239. gpio_mt_run(20);
  240. jump_send_count = 20;
  241. }
  242. //连续发20次蹲,终端再处理
  243. if(jump_send_count > 0)
  244. {
  245. is_jump = 1;
  246. jump_send_count --;
  247. }
  248. else
  249. {
  250. is_jump = 0;
  251. }
  252. gyr[0] = (float)gyro[0] / GYR_LSB;
  253. gyr[1] = (float)gyro[1] / GYR_LSB;
  254. gyr[2] = (float)gyro[2] / GYR_LSB;
  255. acc[0] = (float)accel[0] / ACC_LSB;
  256. acc[1] = (float)accel[1] / ACC_LSB;
  257. acc[2] = (float)accel[2] / ACC_LSB;
  258. unsigned char left_tag = footPDR(time_stamp, gyr, acc, left_press, h_pos, h_att, &h_zupt);
  259. if (h_zupt > 1 || h_zupt < 0)
  260. {
  261. // send_motion_to_phone(MOTION_LEFT, time_stamp);
  262. gpio_mt_run(20);
  263. }
  264. // memcpy(pos_n_offset, s_gyro, 3*sizeof(short));
  265. send_data_to_pc();
  266. }