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);
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)
{
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
{
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);
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;
{
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
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)
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)
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