hengai k18 sleep
author@CHENG <2393524978@qq.com>
Fri, 11 Oct 2024 04:13:08 +0000 (12:13 +0800)
committer@CHENG <2393524978@qq.com>
Fri, 11 Oct 2024 04:13:08 +0000 (12:13 +0800)
2.sdk/sdk/gui/lv_watch/include/ui_nvm_interface.h
2.sdk/sdk/gui/lv_watch/lv_apps/custom_function/heng_ai_http_protocol.c
2.sdk/sdk/gui/lv_watch/lv_apps/custom_function/heng_ai_sleep_k18.c
2.sdk/sdk/gui/lv_watch/lv_apps/custom_function/heng_ai_sleep_k18.h
2.sdk/sdk/gui/lv_watch/mmi_protocol/mmi_protocol_fzd.c
2.sdk/sdk/gui/lv_watch/mmi_protocol/mmi_protocol_fzd.h
2.sdk/sdk/gui/lv_watch/mmi_protocol/mmi_protocol_fzd_content.c
2.sdk/sdk/gui/lv_watch/mmi_sundry/mmi_sundry.c

index f51d258..195afb4 100644 (file)
@@ -474,6 +474,9 @@ typedef struct
        char token[NV_HENGAI_HEALTH_TOKEN_LEN + 1];
        uint8_t is_calibrated; // 0-not calibrated; 1-calibrated
        hal_rtc_t calibrate_time;
+#ifdef __MMI_CUSTOM_HENGAI_SLEEP_K18__
+       uint8_t is_sleep_activated; // 0-not activated; 1-activated
+#endif
 } __packed nv_watch_hengai_health_data_t;
 #endif
 
index da2aad3..2e1dac0 100644 (file)
@@ -1100,6 +1100,7 @@ FREE_AND_EXIT:
 void mmi_hengai_tcp_health_lib_activation_check_action(void)
 {
        HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__);
+       UART_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__);
        
        if(0 == mmi_hengai_health_lib_activated_flag_get())
        {
@@ -1194,11 +1195,20 @@ void mmi_hengai_tcp_health_lib_activation_check_action(void)
                        data_ptr = NULL;
                }
        }
+       else
+       {
+               HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__);
+               UART_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__);
+       #ifdef __MMI_CUSTOM_HENGAI_SLEEP_K18__
+               mmi_hengai_health_sleep_activation_check();
+       #endif
+       }
 }
 
 void mmi_hengai_tcp_algorithm_interface_login_action(void)
 {
        HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__);
+       UART_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__);
        
        char * token = mmi_hengai_health_token_get();
        if(0 == strlen(token))
@@ -1301,6 +1311,29 @@ void mmi_hengai_tcp_algorithm_interface_login_action(void)
        }
 }
 
+static void * s_delay_timer_id = NULL;
+static void mmi_hengai_tcp_algorithm_login_cb(uint32_t para)
+{
+       if(NULL != s_delay_timer_id)
+       {
+               uos_timer_stop(s_delay_timer_id);
+               uos_timer_delete(s_delay_timer_id);
+       }
+       
+       mmi_hengai_tcp_algorithm_interface_login_action();
+}
+
+void mmi_hengai_tcp_algorithm_login_action(void)
+{
+       HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__);
+       if(NULL == s_delay_timer_id)
+       {
+               uos_timer_create(&s_delay_timer_id);
+       }
+       uos_timer_stop(s_delay_timer_id);
+       uos_timer_start(s_delay_timer_id, MS_TO_TICKS(1000*10), 0, mmi_hengai_tcp_algorithm_login_cb, NULL);
+}
+
 bool mmi_hengai_health_data_parse(unsigned char * next_buff, unsigned int next_buff_len)
 {
        if(NULL == next_buff || 0 == next_buff_len)
@@ -1309,11 +1342,11 @@ bool mmi_hengai_health_data_parse(unsigned char * next_buff, unsigned int next_b
                return false;
        }
 
-       HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: %d\n", __FUNCTION__, __LINE__, next_buff_len);
-       HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG]: %s\n", next_buff);
-       HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG]: %s\n", next_buff + 90);
-       HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG]: %s\n", next_buff + 180);
-       HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG]: %s\n", next_buff + 270);
+       //HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: %d\n", __FUNCTION__, __LINE__, next_buff_len);
+       //HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG]: %s\n", next_buff);
+       //HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG]: %s\n", next_buff + 90);
+       //HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG]: %s\n", next_buff + 180);
+       //HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG]: %s\n", next_buff + 270);
 
        uint32_t output_len = 0;
        char * t_decode_str = lv_mem_alloc(next_buff_len);
