app_Authen.c 2.2 KB

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