hengai
authorCCC <2393524978@qq.com>
Fri, 8 Dec 2023 01:38:40 +0000 (09:38 +0800)
committerCCC <2393524978@qq.com>
Fri, 8 Dec 2023 01:38:40 +0000 (09:38 +0800)
2.sdk/sdk/gui/lv_watch/lv_apps/custom_function/heng_ai_sleep_activation.c
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

index b0d240a..82d1b88 100644 (file)
@@ -18,6 +18,7 @@ static uint32_t s_hengai_sleep_gsensor_counter = 0;
 
 static sleep_data_t s_hengai_sdata = {0};
 
+void mmi_hengai_sleep_activation_check_action(void);
 static void mmi_hengai_gsensor_data_get(uint32_t para);
 
 
@@ -82,13 +83,33 @@ void mmi_hengai_sleep_activation_check_action(void)
 
                mmi_protocol_fzd_action_hengai_activation(req_code);
        }
+       else
+       {
+               int result = 0;
+               result = activate_algorithm(s_hengai_sleep_activation.req_code,
+                                                                               strlen(s_hengai_sleep_activation.req_code),
+                                                                               s_hengai_sleep_activation.act_code,
+                                                                               strlen(s_hengai_sleep_activation.act_code));  //result=1±íʾËã·¨¼¤»î
+
+               printf("[@CHENG_DEBUG][%s][%d]: result=%d\n", __FUNCTION__, __LINE__, result);
+               if(1 != result)
+               {
+                       _lv_memset_00(&s_hengai_sleep_activation, sizeof(nv_watch_heng_ai_sleep_activation_t));
+                       mmi_hengai_sleep_activation_nv_write();
+                       
+                       mmi_hengai_sleep_activation_check_action();
+               }       
+       }
 }
 
 
-#if 1
+#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)
 {
        if(0 == s_gsensor_upload_switch)
@@ -122,6 +143,211 @@ 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);
+       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;
+       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);
+       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
 
 
@@ -196,6 +422,13 @@ void mmi_hengai_sleep_data_get(void)
        {
                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);
@@ -203,6 +436,7 @@ 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;
        
@@ -221,7 +455,9 @@ 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
@@ -229,10 +465,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__);
        
        if(NULL != s_hengai_sleep_gsensor_timer_id)
@@ -247,10 +485,12 @@ 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)
@@ -261,6 +501,10 @@ 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
 }
 #endif
 
index ffa78e2..f94948d 100644 (file)
@@ -3014,7 +3014,7 @@ bool mmi_protocol_fzd_action_hengai_sleep_data(char * file_buf, uint32_t file_si
        return result;
 }
 
-#if 1
+#if 0
 bool mmi_protocol_fzd_action_hengai_gsensor_data(char * file_buf, uint32_t file_size)
 {
        bool result = false;
@@ -3063,6 +3063,53 @@ bool mmi_protocol_fzd_parse_SERVER_SET_GSENSOR_UPLOAD_SWITCH(unsigned char * nex
        return result;
 }
 
+bool mmi_protocol_fzd_parse_SERVER_SET_GSENSOR_DATA(unsigned char * next_buff, unsigned int next_buff_len)
+{
+       bool result = false;
+       MMI_PROTOCOL_FZD_ACTION_ENUM action = MMI_FZD_SERVER_SET_GSENSOR_DATA;
+
+       if(NULL == next_buff || 0 == next_buff_len)
+       {
+               PROTOCOL_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__);
+               return false;
+       }
+       
+       result = true;
+       mmi_protocol_fzd_send_without_data(action);
+
+       
+       PROTOCOL_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__);
+       
+       __gsensor_data_set(next_buff, next_buff_len);
+       
+       return result;
+}
+
+
+bool mmi_protocol_fzd_action_hengai_sleep_data_test(char * file_buf, uint32_t file_size)
+{
+       bool result = false;
+       MMI_PROTOCOL_FZD_ACTION_ENUM action = MMI_FZD_ACTION_HENGAI_SLEEP_DATA_TEST;
+       unsigned char * content_buff = NULL;
+       unsigned int content_lenth = 0;
+
+       content_buff = (unsigned char *)lv_mem_alloc(file_size + 2);
+       if(NULL == content_buff)
+       {
+               PROTOCOL_DEBUG_PRINTF("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__);
+               return false;
+       }
+       _lv_memset_00(content_buff, file_size + 2);
+       sprintf(content_buff, ",");
+       _lv_memcpy(content_buff + 1, file_buf, file_size);
+       content_lenth = file_size;
+       
+       result = mmi_protocol_fzd_send_with_data(action, content_buff, content_lenth);
+       lv_mem_free(content_buff);
+       
+       return result;
+}
+
 #endif
 
 #endif
index 994eccb..28f07bd 100644 (file)
@@ -165,9 +165,11 @@ typedef enum
        MMI_FZD_ACTION_HENGAI_ACTIVATION,
        MMI_FZD_ACTION_HENGAI_ACTIVATION_FEEDBACK,
        MMI_FZD_ACTION_HENGAI_SLEEP_DATA,
-#if 1
+#if 0
 MMI_FZD_ACTION_GSENSOR_DATA_UPLOAD,
 MMI_FZD_SERVER_SET_GSENSOR_UPLOAD_SWITCH,
+MMI_FZD_SERVER_SET_GSENSOR_DATA,
+MMI_FZD_ACTION_HENGAI_SLEEP_DATA_TEST,
 #endif
 #endif
 
index d9a6e11..452a73f 100644 (file)
@@ -97,8 +97,12 @@ static unsigned char * mmi_protocol_fzd_action_string_get(MMI_PROTOCOL_FZD_ACTIO
                        {MMI_FZD_ACTION_HENGAI_ACTIVATION_FEEDBACK, "HENGAI_ACTIVATION_FEEDBACK"},
                        {MMI_FZD_ACTION_HENGAI_SLEEP_DATA, "HENGAI_SLEEP_DATA"},
 
+                       #if 0
                        {MMI_FZD_ACTION_GSENSOR_DATA_UPLOAD, "TEST_SLEEP_UPLOAD"},
                        {MMI_FZD_SERVER_SET_GSENSOR_UPLOAD_SWITCH, "TEST_SLEEP_CONTROL"},
+                       {MMI_FZD_SERVER_SET_GSENSOR_DATA, "TEST_SLEEP_SNED"},                   
+                       {MMI_FZD_ACTION_HENGAI_SLEEP_DATA_TEST, "TEST_SLEEP_DATA"},                     
+                       #endif
                #endif
 
                
@@ -346,11 +350,18 @@ static bool mmi_protocol_fzd_content_parse(unsigned char * content_ptr, unsigned
                case MMI_FZD_ACTION_HENGAI_SLEEP_DATA:
                        break;
 
+               #if 0
                case MMI_FZD_ACTION_GSENSOR_DATA_UPLOAD:
                        break;
                case MMI_FZD_SERVER_SET_GSENSOR_UPLOAD_SWITCH:
                        mmi_protocol_fzd_parse_SERVER_SET_GSENSOR_UPLOAD_SWITCH(next_buff, next_buff_len);
                        break;
+               case MMI_FZD_SERVER_SET_GSENSOR_DATA:
+                       mmi_protocol_fzd_parse_SERVER_SET_GSENSOR_DATA(next_buff, next_buff_len);
+                       break;
+               case MMI_FZD_ACTION_HENGAI_SLEEP_DATA_TEST:
+                       break;
+               #endif
        #endif