@@ -1333,11 +1366,13 @@ bool mmi_hengai_health_data_parse(unsigned char * next_buff, unsigned int next_b
                return false;
        }
 
-       HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: %d\n", __FUNCTION__, __LINE__, strlen(t_decode_str));
-       HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG]: %s\n", t_decode_str);
-       HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG]: %s\n", t_decode_str + 90);
-       HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG]: %s\n", t_decode_str + 180);
-       HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG]: %s\n", t_decode_str + 270);
+       //HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: %d\n", __FUNCTION__, __LINE__, strlen(t_decode_str));
+       HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG][%d]: %s\n", __LINE__, t_decode_str);
+       //HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG]: %s\n", t_decode_str + 90);
+       //HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG]: %s\n", t_decode_str + 180);
+       //HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG]: %s\n", t_decode_str + 270);
+       //mmi_debug_info_write_to_file("C:/data_parse.txt", t_decode_str, strlen(t_decode_str));
+       UART_DEBUG_PRINTF("[@CHENG_DEBUG][%d]: %s\n", __LINE__, t_decode_str);
        
        cJSON * json_recv = cJSON_Parse(t_decode_str);
        if(NULL != json_recv)
@@ -2380,48 +2415,27 @@ uint8_t mmi_hengai_health_lib_activated_flag_get(void)
        return flag;
 }
 
-void mmi_hengai_health_activated_flag_set(uint8_t flag)
-{
-/*
-       s_hengai_health_data.is_activated = flag;
-       mmi_hengai_health_data_nv_write();
-*/
-}
-
 char * mmi_hengai_health_lib_req_code_get(void)
 {
-       //return (s_hengai_health_data.req_code);
        char * req_code = get_HA_req_code();
        HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: req_code=\n", __FUNCTION__, __LINE__);
-       HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG]: %s\n", req_code);
+       HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG][%d]: %s\n", __LINE__, req_code);
        
        return req_code;
 }
 
-void mmi_hengai_health_req_code_set(char * req_code)
+char * mmi_hengai_health_lib_act_code_get(void)
 {
-/*
-       if(NULL == req_code)
-               return;
+       char * act_code = get_HA_key_code();
+       HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: act_code=\n", __FUNCTION__, __LINE__);
+       HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG][%d]: %s\n", __LINE__, act_code);
        
-       if(NV_HENGAI_HEALTH_REQ_CODE_LEN < strlen(req_code))
-               return;
-
-       HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__);
-       HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG]: %s\n", req_code);
-       _lv_memcpy(s_hengai_health_data.req_code, req_code, strlen(req_code));
-       mmi_hengai_health_data_nv_write();
-*/
-}
-
-char * mmi_hengai_health_act_code_get(void)
-{
-       //return (s_hengai_health_data.act_code);
+       return act_code;
 }
 
 void mmi_hengai_health_lib_act_code_set(char * act_code)
 {
-       HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: act_code=\n", __FUNCTION__, __LINE__);
+       HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: %d,act_code=\n", __FUNCTION__, __LINE__, strlen(act_code));
        HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG]: %s\n", act_code);
 /*
        if(NULL == act_code)
@@ -2435,6 +2449,7 @@ void mmi_hengai_health_lib_act_code_set(char * act_code)
 */
        int ret = HA_lib_activate(act_code);
        HENGAI_HEALTH_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: ret=%d\n", __FUNCTION__, __LINE__, ret);
+       UART_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: ret=%d\n", __FUNCTION__, __LINE__, ret);
        if(ret)
        {
        #ifdef __MMI_CUSTOM_HENGAI_HEALTH_UPLOAD_USE_TCP__
@@ -2442,11 +2457,11 @@ void mmi_hengai_health_lib_act_code_set(char * act_code)
        #else
                mmi_hengai_health_lib_activation_feedback();
        #endif
-       #ifdef __MMI_CUSTOM_HENGAI_SLEEP_K18__
-               char * req_code = mmi_hengai_health_lib_req_code_get();
-               mmi_hengai_health_sleep_lib_active(req_code, act_code);
-       #endif
        }
