process timing to cause ts adjustment.

This commit is contained in:
pandx 2024-11-13 10:41:25 +08:00
parent a36142bcf8
commit d60443eca0
2 changed files with 19 additions and 6 deletions

View File

@ -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 &param) {
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);
}

View File

@ -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<unsigned long>(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: {