app_data_transfer.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 "app_flash.h"
  9. #include "app_game.h"
  10. #include "app_data_transfer.h"
  11. #include "app_step.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(app_game_GetGameMode() || app_step_Real_Get())
  20. {
  21. if(!flag){flag =1;
  22. Process_SetHoldOn(app_data_transfer_Process,1);
  23. }
  24. if(TIME_GetTicks()-tim>=500){tim = TIME_GetTicks();
  25. if( 0 == slave_isconnect()){
  26. // DEBUG_LOG("app_data_transfer_Process advertising_start\r\n");
  27. advertising_stop();
  28. advertising_start();
  29. }
  30. if(mFlash.isHost && 0 == host_isconnect())scan_start();
  31. }
  32. if(TIME_GetTicks()-tim2>=3){tim2 = TIME_GetTicks();
  33. IMU_Dtalige();
  34. }
  35. }
  36. else{
  37. if(flag){flag =0;
  38. Process_SetHoldOn(app_data_transfer_Process,0);
  39. }
  40. }
  41. }
  42. /*API -------------------------------------------------------*/
  43. /**
  44. @brief 将旧版本的IMU_SetSlaveData(uint8_t* pdat,uint8_t len)写在这里
  45. @param pdat 略
  46. @param len 略
  47. @return 无
  48. */
  49. void app_data_transfer_set_SlaveData(uint8_t* pdat,uint8_t len)
  50. {
  51. if(pdat[3]==BLE_TRACK){
  52. IMU_Rec_data(pdat,len);
  53. }
  54. app_game_SetClientGameMode();
  55. }
  56. /**
  57. @brief 初始化数据传输应用
  58. @param 无
  59. @return 错误代码 - [out] -1失败,0成功
  60. */
  61. int app_data_transfer_Init(void)
  62. {
  63. //设置数据传输线程
  64. Process_Start(0,"app_data_transfer",app_data_transfer_Process);
  65. BLE_Host_Rx_Regist_Game(app_data_transfer_set_SlaveData);
  66. return 0;
  67. }
  68. void send_protocol(uint8_t index,uint8_t cmd,uint8_t* p,uint8_t datLen)
  69. {
  70. BLE_Client_Tx_Send(0,(BLE_CMD_n)cmd,p,datLen);
  71. }