Merge #1777 into sdk650pathc0423 from refs/changes/1777/head 1780/target/1
author彭磊 <1624952103@qq.com>
Thu, 22 May 2025 02:00:35 +0000 (02:00 +0000)
committer袁清梦 <3449750381@qq.com>
Thu, 22 May 2025 02:00:35 +0000 (02:00 +0000)
Code review from 彭磊

* refs/changes/1777/head: (2 commits squashed)

  - 分离dml数据存储,添加表冠、马达功能

  - Merge branch &#39;sdk650pathc0423&#39; of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk650pathc0423

Signed-off-by: aliyun6865282430 <1624952103@qq.com>
Merged-by: Caisking <3449750381@qq.com>
link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/1777
24 files changed:
code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/src/goalmodel.cpp
code/sdk/build/config/target_config/brandy/config.py
code/sdk/middleware/services/gui/hal/input/src/input_manager.c
code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dock/lite_encoder_device.cpp [new file with mode: 0644]
code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dock/lite_encoder_device.h [new file with mode: 0644]
code/sdk/middleware/services/gui/uikit/proprietary/src/utils/frameworks/hals/lite_input_distributer.cpp
code/sdk/middleware/services/gui/uikit/proprietary/src/utils/frameworks/hals/lite_input_hal.cpp
code/sdk/middleware/services/gui/uikit/proprietary/src/utils/innerkits/hals/lite_input_distributer.h
code/sdk/middleware/services/gui/uikit/ui/frameworks/dock/rotate_input_device.cpp
code/sdk/zhihui/drivers/cywee/CMakeLists.txt
code/sdk/zhihui/drivers/cywee/ble_service/cywee_ble_service.c
code/sdk/zhihui/drivers/cywee/data/CMakeLists.txt [new file with mode: 0644]
code/sdk/zhihui/drivers/cywee/data/cywee_data.c [new file with mode: 0644]
code/sdk/zhihui/drivers/cywee/data/cywee_data.h [new file with mode: 0644]
code/sdk/zhihui/drivers/cywee/dml/cywee_dml.h
code/sdk/zhihui/drivers/cywee/dml/main_dml.c
code/sdk/zhihui/drivers/cywee/hal/cywee_hal.c
code/sdk/zhihui/drivers/cywee/hal/cywee_hal.h
code/sdk/zhihui/drivers/cywee/service/cywee_service.c
code/sdk/zhihui/services/ble_service/blemoder/bleInstruct.cpp
code/sdk/zhihui/services/ble_service/blemoder/bleinstruct_sample.cpp
code/sdk/zhihui/utils/custom_fileoperate_service.c
code/sdk/zhihui/utils/custom_utils.c
code/sdk/zhihui/utils/custom_utils.h

index 8f0bc41..91fc92c 100644 (file)
@@ -43,7 +43,9 @@ namespace OHOS
       // calories_goal=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_CALORIES);
       // stand_goal=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_STANDUP_TIMES);
 
+#ifdef SUPPORT_CYWEE_SERVICE
       // standdata_now=cywee_get_now_stand_count();
+#endif
 
       // show_step=goal_parse_step_data();
       // show_calories=goal_parse_calories_data();
@@ -524,7 +526,7 @@ namespace OHOS
       // uint32_t toal_date;
       
       // toal_date=show_step;
-      // cywee_get_now_hour_data(&value,CYWEE_SAVE_DATA_STEP);
+      // cywee_get_now_hour_data(&value,STEP);
       // if(value>0)
       // toal_date+=value;
       // return toal_date;
@@ -537,7 +539,7 @@ namespace OHOS
       // float   _f_value=0;
       // float   toal_date;
       // toal_date=show_calories;
-      // cywee_get_now_hour_data(&_f_value,CYWEE_SAVE_DATA_CALORIES);
+      // cywee_get_now_hour_data(&_f_value,CALORIES);
       // if(_f_value>0)
       // toal_date+=_f_value;
    
@@ -551,7 +553,7 @@ namespace OHOS
       // float   _f_value=0;
       // float   toal_date;
       // toal_date=show_distance;
-      // cywee_get_now_hour_data(&_f_value,CYWEE_SAVE_DATA_DISTANCE);
+      // cywee_get_now_hour_data(&_f_value,DISTANCE);
       // if(_f_value>0)
       // toal_date+=_f_value;
    
@@ -566,7 +568,7 @@ namespace OHOS
       // uint16_t   _16_value=0;
       // uint32_t   toal_date;
       // toal_date=show_fat;
-      // cywee_get_now_hour_data(&_16_value,CYWEE_SAVE_DATA_FAT);
+      // cywee_get_now_hour_data(&_16_value,FAT);
       // if(_16_value>0)
       // toal_date+=_16_value;
    
index 90bfe50..88d33de 100644 (file)
@@ -412,6 +412,7 @@ target = {
                             "cywee_dml",
                             "cywee_hal",
                             #"cyweeBleService",
+                            "cywee_data",
                            ],
                'image_analysis': False,
                'fs_image_path':'fd230',
@@ -463,7 +464,7 @@ target = {
         # 'ACC_LIS2DOC',
         # 'ENABLE_CUSTOM_I2C',
         # 'MAG_MMC5603',
-        # 'ENABLE_VIBRATOR',
+        'ENABLE_VIBRATOR',
         # 'ENABLE_SLIP',
         'ENCODER_SUPPORT',
         # 'SUPPORT_SPO2_NOTIFICATION',
index 8e8e6f6..2d1bd61 100644 (file)
@@ -60,6 +60,24 @@ __attribute__((weak)) uint32_t button_close(void)
     return INPUT_FAILURE;
 }
 
+__attribute__((weak)) uint32_t re_register_report_event_cb(report_event_cb callback)
+{
+    (void)(callback);
+    return INPUT_FAILURE;
+}
+__attribute__((weak)) uint32_t re_unregister_report_event_cb(void)
+{
+    return INPUT_FAILURE;
+}
+__attribute__((weak)) uint32_t re_init(void)
+{
+    return INPUT_FAILURE;
+}
+__attribute__((weak)) uint32_t re_close(void)
+{
+    return INPUT_FAILURE;
+}
+
 static void InitInputDevices(void)
 {
     for (uint8_t i = 0; i < INDEV_TYPE_UNKNOWN; i++) {
@@ -67,6 +85,13 @@ static void InitInputDevices(void)
         g_inputDevs[i].initState = INDEV_UNINITIALIZED;
     }
 
+    /* Init Encoder Device */
+    g_inputDevs[INDEV_TYPE_ENCODER].type = INDEV_TYPE_ENCODER;
+    g_inputDevs[INDEV_TYPE_ENCODER].funcs.Init = re_init;
+    g_inputDevs[INDEV_TYPE_ENCODER].funcs.Close = re_close;
+    g_inputDevs[INDEV_TYPE_ENCODER].funcs.RegisterReportEventCb = re_register_report_event_cb;
+    g_inputDevs[INDEV_TYPE_ENCODER].funcs.UnregisterReportEventCb = re_unregister_report_event_cb;
+
     /* Init Touch Device */
     g_inputDevs[INDEV_TYPE_TOUCH].type = INDEV_TYPE_TOUCH;
     g_inputDevs[INDEV_TYPE_TOUCH].funcs.Init = ts_init;
diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dock/lite_encoder_device.cpp b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dock/lite_encoder_device.cpp
new file mode 100644 (file)
index 0000000..fbeb94b
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * @Author: penglei 1624952103@qq.com
+ * @Date: 2025-05-20 18:18:09
+ * @LastEditors: penglei 1624952103@qq.com
+ * @LastEditTime: 2025-05-20 18:18:14
+ * @FilePath: /FD230/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dock/lite_encoder_device.cpp
+ * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
+ */
+/*
+ * Copyright (c) 2022 CompanyNameMagicTag.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "lite_encoder_device.h"
+#include "gfx_utils/input_event_info.h"
+#include "lite_input_distributer.h"
+
+namespace OHOS {
+bool LiteEncoderDevice::Read(DeviceData& data)
+{
+    (void)LiteInputDistributer::GetInstance()->GetEventData(data, InputDevType::INDEV_TYPE_ENCODER);
+    return false;
+}
+
+bool LiteEncoderDevice::IsEventEmpty()
+{
+    return LiteInputDistributer::GetInstance()->IsEventEmpty(InputDevType::INDEV_TYPE_ENCODER);
+}
+}
diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dock/lite_encoder_device.h b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dock/lite_encoder_device.h
new file mode 100644 (file)
index 0000000..9d177ca
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * @Author: penglei 1624952103@qq.com
+ * @Date: 2025-05-20 18:17:49
+ * @LastEditors: penglei 1624952103@qq.com
+ * @LastEditTime: 2025-05-20 18:17:55
+ * @FilePath: /FD230/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dock/lite_encoder_device.h
+ * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
+ */
+/*
+ * Copyright (c) 2022 CompanyNameMagicTag.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef GRAPHIC_LITE_LITE_ENCODER_DEVICE_H
+#define GRAPHIC_LITE_LITE_ENCODER_DEVICE_H
+#include "dock/rotate_input_device.h"
+
+namespace OHOS {
+class LiteEncoderDevice : public RotateInputDevice {
+public:
+    LiteEncoderDevice() {}
+    ~LiteEncoderDevice() override {}
+    bool Read(DeviceData& data) override;
+    bool IsEventEmpty() override;
+};
+}
+#endif
index 7cf4a51..2ed0314 100644 (file)
@@ -57,7 +57,20 @@ void LiteInputDistributer::SendRawEvent(const RawEvent& rawEvent)
 void LiteInputDistributer::GetEventData(DeviceData& data, InputDevType type)
 {
     eventLock_.Lock();
-    if (type == InputDevType::INDEV_TYPE_TOUCH) {
+    
+    if (type == InputDevType::INDEV_TYPE_ENCODER) {
+         if (encoderDataList_.empty()) {
+            data.rotate = 0;
+            eventLock_.Unlock();
+            return;
+        }
+        DeviceData tmp = encoderDataList_.front();
+        encoderDataList_.pop_front();
+        data.rotate = tmp.rotate;
+        data.state = tmp.state;
+        data.timestamp = tmp.timestamp;
+
+    }else if (type == InputDevType::INDEV_TYPE_TOUCH) {
         if (IsShowPoint() && (deviceData_.timestamp != g_lastData.timestamp)) {
             DfxTPGetEvent();
         }
@@ -111,8 +124,20 @@ void LiteInputDistributer::SetEventData(const RawEvent& event)
         tpList_.push_back(deviceData_);
         eventLock_.Unlock();
         return;
-    }
-    if (event.type == InputDevType::INDEV_TYPE_KEY) {
+    }else if (event.type == InputDevType::INDEV_TYPE_ENCODER) {
+        // if (IsShowPoint()) {
+        //     DfxTPSetEvent(event.timestamp - encoderDataList_.timestamp);
+        // }
+        DeviceData data;
+        data.rotate = event.rotate;
+        data.state = event.state;
+        data.timestamp = event.timestamp;
+        if (encoderDataList_.size() >= MAX_ENCODER_DATA_LIST_SIZE) {
+            encoderDataList_.pop_front();
+        }
+        encoderDataList_.push_back(data);
+
+    }else if (event.type == InputDevType::INDEV_TYPE_KEY) {
         DeviceData data;
         data.keyId = event.keyId;
         data.state = event.state;
@@ -131,6 +156,8 @@ bool LiteInputDistributer::IsEventEmpty(InputDevType type)
         return ((g_lastData.state == 0) && (deviceData_.state == 0) && (tpList_.empty()));
     } else if (type == InputDevType::INDEV_TYPE_KEY) {
         return keyList_.empty();
+    } else if (type == InputDevType::INDEV_TYPE_ENCODER){
+        return encoderDataList_.empty();
     }
     return true;
 }
@@ -143,7 +170,10 @@ void LiteInputDistributer::ClearEvent(InputDevType type)
         deviceData_.state = 0;
     } else if (type == InputDevType::INDEV_TYPE_KEY) {
         keyList_.clear();
-    }
+    } else if (type == InputDevType::INDEV_TYPE_ENCODER)
+       {
+               encoderDataList_.clear();
+       }
     eventLock_.Unlock();
 }
 
index 62983fa..08ef0ca 100644 (file)
@@ -20,6 +20,7 @@
 #include "hals/lite_input_distributer.h"\r
 #include "dock/lite_key_device.h"\r
 #include "dock/lite_touch_device.h"\r
+#include "dock/lite_encoder_device.h"\r
 #include "dfx/dfx_record.h"\r
 \r
 namespace OHOS {\r
@@ -52,6 +53,14 @@ static void EventCallback(InputDevData* data)
         event.state = data->state;\r
         event.timestamp = data->timestamp;\r
         event.type = InputDevType::INDEV_TYPE_TOUCH;\r
+    } else if (data->type == INDEV_TYPE_ENCODER) {\r
+         if (IsShowTPRaw()) {\r
+            GRAPHIC_LOGP("Encoder s: %u, rotate: %d, t: %u", data->state,data->rotate, data->timestamp);\r
+        }\r
+        event.rotate = data->rotate;\r
+        event.state = data->state;\r
+        event.timestamp = data->timestamp;\r
+        event.type = InputDevType::INDEV_TYPE_ENCODER;\r
     } else if (data->type == INDEV_TYPE_KEY) {\r
         if (!ConvertKeyId(data->keyId, &event.keyId)) {\r
             return;\r
@@ -68,7 +77,9 @@ static void EventCallback(InputDevData* data)
 void LiteInputHal::AddToIndevManager(uint8_t type)\r
 {\r
     InputDevice* dev = nullptr;\r
-    if (type == static_cast<uint8_t>(INDEV_TYPE_TOUCH)) {\r
+    if (type == static_cast<uint8_t>(INDEV_TYPE_ENCODER)) {\r
+        dev = new LiteEncoderDevice();\r
+    } else if (type == static_cast<uint8_t>(INDEV_TYPE_TOUCH)) {\r
         dev = new LiteTouchDevice();\r
     } else if (type == static_cast<uint8_t>(INDEV_TYPE_KEY)) {\r
         dev = new LiteKeyDevice();\r
index d7d5bdc..9af3f8b 100644 (file)
@@ -1,3 +1,11 @@
+/*
+ * @Author: penglei 1624952103@qq.com
+ * @Date: 2025-05-15 11:27:18
+ * @LastEditors: penglei 1624952103@qq.com
+ * @LastEditTime: 2025-05-20 18:25:41
+ * @FilePath: /FD230/code/sdk/middleware/services/gui/uikit/proprietary/src/utils/innerkits/hals/lite_input_distributer.h
+ * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
+ */
 /*
  * Copyright (c) 2022 CompanyNameMagicTag.
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,6 +34,7 @@ namespace OHOS {
 const uint16_t INVALID_KEY_ID = 0xffff;
 const uint8_t MAX_KEY_LIST_SIZE = 60;
 const uint8_t MAX_TP_LIST_SIZE = 3;
+const uint8_t MAX_ENCODER_DATA_LIST_SIZE = 2;
 class LiteInputDistributer : public HeapBase {
 public:
     static LiteInputDistributer* GetInstance()
@@ -48,6 +57,7 @@ private:
 
     GraphicMutex eventLock_;
     DeviceData deviceData_;
+    std::list<DeviceData> encoderDataList_;
     std::list<DeviceData> keyList_;
     std::list<DeviceData> tpList_;
 };
index 69bbcfe..defc9b8 100644 (file)
@@ -36,16 +36,59 @@ RotateInputDevice::RotateInputDevice() : rotateStart_(false), threshold_(ROTATE_
 void RotateInputDevice::DispatchEvent(const DeviceData &data)
 {
     bool cachedToRotate = false;
-    if (data.rotate == 0 || rotateStart_) {
+    // INDEV_STATE_PRESS == 1   转动
+    // INDEV_STATE_RELEASE == 0  静止
+ 
+    static DeviceData lastdevdata={0xFF};
+    static int has_report_still = 0;
+    #define BUF_COUNT 5
+    // printf(" %s  rotate = %d , state %d\n",__func__,data.rotate,data.state);
+    static int16_t zero_count = 0;
+    // if(data.rotate == 0 && data.state == 0)
+
+    if(data.rotate == 0 )
+    {
+        //转动0,data.state 0静止,代表停止转动
+        // if (lastdevdata.state == 0 && lastdevdata.rotate == 0)
+        if (lastdevdata.state == 0 )
+            zero_count++;
+
+        if (zero_count >= BUF_COUNT)
+        {
+            //连续BUF_COUNT个0 ,buf已满无需再次添加
+            zero_count = BUF_COUNT; //防止int16_t 溢出
+            //TODO: 只上报一次 has_report_still
+            if(has_report_still == 0)
+            {
+                has_report_still = 1;
+            }else{
+                //report过就不再report
+                return ;
+            }
+        }else
+        {
+            //少于BUF_COUNT个0 不上报,但要继续在缓存添加数据,否则计数不会变化
+            lastdevdata = data;
+            return ;
+        }
+    }else{
+        //只要有一次非still,则重新计量是否需要report
+        zero_count = 0;
+        has_report_still = 0;
+        lastdevdata = data;
+    }
+
+    if (data.rotate == 0 || rotateStart_) { //如果旋转0,或者已经开始,则清空cache 重新计数
         cachedRotation_ = 0;
-    } else {
+    } else { //否则缓存旋转角度
         cachedRotation_ += data.rotate;
-        if (MATH_ABS(cachedRotation_) >= threshold_) {
-            cachedToRotate = true;
+        if (MATH_ABS(cachedRotation_) >= threshold_) {  
+            cachedToRotate = true; //缓存角度大于阈值则开始转动
         }
     }
 
     if (!cachedToRotate && !rotateStart_) {
+        //没达到缓存标准的,不做动作,继续缓存。
         return;
     }
 
@@ -71,9 +114,12 @@ void RotateInputDevice::DispatchEvent(const DeviceData &data)
         }
     }
     if (MATH_ABS(data.rotate) < threshold_ && !rotateStart_ && !cachedToRotate) {
+        //当前值没达到阈值,且没开始旋转,也没有缓存达到旋转标准,则不做动作。
+        //按理这一步走不到。前面已经做了条件限制。
         return;
     }
     if (data.rotate == 0 && rotateStart_) {
+        //已经开始转动,但是当前值为零,认为停止转动。
         if (view != nullptr) {
             view->OnRotateEndEvent(0);
         }
@@ -81,6 +127,7 @@ void RotateInputDevice::DispatchEvent(const DeviceData &data)
         return;
     }
     if (!rotateStart_) {
+        //缓存可以转动,且之前没有开始转动,会走到这里,执行开始转动消息。
         if (view != nullptr) {
             view->OnRotateStartEvent(data.rotate);
         }
index 034aad2..863d012 100644 (file)
@@ -1,4 +1,5 @@
 add_subdirectory_if_exist(service)
 add_subdirectory_if_exist(hal)
 add_subdirectory_if_exist(dml)
+add_subdirectory_if_exist(data)
 add_subdirectory_if_exist(ble_service)
\ No newline at end of file
index f4569b9..f14fb16 100644 (file)
@@ -163,429 +163,6 @@ void cywee_recv_cmd_data(uint8_t *buf, uint16_t event_size,uint16_t handle)
     if(buf != NULL)
         printf("cywee_recv_cmd_data len %d , handle 0x%X ,*buf 0x%02X\r\n",event_size,handle,*buf);
     /****此处为接收指令,处理后反馈结果的参考**/
-    // cywee_log_switch(*buf);
+    // cywee_set_log_switch(*buf);
     /*****参考结束****/
 }
