12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #include "system.h"
- #include "app_host.h"
- #include "hal_ble_client.h"
- #include "hal_ble_host.h"
- #include "bsp_time.h"
- #include "hal_led.h"
- #include "ble_gap.h"
- #include "hal_battery.h"
- #include "app_flash.h"
- #include "ble_comm.h"
- #include "app_client.h"
- static uint8_t vol_R = 0;
- static uint8_t temp_R = 0;
- static uint32_t press_R = 0;
- static int16_t volADC_R = 0;
- uint8_t app_host_GetVol_R(void){ return vol_R; }
- int16_t app_host_GetVolAdc_R(void){ return volADC_R; }
- uint8_t app_host_GetTemp_R(void){ return temp_R; }
- uint32_t app_host_GetPress_R(void){ return press_R; }
- static BLE_Host_Tx_t mBLE_Host_T_UPDATE_INFO_R = {
- .n = 10,
- .t = 1000,
- .cb = 0,
- };
- void app_host_GetClientInfo(void)
- {
- static uint8_t buf=BLE_UPDATE_BASEINFO;
- BLE_Host_Tx_Send(&mBLE_Host_T_UPDATE_INFO_R,BLE_UPDATE,&buf,1);
- }
- static BLE_Host_Tx_t mBLE_Host_T_UPDATE_DATA_R = {
- .n = 0,
- .t = 500,
- .cb = 0,
- };
- void app_host_GetClientData(uint8_t temp)
- {
- static uint8_t buf=BLE_UPDATE_DATA;
- BLE_Host_Tx_Send(0,BLE_UPDATE,&buf,1);
- if(0 == mBLE_Host_T_UPDATE_DATA_R.n && temp >=2){
- mBLE_Host_T_UPDATE_DATA_R.n = temp;
- BLE_Host_Tx_Send(&mBLE_Host_T_UPDATE_DATA_R,BLE_UPDATE,&buf,1);
- }
- }
-
- void cb_BLE_Host_R_UPDATE(void* handle)
- {
- BLE_Host_Rx_t *target = handle;
- uint8_t _cmd = target->pDat[0];
- switch(_cmd){
- case BLE_UPDATE_BASEINFO:{
-
- for(int i=0;i<6;i++) mFlash.mClient.macAddr[i] = target->pDat[i+1+SHOES_NAME_LEN];
- uint8_t L = SHOES_NAME_LEN+7;
- mFlash.mClient.hardVersion = ((uint32_t)target->pDat[L]<<24) |((uint32_t)target->pDat[L+1]<<16) |((uint32_t)target->pDat[L+2]<<8) |((uint32_t)target->pDat[L+3]);
- mFlash.mClient.sotfVersion = ((uint16_t)target->pDat[L+4]<<8 | (uint16_t)target->pDat[L+5]);
- app_client_infomation_Send();
- break;}
- case BLE_UPDATE_DATA:{
-
- vol_R = target->pDat[1];
- temp_R = target->pDat[2];
- press_R = ((uint32_t)target->pDat[3]<<24)|((uint32_t)target->pDat[4]<<16)|((uint32_t)target->pDat[5]<<8)|((uint32_t)target->pDat[6]<<0);
- mFlash.mStep.stepCur[1] = ((uint32_t)target->pDat[7]<<24)|((uint32_t)target->pDat[8]<<16)|((uint32_t)target->pDat[9]<<8)|((uint32_t)target->pDat[10]<<0);
-
- if(target->datLen >= 25)volADC_R = ((target->pDat[21]<<8)+target->pDat[22]);
-
- mBLE_Host_T_UPDATE_DATA_R.n = 0;
- app_client_DataUpdate_Send();
- break;}
- default:break;
- }
- }
- void app_host_Initialize(void)
- {
- if(1 == mFlash.isHost){
- BLE_Host_Rx_Regist(BLE_UPDATE,cb_BLE_Host_R_UPDATE);
- }
- }
|