From: hcj_ <1224667075@qq.com> Date: Wed, 29 May 2024 16:07:30 +0000 (+0800) Subject: 增加步数数据整点存储及协议数据发送 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=8b4bfd1e805af3822a4cd01665c0eb07819aab27;p=mirrors%2FFD230.git 增加步数数据整点存储及协议数据发送 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp b/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp index 2e557750c..28adda236 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp @@ -88,6 +88,15 @@ static void AlarmCallBackProcB(void) GraphicService::GetInstance()->PostGraphicEvent(SetZeroAlarm); } +static void on_time_CallBackProc(void) +{ + AlarmClockEventData unuse; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "on_time_CallBackProc"); + GraphicService::GetInstance()->PostGraphicEvent( + std::bind(AlarmTimerEventPublish, TOPIC_EVENT_ON_TIME, unuse)); +} + + void AlarmScan(void *arg) { struct tm curTime; @@ -114,6 +123,11 @@ void AlarmScan(void *arg) g_alarmCtrB.state = ALARM_STATUS_CREATED; } } + if(curTime.tm_min==0 && curTime.tm_sec==0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "time: %d : %d",curTime.tm_hour,curTime.tm_min); + on_time_CallBackProc(); + } } static int32_t AlarmCreate(AlarmCtrl *alarmCtrl, AlarmCallBack callback) diff --git a/code/sdk/application/wearable/fd230app/nativeui/phone/src/phoneaddressmodel.cpp b/code/sdk/application/wearable/fd230app/nativeui/phone/src/phoneaddressmodel.cpp index 67f0af0f2..47960cd79 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/phone/src/phoneaddressmodel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/phone/src/phoneaddressmodel.cpp @@ -170,6 +170,7 @@ namespace OHOS } // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "read_addressbook_bin_file!!!!!!"); char* buf = (char *)malloc(512); + memset(buf,0,512); int ret=fread(buf,1,512,fp); if(ret==0) @@ -178,7 +179,7 @@ namespace OHOS free(buf); return; } - + int offset_f=512; while (ret==512) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/systemupdate/src/SystemUpdateView.cpp b/code/sdk/application/wearable/fd230app/nativeui/systemupdate/src/SystemUpdateView.cpp index 0262dde94..c3593a08f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/systemupdate/src/SystemUpdateView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/systemupdate/src/SystemUpdateView.cpp @@ -856,8 +856,8 @@ namespace OHOS TryAgainLaterButton->SetVisible(false); TryAgainLaterLabel->SetVisible(false); - NEWMSGLabel->SetVisible(false); - NEWVersionIdLabel->SetVisible(false); + NEWMSGLabel->SetVisible(true); + NEWVersionIdLabel->SetVisible(true); //VersionIdLabel->SetText("OTA V4.0.0"); updatasider->SetVisible(true); diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp index a3b376c80..aa82c750e 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -57,6 +57,36 @@ extern "C" { #include "bleService.h" #include "bletest.h" + +#define CWM_HISTORY_DATA_PATH "/system/" + +char * ble_step_history(uint8_t day) +{ + char path_[64]={0}; + char timeday[12] = {0}; + uapi_get_YYMMDD_Time(timeday, '_'); + sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_PATH,timeday); + + FILE * fp = fopen(path_,"rb+"); + if(fp==NULL) + { + return NULL; + } + uint32_t size; + if (fp != NULL) + { + fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾 + size = ftell(fp); // 获取当前文件指针位置,即文件大小 + fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头 + } + + char * buf=(char *)malloc(size); + uint32_t ret= fread(buf,1,size,fp); + printf("fread %d \r\n",ret); + + return buf; + +} void ble_set_sleep_remind(msg_get_sleep_param_info_t data) { OHOS::ConfigModel *p_ConfigModel = OHOS::ConfigModel::GetInstance(); @@ -75,8 +105,6 @@ void ble_set_sleep_remind(msg_get_sleep_param_info_t data) printf("睡前提醒 %d\r\n",data.bedtime_alarm); p_ConfigModel->set_condigData_Int(OHOS::ConfigModel::CONFIFMOFEL_ITEM_SLEEP_REMIND,data.bedtime_alarm); - - } return; } diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h index 4a7dd3616..c4b12c18e 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h @@ -180,6 +180,8 @@ void ble_get_drink_remind(msg_drink_info_t *data); void ble_get_sleep_remind(msg_get_sleep_param_info_t *data); void ble_set_sleep_remind(msg_get_sleep_param_info_t data); + +char * ble_step_history(uint8_t day); #ifdef __cplusplus #if __cplusplus } diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c index 261157bfb..320572786 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -279,6 +279,7 @@ static uint8_t get_crc_from_lrc(uint8_t lrcValue) return crcbuf; } +#define USE_DEMO static bool Check_CRC(uint8_t *data,uint16_t len,uint8_t crcvalue)//计算20byte的的校验位 { uint8_t crcbuf = 0; @@ -303,7 +304,11 @@ static bool Check_CRC(uint8_t *data,uint16_t len,uint8_t crcvalue)//计算20byte if(uapi_dev_runtime_get_android_connection_status()==1) return true; else + #ifndef USE_DEMO return false; + #else + return true; + #endif } } @@ -4207,7 +4212,7 @@ uint32_t EACH_DATA_LEN=0;//每种数据类型的的长度 -void Read_file_buf_send_bin_Data(uint8_t num,uint16_t id,char *data_item) +void Read_JSON_file_buf_send_bin_Data(uint8_t num,uint16_t id,char *data_item) { sendbigDataBufState = true;//分包同步数据不允许打断 char *buf=NULL; @@ -4358,6 +4363,83 @@ void Read_file_buf_send_bin_Data(uint8_t num,uint16_t id,char *data_item) } +void Read_BIN_file_buf_send_bin_Data(uint32_t pack_size,uint16_t id) +{ + sendbigDataBufState = true;//分包同步数据不允许打断 + char *buf=NULL; + const char *data=NULL; + uint8_t timeBit = 4;//默认是4个字节的时间戳 + uint8_t dataBit = 1;//默认是1个字节的数据 + switch (id) + { + case 0x43: //同步步数历史数据 + data=ble_step_history(0); + dataBit = 4;//心率数据字节4个字节 uint32_t + break; + case 0x44://同步燃脂时间数据 + data=NULL; + break; + case 0x45://同步站立历史数据 + data=NULL; + break; + case 0x46://同步卡路里历史数据 + data=NULL; + break; + case 0x47://同步距离历史数据 + data=NULL; + break; + case 0x49://同步基础训练历史数据 + data=NULL; + break; + case 0x4b://睡眠历史数据 + data=NULL; + break; + } + + if(data==NULL) + { + send_big_data(1,NULL,0,0,1,1,id,1); + sendbigDataBufState = false;//分包同步数据不允许打断 + return; + } + + uint32_t data_len = strlen(data); + + uint32_t surplus_len=data_len; + uint32_t pack; + if(data_len%pack_size==0) + { + pack=data_len/pack_size; + } + else + { + pack=data_len/pack_size+1; + } + //printf("%d %d %d %d\r\n",data_len,surplus_len,pack_id,pack); + uint32_t pack_id=1; + uint32_t offset=0; + while (surplus_len!=0) + { + if(surplus_len>=pack_size) + { + surplus_len=surplus_len-pack_size; + send_big_data(1,data+offset,pack_size,data_len,pack_id,pack,id,1); + offset+=pack_size; + } + else + { + + printf("%d %d %d %d\r\n",data_len,surplus_len,pack_id,pack); + send_big_data(1,data+offset,surplus_len,data_len,pack_id,pack,id,1); + break; + } + pack_id++; + } + free(data); + sendbigDataBufState = false; + +} + //手机app下发读设备数据指令 void readDevDataBle(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,uint8_t crcvalue) { @@ -4392,39 +4474,43 @@ void readDevDataBle(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,u num=96; } printf("同步心率数据,每包最多:%d 条数据 data:%d\r\n",num,data[0]); - Read_file_buf_send_bin_Data(num,0x40,"heart_data_list"); + Read_JSON_file_buf_send_bin_Data(num,0x40,"heart_data_list"); break; case 0x41://同步血氧历史数据 printf("同步血氧数据\r\n"); EACH_DATA_LEN = SPO2_DATA_LEN; num=(ble_nus_max_data_len-18)/EACH_DATA_LEN; - Read_file_buf_send_bin_Data(num,0x41,"heart_data_list"); + Read_JSON_file_buf_send_bin_Data(num,0x41,"heart_data_list"); break; case 0x43: //同步步数历史数据 - EACH_DATA_LEN = STEP_DATA_LEN; - num=(ble_nus_max_data_len-18)/EACH_DATA_LEN; - Read_file_buf_send_bin_Data(num,0x43,"heart_data_list"); + + num=(ble_nus_max_data_len-18); + if(num>482) + { + num=482; + } + Read_BIN_file_buf_send_bin_Data(num,0x43); break; case 0x44://同步燃脂时间数据 EACH_DATA_LEN = FATTIME_DATA_LEN; num=(ble_nus_max_data_len-18)/EACH_DATA_LEN; - Read_file_buf_send_bin_Data(num,0x44,"heart_data_list"); + Read_JSON_file_buf_send_bin_Data(num,0x44,"heart_data_list"); break; case 0x45://同步站立历史数据 EACH_DATA_LEN = STAND_DATA_LEN; num=(ble_nus_max_data_len-18)/EACH_DATA_LEN; - Read_file_buf_send_bin_Data(num,0x45,"heart_data_list"); + Read_JSON_file_buf_send_bin_Data(num,0x45,"heart_data_list"); break; case 0x46://同步卡路里历史数据 EACH_DATA_LEN = KCAL_DATA_LEN; num=(ble_nus_max_data_len-18)/EACH_DATA_LEN; - Read_file_buf_send_bin_Data(num,0x46,"heart_data_list"); + Read_JSON_file_buf_send_bin_Data(num,0x46,"heart_data_list"); break; case 0x47://同步距离历史数据 EACH_DATA_LEN = DIS_DATA_LEN; num=(ble_nus_max_data_len-18)/EACH_DATA_LEN; - Read_file_buf_send_bin_Data(num,0x47,"heart_data_list"); + Read_JSON_file_buf_send_bin_Data(num,0x47,"heart_data_list"); break; case 0x49://同步基础训练历史数据 EACH_DATA_LEN = DIS_DATA_LEN; @@ -4447,7 +4533,7 @@ void readDevDataBle(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,u case 0x4b://睡眠历史数据 EACH_DATA_LEN = DIS_DATA_LEN; num=(ble_nus_max_data_len-18)/EACH_DATA_LEN; - Read_file_buf_send_bin_Data(num,0x4b,"heart_data_list"); + Read_JSON_file_buf_send_bin_Data(num,0x4b,"heart_data_list"); break; default: diff --git a/code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h b/code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h index b1d6e567f..a925ba556 100755 --- a/code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h +++ b/code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h @@ -33,6 +33,7 @@ typedef enum { TOPIC_DEMO_ACORE_MSG = TOPIC_START_NUM, TOPIC_DEMO_ALL_MSG, TOPIC_EVENT_ALARM_RING, + TOPIC_EVENT_ON_TIME, TOPIC_EVENT_UTCTIME_UPDATE, TOPIC_EVENT_NEXTDAY_UPDATE, TOPIC_EVENT_WEARSTATE_UPDATE, diff --git a/code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c b/code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c index db59f3d6c..4ad305576 100755 --- a/code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c +++ b/code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c @@ -20,6 +20,7 @@ static const TopicToCore topicToCoreArray[] = { {TOPIC_DEMO_ACORE_MSG, A_CORE_MASK, 1}, {TOPIC_DEMO_ALL_MSG, A_CORE_MASK, 1}, {TOPIC_EVENT_ALARM_RING, A_CORE_MASK, 1}, + {TOPIC_EVENT_ON_TIME, A_CORE_MASK, 1}, {TOPIC_EVENT_UTCTIME_UPDATE, A_CORE_MASK, 1}, {TOPIC_EVENT_NEXTDAY_UPDATE, A_CORE_MASK, 1}, {TOPIC_EVENT_WEARSTATE_UPDATE, A_CORE_MASK, 1}, diff --git a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp index 01bf0043e..8bd10ae7c 100644 --- a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp @@ -55,6 +55,7 @@ extern "C" { /* 订阅事件设定优先级 */ const PriorityMapper g_pri_mapper[] = { {TOPIC_EVENT_ALARM_RING, PRIORITY_TWO}, + {TOPIC_EVENT_ON_TIME,PRIORITY_TWO}, {TOPIC_EVENT_NEXTDAY_UPDATE, PRIORITY_TWO}, {TOPIC_EVENT_ACTIVITY_UPDATE,PRIORITY_TWO}, {TOPIC_EVENT_INACTIVITY_UPDATE,PRIORITY_TWO}, @@ -120,6 +121,7 @@ static bool CheckPriority(const Topic topic) void MsgCenterSubscribe() { MsgCenterSubscribeTopic(TOPIC_EVENT_ALARM_RING); + MsgCenterSubscribeTopic(TOPIC_EVENT_ON_TIME); MsgCenterSubscribeTopic(TOPIC_EVENT_NEXTDAY_UPDATE); MsgCenterSubscribeTopic(TOPIC_EVENT_HFP_INCOMMING); MsgCenterSubscribeTopic(TOPIC_EVENT_HFP_PHONE_ACTIVE); @@ -244,6 +246,18 @@ void MsgCenterNotifyAlarmProc(const Topic topic, Request* req) AlarmPopUpPresenter::GetInstance()->DelayAlarmRing(); } } + + +void MsgCenterNotifyONtimeProc(const Topic topic, Request* req) +{ + unused(req); + // The alarm notification is not displayed if the incoming call notification is already being processed + // cywee_save_data(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "保存每小时步数"); + step_history_save(); +} + + #ifdef FD230 #ifdef SUPPORT_CHARGER_PLUG_DETECTION_NOTIFICATION /*充电器已插上*/ @@ -912,6 +926,7 @@ void MsgCenterNotifybleAPPtraining(const Topic topic, Request* req) /* 订阅事件通知逻辑可定制 */ static msg_center_notify_table_t g_msg_center_notify_table[] = { {TOPIC_EVENT_ALARM_RING, MsgCenterNotifyAlarmProc}, + {TOPIC_EVENT_ON_TIME, MsgCenterNotifyONtimeProc},//增加整点保存数据 {TOPIC_EVENT_NEXTDAY_UPDATE, MsgCenterNotifyNextDayProc}, {TOPIC_EVENT_HFP_INCOMMING, MsgCenterNotifyHfpIncomingProc}, {TOPIC_EVENT_HFP_PHONE_ACTIVE, MsgCenterNotifyHfpPhoneProc}, diff --git a/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h b/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h index 80e17978e..e55d199a6 100644 --- a/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h +++ b/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h @@ -19,6 +19,7 @@ extern "C" { #include "stdint.h" #include "errcode.h" + extern uint64_t CWM_OS_GetTimeNs(void); extern int CWM_OS_dbgOutput(const char * format); extern int CWM_OS_dbgPrintf(const char * format,...); @@ -31,6 +32,7 @@ extern int CWM_OS_i2cTransfer(uint16_t slaveAddr, uint16_t reg, int regLength, u extern void* CWM_OS_malloc(int size); extern void CWM_OS_free(void *ptr); extern void CWM_OS_saveData(int* data, uint32_t len); +extern void CWM_OS_saveData_history(int* new_data,int *history ,uint32_t len); extern void CWM_OS_restoreData(int* data, uint32_t len); /********************CYWEE LIB*************************/ @@ -504,6 +506,7 @@ void cywee_activity_mode_change(int mode); void cywee_hand_updown_switch(int cmd); void cywee_ar_alert_switch(int cmd); void cywee_save_data(void); +void step_history_save(void); extern uint8_t hrs_mode_state; #pragma pack() diff --git a/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c b/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c index 599bd1856..074456e21 100644 --- a/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c +++ b/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c @@ -278,6 +278,51 @@ void CWM_OS_saveData(int* data, uint32_t len){ } fclose(fp); } + + +#define CWM_HISTORY_DATA_PATH "/system/" + +void CWM_OS_saveData_history(int* new_data,int *history ,uint32_t len){ + char path_[64]={0}; + char timeday[12] = {0}; + uapi_get_YYMMDD_Time(timeday, '_'); + + sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_PATH,timeday); + CWM_OS_dbgPrintf(" save path %s \n",path_); + + FILE * fp = fopen(path_,"ab+"); + if(fp==NULL) + { + CWM_OS_dbgPrintf("open fail\n"); + return; + } + uint32_t creationTime; + int ret =uapi_get_timestampe_ss(&creationTime); + + CWM_OS_dbgPrintf("uapi_get_timestampe_ss %d\n",ret); + + ret =fwrite(&creationTime,1,len,fp); + if(ret==0) + { + CWM_OS_dbgPrintf("fwrite failed %d\n",ret); + } + + //新数据减去旧数据,作为这一个小时的步数值 + + int data= *new_data-*history; + ret =fwrite(&data,1,len,fp); + if(ret==0) + { + CWM_OS_dbgPrintf("fwrite failed %d\n",ret); + } + + *history=*new_data; + + fclose(fp); +} + + + void CWM_OS_restoreData(int* data, uint32_t len){ FILE * fp = fopen(CWM_DATA_PATH,"rb"); if(fp==NULL) diff --git a/code/sdk/drivers/peripheral/cywee/src/main_dml.c b/code/sdk/drivers/peripheral/cywee/src/main_dml.c index 8a75043a4..337b9cda3 100644 --- a/code/sdk/drivers/peripheral/cywee/src/main_dml.c +++ b/code/sdk/drivers/peripheral/cywee/src/main_dml.c @@ -44,9 +44,17 @@ uint8_t hrs_mode_state = 0; int history_step = 0; int stepcount = 0; +int history_step_=0;//存一个小时前的步数数据,每次保存步数时会更新改数据 + void cywee_save_data(void) { CWM_OS_saveData(&stepcount,sizeof(int)); + +} + +void step_history_save(void) +{ + CWM_OS_saveData_history(&stepcount,&history_step_,sizeof(int)); } void cywee_ar_alert_switch(int cmd) @@ -925,6 +933,7 @@ int cywee_main_dml(void) //CWM_Sensor_Enable(IDX_ALGO_ABSOLUTE_STATIC); //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); CWM_OS_restoreData(&history_step,sizeof(int)); + history_step_=history_step; cywee_activity_mode_change(SPORT_ACTIVE_MODE_NORMAL);