app_data_transfer.c 1.9 KB

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