send_data.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. #include "send_data.h"
  2. void send_package_data(uint16_t package_num, int32_t right_pos_data[3], int32_t left_pos_data[3], int16_t right_att_data[3], int16_t left_att_data[3],
  3. int16_t s_zupt, int16_t h_zupt,int16_t is_down, int16_t is_jump, int8_t s_rssi, uint8_t time_stamp)
  4. {
  5. uint8_t buf[256];
  6. uint8_t L=0;
  7. buf[L++] = (uint8_t)(right_pos_data[0]>>24);
  8. buf[L++] = (uint8_t)(right_pos_data[0]>>16);
  9. buf[L++] = (uint8_t)(right_pos_data[0]>>8);
  10. buf[L++] = (uint8_t)(right_pos_data[0]>>0);
  11. buf[L++] = (uint8_t)(right_pos_data[1]>>24);
  12. buf[L++] = (uint8_t)(right_pos_data[1]>>16);
  13. buf[L++] = (uint8_t)(right_pos_data[1]>>8);
  14. buf[L++] = (uint8_t)(right_pos_data[1]>>0);
  15. buf[L++] = (uint8_t)(right_pos_data[2]>>24);
  16. buf[L++] = (uint8_t)(right_pos_data[2]>>16);
  17. buf[L++] = (uint8_t)(right_pos_data[2]>>8);
  18. buf[L++] = (uint8_t)(right_pos_data[2]>>0);
  19. buf[L++] = (uint8_t)(left_pos_data[0]>>24);
  20. buf[L++] = (uint8_t)(left_pos_data[0]>>16);
  21. buf[L++] = (uint8_t)(left_pos_data[0]>>8);
  22. buf[L++] = (uint8_t)(left_pos_data[0]>>0);
  23. buf[L++] = (uint8_t)(left_pos_data[1]>>24);
  24. buf[L++] = (uint8_t)(left_pos_data[1]>>16);
  25. buf[L++] = (uint8_t)(left_pos_data[1]>>8);
  26. buf[L++] = (uint8_t)(left_pos_data[1]>>0);
  27. buf[L++] = (uint8_t)(left_pos_data[2]>>24);
  28. buf[L++] = (uint8_t)(left_pos_data[2]>>16);
  29. buf[L++] = (uint8_t)(left_pos_data[2]>>8);
  30. buf[L++] = (uint8_t)(left_pos_data[2]>>0);
  31. buf[L++] = (uint8_t)(right_att_data[0]>>8);
  32. buf[L++] = (uint8_t)(right_att_data[0]>>0);
  33. buf[L++] = (uint8_t)(right_att_data[1]>>8);
  34. buf[L++] = (uint8_t)(right_att_data[1]>>0);
  35. buf[L++] = (uint8_t)(right_att_data[2]>>8);
  36. buf[L++] = (uint8_t)(right_att_data[2]>>0);
  37. buf[L++] = (uint8_t)(left_att_data[0]>>8);
  38. buf[L++] = (uint8_t)(left_att_data[0]>>0);
  39. buf[L++] = (uint8_t)(left_att_data[1]>>8);
  40. buf[L++] = (uint8_t)(left_att_data[1]>>0);
  41. buf[L++] = (uint8_t)(left_att_data[2]>>8);
  42. buf[L++] = (uint8_t)(left_att_data[2]>>0);
  43. int is_girl = 0;
  44. if(GIRL_SHOES)
  45. is_girl = 1;
  46. buf[L++] = (uint8_t)(is_girl * 16 + s_zupt * 8 + h_zupt * 4 + is_down * 2 + is_jump * 1);
  47. buf[L++] = (uint8_t)(s_rssi >> 0);
  48. buf[L++] = (uint8_t)(time_stamp);
  49. send_protocol(DEX_NUM,package_num,buf,L);
  50. }
  51. void send_data_to_com(int32_t s_pos[3], int32_t h_pos[3], int16_t s_att[3], int16_t h_att[3] , int16_t s_zupt, int16_t h_zupt, int16_t is_down, int16_t is_jump, int8_t s_rssi)
  52. {
  53. static uint8_t time_stamp = 0;
  54. if(LEFT_IS_HOST)
  55. send_package_data( 0x04, s_pos, h_pos, s_att, h_att ,s_zupt, h_zupt, is_down, is_jump, s_rssi, time_stamp);
  56. else
  57. send_package_data( 0x04, h_pos, s_pos, h_att, s_att ,h_zupt, s_zupt, is_down, is_jump, s_rssi, time_stamp);
  58. time_stamp ++;
  59. }
  60. void send_data_to_host(uint16_t press, int32_t pos_n_offset[3], int16_t att[3], int16_t zupt)
  61. {
  62. static uint16_t ts = 0;
  63. uint8_t buf[256];
  64. uint8_t L=0;
  65. buf[L++] = (uint8_t)(press>>8);
  66. buf[L++] = (uint8_t)(press>>0);
  67. buf[L++] = (uint8_t)(pos_n_offset[0]>>24);
  68. buf[L++] = (uint8_t)(pos_n_offset[0]>>16);
  69. buf[L++] = (uint8_t)(pos_n_offset[0]>>8);
  70. buf[L++] = (uint8_t)(pos_n_offset[0]>>0);
  71. buf[L++] = (uint8_t)(pos_n_offset[1]>>24);
  72. buf[L++] = (uint8_t)(pos_n_offset[1]>>16);
  73. buf[L++] = (uint8_t)(pos_n_offset[1]>>8);
  74. buf[L++] = (uint8_t)(pos_n_offset[1]>>0);
  75. buf[L++] = (uint8_t)(pos_n_offset[2]>>24);
  76. buf[L++] = (uint8_t)(pos_n_offset[2]>>16);
  77. buf[L++] = (uint8_t)(pos_n_offset[2]>>8);
  78. buf[L++] = (uint8_t)(pos_n_offset[2]>>0);
  79. buf[L++] = (uint8_t)(att[0]>>8);
  80. buf[L++] = (uint8_t)(att[0]>>0);
  81. buf[L++] = (uint8_t)(att[1]>>8);
  82. buf[L++] = (uint8_t)(att[1]>>0);
  83. buf[L++] = (uint8_t)(att[2]>>8);
  84. buf[L++] = (uint8_t)(att[2]>>0);
  85. buf[L++] = (uint8_t)(zupt>>0);
  86. buf[L++] = (uint8_t)(ts>>8);
  87. buf[L++] = (uint8_t)(ts>>0);
  88. ts++;
  89. send_protocol(DEX_NUM,CMD_HEART,buf,L);
  90. }
  91. void send_acc_mag_to_host(uint16_t press, int16_t accl[3], int16_t magn[3], int16_t zupt)
  92. {
  93. static uint16_t ts = 0;
  94. uint8_t buf[256];
  95. uint8_t L=0;
  96. buf[L++] = 0;
  97. buf[L++] = 0;
  98. buf[L++] = (uint8_t)(press>>8);
  99. buf[L++] = (uint8_t)(press>>0);
  100. buf[L++] = (uint8_t)(accl[0]>>8);
  101. buf[L++] = (uint8_t)(accl[0]>>0);
  102. buf[L++] = (uint8_t)(accl[1]>>8);
  103. buf[L++] = (uint8_t)(accl[1]>>0);
  104. buf[L++] = (uint8_t)(accl[2]>>8);
  105. buf[L++] = (uint8_t)(accl[2]>>0);
  106. buf[L++] = (uint8_t)(magn[0]>>8);
  107. buf[L++] = (uint8_t)(magn[0]>>0);
  108. buf[L++] = (uint8_t)(magn[1]>>8);
  109. buf[L++] = (uint8_t)(magn[1]>>0);
  110. buf[L++] = (uint8_t)(magn[2]>>8);
  111. buf[L++] = (uint8_t)(magn[2]>>0);
  112. buf[L++] = (uint8_t)(zupt>>0);
  113. ts++;
  114. send_protocol(DEX_NUM,CMD_HEART,buf,L);
  115. }
  116. void send_imu_data_to_host(uint16_t press, int16_t gyro[3], int16_t accl[3], int16_t magn[3], int16_t zupt)
  117. {
  118. static uint16_t ts = 0;
  119. uint8_t buf[256];
  120. uint8_t L=0;
  121. buf[L++] = (uint8_t)(press>>8);
  122. buf[L++] = (uint8_t)(press>>0);
  123. buf[L++] = (uint8_t)(gyro[0]>>8);
  124. buf[L++] = (uint8_t)(gyro[0]>>0);
  125. buf[L++] = (uint8_t)(gyro[1]>>8);
  126. buf[L++] = (uint8_t)(gyro[1]>>0);
  127. buf[L++] = (uint8_t)(gyro[2]>>8);
  128. buf[L++] = (uint8_t)(gyro[2]>>0);
  129. buf[L++] = (uint8_t)(accl[0]>>8);
  130. buf[L++] = (uint8_t)(accl[0]>>0);
  131. buf[L++] = (uint8_t)(accl[1]>>8);
  132. buf[L++] = (uint8_t)(accl[1]>>0);
  133. buf[L++] = (uint8_t)(accl[2]>>8);
  134. buf[L++] = (uint8_t)(accl[2]>>0);
  135. buf[L++] = (uint8_t)(magn[0]>>8);
  136. buf[L++] = (uint8_t)(magn[0]>>0);
  137. buf[L++] = (uint8_t)(magn[1]>>8);
  138. buf[L++] = (uint8_t)(magn[1]>>0);
  139. buf[L++] = (uint8_t)(magn[2]>>8);
  140. buf[L++] = (uint8_t)(magn[2]>>0);
  141. buf[L++] = (uint8_t)(zupt>>0);
  142. buf[L++] = (uint8_t)(ts>>8);
  143. buf[L++] = (uint8_t)(ts>>0);
  144. ts++;
  145. send_protocol(DEX_NUM,CMD_HEART,buf,L);
  146. }
  147. void send_imu_data_to_ble(uint16_t press, int16_t gyro[3], int16_t accl[3], int16_t magn[3],
  148. uint16_t s_press, int16_t s_gyro[3], int16_t s_accl[3], int16_t s_magn[3], int8_t rssi )
  149. {
  150. static uint16_t ts = 0;
  151. uint8_t buf[256];
  152. uint8_t L=0;
  153. buf[L++] = (uint8_t)(press>>8);
  154. buf[L++] = (uint8_t)(press>>0);
  155. buf[L++] = (uint8_t)(gyro[0]>>8);
  156. buf[L++] = (uint8_t)(gyro[0]>>0);
  157. buf[L++] = (uint8_t)(gyro[1]>>8);
  158. buf[L++] = (uint8_t)(gyro[1]>>0);
  159. buf[L++] = (uint8_t)(gyro[2]>>8);
  160. buf[L++] = (uint8_t)(gyro[2]>>0);
  161. buf[L++] = (uint8_t)(accl[0]>>8);
  162. buf[L++] = (uint8_t)(accl[0]>>0);
  163. buf[L++] = (uint8_t)(accl[1]>>8);
  164. buf[L++] = (uint8_t)(accl[1]>>0);
  165. buf[L++] = (uint8_t)(accl[2]>>8);
  166. buf[L++] = (uint8_t)(accl[2]>>0);
  167. buf[L++] = (uint8_t)(magn[0]>>8);
  168. buf[L++] = (uint8_t)(magn[0]>>0);
  169. buf[L++] = (uint8_t)(magn[1]>>8);
  170. buf[L++] = (uint8_t)(magn[1]>>0);
  171. buf[L++] = (uint8_t)(magn[2]>>8);
  172. buf[L++] = (uint8_t)(magn[2]>>0);
  173. buf[L++] = (uint8_t)(s_press>>8);
  174. buf[L++] = (uint8_t)(s_press>>0);
  175. buf[L++] = (uint8_t)(s_gyro[0]>>8);
  176. buf[L++] = (uint8_t)(s_gyro[0]>>0);
  177. buf[L++] = (uint8_t)(s_gyro[1]>>8);
  178. buf[L++] = (uint8_t)(s_gyro[1]>>0);
  179. buf[L++] = (uint8_t)(s_gyro[2]>>8);
  180. buf[L++] = (uint8_t)(s_gyro[2]>>0);
  181. buf[L++] = (uint8_t)(s_accl[0]>>8);
  182. buf[L++] = (uint8_t)(s_accl[0]>>0);
  183. buf[L++] = (uint8_t)(s_accl[1]>>8);
  184. buf[L++] = (uint8_t)(s_accl[1]>>0);
  185. buf[L++] = (uint8_t)(s_accl[2]>>8);
  186. buf[L++] = (uint8_t)(s_accl[2]>>0);
  187. buf[L++] = (uint8_t)(s_magn[0]>>8);
  188. buf[L++] = (uint8_t)(s_magn[0]>>0);
  189. buf[L++] = (uint8_t)(s_magn[1]>>8);
  190. buf[L++] = (uint8_t)(s_magn[1]>>0);
  191. buf[L++] = (uint8_t)(s_magn[2]>>8);
  192. buf[L++] = (uint8_t)(s_magn[2]>>0);
  193. buf[L++] = (uint8_t)(rssi);
  194. send_protocol(DEX_NUM,CMD_HEART,buf,L);
  195. }