+
+#ifdef __MMI_CUSTOM_HENGAI_SLEEP_K18__
+       mmi_hengai_health_sleep_lib_active();
+#endif
 }
 
 char * mmi_hengai_health_token_get(void)
@@ -2501,6 +2516,28 @@ void mmi_hengai_bp_calibrated_time_get(hal_rtc_t * time_ptr)
        _lv_memcpy(time_ptr, &(s_hengai_health_data.calibrate_time), sizeof(hal_rtc_t));
 }
 
+#ifdef __MMI_CUSTOM_HENGAI_SLEEP_K18__
+void mmi_hengai_health_sleep_activated_flag_set(uint8_t flag)
+{
+       s_hengai_health_data.is_sleep_activated = flag;
+       mmi_hengai_health_data_nv_write();
+}
+
+uint8_t mmi_hengai_health_sleep_activated_flag_get(void)
+{
+       return (s_hengai_health_data.is_sleep_activated);
+}
+
+void mmi_hengai_health_sleep_activation_check(void)
+{
+       if(0 == mmi_hengai_health_sleep_activated_flag_get())
+       {               
+               mmi_hengai_health_sleep_lib_active();
+       }
+}
+#endif
+
+
 #endif
 
 
index 6ca493d..9415a5b 100644 (file)
@@ -20,273 +20,31 @@ static sleep_data_t s_hengai_sdata = {0};
 static void mmi_hengai_gsensor_data_get(uint32_t para);
 
 
-
-#ifdef __MMI_HENG_AI_DEBUG__
-static uint8_t s_gsensor_upload_switch = 0; // 0-off; 1-on
-static char s_gsensor_buff_send[45000] = {0}; // 3000 * 3 * (4 + 1)
-
-#define HENGAI_SLEEP_RESULT_FILE       "C:/hengai_sleep_result.txt"
-
-
-void mmi_heng_ai_gsensor_upload_action(void)
+static bool mmi_hengai_sleep_data_send(void)
 {
-       if(0 == s_gsensor_upload_switch)
-               return;
-
-       _lv_memset_00(s_gsensor_buff_send, sizeof(s_gsensor_buff_send));
-
-       char * temp_ptr = s_gsensor_buff_send;
-       uint32_t counter = 0;
-       uint32_t index = 0;
-       for(index = 0; index < (HENGAI_SLEEP_GSENSOR_DATA_MAX / 3); index++)
-       {
-               temp_ptr += counter;
-               sprintf(temp_ptr, "%d,%d,%d,%d,%d,%d,%d,%d,%d,",
-                                                       s_hengai_sleep_gsensor_data[index].x,
-                                                       s_hengai_sleep_gsensor_data[index].y,
-                                                       s_hengai_sleep_gsensor_data[index].z,
-                                                       s_hengai_sleep_gsensor_data[index + 1].x,
-                                                       s_hengai_sleep_gsensor_data[index + 1].y,
-                                                       s_hengai_sleep_gsensor_data[index + 1].z,
-                                                       s_hengai_sleep_gsensor_data[index + 2].x,
-                                                       s_hengai_sleep_gsensor_data[index + 2].y,
-                                                       s_hengai_sleep_gsensor_data[index + 2].z);
-               counter = strlen(temp_ptr);
-       }
+       PROTOCOL_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__);
        
