app_Authen.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. /************************ º¯ÊýÉùÃ÷ ***********************************/
  12. static BLE_Host_Tx_t m_Host_BLE_AUTHEN = {
  13. .n = 0,
  14. .t = 300,
  15. };
  16. static uint8_t Phoneflag =0;
  17. static void cb_BLE_Client_BLE_AUTHEN(void* handle){
  18. DEBUG_LOG("Get cb_BLE_Client_BLE_AUTHEN\r\n");
  19. uint8_t dat =1;
  20. if(m_Host_BLE_AUTHEN.n <= 1){
  21. m_Host_BLE_AUTHEN.n =10;
  22. BLE_Host_Tx_Send(&m_Host_BLE_AUTHEN,BLE_AUTHEN,&dat,1);
  23. }
  24. else BLE_Host_Tx_Send(0,BLE_AUTHEN,&dat,1);
  25. Phoneflag =1;
  26. }
  27. static void cb_BLE_Host_BLE_AUTHEN(void* handle){
  28. BLE_Host_Rx_t* target = handle;
  29. BLE_Client_Tx_Send(0,BLE_AUTHEN,target->pDat,target->datLen);
  30. }
  31. //static BLE_Client_Tx_t m_Client_BLE_AUTHEN = {
  32. // .n = 10,
  33. // .t = 100,
  34. //};
  35. static void app_Authen_Process(void){
  36. static uint8_t state =0;
  37. bll_imu_data_t data= {0};
  38. static uint8_t LIFE_SIGNAL =0;
  39. uint8_t buf =0;
  40. static uint8_t host_state =1;
  41. static uint8_t Client_state =1;
  42. static uint32_t tim =0;
  43. if(mFlash.isHost){
  44. if(!slave_isconnect()){
  45. if(BLE_RIGHT_CONNTED == app_conneted_getRight() && 1 == host_state){
  46. DEBUG_LOG("app_conneted_getRight>>>>>>>>\r\n");
  47. buf =1;
  48. BLE_Host_Tx_Send(&m_Host_BLE_AUTHEN,BLE_AUTHEN,&buf,1);
  49. }
  50. host_state =0;
  51. }
  52. else {
  53. host_state =1;
  54. }
  55. }
  56. switch(state){
  57. case 0:
  58. if(slave_isconnect()){
  59. if(0 == Client_state){
  60. state =1;
  61. tim = TIME_GetTicks();
  62. Client_state =1;
  63. }
  64. }
  65. else Client_state =0;
  66. break;
  67. case 1:
  68. if(!slave_isconnect()){
  69. state =3;
  70. }
  71. else if(1 == Phoneflag){
  72. state =2;
  73. }
  74. else if(TIME_GetTicks() - tim >= 15000){
  75. if(slave_isconnect())slave_disconnect();
  76. else state =3;
  77. DEBUG_LOG("AUTHEN over time\r\n");
  78. }
  79. break;
  80. case 2:
  81. if(!slave_isconnect()){
  82. state =3;
  83. }
  84. // else if(TIME_GetTicks() - tim >= 15000){//²âÊÔʹÓÃ
  85. // state =3;
  86. // }
  87. // else {
  88. // int16_t data_size = 0;
  89. //
  90. // data_size = bll_imu_get_data_num(BLL_IMU_DIR_FRONT);
  91. //
  92. // if(data_size > 0){
  93. //
  94. // bll_imu_get_data(BLL_IMU_DIR_FRONT, data_size -1 , &data);
  95. //
  96. // int32_t acc_norm = (data.acc[0] * data.acc[0] +data.acc[1] * data.acc[1] + data.acc[2] * data.acc[2]);
  97. //
  98. // if(abs(acc_norm - 4194304) < 362144 && data.acc[2] > 1536){
  99. // LIFE_SIGNAL = 3;
  100. // }
  101. // else if(LIFE_SIGNAL > 0)LIFE_SIGNAL --;
  102. //
  103. // if(abs(acc_norm - 4194304) < 362144 && data.acc[2] < -1024)LIFE_SIGNAL = 0;
  104. //
  105. // if(LIFE_SIGNAL > 0){
  106. // buf =3;
  107. // BLE_Client_Tx_Send(&m_Client_BLE_AUTHEN,BLE_AUTHEN,&buf,1);
  108. // state =0;
  109. // }
  110. // }
  111. // }
  112. break;
  113. case 3:
  114. default:state=0;Phoneflag =0;break;
  115. }
  116. }
  117. void app_Authen_Init(void)
  118. {
  119. Process_Start(1000,"app_charge",app_Authen_Process);
  120. BLE_Client_Rx_Regist(BLE_AUTHEN,cb_BLE_Client_BLE_AUTHEN);
  121. DEBUG_LOG("BLE_Client_Rx_Regist %02x\r\n",BLE_AUTHEN);
  122. BLE_Host_Rx_Regist(BLE_AUTHEN,cb_BLE_Host_BLE_AUTHEN);
  123. }