app_Authen.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include "usr_config.h"
  2. #include "app_Authen.h"
  3. #include "system.h"
  4. #include "hal_ble_client.h"
  5. #include "hal_ble_host.h"
  6. #include "bsp_time.h"
  7. #include "ble_comm.h"
  8. #include "bll_imu.h"
  9. #include "app_flash.h"
  10. #include "app_connect_manage.h"
  11. #include "app_detectIsHost.h"
  12. /************************ 函数声明 ***********************************/
  13. static BLE_Host_Tx_t m_Host_BLE_AUTHEN = {
  14. .n = 10,
  15. .t = 300,
  16. };
  17. static uint8_t TrenCnt = 0;
  18. static void cb_BLE_Client_BLE_AUTHEN(void* handle){
  19. BLE_Client_Rx_t* target = (BLE_Client_Rx_t*)handle;
  20. TrenCnt = 0;
  21. // SEGGER_RTT_printf(0,"AUTHEN\r\n");
  22. if(target->datLen==1){ //SEGGER_RTT_printf(0,"target->pDat[0]=%d\r\n",target->pDat[0]);
  23. if(target->pDat[0]==1 ){ //是手机发的
  24. // SEGGER_RTT_printf(0,"=============LR==========\r\n");
  25. //固化左右鞋区分函数调用
  26. if('C' == mFlash.mClient.isConfig != mFlash.LR_FLAG){
  27. app_detect_LR_process_stop();
  28. mFlash.LR_FLAG = LR_FLAG_VALUE;
  29. if(Flash_SaveInfomation() != ZONE_OP_SUCCESS)Except_TxError(EXCEPT_FLASH,"pwr save information fail");
  30. mBackup.isHost= mFlash.isHost;
  31. mBackup.LR_FLAG = mFlash.LR_FLAG;
  32. if(Flash_SaveBackup() != ZONE_OP_SUCCESS)Except_TxError(EXCEPT_FLASH,"app_detect_LR save backup fail");
  33. }
  34. }
  35. }
  36. if(mFlash.isHost){
  37. BLE_Host_Tx_Send(&m_Host_BLE_AUTHEN,BLE_AUTHEN,target->pDat,target->datLen);
  38. }
  39. }
  40. static void app_Authen_Process(void){
  41. static uint8_t cnt = 0;
  42. static uint8_t HostAutodat =2;
  43. if(mFlash.isHost){ //
  44. if(host_isconnect()){
  45. if(cnt<30){ cnt++;
  46. BLE_Host_Tx_Send(0,BLE_AUTHEN,&HostAutodat,1);
  47. }
  48. }else{
  49. if(cnt>0) cnt = 0;
  50. }
  51. }
  52. if(slave_isconnect()){
  53. // SEGGER_RTT_printf(0,"1");
  54. if(TrenCnt>0){
  55. if(++TrenCnt>150){ TrenCnt = 150;
  56. slave_disconnect();
  57. // SEGGER_RTT_printf(0,"slave_disconnect %d\r\n");
  58. }
  59. }
  60. }else{
  61. if(TrenCnt!=1) TrenCnt = 1;
  62. }
  63. }
  64. void app_Authen_Init(void)
  65. {
  66. Process_Start(100,"app_Authon",app_Authen_Process);
  67. BLE_Client_Rx_Regist(BLE_AUTHEN,cb_BLE_Client_BLE_AUTHEN);
  68. }