-       mmi_protocol_fzd_action_hengai_gsensor_data(s_gsensor_buff_send, strlen(s_gsensor_buff_send));
-}
-
-void mmi_heng_ai_gsensor_upload_switch_set(uint8_t value)
-{
-       s_gsensor_upload_switch = value;
-}
-
-void mmi_hengai_data_save_to_file(char * path, void * data_buf, uint32_t data_size)
-{
-       lv_fs_file_t file_p;
-       lv_fs_res_t res;
-       uint32_t bytes_write = 0;
-
-       res = lv_fs_open(&file_p, path, LV_FS_MODE_WR | LV_FS_MODE_APPEND);
-       if(LV_FS_RES_OK != res) 
-       {
-               printf("[@CHENG_DEBUG][%s][%d]: errno=%d\n", __FUNCTION__, __LINE__, res);
-               lv_fs_close(&file_p);
-               return false;
-       }
-
-       res = lv_fs_write(&file_p, data_buf, data_size, &bytes_write);
-       lv_fs_close(&file_p);
-       if(LV_FS_RES_OK != res)
-       {
-               printf("[@CHENG_DEBUG][%s][%d]: errno=%d\n", __FUNCTION__, __LINE__, res);
-               return false;
-       }
-       printf("[@CHENG_DEBUG][%s][%d]: file_size=%d,write_size=%d\n", __FUNCTION__, __LINE__, data_size, bytes_write);
-
-       return true;
-}
-
-#define HENGAI_SLEEP_RESULT_FILE       "C:/hengai_sleep_result.txt"
-
-void mmi_hengai_sleep_result_save(sleep_time_t * curtime, int result)
-{
-       char * temp_buff = NULL;
-       uint32_t buff_size = 64;
-
-       temp_buff = lv_mem_alloc(buff_size + 1);
-       if(NULL == temp_buff)
-       {
-               printf("[@CHENG_DEBUG][%s][%d]: memory alloc failed\n", __FUNCTION__, __LINE__);
-               return;
-       }
-       _lv_memset_00(temp_buff, buff_size + 1);
-
-       sprintf(temp_buff, "%d,%d,%d,%d,%d:%d;",
-                                               curtime->year,
-                                               curtime->month,
-                                               curtime->day,
-                                               curtime->hour,
-                                               curtime->minute,
-                                               result);
-
-       mmi_hengai_data_save_to_file(HENGAI_SLEEP_RESULT_FILE, temp_buff, strlen(temp_buff));
-       
-       if(NULL != temp_buff)
-       {
-               lv_mem_free(temp_buff);
-               temp_buff = NULL;
-       }
-}
-
-bool mmi_hengai_sleep_result_send(void)
-{
-       char * file_buf = NULL;
-       uint32_t file_size = 0;
-       lv_fs_file_t file_p;
-       lv_fs_res_t res;
-       uint32_t bytes_read = 0;
-
-       res = lv_fs_open(&file_p, HENGAI_SLEEP_RESULT_FILE, LV_FS_MODE_RD);
-       if(LV_FS_RES_OK != res) 
-       {
-               printf("[@CHENG_DEBUG][%s][%d]: errno=%d\n", __FUNCTION__, __LINE__, res);
-               goto exit_free_res;
-       }
-
-       lv_fs_size(&file_p, &file_size);
-       file_buf = (char *)lv_mem_alloc(file_size + 1);
-       if(NULL == file_buf)
-       {
-               printf("[@CHENG_DEBUG][%s][%d]: memory alloce fail\n", __FUNCTION__, __LINE__);
-               goto exit_free_res;
-       }
-       _lv_memset_00(file_buf, file_size + 1);
-       res = lv_fs_read(&file_p, file_buf, file_size, &bytes_read);
-       if(LV_FS_RES_OK != res)
-       {
-               printf("[@CHENG_DEBUG][%s][%d]: errno=%d\n", __FUNCTION__, __LINE__, res);
-               goto exit_free_res;
-       }
-       printf("[@CHENG_DEBUG][%s][%d]: file_size=%d,bytes_read=%d,file_buf=%p\n", __FUNCTION__, __LINE__, file_size, bytes_read, file_buf);
-
-       //mmi_protocol_fzd_action_sleep_result(file_buf, file_size);
-       mmi_protocol_fzd_action_hengai_sleep_data_test(file_buf, file_size);
-
-
-exit_free_res:
-       lv_fs_close(&file_p);
-       if(NULL != file_buf)
-       {
-               lv_mem_free(file_buf);
-               file_buf = NULL;
-       }
-}
-
-bool mmi_hengai_sleep_data_test_send(void)
-{
        char * temp_buff = NULL;
        uint32_t buff_size = sizeof(sleep_data_t);
        char * temp_ptr = NULL;
        uint32_t temp_count = 0;
        uint8_t i = 0;
 
-       temp_buff = lv_mem_alloc(buff_size + 1);
+       temp_buff = lv_mem_alloc(buff_size+ 32 + 1);
        if(NULL == temp_buff)
        {
                printf("[@CHENG_DEBUG][%s][%d]: memory alloc failed\n", __FUNCTION__, __LINE__);
                return;
        }
-       _lv_memset_00(temp_buff, buff_size + 1);
+       _lv_memset_00(temp_buff, buff_size + 32 + 1);
 
        temp_count = 0;
        temp_ptr = temp_buff + temp_count;
-       sprintf(temp_ptr, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
-                                               s_hengai_sdata.total_sleep_time,
-                                               s_hengai_sdata.begin_sleep_time.year,
-                                               s_hengai_sdata.begin_sleep_time.month,
-                                               s_hengai_sdata.begin_sleep_time.day,
-                                               s_hengai_sdata.begin_sleep_time.hour,
-                                               s_hengai_sdata.begin_sleep_time.minute,
-                                               s_hengai_sdata.end_sleep_time.year,
-                                               s_hengai_sdata.end_sleep_time.month,
-                                               s_hengai_sdata.end_sleep_time.day,
-                                               s_hengai_sdata.end_sleep_time.hour,
-                                               s_hengai_sdata.end_sleep_time.minute);
-       temp_count = strlen(temp_ptr);
 
-       temp_ptr += temp_count;
-       sprintf(temp_ptr, ",%d", s_hengai_sdata.state_count);
+       sprintf(temp_ptr, ",HENGAI_SLEEP_DATA,");
        temp_count = strlen(temp_ptr);
-       
-       for(i = 0; i < s_hengai_sdata.state_count; i++)
-       {
-               temp_ptr += temp_count;
-               sprintf(temp_ptr, ",%d,%d", s_hengai_sdata.data[i].duration, s_hengai_sdata.data[i].state);
-               temp_count = strlen(temp_ptr);
-       }
-       
-       mmi_protocol_fzd_action_hengai_sleep_data_test(temp_buff, strlen(temp_buff));
-
-       if(NULL != temp_buff)
-       {
-               lv_mem_free(temp_buff);
-               temp_buff = NULL;
-       }
-}
-
-
-//#ifndef __MMI_HENG_AI_DEBUG__
-//#define __MMI_HENG_AI_DEBUG__
-//#endif
-
-static uint32_t __sleep_gsensor_counter = 0;
-
-void mmi_hengai_sleep_data_get(void);
-
-void __gsensor_data_set(unsigned char * next_buff, unsigned int next_buff_len)
-{
-#ifdef __MMI_HENG_AI_DEBUG__
-       // 300 set datas per 3 seconds
-       uint32_t index = 0;
-       char * temp_ptr = NULL;
-       uint32_t i = 0;
-       
-       for(i = 0; i < 300; i++)
-       {
-               index = __sleep_gsensor_counter + i;
-               
-               temp_ptr = km_strtok_r(NULL, ",", &next_buff);
-               s_hengai_sleep_gsensor_data[index].x = atoi(temp_ptr);
-
-               temp_ptr = km_strtok_r(NULL, ",", &next_buff);
-               s_hengai_sleep_gsensor_data[index].y = atoi(temp_ptr);
-               
-               temp_ptr = km_strtok_r(NULL, ",", &next_buff);
-               s_hengai_sleep_gsensor_data[index].z = atoi(temp_ptr);
-       }
-
-       __sleep_gsensor_counter += 300;
-       printf("[@CHENG_DEBUG][%s][%d]: %d\n", __FUNCTION__, __LINE__, __sleep_gsensor_counter);
-       if(HENGAI_SLEEP_GSENSOR_DATA_MAX <= __sleep_gsensor_counter)
-       {
-               printf("[@CHENG_DEBUG][%d]: %d,%d,%d,%d,%d,%d\n", __LINE__,
-                                                                       s_hengai_sleep_gsensor_data[0].x,
-                                                                       s_hengai_sleep_gsensor_data[0].y,
-                                                                       s_hengai_sleep_gsensor_data[0].z,
-                                                                       s_hengai_sleep_gsensor_data[1].x,
-                                                                       s_hengai_sleep_gsensor_data[1].y,
-                                                                       s_hengai_sleep_gsensor_data[1].z
-                                                                       );
-               
-               __sleep_gsensor_counter = 0;
-               mmi_hengai_sleep_data_get();
-       }
-#endif
-}
-
-#endif
-
 
