#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" /************************ º¯ÊýÉùÃ÷ ***********************************/ static uint8_t flag =0; static uint32_t tim =0; static void cb_BLE_Client_BLE_AUTHEN(void* handle){ BLE_Client_Rx_t* target = handle; flag = target->pDat[0]; tim = TIME_GetTicks(); } 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; switch(state){ case 0: if(1 == flag){state =1;} break; case 1: if(2 == flag){ if(mFlash.isHost){ state =2; flag =1; } else { state =0; flag =0; } } else if(TIME_GetTicks() - tim >=3000){ state =0; flag =0; if(slave_isconnect())slave_disconnect(); } break; case 2: if(!slave_isconnect()){ state =0; flag =0; } 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; flag =0; } } } break; default:state=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); BLE_Host_Rx_Regist(BLE_AUTHEN,cb_BLE_Host_BLE_AUTHEN); }