app_data_transfer.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*Includes ----------------------------------------------*/
  2. #include "system.h"
  3. #include "ble_comm.h"
  4. #include "bsp_time.h"
  5. #include "hal_ble_host.h"
  6. #include "hal_ble_client.h"
  7. #include "hal_ble_common.h"
  8. #include "hal_ser_imu_mode_manage.h"
  9. #include "app_flash.h"
  10. #include "app_game.h"
  11. #include "app_data_transfer.h"
  12. /*Local Functions ------------------------------------------------------------------------------------------------------------------------------------*/
  13. static void app_data_transfer_Process(void)
  14. {
  15. static uint32_t tim = 0;
  16. static uint32_t tim2 = 0;
  17. static uint8_t flag = 0;
  18. if(hal_ser_imu_mode_manage_get_ready(HAL_SER_IMU_MODE_MANAGE_GAME) != -1 || \
  19. hal_ser_imu_mode_manage_get_ready(HAL_SER_IMU_MODE_MANAGE_REALSTEP) != -1)
  20. {
  21. if(!flag){
  22. Process_SetHoldOn(app_data_transfer_Process,1);
  23. flag =1;
  24. }
  25. if(TIME_GetTicks()-tim>=500){tim = TIME_GetTicks();
  26. if( 0 == slave_isconnect()){
  27. SEGGER_RTT_printf(0,"app_data_transfer_Process advertising_start\r\n");
  28. advertising_stop();
  29. advertising_start();
  30. }
  31. if(mFlash.isHost && 0 == host_isconnect())scan_start();
  32. }
  33. if(TIME_GetTicks()-tim2>=3){tim2 = TIME_GetTicks();
  34. IMU_Dtalige();
  35. }
  36. }
  37. else{
  38. if(flag){
  39. Process_SetHoldOn(app_data_transfer_Process,0);
  40. flag =0;
  41. }
  42. }
  43. }
  44. /*API -------------------------------------------------------*/
  45. /**
  46. @brief 将旧版本的IMU_SetSlaveData(uint8_t* pdat,uint8_t len)写在这里
  47. @param pdat 略
  48. @param len 略
  49. @return 无
  50. */
  51. void app_data_transfer_set_SlaveData(uint8_t* pdat,uint8_t len)
  52. {
  53. if(pdat[3]==BLE_TRACK){
  54. IMU_Rec_data(pdat,len);
  55. }
  56. app_game_SetClientGameMode();
  57. }
  58. /**
  59. @brief 初始化数据传输应用
  60. @param 无
  61. @return 错误代码 - [out] -1失败,0成功
  62. */
  63. int app_data_transfer_Init(void)
  64. {
  65. //设置数据传输线程
  66. Process_Start(0,"app_data_transfer_Process",app_data_transfer_Process);
  67. BLE_Host_Rx_Regist_Game(app_data_transfer_set_SlaveData);
  68. return 0;
  69. }
  70. void send_protocol(uint8_t index,uint8_t cmd,uint8_t* p,uint8_t datLen)
  71. {
  72. BLE_Client_Tx_Send(0,(BLE_CMD_n)cmd,p,datLen);
  73. }