-bool mmi_hengai_sleep_data_send(void)
-{
-       char * temp_buff = NULL;
-       uint32_t buff_size = sizeof(sleep_data_t);
-       char * temp_ptr = NULL;
-       uint32_t temp_count = 0;
-       uint8_t i = 0;
-
-       temp_buff = lv_mem_alloc(buff_size + 1);
-       if(NULL == temp_buff)
-       {
-               printf("[@CHENG_DEBUG][%s][%d]: memory alloc failed\n", __FUNCTION__, __LINE__);
-               return;
-       }
-       _lv_memset_00(temp_buff, buff_size + 1);
-
-       temp_count = 0;
-       temp_ptr = temp_buff + temp_count;
+       temp_ptr += temp_count;
        sprintf(temp_ptr, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
                                                s_hengai_sdata.total_sleep_time,
                                                s_hengai_sdata.begin_sleep_time.year,
@@ -312,7 +70,8 @@ bool mmi_hengai_sleep_data_send(void)
                temp_count = strlen(temp_ptr);
        }
        
-       mmi_protocol_fzd_action_hengai_sleep_data(temp_buff, strlen(temp_buff));
+       //mmi_protocol_fzd_action_hengai_sleep_data(temp_buff, strlen(temp_buff));
+       mmi_protocol_fzd_action_tcp_http(temp_buff, strlen(temp_buff));
 
        if(NULL != temp_buff)
        {
@@ -321,7 +80,7 @@ bool mmi_hengai_sleep_data_send(void)
        }
 }
 
