app_Authen.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 uint8_t HostAutodat =1;
  18. static void cb_BLE_Client_BLE_AUTHEN(void* handle){
  19. DEBUG_LOG("Get cb_BLE_Client_BLE_AUTHEN\r\n");
  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,&HostAutodat,1);
  23. }
  24. else BLE_Host_Tx_Send(0,BLE_AUTHEN,&HostAutodat,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 void app_Authen_Process(void){
  32. static uint8_t state =0;
  33. uint8_t NowClient_state =0;
  34. static uint8_t LastClient_state =0;
  35. static uint32_t tim =0;
  36. if(slave_isconnect())NowClient_state = 1;
  37. else NowClient_state = 0;
  38. if(mFlash.isHost){
  39. if(0 == NowClient_state){
  40. if(BLE_RIGHT_CONNTED == app_conneted_getRight() && 1 == LastClient_state){
  41. DEBUG_LOG("app_conneted_getRight>>>>>>>>\r\n");
  42. BLE_Host_Tx_Send(&m_Host_BLE_AUTHEN,BLE_AUTHEN,&HostAutodat,1);
  43. }
  44. }
  45. }
  46. switch(state){
  47. case 0:
  48. if(NowClient_state && 0 == LastClient_state){
  49. state =1;
  50. tim = TIME_GetTicks();
  51. }
  52. break;
  53. case 1:
  54. if(0 == NowClient_state){state =3;}
  55. else if(1 == Phoneflag){state =2;}
  56. else if(TIME_GetTicks() - tim >= 15000){
  57. if(NowClient_state)slave_disconnect();
  58. else state =3;
  59. DEBUG_LOG("AUTHEN over time\r\n");
  60. }
  61. break;
  62. case 2:
  63. if(0 == NowClient_state){state =3;}
  64. break;
  65. case 3:
  66. default:state=0;Phoneflag =0;break;
  67. }
  68. LastClient_state = NowClient_state;
  69. }
  70. void app_Authen_Init(void)
  71. {
  72. Process_Start(1000,"app_Authon",app_Authen_Process);
  73. BLE_Client_Rx_Regist(BLE_AUTHEN,cb_BLE_Client_BLE_AUTHEN);
  74. DEBUG_LOG("BLE_Client_Rx_Regist %02x\r\n",BLE_AUTHEN);
  75. BLE_Host_Rx_Regist(BLE_AUTHEN,cb_BLE_Host_BLE_AUTHEN);
  76. }