modify timing logic.

This commit is contained in:
pandx 2024-10-28 11:02:29 +08:00
parent 70a6cdb10b
commit 38e2065625

View File

@ -77,9 +77,19 @@ std::string JsonData::JsonCmd_Cgi_02(Param_02 &param) {
if (0 == param.mMode) { if (0 == param.mMode) {
jsonVal["type"] = "SET"; jsonVal["type"] = "SET";
if (param.mMode == 0) { //本地校时 if (param.mMode == 0) { //本地校时
SetTime((unsigned long)param.mTimeStamp); unsigned long set_timestamp = (unsigned long)param.mTimeStamp;
mssleep(200); char localtimestamp[32] = {0};
system("hwclock -w"); 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 - set_timestamp);
if (diff_seconds > 5) {
SetTime((unsigned long)param.mTimeStamp);
mssleep(200);
system("hwclock -w");
} else {
zlog_warn(zct, "diff seconds:%ld lesser than 5, not to modify", diff_seconds);
}
} else if (param.mMode == 1) { //与服务器校时 } else if (param.mMode == 1) { //与服务器校时
char buf[256] = {0}; char buf[256] = {0};
sprintf(buf, "{\"dataNodeGatewayNo\":\"%s\",\"cmd\":\"12\",\"status\":\"REQ\"}", GlobalConfig::MacAddr_G.c_str()); sprintf(buf, "{\"dataNodeGatewayNo\":\"%s\",\"cmd\":\"12\",\"status\":\"REQ\"}", GlobalConfig::MacAddr_G.c_str());