-void mmi_hengai_sleep_data_get(void)
+static void mmi_hengai_sleep_data_get(void)
 {
        sleep_time_t curtime = {0};
        hal_rtc_t cur_time = {0};
@@ -336,17 +95,11 @@ void mmi_hengai_sleep_data_get(void)
        int result = 0;
        result = get_sleep_time(s_hengai_sleep_gsensor_data, HENGAI_SLEEP_GSENSOR_DATA_MAX, curtime, &s_hengai_sdata);
        printf("[@CHENG_DEBUG][%s][%d]: result=%d\n", __FUNCTION__, __LINE__, result);
+       UART_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: result=%d\n", __FUNCTION__, __LINE__, result);
        if(1 == result)
        {
                mmi_hengai_sleep_data_send();           
        }
-#ifdef __MMI_HENG_AI_DEBUG__
-       else
-       {
-               mmi_hengai_sleep_data_test_send();
-       }
-       mmi_hengai_sleep_result_save(&curtime, result);
-#endif
 
        _lv_memset_00(s_hengai_sleep_gsensor_data, sizeof(s_hengai_sleep_gsensor_data));
        mmi_hengai_gsensor_data_get(0);
@@ -354,7 +107,6 @@ void mmi_hengai_sleep_data_get(void)
 
 static void mmi_hengai_gsensor_data_get(uint32_t para)
 {
-#ifndef __MMI_HENG_AI_DEBUG__
        int16_t t_mems_data[32 * 3] = {0};
        uint8_t i = 0;
        
@@ -373,9 +125,6 @@ static void mmi_hengai_gsensor_data_get(uint32_t para)
        {
                uos_timer_stop(s_hengai_sleep_gsensor_timer_id);
                s_hengai_sleep_gsensor_counter = 0;
-       #ifdef __MMI_HENG_AI_DEBUG__
-               mmi_heng_ai_gsensor_upload_action();
-       #endif
                mmi_hengai_sleep_data_get();
        }
        else
@@ -383,13 +132,12 @@ static void mmi_hengai_gsensor_data_get(uint32_t para)
                uos_timer_stop(s_hengai_sleep_gsensor_timer_id);
                uos_timer_start(s_hengai_sleep_gsensor_timer_id, MS_TO_TICKS(600), 0, mmi_hengai_gsensor_data_get, NULL);
        }
-#endif
 }
 
 void mmi_hengai_get_sleep_data_start(void)
 {
-#ifndef __MMI_HENG_AI_DEBUG__
        printf("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__);
+       UART_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__);
        
        if(NULL != s_hengai_sleep_gsensor_timer_id)
                uos_timer_stop(s_hengai_sleep_gsensor_timer_id);
@@ -403,12 +151,10 @@ void mmi_hengai_get_sleep_data_start(void)
     init_sleep_data(&s_hengai_sdata);
     
        uos_timer_start(s_hengai_sleep_gsensor_timer_id, MS_TO_TICKS(600), 0, mmi_hengai_gsensor_data_get, NULL);
-#endif
 }
 
 void mmi_hengai_get_sleep_data_stop(void)
 {
-#ifndef __MMI_HENG_AI_DEBUG__
        printf("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__);
 
        if(NULL != s_hengai_sleep_gsensor_timer_id)
@@ -419,21 +165,47 @@ void mmi_hengai_get_sleep_data_stop(void)
 
        s_hengai_sleep_gsensor_counter = 0;
        _lv_memset_00(s_hengai_sleep_gsensor_data, sizeof(s_hengai_sleep_gsensor_data));
-#else
-       mmi_hengai_sleep_result_send();
-       lv_fs_remove(HENGAI_SLEEP_RESULT_FILE);
-#endif
 }
 
-void mmi_hengai_health_sleep_lib_active(char * req_code, char * act_code)
+/*
+static unsigned char s_sleep_req_code[128 + 1] = {0};
+static char * mmi_hengai_health_sleep_req_code_get(void)
 {
-       if(NULL == req_code || NULL == act_code)
-               return;
-       
+       if(0 == strlen(s_sleep_req_code))
+       {
+               char imei[16 + 1] = {0};
+               app_adp_get_imei_req(imei);
+               
+               unsigned int* req_len = 0;
+               //UART_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__);
+               request_validation((unsigned char *)"ZHSX", 4, (unsigned char *)imei, strlen(imei), (unsigned char *)s_sleep_req_code, &req_len);
+       }
+
+       return s_sleep_req_code;
+}
+*/
+
+void mmi_hengai_health_sleep_lib_active(void)
+{      
+       char * req_code = mmi_hengai_health_lib_req_code_get();
        printf("[@CHENG_DEBUG][%s][%d]: req_code=%s\n", __FUNCTION__, __LINE__, req_code);
+       UART_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: req_code=%s\n", __FUNCTION__, __LINE__, req_code);
+       if(NULL == req_code)
+               return;
+
+       char * act_code = mmi_hengai_health_lib_act_code_get();
        printf("[@CHENG_DEBUG][%s][%d]: act_code=%s\n", __FUNCTION__, __LINE__, act_code);
+       UART_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: act_code=%s\n", __FUNCTION__, __LINE__, act_code);
+       if(NULL == act_code)
+               return;
+       
        int ret = activate_algorithm((unsigned char *)req_code, strlen(req_code), (unsigned char *)act_code, strlen(act_code));
        printf("[@CHENG_DEBUG][%s][%d]: ret=%d\n", __FUNCTION__, __LINE__, ret);
+       UART_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: ret=%d\n", __FUNCTION__, __LINE__, ret);
+       if(ret)
+       {
+               mmi_hengai_health_sleep_activated_flag_set(1);
+       }
 }
 #endif
 
index a001880..1d8d3fa 100644 (file)
@@ -22,7 +22,7 @@ extern "C" {
 void mmi_hengai_get_sleep_data_start(void);
 void mmi_hengai_get_sleep_data_stop(void);
 
-void mmi_hengai_health_sleep_lib_active(char * req_code, char * act_code);
+void mmi_hengai_health_sleep_lib_active(void);
 
 
 #endif
index b31ec45..cb1dd30 100644 (file)
@@ -564,7 +564,8 @@ bool mmi_protocol_fzd_parse_LINK(unsigned char * next_buff, unsigned int next_bu
 {
 #ifdef __MMI_CUSTOM_HENGAI_HEALTH__
 #ifdef __MMI_CUSTOM_HENGAI_HEALTH_UPLOAD_USE_TCP__
-       mmi_hengai_tcp_algorithm_interface_login_action();
+       //mmi_hengai_tcp_algorithm_interface_login_action();
+       mmi_hengai_tcp_algorithm_login_action();
 #else
        mmi_hengai_algorithm_interface_login_action();
        mmi_hengai_health_lib_activation_check_action();
@@ -3654,7 +3655,7 @@ bool mmi_protocol_fzd_action_hengai_activation_feedback(void)
 }
 #endif
 
-#if defined(__MMI_CUSTOM_HENGAI_SLEEP__) || defined(__MMI_CUSTOM_HENGAI_SLEEP_K18__)
+#if defined(__MMI_CUSTOM_HENGAI_SLEEP__) // || defined(__MMI_CUSTOM_HENGAI_SLEEP_K18__)
 bool mmi_protocol_fzd_action_hengai_sleep_data(char * file_buf, uint32_t file_size)
 {
        bool result = false;
@@ -3864,6 +3865,7 @@ bool mmi_protocol_fzd_action_tcp_http(char * data_ptr, uint32_t data_len)
 #if 1
        PROTOCOL_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: %d\n", __FUNCTION__, __LINE__, data_len);
        PROTOCOL_DEBUG_PRINTF("[@CHENG_DEBUG][%d]: %s\n", __LINE__, data_ptr);
+       UART_DEBUG_PRINTF("[@CHENG_DEBUG][%d]: %s\n", __LINE__, data_ptr);
 
        result = mmi_protocol_fzd_send_with_data(action, data_ptr, data_len);
 #else
index 63b6e3a..ab8a29d 100644 (file)
@@ -194,7 +194,7 @@ typedef enum
        MMI_FZD_ACTION_HENGAI_ACTIVATION,
        MMI_FZD_ACTION_HENGAI_ACTIVATION_FEEDBACK,
 #endif
-#if defined(__MMI_CUSTOM_HENGAI_SLEEP__) || defined(__MMI_CUSTOM_HENGAI_SLEEP_K18__)
+#if defined(__MMI_CUSTOM_HENGAI_SLEEP__) // || defined(__MMI_CUSTOM_HENGAI_SLEEP_K18__)
        MMI_FZD_ACTION_HENGAI_SLEEP_DATA,
 #if 0
 MMI_FZD_ACTION_GSENSOR_DATA_UPLOAD,
@@ -368,7 +368,7 @@ bool mmi_protocol_fzd_action_hengai_activation(char * req_code);
 bool mmi_protocol_fzd_parse_ACTION_HENGAI_ACTIVATION(unsigned char * next_buff, unsigned int next_buff_len);
 bool mmi_protocol_fzd_action_hengai_activation_feedback(void);
 #endif
-#if defined(__MMI_CUSTOM_HENGAI_SLEEP__) || defined(__MMI_CUSTOM_HENGAI_SLEEP_K18__)
+#if defined(__MMI_CUSTOM_HENGAI_SLEEP__) // || defined(__MMI_CUSTOM_HENGAI_SLEEP_K18__)
 bool mmi_protocol_fzd_action_hengai_sleep_data(char * file_buf, uint32_t file_size);
 #endif
 #ifdef __MMI_CUSTOM_HENGAI_TCMS__
index 1fedb8f..1312f4f 100644 (file)
@@ -126,7 +126,7 @@ static unsigned char * mmi_protocol_fzd_action_string_get(MMI_PROTOCOL_FZD_ACTIO
                        {MMI_FZD_ACTION_HENGAI_ACTIVATION, "HENGAI_ACTIVATION"},
                        {MMI_FZD_ACTION_HENGAI_ACTIVATION_FEEDBACK, "HENGAI_ACTIVATION_FEEDBACK"},
                #endif
-               #if defined(__MMI_CUSTOM_HENGAI_SLEEP__) || defined(__MMI_CUSTOM_HENGAI_SLEEP_K18__)
+               #if defined(__MMI_CUSTOM_HENGAI_SLEEP__) // || defined(__MMI_CUSTOM_HENGAI_SLEEP_K18__)
                        {MMI_FZD_ACTION_HENGAI_SLEEP_DATA, "HENGAI_SLEEP_DATA"},
 
                        #if 0
@@ -449,7 +449,7 @@ static bool mmi_protocol_fzd_content_parse(unsigned char * content_ptr, unsigned
                case MMI_FZD_ACTION_HENGAI_ACTIVATION_FEEDBACK:
                        break;
        #endif
-       #if defined(__MMI_CUSTOM_HENGAI_SLEEP__) || defined(__MMI_CUSTOM_HENGAI_SLEEP_K18__)
+       #if defined(__MMI_CUSTOM_HENGAI_SLEEP__) // || defined(__MMI_CUSTOM_HENGAI_SLEEP_K18__)
                case MMI_FZD_ACTION_HENGAI_SLEEP_DATA:
                        break;
 
index 152f6cd..04ec650 100644 (file)
@@ -1327,8 +1327,16 @@ void mmi_watch_sleep_time_mission_check(void)
                SUNDRY_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__);
                if(0 == s_sleep_mission_in_progress)
                {
+               #ifdef __MMI_CUSTOM_HENGAI_SLEEP_K18__
+                       if(0 != mmi_hengai_health_sleep_activated_flag_get())
+                       {
+                               s_sleep_mission_in_progress = 1;
+                               mmi_watch_get_sleep_data_start();
+                       }
+               #else
                        s_sleep_mission_in_progress = 1;
                        mmi_watch_get_sleep_data_start();
+               #endif
                }
        }
        else