站立次数同步
authorhcj <1224667075@qq.com>
Tue, 11 Jun 2024 07:49:45 +0000 (15:49 +0800)
committerhcj <1224667075@qq.com>
Tue, 11 Jun 2024 07:49:45 +0000 (15:49 +0800)
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/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 8b6c4f1..54ee727 100644 (file)
@@ -100,8 +100,50 @@ char * ble_step_history(uint8_t day,uint16_t *len)
     }
     *len=size;
     return buf;
+}
+
+#define CWM_HISTORY_STAND_DATA_PATH "/user/userdata/stand_"
 
+char * ble_stand_history(uint8_t day,uint16_t *len)
+{
+    char path_[64]={0};
+    char timeday[12] = {0};
+    uapi_get_YYMMDD_Time(timeday, '_');
+    sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_STAND_DATA_PATH,timeday);
+   
+    FILE * fp = fopen(path_,"rb+");
+    if(fp==NULL)
+    {
+         printf("fopen fail\r\n");
+        return NULL;
+    }
+    uint32_t size;
+    if (fp != NULL)
+    {
+        fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾
+        size = ftell(fp);       // 获取当前文件指针位置,即文件大小
+        fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头
+    }
+    printf("size %d \r\n",size);
+
+    char * buf=(char *)malloc(size);
+    if(buf==NULL)
+    {
+        printf("malloc fail\r\n");
+        return buf;
+    }
+    uint32_t ret= fread(buf,1,size,fp);
+
+    printf("fread %d \r\n",ret);
+    for(int i=0;i<ret;i++)
+    {
+        printf(" %X",buf[i]);
+    }
+    *len=size;
+    return buf;
 }
+
+
 void ble_set_sleep_remind(msg_get_sleep_param_info_t data)
 {
     OHOS::ConfigModel *p_ConfigModel  =   OHOS::ConfigModel::GetInstance();
index fa8f953..bae8650 100644 (file)
@@ -196,6 +196,9 @@ void ble_set_sleep_remind(msg_get_sleep_param_info_t data);
 
 char * ble_step_history(uint8_t day,uint16_t *len);
 
+char * ble_stand_history(uint8_t day,uint16_t *len);
+
+
 void Set_DmpChangeMode(int state);
 int Get_DmpChangeMode(void);
 
index 2dbc96b..7d094c7 100644 (file)
@@ -4447,13 +4447,12 @@ void Read_BIN_file_buf_send_bin_Data(uint32_t pack_size,uint16_t id)
     {\r
         case 0x43: //同步步数历史数据\r
             data=ble_step_history(0,&data_len);\r
-            dataBit = 4;//心率数据字节4个字节 uint32_t\r
             break;\r
         case 0x44://同步燃脂时间数据\r
-            data=NULL;\r
+            data=ble_stand_history(0,&data_len);\r
             break;\r
         case 0x45://同步站立历史数据\r
-            data=NULL;\r
+            data=ble_stand_history(0,&data_len);\r
             break;\r
         case 0x46://同步卡路里历史数据\r
             data=NULL;   \r
@@ -4461,9 +4460,6 @@ void Read_BIN_file_buf_send_bin_Data(uint32_t pack_size,uint16_t id)
         case 0x47://同步距离历史数据\r
             data=NULL;    \r
             break;\r
-        case 0x49://同步基础训练历史数据\r
-            data=NULL;   \r
-            break;\r
         case 0x4b://睡眠历史数据\r
             data=NULL;\r
             break;\r
@@ -4571,9 +4567,14 @@ void readDevDataBle(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,u
                 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_JSON_file_buf_send_bin_Data(num,0x45,"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,0x45);\r
+\r
                 break;\r
             case 0x46://同步卡路里历史数据\r
                 EACH_DATA_LEN = KCAL_DATA_LEN;\r
index d4830a4..3c4d271 100644 (file)
@@ -272,6 +272,8 @@ void MsgCenterNotifyONtimeProc(const Topic topic, Request* req)
    // cywee_save_data();
     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "保存每小时步数");
    step_history_save();
+   WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "保存每小时站立数据");
+   stand_history_save();
 }
 
 
@@ -912,9 +914,16 @@ void MsgCenterNotifyInactivityProc(const Topic topic, Request *req)
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "memcpy_s cywee_inactivity_result_t failed, ret = %d", rets);
         return;
     }
