From 7c02e3d1471cc21b685e8b82451b594b89c4b747 Mon Sep 17 00:00:00 2001 From: SnickerSun Date: Wed, 5 Jun 2024 23:24:58 +0800 Subject: [PATCH] =?utf8?q?=E9=87=87=E7=94=A8sdk=E8=87=AA=E5=B8=A6=E7=9A=84?= =?utf8?q?=E4=BE=8B=E5=AD=90=E6=9B=B4=E6=96=B0rtc=20,=20=E4=BC=98=E5=8C=96?= =?utf8?q?=E6=97=B6=E9=97=B4=E5=87=BD=E6=95=B0,=20=E6=B7=BB=E5=8A=A024?= =?utf8?q?=E5=B0=8F=E6=97=B6=2012=E5=B0=8F=E6=97=B6=20=E6=94=AF=E6=8C=81?= =?utf8?q?=EF=BC=8C=E5=B9=B6=E5=A2=9E=E5=8A=A0=20AT^24HOUR=E6=B5=8B?= =?utf8?q?=E8=AF=95=E6=8C=87=E4=BB=A4=20=E4=BC=98=E5=8C=96sntp=20=E6=9B=B4?= =?utf8?q?=E6=96=B0=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/activity/src/ActivityModel.cpp | 4 +- .../bloodoxygen/src/BloodOxygenPresenter.cpp | 1 - .../nativeui/clock/src/MainClockView.cpp | 81 ++++++++++--------- .../nativeui/heartrate/src/HeartModel.cpp | 1 - .../main/include/dial/DialModelTime.h | 1 + .../nativeui/main/src/dial/DialModelTime.cpp | 26 +++++- .../nativeui/player/src/PlayersModel.cpp | 2 +- .../takephotos/src/TakephotosModel.cpp | 1 - .../nativeui/traing/src/TraingModel.cpp | 1 - .../src/notify/makephone_notification.cpp | 2 +- .../peripheral/config/include/ConfigModel.h | 15 ++-- .../peripheral/config/include/ConfigModelC.h | 10 ++- .../peripheral/config/src/ConfigModel.cpp | 30 +++++-- .../drivers/peripheral/utils/custom_runtime.c | 18 +++-- .../drivers/peripheral/utils/custom_runtime.h | 12 ++- .../drivers/peripheral/utils/custom_utils.c | 59 +++++++------- .../drivers/peripheral/utils/custom_utils.h | 10 ++- .../peripheral/utils/custom_utils_at_cmd.c | 32 +++++++- .../chips/brandy/exception/chip_system_time.c | 67 +++++++++++---- .../chips/brandy/exception/chip_system_time.h | 13 ++- .../lwip-2.1/porting/include/lwip/lwipopts.h | 3 +- 21 files changed, 257 insertions(+), 132 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/activity/src/ActivityModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/activity/src/ActivityModel.cpp index 3e2d902a0..9a36d0060 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/activity/src/ActivityModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/activity/src/ActivityModel.cpp @@ -217,7 +217,7 @@ static void SaveEveryMinCallbackProc(int data) 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); } } @@ -279,7 +279,7 @@ uint32_t ActivityModel::ZeroHourStepHandle(void) 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) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenPresenter.cpp index ce5e8998e..7956aefc7 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenPresenter.cpp @@ -35,7 +35,6 @@ #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 diff --git a/code/sdk/application/wearable/fd230app/nativeui/clock/src/MainClockView.cpp b/code/sdk/application/wearable/fd230app/nativeui/clock/src/MainClockView.cpp index dc45343a7..ec190bfe8 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/clock/src/MainClockView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/clock/src/MainClockView.cpp @@ -15,6 +15,7 @@ #include #include #include +#include "custom_runtime.h" std::string weekdays[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; namespace OHOS { @@ -208,48 +209,52 @@ 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(pTM.tm_hour) << ":" - << std::setfill('0') << std::setw(2) << static_cast(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(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(hour % HOURLY_SYSTEM); - uint8_t realMinute = static_cast(minute % MIN_TO_HOUR); - - // uint16_t realMilliSecond = static_cast((second % MIN_TO_HOUR) * SEC_TO_MILLI +uSecond / USEC_TO_MILLI); - - // 拼接小时和分钟字符串 - std::ostringstream oss; - oss << std::setfill('0') << std::setw(2) << static_cast(realHour) << ":" - << std::setfill('0') << std::setw(2) << static_cast(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的消息 } /* -------------------------------------------------------------------------- */ diff --git a/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp index 5716f3898..089e68c40 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp @@ -13,7 +13,6 @@ #include "health_service.h" #include "custom_utils.h" -extern "C" errcode_t uapi_get_timestampe_ms(uint32_t *tm); #ifdef __cplusplus extern "C" { diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialModelTime.h b/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialModelTime.h index 2f36c4017..65067ac6f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialModelTime.h +++ b/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialModelTime.h @@ -29,6 +29,7 @@ private: uint16_t angleM_ = 0; uint16_t angleS_ = 0; float angleMS_ = 0; + uint8_t pm_ = 0; }; } #endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelTime.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelTime.cpp index 2094fdae0..d327e51f6 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelTime.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelTime.cpp @@ -8,7 +8,7 @@ #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) @@ -79,8 +79,28 @@ void DialModelTime::UpdateTime() /*优化为更安全的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); diff --git a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp index ce172b326..526adb4ae 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp @@ -371,7 +371,7 @@ void PlayersModel::RandomPlayout() { int16_t random; int16_t indexMax; - srand((unsigned)time(NULL)); + srand((unsigned)time(nullptr)); List &playersCaseList = PlayersListGroup::GetInstance()->GetCase(); indexMax = playersCaseList.Size() - 1; random = (rand() % (indexMax + 1)); diff --git a/code/sdk/application/wearable/fd230app/nativeui/takephotos/src/TakephotosModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/takephotos/src/TakephotosModel.cpp index 43ea0c10f..0ab853229 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/takephotos/src/TakephotosModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/takephotos/src/TakephotosModel.cpp @@ -20,7 +20,6 @@ #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 diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp index 20ad4b6f7..f76687a79 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp @@ -60,7 +60,6 @@ #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 diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/makephone_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/makephone_notification.cpp index b658e8ca7..08820169c 100755 --- a/code/sdk/application/wearable/service/msg_center/src/notify/makephone_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/makephone_notification.cpp @@ -120,7 +120,7 @@ void calllog_info_init() 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; diff --git a/code/sdk/drivers/peripheral/config/include/ConfigModel.h b/code/sdk/drivers/peripheral/config/include/ConfigModel.h index 657404ead..5b15392ce 100644 --- a/code/sdk/drivers/peripheral/config/include/ConfigModel.h +++ b/code/sdk/drivers/peripheral/config/include/ConfigModel.h @@ -43,7 +43,7 @@ namespace OHOS 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, //单位分钟 默认+8 小时 = 15*4*8 = 480 分钟 + CONFIGMODEL_ITEM_TIMEZONE, //单位刻钟 默认+8 小时 = 8*4 = 32 刻钟 CONFIGMODEL_ITEM_SILENT_MODE, //静音模式模式 CONFIGMODEL_ITEM_VIBRATOR_SWITCH, // 马达 开关,0 强,1 中,2 弱,3 关 CONFIGMODEL_ITEM_RAISE_TO_WAKE, //抬腕亮屏开关 @@ -102,6 +102,7 @@ namespace OHOS 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, } ; @@ -257,7 +258,7 @@ namespace OHOS {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, @@ -308,16 +309,18 @@ namespace OHOS {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; // 禁止拷贝构造 diff --git a/code/sdk/drivers/peripheral/config/include/ConfigModelC.h b/code/sdk/drivers/peripheral/config/include/ConfigModelC.h index 5a90c0858..d059c4ba1 100644 --- a/code/sdk/drivers/peripheral/config/include/ConfigModelC.h +++ b/code/sdk/drivers/peripheral/config/include/ConfigModelC.h @@ -2,7 +2,7 @@ * @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_ @@ -82,9 +82,13 @@ bool get_HFP_switch(void); 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 diff --git a/code/sdk/drivers/peripheral/config/src/ConfigModel.cpp b/code/sdk/drivers/peripheral/config/src/ConfigModel.cpp index 710969b2a..027273dac 100644 --- a/code/sdk/drivers/peripheral/config/src/ConfigModel.cpp +++ b/code/sdk/drivers/peripheral/config/src/ConfigModel.cpp @@ -971,8 +971,11 @@ extern "C" { /*开机时从配置文件里读取的文件,直接同步到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) @@ -1093,18 +1096,29 @@ bool get_A2DP_switch(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 } diff --git a/code/sdk/drivers/peripheral/utils/custom_runtime.c b/code/sdk/drivers/peripheral/utils/custom_runtime.c index f9fb39902..cd3ce8045 100644 --- a/code/sdk/drivers/peripheral/utils/custom_runtime.c +++ b/code/sdk/drivers/peripheral/utils/custom_runtime.c @@ -1,5 +1,5 @@ #include "custom_runtime.h" - +#include "chip_system_time.h" static runtime_status_t g_runtime={0}; runtime_status_t * get_device_runtime_status(void) { @@ -54,19 +54,21 @@ uint8_t uapi_dev_runtime_get_android_connection_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 diff --git a/code/sdk/drivers/peripheral/utils/custom_runtime.h b/code/sdk/drivers/peripheral/utils/custom_runtime.h index 173290121..d5596c8ad 100644 --- a/code/sdk/drivers/peripheral/utils/custom_runtime.h +++ b/code/sdk/drivers/peripheral/utils/custom_runtime.h @@ -78,7 +78,7 @@ typedef struct 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; /** @@ -132,13 +132,17 @@ void uapi_dev_runtime_set_android_connection_status(uint8_t is_android); */ 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 diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index 105c53ec5..1d11fb7aa 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -378,6 +378,8 @@ errcode_t uaip_cmd_update_request(void) #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 }; @@ -396,58 +398,47 @@ errcode_t uapi_get_timestampe_ss(uint32_t *tm) 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; @@ -460,7 +451,9 @@ errcode_t uaip_set_time_local(uint32_t seconds) 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; @@ -1595,7 +1588,10 @@ void uapi_delete_files(void) uint32_t uapi_calendar_store_date(void) { - +#if 1 + save_time(); + return ERRCODE_SUCC; +#else calendar_t date; time_t rawtime; @@ -1617,11 +1613,15 @@ uint32_t uapi_calendar_store_date(void) } 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) { @@ -1647,10 +1647,11 @@ uint32_t uapi_calendar_recover_date(void) } 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; @@ -1658,7 +1659,7 @@ void test_bandy_time(uint32_t time) 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"); diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.h b/code/sdk/drivers/peripheral/utils/custom_utils.h index c657778f0..5bd5c3b68 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -42,14 +42,20 @@ errcode_t uapi_get_timestampe_ms(uint32_t *tm); /*获取单位秒的时间戳*/ 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); diff --git a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c index 59ec91136..cda26d514 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c @@ -6,7 +6,7 @@ #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])) @@ -553,7 +553,34 @@ static uint32_t custom_test_time_synct(uint8_t *para, uint32_t paraLen, char *st 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; } @@ -621,6 +648,7 @@ static const at_cmd_table_t g_custom_utils_cmd[] = { { (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 *)" " }, diff --git a/code/sdk/middleware/chips/brandy/exception/chip_system_time.c b/code/sdk/middleware/chips/brandy/exception/chip_system_time.c index 2d0ce3ede..3ca6d5c3d 100644 --- a/code/sdk/middleware/chips/brandy/exception/chip_system_time.c +++ b/code/sdk/middleware/chips/brandy/exception/chip_system_time.c @@ -8,8 +8,10 @@ #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 @@ -37,16 +39,19 @@ void print_time_2(struct tm *date) 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); } @@ -72,7 +77,7 @@ uint32_t get_current_timestamp(void) 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; } @@ -98,30 +103,58 @@ void restore_time(void) 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); } @@ -133,7 +166,7 @@ uint32_t sync_time(uint32_t timestamp, uint32_t timezone) // 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"); diff --git a/code/sdk/middleware/chips/brandy/exception/chip_system_time.h b/code/sdk/middleware/chips/brandy/exception/chip_system_time.h index e097a4a25..a5c58adfe 100644 --- a/code/sdk/middleware/chips/brandy/exception/chip_system_time.h +++ b/code/sdk/middleware/chips/brandy/exception/chip_system_time.h @@ -50,18 +50,25 @@ void restore_time(void); * @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 diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/lwipopts.h b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/lwipopts.h index 414886b50..5cfb687e2 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/lwipopts.h +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/lwipopts.h @@ -275,13 +275,14 @@ #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) -- 2.17.1