123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- #include "usr_config.h"
- #include "app_Authen.h"
- #include "system.h"
- #include "hal_ble_client.h"
- #include "hal_ble_host.h"
- #include "bsp_time.h"
- #include "ble_comm.h"
- #include "bll_imu.h"
- #include "app_flash.h"
- #include "app_connect_manage.h"
- /************************ º¯ÊýÉùÃ÷ ***********************************/
- static BLE_Host_Tx_t m_Host_BLE_AUTHEN = {
- .n = 0,
- .t = 300,
- };
- static uint8_t Phoneflag =0;
- static void cb_BLE_Client_BLE_AUTHEN(void* handle){
- DEBUG_LOG("Get cb_BLE_Client_BLE_AUTHEN\r\n");
- uint8_t dat =1;
- if(m_Host_BLE_AUTHEN.n <= 1){
- m_Host_BLE_AUTHEN.n =10;
- BLE_Host_Tx_Send(&m_Host_BLE_AUTHEN,BLE_AUTHEN,&dat,1);
- }
- else BLE_Host_Tx_Send(0,BLE_AUTHEN,&dat,1);
- Phoneflag =1;
- }
- static void cb_BLE_Host_BLE_AUTHEN(void* handle){
- BLE_Host_Rx_t* target = handle;
- BLE_Client_Tx_Send(0,BLE_AUTHEN,target->pDat,target->datLen);
- }
- //static BLE_Client_Tx_t m_Client_BLE_AUTHEN = {
- // .n = 10,
- // .t = 100,
- //};
- static void app_Authen_Process(void){
- static uint8_t state =0;
- bll_imu_data_t data= {0};
- static uint8_t LIFE_SIGNAL =0;
- uint8_t buf =0;
- static uint8_t host_state =1;
- static uint8_t Client_state =1;
- static uint32_t tim =0;
-
- if(mFlash.isHost){
- if(!slave_isconnect()){
- if(BLE_RIGHT_CONNTED == app_conneted_getRight() && 1 == host_state){
- DEBUG_LOG("app_conneted_getRight>>>>>>>>\r\n");
- buf =1;
- BLE_Host_Tx_Send(&m_Host_BLE_AUTHEN,BLE_AUTHEN,&buf,1);
- }
- host_state =0;
- }
- else {
- host_state =1;
- }
- }
-
-
- switch(state){
- case 0:
- if(slave_isconnect()){
- if(0 == Client_state){
- state =1;
- tim = TIME_GetTicks();
- Client_state =1;
- }
- }
- else Client_state =0;
- break;
- case 1:
- if(!slave_isconnect()){
- state =3;
- }
- else if(1 == Phoneflag){
- state =2;
- }
- else if(TIME_GetTicks() - tim >= 15000){
- if(slave_isconnect())slave_disconnect();
- else state =3;
- DEBUG_LOG("AUTHEN over time\r\n");
- }
- break;
- case 2:
- if(!slave_isconnect()){
- state =3;
- }
- // else if(TIME_GetTicks() - tim >= 15000){//²âÊÔʹÓÃ
- // state =3;
- // }
- // else {
- // int16_t data_size = 0;
- //
- // data_size = bll_imu_get_data_num(BLL_IMU_DIR_FRONT);
- //
- // if(data_size > 0){
- //
- // bll_imu_get_data(BLL_IMU_DIR_FRONT, data_size -1 , &data);
- //
- // int32_t acc_norm = (data.acc[0] * data.acc[0] +data.acc[1] * data.acc[1] + data.acc[2] * data.acc[2]);
- //
- // if(abs(acc_norm - 4194304) < 362144 && data.acc[2] > 1536){
- // LIFE_SIGNAL = 3;
- // }
- // else if(LIFE_SIGNAL > 0)LIFE_SIGNAL --;
- //
- // if(abs(acc_norm - 4194304) < 362144 && data.acc[2] < -1024)LIFE_SIGNAL = 0;
- //
- // if(LIFE_SIGNAL > 0){
- // buf =3;
- // BLE_Client_Tx_Send(&m_Client_BLE_AUTHEN,BLE_AUTHEN,&buf,1);
- // state =0;
- // }
- // }
- // }
- break;
- case 3:
- default:state=0;Phoneflag =0;break;
- }
-
- }
- void app_Authen_Init(void)
- {
- Process_Start(1000,"app_charge",app_Authen_Process);
- BLE_Client_Rx_Regist(BLE_AUTHEN,cb_BLE_Client_BLE_AUTHEN);
- DEBUG_LOG("BLE_Client_Rx_Regist %02x\r\n",BLE_AUTHEN);
- BLE_Host_Rx_Regist(BLE_AUTHEN,cb_BLE_Host_BLE_AUTHEN);
- }
|