-    
+      
+            
     WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "cywee_Inactivity_Info->sedentary_status = %d, stand_freq = %d", cywee_Inactivity_Info->sedentary_status, cywee_Inactivity_Info->stand_freq);
     WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "cywee_Inactivity_Info->output_number = %d", cywee_Inactivity_Info->output_number);
+    if(cywee_Inactivity_Info->sedentary_status==9)
+    {
+        set_stand_falg();
+    }
+
+                
     
     static int interval = 0;//久坐间隔时间
     switch (cywee_Inactivity_Info->output_number)
index ab35997..2eaf1dd 100644 (file)
@@ -33,6 +33,7 @@ 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_saveData_STAND_history(uint8_t *falg,uint32_t len);
 extern void CWM_OS_restoreData(int* data, uint32_t len);
 
 /********************CYWEE LIB*************************/
@@ -507,6 +508,8 @@ void cywee_time_sync(void);
 void cywee_hand_updown_switch(int cmd);
 void cywee_ar_alert_switch(int cmd);
 void step_history_save(void);
+void stand_history_save(void);
+void set_stand_falg(void);
 void cywee_get_chipinfo(char *databuf,uint8_t len);
 void cywee_get_acc_switch(uint8_t cmd);
 void cywee_set_sedentary_interval(int time);
index df7fe1b..cda4297 100644 (file)
@@ -332,32 +332,48 @@ void CWM_OS_saveData_history(int* new_data,int *history ,uint32_t len){
 }
 #define CWM_HISTORY_STAND_DATA_PATH "/user/userdata/stand_"
 
-void CWM_OS_saveData_STAND_history(int *time ,uint32_t len){
-    char path_[64]={0};
-    char timeday[12] = {0};
-    uapi_get_YYMMDD_Time(timeday, '_');
+void CWM_OS_saveData_STAND_history(uint8_t *falg,uint32_t len){
+    if(*falg)
+    {
+        char path_[64]={0};
+        char timeday[12] = {0};
+        uapi_get_YYMMDD_Time(timeday, '_');
+
+        sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_STAND_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);
+
+        creationTime=creationTime-60*60;
+        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);
+        }
 
-    sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_STAND_DATA_PATH,timeday);
-    CWM_OS_dbgPrintf(" save path %s \n",path_);
+         fclose(fp);
 
-    FILE * fp = fopen(path_,"ab+");
-    if(fp==NULL)
-    {
-        CWM_OS_dbgPrintf("open fail\n");
-        return;
+        *falg=0;
     }
- 
-    int ret =fwrite(time,1,len,fp);
-    if(ret==0)
+    else
     {
-        CWM_OS_dbgPrintf("fwrite failed %d\n",ret);
+        return;
     }
-    //CWM_OS_dbgPrintf("fwrite data %d\n",data);
-
-    *time=0;
 
-    fclose(fp);
 }
+   
+    //CWM_OS_dbgPrintf("fwrite data %d\n",data);
+
+   
 
 
 
index f6b61b2..17ac1f2 100644 (file)
@@ -46,6 +46,8 @@ static int stepcount = 0;
 
 int history_step_=0;//存一个小时前的步数数据,每次保存步数时会更新改数据
 
+uint8_t stand_falg=0;//站立falg,如果发生站立,一个小时内会被置1;
+
 static char chipInfo[64] = {0};
 
 static int get_acc_swtich = 0;
@@ -82,6 +84,16 @@ void step_history_save(void)
     CWM_OS_saveData_history(&stepcount,&history_step_,sizeof(int));
 }
 
+void set_stand_falg(void)
+{
+    stand_falg=1;
+}
+void stand_history_save(void)
+{
+    CWM_OS_saveData_STAND_history(&stand_falg,sizeof(int));
+}
+
+
 void cywee_ar_alert_switch(int cmd)
 {
     memset(&scl, 0, sizeof(scl));