app_data_transfer.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. if(hal_ser_imu_mode_manage_get_ready(HAL_SER_IMU_MODE_MANAGE_GAME) != -1 || \
  18. hal_ser_imu_mode_manage_get_ready(HAL_SER_IMU_MODE_MANAGE_REALSTEP) != -1)
  19. {
  20. if(TIME_GetTicks()-tim>=500){tim = TIME_GetTicks();
  21. if( 0 == slave_isconnect())advertising_start();
  22. if(mFlash.isHost && 0 == host_isconnect())scan_start();
  23. }
  24. if(TIME_GetTicks()-tim2>=FullPower_Interval){tim2 = TIME_GetTicks();
  25. IMU_Dtalige();
  26. }
  27. }
  28. }
  29. /*API -------------------------------------------------------*/
  30. /**
  31. @brief 将旧版本的IMU_SetSlaveData(uint8_t* pdat,uint8_t len)写在这里
  32. @param pdat 略
  33. @param len 略
  34. @return 无
  35. */
  36. void app_data_transfer_set_SlaveData(uint8_t* pdat,uint8_t len)
  37. {
  38. if(pdat[3]==BLE_TRACK){
  39. IMU_Rec_data(pdat,len);
  40. }
  41. app_game_SetClientGameMode();
  42. }
  43. /**
  44. @brief 初始化数据传输应用
  45. @param 无
  46. @return 错误代码 - [out] -1失败,0成功
  47. */
  48. int app_data_transfer_Init(void)
  49. {
  50. //设置数据传输线程
  51. Process_Start(0,"app_data_transfer_Process",app_data_transfer_Process);
  52. BLE_Host_Rx_Regist_Game(app_data_transfer_set_SlaveData);
  53. return 0;
  54. }
  55. void send_protocol(uint8_t index,uint8_t cmd,uint8_t* p,uint8_t datLen)
  56. {
  57. BLE_Client_Tx_Send(0,(BLE_CMD_n)cmd,p,datLen);
  58. }