#include "../../../../product/craneg_modem/cust/heng_ai_sleep/inc/lib_sleep.h"
-#define HENGAI_SLEEP_DATA_FILE "C:/hengai_sleep_data.txt"
static nv_watch_heng_ai_sleep_activation_t s_hengai_sleep_activation = {0};
static void * s_hengai_sleep_gsensor_timer_id = NULL;
static gsensor_data_t s_hengai_sleep_gsensor_data[HENGAI_SLEEP_GSENSOR_DATA_MAX] = {0};
static uint32_t s_hengai_sleep_gsensor_counter = 0;
-static uint32_t s_hengai_sleep_data_counter = 0;
+
+static sleep_data_t s_hengai_sdata = {0};
static void mmi_hengai_gsensor_data_get(uint32_t para);
void mmi_hengai_sleep_activation_act_code_set(char * act_code, uint32_t act_code_len)
{
- s_hengai_sleep_activation.is_activated = 1;
- _lv_memcpy(s_hengai_sleep_activation.act_code, act_code, act_code_len);
- mmi_hengai_sleep_activation_nv_write();
-
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±íʾËã·¨¼¤»î
+ act_code,
+ act_code_len); //result=1±íʾËã·¨¼¤»î
printf("[@CHENG_DEBUG][%s][%d]: result=%d\n", __FUNCTION__, __LINE__, result);
if(1 == result)
{
mmi_protocol_fzd_action_hengai_activation_feedback();
+
+ s_hengai_sleep_activation.is_activated = 1;
+ _lv_memcpy(s_hengai_sleep_activation.act_code, act_code, act_code_len);
+ mmi_hengai_sleep_activation_nv_write();
}
}
}
}
-void mmi_hengai_sleep_data_save_to_file(void * data_buf, uint32_t data_size)
+bool mmi_hengai_sleep_data_send(void)
{
- lv_fs_file_t file_p;
- lv_fs_res_t res;
- uint32_t bytes_write = 0;
+ 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;
- res = lv_fs_open(&file_p, HENGAI_SLEEP_DATA_FILE, LV_FS_MODE_WR | LV_FS_MODE_APPEND);
- if(LV_FS_RES_OK != res)
+ 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++)
{
- printf("[@CHENG_DEBUG][%s][%d]: errno=%d\n", __FUNCTION__, __LINE__, res);
- lv_fs_close(&file_p);
- return false;
+ 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(temp_buff, strlen(temp_buff));
- res = lv_fs_write(&file_p, data_buf, data_size, &bytes_write);
- lv_fs_close(&file_p);
- if(LV_FS_RES_OK != res)
+ if(NULL != temp_buff)
{
- printf("[@CHENG_DEBUG][%s][%d]: errno=%d\n", __FUNCTION__, __LINE__, res);
- return false;
+ lv_mem_free(temp_buff);
+ temp_buff = NULL;
}
- printf("[@CHENG_DEBUG][%s][%d]: file_size=%d,write_size=%d\n", __FUNCTION__, __LINE__, data_size, bytes_write);
-
- return true;
}
void mmi_hengai_sleep_data_get(void)
{
- sleep_data_t sdata = {0};
-
- init_sleep_data(&sdata); //³õʼ»¯sdata
-
sleep_time_t curtime = {0};
hal_rtc_t cur_time = {0};
curtime.minute = cur_time.tm_min;
int result = 0;
- result = get_sleep_time(s_hengai_sleep_gsensor_data, HENGAI_SLEEP_GSENSOR_DATA_MAX, curtime, &sdata);
+ 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);
if(1 == result)
{
- mmi_hengai_sleep_data_save_to_file(&sdata, sizeof(sdata));
- }
- s_hengai_sleep_data_counter++;
- if(60 <= s_hengai_sleep_data_counter) // 60mins
- {
- s_hengai_sleep_data_counter = 0;
- mmi_hengai_sleep_data_send();
- lv_fs_remove(HENGAI_SLEEP_DATA_FILE);
+ mmi_hengai_sleep_data_send();
}
_lv_memset_00(s_hengai_sleep_gsensor_data, sizeof(s_hengai_sleep_gsensor_data));
}
}
-bool mmi_hengai_sleep_data_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_DATA_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_hengai_sleep_data(file_buf, file_size);
-
-exit_free_res:
- lv_fs_close(&file_p);
- if(NULL != file_buf)
- {
- lv_mem_free(file_buf);
- file_buf = NULL;
- }
-}
-
void mmi_hengai_get_sleep_data_start(void)
{
printf("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__);
uos_timer_create(&s_hengai_sleep_gsensor_timer_id);
s_hengai_sleep_gsensor_counter = 0;
- s_hengai_sleep_data_counter = 0;
+ _lv_memset_00(s_hengai_sleep_gsensor_data, sizeof(s_hengai_sleep_gsensor_data));
- //mmi_hengai_gsensor_data_get(0);
+ //³õʼ»¯sdata
+ init_sleep_data(&s_hengai_sdata);
+
uos_timer_start(s_hengai_sleep_gsensor_timer_id, MS_TO_TICKS(500), 0, mmi_hengai_gsensor_data_get, NULL);
}
}
s_hengai_sleep_gsensor_counter = 0;
- s_hengai_sleep_data_counter = 0;
-
- mmi_hengai_sleep_data_send();
-
- lv_fs_remove(HENGAI_SLEEP_DATA_FILE);
-}
-#endif
-
-
-
-#if 0
-bool mmi_debug_0(void)
-{
- lv_fs_file_t file_p;
- lv_fs_res_t res;
- uint32_t bytes_write = 0;
- char * info_buf = s_hengai_sleep_gsensor_data;
- uint32_t info_size = sizeof(s_hengai_sleep_gsensor_data);
-
- res = lv_fs_open(&file_p, MMI_DEBUG_LOG_FILE, 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;
- }
-
- hal_rtc_t cur_time = {0};
- char str_time[24] = {0};
-
- Hal_Rtc_Gettime(&cur_time);
- sprintf(str_time, "\n[%04d%02d%02d_%02d%02d%02d]",
- cur_time.tm_year,
- cur_time.tm_mon,
- cur_time.tm_mday,
- cur_time.tm_hour,
- cur_time.tm_min,
- cur_time.tm_sec);
-
- //lv_fs_seek
- res = lv_fs_write(&file_p, str_time, strlen(str_time), &bytes_write);
- 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, info_buf, info_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__, info_size, bytes_write);
-
- return true;
-}
-
-static void mmi_debug_1(uint32_t para)
-{
- int16_t t_mems_data[32 * 3] = {0};
- uint8_t i = 0;
-
- get_Gsensor_fifo_xyz(t_mems_data);
- for(i = 0; i < 25; i++)
- {
- s_hengai_sleep_gsensor_data[s_hengai_sleep_gsensor_counter * 25 + i].x = *(t_mems_data + i);
- s_hengai_sleep_gsensor_data[s_hengai_sleep_gsensor_counter * 25 + i].y = *(t_mems_data + 32 + i);
- s_hengai_sleep_gsensor_data[s_hengai_sleep_gsensor_counter * 25 + i].z = *(t_mems_data + 64 + i);
- }
-
- printf("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__);
- for(i = 0; i < 25; i++)
- {
- printf("[%d]:x=%d,y=%d,z=%d",
- s_hengai_sleep_gsensor_counter * 25 + i,
- s_hengai_sleep_gsensor_data[s_hengai_sleep_gsensor_counter * 25 + i].x,
- s_hengai_sleep_gsensor_data[s_hengai_sleep_gsensor_counter * 25 + i].y,
- s_hengai_sleep_gsensor_data[s_hengai_sleep_gsensor_counter * 25 + i].z
- );
- }
-
- s_hengai_sleep_gsensor_counter++;
- if((3) <= s_hengai_sleep_gsensor_counter) // 1 minute
- {
- printf("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__);
-
- uos_timer_stop(s_hengai_sleep_gsensor_timer_id);
- s_hengai_sleep_gsensor_counter = 0;
-
- mmi_debug_0();
- }
- else
- {
- printf("[@CHENG_DEBUG][%s][%d]: \n", __FUNCTION__, __LINE__);
-
- uos_timer_stop(s_hengai_sleep_gsensor_timer_id);
- uos_timer_start(s_hengai_sleep_gsensor_timer_id, MS_TO_TICKS(500), 0, mmi_debug_1, NULL);
- }
-}
-
-void mmi_debug_sleep(void)
-{
- if(NULL != s_hengai_sleep_gsensor_timer_id)
- uos_timer_stop(s_hengai_sleep_gsensor_timer_id);
- else
- uos_timer_create(&s_hengai_sleep_gsensor_timer_id);
-
- mmi_debug_1(0);
+ _lv_memset_00(s_hengai_sleep_gsensor_data, sizeof(s_hengai_sleep_gsensor_data));
}
#endif
-