app_data_transfer.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. //全功率模式
  19. if(hal_ser_imu_mode_manage_get_ready(HAL_SER_IMU_MODE_MANAGE_GAME) != -1 || \
  20. hal_ser_imu_mode_manage_get_ready(HAL_SER_IMU_MODE_MANAGE_REALSTEP) != -1)
  21. {
  22. if(!flag){flag =1;
  23. Process_SetHoldOn(app_data_transfer_Process,1);
  24. }
  25. if(TIME_GetTicks()-tim>=500){tim = TIME_GetTicks();
  26. if( 0 == slave_isconnect()){
  27. // DEBUG_LOG("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){flag =0;
  39. Process_SetHoldOn(app_data_transfer_Process,0);
  40. }
  41. }
  42. }
  43. /*API -------------------------------------------------------*/
  44. /**
  45. @brief 将旧版本的IMU_SetSlaveData(uint8_t* pdat,uint8_t len)写在这里
  46. @param pdat 略
  47. @param len 略
  48. @return 无
  49. */
  50. void app_data_transfer_set_SlaveData(uint8_t* pdat,uint8_t len)
  51. {
  52. if(pdat[3]==BLE_TRACK){
  53. IMU_Rec_data(pdat,len);
  54. }
  55. app_game_SetClientGameMode();
  56. }
  57. /**
  58. @brief 初始化数据传输应用
  59. @param 无
  60. @return 错误代码 - [out] -1失败,0成功
  61. */
  62. int app_data_transfer_Init(void)
  63. {
  64. //设置数据传输线程
  65. Process_Start(0,"app_data_transfer_Process",app_data_transfer_Process);
  66. BLE_Host_Rx_Regist_Game(app_data_transfer_set_SlaveData);
  67. return 0;
  68. }
  69. void send_protocol(uint8_t index,uint8_t cmd,uint8_t* p,uint8_t datLen)
  70. {
  71. BLE_Client_Tx_Send(0,(BLE_CMD_n)cmd,p,datLen);
  72. }