增加步数数据整点存储及协议数据发送
authorhcj_ <1224667075@qq.com>
Wed, 29 May 2024 16:07:30 +0000 (00:07 +0800)
committerhcj_ <1224667075@qq.com>
Wed, 29 May 2024 16:07:30 +0000 (00:07 +0800)
12 files changed:
code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp
code/sdk/application/wearable/fd230app/nativeui/phone/src/phoneaddressmodel.cpp
code/sdk/application/wearable/fd230app/nativeui/systemupdate/src/SystemUpdateView.cpp
code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp
code/sdk/application/wearable/service/ble_service/blemoder/bletest.h
code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c
code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h
code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c
code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp
code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h
code/sdk/drivers/peripheral/cywee/src/board_yh601s.c
code/sdk/drivers/peripheral/cywee/src/main_dml.c

index 2e55775..28adda2 100644 (file)
@@ -88,6 +88,15 @@ static void AlarmCallBackProcB(void)
     GraphicService::GetInstance()->PostGraphicEvent(SetZeroAlarm);\r
 }\r
 \r
+static void on_time_CallBackProc(void)\r
+{\r
+    AlarmClockEventData unuse;\r
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "on_time_CallBackProc");\r
+    GraphicService::GetInstance()->PostGraphicEvent(\r
+        std::bind(AlarmTimerEventPublish, TOPIC_EVENT_ON_TIME, unuse));\r
+}\r
+\r
+\r
 void AlarmScan(void *arg)\r
 {\r
     struct tm curTime;\r
@@ -114,6 +123,11 @@ void AlarmScan(void *arg)
             g_alarmCtrB.state = ALARM_STATUS_CREATED;\r
         }\r
     }\r
+    if(curTime.tm_min==0 && curTime.tm_sec==0)\r
+    {\r
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "time: %d : %d",curTime.tm_hour,curTime.tm_min);\r
+        on_time_CallBackProc();\r
+    }\r
 }\r
 \r
 static int32_t AlarmCreate(AlarmCtrl *alarmCtrl, AlarmCallBack callback)\r
index 67f0af0..47960cd 100644 (file)
@@ -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)
         {
index 0262dde..c3593a0 100644 (file)
@@ -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);
index a3b376c..aa82c75 100644 (file)
@@ -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;
 }
index 4a7dd36..c4b12c1 100644 (file)
@@ -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
 }
index 261157b..3205727 100644 (file)
@@ -279,6 +279,7 @@ static uint8_t get_crc_from_lrc(uint8_t lrcValue)
     return crcbuf;\r
 }\r
 \r
+#define USE_DEMO\r
 static bool Check_CRC(uint8_t *data,uint16_t len,uint8_t crcvalue)//计算20byte的的校验位\r
 {\r
        uint8_t crcbuf  = 0;\r
@@ -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)\r
                    return true;\r
         else\r
+        #ifndef USE_DEMO\r
             return false;\r
+        #else\r
+             return true;\r
+        #endif\r
     }\r
         \r
 }\r
@@ -4207,7 +4212,7 @@ uint32_t EACH_DATA_LEN=0;//每种数据类型的的长度
 \r
 \r
 \r
-void Read_file_buf_send_bin_Data(uint8_t num,uint16_t id,char *data_item)\r
+void Read_JSON_file_buf_send_bin_Data(uint8_t num,uint16_t id,char *data_item)\r
 {\r
     sendbigDataBufState = true;//分包同步数据不允许打断\r
     char *buf=NULL;\r
@@ -4358,6 +4363,83 @@ void Read_file_buf_send_bin_Data(uint8_t num,uint16_t id,char *data_item)
     \r
 }\r
 \r
