if (savedValue != g_stepData1.weekSteps[today]) {
struct tm curTime;
time_t second = time(nullptr);
- (void)gmtime_r((const time_t *)&second, &curTime);
+ (void)localtime_r((const time_t *)&second, &curTime);
ActivityModel::GetInstance()->SaveStepToFile(&curTime);
}
}
g_stepData1.weekSteps[weekToday] = stepCounter;
struct tm historyTime;
time_t second = time(nullptr) - SECONDS_ONEDAY;
- (void)gmtime_r((const time_t *)&second, &historyTime);
+ (void)localtime_r((const time_t *)&second, &historyTime);
SaveStepToFile(&historyTime);
stepCounter = 0;
if (weekToday == SUNDAY_STEP_COUNTER) {
#include "power_display_service.h"
#include "custom_utils.h"
#include "cywee_service.h"
-extern "C" errcode_t uapi_get_timestampe_ms(uint32_t *tm);
#define BLOODKEYABLE 0
namespace OHOS
#include <iostream>
#include <sstream>
#include <iomanip>
+#include "custom_runtime.h"
std::string weekdays[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
namespace OHOS
{
void MainClockView::InitDateTime(void)
{
- struct tm pTM;
- time_t seconds;
- time(&seconds);
- localtime_r(&seconds, &pTM);
- // 这里用来初始化时间
- // 拼接小时和分钟字符串
- std::ostringstream oss;
- oss << std::setfill('0') << std::setw(2) << static_cast<int>(pTM.tm_hour) << ":"
- << std::setfill('0') << std::setw(2) << static_cast<int>(pTM.tm_min);
-
- std::string timeStr = oss.str();
- timerlabel->SetText(timeStr.c_str());
-
- // 日期初始化
- std::ostringstream dateStr;
- dateStr << std::setfill('0') << std::setw(2) << static_cast<int>(pTM.tm_mday);
- datelabel->SetText((dateStr.str()).c_str());
- // 星期初始化
- weekLabel->SetText(weekdays[pTM.tm_wday].c_str());
+ UpdateTime();
}
void MainClockView::UpdateTime(void)
- {
- struct timeval tv;
- gettimeofday(&tv, NULL);
- uint64_t second = tv.tv_sec;
- uint64_t uSecond = tv.tv_usec;
- uint64_t minute = second / MIN_TO_HOUR;
- uint64_t hour = minute / MIN_TO_HOUR + timezone / (MIN_TO_HOUR * MIN_TO_HOUR);
- uint8_t realHour = static_cast<uint8_t>(hour % HOURLY_SYSTEM);
- uint8_t realMinute = static_cast<uint8_t>(minute % MIN_TO_HOUR);
-
- // uint16_t realMilliSecond = static_cast<uint16_t>((second % MIN_TO_HOUR) * SEC_TO_MILLI +uSecond / USEC_TO_MILLI);
-
- // 拼接小时和分钟字符串
- std::ostringstream oss;
- oss << std::setfill('0') << std::setw(2) << static_cast<int>(realHour) << ":"
- << std::setfill('0') << std::setw(2) << static_cast<int>(realMinute);
-
- std::string timeStr = oss.str();
+ {
+ struct tm local_time={0};
+ time_t seconds = time(nullptr);
+ uint8_t hour = 0 ;
+ uint8_t minute = 0 ;
+ if (localtime_r(&seconds, &local_time) != NULL) {
+ hour = local_time.tm_hour;
+ minute = local_time.tm_min;
+ }else{
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "get localtime error!");
+ hour = 0 ;
+ minute = 0;
+ }
+
+ if (hour > 24) hour = 0;
+ if (minute >= 60) minute = 0;
+
+ char *phour = nullptr;
+ char timebuf[64]={0};
+ if(uapi_dev_runtime_get_time_hour_show_model() == 12 )
+ {
+ if(hour < 12)
+ {
+ phour="AM";
+ }else if (hour == 12)
+ {
+ phour="PM";
+ }else{
+ phour="PM";
+ hour = hour - 12;
+ }
+ }
+ if (phour == nullptr)
+ {
+ sprintf_s(timebuf,sizeof(timebuf),"%02d:%02d",hour,minute);
+ }else{
+ sprintf_s(timebuf,sizeof(timebuf),"%02d:%02d",hour,minute);
+ // sprintf_s(timebuf,sizeof(timebuf),"%s%02d:%02d",phour,hour,minute);
+ }
+
// 更新界面上的文本
- timerlabel->SetText(timeStr.c_str());
+ timerlabel->SetText(timebuf);
// 更新日期需要nextday的消息
}
/* -------------------------------------------------------------------------- */
#include "health_service.h"\r
#include "custom_utils.h"\r
\r
-extern "C" errcode_t uapi_get_timestampe_ms(uint32_t *tm);\r
#ifdef __cplusplus\r
extern "C"\r
{\r
uint16_t angleM_ = 0;
uint16_t angleS_ = 0;
float angleMS_ = 0;
+ uint8_t pm_ = 0;
};
}
#endif
#include "sys/time.h"
#include "RegisterDialModel.h"
#include "DialModelTime.h"
-
+#include "custom_runtime.h"
#define REGIST_DIAL_MODULE_ANGLE_H(type, func) static OHOS::RegisterDialModel(REGIST_ANGLE_H)(type, func)
#define REGIST_DIAL_MODULE_ANGLE_M(type, func) static OHOS::RegisterDialModel(REGIST_ANGLE_M)(type, func)
#define REGIST_DIAL_MODULE_ANGLE_S(type, func) static OHOS::RegisterDialModel(REGIST_ANGLE_S)(type, func)
/*优化为更安全的localtime_r()*/
struct timeval tv;
gettimeofday(&tv, NULL);
- localtime_r(&tv.tv_sec, &tblock_);
- int realMS = tblock_.tm_sec * S_MS_US_TRANS + tv.tv_usec / S_MS_US_TRANS;
+ struct tm tmp={0};
+ localtime_r(&tv.tv_sec, &tmp);
+ int realMS = tmp.tm_sec * S_MS_US_TRANS + tv.tv_usec / S_MS_US_TRANS;
+ tblock_.tm_year = tmp.tm_year;
+ tblock_.tm_mon = tmp.tm_mon;
+ tblock_.tm_mday = tmp.tm_mday;
+ tblock_.tm_wday = tmp.tm_wday;
+ tblock_.tm_hour = tmp.tm_hour;
+ tblock_.tm_min = tmp.tm_min;
+ tblock_.tm_sec = tmp.tm_sec;
+
+ if (tmp.tm_hour >=12)
+ {
+ pm_ = 1;
+ }else {
+ pm_ = 0;
+ }
+ if (uapi_dev_runtime_get_time_hour_show_model() == 12 )
+ {
+ if (tmp.tm_hour > 12)
+ tblock_.tm_hour = tmp.tm_hour - 12 ;
+ }
#endif
angleH_ = ConvertHandValueToAngle(tblock_.tm_hour, HALF_DAY_IN_HOUR, tblock_.tm_min, ONE_HOUR_IN_MINUTE);
{
int16_t random;
int16_t indexMax;
- srand((unsigned)time(NULL));
+ srand((unsigned)time(nullptr));
List<PlayerCaseInfo> &playersCaseList = PlayersListGroup::GetInstance()->GetCase();
indexMax = playersCaseList.Size() - 1;
random = (rand() % (indexMax + 1));
#include "AppViewIDs.h"
#include "bleEvent.h"
-extern "C" errcode_t uapi_get_timestampe_ms(uint32_t *tm);
extern "C" void custom_VibratorFunc(OHOS::VibratorType vibratorType);
#ifdef __cplusplus
#define HIGH_INTENSITY_LOWER_THRESHOLD 70
#define HIGH_INTENSITY_UPPER_THRESHOLD 79
-extern "C" errcode_t uapi_get_timestampe_ms(uint32_t *tm);
extern "C" void custom_VibratorFunc(OHOS::VibratorType vibratorType);
#ifdef __cplusplus
int len=strlen(CallerLogModel::GetInstance()->GetPhoneNumber().c_str());
memcpy_s(info.tel,20,CallerLogModel::GetInstance()->GetPhoneNumber().c_str(),len+1);
uint32_t tmptime=0;
- uapi_get_timestampe_ms(&tmptime);
+ uapi_get_timestampe_ss(&tmptime);
info.creationTime = tmptime;
info.callDurTime=0;
CONFIGMODEL_ITEM_CAT1_PYVER, //Cat1 Python app version
CONFIGMODEL_ITEM_LANGUAGE_ID, //语言ID int id
CONFIGMODEL_ITEM_LANGUAGE_CODE, //语言Code string "zh","en"
- CONFIGMODEL_ITEM_TIMEZONE, //å\8d\95ä½\8då\88\86é\92\9f é»\98认+8 å°\8fæ\97¶ = 15*4*8 = 480 å\88\86钟
+ CONFIGMODEL_ITEM_TIMEZONE, //å\8d\95ä½\8då\88»é\92\9f é»\98认+8 å°\8fæ\97¶ = 8*4 = 32 å\88»钟
CONFIGMODEL_ITEM_SILENT_MODE, //静音模式模式
CONFIGMODEL_ITEM_VIBRATOR_SWITCH, // 马达 开关,0 强,1 中,2 弱,3 关
CONFIGMODEL_ITEM_RAISE_TO_WAKE, //抬腕亮屏开关
CONFIGMODEL_ITEM_DMP_CHANGE_MODE,//入库切换模式 默认是1 电信入库 2-255其他是移动入库 0是关闭
CONFIGMODEL_ITEM_DMP_CHANGE_MODE_OLD,//入库切换模式旧模式 防止切换来回数据不清楚问题 默认是1 电信入库 2-255其他是移动入库
+ CONFIGMODEL_ITEM_24HOUR,//默认24小时模式显示
CONFIGMODEL_ITEM_MAX,
} ;
{ConfigDataType::DATATYPE_STRING, "Cat1_PYVer", "" },//CONFIGMODEL_ITEM_CAT1_PYVER,
{ConfigDataType::DATATYPE_INT, "LanguageID", "-1" },//CONFIGMODEL_ITEM_LANGUAGE_ID, //默认没有选择语言
{ConfigDataType::DATATYPE_STRING, "LanguageCode", "" },//CONFIGMODEL_ITEM_LANGUAGE_CODE, //默认没有选择语言
- {ConfigDataType::DATATYPE_INT, "TimeZone", "480" },//CONFIGMODEL_ITEM_TIMEZONE, //单位分钟 默认+8 小时 = 15*4*8 = 480 分钟
+ {ConfigDataType::DATATYPE_INT, "TimeZone", "32" },//CONFIGMODEL_ITEM_TIMEZONE, //单位刻钟 默认+8 小时 = 4*8 = 32 刻钟
{ConfigDataType::DATATYPE_BOOL, "SlientMode", "false" },//CONFIGMODEL_ITEM_SILENT_MODE,
{ConfigDataType::DATATYPE_INT, "VibratorSwitch", "1" },//CONFIGMODEL_ITEM_VIBRATOR_SWITCH, // 马达 开关,0 强,1 中,2 弱,3 关
{ConfigDataType::DATATYPE_BOOL, "Rase2Wake", "true" },//CONFIGMODEL_ITEM_RAISE_TO_WAKE,
{ConfigDataType::DATATYPE_STRING, "sim_iccid", "" },//CONFIGMODEL_ITEM_SIM_ICCID cat1的iccid
{ConfigDataType::DATATYPE_STRING, "telecom_regist_timesec", "" },//CONFIGMODEL_ITEM_TELECOM_DMP_TIMESEC
{ConfigDataType::DATATYPE_INT, "dmp_factory_status", "0" },//CONFIGMODEL_ITEM_DMP_FACTORY_STATUS默认是0
- #if defined(SUPPORT_TELECOM_DMP) //电信入库
+ #if defined(SUPPORT_TELECOM_DMP) //电信入库
{ConfigDataType::DATATYPE_INT, "dmp_change_mode", "1" },//CONFIGMODEL_ITEM_DMP_CHANGE_MODE 入库切换模式 默认值 1
- {ConfigDataType::DATATYPE_INT, "dmp_change_mode_old", "1" }//CONFIGMODEL_ITEM_DMP_CHANGE_MODE_OLD 默认值 1 要和新默认值一致
+ {ConfigDataType::DATATYPE_INT, "dmp_change_mode_old", "1" },//CONFIGMODEL_ITEM_DMP_CHANGE_MODE_OLD 默认值 1 要和新默认值一致
#elif defined(SUPPORT_CHINA_MOBILE_DMP) //移动入库
{ConfigDataType::DATATYPE_INT, "dmp_change_mode", "2" },//CONFIGMODEL_ITEM_DMP_CHANGE_MODE 入库切换模式 默认值 1
- {ConfigDataType::DATATYPE_INT, "dmp_change_mode_old", "2" }//CONFIGMODEL_ITEM_DMP_CHANGE_MODE_OLD 默认值 1 要和新默认值一致
+ {ConfigDataType::DATATYPE_INT, "dmp_change_mode_old", "2" },//CONFIGMODEL_ITEM_DMP_CHANGE_MODE_OLD 默认值 1 要和新默认值一致
#else //关闭入库功能
{ConfigDataType::DATATYPE_INT, "dmp_change_mode", "0" },//CONFIGMODEL_ITEM_DMP_CHANGE_MODE 入库切换模式 默认值 1
- {ConfigDataType::DATATYPE_INT, "dmp_change_mode_old", "0" }//CONFIGMODEL_ITEM_DMP_CHANGE_MODE_OLD 默认值 1 要和新默认值一致
+ {ConfigDataType::DATATYPE_INT, "dmp_change_mode_old", "0" },//CONFIGMODEL_ITEM_DMP_CHANGE_MODE_OLD 默认值 1 要和新默认值一致
#endif
+ {ConfigDataType::DATATYPE_INT, "time_hour_show_model", "24" }//CONFIGMODEL_ITEM_24HOUR,//默认24小时模式显示 ,12 12小时显示 ,24 24小时显示
+
};
ConfigModel(); // 私有构造函数,确保无法在外部实例化
ConfigModel(const ConfigModel &) = delete; // 禁止拷贝构造
* @Author: luozheng 1732036298@qq.com
* @Date: 2024-04-17 09:32:03
* @LastEditors: SnickerSun snickersun@163.com
- * @LastEditTime: 2024-06-03 16:39:34
+ * @LastEditTime: 2024-06-05 23:20:27
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModelC.h
*/
#ifndef _CONFIG_MODEL_C_H_
bool get_A2DP_switch(void);
-void set_timezone_minutes(int16_t timezone_minutes);
+void set_timezone_quarters(int16_t timezone_quarters);
-int16_t get_timezone_minutes(void);
+int16_t get_timezone_quarters(void);
+
+
+uint8_t get_hour_show_model(void);
+void set_hour_show_model(uint8_t showtype);
#ifdef __cplusplus
#if __cplusplus
/*开机时从配置文件里读取的文件,直接同步到runtime里,方便其他应用使用*/
void installize_dev_runtime(void)
{
- int16_t timezone = get_timezone_minutes();
- uapi_dev_runtime_set_timezone_minutes(timezone);
+ int16_t timezone = get_timezone_quarters();
+ uapi_set_timezone(timezone);
+ //更新24小时显示模式
+ uint8_t showtype=get_hour_show_model();
+ uapi_dev_runtime_set_time_hour_show_model(showtype);
}
uint32_t ConfigModelInit(void)
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "getA2DPSwitch %d",isopen);
return isopen;
}
-void set_timezone_minutes(int16_t timezone_minutes)
+void set_timezone_quarters(int16_t timezone_quarters)
{
- OHOS::ConfigModel::GetInstance()->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_TIMEZONE,timezone_minutes);
+ OHOS::ConfigModel::GetInstance()->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_TIMEZONE,timezone_quarters);
}
-int16_t get_timezone_minutes(void)
+int16_t get_timezone_quarters(void)
{
- int16_t timezone_minutes;
- timezone_minutes = OHOS::ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_TIMEZONE);
- return timezone_minutes;
+ int16_t timezone_quarters;
+ timezone_quarters = OHOS::ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_TIMEZONE);
+ return timezone_quarters;
}
+uint8_t get_hour_show_model(void)
+{
+ uint8_t showtype = 0;
+ showtype = OHOS::ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_24HOUR);
+ return showtype;
+}
+
+void set_hour_show_model(uint8_t showtype)
+{
+ OHOS::ConfigModel::GetInstance()->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_24HOUR,showtype);
+}
#ifdef __cplusplus
#if __cplusplus
}
#include "custom_runtime.h"
-
+#include "chip_system_time.h"
static runtime_status_t g_runtime={0};
runtime_status_t * get_device_runtime_status(void)
{
return g_runtime.android_app_connected;
}
-void uapi_dev_runtime_set_timezone_minutes(int16_t timezone_minutes)
+uint8_t uapi_dev_runtime_get_time_hour_show_model(void)
{
- g_runtime.timezone_minutes = timezone_minutes;
+ return g_runtime.time_hour_show_model;
}
-
-int16_t uapi_dev_runtime_get_timezone_minutes(void)
+void uapi_dev_runtime_set_time_hour_show_model(uint8_t hour_type)
{
- return g_runtime.timezone_minutes;
+ g_runtime.time_hour_show_model = hour_type;
}
-
//关机前,把runtime数据同步到config文件里
void uapi_dev_runtime_sync_runtime_env_to_config(void)
{
- set_timezone_minutes(g_runtime.timezone_minutes);
+ uint16_t timezone_quarters=uapi_get_timezone();
+ set_timezone_quarters(timezone_quarters);
+ set_hour_show_model(g_runtime.time_hour_show_model);
+
+
}
\ No newline at end of file
uint8_t android_app_connected;
cat1_runtime_status_t cat1_runtime;
uint8_t current_dial_name[32];
- int16_t timezone_minutes;
+ uint8_t time_hour_show_model;
} runtime_status_t;
/**
*/
uint8_t uapi_dev_runtime_get_android_connection_status(void);
+/**
+ *
+*/
+void uapi_dev_runtime_sync_runtime_env_to_config(void);
-void uapi_dev_runtime_set_timezone_minutes(int16_t timezone_minutes);
-int16_t uapi_dev_runtime_get_timezone_minutes(void);
+uint8_t uapi_dev_runtime_get_time_hour_show_model(void);
+void uapi_dev_runtime_set_time_hour_show_model(uint8_t hour_type);
+
-void uapi_dev_runtime_sync_runtime_env_to_config(void);
#ifdef __cplusplus
#if __cplusplus
#include "systick.h"
#include "sys/time.h"
#include "time.h"
+#include "chip_system_time.h"
+
errcode_t uapi_get_timestampe_ms(uint32_t *tm)
{
struct timeval tv = { 0 };
if (tm == NULL) {
return ERRCODE_FAIL;
}
- struct timeval tv = { 0 };
-
- if (gettimeofday(&tv, NULL)) {
- return ERRCODE_FAIL;
- }
- *tm = (uint32_t)(tv.tv_sec);
- printf("[timestamp:%u]\n", (uint32_t)(tv.tv_sec));
+
+ *tm = get_local_timestamp();
+ printf("[timestamp:%u]\n", *tm);
return ERRCODE_SUCC;
}
-errcode_t uaip_set_time_utc_zone(uint32_t seconds,int16_t zone_minutes)
-{
- struct timeval tv = { 0 };
- struct timezone tz = { 0 };
-
- tv.tv_sec = seconds;
- tv.tv_usec = 0;
- tz.tz_dsttime = 0;
- tz.tz_minuteswest = zone_minutes;
- uapi_dev_runtime_set_timezone_minutes(zone_minutes);
- return settimeofday(&tv, &tz);
+errcode_t uaip_set_time_utc_zone(uint32_t seconds,int16_t zone_quarters)
+{
+ return sync_time_utc(seconds,zone_quarters);
}
errcode_t uaip_sntp_set_time_utc(uint32_t seconds)
{
- int zone_minutes = uapi_dev_runtime_get_timezone_minutes();
+ int zone_quarters = uapi_get_timezone();
- uaip_set_time_utc_zone(seconds,zone_minutes);
+ errcode_t ret = sync_time_utc(seconds,zone_quarters);
time_t rawtime;
struct tm timeinfo;
time(&rawtime);
localtime_r(&rawtime,&timeinfo);
- printf("uaip_sntp_set_time_utc set time success %04d-%02d-%02d %02d:%02d:%02d %d\n",
+ printf("uaip_sntp_set_time_utc set time success %04d-%02d-%02d %02d:%02d:%02d %d , ret %X\n",
timeinfo.tm_year + 1900,
timeinfo.tm_mon + 1,
timeinfo.tm_mday,
timeinfo.tm_hour,
timeinfo.tm_min,
- timeinfo.tm_sec,zone_minutes);
+ timeinfo.tm_sec,zone_quarters,ret);
+ printf("utc timestamp %d , local timestamp %d\n",get_current_timestamp(),get_local_timestamp());
return ERRCODE_SUCC;
}
/*已经包含timezone时间,*/
errcode_t uaip_set_time_local(uint32_t seconds)
{
- int zone_minutes = uapi_dev_runtime_get_timezone_minutes();
+ int zone_quarters = uapi_get_timezone();
- uaip_set_time_utc_zone((seconds-(zone_minutes*60)),zone_minutes);
+ sync_time(seconds,zone_quarters);
time_t rawtime;
struct tm timeinfo;
timeinfo.tm_mday,
timeinfo.tm_hour,
timeinfo.tm_min,
- timeinfo.tm_sec,zone_minutes);
+ timeinfo.tm_sec,zone_quarters);
+
+ printf("utc timestamp %d , local timestamp %d\n",get_current_timestamp(),get_local_timestamp());
return ERRCODE_SUCC;
uint32_t uapi_calendar_store_date(void)
{
-
+#if 1
+ save_time();
+ return ERRCODE_SUCC;
+#else
calendar_t date;
time_t rawtime;
}
printf("Set datetime failed, error code = %d \r\n", ret);
return ret;
+#endif
}
uint32_t uapi_calendar_recover_date(void)
{
-
+#if 1
+ restore_time();
+ return ERRCODE_SUCC;
+#else
calendar_t date;
errcode_t ret = uapi_calendar_get_datetime(&date);
if (ret == ERRCODE_SUCC) {
}
printf("Get datetime failed, error code = %d \r\n", ret);
return ret;
+#endif
}
#include "chip_system_time.h"
-void test_bandy_time(uint32_t time)
+void test_bandy_time(uint32_t timestamp)
{
struct tm tm;
struct timeval tv;
printf("--------SYNC TIME----------\r\n");
get_current_timestamp();
get_current_time(&tv, &tm);
- sync_time(time, 8);
+ sync_time(timestamp, 8*4);
get_current_timestamp();
get_current_time(&tv, &tm);
printf("--------SAVE TIME----------\r\n");
/*获取单位秒的时间戳*/
errcode_t uapi_get_timestampe_ss(uint32_t *tm);
+/**返回timezone quarters*/
+uint16_t uapi_get_timezone(void);
+/**set timezone quarters*/
+void uapi_set_timezone(uint16_t timezone_quarters);
+
/**设置utc时间+timezone*/
-errcode_t uaip_set_time_utc_zone(uint32_t seconds,int16_t zone_minutes);
+errcode_t uaip_set_time_utc_zone(uint32_t seconds,int16_t zone_quarters);
-/*sntp同步UTC 时间 , 采用默认timezone,或者已经保存detimezone*/
+/*sntp同步UTC 时间 , 采用默认timezone,或者已经保存的timezone*/
errcode_t uaip_sntp_set_time_utc(uint32_t seconds);
/*已经包含timezone时间,*/
errcode_t uaip_set_time_local(uint32_t seconds);
+
/*已经包含timezone时间,*/
errcode_t uaip_set_time_local_full(uint32_t year,uint32_t month, uint32_t day, uint32_t hour,uint32_t minutes,uint32_t seconds);
#include "pm_control.h"
#include "custom_utils.h"
#include "debug_print.h"
-
+#include "custom_runtime.h"
#include "lwip/altcp_tls.h"
#define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0]))
uint32_t inpdustr = atol((char*)argv[0]);
- test_bandy_time(inpdustr);
+ (inpdustr);
+
+ return ERRCODE_SUCC;
+}
+static uint32_t custom_test_time_showtype(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
+{
+ UNUSED(strCommonCmd);
+ uint8_t argv[CUSTOM_UTILS_MAX_ARGC][CUSTOM_UTILS_MAX_ARGV_LEN] = { 0 };
+ uint32_t argc = 0;
+
+ int ret = ConvertCmdToParam(para, paraLen, argv, &argc);
+ if (ret != CUSTOM_UTILS_SUCCESS) {
+ PRINT("CUSTOM_UTILSTEST ATCMD Convert Command Failed\n");
+ return ERRCODE_FAIL;
+ }
+
+ if (argc != 1) {
+ PRINT("CUSTOM_UTILSTEST ATCMD Set Parameter Failed argc %d\n",argc);
+ return ERRCODE_FAIL;
+ }
+ uint32_t inpdustr = atol((char*)argv[0]);
+
+ if (inpdustr == 12 || inpdustr == 24)
+ {
+ uapi_dev_runtime_set_time_hour_show_model(inpdustr);
+ } else{
+ PRINT(" only accept 12 or 24 !\n");
+ }
return ERRCODE_SUCC;
}
{ (char *)"AT^PDUDEC", custom_utils_pdudec, (char *)" " },
{ (char *)"AT^SNTP", custom_test_sntp, (char *)" " },
{ (char *)"AT^TIMESYNC", custom_test_time_synct, (char *)" " },
+ { (char *)"AT^24HOUR", custom_test_time_showtype, (char *)" " },
#include "chip_system_time.h"
-#define SECONDS_PER_MINUTE 60 /* second per minute */
-#define MINUTES_PER_HOUR 60 /* second per minute */
+#define SECONDS_PER_MINUTE 60 /* seconds per minute */
+#define MINUTES_PER_HOUR 60 /* minutes per hour */
+#define MINUTES_PER_QUARTER 15 /* seconds per quarter */
+#define QUARTERS_PER_HOUR 4 /* quarters per hour */
#define MSEC_PER_SEC 1000
#define USEC_PER_MSEC 1000
#define TZ_ADDRESS 0x5702C014
date->tm_min,
date->tm_sec);
}
-
-static uint16_t get_timezone(void)
+/**
+ * return quarters for timezone
+*/
+uint16_t uapi_get_timezone(void)
{
- return readw(TZ_ADDRESS) & 0x00FF;
+ uint16_t timezone_quarters = readw(TZ_ADDRESS) & 0x00FF;
+ return timezone_quarters ;
}
-static void set_timezone(uint16_t timezone)
+void uapi_set_timezone(uint16_t timezone_quarters)
{
uint16_t tz_zone = readw(TZ_ADDRESS) & 0xFF00;
- tz_zone = tz_zone | timezone;
+ tz_zone = tz_zone | timezone_quarters;
writew(TZ_ADDRESS, tz_zone);
}
uint32_t get_local_timestamp(void)
{
- uint32_t timestamp = get_current_timestamp() + get_timezone() * MINUTES_PER_HOUR * SECONDS_PER_MINUTE;
+ uint32_t timestamp = get_current_timestamp() + uapi_get_timezone() * MINUTES_PER_QUARTER * SECONDS_PER_MINUTE;
return timestamp;
}
uapi_calendar_get_timestamp(&sec);
printf("callendar timestamp = %lld \r\n", sec);
sec = sec / MSEC_PER_SEC;
- sync_time(sec, get_timezone());
+ sync_time(sec, uapi_get_timezone());
+}
+uint32_t sync_time_utc(uint32_t timestamp, uint32_t timezone_quarters)
+{
+ printf("sync time utc timestamp %d, timezone_in_quarters %d \r\n", timestamp, timezone_quarters);
+ uint32_t seconds;
+ if (timezone_quarters > (MAX_TIMEZONE_HOURS * QUARTERS_PER_HOUR)) {
+ return ERRCODE_FAIL;
+ }
+ if (timestamp == 0) {
+ return ERRCODE_FAIL;
+ }
+#if 0
+ else if (timestamp <= (timezone_quarters * MINUTES_PER_QUARTER * SECONDS_PER_MINUTE)) {
+ seconds = 0;
+ } else {
+ seconds = timestamp - (timezone_quarters * MINUTES_PER_QUARTER * SECONDS_PER_MINUTE);
+ }
+#else
+ seconds = timestamp;
+#endif
+ uapi_set_timezone(timezone_quarters);
+ struct timeval tv = {0};
+ struct timezone tzone = {0};
+ tv.tv_sec = seconds;
+ tv.tv_usec = 0;
+ tzone.tz_dsttime = 0;
+ tzone.tz_minuteswest = timezone_quarters * MINUTES_PER_QUARTER;
+ return settimeofday(&tv, &tzone);
}
-uint32_t sync_time(uint32_t timestamp, uint32_t timezone)
+uint32_t sync_time(uint32_t timestamp, uint32_t timezone_quarters)
{
- printf("sync time timestamp %d, timezone %d \r\n", timestamp, timezone);
+ printf("sync time timestamp %d, timezone_in_quarters %d \r\n", timestamp, timezone_quarters);
uint32_t seconds;
- if (timezone > MAX_TIMEZONE_HOURS) {
+ if (timezone_quarters > (MAX_TIMEZONE_HOURS * QUARTERS_PER_HOUR)) {
return ERRCODE_FAIL;
}
if (timestamp == 0) {
return ERRCODE_FAIL;
- } else if (timestamp <= (timezone * MINUTES_PER_HOUR * SECONDS_PER_MINUTE)) {
+ } else if (timestamp <= (timezone_quarters * MINUTES_PER_QUARTER * SECONDS_PER_MINUTE)) {
seconds = 0;
} else {
- seconds = timestamp - (timezone * MINUTES_PER_HOUR * SECONDS_PER_MINUTE);
+ seconds = timestamp - (timezone_quarters * MINUTES_PER_QUARTER * SECONDS_PER_MINUTE);
}
- set_timezone(timezone);
+ uapi_set_timezone(timezone_quarters);
struct timeval tv = {0};
struct timezone tzone = {0};
tv.tv_sec = seconds;
tv.tv_usec = 0;
tzone.tz_dsttime = 0;
- tzone.tz_minuteswest = timezone * MINUTES_PER_HOUR;
+ tzone.tz_minuteswest = timezone_quarters * MINUTES_PER_QUARTER;
return settimeofday(&tv, &tzone);
}
// printf("--------SYNC TIME----------\r\n");
// get_current_timestamp();
// get_current_time(&tv, &tm);
-// sync_time(time, 8);
+// sync_time(time, 8*QUARTERS_PER_HOUR);
// get_current_timestamp();
// get_current_time(&tv, &tm);
// printf("--------SAVE TIME----------\r\n");
* @brief Synchronize the system time with the given timestamp and timezone
* @return void.
*/
-uint32_t sync_time(uint32_t timestamp, uint32_t timezone);
-
+uint32_t sync_time(uint32_t timestamp, uint32_t timezone_in_quarters);
+/**
+ * @brief Synchronize the system time with the given utc timestamp and timezone
+ * means that , do not need remove timezone difference when set time.
+ * @return void.
+*/
+uint32_t sync_time_utc(uint32_t timestamp, uint32_t timezone_quarters);
/**
* @brief use for test
* @return void.
*/
-void test_bandy_time(uint32_t time);
+void test_bandy_time(uint32_t timestamp);
/**
* @brief Get the current system time as a local timestamp with timezone offset
* @return void.
*/
uint32_t get_local_timestamp(void);
+
+
#endif
#endif
\ No newline at end of file
#define LWIP_HTTPC_HAVE_FILE_IO 1
#define HTTPC_DEBUG_REQUEST 1
-#define LWIP_DHCP_MAX_NTP_SERVERS 3
+#define LWIP_DHCP_MAX_NTP_SERVERS 3
#define SNTP_SERVER_DNS 1
#if SNTP_SERVER_DNS
#define SNTP_SERVER_ADDRESS "cn.pool.ntp.org" //"pool.ntp.org"
#define SNTP_SERVER_ADDRESS2 "ntp1.aliyun.com" //"pool.ntp.org"
#define SNTP_SERVER_ADDRESS3 "pool.ntp.org" //"pool.ntp.org"
#endif
+#define SNTP_CHECK_RESPONSE 2
#define SNTP_SET_SYSTEM_TIME(sec) uaip_sntp_set_time_utc(sec)