* @Author: penglei 1624952103@qq.com
* @Date: SLEPPNOTIFY24-06-26 19:36:48
* @LastEditors: penglei 1624952103@qq.com
- * @LastEditTime: 2024-09-13 17:00:34
+ * @LastEditTime: 2024-09-14 14:26:11
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp
* @Description:
*
static NAP_T nap_data = {0};
static SLEEP_T sleep_data = {0};
static SLEEP_STATE_T sleep_status = {0};
+ static uint32_t sleep_update_timestamp = 0;
+ static uint32_t nap_update_timestamp = 0;
bool save_nap_data(NAP_T *data)
{
uint32_t fall_asleep_timestamp = data->fall_asleep_timestamp;
fwrite(&fall_asleep_timestamp, 1, 4, fp);
- uint32_t wake_up_timestamp = data->wake_up_timestamp;
+
+ uint32_t wake_up_timestamp = 0;
+
+ if(data->wake_up_timestamp == 0)
+ uapi_get_timestampe_ss(&wake_up_timestamp);
+ else
+ wake_up_timestamp = data->wake_up_timestamp;
+
+ nap_update_timestamp = wake_up_timestamp;
+
fwrite(&wake_up_timestamp, 1, 4, fp);
uint16_t total_time = data->total_time;
static uint32_t fall_asleep_timestamp = 0;
static uint32_t history_wake_up_timestamp = 0;
static char day[12] = {0};
+ static char dir_path[64] = {0};
void clean_sleep_data(void)
{
memset(time_file_path,0,sizeof(time_file_path));
memset(status_file_path,0,sizeof(status_file_path));
memset(day,0,sizeof(day));
+ memset(dir_path,0,sizeof(dir_path));
fall_asleep_timestamp = 0;
}
+ void clean_sleep_file(void)
+ {
+ uint32_t sleep_time = get_sleep_time_from_config_model();
+ uint32_t wake_up_time = get_wake_up_time_from_config_model();
+ uint32_t sleep_min = ((sleep_time & 0xFFFF0000) >> 16) * 60 + sleep_time & 0x0000FFFF;
+ uint32_t wake_min = ((wake_up_time & 0xFFFF0000) >> 16) * 60 + wake_up_time & 0x0000FFFF;
+ if(sleep_min < wake_min)
+ {
+ uapi_delete_files(dir_path);
+ }
+ }
+
bool create_sleep_folder(void)
{
struct stat info;
- char dir_path[64] = {0};
uint32_t sleep_time = get_sleep_time_from_config_model();
uint32_t wake_up_time = get_wake_up_time_from_config_model();
-
- if(sleep_time > wake_up_time)
- uapi_get_YYMMDD_Time_extend(day, '\0' , -1);
+ uint32_t sleep_min = ((sleep_time & 0xFFFF0000) >> 16) * 60 + sleep_time & 0x0000FFFF;
+ uint32_t wake_min = ((wake_up_time & 0xFFFF0000) >> 16) * 60 + wake_up_time & 0x0000FFFF;
+ uint32_t current_min = 0;
+
+ if(sleep_min > wake_min)
+ {
+ time_t rawtime;
+ struct tm* timeinfo;
+
+ time(&rawtime);
+ timeinfo = localtime(&rawtime);
+
+ current_min = timeinfo->tm_hour * 60 + timeinfo->tm_min;
+
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "sleep_min : %d ,wake_min : %d ,current_min : %d ", sleep_min,wake_min,current_min);
+
+ if(current_min >= sleep_min && current_min < 24 * 60)
+ uapi_get_YYMMDD_Time_extend(day, '\0' , -1);
+ else if(current_min >= 24 * 60 && current_min < wake_min)
+ uapi_get_YYMMDD_Time_extend(day, '\0' , 0);
+ }
else
uapi_get_YYMMDD_Time_extend(day, '\0' , 0);
}
}
- if (stat(dir_path, &info) != 0)
+ if(stat(dir_path, &info) != 0)
{
if (mkdir(dir_path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "mkdir fail %s", dir_path);
return false; // Failed to create folder
- }
+ }
}
+
return true;
}
}
fwrite(&fall_asleep_timestamp, 1, 4, fp);
-
- uint32_t wake_up_timestamp = data->wake_up_timestamp;
- fwrite(&wake_up_timestamp, 1, 4, fp);
+ uint32_t wake_up_timestamp = 0;
if(data->wake_up_timestamp == 0)
- total_time = data->total_time;
+ uapi_get_timestampe_ss(&wake_up_timestamp);
else
- total_time = (wake_up_timestamp - fall_asleep_timestamp) / 60;
+ wake_up_timestamp = data->wake_up_timestamp;
+
+ sleep_update_timestamp = 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);
total_time_minute = (total_rem_sleep_time % 60);
fwrite(&total_time_minute, 1, 1, fp);
- if(data->wake_up_timestamp == 0)
- total_wake_time = data->total_wake_time;
- else
- total_wake_time = total_time - total_rem_sleep_time - total_mild_sleep_time - total_deep_sleep_time;
+ total_wake_time = total_time - total_rem_sleep_time - total_mild_sleep_time - total_deep_sleep_time;
+
total_time_hour = (total_wake_time / 60);
fwrite(&total_time_hour, 1, 1, fp);
//关闭蓝牙
if(uapi_dev_runtime_get_bt_powerstat())
{
-
stop_custom_ble_service();
}
-
//关闭cat1
if(uapi_dev_runtime_get_cat1_powerstat())
{
//打开蓝牙
- if(uapi_dev_runtime_get_bt_powerstat())
+ if(cm_custom_ble_service_on_flag())
start_custom_ble_service();
//打开cat1
- if(uapi_dev_runtime_get_cat1_powerstat())
+ if(cm_poweron_cat1_on_bootup_flag())
uapi_set4GCapability(true);
//开启心率周期检测(runtime)
}
else
fileSize = *len;
+ if(data == NULL)
+ data = (uint8_t *)malloc(fileSize);
size_t bytesRead = fread(data, 1, fileSize, file);
if (bytesRead != fileSize)
{
PRINT("fread failed \n");
fclose(file);
+ free(data);
return ;
}
fclose(file);
#ifdef CYWEE_MAC_ACTIVE
-uint8_t DEFAULT_MAC_KEY[88] = {
+uint8_t DEFAULT_MAC_KEY[] = {
0x23, 0x20, 0x86, 0xae, 0x58, 0x00, 0x00, 0x00, 0x01, 0x00, 0x1f, 0x02, 0x62, 0x0e, 0x1e, 0x25,
0x1f, 0x4e, 0x8b, 0x0b, 0xcc, 0xb1, 0x1f, 0x38, 0x34, 0xfa, 0x71, 0x2e, 0xa4, 0xf0, 0xbd, 0x18,
0x49, 0xc2, 0x6d, 0x19, 0x45, 0xfd, 0xd3, 0xbb, 0x68, 0xf8, 0x9c, 0x5a, 0xd7, 0x55, 0xbc, 0x99,