+void Read_BIN_file_buf_send_bin_Data(uint32_t pack_size,uint16_t id)\r
+{\r
+    sendbigDataBufState = true;//分包同步数据不允许打断\r
+    char *buf=NULL;\r
+    const char *data=NULL;\r
+    uint8_t timeBit = 4;//默认是4个字节的时间戳\r
+    uint8_t dataBit = 1;//默认是1个字节的数据\r
+    switch (id)\r
+    {\r
+        case 0x43: //同步步数历史数据\r
+            data=ble_step_history(0);\r
+            dataBit = 4;//心率数据字节4个字节 uint32_t\r
+            break;\r
+        case 0x44://同步燃脂时间数据\r
+            data=NULL;\r
+            break;\r
+        case 0x45://同步站立历史数据\r
+            data=NULL;\r
+            break;\r
+        case 0x46://同步卡路里历史数据\r
+            data=NULL;   \r
+            break;\r
+        case 0x47://同步距离历史数据\r
+            data=NULL;    \r
+            break;\r
+        case 0x49://同步基础训练历史数据\r
+            data=NULL;   \r
+            break;\r
+        case 0x4b://睡眠历史数据\r
+            data=NULL;\r
+            break;\r
+    }\r
+\r
+    if(data==NULL)\r
+    {\r
+        send_big_data(1,NULL,0,0,1,1,id,1);\r
+        sendbigDataBufState = false;//分包同步数据不允许打断\r
+        return;\r
+    }\r
+    \r
+        uint32_t data_len = strlen(data);\r
+\r
+        uint32_t surplus_len=data_len;\r
+        uint32_t pack;\r
+        if(data_len%pack_size==0)\r
+        {\r
+            pack=data_len/pack_size;\r
+        }\r
+        else\r
+        {   \r
+            pack=data_len/pack_size+1;\r
+        }\r
+         //printf("%d %d %d %d\r\n",data_len,surplus_len,pack_id,pack);\r
+        uint32_t pack_id=1;\r
+        uint32_t offset=0;\r
+        while (surplus_len!=0)\r
+        {\r
+           if(surplus_len>=pack_size)\r
+           {\r
+                surplus_len=surplus_len-pack_size;\r
+                send_big_data(1,data+offset,pack_size,data_len,pack_id,pack,id,1);\r
+                offset+=pack_size;\r
+           }\r
+           else\r
+           {\r
+                \r
+                printf("%d %d %d %d\r\n",data_len,surplus_len,pack_id,pack);\r
+                send_big_data(1,data+offset,surplus_len,data_len,pack_id,pack,id,1);\r
+                break;\r
+           }\r
+           pack_id++;\r
+        }\r
+        free(data);\r
+        sendbigDataBufState = false;\r
+    \r
+}\r
+\r
 //手机app下发读设备数据指令\r
 void readDevDataBle(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,uint8_t crcvalue)\r
 {\r
@@ -4392,39 +4474,43 @@ void readDevDataBle(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,u
                     num=96;\r
                 }\r
                 printf("同步心率数据,每包最多:%d 条数据 data:%d\r\n",num,data[0]);\r
-                Read_file_buf_send_bin_Data(num,0x40,"heart_data_list");\r
+                Read_JSON_file_buf_send_bin_Data(num,0x40,"heart_data_list");\r
                 break;\r
             case 0x41://同步血氧历史数据\r
                 printf("同步血氧数据\r\n");\r
                 EACH_DATA_LEN = SPO2_DATA_LEN;\r
                 num=(ble_nus_max_data_len-18)/EACH_DATA_LEN;\r
-                Read_file_buf_send_bin_Data(num,0x41,"heart_data_list");\r
+                Read_JSON_file_buf_send_bin_Data(num,0x41,"heart_data_list");\r
                 break;\r
             case 0x43: //同步步数历史数据\r
-                EACH_DATA_LEN = STEP_DATA_LEN;\r
-                num=(ble_nus_max_data_len-18)/EACH_DATA_LEN;\r
-                 Read_file_buf_send_bin_Data(num,0x43,"heart_data_list");\r
+            \r
+                num=(ble_nus_max_data_len-18);\r
+                if(num>482)\r
+                {\r
+                    num=482;\r
+                }\r
+                 Read_BIN_file_buf_send_bin_Data(num,0x43);\r
 \r
                 break;\r
             case 0x44://同步燃脂时间数据\r
                 EACH_DATA_LEN = FATTIME_DATA_LEN;\r
                 num=(ble_nus_max_data_len-18)/EACH_DATA_LEN;\r
-                Read_file_buf_send_bin_Data(num,0x44,"heart_data_list");\r
+                Read_JSON_file_buf_send_bin_Data(num,0x44,"heart_data_list");\r
                 break;\r
             case 0x45://同步站立历史数据\r
                 EACH_DATA_LEN = STAND_DATA_LEN;\r
                 num=(ble_nus_max_data_len-18)/EACH_DATA_LEN;\r
-                 Read_file_buf_send_bin_Data(num,0x45,"heart_data_list");\r
+                 Read_JSON_file_buf_send_bin_Data(num,0x45,"heart_data_list");\r
                 break;\r
             case 0x46://同步卡路里历史数据\r
                 EACH_DATA_LEN = KCAL_DATA_LEN;\r
                 num=(ble_nus_max_data_len-18)/EACH_DATA_LEN;\r
-                Read_file_buf_send_bin_Data(num,0x46,"heart_data_list");\r
+                Read_JSON_file_buf_send_bin_Data(num,0x46,"heart_data_list");\r
                 break;\r
             case 0x47://同步距离历史数据\r
                 EACH_DATA_LEN = DIS_DATA_LEN;\r
                 num=(ble_nus_max_data_len-18)/EACH_DATA_LEN;\r
-                Read_file_buf_send_bin_Data(num,0x47,"heart_data_list");\r
+                Read_JSON_file_buf_send_bin_Data(num,0x47,"heart_data_list");\r
                 break;\r
             case 0x49://同步基础训练历史数据\r
                 EACH_DATA_LEN = DIS_DATA_LEN;\r
@@ -4447,7 +4533,7 @@ void readDevDataBle(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,u
             case 0x4b://睡眠历史数据\r
                 EACH_DATA_LEN = DIS_DATA_LEN;\r
                 num=(ble_nus_max_data_len-18)/EACH_DATA_LEN;\r
-                Read_file_buf_send_bin_Data(num,0x4b,"heart_data_list");\r
+                Read_JSON_file_buf_send_bin_Data(num,0x4b,"heart_data_list");\r
 \r
                 break;\r
             default:\r
index b1d6e56..a925ba5 100755 (executable)
@@ -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,
index db59f3d..4ad3055 100755 (executable)
@@ -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},
index 01bf004..8bd10ae 100644 (file)
@@ -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},
index 80e1797..e55d199 100644 (file)
@@ -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()
index 599bd18..074456e 100644 (file)
@@ -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)
index 8a75043..337b9cd 100644 (file)
@@ -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);