-
-
-void CWM_OS_saveData_history(void* new_data,void *history ,uint32_t len,uint8_t type,uint32_t time)
-{
-#ifdef SUPPORT_CYWEE_BLE_SERVICE
-    struct stat info;
-
-    if (stat(GOAL_DATA_CONFIG_DIR, &info) != 0)
-    {
-        if (mkdir(GOAL_DATA_CONFIG_DIR, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
-        {
-            return ; // Failed to create folder
-        }
-    }
-
-    if (stat(GOAL_DATA_CONFIG_DIR_STEP, &info) != 0)
-    {
-        if (mkdir(GOAL_DATA_CONFIG_DIR_STEP, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
-        {
-            return ; // Failed to create folder
-        }
-    }
-
-    if (stat(GOAL_DATA_CONFIG_DIR_DISTANCE, &info) != 0)
-    {
-        if (mkdir(GOAL_DATA_CONFIG_DIR_DISTANCE, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
-        {
-            return ; // Failed to create folder
-        }
-    }
-
-    if (stat(GOAL_DATA_CONFIG_DIR_STAND, &info) != 0)
-    {
-        if (mkdir(GOAL_DATA_CONFIG_DIR_STAND, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
-        {
-            return ; // Failed to create folder
-        }
-    }
-
-    if (stat(GOAL_DATA_CONFIG_DIR_FAT, &info) != 0)
-    {
-        if (mkdir(GOAL_DATA_CONFIG_DIR_FAT, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
-        {
-            return ; // Failed to create folder
-        }
-    }
-
-    if (stat(GOAL_DATA_CONFIG_DIR_CALORIES, &info) != 0)
-    {
-        if (mkdir(GOAL_DATA_CONFIG_DIR_CALORIES, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
-        {
-            return ; // Failed to create folder
-        }
-    }
-
-
-
-    char path_[64]={0};
-    char timeday[12] = {0};
-    uapi_get_TIME_STR(time,timeday, '_','\0',DATE_Y_M_D);
-
-    int i_data=0;
-    float f_data=0;
-    int16_t i_data_16=0;
-
-    switch (type)
-    {
-    case CYWEE_DATA_CALORIES:
-        sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_CALORIES_PATH,timeday);
-
-        f_data=*(float*)new_data-*(float*)history;
-
-        break;
-    case CYWEE_DATA_STEP:
-       sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_PATH,timeday);
-
-        i_data= *(int*)new_data-*(int*)history;//新数据减去旧数据,作为这一个小时的值
-        // {   
-        //     FILE *fp= fopen("/user/userdata/i_data_test.txt","ab+");
-        //     fwrite("x",1,1,fp);
-        //     fclose(fp);
-        // }
-       
-
-        break;
-    case CYWEE_DATA_DISTANCE:
-       sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_DISTANCE_PATH,timeday);
-       f_data=*(float*)new_data-*(float*)history;
-
-        break;
-    case CYWEE_DATA_FAT:
-       sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_FAT_PATH,timeday);
-        i_data_16= *(int16_t*)new_data-*(int16_t*)history;//新数据减去旧数据,作为这一个小时的值
-        
-        break;
-
-    default:
-        break;
-    }
-   
-    CWM_OS_dbgPrintf(" save path %s \n",path_);
-
-    if(i_data<0 || f_data<0 ||i_data_16<0)
-    {
-        i_data=0;
-        f_data=0;
-        *(int*)history=0;
-        return;
-    }
-
-    if(type==CYWEE_DATA_STEP && i_data!=0)
-    {
-        #ifdef GOAL_DATA_AMEND
-        time_and_32_date_t array[25]={0};
-
-        for(int i=0;i<25;i++)
-        {
-            array[i].data=0;
-            array[i].time=0;
-        }
-       
-
-        if(time_is_repetition(time,&i_data,path_,array,0))
-        {
-
-
-            FILE * fp = fopen(path_,"wb+");
-            if(fp==NULL)
-            {
-                CWM_OS_dbgPrintf("open fail\n");
-                return;
-            }
-
-            for(int i=0;i<25;i++)
-            {
-                if(array[i].time && array[i].data)
-                {
-                    fwrite(&array[i].time,sizeof(array[i].time),1,fp);
-                    fwrite(&array[i].data,sizeof(array[i].data),1,fp);
-                }
-
-            }
-            fclose(fp);
-
-        }
-        else
-        #endif
-        {
-       
-            FILE * fp = fopen(path_,"ab+");
-            if(fp)
-            {
-                uint32_t creationTime;
-                creationTime=time;//当前值计入上小时
-
-                int ret =fwrite(&creationTime,1,4,fp);
-                if(ret==0)
-                {
-                    CWM_OS_dbgPrintf("fwrite failed %d\n",ret);
-                }
-                if(i_data)
-                ret =fwrite(&i_data,1,sizeof(i_data),fp);
-                fclose(fp);
-            }
-            else
-            {
-                msleep(5);
-                FILE * fp = fopen(path_,"ab+");
-                uint32_t creationTime;
-                creationTime=time;//当前值计入上小时
-
-                int ret =fwrite(&creationTime,1,4,fp);
-                if(ret==0)
-                {
-                    CWM_OS_dbgPrintf("fwrite failed %d\n",ret);
-                }
-                if(i_data)
-                ret =fwrite(&i_data,1,sizeof(i_data),fp);
-                fclose(fp);
-            }
-
-            
-
-     
-        }
-
-    }
-    if((type==CYWEE_DATA_CALORIES|| type==CYWEE_DATA_DISTANCE) && f_data!=0)
-    {
-
-        #ifdef GOAL_DATA_AMEND
-         time_and_float_date_t array[25]={0};
-
-        for(int i=0;i<25;i++)
-        {
-            array[i].data=0;
-            array[i].time=0;
-        }
-       
-        if(time_is_repetition(time,&i_data,path_,array,1))
-        {
-
-            FILE * fp = fopen(path_,"wb+");
-            if(fp==NULL)
-            {
-                CWM_OS_dbgPrintf("open fail\n");
-                return;
-            }
-
-            for(int i=0;i<25;i++)
-            {
-                if(array[i].time && array[i].data)
-                {
-                    fwrite(&array[i].time,sizeof(array[i].time),1,fp);
-                    fwrite(&array[i].data,sizeof(array[i].data),1,fp);
-                }
-
-            }
-            fclose(fp);
-
-        }
-        else
-        #endif
-        {
-        
-            FILE * fp = fopen(path_,"ab+");
-            if(fp)
-            {
-                uint32_t creationTime;
-                creationTime=time;//当前值计入上小时
-
-                int ret =fwrite(&creationTime,1,4,fp);
-                if(ret==0)
-                {
-                    CWM_OS_dbgPrintf("fwrite failed %d\n",ret);
-                }
-                if(f_data)
-                ret =fwrite(&f_data,1,sizeof(f_data),fp);
-
-                fclose(fp);
-
-            }        
-        }
-    }
-
-    if((type==CYWEE_DATA_FAT) && i_data_16!=0)
-    {
-
-        #ifdef GOAL_DATA_AMEND
-         time_and_16_date_t array[25]={0};
-
-        for(int i=0;i<25;i++)
-        {
-            array[i].data=0;
-            array[i].time=0;
-        }
-       
-        if(time_is_repetition(time,&i_data,path_,array,2))
-        {
-
-            FILE * fp = fopen(path_,"wb+");
-            if(fp==NULL)
-            {
-                CWM_OS_dbgPrintf("open fail\n");
-                return;
-            }
-
-            for(int i=0;i<25;i++)
-            {
-                if(array[i].time && array[i].data)
-                {
-                    fwrite(&array[i].time,sizeof(array[i].time),1,fp);
-                    fwrite(&array[i].data,sizeof(array[i].data),1,fp);
-                }
-
-            }
-            fclose(fp);
-
-        }
-        else
-        #endif
-
-        {
-            FILE * fp = fopen(path_,"ab+");
-            if(fp)
-            {
-                uint32_t creationTime;
-                creationTime=time;//当前值计入上小时
-
-                int ret =fwrite(&creationTime,1,4,fp);
-                if(ret==0)
-                {
-                    CWM_OS_dbgPrintf("fwrite failed %d\n",ret);
-                }
-                if(i_data_16)
-                ret =fwrite(&i_data_16,1,sizeof(i_data_16),fp);
-
-                fclose(fp);
-
-            }        
-        }
-    }
-    
-
-     if(i_data)
-    *(int*)history=*(int*)new_data;
-     else if(i_data_16)
-    *(int16_t*)history=*(int16_t*)new_data;
-    else if(f_data)
-    *(float*)history=*(float*)new_data;
-#endif
-   
-}
-
-void CWM_OS_saveData_STAND_history(uint8_t *falg,uint32_t len,uint32_t time)
-{
-#ifdef SUPPORT_CYWEE_BLE_SERVICE
-    if(*falg)
-    {
-        struct stat info;
-
-        if (stat(GOAL_DATA_CONFIG_DIR, &info) != 0)
-        {
-            if (mkdir(GOAL_DATA_CONFIG_DIR, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
-            {
-                return ; // Failed to create folder
-            }
-        }
-        
-        if (stat(GOAL_DATA_CONFIG_DIR_STAND, &info) != 0)
-        {
-            if (mkdir(GOAL_DATA_CONFIG_DIR_STAND, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
-            {
-                return ; // Failed to create folder
-            }
-        }
-
-        char path_[64]={0};
-        char timeday[12] = {0};
-        uapi_get_TIME_STR(time,timeday, '_','\0',DATE_Y_M_D);
-
-
-        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 ret;
-
-        uint32_t creationTime;
-        creationTime=time;//当前值计入上小时
-
-        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);
-        }
-
-         fclose(fp);
-
-        *falg=0;
-    }
-    else
-    {
-        return;
-    }
-#endif
-}
-  // calories 数据存储
-
-uint8_t get_stand_count(void)
-{
-    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_,"rb+");
-    if(fp==NULL)
-    {
-        CWM_OS_dbgPrintf("open fail\n");
-        return 0;
-    }
-    fseek(fp, 0, SEEK_END);
-    uint8_t size = ftell(fp);
-    fseek(fp, 0, SEEK_SET);
-
-    uint32_t array[25]={0};
-    uint8_t read_size=0;
-    fread(array,sizeof(uint32_t),size/4,fp);
-    uint8_t is_repetition=0;
-    for(int x=0;x<size/4;x++)
-    {
-        if(array[x])
-        {
-            for(int y=0;y<size/4;y++)
-            {
-                if(array[y]==array[x] && y!=x)
-                {
-                   is_repetition++;
-                }
-            }
-        }
-       
-    }
-    
-    
-
-    fclose(fp);
-    return size/4-is_repetition;
-
-}
-
-
diff --git a/code/sdk/zhihui/drivers/cywee/data/CMakeLists.txt b/code/sdk/zhihui/drivers/cywee/data/CMakeLists.txt
new file mode 100644 (file)
index 0000000..0d9621e
--- /dev/null
@@ -0,0 +1,37 @@
+#===============================================================================
+# @brief    cmake file
+# Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved.
+#===============================================================================
+
+set(COMPONENT_NAME "cywee_data")
+
+set(PUBLIC_HEADER
+${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+set(SOURCES
+${CMAKE_CURRENT_SOURCE_DIR}/cywee_data.c
+)
+
+set(COMPONENT_PUBLIC_CCFLAGS
+)
+
+set(COMPONENT_CCFLAGS
+
+)
+
+set(WHOLE_LINK
+    true
+)
+
+set(MAIN_COMPONENT
+    false
+)
+
+set(PUBLIC_DEFINES
+)
+
+set(PRIVATE_DEFINES
+)
+
+build_component()
diff --git a/code/sdk/zhihui/drivers/cywee/data/cywee_data.c b/code/sdk/zhihui/drivers/cywee/data/cywee_data.c
new file mode 100644 (file)
index 0000000..72b0e46
--- /dev/null
@@ -0,0 +1,833 @@
+/*
+ * @Author: penglei 1624952103@qq.com
+ * @Date: 2024-04-08 14:53:31
+ * @LastEditors: penglei 1624952103@qq.com
+ * @LastEditTime: 2025-05-20 17:13:34
+ * @FilePath: /FD230/code/sdk/drivers/peripheral/cywee/service/cywee_hal.c
+ * @Description: 
+ * 
+ * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. 
+ */
+
+#include <stdio.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include "cywee_hal.h"
+#include "custom_utils.h"
+#include <sys/stat.h>
+#include "cywee_data.h"
+#include "debug_print.h"
+
+static void CWM_OS_restoreData(int* data, uint32_t len,uint8_t type)
+{
+    FILE * fp=NULL;
+    switch (type)
+    {
+    case CALORIES:
+        fp  = fopen(CWM_CALORIES_DATA_PATH,"rb");
+        break;
+    case STEP:
+        fp  = fopen(CWM_STEP_DATA_PATH,"rb");
+        break;
+    case DISTANCE:
+        fp  = fopen(CWM_DISTANCE_DATA_PATH,"rb");
+        break;
+    case FAT:
+        fp  = fopen(CWM_FAT_DATA_PATH,"rb");
+        break;
+    default:
+        break;
+    }
+
+    if(fp==NULL)
+    {
+        PRINT("%s open fail\n",CWM_HISTORY_DATA_PATH);;
+        return;
+    }
+    int ret =fread(data,1,len,fp);
+   
+    //PRINT("CWM_OS_restoreData fread failed %d %d\n",ret,*data);
+    
+    fclose(fp);
+}
+
+static void CWM_OS_OneHourAgo_restoreData(void* data, uint32_t len,uint8_t type)
+{
+    FILE * fp=NULL;
+    switch (type)
+    {
+    case CALORIES:
+        fp  = fopen(CWM_CALORIES_DATA_PATH_AGO,"rb");
+        break;
+    case STEP:
+        fp  = fopen(CWM_STEP_DATA_PATH_AGO,"rb");
+        break;
+    case DISTANCE:
+        fp  = fopen(CWM_DISTANCE_DATA_PATH_AGO,"rb");
+        break;
+    case FAT:
+        fp  = fopen(CWM_FAT_DATA_PATH_AGO,"rb");
+        break;
+    default:
+        break;
+    }
+
+
+    if(fp==NULL)
+    {
+        PRINT("%s open fail\n",CWM_HISTORY_DATA_PATH);;
+        return;
+    }
+    int ret =fread(data,1,len,fp);
+   
+    //PRINT("CWM_OS_restoreData fread failed %d %d\n",ret,*(int*)data);
+    
+    fclose(fp);
+}
+
+static void CWM_OS_saveData(int* data, uint32_t len,uint8_t type){
+    
+     struct stat info;
+
+    if (stat(CWM_DATA_DIR_PATH, &info) != 0)
+    {
+        if (mkdir(CWM_DATA_DIR_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
+        {
+            return ; // Failed to create folder
+        }
+    }
+    FILE * fp=NULL;
+    switch (type)
+    {
+    case CALORIES:
+        fp  = fopen(CWM_CALORIES_DATA_PATH,"wb");
+        break;
+    case STEP:
+        fp  = fopen(CWM_STEP_DATA_PATH,"wb");
+        break;
+    case DISTANCE:
+        fp  = fopen(CWM_DISTANCE_DATA_PATH,"wb");
+        break;
+    case FAT:
+        fp  = fopen(CWM_FAT_DATA_PATH,"wb");
+        break;
+
+    default:
+        break;
+    }
+    
+    if(fp==NULL)
+    {
+        PRINT("%s open fail\n",CWM_STEP_DATA_PATH);
+        return;
+    }
+    int ret =fwrite(data,1,len,fp);
+   
+    PRINT("CWM_OS_saveData fwrite failed %d %d\n",ret,*data);
+    
+    fclose(fp);
+}
+
+
+static void CWM_OS_OneHourAgo_saveData(void* data, uint32_t len,uint8_t type)
+{
+     struct stat info;
+
+    if (stat(CWM_DATA_DIR_PATH, &info) != 0)
+    {
+        if (mkdir(CWM_DATA_DIR_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
+        {
+            return ; // Failed to create folder
+        }
+    }
+    FILE * fp=NULL;
+    switch (type)
+    {
+    case CALORIES:
+        fp  = fopen(CWM_CALORIES_DATA_PATH_AGO ,"wb");
+        break;
+    case STEP:
+        fp  = fopen(CWM_STEP_DATA_PATH_AGO ,"wb");
+        break;
+    case DISTANCE:
+        fp  = fopen(CWM_DISTANCE_DATA_PATH_AGO ,"wb");
+        break;
+    case FAT:
+        fp  = fopen(CWM_FAT_DATA_PATH_AGO ,"wb");
+        break;
+
+    default:
+        break;
+    }
+    
+    if(fp==NULL)
+    {
+        PRINT("%s open fail\n",CWM_STEP_DATA_PATH_AGO );
+        return;
+    }
+    int ret =fwrite(data,1,len,fp);
+   
+    //PRINT("CWM_OS_saveData fwrite failed %d %d\n",ret,*(int *)data);
+    
+    fclose(fp);
+}
+
+static uint8_t time_is_repetition(uint32_t time,void *data,char *path,void *data_array,uint8_t type)
+{
+    uint8_t is_repetition=0;
+
+    if(type==0)
+    {
+        time_and_32_date_t * p= (time_and_32_date_t*)data_array;
+        FILE *fp=fopen(path,"rb+");
+        if (fp == NULL) return 0;
+
+        fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾
+        uint32_t size = ftell(fp);       // 获取当前文件指针位置,即文件大小
+        fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头
+      
+        for(int i=0;i<size/8;i++)
+        {
+            fread(&p[i].time,sizeof(uint32_t),1,fp);
+            fread(&p[i].data,sizeof(uint32_t),1,fp);
+            if(p[i].time==time)
+            {
+                is_repetition++;
+                uint32_t _32_data=*(uint32_t *)data;
+                p[i].data+=_32_data;
+            }
+        }
+        fclose(fp);
+        
+    }
+    else if(type==1)
+    {
+
+        time_and_float_date_t * p= (time_and_float_date_t*)data_array;
+        FILE *fp=fopen(path,"rb+");
+        if (fp == NULL) return 0;
+
+        fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾
+        uint32_t size = ftell(fp);       // 获取当前文件指针位置,即文件大小
+        fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头
+      
+        for(int i=0;i<size/8;i++)
+        {
+            fread(&p[i].time,sizeof(uint32_t),1,fp);
+            fread(&p[i].data,sizeof(float),1,fp);
+            if(p[i].time==time)
+            {
+                is_repetition++;
+                float _float_data=*(float *)data;
+                p[i].data+=_float_data;
+            }
+        }
+        fclose(fp);
+    }
+     else if(type==2)
+    {
+
+        time_and_16_date_t * p= (time_and_16_date_t*)data_array;
+        FILE *fp=fopen(path,"rb+");
+        if (fp == NULL) return 0;
+
+        fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾
+        uint32_t size = ftell(fp);       // 获取当前文件指针位置,即文件大小
+        fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头
+      
+        for(int i=0;i<size/6;i++)
+        {
+            fread(&p[i].time,sizeof(uint32_t),1,fp);
+            fread(&p[i].data,sizeof(uint16_t),1,fp);
+            if(p[i].time==time)
+            {
+                is_repetition++;
+                 uint16_t _16_data=*(uint16_t *)data;
+                p[i].data+=_16_data;
+            }
+        }
+        fclose(fp);
+    }
+
+    return is_repetition;
+}
+
+void cywee_save_data(void)
+{
+    if(uapi_dev_runtime_get_goal_storage_status())
+    {
+        // return
+        msleep(10);
+    }
+    uapi_dev_runtime_set_goal_storage_status(1);
+
+    int step = cywee_get_sport_data(STEP) + cywee_get_sport_data(HISTORY_STEP);
+    int calories = cywee_get_sport_data(CALORIES) + cywee_get_sport_data(HISTORY_CALORIES);
+    int distances = cywee_get_sport_data(DISTANCE) + cywee_get_sport_data(HISTORY_DISTANCE);
+    int fat = cywee_get_sport_data(FAT) + cywee_get_sport_data(HISTORY_FAT);
+
+    int history_step_ = cywee_get_sport_data(HISTORY_STEP_);
+    int history_calories_ = cywee_get_sport_data(HISTORY_CALORIES_);
+    int history_distances_ = cywee_get_sport_data(HISTORY_DISTANCE_);
+    int history_fat_ = cywee_get_sport_data(HISTORY_FAT_);
+
+    CWM_OS_saveData(&step,sizeof(int),STEP);
+    CWM_OS_OneHourAgo_saveData(&history_step_,sizeof(int),STEP);
+
+    CWM_OS_saveData(&(calories),sizeof(int),CALORIES);
+    CWM_OS_OneHourAgo_saveData(&history_calories_,sizeof(float),CALORIES);
+
+    CWM_OS_saveData(&(distances),sizeof(int),DISTANCE);
+    CWM_OS_OneHourAgo_saveData(&history_distances_,sizeof(float),DISTANCE);
+  
+    CWM_OS_saveData(&fat,sizeof(int),FAT);
+    CWM_OS_OneHourAgo_saveData(&history_fat_,sizeof(uint16_t),FAT);
+
+    uapi_dev_runtime_set_goal_storage_status(0);
+}
+
+void cywee_restoreData(void)
+{
+    int history_step = 0;
+    int history_calories = 0;
+    int history_distances = 0;
+    int history_fat = 0;
+
+    int history_step_ = 0;
+    int history_calories_ = 0;
+    int history_distances_ = 0;
+    int history_fat_ = 0;
+
+    CWM_OS_restoreData(&history_step,sizeof(int),STEP);
+    CWM_OS_OneHourAgo_restoreData(&history_step_,sizeof(int),STEP);
+    cywee_set_sport_data(history_step,HISTORY_STEP);
+    cywee_set_sport_data(history_step_,HISTORY_STEP_);
+
+    CWM_OS_restoreData(&history_calories,sizeof(int),CALORIES);
+    CWM_OS_OneHourAgo_restoreData(&history_calories_,sizeof(float),CALORIES);
+    cywee_set_sport_data(history_calories,HISTORY_CALORIES);
+    cywee_set_sport_data(history_calories_,HISTORY_CALORIES_);
+
+    CWM_OS_restoreData(&history_distances,sizeof(int),DISTANCE);
+    CWM_OS_OneHourAgo_restoreData(&history_distances_,sizeof(float),DISTANCE);
+    cywee_set_sport_data(history_distances,HISTORY_DISTANCE);
+    cywee_set_sport_data(history_distances_,HISTORY_DISTANCE_);
+
+    CWM_OS_restoreData(&history_fat,sizeof(int),FAT);
+    CWM_OS_OneHourAgo_restoreData(&history_fat_,sizeof(uint16_t),FAT);
+    cywee_set_sport_data(history_fat,HISTORY_FAT);
+    cywee_set_sport_data(history_fat_,HISTORY_FAT_);
+
+    //CWM_OS_restoreData(int* data, uint32_t len,uint8_t type)(int* data, uint32_t len,uint8_t type);
+}
+
+static void CWM_OS_saveData_history(void* new_data,void *history ,uint32_t len,uint8_t type,uint32_t time)
+{
+    struct stat info;
+
+    if (stat(GOAL_DATA_CONFIG_DIR, &info) != 0)
+    {
+        if (mkdir(GOAL_DATA_CONFIG_DIR, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
+        {
+            return ; // Failed to create folder
+        }
+    }
+
+    if (stat(GOAL_DATA_CONFIG_DIR_STEP, &info) != 0)
+    {
+        if (mkdir(GOAL_DATA_CONFIG_DIR_STEP, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
+        {
+            return ; // Failed to create folder
+        }
+    }
+
+    if (stat(GOAL_DATA_CONFIG_DIR_DISTANCE, &info) != 0)
+    {
+        if (mkdir(GOAL_DATA_CONFIG_DIR_DISTANCE, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
+        {
+            return ; // Failed to create folder
+        }
+    }
+
+    if (stat(GOAL_DATA_CONFIG_DIR_STAND, &info) != 0)
+    {
+        if (mkdir(GOAL_DATA_CONFIG_DIR_STAND, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
+        {
+            return ; // Failed to create folder
+        }
+    }
+
+    if (stat(GOAL_DATA_CONFIG_DIR_FAT, &info) != 0)
+    {
+        if (mkdir(GOAL_DATA_CONFIG_DIR_FAT, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
+        {
+            return ; // Failed to create folder
+        }
+    }
+
+    if (stat(GOAL_DATA_CONFIG_DIR_CALORIES, &info) != 0)
+    {
+        if (mkdir(GOAL_DATA_CONFIG_DIR_CALORIES, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
+        {
+            return ; // Failed to create folder
+        }
+    }
+
+
+
+    char path_[64]={0};
+    char timeday[12] = {0};
+    uapi_get_TIME_STR(time,timeday, '_','\0',DATE_Y_M_D);
+
+    int i_data=0;
+    float f_data=0;
+    int16_t i_data_16=0;
+
+    switch (type)
+    {
+    case CALORIES:
+        sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_CALORIES_PATH,timeday);
+
+        f_data=*(float*)new_data-*(float*)history;
+
+        break;
+    case STEP:
+       sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_PATH,timeday);
+
+        i_data= *(int*)new_data-*(int*)history;//新数据减去旧数据,作为这一个小时的值
+        // {   
+        //     FILE *fp= fopen("/user/userdata/i_data_test.txt","ab+");
+        //     fwrite("x",1,1,fp);
+        //     fclose(fp);
+        // }
+       
+
+        break;
+    case DISTANCE:
+       sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_DISTANCE_PATH,timeday);
+       f_data=*(float*)new_data-*(float*)history;
+
+        break;
+    case FAT:
+       sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_FAT_PATH,timeday);
+        i_data_16= *(int16_t*)new_data-*(int16_t*)history;//新数据减去旧数据,作为这一个小时的值
+        
+        break;
+
+    default:
+        break;
+    }
+   
+    PRINT(" save path %s \n",path_);
+
+    if(i_data<0 || f_data<0 ||i_data_16<0)
+    {
+        i_data=0;
+        f_data=0;
+        *(int*)history=0;
+        return;
+    }
+
+    if(type==STEP && i_data!=0)
+    {
+        #ifdef GOAL_DATA_AMEND
+        time_and_32_date_t array[25]={0};
+
+        for(int i=0;i<25;i++)
+        {
+            array[i].data=0;
+            array[i].time=0;
+        }
+       
+
+        if(time_is_repetition(time,&i_data,path_,array,0))
+        {
+
+
+            FILE * fp = fopen(path_,"wb+");
+            if(fp==NULL)
+            {
+                PRINT("open fail\n");
+                return;
+            }
+
+            for(int i=0;i<25;i++)
+            {
+                if(array[i].time && array[i].data)
+                {
+                    fwrite(&array[i].time,sizeof(array[i].time),1,fp);
+                    fwrite(&array[i].data,sizeof(array[i].data),1,fp);
+                }
+
+            }
+            fclose(fp);
+
+        }
+        else
+        #endif
+        {
+       
+            FILE * fp = fopen(path_,"ab+");
+            if(fp)
+            {
+                uint32_t creationTime;
+                creationTime=time;//当前值计入上小时
+
+                int ret =fwrite(&creationTime,1,4,fp);
+                if(ret==0)
+                {
+                    PRINT("fwrite failed %d\n",ret);
+                }
+                if(i_data)
+                ret =fwrite(&i_data,1,sizeof(i_data),fp);
+                fclose(fp);
+            }
+            else
+            {
+                msleep(5);
+                FILE * fp = fopen(path_,"ab+");
+                uint32_t creationTime;
+                creationTime=time;//当前值计入上小时
+
+                int ret =fwrite(&creationTime,1,4,fp);
+                if(ret==0)
+                {
+                    PRINT("fwrite failed %d\n",ret);
+                }
+                if(i_data)
+                ret =fwrite(&i_data,1,sizeof(i_data),fp);
+                fclose(fp);
+            }
+
+            
+
+     
+        }
+
+    }
+    if((type==CALORIES|| type==DISTANCE) && f_data!=0)
+    {
+
+        #ifdef GOAL_DATA_AMEND
+         time_and_float_date_t array[25]={0};
+
+        for(int i=0;i<25;i++)
+        {
+            array[i].data=0;
+            array[i].time=0;
+        }
+       
+        if(time_is_repetition(time,&i_data,path_,array,1))
+        {
+
+            FILE * fp = fopen(path_,"wb+");
+            if(fp==NULL)
+            {
+                PRINT("open fail\n");
+                return;
+            }
+
+            for(int i=0;i<25;i++)
+            {
+                if(array[i].time && array[i].data)
+                {
+                    fwrite(&array[i].time,sizeof(array[i].time),1,fp);
+                    fwrite(&array[i].data,sizeof(array[i].data),1,fp);
+                }
+
+            }
+            fclose(fp);
+
+        }
+        else
+        #endif
+        {
+        
+            FILE * fp = fopen(path_,"ab+");
+            if(fp)
+            {
+                uint32_t creationTime;
+                creationTime=time;//当前值计入上小时
+
+                int ret =fwrite(&creationTime,1,4,fp);
+                if(ret==0)
+                {
+                    PRINT("fwrite failed %d\n",ret);
+                }
+                if(f_data)
+                ret =fwrite(&f_data,1,sizeof(f_data),fp);
+
+                fclose(fp);
+
+            }        
+        }
+    }
+
+    if((type==FAT) && i_data_16!=0)
+    {
+
+        #ifdef GOAL_DATA_AMEND
+         time_and_16_date_t array[25]={0};
+
+        for(int i=0;i<25;i++)
+        {
+            array[i].data=0;
+            array[i].time=0;
+        }
+       
+        if(time_is_repetition(time,&i_data,path_,array,2))
+        {
+
+            FILE * fp = fopen(path_,"wb+");
+            if(fp==NULL)
+            {
+                PRINT("open fail\n");
+                return;
+            }
+
+            for(int i=0;i<25;i++)
+            {
+                if(array[i].time && array[i].data)
+                {
+                    fwrite(&array[i].time,sizeof(array[i].time),1,fp);
+                    fwrite(&array[i].data,sizeof(array[i].data),1,fp);
+                }
+
+            }
+            fclose(fp);
+
+        }
+        else
+        #endif
+
+        {
+            FILE * fp = fopen(path_,"ab+");
+            if(fp)
+            {
+                uint32_t creationTime;
+                creationTime=time;//当前值计入上小时
+
+                int ret =fwrite(&creationTime,1,4,fp);
+                if(ret==0)
+                {
+                    PRINT("fwrite failed %d\n",ret);
+                }
+                if(i_data_16)
+                ret =fwrite(&i_data_16,1,sizeof(i_data_16),fp);
+
+                fclose(fp);
+
+            }        
+        }
+    }
+    
+
+     if(i_data)
+    *(int*)history=*(int*)new_data;
+     else if(i_data_16)
+    *(int16_t*)history=*(int16_t*)new_data;
+    else if(f_data)
+    *(float*)history=*(float*)new_data;
+
+}
+
+static void CWM_OS_saveData_STAND_history(uint8_t *falg,uint32_t len,uint32_t time)
+{
+    if(*falg)
+    {
+        struct stat info;
+
+        if (stat(GOAL_DATA_CONFIG_DIR, &info) != 0)
+        {
+            if (mkdir(GOAL_DATA_CONFIG_DIR, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
+            {
+                return ; // Failed to create folder
+            }
+        }
+        
+        if (stat(GOAL_DATA_CONFIG_DIR_STAND, &info) != 0)
+        {
+            if (mkdir(GOAL_DATA_CONFIG_DIR_STAND, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
+            {
+                return ; // Failed to create folder
+            }
+        }
+
+        char path_[64]={0};
+        char timeday[12] = {0};
+        uapi_get_TIME_STR(time,timeday, '_','\0',DATE_Y_M_D);
+
+
+        sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_STAND_DATA_PATH,timeday);
+        PRINT(" save path %s \n",path_);
+
+        FILE * fp = fopen(path_,"ab+");
+        if(fp==NULL)
+        {
+            PRINT("open fail\n");
+            return;
+        }
+        uint32_t ret;
+
+        uint32_t creationTime;
+        creationTime=time;//当前值计入上小时
+
+        PRINT("uapi_get_timestampe_ss %d\n",ret);
+    
+        ret =fwrite(&creationTime,1,len,fp);
+        if(ret==0)
+        {
+            PRINT("fwrite failed %d\n",ret);
+        }
+
+         fclose(fp);
+
+        *falg=0;
+    }
+    else
+    {
+        return;
+    }
+}
+
+
+uint8_t cywee_get_now_stand_count(void)
+{
+    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);
+    PRINT(" save path %s \n",path_);
+
+    FILE * fp = fopen(path_,"rb+");
+    if(fp==NULL)
+    {
+        PRINT("open fail\n");
+        return 0;
+    }
+    fseek(fp, 0, SEEK_END);
+    uint8_t size = ftell(fp);
+    fseek(fp, 0, SEEK_SET);
+
+    uint32_t array[25]={0};
+    uint8_t read_size=0;
+    fread(array,sizeof(uint32_t),size/4,fp);
+    uint8_t is_repetition=0;
+    for(int x=0;x<size/4;x++)
+    {
+        if(array[x])
+        {
+            for(int y=0;y<size/4;y++)
+            {
+                if(array[y]==array[x] && y!=x)
+                {
+                   is_repetition++;
+                }
+            }
+        }
+       
+    }
+
+    fclose(fp);
+    return size/4-is_repetition;
+}
+
+void cywee_stand_history_save(uint32_t time) 
+{
+    // PRINT("stand_history is saving\n");
+    uint8_t flag = cywee_get_stand_flag();
+    CWM_OS_saveData_STAND_history(&flag,sizeof(int),time);
+}
+
+int32_t cywee_get_now_hour_data(void*value, uint8_t type)
+{   
+    int data;
+    float f_data;
+    int16_t data_;
+    switch (type)
+    {
+        case STEP:
+            
+            data = cywee_get_sport_data(HISTORY_STEP) + cywee_get_sport_data(STEP) - cywee_get_sport_data(HISTORY_STEP_);
+            if(data<0)
+            return 0;
+            memcpy_s(value,4,&data,4);
+            return 1;
+
+        case CALORIES:
+            data = cywee_get_sport_data(HISTORY_CALORIES) + cywee_get_sport_data(NEW_CALORIES);
+            f_data=(float)data-cywee_get_sport_data(HISTORY_CALORIES_);
+            if(f_data<0)
+            return 0;
+            memcpy_s(value,4,&f_data,4);
+            return 1;
+            
+        case DISTANCE:
+            data= cywee_get_sport_data(HISTORY_DISTANCE) + cywee_get_sport_data(NEW_DISTANCE);
+            f_data=(float)data/1000.0-cywee_get_sport_data(HISTORY_DISTANCE_);
+            if(f_data<0)
+            return 0;
+            memcpy_s(value,4,&f_data,4);
+            return 1;
+
+        case FAT:
+            data= cywee_get_sport_data(HISTORY_FAT) + cywee_get_sport_data(NEW_FAT);
+            data_=data/60-cywee_get_sport_data(HISTORY_FAT_);
+            if(data_<0 || data_>60)
+            return 0;
+            memcpy_s(value,2,&data_,2);
+            return 1;
+    default:
+        break;
+    }
+    return 0;
+}
+
+void cywee_calories_history_save(uint32_t time)
+{
+    int data = cywee_get_sport_data(HISTORY_CALORIES) + cywee_get_sport_data(NEW_CALORIES);
+
+    float history_calories = (float)data;
+    float history_calories_ = cywee_get_sport_data(HISTORY_CALORIES_);
+    // CWM_OS_dbgPrintf("history_calories is saving\n");
+    CWM_OS_saveData_history(&history_calories,&history_calories_,sizeof(float),CALORIES,time);
+}
+
+void cywee_distances_history_save(uint32_t time)
+{
+    int data= cywee_get_sport_data(HISTORY_DISTANCE) + cywee_get_sport_data(NEW_DISTANCE);
+    float history_distances_now = (float)data / 1000.0;
+    float history_distances_ = cywee_get_sport_data(HISTORY_DISTANCE_);
+    // CWM_OS_dbgPrintf("history_distances is saving\n");
+    CWM_OS_saveData_history(&history_distances_now,&history_distances_,sizeof(float),DISTANCE,time);
+}
+
+void cywee_fat_history_save(uint32_t time)
+{
+    int data = cywee_get_sport_data(HISTORY_FAT) + cywee_get_sport_data(NEW_FAT);
+
+    int16_t temp_data=0;
+    temp_data = data / 60;
+    // CWM_OS_dbgPrintf("history_fat is saving\n");
+    if(temp_data-cywee_get_sport_data(HISTORY_FAT_)>60 || temp_data-cywee_get_sport_data(HISTORY_FAT_)<0)
+    {   
+        cywee_set_sport_data(0,HISTORY_FAT_);
+        return;
+    }
+    int history_fat_ = cywee_get_sport_data(HISTORY_FAT_);
+    CWM_OS_saveData_history(&temp_data,&history_fat_,sizeof(uint16_t),FAT,time);
+}
+
+
+void cywee_step_history_save(uint32_t time)
+{
+    int data = cywee_get_sport_data(HISTORY_STEP) + cywee_get_sport_data(STEP);
+    int history_step_ = cywee_get_sport_data(HISTORY_STEP_);
+    // CWM_OS_dbgPrintf("step_history is saving\n");
+    CWM_OS_saveData_history(&data,&history_step_,sizeof(int),STEP,time);
+}
+
+
diff --git a/code/sdk/zhihui/drivers/cywee/data/cywee_data.h b/code/sdk/zhihui/drivers/cywee/data/cywee_data.h
new file mode 100644 (file)
index 0000000..9449b92
--- /dev/null
@@ -0,0 +1,85 @@
+/**
+ * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. \n
+ *
+ * Description: Test adc header \n
+ * Author: @CompanyNameTag \n
+ * History: \n
+ * 2022-08-16, Create file. \n
+ */
+
+#ifndef CYWEE_DATA_H__
+#define CYWEE_DATA_H__
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#include "stdint.h"
+#include "errcode.h"
+
+
+#define CWM_STEP_DATA_PATH_AGO "/user/userdata/sport/stepcount_ago.bin"
+#define CWM_CALORIES_DATA_PATH_AGO "/user/userdata/sport/caloriescount_ago.bin"
+#define CWM_DISTANCE_DATA_PATH_AGO "/user/userdata/sport/distancecount_ago.bin"
+#define CWM_FAT_DATA_PATH_AGO "/user/userdata/sport/fatcount_ago.bin"
+
+#define CWM_STEP_DATA_PATH "/user/userdata/sport/stepcount.bin"
+#define CWM_CALORIES_DATA_PATH "/user/userdata/sport/caloriescount.bin"
+#define CWM_DISTANCE_DATA_PATH "/user/userdata/sport/distancecount.bin"
+#define CWM_FAT_DATA_PATH "/user/userdata/sport/fatcount.bin"
+
+
+
+#define CWM_HISTORY_DATA_PATH "/user/userdata/goal/step/step_"
+#define CWM_HISTORY_DATA_CALORIES_PATH "/user/userdata/goal/calories/calories_"
+#define CWM_HISTORY_DATA_DISTANCE_PATH "/user/userdata/goal/distance/distance_"
+#define CWM_HISTORY_STAND_DATA_PATH "/user/userdata/goal/stand/stand_"
+#define CWM_HISTORY_DATA_FAT_PATH "/user/userdata/goal/fat/fat_"
+#define GOAL_DATA_CONFIG_DIR "/user/userdata/goal"
+#define GOAL_DATA_CONFIG_DIR_STEP "/user/userdata/goal/step"
+#define GOAL_DATA_CONFIG_DIR_DISTANCE "/user/userdata/goal/distance"
+#define GOAL_DATA_CONFIG_DIR_STAND "/user/userdata/goal/stand"
+#define GOAL_DATA_CONFIG_DIR_FAT "/user/userdata/goal/fat"
+#define GOAL_DATA_CONFIG_DIR_CALORIES "/user/userdata/goal/calories"
+#define CWM_DATA_DIR_PATH "/user/userdata/sport"
+
+typedef struct time_and_32_date
+{
+   uint32_t time;
+   uint32_t data;
+
+}time_and_32_date_t;
+
+
+typedef struct time_and_float_date
+{
+   uint32_t time;
+   float data;
+
+}time_and_float_date_t;
+
+typedef struct time_and_16_date
+{
+   uint16_t time;
+   float data;
+
+}time_and_16_date_t;
+
+uint8_t cywee_get_now_stand_count(void);
+void cywee_stand_history_save(uint32_t time);
+void cywee_step_history_save(uint32_t time);
+void cywee_distances_history_save(uint32_t time);
+void cywee_calories_history_save(uint32_t time);
+void cywee_stand_history_save(uint32_t time);
+void cywee_restoreData(void);
+void cywee_save_data(void);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#endif
\ No newline at end of file
index 7794ce6..18c434f 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: penglei 1624952103@qq.com
  * @Date: 2025-05-19 14:25:40
  * @LastEditors: penglei 1624952103@qq.com
- * @LastEditTime: 2025-05-20 10:56:40
+ * @LastEditTime: 2025-05-21 11:53:41
  * @FilePath: /FD230/code/sdk/zhihui/drivers/cywee/dml/cywee_dml.h
  * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  */
@@ -39,14 +39,7 @@ extern int CWM_OS_i2cWrite(uint16_t slaveAddr, uint16_t reg, int regLength, uint
 extern int CWM_OS_i2cTransfer(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, uint8_t *readData, int readDataSize, int busIndex);
 extern void* CWM_OS_malloc(int size);
 extern void CWM_OS_free(void *ptr);
-extern void CWM_OS_saveData(int* data, uint32_t len,uint8_t type);
-extern  void CWM_OS_OneHourAgo_saveData(void* data, uint32_t len,uint8_t type);
 
-extern void CWM_OS_saveData_history(void* new_data,void *history ,uint32_t len,uint8_t type,uint32_t time);
-extern void CWM_OS_saveData_STAND_history(uint8_t *falg,uint32_t len,uint32_t time);
-extern uint8_t get_stand_count(void);
-extern void CWM_OS_restoreData(int* data, uint32_t len,uint8_t type);
-extern void CWM_OS_OneHourAgo_restoreData(void* data, uint32_t len,uint8_t type);
 
 /********************CYWEE LIB*************************/
 
@@ -447,111 +440,46 @@ typedef struct
     int mag_axis_setting;// int[2] = mag_axis setting    (0: default, 1-24: axis_mode)
 }input_sensor_config_t;
 
-#pragma pack(1)
-
-typedef struct 
-{
-    int output_number;
-    int status;//状态
-    int stand_freq;//站立次数
-    int month;
-    int day;
-    int hour;
-    int minute;
-}cywee_inactivity_result_t;
-
-typedef struct 
-{
-    int output_number;
-    int total_time;//总共睡眠时间
-    int total_mild_sleep_time;//总共浅睡时间
-    int total_deep_sleep_time;//总共深睡时间
-    int total_wake_time;//总共清醒时间
-    int total_rem_sleep_time;//动眼
-}cywee_inactivity_accumulate_time_t;
-
-typedef struct
-{
-    uint32_t timestamp; //时间戳
-    uint8_t stat;       // 状态
-
-} SLEEP_STAT_T;
-
-typedef struct
-{
-    uint32_t fall_asleep_timestamp; // 入睡
-    uint32_t wake_up_timestamp;     // 出睡
-    uint16_t total_time;            // 总时长
-} NAP_T;
-
-typedef struct
-{
-    uint32_t fall_asleep_timestamp; // 入睡
-    uint32_t wake_up_timestamp;     // 出睡
-    uint16_t total_time;            // 总时长
-} SLEEP_T;
-
-#pragma pack()
-
-
+uint8_t cywee_dml_get_log_flag(void);
 void cywee_dml_get_gsensor_data(uint8_t cnt,gsenson_t t[]);
 
-void cywee_dml_activity_mode_setstatus(int cmd);
+void cywee_dml_set_activity_mode_setstatus(int cmd);
 void cywee_dml_oncharging_update(int oncharging_status);
 void cywee_dml_wearstatus_update(int wearstatus);
 void cywee_hrs_update(void);
 void cywee_dml_set_user_info(void);
 void cywee_dml_get_sleep_data(int cmd);
 void cywee_dml_reset_daily_data(void);
-void cywee_inactivity_mode_change(int mode);
+void cywee_dml_inactivity_mode_change(int mode);
 void cywee_dml_activity_mode_change(int mode);
 void cywee_dml_time_sync(void);
 void cywee_dml_hand_updown_switch(int cmd);
 void cywee_dml_ar_alert_switch(int cmd);
 
-void cywee_dml_step_history_save(uint32_t time);
-uint32_t cywee_dml_get_step_data(void);
-void cywee_dml_set_step_data(uint32_t data);
-
-void cywee_dml_stand_history_save(uint32_t time);
-void cywee_dml_calories_history_save(uint32_t time);
-void cywee_dml_distances_history_save(uint32_t time);
-void cywee_dml_fat_history_save(uint32_t time);
-int32_t cywee_dml_get_now_hour_data(void*value, uint8_t type);
-
-void cywee_dml_set_stand_falg(void);
-uint8_t cywee_dml_get_stand_falg(void);
-uint8_t cywee_dml_get_now_stand_count(void);
-void cywee_dml_set_calories_data(uint32_t data);
-int cywee_dml_get_calories_data(void);
-
-void cywee_dml_set_distance_data(uint32_t data);
-int cywee_dml_get_distance_data(void );
-
-void cywee_dml_set_fat_time_data(int time);
-int cywee_dml_get_fat_time_data(void);
+void cywee_dml_set_stand_flag(void);
+uint8_t cywee_dml_get_stand_flag(void);
 
 void cywee_dml_get_chipinfo(char *databuf,uint8_t len);
 void cywee_dml_set_sedentary_interval(int interval);
 void cywee_dml_set_sedentary_switch(int cmd);
-// void cywee_get_acc_switch(int cmd);
+
 void cywee_sensor_stop(void);
 uint8_t cywee_dml_get_active_state(void);
 uint8_t cywee_dml_get_static_state(void);
 void cywee_dml_restart_acc(void);
-void cywee_dml_log_switch(int cmd);
+void cywee_dml_set_log_switch(int cmd);
 void cywee_dml_get_version(char *databuf,uint8_t len);
-void cywee_dml_save_data(void);
+
 void cywee_dml_save_sleep_data(void);
 void cywee_dml_save_nap_data(void);
+
 void cywee_dml_reset_history_daily_data(void);
 void cywee_dml_check_acc(void);
 
 void cywee_custom_save_wear_data(void);
-#pragma pack()
-
-/********************CYWEE  DML*********************/
 
+uint32_t cywee_dml_get_sport_data(uint8_t type);
+void cywee_dml_set_sport_data(uint32_t data,uint8_t type);
 
 int cywee_main_dml(void);
 void cywee_dml_int_handler(void);
@@ -559,6 +487,10 @@ void cywee_dml_int_handler(void);
 act_result_t cywee_dml_get_act_data(void);
 act_ext_result_t cywee_dml_get_act_ext_data(void);
 
+SLEEP_T cywee_dml_get_sleep_time_data(void);
+
+#pragma pack()
+
 #ifdef __cplusplus
 #if __cplusplus
 }
index 02348bf..971c006 100644 (file)
 #include "time.h"
 #include "ConfigModelC.h"
 #include "battery_hal.h"
-
 #include "custom_save_runtime.h"
-
-#include <sys/stat.h>
-
+#include "cywee_data.h"
+#include "cywee_dml.h"
+#include "cywee_hal.h"
 #ifdef SUPPORT_GNSS
 #include "gnss_ctl.h"
 #include "NMEA0183.h"
 #endif
-
 #ifdef SUPPORT_PPG_SERVICE
 #include "ppg_hal.h"
 #include "ppg_service.h"
 #endif
 
-#include "cywee_dml.h"
-
-#include "cywee_hal.h"
-
-
 #define AP_ENABLE_DML_SDO_LISTEN
-
 #define GSENSON_MSG_COUNT   64
-
 #define SLEEP_STATUS_LENGTH 50
-
 #define WEAR_FILE_COUNT 50
 
-
-static uint8_t gsenson_falg=0;
-
-static uint16 num_falg=0;
-static gsenson_t gxyz_t_queue[GSENSON_MSG_COUNT]={0};
-static int16 left_falg=0;
-static int16 right_falg=-1;
-
 SettingControl_t scl;
-
-static uint8_t cywee_installized = 0 ;
-
 CustomSensorData csd;
 
-// static uint8_t hrs = 0;
+static uint16 num_flag = 0;
+static int16 left_flag = 0;
+static int16 right_flag = -1;
+static gsenson_t gxyz_t_queue[GSENSON_MSG_COUNT] = {0};
 
-uint8_t hrs_mode_state = 0;
+static uint8_t cywee_installized = 0;
 
-static int history_step = 0;
 static int stepcount = 0;
-static int history_step_=0;//存一个小时前的步数数据,每次保存步数时会更新改数据
-
-uint8_t stand_falg=0;//站立falg,如果发生站立,一个小时内会被置1;
+static int history_step = 0;
+static int history_step_ = 0;//存一个小时前的步数数据,每次保存步数时会更新改数据
 
-int new_calories=0; //存卡路里数据 
-int history_calories=0; //
-float history_calories_=0;//一小时前卡路里数据
+static uint8_t stand_flag = 0;//站立falg,如果发生站立,一个小时内会被置1;
 
-int new_distance=0; //存距离数据 
-int history_distances=0; //历史数据
-float history_distances_=0; //一小时前距离数据
+static int new_calories = 0; //存卡路里数据 
+static int history_calories = 0; //
+static float history_calories_ = 0;//一小时前卡路里数据
 
+static int new_distance=0; //存距离数据 
+static int history_distances=0; //历史数据
+static float history_distances_=0; //一小时前距离数据
 
-int new_fat=0; //存燃脂数据 
-int history_fat=0; //历史数据
-int history_fat_=0; //一小时前燃脂数据
+static int new_fat=0; //存燃脂数据 
+static int history_fat=0; //历史数据
+static int history_fat_=0; //一小时前燃脂数据
 
 static char chipInfo[64] = {0};
 
 static int sedentary_interval = 1;
-
 static int sedentary_interval_count = 0;
 
-// #ifdef FD230
-// static int cywee_switch = 1;
-// #else
-// static int cywee_switch = 0;
-// #endif
 static uint8_t cywee_is_active = 0;
-
 static uint8_t is_static_state = 0;
 
-uint8_t cywee_ble_service_flag = 0;
+uint8_t cywee_log_flag = 0;
 
 static char cywee_version[20] = {0};
 
 static SLEEP_STAT_T sleep_stat[SLEEP_STATUS_LENGTH] = {0};
-static cywee_inactivity_accumulate_time_t sleep_time = {0};
+static inact_ext_result_t sleep_time = {0};
 // static NAP_T nap_data = {0};
 static int stat_num = 0;
 static int current_year = 0;
@@ -122,24 +96,20 @@ static uint16_t total_wake_time = 0;
 static char time_file_path[64] = {0};
 static char status_file_path[64] = {0};
 static char nap_file_path[64] = {0};
-
 static char dir_path[64] = {0};
 
 static uint8_t ephemeral_flag = 0; //临时数据
-
 static uint8_t wear_status = 0;//佩戴状态
-
 static uint8_t timeout = 0;
-
 static uint8_t wake_up_flag = 0;
 
 static osTimerId_t g_sport_timer = NULL;
 static bool g_sport_stat = false;
 
-static act_result_t c_activity_result_t = {0};
-static cywee_inactivity_result_t c_inactivity_result_t = {0};
-static cywee_inactivity_accumulate_time_t c_inactivity_accumulate_time_t = {0};
-static act_ext_result_t c_activity_result_extre_info_t = {0};
+static act_result_t c_act_result_t = {0};
+static inact_result_t c_inact_result_t = {0};
+static inact_ext_result_t c_inact_ext_result_t = {0};
+static act_ext_result_t c_act_ext_result_t = {0};
 
 #define SPORT_CHECK_MS 1000
 
@@ -153,6 +123,20 @@ int cm__hs1__init(void);
 int cm__hs1__deinit(void);
 #endif
 
+SLEEP_T cywee_dml_get_sleep_time_data(void)
+{
+    SLEEP_T data = {0};
+    data.fall_asleep_timestamp = fall_asleep_timestamp;
+    data.wake_up_timestamp = wake_up_timestamp;
+    data.total_time = total_time;
+    return data;
+}
+
+uint8_t cywee_dml_get_log_flag(void)
+{
+    return cywee_log_flag;
+}
+
 void cywee_gnss_update(void)
 {
 #ifdef SUPPORT_GNSS
@@ -287,215 +271,93 @@ void clean_sleep_data(void)
     wake_up_flag = 0;
 }
 
-void cywee_save_nap_data(cywee_inactivity_accumulate_time_t c_inactivity_accumulate_time_t)
+void cywee_set_sleep_time_data(inact_ext_result_t *sleep_data)
 {
-    if (access(nap_file_path, 0) == -1) //如果小睡文件不存在,创建睡眠文件夹
-    {
-        char day[12] = {0};
-        memset(dir_path,0,sizeof(dir_path));
-        memset(nap_file_path,0,sizeof(nap_file_path));
-
-        uapi_get_YYMMDD_Time(day, '\0');
-        sprintf_s(dir_path, 64, SLEEP_DIR_PATH, day);
-        uapi_create_folder(dir_path);
-        sprintf_s(nap_file_path, 64, NAP_PATH, day);
-    }
-
-
-    uint32_t size = uapi_get_file_size(nap_file_path);
-
-    FILE *fp;
-    fp = fopen(nap_file_path, "ab+"); //小睡数据全部存入一个文件
-    if(fp==NULL)
-    {
-        CWM_OS_dbgPrintf("save_nap_sleep_data %s fopen fail \n", nap_file_path);
-        return;
-    }
-
-    uint8_t id=size/14+1;
-
-    uint16_t nap_size=12;
-    fwrite(&nap_size, 1, 2, fp);
-
-    fwrite(&id, 1, 1, fp);
-
-    uint8_t sleep_type = 0;  //不存睡眠类型 改用文件名判断
-    fwrite(&sleep_type, 1, 1, fp);
-
-    fwrite(&fall_asleep_timestamp, 1, 4, fp);
-
-    fwrite(&wake_up_timestamp, 1, 4, fp);
-
-    uint16_t total_time = c_inactivity_accumulate_time_t.total_time;
-
-    uint8_t total_time_hour = (total_time / 60);
-    fwrite(&total_time_hour, 1, 1, fp);
-
-    uint8_t total_time_minute = (total_time % 60);
-    fwrite(&total_time_minute, 1, 1, fp);
-
-    // CWM_OS_dbgPrintf("save_nap_sleep_data succ \n");
-
-    fclose(fp);
-
-    update_nap_data(fall_asleep_timestamp,wake_up_timestamp,total_time);
+    memset(&sleep_time, 0, sizeof(inact_ext_result_t));
+    memcpy_s(&sleep_time, sizeof(inact_ext_result_t), sleep_data, sizeof(inact_ext_result_t));
 }
 
-static void cywee_set_sleep_time_data(cywee_inactivity_accumulate_time_t *sleep_data)
+void cywee_dml_save_sleep_data(void)
 {
-    memset(&sleep_time, 0, sizeof(cywee_inactivity_accumulate_time_t));
-    memcpy_s(&sleep_time, sizeof(cywee_inactivity_accumulate_time_t), sleep_data, sizeof(cywee_inactivity_accumulate_time_t));
+    uapi_dev_runtime_set_sleep_storage_status(1);
+    cywee_save_sleep_time_data(sleep_time);
+    cywee_save_sleep_stat_data();
+    uapi_dev_runtime_set_sleep_storage_status(0);
 }
 
-void cywee_save_sleep_time_data(cywee_inactivity_accumulate_time_t sleep_time)
+void cywee_dml_save_nap_data(void)
 {
-    // if (access(time_file_path, 0) == -1)
-    {
-        char day[12] = {0};
-        memset(time_file_path, 0, sizeof(time_file_path));
-        get_sleep_file_day(day);
-        sprintf_s(time_file_path, 64, SLEEP_TIME_PATH, day);
-    }
+    uapi_dev_runtime_set_sleep_storage_status(1);
+    cywee_save_nap_data(sleep_time);
+    uapi_dev_runtime_set_sleep_storage_status(0);
+}
 
+void static wear_file_check(SLEEP_STAT_T newStruct, const char *filename) 
+{
     FILE *fp;
-    fp = fopen(time_file_path, "wb+");
-    if(fp == NULL)
-    {
-        CWM_OS_dbgPrintf("save_sleep_data fopen fail \n");
-        return;
-    }
-
-    uint8_t sleep_type = 1;
-    fwrite(&sleep_type, 1, 1, fp);
+    uint16_t count = 0;
+    fp = fopen(filename, "r+b");
+    if(!fp)
+        fp = fopen(filename, "wb");
 
-    fwrite(&fall_asleep_timestamp, 1, 4, fp);
+    fseek(fp, 0, SEEK_END);
+    count = ftell(fp) / sizeof(SLEEP_STAT_T);
+    fseek(fp, 0, SEEK_SET);
 
-    if (wake_up_timestamp == 0)
+    if (count >= WEAR_FILE_COUNT) 
     {
-        uapi_get_timestampe_ss(&wake_up_timestamp);
-    }
-
-    fwrite(&wake_up_timestamp, 1, 4, fp);
-
-    total_time = (wake_up_timestamp - fall_asleep_timestamp) / 60;
-
-    uint8_t total_time_hour = (total_time / 60);
-    fwrite(&total_time_hour, 1, 1, fp);
-
-    uint8_t total_time_minute = (total_time % 60);
-    fwrite(&total_time_minute, 1, 1, fp);
-
-    total_deep_sleep_time += sleep_time.total_deep_sleep_time;
-
-    total_time_hour = (total_deep_sleep_time / 60);
-    fwrite(&total_time_hour, 1, 1, fp);
-
-    total_time_minute = (total_deep_sleep_time % 60);
-    fwrite(&total_time_minute, 1, 1, fp);
-
-    total_mild_sleep_time += sleep_time.total_mild_sleep_time;
-    total_time_hour = (total_mild_sleep_time / 60);
-    fwrite(&total_time_hour, 1, 1, fp);
-
-    total_time_minute = (total_mild_sleep_time % 60);
-    fwrite(&total_time_minute, 1, 1, fp);
-
-    total_rem_sleep_time += sleep_time.total_rem_sleep_time;
-    total_time_hour = (total_rem_sleep_time / 60);
-    fwrite(&total_time_hour, 1, 1, fp);
+        SLEEP_STAT_T data[WEAR_FILE_COUNT] = {0};
 
-    total_time_minute = (total_rem_sleep_time % 60);
-    fwrite(&total_time_minute, 1, 1, fp);
+        fseek(fp,(count - WEAR_FILE_COUNT + 1) * sizeof(SLEEP_STAT_T), SEEK_SET);
+        fread(data, sizeof(SLEEP_STAT_T), WEAR_FILE_COUNT - 1, fp);
 
-    total_wake_time = total_time - total_rem_sleep_time - total_mild_sleep_time -
-                      total_deep_sleep_time;
+        data[WEAR_FILE_COUNT - 1] = newStruct;
 
-    total_time_hour = (total_wake_time / 60);
-    fwrite(&total_time_hour, 1, 1, fp);
+        if(count > WEAR_FILE_COUNT)
+        {
+            fp = freopen(filename, "wb", fp);
+        }
 
-    total_time_minute = (total_wake_time % 60);
-    fwrite(&total_time_minute, 1, 1, fp);
-    fclose(fp);
+        fseek(fp, 0, SEEK_SET);
 
-    if (ephemeral_flag) // 临时数据清掉
+        fwrite(data, sizeof(SLEEP_STAT_T), WEAR_FILE_COUNT, fp);
+    }
+    else
     {
-        total_deep_sleep_time -= sleep_time.total_deep_sleep_time;
-        total_mild_sleep_time -= sleep_time.total_mild_sleep_time;
-        total_rem_sleep_time -= sleep_time.total_rem_sleep_time;
-        ephemeral_flag = 0;
+        fseek(fp, 0, SEEK_END);
+        fwrite(&newStruct, sizeof(SLEEP_STAT_T), 1, fp);
     }
 
-    // CWM_OS_dbgPrintf("wake_up_timestamp : %d ,fall_asleep_timestamp : %d \n",wake_up_timestamp,fall_asleep_timestamp);
-    // CWM_OS_dbgPrintf("total_time[%d], total_deep_sleep_time[%d], total_mild_sleep_time[%d], total_rem_sleep_time[%d], total_wake_time[%d] \n",
-    // total_time,total_deep_sleep_time,total_mild_sleep_time,total_rem_sleep_time,total_wake_time);
-
-    // update_sleep_data(fall_asleep_timestamp,wake_up_timestamp,total_time);
-
+    fclose(fp);
 }
 
-static void cywee_save_sleep_stat_data(void)
+void cywee_custom_save_wear_data(void)
 {
-    memset(status_file_path, 0, sizeof(status_file_path));
-    char day[12] = {0};
-    get_sleep_file_day(day);
-    sprintf_s(status_file_path, 64, SLEEP_STATUS_PATH, day);
-    if (access(status_file_path, 0) == -1) // 文件不存在 直接写入
-    {
-        uapi_save_file_data(status_file_path,(uint8_t *)sleep_stat,stat_num * sizeof(SLEEP_STAT_T),"wb+");  
-    }
-    else // 文件已存在 需要判断是否需要补上清醒状态
-    {
-        
-        FILE *fp = fopen(status_file_path, "rb+");
-        if (fp == NULL)
-        {
-            CWM_OS_dbgPrintf("save_sleep_data fopen fail \n");
-            return;
-        }
-
-        fseek(fp, -sizeof(SLEEP_STAT_T), SEEK_END);
-        SLEEP_STAT_T sleep_status = {0, 0};
-        fread(&sleep_status, sizeof(SLEEP_STAT_T), 1, fp);
-        if (sleep_status.stat == 4) // 如果存在出睡睡觉 替换为清醒
-        {
-            sleep_status.stat = 3; // 清醒状态
-            // sleep_status.timestamp = history_wake_up_timestamp; // 清醒状态时间为上一次的出睡时间
-            fseek(fp, -sizeof(SLEEP_STAT_T), SEEK_END);
-            fwrite(&sleep_status, sizeof(SLEEP_STAT_T), 1, fp); // 补上清醒状态
-            // fwrite(data->sleep_status, sizeof(SLEEP_STATE_T), data->status_num, fp); //写入本次睡眠状态
-            if(sleep_stat[0].stat == 0)
-            {
-                sleep_stat[0].stat = 1;
-                fwrite(sleep_stat, sizeof(SLEEP_STAT_T),stat_num, fp); // 跳过入睡状态写入文件
-            }
-            else
-                fwrite(sleep_stat, sizeof(SLEEP_STAT_T), stat_num, fp);
-
-        }
-        else // 不满足补清醒状态条件 直接写入本次睡眠状态
-        {
-            fseek(fp, 0, SEEK_END);
-            fwrite(sleep_stat, sizeof(SLEEP_STAT_T), stat_num, fp);
-        }
-        fclose(fp);
-    }
-    
-    stat_num = 0;
-    memset(sleep_stat,0,SLEEP_STATUS_LENGTH * sizeof(SLEEP_STAT_T));
+    // int len = uapi_get_file_size("user/userdata/wear.bin");
+    // if(len > sizeof(SLEEP_STAT_T) * 50)
+    // {
+    //     uapi_delete_files("user/userdata/wear.bin");
+    // }
+    SLEEP_STAT_T data;
+    uint32_t tm = 0;
+    uapi_get_timestampe_ss(&tm);
+    data.timestamp = tm;
+    data.stat = wear_status;
+    // CWM_OS_dbgPrintf("data.timestamp : %d , data.stat : %d\n", data.timestamp,data.stat);
+    // uapi_save_file_data("user/userdata/wear.bin",&data,sizeof(SLEEP_STAT_T),"ab");
+    wear_file_check(data,"user/userdata/wear.bin");
+}
 
-    if(wake_up_flag)
-        uapi_dev_runtime_set_sleep_status(0);
 
-}
-void cywee_set_sleep_stat_data(cywee_inactivity_result_t c_inactivity_result_t)
+void cywee_set_sleep_stat_data(inact_result_t c_inact_result_t)
 {
     uint32_t timestamp = 0;
     if(stat_num < SLEEP_STATUS_LENGTH)
     {
-        uapi_get_timestampe_ss_extend(&timestamp,current_year,c_inactivity_result_t.month,c_inactivity_result_t.day,c_inactivity_result_t.hour,c_inactivity_result_t.minute,0);
+        uapi_get_timestampe_ss_extend(&timestamp,current_year,c_inact_result_t.month,c_inact_result_t.day,c_inact_result_t.hour,c_inact_result_t.minute,0);
 
         sleep_stat[stat_num].timestamp = timestamp;
-        sleep_stat[stat_num].stat = c_inactivity_result_t.status;
+        sleep_stat[stat_num].stat = c_inact_result_t.status;
         // CWM_OS_dbgPrintf("stat : %d , timestamp : %d \n", sleep_stat[stat_num].stat,sleep_stat[stat_num].timestamp);
         if(sleep_stat[stat_num].stat == 0) //0进入睡眠  1潜睡 2深睡 3清醒 4结束睡眠 6入睡 7出睡最后一笔输出 8未出睡最后一笔输出 12快速动眼 13取消入睡
         {
@@ -526,7 +388,7 @@ static void cywee_set_abs_static(void)
     CWM_SettingControl(SCL_ABS_STATIC_CONFIG, &scl);
 }
 
-void cywee_dml_log_switch(int cmd)
+void cywee_dml_set_log_switch(int cmd)
 {
     if(cmd)
     {
@@ -536,18 +398,17 @@ void cywee_dml_log_switch(int cmd)
         scl.iData[4] = 5;
         scl.iData[7] = -1;
         CWM_SettingControl(SCL_LOG, &scl); 
-        cywee_ble_service_flag = 1;
+        cywee_log_flag = 1;
     }
     else
     {
         memset(&scl, 0, sizeof(scl));
         scl.iData[0] = 1;
         CWM_SettingControl(SCL_LOG, &scl);
-        cywee_ble_service_flag = 0; 
+        cywee_log_flag = 0; 
     }
 }
 
-
 void cywee_dml_restart_acc(void)
 {
     uint32_t tm = 0;
@@ -610,195 +471,105 @@ void cywee_dml_get_version(char *databuf,uint8_t len)
     memcpy_s(databuf,len,cywee_version,strlen(cywee_version));
 }
 
-void cywee_dml_save_data(void)
-{
-    if(uapi_dev_runtime_get_goal_storage_status())
-    {
-        // return
-        msleep(10);
-    }
-    uapi_dev_runtime_set_goal_storage_status(1);
-    
-    int step=history_step+stepcount;
-    CWM_OS_saveData(&step,sizeof(int),CYWEE_SAVE_DATA_STEP);
-    CWM_OS_OneHourAgo_saveData(&history_step_,sizeof(int),CYWEE_SAVE_DATA_STEP);
-    
-    int calories=history_calories+new_calories;
-    CWM_OS_saveData(&(calories),sizeof(int),CYWEE_SAVE_DATA_CALORIES);
-    CWM_OS_OneHourAgo_saveData(&history_calories_,sizeof(float),CYWEE_SAVE_DATA_CALORIES);
-
-    int distances=history_distances+new_distance;
-    CWM_OS_saveData(&(distances),sizeof(int),CYWEE_SAVE_DATA_DISTANCE);
-    CWM_OS_OneHourAgo_saveData(&history_distances_,sizeof(float),CYWEE_SAVE_DATA_DISTANCE);
-  
-
-    int fat=history_fat+new_fat;
-    CWM_OS_saveData(&fat,sizeof(int),CYWEE_SAVE_DATA_FAT);
-    CWM_OS_OneHourAgo_saveData(&history_fat_,sizeof(uint16_t),CYWEE_SAVE_DATA_FAT);
-
-    uapi_dev_runtime_set_goal_storage_status(0);
-}
 
-static void cywee_restoreData(void)
+uint32_t cywee_dml_get_sport_data(uint8_t type)
 {
-    CWM_OS_restoreData(&history_step,sizeof(int),CYWEE_SAVE_DATA_STEP);
-    CWM_OS_OneHourAgo_restoreData(&history_step_,sizeof(int),CYWEE_SAVE_DATA_STEP);
-
-    CWM_OS_restoreData(&history_calories,sizeof(int),CYWEE_SAVE_DATA_CALORIES);
-    CWM_OS_OneHourAgo_restoreData(&history_calories_,sizeof(float),CYWEE_SAVE_DATA_CALORIES);
-
-    CWM_OS_restoreData(&history_distances,sizeof(int),CYWEE_SAVE_DATA_DISTANCE);
-    CWM_OS_OneHourAgo_restoreData(&history_distances_,sizeof(float),CYWEE_SAVE_DATA_DISTANCE);
-   
-
-    CWM_OS_restoreData(&history_fat,sizeof(int),CYWEE_SAVE_DATA_FAT);
-    CWM_OS_OneHourAgo_restoreData(&history_fat_,sizeof(uint16_t),CYWEE_SAVE_DATA_FAT);
-   
-
-    //CWM_OS_restoreData(int* data, uint32_t len,uint8_t type)(int* data, uint32_t len,uint8_t type);
-}
-
-void cywee_dml_set_step_data(uint32_t data)
-{
-    stepcount=data;
-}
-
-uint32_t cywee_dml_get_step_data(void)
-{
-    return stepcount+history_step;
-}
-
-int cywee_dml_get_calories_data(void)
-{
-    return new_calories+history_calories;
-}
-void cywee_dml_set_calories_data(uint32_t data)
-{
-    new_calories=data;
-}
-
-
-void cywee_dml_set_distance_data(uint32_t data)
-{
-    new_distance=data;
-}
-
-int cywee_dml_get_distance_data(void )
-{
-    return new_distance+history_distances;
-}
-
-void cywee_dml_set_fat_time_data(int time)
-{
-    new_fat += time;
-}
-
-int cywee_dml_get_fat_time_data(void)
-{
-    return new_fat+history_fat;
-}
-
-void cywee_dml_set_stand_falg(void)
-{
-    stand_falg=1;
-}
-
-uint8_t cywee_dml_get_stand_falg(void)
-{
-    return stand_falg;
-}
-
-uint8_t cywee_dml_get_now_stand_count(void)
-{
-    return get_stand_count();
-}
-void cywee_dml_stand_history_save(uint32_t time) {
-    // CWM_OS_dbgPrintf("stand_history is saving\n");
-    CWM_OS_saveData_STAND_history(&stand_falg,sizeof(int),time);
-}
-
-
-int32_t cywee_dml_get_now_hour_data(void*value, uint8_t type)
-{   
-    int data;
-    float f_data;
-    int16_t data_;
+    uint32_t data = 0;
     switch (type)
     {
-        case CYWEE_SAVE_DATA_STEP:
-          
-            data = cywee_dml_get_step_data()-history_step_;
-            if(data<0)
-            return 0;
-            memcpy_s(value,4,&data,4);
-            return 1;
-
-        case CYWEE_SAVE_DATA_CALORIES:
-            data = cywee_dml_get_calories_data();
-            f_data=(float)data-history_calories_;
-            if(f_data<0)
-            return 0;
-            memcpy_s(value,4,&f_data,4);
-            return 1;
-        case CYWEE_SAVE_DATA_DISTANCE:
-            data= cywee_dml_get_distance_data();
-            f_data=(float)data/1000.0-history_distances_;
-            if(f_data<0)
-            return 0;
-            memcpy_s(value,4,&f_data,4);
-            return 1;
-
-        case CYWEE_SAVE_DATA_FAT:
-            data= cywee_dml_get_fat_time_data();
-            data_=data/60-history_fat_;
-            if(data_<0 || data_>60)
-            return 0;
-            memcpy_s(value,2,&data_,2);
-            return 1;
+    case STEP:
+        data  = stepcount;
+        break;
+    case HISTORY_STEP:
+        data  = history_step;
+        break;
+    case HISTORY_DISTANCE:
+        data  = history_distances;
+        break;
+    case HISTORY_CALORIES:
+        data  = history_calories;
+        break;
+    case HISTORY_FAT:
+        data  = history_fat;
+        break;
+    case HISTORY_STEP_:
+        data  = history_step_;
+        break;
+    case HISTORY_DISTANCE_:
+        data  = history_distances_;
+        break;
+    case HISTORY_CALORIES_:
+        data  = history_calories_;
+        break;
+    case HISTORY_FAT_:
+        data  = history_fat_;
+        break;
+    case NEW_DISTANCE:
+        data  = new_distance;
+        break;
+    case NEW_CALORIES:
+        data  = new_calories;
+        break;
+    case NEW_FAT:
+        data  = new_fat;
     default:
         break;
     }
     return 0;
 }
 
-
-void cywee_dml_step_history_save(uint32_t time)
+void cywee_dml_set_sport_data(uint32_t data,uint8_t type)
 {
-    int data = get_step_data();
-    // CWM_OS_dbgPrintf("step_history is saving\n");
-    CWM_OS_saveData_history(&data,&history_step_,sizeof(int),CYWEE_SAVE_DATA_STEP,time);
+    switch (type)
+    {
+    case HISTORY_STEP:
+        history_step  = data;
+        break;
+    case HISTORY_DISTANCE:
+        history_distances  = data;
+        break;
+    case HISTORY_CALORIES:
+        history_calories  = data;
+        break;
+    case HISTORY_FAT:
+        history_fat  = data;
+        break;
+    case HISTORY_STEP_:
+        history_step_  = data;
+        break;
+    case HISTORY_DISTANCE_:
+        history_distances_  = data;
+        break;
+    case HISTORY_CALORIES_:
+        history_calories_  = data;
+        break;
+    case HISTORY_FAT_:
+        history_fat_  = data;
+        break;
+    case NEW_DISTANCE:
+        new_distance  = data;
+        break;
+    case NEW_CALORIES:
+        new_calories  = data;
+        break;
+    case NEW_FAT:
+        new_fat  = data;
+        break;
+    default:
+        break;
+    }
 }
 
-
-void cywee_dml_calories_history_save(uint32_t time)
+void cywee_dml_set_stand_flag(void)
 {
-    int data = cywee_dml_get_calories_data();
-    float history_calories = (float)data;
-    // CWM_OS_dbgPrintf("history_calories is saving\n");
-    CWM_OS_saveData_history(&history_calories,&history_calories_,sizeof(float),CYWEE_SAVE_DATA_CALORIES,time);
+    stand_flag = 1;
 }
 
-void cywee_dml_distances_history_save(uint32_t time)
+uint8_t cywee_dml_get_stand_flag(void)
 {
-    int data= cywee_dml_get_distance_data();
-    float history_distances_now = (float)data / 1000.0;
-    // CWM_OS_dbgPrintf("history_distances is saving\n");
-    CWM_OS_saveData_history(&history_distances_now,&history_distances_,sizeof(float),CYWEE_SAVE_DATA_DISTANCE,time);
+    return stand_flag;
 }
 
-void cywee_dml_fat_history_save(uint32_t time)
-{
-    int data= cywee_dml_get_fat_time_data();
-    int16_t temp_data=0;
-    temp_data = data / 60;
-    // CWM_OS_dbgPrintf("history_fat is saving\n");
-    if(temp_data-history_fat_>60 || temp_data-history_fat_<0)
-    {   
-        history_fat_=0;
-        return;
-    }
-    CWM_OS_saveData_history(&temp_data,&history_fat_,sizeof(uint16_t),CYWEE_SAVE_DATA_FAT,time);
-}
 
 void cywee_dml_ar_alert_switch(int cmd)
 {
@@ -936,19 +707,18 @@ void cywee_dml_wearstatus_update(int wearstatus)
 }
 
 //0:resume , 1:pause
-void cywee_dml_activity_mode_setstatus(int cmd)
+void cywee_dml_set_activity_mode_setstatus(int cmd)
 {
     memset(&scl, 0, sizeof(scl));
     scl.iData[0] = 1;
     scl.iData[1] = cmd; 
     CWM_SettingControl(SCL_ACTIVITY_PAUSE, &scl);
 
-    if(hrs_mode_state == 0)
+    if(cmd == 0)
     {
 #ifdef SUPORT_PPG_SERVICE
         send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_DO_PPG_TEST);
 #endif
-        hrs_mode_state = 1;
         uapi_save_runtime_log(RUNTIME_LOG_HEART_SPORT_MEASURE);
     }
     else
@@ -956,7 +726,6 @@ void cywee_dml_activity_mode_setstatus(int cmd)
 #ifdef SUPORT_PPG_SERVICE
         send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_STOP_PPG_TEST);
 #endif
-        hrs_mode_state = 0;
         uapi_save_runtime_log(RUNTIME_LOG_OXYGEN_SPORT_MEASURE_END);
     }
 }
@@ -1111,20 +880,20 @@ void cywee_dml_get_gsensor_data(uint8_t cnt,gsenson_t t[])
         //     CWM_OS_dbgPrintf("get_gsonsen_xyz_fail\n");
         //     return;
         // }
-        //CWM_OS_dbgPrintf("x=%.3f, y=%.3f, z=%.3f\n", gxyz_t_queue[left_falg].x, gxyz_t_queue[left_falg].y, gxyz_t_queue[left_falg].z);
-        t[i].x= gxyz_t_queue[left_falg].x;
-        t[i].y= gxyz_t_queue[left_falg].y;
-        t[i].z= gxyz_t_queue[left_falg].z;
-
-        gxyz_t_queue[left_falg].x = 0.0f;
-        gxyz_t_queue[left_falg].y = 0.0f;
-        gxyz_t_queue[left_falg].z = 0.0f;
+        //CWM_OS_dbgPrintf("x=%.3f, y=%.3f, z=%.3f\n", gxyz_t_queue[left_flag].x, gxyz_t_queue[left_flag].y, gxyz_t_queue[left_flag].z);
+        t[i].x= gxyz_t_queue[left_flag].x;
+        t[i].y= gxyz_t_queue[left_flag].y;
+        t[i].z= gxyz_t_queue[left_flag].z;
+
+        gxyz_t_queue[left_flag].x = 0.0f;
+        gxyz_t_queue[left_flag].y = 0.0f;
+        gxyz_t_queue[left_flag].z = 0.0f;
         
-        if(num_falg)
+        if(num_flag)
         {
-            left_falg++;
-            left_falg=left_falg%GSENSON_MSG_COUNT;
-            num_falg--;
+            left_flag++;
+            left_flag=left_flag%GSENSON_MSG_COUNT;
+            num_flag--;
 
         }   
         // osal_mutex_unlock(&mutex_gsenson_queue);
@@ -1145,27 +914,27 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) {
                                                    sensorEVT->fData[2]
                                                     );
 
-            if(num_falg==GSENSON_MSG_COUNT)
+            if(num_flag==GSENSON_MSG_COUNT)
             {
-                left_falg++;
-                right_falg++;
-                right_falg=right_falg%GSENSON_MSG_COUNT;
-                left_falg=left_falg%GSENSON_MSG_COUNT;
-                gxyz_t_queue[right_falg].x= sensorEVT->fData[0];
-                gxyz_t_queue[right_falg].y= sensorEVT->fData[1];
-                gxyz_t_queue[right_falg].z= sensorEVT->fData[2];
+                left_flag++;
+                right_flag++;
+                right_flag=right_flag%GSENSON_MSG_COUNT;
+                left_flag=left_flag%GSENSON_MSG_COUNT;
+                gxyz_t_queue[right_flag].x= sensorEVT->fData[0];
+                gxyz_t_queue[right_flag].y= sensorEVT->fData[1];
+                gxyz_t_queue[right_flag].z= sensorEVT->fData[2];
             }    
             else 
             {
-                //left_falg++;
-                right_falg++;
-                right_falg=right_falg%GSENSON_MSG_COUNT ;
-                //left_falg=left_falg%16;
-                num_falg++;
-                gxyz_t_queue[right_falg].x= sensorEVT->fData[0];
-                gxyz_t_queue[right_falg].y= sensorEVT->fData[1];
-                gxyz_t_queue[right_falg].z= sensorEVT->fData[2];
-                //CWM_OS_dbgPrintf("write: x=%d, y=%d, z=%d\n", gxyz_t_queue[right_falg].x ,gxyz_t_queue[right_falg].y ,gxyz_t_queue[right_falg].z);
+                //left_flag++;
+                right_flag++;
+                right_flag=right_flag%GSENSON_MSG_COUNT ;
+                //left_flag=left_flag%16;
+                num_flag++;
+                gxyz_t_queue[right_flag].x= sensorEVT->fData[0];
+                gxyz_t_queue[right_flag].y= sensorEVT->fData[1];
+                gxyz_t_queue[right_flag].z= sensorEVT->fData[2];
+                //CWM_OS_dbgPrintf("write: x=%d, y=%d, z=%d\n", gxyz_t_queue[right_flag].x ,gxyz_t_queue[right_flag].y ,gxyz_t_queue[right_flag].z);
             
             }
         
@@ -1250,7 +1019,6 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) {
 #ifdef SUPORT_PPG_SERVICE
                     send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_DO_PPG_TEST);
 #endif
-                    hrs_mode_state = 1;
                     uapi_save_runtime_log(RUNTIME_LOG_HEART_SPORT_MEASURE);
                     // hrs = 0;//运动开始,清零心率
                 }
@@ -1259,7 +1027,6 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) {
 #ifdef SUPORT_PPG_SERVICE
                     send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_STOP_PPG_TEST);
 #endif
-                    hrs_mode_state = 0;
                     uapi_save_runtime_log(RUNTIME_LOG_OXYGEN_SPORT_MEASURE_END);
                 }
             }
@@ -1297,133 +1064,132 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) {
             if((int)sensorEVT->fData[0] == 20)
             {
 
-                memset(&c_inactivity_result_t,0,sizeof(cywee_inactivity_result_t));
+                memset(&c_inact_result_t,0,sizeof(inact_result_t));
 
-                c_inactivity_result_t.output_number = (int)sensorEVT->fData[0];
+                c_inact_result_t.output_number = (int)sensorEVT->fData[0];
 
-                c_inactivity_result_t.status = (int)sensorEVT->fData[2];
-                c_inactivity_result_t.stand_freq = (int)sensorEVT->fData[3];
-                c_inactivity_result_t.day = (int)sensorEVT->fData[8];
-                c_inactivity_result_t.hour = (int)sensorEVT->fData[9];
-                c_inactivity_result_t.minute = (int)sensorEVT->fData[10];
+                c_inact_result_t.status = (int)sensorEVT->fData[2];
+                c_inact_result_t.stand_freq = (int)sensorEVT->fData[3];
+                c_inact_result_t.day = (int)sensorEVT->fData[8];
+                c_inact_result_t.hour = (int)sensorEVT->fData[9];
+                c_inact_result_t.minute = (int)sensorEVT->fData[10];
 
-                if(c_inactivity_result_t.status == 1)
+                if(c_inact_result_t.status == 1)
                 {
                     sedentary_interval_count++;
                     if(sedentary_interval_count == sedentary_interval)
                     {
                         sedentary_interval_count = 0;
-                        // cywee_func(CYWEE_MSG_TYPE_INACTIVITY_UPDATE,&c_inactivity_result_t,sizeof(cywee_inactivity_result_t));
-                        //CustomEventPublish(TOPIC_EVENT_INACTIVITY_UPDATE, &c_inactivity_result_t, sizeof(cywee_inactivity_result_t));
+                        // cywee_func(CYWEE_MSG_TYPE_INACTIVITY_UPDATE,&c_inact_result_t,sizeof(inact_result_t));
+                        //CustomEventPublish(TOPIC_EVENT_INACTIVITY_UPDATE, &c_inact_result_t, sizeof(inact_result_t));
                     }
                 }
-                else if(c_inactivity_result_t.status != 3)
+                else if(c_inact_result_t.status != 3)
                 {
                     sedentary_interval_count = 0;    
-                    // cywee_func(CYWEE_MSG_TYPE_INACTIVITY_UPDATE,&c_inactivity_result_t,sizeof(cywee_inactivity_result_t)); 
-                    //CustomEventPublish(TOPIC_EVENT_INACTIVITY_UPDATE, &c_inactivity_result_t, sizeof(cywee_inactivity_result_t));
+                    // cywee_func(CYWEE_MSG_TYPE_INACTIVITY_UPDATE,&c_inact_result_t,sizeof(inact_result_t)); 
+                    //CustomEventPublish(TOPIC_EVENT_INACTIVITY_UPDATE, &c_inact_result_t, sizeof(inact_result_t));
                 }
 
             }else if((int)sensorEVT->fData[0] == 21){
 
-                memset(&c_inactivity_result_t,0,sizeof(cywee_inactivity_result_t));
+                memset(&c_inact_result_t,0,sizeof(inact_result_t));
 
-                c_inactivity_result_t.output_number = (int)sensorEVT->fData[0];
-                c_inactivity_result_t.status = (int)sensorEVT->fData[2];
-                c_inactivity_result_t.month = (int)sensorEVT->fData[3];
-                c_inactivity_result_t.day = (int)sensorEVT->fData[4];
-                c_inactivity_result_t.hour = (int)sensorEVT->fData[5];
-                c_inactivity_result_t.minute = (int)sensorEVT->fData[6];
+                c_inact_result_t.output_number = (int)sensorEVT->fData[0];
+                c_inact_result_t.status = (int)sensorEVT->fData[2];
+                c_inact_result_t.month = (int)sensorEVT->fData[3];
+                c_inact_result_t.day = (int)sensorEVT->fData[4];
+                c_inact_result_t.hour = (int)sensorEVT->fData[5];
+                c_inact_result_t.minute = (int)sensorEVT->fData[6];
 
                 // /*保存睡眠状态*/
-                // if(c_inactivity_result_t.status >= 6 && c_inactivity_result_t.status <= 13)
+                // if(c_inact_result_t.status >= 6 && c_inact_result_t.status <= 13)
                 // {
                 //     uapi_get_timestampe_ss(&sleep_flag_t.timestamp);
-                //     sleep_flag_t.stat = c_inactivity_result_t.status;
+                //     sleep_flag_t.stat = c_inact_result_t.status;
                 //     // uapi_save_sleep_flag(&sleep_flag_t,sizeof(SLEEP_FLAG_T));
                 // }
-                // CWM_OS_dbgPrintf("c_inactivity_result_t.status : %d \n", c_inactivity_result_t.status);
+                // CWM_OS_dbgPrintf("c_inact_result_t.status : %d \n", c_inact_result_t.status);
                 //0进入睡眠  1潜睡 2深睡 3清醒 4结束睡眠 6入睡 7出睡最后一笔输出 9未出睡最后一笔输出 12快速动眼 13取消入睡
-                if(c_inactivity_result_t.status >= 6 && c_inactivity_result_t.status <= 9)
+                if(c_inact_result_t.status >= 6 && c_inact_result_t.status <= 9)
                 {
-                    if(c_inactivity_result_t.status == 6)
+                    if(c_inact_result_t.status == 6)
                     {
                         wake_up_flag = 0;
                         uapi_dev_runtime_set_sleep_status(1);
                         uapi_get_timestampe_ss(&asleep_timestampe);
                     }
-                    else if(c_inactivity_result_t.status == 9)
+                    else if(c_inact_result_t.status == 9)
                     {
                         ephemeral_flag = 1; //临时数据
                     }
                     break; //只要是通知都不发消息,直接退出
                 }
-                else if(c_inactivity_result_t.status == 4 || c_inactivity_result_t.status == 13)
+                else if(c_inact_result_t.status == 4 || c_inact_result_t.status == 13)
                 {
                     wake_up_flag = 1;
-                    if(c_inactivity_result_t.status == 13)
+                    if(c_inact_result_t.status == 13)
                         break;
                 }
 
-                cywee_set_sleep_stat_data(c_inactivity_result_t);
-                // cywee_func(CYWEE_MSG_TYPE_INACTIVITY_UPDATE,&c_inactivity_result_t,sizeof(cywee_inactivity_result_t));
+                cywee_set_sleep_stat_data(c_inact_result_t);
+                // cywee_func(CYWEE_MSG_TYPE_INACTIVITY_UPDATE,&c_inact_result_t,sizeof(inact_result_t));
 
             }else if((int)sensorEVT->fData[0] == 31){
-                memset(&c_inactivity_accumulate_time_t,0,sizeof(cywee_inactivity_accumulate_time_t));
+                memset(&c_inact_ext_result_t,0,sizeof(inact_ext_result_t));
                 
-                c_inactivity_accumulate_time_t.output_number = (int)sensorEVT->fData[0];
-                c_inactivity_accumulate_time_t.total_time = (int)sensorEVT->fData[1];
-                c_inactivity_accumulate_time_t.total_mild_sleep_time = (int)sensorEVT->fData[2];
-                c_inactivity_accumulate_time_t.total_deep_sleep_time = (int)sensorEVT->fData[3];
-                c_inactivity_accumulate_time_t.total_wake_time = (int)sensorEVT->fData[4];
-                c_inactivity_accumulate_time_t.total_rem_sleep_time = (int)sensorEVT->fData[5];
-
-                cywee_set_sleep_time_data(&c_inactivity_accumulate_time_t);
+                c_inact_ext_result_t.output_number = (int)sensorEVT->fData[0];
+                c_inact_ext_result_t.total_time = (int)sensorEVT->fData[1];
+                c_inact_ext_result_t.total_mild_sleep_time = (int)sensorEVT->fData[2];
+                c_inact_ext_result_t.total_deep_sleep_time = (int)sensorEVT->fData[3];
+                c_inact_ext_result_t.total_wake_time = (int)sensorEVT->fData[4];
+                c_inact_ext_result_t.total_rem_sleep_time = (int)sensorEVT->fData[5];
+
                 do_custom_fileoperate_service_check_msg(CUSTOM_FILEOPERATE_MSG_TYPE_SLEEPDATA_SAVE, NULL, 0);
-                // cywee_func(CYWEE_MSG_TYPE_INACTIVITY_ACCUMULATE_TIME_UPDATE,&c_inactivity_accumulate_time_t,sizeof(cywee_inactivity_accumulate_time_t));
+                // cywee_func(CYWEE_MSG_TYPE_INACTIVITY_ACCUMULATE_TIME_UPDATE,&c_inact_ext_result_t,sizeof(inact_ext_result_t));
 
             }else if((int)sensorEVT->fData[0] == 22){
 
-                memset(&c_inactivity_result_t,0,sizeof(cywee_inactivity_result_t));
+                memset(&c_inact_result_t,0,sizeof(inact_result_t));
 
-                c_inactivity_result_t.output_number = (int)sensorEVT->fData[0];
-                c_inactivity_result_t.status = (int)sensorEVT->fData[2];
-                c_inactivity_result_t.month = (int)sensorEVT->fData[3];
-                c_inactivity_result_t.day = (int)sensorEVT->fData[4];
-                c_inactivity_result_t.hour = (int)sensorEVT->fData[5];
-                c_inactivity_result_t.minute = (int)sensorEVT->fData[6];
+                c_inact_result_t.output_number = (int)sensorEVT->fData[0];
+                c_inact_result_t.status = (int)sensorEVT->fData[2];
+                c_inact_result_t.month = (int)sensorEVT->fData[3];
+                c_inact_result_t.day = (int)sensorEVT->fData[4];
+                c_inact_result_t.hour = (int)sensorEVT->fData[5];
+                c_inact_result_t.minute = (int)sensorEVT->fData[6];
 
-                if(c_inactivity_result_t.status == 0)
+                if(c_inact_result_t.status == 0)
                 {
                     uapi_dev_runtime_set_nap_status(1);
                     //获取小睡入睡时间戳
-                    uapi_get_timestampe_ss_extend(&fall_asleep_timestamp,current_year,c_inactivity_result_t.month,c_inactivity_result_t.day,c_inactivity_result_t.hour,c_inactivity_result_t.minute,0);
+                    uapi_get_timestampe_ss_extend(&fall_asleep_timestamp,current_year,c_inact_result_t.month,c_inact_result_t.day,c_inact_result_t.hour,c_inact_result_t.minute,0);
                 }
-                else if(c_inactivity_result_t.status == 14)
+                else if(c_inact_result_t.status == 14)
                 {
                     uapi_dev_runtime_set_nap_status(0);
                     //获取小睡出睡时间戳
-                    uapi_get_timestampe_ss_extend(&wake_up_timestamp,current_year,c_inactivity_result_t.month,c_inactivity_result_t.day,c_inactivity_result_t.hour,c_inactivity_result_t.minute,0);
+                    uapi_get_timestampe_ss_extend(&wake_up_timestamp,current_year,c_inact_result_t.month,c_inact_result_t.day,c_inact_result_t.hour,c_inact_result_t.minute,0);
                     nap_update_timestamp = wake_up_timestamp;
                 }
-                // cywee_func(CYWEE_MSG_TYPE_INACTIVITY_UPDATE,&c_inactivity_result_t,sizeof(cywee_inactivity_result_t));
+                // cywee_func(CYWEE_MSG_TYPE_INACTIVITY_UPDATE,&c_inact_result_t,sizeof(inact_result_t));
 
             }else if((int)sensorEVT->fData[0] == 32){
 
-                memset(&c_inactivity_accumulate_time_t,0,sizeof(cywee_inactivity_accumulate_time_t));
+                memset(&c_inact_ext_result_t,0,sizeof(inact_ext_result_t));
                 
-                c_inactivity_accumulate_time_t.output_number = (int)sensorEVT->fData[0];
-                c_inactivity_accumulate_time_t.total_time = (int)sensorEVT->fData[1];
-                c_inactivity_accumulate_time_t.total_mild_sleep_time = (int)sensorEVT->fData[2];
-                c_inactivity_accumulate_time_t.total_deep_sleep_time = (int)sensorEVT->fData[3];
-                c_inactivity_accumulate_time_t.total_wake_time = (int)sensorEVT->fData[4];
-                c_inactivity_accumulate_time_t.total_rem_sleep_time = (int)sensorEVT->fData[5];
-
-                cywee_set_sleep_time_data(&c_inactivity_accumulate_time_t);
+                c_inact_ext_result_t.output_number = (int)sensorEVT->fData[0];
+                c_inact_ext_result_t.total_time = (int)sensorEVT->fData[1];
+                c_inact_ext_result_t.total_mild_sleep_time = (int)sensorEVT->fData[2];
+                c_inact_ext_result_t.total_deep_sleep_time = (int)sensorEVT->fData[3];
+                c_inact_ext_result_t.total_wake_time = (int)sensorEVT->fData[4];
+                c_inact_ext_result_t.total_rem_sleep_time = (int)sensorEVT->fData[5];
+
+                cywee_set_sleep_time_data(&c_inact_ext_result_t);
                 do_custom_fileoperate_service_check_msg(CUSTOM_FILEOPERATE_MSG_TYPE_NAPDATA_SAVE, NULL, 0);
-                // save_nap_data(c_inactivity_accumulate_time_t);
+                // save_nap_data(c_inact_ext_result_t);
 
-                // cywee_func(CYWEE_MSG_TYPE_INACTIVITY_ACCUMULATE_TIME_UPDATE,&c_inactivity_accumulate_time_t,sizeof(cywee_inactivity_accumulate_time_t));
+                // cywee_func(CYWEE_MSG_TYPE_INACTIVITY_ACCUMULATE_TIME_UPDATE,&c_inact_ext_result_t,sizeof(inact_ext_result_t));
             }  
             break;
         case IDX_ALGO_ACTIVITY_OUTPUT:
@@ -1431,34 +1197,34 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) {
             // cywee_func = cywee_get_send_msg_callback_func();
             if((int)sensorEVT->fData[0] == 100)
             {
-                memset(&c_activity_result_extre_info_t,0,sizeof(act_ext_result_t));
-
-                c_activity_result_extre_info_t.avg_step_freq = (int)sensorEVT->fData[1];
-                c_activity_result_extre_info_t.avg_step_len = (float)sensorEVT->fData[2];
-                c_activity_result_extre_info_t.avg_pace = (int)(sensorEVT->fData[3] * 60);
-                c_activity_result_extre_info_t.max_step_freq = (int)sensorEVT->fData[4];
-                c_activity_result_extre_info_t.max_pace = (int)(sensorEVT->fData[5] * 60);
-                c_activity_result_extre_info_t.activity_zone = (int)sensorEVT->fData[10];
-                c_activity_result_extre_info_t.ativity_zone_moderate_duration = (int)sensorEVT->fData[11];
-                c_activity_result_extre_info_t.ativity_zone_high_duration = (int)sensorEVT->fData[12];
-                c_activity_result_extre_info_t.MHR_zone = (int)sensorEVT->fData[13];
-                c_activity_result_extre_info_t.distance_motion = (int)sensorEVT->fData[14];
-
-                // cywee_func(CYWEE_MSG_TYPE_ACTIVITY_EXTRA_INFO_UPDATE,&c_activity_result_extre_info_t,sizeof(act_ext_result_t));
-                //CustomEventPublish(TOPIC_EVENT_ACTIVITY_EXTRA_INFO_UPDATE, &c_activity_result_extre_info_t, sizeof(act_ext_result_t));
+                memset(&c_act_ext_result_t,0,sizeof(act_ext_result_t));
+
+                c_act_ext_result_t.avg_step_freq = (int)sensorEVT->fData[1];
+                c_act_ext_result_t.avg_step_len = (float)sensorEVT->fData[2];
+                c_act_ext_result_t.avg_pace = (int)(sensorEVT->fData[3] * 60);
+                c_act_ext_result_t.max_step_freq = (int)sensorEVT->fData[4];
+                c_act_ext_result_t.max_pace = (int)(sensorEVT->fData[5] * 60);
+                c_act_ext_result_t.activity_zone = (int)sensorEVT->fData[10];
+                c_act_ext_result_t.ativity_zone_moderate_duration = (int)sensorEVT->fData[11];
+                c_act_ext_result_t.ativity_zone_high_duration = (int)sensorEVT->fData[12];
+                c_act_ext_result_t.MHR_zone = (int)sensorEVT->fData[13];
+                c_act_ext_result_t.distance_motion = (int)sensorEVT->fData[14];
+
+                // cywee_func(CYWEE_MSG_TYPE_ACTIVITY_EXTRA_INFO_UPDATE,&c_act_ext_result_t,sizeof(act_ext_result_t));
+                //CustomEventPublish(TOPIC_EVENT_ACTIVITY_EXTRA_INFO_UPDATE, &c_act_ext_result_t, sizeof(act_ext_result_t));
 
             }else if((int)sensorEVT->fData[0] == 5001)
             {
-                memset(&c_activity_result_t,0,sizeof(act_result_t));
+                memset(&c_act_result_t,0,sizeof(act_result_t));
 
-                c_activity_result_t.activity_mode = (int)sensorEVT->fData[0];
-                c_activity_result_t.calories = (int)sensorEVT->fData[1];
-                c_activity_result_t.duration = (int)sensorEVT->fData[5];
-                c_activity_result_t.MHR_zone = (int)sensorEVT->fData[6];
-                // c_activity_result_t.hrs = hrs;
+                c_act_result_t.activity_mode = (int)sensorEVT->fData[0];
+                c_act_result_t.calories = (int)sensorEVT->fData[1];
+                c_act_result_t.duration = (int)sensorEVT->fData[5];
+                c_act_result_t.MHR_zone = (int)sensorEVT->fData[6];
+                // c_act_result_t.hrs = hrs;
                 // hrs = 0; //每次上报完 清除心率值
-                // cywee_func(CYWEE_MSG_TYPE_ACTIVITY_UPDATE,&c_activity_result_t,sizeof(act_result_t));
-                //CustomEventPublish(TOPIC_EVENT_ACTIVITY_UPDATE, &c_activity_result_t, sizeof(act_result_t));
+                // cywee_func(CYWEE_MSG_TYPE_ACTIVITY_UPDATE,&c_act_result_t,sizeof(act_result_t));
+                //CustomEventPublish(TOPIC_EVENT_ACTIVITY_UPDATE, &c_act_result_t, sizeof(act_result_t));
 
             }else if((int)sensorEVT->fData[0] == 102)
             {
@@ -1469,18 +1235,18 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) {
                 
             }else{
                 stepcount = (int)sensorEVT->fData[1];
-                memset(&c_activity_result_t,0,sizeof(act_result_t));
-                c_activity_result_t.activity_mode = (int)sensorEVT->fData[0];
-                c_activity_result_t.steps = stepcount;
-                c_activity_result_t.distance = (int)sensorEVT->fData[2];
-                c_activity_result_t.calories = (int)sensorEVT->fData[3];
-                c_activity_result_t.step_frequency = (int)sensorEVT->fData[5];
-                c_activity_result_t.step_length = (float)sensorEVT->fData[6];
-                c_activity_result_t.pace = (int)(sensorEVT->fData[7] * 60);
-                // c_activity_result_t.hrs = hrs;
+                memset(&c_act_result_t,0,sizeof(act_result_t));
+                c_act_result_t.activity_mode = (int)sensorEVT->fData[0];
+                c_act_result_t.steps = stepcount;
+                c_act_result_t.distance = (int)sensorEVT->fData[2];
+                c_act_result_t.calories = (int)sensorEVT->fData[3];
+                c_act_result_t.step_frequency = (int)sensorEVT->fData[5];
+                c_act_result_t.step_length = (float)sensorEVT->fData[6];
+                c_act_result_t.pace = (int)(sensorEVT->fData[7] * 60);
+                // c_act_result_t.hrs = hrs;
                 // hrs = 0; //每次上报完 清除心率值
-                // cywee_func(CYWEE_MSG_TYPE_ACTIVITY_UPDATE,&c_activity_result_t,sizeof(act_result_t));
-                //CustomEventPublish(TOPIC_EVENT_ACTIVITY_UPDATE, &c_activity_result_t, sizeof(act_result_t));
+                // cywee_func(CYWEE_MSG_TYPE_ACTIVITY_UPDATE,&c_act_result_t,sizeof(act_result_t));
+                //CustomEventPublish(TOPIC_EVENT_ACTIVITY_UPDATE, &c_act_result_t, sizeof(act_result_t));
                 //CustomEventPublish(TOPIC_EVENT_STEPDATA_UPDATE,&stepcount,sizeof(int)); 
             }
             break;
@@ -1583,27 +1349,27 @@ void CWM_AP_dmlSensorDataOutput_listen(const dml_sensorData_t * pSdo)
             rawdata[AccdataCount].acc_y = pSdo->acc_data[1];
             rawdata[AccdataCount].acc_z = pSdo->acc_data[2];
 
-            if(num_falg==GSENSON_MSG_COUNT)
+            if(num_flag==GSENSON_MSG_COUNT)
             {
-                left_falg++;
-                right_falg++;
-                right_falg=right_falg%GSENSON_MSG_COUNT;
-                left_falg=left_falg%GSENSON_MSG_COUNT;
-                gxyz_t_queue[right_falg].x= pSdo->acc_data[0];
-                gxyz_t_queue[right_falg].y= pSdo->acc_data[1];
-                gxyz_t_queue[right_falg].z= pSdo->acc_data[2];
+                left_flag++;
+                right_flag++;
+                right_flag=right_flag%GSENSON_MSG_COUNT;
+                left_flag=left_flag%GSENSON_MSG_COUNT;
+                gxyz_t_queue[right_flag].x= pSdo->acc_data[0];
+                gxyz_t_queue[right_flag].y= pSdo->acc_data[1];
+                gxyz_t_queue[right_flag].z= pSdo->acc_data[2];
             }    
             else 
             {
-                //left_falg++;
-                right_falg++;
-                right_falg=right_falg%GSENSON_MSG_COUNT;
-                //left_falg=left_falg%16;
-                num_falg++;
-                gxyz_t_queue[right_falg].x= pSdo->acc_data[0];
-                gxyz_t_queue[right_falg].y= pSdo->acc_data[1];
-                gxyz_t_queue[right_falg].z= pSdo->acc_data[2];
-                //CWM_OS_dbgPrintf("write: x=%d, y=%d, z=%d\n", gxyz_t_queue[right_falg].x ,gxyz_t_queue[right_falg].y ,gxyz_t_queue[right_falg].z);
+                //left_flag++;
+                right_flag++;
+                right_flag=right_flag%GSENSON_MSG_COUNT;
+                //left_flag=left_flag%16;
+                num_flag++;
+                gxyz_t_queue[right_flag].x= pSdo->acc_data[0];
+                gxyz_t_queue[right_flag].y= pSdo->acc_data[1];
+                gxyz_t_queue[right_flag].z= pSdo->acc_data[2];
+                //CWM_OS_dbgPrintf("write: x=%d, y=%d, z=%d\n", gxyz_t_queue[right_flag].x ,gxyz_t_queue[right_flag].y ,gxyz_t_queue[right_flag].z);
             
             }
             
@@ -1921,7 +1687,7 @@ int cywee_main_dml(void)
     // CWM_Sensor_Enable(IDX_ALGO_ANY_MOTION);
     CWM_Sensor_Enable(IDX_ALGO_ABSOLUTE_STATIC);
     //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__);
-    cywee_restoreData();
+    // cywee_restoreData();
 
     cywee_dml_set_user_info();
 
@@ -1979,326 +1745,17 @@ void cywee_dml_int_handler(void)
 
 }
 
-void cywee_dml_save_sleep_data(void)
-{
-    uapi_dev_runtime_set_sleep_storage_status(1);
-    cywee_save_sleep_time_data(sleep_time);
-    cywee_save_sleep_stat_data();
-    uapi_dev_runtime_set_sleep_storage_status(0);
-}
-
-void cywee_dml_save_nap_data(void)
-{
-    uapi_dev_runtime_set_sleep_storage_status(1);
-    cywee_save_nap_data(sleep_time);
-    uapi_dev_runtime_set_sleep_storage_status(0);
-}
-
-void static wear_file_check(SLEEP_STAT_T newStruct, const char *filename) 
-{
-    FILE *fp;
-    uint16_t count = 0;
-    fp = fopen(filename, "r+b");
-    if(!fp)
-        fp = fopen(filename, "wb");
-
-    fseek(fp, 0, SEEK_END);
-    count = ftell(fp) / sizeof(SLEEP_STAT_T);
-    fseek(fp, 0, SEEK_SET);
-
-    if (count >= WEAR_FILE_COUNT) 
-    {
-        SLEEP_STAT_T data[WEAR_FILE_COUNT] = {0};
-
-        fseek(fp,(count - WEAR_FILE_COUNT + 1) * sizeof(SLEEP_STAT_T), SEEK_SET);
-        fread(data, sizeof(SLEEP_STAT_T), WEAR_FILE_COUNT - 1, fp);
-
-        data[WEAR_FILE_COUNT - 1] = newStruct;
-
-        if(count > WEAR_FILE_COUNT)
-        {
-            fp = freopen(filename, "wb", fp);
-        }
-
-        fseek(fp, 0, SEEK_SET);
-
-        fwrite(data, sizeof(SLEEP_STAT_T), WEAR_FILE_COUNT, fp);
-    }
-    else
-    {
-        fseek(fp, 0, SEEK_END);
-        fwrite(&newStruct, sizeof(SLEEP_STAT_T), 1, fp);
-    }
-
-    fclose(fp);
-}
-
-void cywee_custom_save_wear_data(void)
-{
-    // int len = uapi_get_file_size("user/userdata/wear.bin");
-    // if(len > sizeof(SLEEP_STAT_T) * 50)
-    // {
-    //     uapi_delete_files("user/userdata/wear.bin");
-    // }
-    SLEEP_STAT_T data;
-    uint32_t tm = 0;
-    uapi_get_timestampe_ss(&tm);
-    data.timestamp = tm;
-    data.stat = wear_status;
-    // CWM_OS_dbgPrintf("data.timestamp : %d , data.stat : %d\n", data.timestamp,data.stat);
-    // uapi_save_file_data("user/userdata/wear.bin",&data,sizeof(SLEEP_STAT_T),"ab");
-    wear_file_check(data,"user/userdata/wear.bin");
-}
-
 act_result_t cywee_dml_get_act_data(void)
 {
     act_result_t data = {0};
-    memcpy_s(&data,sizeof(act_result_t),&c_activity_result_t,sizeof(act_result_t));
+    memcpy_s(&data,sizeof(act_result_t),&c_act_result_t,sizeof(act_result_t));
     return data;
 }
 
 act_ext_result_t cywee_dml_get_act_ext_data(void)
 {
     act_ext_result_t data = {0};
-    memcpy_s(&data,sizeof(act_ext_result_t),&c_activity_result_t,sizeof(act_ext_result_t));
+    memcpy_s(&data,sizeof(act_ext_result_t),&c_act_result_t,sizeof(act_ext_result_t));
     return data;
 }
 
-void CWM_OS_restoreData(int* data, uint32_t len,uint8_t type)
-{
-    FILE * fp=NULL;
-    switch (type)
-    {
-    case CYWEE_SAVE_DATA_CALORIES:
-        fp  = fopen(CWM_CALORIES_DATA_PATH,"rb");
-        break;
-    case CYWEE_SAVE_DATA_STEP:
-        fp  = fopen(CWM_STEP_DATA_PATH,"rb");
-        break;
-    case CYWEE_SAVE_DATA_DISTANCE:
-        fp  = fopen(CWM_DISTANCE_DATA_PATH,"rb");
-        break;
-    case CYWEE_SAVE_DATA_FAT:
-        fp  = fopen(CWM_FAT_DATA_PATH,"rb");
-        break;
-    default:
-        break;
-    }
-
-
-    if(fp==NULL)
-    {
-        CWM_OS_dbgPrintf("%s open fail\n",CWM_HISTORY_DATA_PATH);;
-        return;
-    }
-    int ret =fread(data,1,len,fp);
-   
-    //CWM_OS_dbgPrintf("CWM_OS_restoreData fread failed %d %d\n",ret,*data);
-    
-    fclose(fp);
-}
-
-void CWM_OS_OneHourAgo_restoreData(void* data, uint32_t len,uint8_t type){
-
-
-    FILE * fp=NULL;
-    switch (type)
-    {
-    case CYWEE_SAVE_DATA_CALORIES:
-        fp  = fopen(CWM_CALORIES_DATA_PATH_AGO,"rb");
-        break;
-    case CYWEE_SAVE_DATA_STEP:
-        fp  = fopen(CWM_STEP_DATA_PATH_AGO,"rb");
-        break;
-    case CYWEE_SAVE_DATA_DISTANCE:
-        fp  = fopen(CWM_DISTANCE_DATA_PATH_AGO,"rb");
-        break;
-    case CYWEE_SAVE_DATA_FAT:
-        fp  = fopen(CWM_FAT_DATA_PATH_AGO,"rb");
-        break;
-    default:
-        break;
-    }
-
-
-    if(fp==NULL)
-    {
-        CWM_OS_dbgPrintf("%s open fail\n",CWM_HISTORY_DATA_PATH);;
-        return;
-    }
-    int ret =fread(data,1,len,fp);
-   
-    //CWM_OS_dbgPrintf("CWM_OS_restoreData fread failed %d %d\n",ret,*(int*)data);
-    
-    fclose(fp);
-}
-
-void CWM_OS_saveData(int* data, uint32_t len,uint8_t type){
-    
-     struct stat info;
-
-    if (stat(CWM_DATA_DIR_PATH, &info) != 0)
-    {
-        if (mkdir(CWM_DATA_DIR_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
-        {
-            return ; // Failed to create folder
-        }
-    }
-    FILE * fp=NULL;
-    switch (type)
-    {
-    case CYWEE_SAVE_DATA_CALORIES:
-        fp  = fopen(CWM_CALORIES_DATA_PATH,"wb");
-        break;
-    case CYWEE_SAVE_DATA_STEP:
-        fp  = fopen(CWM_STEP_DATA_PATH,"wb");
-        break;
-    case CYWEE_SAVE_DATA_DISTANCE:
-        fp  = fopen(CWM_DISTANCE_DATA_PATH,"wb");
-        break;
-    case CYWEE_SAVE_DATA_FAT:
-        fp  = fopen(CWM_FAT_DATA_PATH,"wb");
-        break;
-
-    default:
-        break;
-    }
-    
-  
-
-    if(fp==NULL)
-    {
-        CWM_OS_dbgPrintf("%s open fail\n",CWM_STEP_DATA_PATH);
-        return;
-    }
-    int ret =fwrite(data,1,len,fp);
-   
-    CWM_OS_dbgPrintf("CWM_OS_saveData fwrite failed %d %d\n",ret,*data);
-    
-    fclose(fp);
-}
-
-
-void CWM_OS_OneHourAgo_saveData(void* data, uint32_t len,uint8_t type){
-    
-     struct stat info;
-
-    if (stat(CWM_DATA_DIR_PATH, &info) != 0)
-    {
-        if (mkdir(CWM_DATA_DIR_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
-        {
-            return ; // Failed to create folder
-        }
-    }
-    FILE * fp=NULL;
-    switch (type)
-    {
-    case CYWEE_SAVE_DATA_CALORIES:
-        fp  = fopen(CWM_CALORIES_DATA_PATH_AGO ,"wb");
-        break;
-    case CYWEE_SAVE_DATA_STEP:
-        fp  = fopen(CWM_STEP_DATA_PATH_AGO ,"wb");
-        break;
-    case CYWEE_SAVE_DATA_DISTANCE:
-        fp  = fopen(CWM_DISTANCE_DATA_PATH_AGO ,"wb");
-        break;
-    case CYWEE_SAVE_DATA_FAT:
-        fp  = fopen(CWM_FAT_DATA_PATH_AGO ,"wb");
-        break;
-
-    default:
-        break;
-    }
-    
-    if(fp==NULL)
-    {
-        CWM_OS_dbgPrintf("%s open fail\n",CWM_STEP_DATA_PATH_AGO );
-        return;
-    }
-    int ret =fwrite(data,1,len,fp);
-   
-    //CWM_OS_dbgPrintf("CWM_OS_saveData fwrite failed %d %d\n",ret,*(int *)data);
-    
-    fclose(fp);
-}
-
-uint8_t time_is_repetition(uint32_t time,void *data,char *path,void *data_array,uint8_t type)
-{
-    uint8_t is_repetition=0;
-
-    if(type==0)
-    {
-        time_and_32_date_t * p= (time_and_32_date_t*)data_array;
-        FILE *fp=fopen(path,"rb+");
-        if (fp == NULL) return 0;
-
-        fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾
-        uint32_t size = ftell(fp);       // 获取当前文件指针位置,即文件大小
-        fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头
-      
-        for(int i=0;i<size/8;i++)
-        {
-            fread(&p[i].time,sizeof(uint32_t),1,fp);
-            fread(&p[i].data,sizeof(uint32_t),1,fp);
-            if(p[i].time==time)
-            {
-                is_repetition++;
-                uint32_t _32_data=*(uint32_t *)data;
-                p[i].data+=_32_data;
-            }
-        }
-        fclose(fp);
-        
-    }
-    else if(type==1)
-    {
-
-        time_and_float_date_t * p= (time_and_float_date_t*)data_array;
-        FILE *fp=fopen(path,"rb+");
-        if (fp == NULL) return 0;
-
-        fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾
-        uint32_t size = ftell(fp);       // 获取当前文件指针位置,即文件大小
-        fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头
-      
-        for(int i=0;i<size/8;i++)
-        {
-            fread(&p[i].time,sizeof(uint32_t),1,fp);
-            fread(&p[i].data,sizeof(float),1,fp);
-            if(p[i].time==time)
-            {
-                is_repetition++;
-                float _float_data=*(float *)data;
-                p[i].data+=_float_data;
-            }
-        }
-        fclose(fp);
-    }
-     else if(type==2)
-    {
-
-        time_and_16_date_t * p= (time_and_16_date_t*)data_array;
-        FILE *fp=fopen(path,"rb+");
-        if (fp == NULL) return 0;
-
-        fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾
-        uint32_t size = ftell(fp);       // 获取当前文件指针位置,即文件大小
-        fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头
-      
-        for(int i=0;i<size/6;i++)
-        {
-            fread(&p[i].time,sizeof(uint32_t),1,fp);
-            fread(&p[i].data,sizeof(uint16_t),1,fp);
-            if(p[i].time==time)
-            {
-                is_repetition++;
-                 uint16_t _16_data=*(uint16_t *)data;
-                p[i].data+=_16_data;
-            }
-        }
-        fclose(fp);
-    }
-
-    return is_repetition;
-}
-
index b4f83e8..ea45918 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: penglei 1624952103@qq.com
  * @Date: 2024-04-08 14:53:31
  * @LastEditors: penglei 1624952103@qq.com
- * @LastEditTime: 2025-05-20 10:45:25
+ * @LastEditTime: 2025-05-20 16:53:48
  * @FilePath: /FD230/code/sdk/drivers/peripheral/cywee/service/cywee_hal.c
  * @Description: 
  * 
@@ -58,15 +58,19 @@ void cywee_int_handler(void)
 
 act_result_t cywee_get_act_data(void)
 {
+    act_result_t data = {0};
 #ifdef CYWEE_DML
-    return cywee_dml_get_act_data();
+    data = cywee_dml_get_act_data();
 #endif
+    return data;
 }
 act_ext_result_t cywee_get_act_ext_data(void)
 {
+    act_ext_result_t data = {0};
 #ifdef CYWEE_DML
-    return cywee_dml_get_act_ext_data();
+    data = cywee_dml_get_act_ext_data();
 #endif
+    return data;
 }
 
 void cywee_activity_mode_change(int mode)
@@ -83,10 +87,10 @@ void cywee_inactivity_mode_change(int mode)
 #endif
 }
 
-void cywee_activity_mode_setstatus(int mode)
+void cywee_set_activity_mode_setstatus(int mode)
 {
 #ifdef CYWEE_DML
-    cywee_dml_activity_mode_setstatus(mode);
+    cywee_dml_set_activity_mode_setstatus(mode);
 #endif
 }
 
@@ -157,10 +161,10 @@ void cywee_check_acc(void)
 #endif      
 }
 
-void cywee_log_switch(int cmd)
+void cywee_set_log_switch(int cmd)
 {
 #ifdef CYWEE_DML
-    cywee_dml_log_switch(cmd);
+    cywee_dml_set_log_switch(cmd);
 #endif        
 }
 
@@ -243,62 +247,6 @@ void cywee_set_user_info(void)
 #endif       
 }
 
-void cywee_fat_history_save(uint32_t time)
-{
-#ifdef CYWEE_DML
-    cywee_dml_fat_history_save(time);
-#endif  
-}
-
-void cywee_step_history_save(uint32_t time)
-{
-#ifdef CYWEE_DML
-    cywee_dml_step_history_save(time);
-#endif  
-}
-
-uint32_t cywee_get_step_data(void)
-{
-#ifdef CYWEE_DML
-    return cywee_dml_get_step_data();
-#endif  
-}
-
-void cywee_set_step_data(uint32_t data)
-{
-#ifdef CYWEE_DML
-    cywee_dml_set_step_data(data);
-#endif  
-}
-
-void cywee_stand_history_save(uint32_t time)
-{
-#ifdef CYWEE_DML
-    cywee_dml_stand_history_save(time);
-#endif  
-}
-
-void cywee_calories_history_save(uint32_t time)
-{
-#ifdef CYWEE_DML
-    cywee_dml_calories_history_save(time);
-#endif  
-}
-
-void cywee_distances_history_save(uint32_t time)
-{
-#ifdef CYWEE_DML
-    cywee_dml_distances_history_save(time);
-#endif  
-}
-
-int32_t cywee_get_now_hour_data(void*value, uint8_t type)
-{
-#ifdef CYWEE_DML
-    return cywee_dml_get_now_hour_data(value,type);
-#endif     
-}
-
 void cywee_set_stand_falg(void)
 {
 #ifdef CYWEE_DML
@@ -311,60 +259,30 @@ uint8_t cywee_get_stand_falg(void)
 #ifdef CYWEE_DML
     return cywee_dml_get_stand_falg();
 #endif  
+    return 0;
 }
 
-uint8_t cywee_get_now_stand_count(void)
-{
-#ifdef CYWEE_DML
-    return cywee_dml_get_now_stand_count();
-#endif     
-}
-
-void cywee_set_calories_data(uint32_t data)
-{
-#ifdef CYWEE_DML
-    cywee_dml_set_calories_data(data);
-#endif  
-}
-
-int cywee_get_calories_data(void)
-{
-#ifdef CYWEE_DML
-    return cywee_dml_get_calories_data();
-#endif  
-}
-
-void cywee_set_distance_data(uint32_t data)
-{
-#ifdef CYWEE_DML
-    cywee_dml_set_distance_data(data);
-#endif  
-}
-
-int cywee_get_distance_data(void)
-{
-#ifdef CYWEE_DML
-    return cywee_dml_get_distance_data();
-#endif  
-}
-
-void cywee_set_fat_time_data(int time)
+uint32_t cywee_get_sport_data(uint8_t type)
 {
+    uint32_t data = 0;
 #ifdef CYWEE_DML
-    cywee_dml_set_fat_time_data(time);
+    data = cywee_dml_get_sport_data(type);
 #endif
+    return data;
 }
 
-int cywee_get_fat_time_data(void)
+void cywee_set_sport_data(uint32_t data,uint8_t type)
 {
 #ifdef CYWEE_DML
-    return cywee_dml_get_fat_time_data();
+    cywee_dml_set_sport_data(data,type);
 #endif
 }
 
-void cywee_save_data(void)
+SLEEP_T cywee_get_sleep_time_data(void)
 {
+    SLEEP_T data = {0};
 #ifdef CYWEE_DML
-    cywee_dml_save_data();
-#endif
+    data = cywee_dml_get_sleep_time_data();
+#endif 
+    return data;
 }
\ No newline at end of file
index fa6f934..81ed084 100644 (file)
@@ -19,38 +19,12 @@ extern "C" {
 #include "stdint.h"
 #include "errcode.h"
 
-
-
 #define SLEEP_TIME_PATH "/user/userdata/sleep/%s/sleep_time.bin"
 #define SLEEP_STATUS_PATH "/user/userdata/sleep/%s/sleep_status.bin"
 #define NAP_PATH "/user/userdata/sleep/%s/nap.bin"
 #define SLEEP_DIR_PATH "/user/userdata/sleep/%s"
 #define SLEEP_DATA_DIR "/user/userdata/sleep/"
 
-#define CWM_STEP_DATA_PATH_AGO "/user/userdata/sport/stepcount_ago.bin"
-#define CWM_CALORIES_DATA_PATH_AGO "/user/userdata/sport/caloriescount_ago.bin"
-#define CWM_DISTANCE_DATA_PATH_AGO "/user/userdata/sport/distancecount_ago.bin"
-#define CWM_FAT_DATA_PATH_AGO "/user/userdata/sport/fatcount_ago.bin"
-
-#define CWM_STEP_DATA_PATH "/user/userdata/sport/stepcount.bin"
-#define CWM_CALORIES_DATA_PATH "/user/userdata/sport/caloriescount.bin"
-#define CWM_DISTANCE_DATA_PATH "/user/userdata/sport/distancecount.bin"
-#define CWM_FAT_DATA_PATH "/user/userdata/sport/fatcount.bin"
-
-
-
-#define CWM_HISTORY_DATA_PATH "/user/userdata/goal/step/step_"
-#define CWM_HISTORY_DATA_CALORIES_PATH "/user/userdata/goal/calories/calories_"
-#define CWM_HISTORY_DATA_DISTANCE_PATH "/user/userdata/goal/distance/distance_"
-#define CWM_HISTORY_STAND_DATA_PATH "/user/userdata/goal/stand/stand_"
-#define CWM_HISTORY_DATA_FAT_PATH "/user/userdata/goal/fat/fat_"
-#define GOAL_DATA_CONFIG_DIR "/user/userdata/goal"
-#define GOAL_DATA_CONFIG_DIR_STEP "/user/userdata/goal/step"
-#define GOAL_DATA_CONFIG_DIR_DISTANCE "/user/userdata/goal/distance"
-#define GOAL_DATA_CONFIG_DIR_STAND "/user/userdata/goal/stand"
-#define GOAL_DATA_CONFIG_DIR_FAT "/user/userdata/goal/fat"
-#define GOAL_DATA_CONFIG_DIR_CALORIES "/user/userdata/goal/calories"
-#define CWM_DATA_DIR_PATH "/user/userdata/sport"
 
 typedef struct {
     float x;
@@ -59,35 +33,31 @@ typedef struct {
 } gsenson_t;
 
 typedef enum {
-    CYWEE_SAVE_DATA_STEP,
-    CYWEE_SAVE_DATA_DISTANCE,
-    CYWEE_SAVE_DATA_CALORIES,
-    CYWEE_SAVE_DATA_FAT,
+    STEP,
+    DISTANCE,
+    CALORIES,
+    FAT,
+    HISTORY_STEP,
+    HISTORY_DISTANCE,
+    HISTORY_CALORIES,
+    HISTORY_FAT,
+    HISTORY_STEP_,
+    HISTORY_DISTANCE_,
+    HISTORY_CALORIES_,
+    HISTORY_FAT_,
+    NEW_STEP,
+    NEW_DISTANCE,
+    NEW_CALORIES,
+    NEW_FAT,
 } CYWEE_SAVE_DATA_TYPE;
 
 
-typedef struct time_and_32_date
-{
-   uint32_t time;
-   uint32_t data;
-
-}time_and_32_date_t;
-
-
-typedef struct time_and_float_date
-{
-   uint32_t time;
-   float data;
-
-}time_and_float_date_t;
-
-typedef struct time_and_16_date
+typedef struct
 {
-   uint16_t time;
-   float data;
-
-}time_and_16_date_t;
+    uint32_t timestamp; //时间戳
+    uint8_t stat;       // 状态
 
+} SLEEP_TIME_T;
 
 #pragma pack(1)
 
@@ -120,9 +90,56 @@ typedef struct
     int distance_motion;//体感距离
 }act_ext_result_t;
 
+
+typedef struct 
+{
+    int output_number;
+    int status;//状态
+    int stand_freq;//站立次数
+    int month;
+    int day;
+    int hour;
+    int minute;
+}inact_result_t;
+
+typedef struct 
+{
+    int output_number;
+    int total_time;//总共睡眠时间
+    int total_mild_sleep_time;//总共浅睡时间
+    int total_deep_sleep_time;//总共深睡时间
+    int total_wake_time;//总共清醒时间
+    int total_rem_sleep_time;//动眼
+}inact_ext_result_t;
+
+typedef struct
+{
+    uint32_t timestamp; //时间戳
+    uint8_t stat;       // 状态
+
+} SLEEP_STAT_T;
+
+typedef struct
+{
+    uint32_t fall_asleep_timestamp; // 入睡
+    uint32_t wake_up_timestamp;     // 出睡
+    uint16_t total_time;            // 总时长
+} NAP_T;
+
+typedef struct
+{
+    uint32_t fall_asleep_timestamp; // 入睡
+    uint32_t wake_up_timestamp;     // 出睡
+    uint16_t total_time;            // 总时长
+} SLEEP_T;
+
 #pragma pack()
 
-void cywee_activity_mode_setstatus(int cmd);
+void cywee_start(void);
+void cywee_stop(void);
+void cywee_int_handler(void);
+
+void cywee_set_activity_mode_setstatus(int cmd);
 void cywee_oncharging_update(int oncharging_status);
 void cywee_wearstatus_update(int wearstatus);
 void cywee_hrs_update(void);
@@ -134,28 +151,10 @@ void cywee_activity_mode_change(int mode);
 void cywee_time_sync(void);
 void cywee_hand_updown_switch(int cmd);
 void cywee_ar_alert_switch(int cmd);
-
-void cywee_step_history_save(uint32_t time);
-uint32_t cywee_get_step_data(void);
-void cywee_set_step_data(uint32_t data);
-
-void cywee_stand_history_save(uint32_t time);
-void cywee_calories_history_save(uint32_t time);
-void cywee_distances_history_save(uint32_t time);
-void cywee_fat_history_save(uint32_t time);
-int32_t cywee_get_now_hour_data(void*value, uint8_t type);
-
+\
 void cywee_set_stand_falg(void);
 uint8_t cywee_get_stand_falg(void);
 uint8_t cywee_get_now_stand_count(void);
-void cywee_set_calories_data(uint32_t data);
-int cywee_get_calories_data(void);
-
-void cywee_set_distance_data(uint32_t data);
-int cywee_get_distance_data(void );
-
-void cywee_set_fat_time_data(int time);
-int cywee_get_fat_time_data(void);
 
 void cywee_get_chipinfo(char *databuf,uint8_t len);
 void cywee_set_sedentary_interval(int interval);
@@ -165,9 +164,8 @@ void cywee_sensor_stop(void);
 uint8_t cywee_get_active_state(void);
 uint8_t cywee_get_static_state(void);
 void cywee_restart_acc(void);
-void cywee_log_switch(int cmd);
+void cywee_set_log_switch(int cmd);
 void cywee_get_version(char *databuf,uint8_t len);
-void cywee_save_data(void);
 
 void cywee_custom_save_sleep_data(void);
 void cywee_custom_save_nap_data(void);
@@ -175,24 +173,16 @@ void cywee_reset_history_daily_data(void);
 void cywee_check_acc(void);
 
 void cywee_custom_save_wear_data(void);
-#pragma pack()
-
-
-
-
 
-
-
-/********************CYWEE  DML*********************/
-
-
-int cywee_main_dml(void);
-void cywee_dml_int_handler(void);
+uint32_t cywee_get_sport_data(uint8_t type);
+void cywee_dml_set_sport_data(uint32_t data,uint8_t type);
 
 act_result_t cywee_get_act_data(void);
 act_ext_result_t cywee_get_act_ext_data(void);
 
 void cywee_get_gsensor_data(uint8_t cnt,gsenson_t *data);
+SLEEP_T cywee_get_sleep_time_data(void);
+
 #ifdef __cplusplus
 #if __cplusplus
 }
index fbe1d1a..56cafd6 100644 (file)
@@ -64,7 +64,7 @@ void cywee_msg_callback(uint8_t msg_type, uint8_t *msg_data, int32_t msg_datalen
     act_result_t c_activity_result_t;
     cywee_inactivity_result_t c_inactivity_result_t;
     act_ext_result_t c_activity_result_extre_info_t;
-    cywee_inactivity_accumulate_time_t c_inactivity_accumulate_time_t;
+    inact_ext_result_t c_inactivity_accumulate_time_t;
 
     if (msg_type == CYWEE_MSG_TYPE_ACTIVITY_UPDATE)
     {
@@ -165,12 +165,12 @@ void cywee_msg_callback(uint8_t msg_type, uint8_t *msg_data, int32_t msg_datalen
     else if (msg_type == CYWEE_MSG_TYPE_INACTIVITY_ACCUMULATE_TIME_UPDATE)
     {
         // 睡眠累计
-        memcpy(&c_inactivity_accumulate_time_t, msg_data, sizeof(cywee_inactivity_accumulate_time_t));
+        memcpy(&c_inactivity_accumulate_time_t, msg_data, sizeof(inact_ext_result_t));
         PRINT("total sleep time[%d], total mild sleep time[%d], total deep sleep time[%d], total wake time[%d], total rem sleep time[%d]\n",
             c_inactivity_accumulate_time_t.total_time, c_inactivity_accumulate_time_t.total_mild_sleep_time,
             c_inactivity_accumulate_time_t.total_deep_sleep_time, c_inactivity_accumulate_time_t.total_wake_time, 
             c_inactivity_accumulate_time_t.total_rem_sleep_time);
-        //CustomEventPublish(TOPIC_EVENT_INACTIVITY_ACCUMULATE_TIME_UPDATE, &c_inactivity_accumulate_time_t, sizeof(cywee_inactivity_accumulate_time_t));
+        //CustomEventPublish(TOPIC_EVENT_INACTIVITY_ACCUMULATE_TIME_UPDATE, &c_inactivity_accumulate_time_t, sizeof(inact_ext_result_t));
 
     }
     else
@@ -306,11 +306,11 @@ static void cywee_service_check_task(void const *arg)
             break;
 
             case CYWEE_SERVICE_CMD_PAUSE:
-                cywee_activity_mode_setstatus(1);
+                cywee_set_activity_mode_setstatus(1);
             break;
 
             case CYWEE_SERVICE_CMD_RESUME:
-                cywee_activity_mode_setstatus(0);
+                cywee_set_activity_mode_setstatus(0);
             break;
 
             case CYWEE_SERVICE_CMD_ONCHARGING_CHANGE:
@@ -369,7 +369,7 @@ static void cywee_service_check_task(void const *arg)
             break;
 
             case CYWEE_SERVICE_CMD_SAVE_DATA:
-                cywee_save_data();
+                // cywee_save_data();
             break;
 
             case CYWEE_SERVICE_CMD_SET_SEDENTARY_INTERVAL:
@@ -457,7 +457,8 @@ errcode_t uapi_cywee_service_init(void)
 
     // cywee_register_msg_callback(cywee_msg_callback);
     do_cywee_service_check_msg(CYWEE_SERVICE_CMD_START_CHECK, NULL);
-    
+    do_custom_fileoperate_service_check_msg(CUSTOM_FILEOPERATE_MSG_TYPE_SPORTDATA_READ, NULL, 0);
+
     return ERRCODE_SUCC;
 }
 
index 3354b24..2019a9e 100644 (file)
@@ -606,7 +606,7 @@ char * ble_sywee_history(uint8_t day,uint16_t *len ,uint8_t type)
         {
             case 0x43: //同步步数历史数据
 
-                if( cywee_get_now_hour_data(&value,CYWEE_SAVE_DATA_STEP))
+                if( cywee_get_now_hour_data(&value,STEP))
                 {
                     if(value>0)
                     {
@@ -619,7 +619,7 @@ char * ble_sywee_history(uint8_t day,uint16_t *len ,uint8_t type)
               
                 break;
             case 0x44://同步燃脂时间数据
-                if(cywee_get_now_hour_data(&value_16,CYWEE_SAVE_DATA_FAT))
+                if(cywee_get_now_hour_data(&value_16,FAT))
                 {
                      if(value_16>0)
                     {
@@ -642,7 +642,7 @@ char * ble_sywee_history(uint8_t day,uint16_t *len ,uint8_t type)
                
                 break;
             case 0x46://同步卡路里历史数据
-                if(cywee_get_now_hour_data(&f_value,CYWEE_SAVE_DATA_CALORIES))
+                if(cywee_get_now_hour_data(&f_value,CALORIES))
                 {   
                     if(f_value>0)
                     {
@@ -655,7 +655,7 @@ char * ble_sywee_history(uint8_t day,uint16_t *len ,uint8_t type)
               
                 break;
             case 0x47://同步距离历史数据
-                if(cywee_get_now_hour_data(&f_value,CYWEE_SAVE_DATA_DISTANCE))
+                if(cywee_get_now_hour_data(&f_value,DISTANCE))
                 {
                     if(f_value>0)
                     {
index cf779b8..86b36ee 100644 (file)
@@ -1326,7 +1326,7 @@ char * ble_sywee_history(uint8_t day,uint16_t *len ,uint8_t type)
         {
             case 0x43: //同步步数历史数据
 
-                if( cywee_get_now_hour_data(&value,CYWEE_SAVE_DATA_STEP))
+                if( cywee_get_now_hour_data(&value,STEP))
                 {
                     if(value>0)
                     {
@@ -1339,7 +1339,7 @@ char * ble_sywee_history(uint8_t day,uint16_t *len ,uint8_t type)
               
                 break;
             case 0x44://同步燃脂时间数据
-                if(cywee_get_now_hour_data(&value_16,CYWEE_SAVE_DATA_FAT))
+                if(cywee_get_now_hour_data(&value_16,FAT))
                 {
                      if(value_16>0)
                     {
@@ -1362,7 +1362,7 @@ char * ble_sywee_history(uint8_t day,uint16_t *len ,uint8_t type)
                
                 break;
             case 0x46://同步卡路里历史数据
-                if(cywee_get_now_hour_data(&f_value,CYWEE_SAVE_DATA_CALORIES))
+                if(cywee_get_now_hour_data(&f_value,CALORIES))
                 {   
                     if(f_value>0)
                     {
@@ -1375,7 +1375,7 @@ char * ble_sywee_history(uint8_t day,uint16_t *len ,uint8_t type)
               
                 break;
             case 0x47://同步距离历史数据
-                if(cywee_get_now_hour_data(&f_value,CYWEE_SAVE_DATA_DISTANCE))
+                if(cywee_get_now_hour_data(&f_value,DISTANCE))
                 {
                     if(f_value>0)
                     {
@@ -3207,7 +3207,7 @@ char * ble_sywee_history(uint8_t day,uint16_t *len ,uint8_t type)
         {
             case 0x43: //同步步数历史数据
 
-                if( cywee_get_now_hour_data(&value,CYWEE_SAVE_DATA_STEP))
+                if( cywee_get_now_hour_data(&value,STEP))
                 {
                     if(value>0)
                     {
@@ -3220,7 +3220,7 @@ char * ble_sywee_history(uint8_t day,uint16_t *len ,uint8_t type)
               
                 break;
             case 0x44://同步燃脂时间数据
-                if(cywee_get_now_hour_data(&value_16,CYWEE_SAVE_DATA_FAT))
+                if(cywee_get_now_hour_data(&value_16,FAT))
                 {
                      if(value_16>0)
                     {
@@ -3243,7 +3243,7 @@ char * ble_sywee_history(uint8_t day,uint16_t *len ,uint8_t type)
                
                 break;
             case 0x46://同步卡路里历史数据
-                if(cywee_get_now_hour_data(&f_value,CYWEE_SAVE_DATA_CALORIES))
+                if(cywee_get_now_hour_data(&f_value,CALORIES))
                 {   
                     if(f_value>0)
                     {
@@ -3256,7 +3256,7 @@ char * ble_sywee_history(uint8_t day,uint16_t *len ,uint8_t type)
               
                 break;
             case 0x47://同步距离历史数据
-                if(cywee_get_now_hour_data(&f_value,CYWEE_SAVE_DATA_DISTANCE))
+                if(cywee_get_now_hour_data(&f_value,DISTANCE))
                 {
                     if(f_value>0)
                     {
index 9cb2067..9689bda 100644 (file)
@@ -51,6 +51,10 @@ extern "C"
 #include "factorytest_protocol.h"
 #endif
 
+#ifdef SUPPORT_CYWEE_SERVICE
+#include "cywee_data.h"
+#endif
+
 
 //进行修复开始
 void repair_file_start(void){}
@@ -172,16 +176,24 @@ static void custom_fileoperate_service_check_task(void const *arg)
         case CUSTOM_FILEOPERATE_MSG_TYPE_MESSAGEDATA_SAVE:
             break;
         case CUSTOM_FILEOPERATE_MSG_TYPE_SLEEPDATA_SAVE:
-            // cywee_custom_save_sleep_data();
+#ifdef SUPPORT_CYWEE_SERVICE
+            cywee_custom_save_sleep_data();
+#endif
             break;
         case CUSTOM_FILEOPERATE_MSG_TYPE_NAPDATA_SAVE:
-            // cywee_custom_save_nap_data();
+#ifdef SUPPORT_CYWEE_SERVICE
+            cywee_custom_save_nap_data();
+#endif
             break;
         case CUSTOM_FILEOPERATE_MSG_TYPE_SLEEPDATA_READ:
+#ifdef SUPPORT_CYWEE_SERVICE
             custom_read_sleep_data();
+#endif
             break;
         case CUSTOM_FILEOPERATE_MSG_TYPE_NAPDATA_READ:
+#ifdef SUPPORT_CYWEE_SERVICE
             custom_read_nap_data();
+#endif
             break;
         case CUSTOM_FILEOPERATE_MSG_TYPE_SLEEPMODLE_UPDATE:
             custom_sleep_model_updata();
@@ -222,7 +234,9 @@ static void custom_fileoperate_service_check_task(void const *arg)
             break;
 
         case CUSTOM_FILEOPERATE_MSG_TYPE_WEAR_DATA_READ:
+#ifdef SUPPORT_CYWEE_SERVICE
             custom_read_wear_data();
+#endif
             break;
 
         case CUSTOM_FILEOPERATE_MSG_TYPE_WEAR_DATA_SAVE:
@@ -240,7 +254,11 @@ static void custom_fileoperate_service_check_task(void const *arg)
         case CUSTOM_FILEOPERATE_MSG_TYPE_MESSAGE_DATA_NOTIFY:
             // show_notify_messgae();
             break;
-
+        case CUSTOM_FILEOPERATE_MSG_TYPE_SPORTDATA_READ:
+#ifdef SUPPORT_CYWEE_SERVICE
+            cywee_restoreData();
+#endif
+            break;
             PRINT("Unknown CUSTOM_FILE_OPERATE_MSG cmd 0x%02X \r\n", mail.cmd);
             break;
         }
index abf6b47..2ca789d 100644 (file)
@@ -322,9 +322,9 @@ void shutdown_reboot_prejobs_task(void)
     
     //保存步数
     // do_cywee_service_check_msg(CYWEE_SERVICE_CMD_SAVE_DATA,NULL);
-    #ifdef FD230_650
+#ifdef SUPPORT_CYWEE_SERVICE
     cywee_save_data();
-    #endif
+#endif
 
    // addressbookTowrite();//同步数据存储
 
index f355bec..cff261e 100644 (file)
@@ -310,6 +310,8 @@ errcode_t do_custom_cmd_service_check_msg_head(int cmd, void *params, int paraml
 
 #define CUSTOM_FILEOPERATE_MSG_TYPE_MESSAGE_DATA_NOTIFY 0x16 //消息数据
 
+#define CUSTOM_FILEOPERATE_MSG_TYPE_SPORTDATA_READ 0x17 //运动数据
+
 errcode_t uapi_custom_fileoperate_service_init(void);
 errcode_t do_custom_fileoperate_service_check_msg(int cmd, void *params, int paramlen);