From d60443eca0777eb39770d5d58aef1451535d3b26 Mon Sep 17 00:00:00 2001 From: pandx Date: Wed, 13 Nov 2024 10:41:25 +0800 Subject: [PATCH] process timing to cause ts adjustment. --- jsonparse/web_cmd_parse.cpp | 2 ++ localserver/mqtt_cmd.cpp | 23 +++++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/jsonparse/web_cmd_parse.cpp b/jsonparse/web_cmd_parse.cpp index 92f3886..573e3b3 100644 --- a/jsonparse/web_cmd_parse.cpp +++ b/jsonparse/web_cmd_parse.cpp @@ -4,6 +4,7 @@ #include "mqttclient/mqtt_client.h" #include "dbaccess/sql_db.hpp" #include "platform/platform_init.hpp" +#include "scheduler/schedule.hpp" #include "utility/md5.h" extern zlog_category_t *zct; @@ -87,6 +88,7 @@ std::string JsonData::JsonCmd_Cgi_02(Param_02 ¶m) { SetTime((unsigned long)param.mTimeStamp); mssleep(200); system("hwclock -w"); + scheduler::instance().ModifyScheduleTs(set_timestamp - current_timestamp); } else { zlog_warn(zct, "diff seconds:%ld lesser than 5, not to modify", diff_seconds); } diff --git a/localserver/mqtt_cmd.cpp b/localserver/mqtt_cmd.cpp index 438191c..947255f 100644 --- a/localserver/mqtt_cmd.cpp +++ b/localserver/mqtt_cmd.cpp @@ -7,6 +7,7 @@ #include "mqttclient/mqtt_client.h" #include "dbaccess/sql_db.hpp" #include "utility/secure.hpp" +#include "scheduler/schedule.hpp" #include "jsonparse/communication_cmd.hpp" extern zlog_category_t *zct; @@ -62,12 +63,22 @@ void LocalServer::HandleFromServer(const char *pData_r, int pLen, const char *to case kTiming: { std::string timestamp = recvBody["timestamp"].asString(); unsigned long itimestamp = atol(timestamp.c_str()); - SetTime(itimestamp); - mssleep(200); - system("hwclock -w"); - if (!recvValue["ZoneId"].isNull() && recvValue["ZoneId"].asString().length() > 0) { - std::string zoneid = recvValue["ZoneId"].asString(); - ZoneConfig(zoneid); + char localtimestamp[32] = {0}; + GetTimeNet(localtimestamp, 1); + std::string current_system_timestamp = std::string(localtimestamp); + unsigned long current_timestamp = boost::lexical_cast(current_system_timestamp); + unsigned long diff_seconds = abs(current_timestamp - itimestamp); + if (diff_seconds > 5) { + SetTime(itimestamp); + mssleep(200); + system("hwclock -w"); + scheduler::instance().ModifyScheduleTs(itimestamp - current_timestamp); + if (!recvValue["ZoneId"].isNull() && recvValue["ZoneId"].asString().length() > 0) { + std::string zoneid = recvValue["ZoneId"].asString(); + ZoneConfig(zoneid); + } + } else { + zlog_warn(zct, "[Timing] diff seconds:%ld lesser than 5, not to modify", diff_seconds); } } break; case 13: {