Browse Source

添加修改时间接口

master
zhaohe 2 years ago
parent
commit
de5978dd2f
  1. 41
      src/main_control_service.cpp
  2. 2
      src/main_control_service.hpp

41
src/main_control_service.cpp

@ -30,6 +30,11 @@ static T jsonGet(json j) {
return val;
}
void MainControlService::dosystem(string order) {
logger->info("do:{}", order);
system(order.c_str());
}
void MainControlService::initialize() {
GET_TO_SERVICE(m_zconfig);
// system("systemctl restart zchromium.service");
@ -220,10 +225,10 @@ void MainControlService::processFrontEndMessage(weak_ptr<WebSocket> webSocket, j
if (cmdstr == "shutdown") {
int delayms = jsonGet<int>(cmd["delayms"]);
logger->info("shutdown {} ms", delayms);
m_autoshutdownThread.reset(new Thread("autoShutdown", [delayms]() {
m_autoshutdownThread.reset(new Thread("autoShutdown", [delayms, this]() {
ThisThread thisThread;
thisThread.sleepForMs(delayms);
system("shutdown -h now");
dosystem("shutdown -h now");
}));
return;
}
@ -231,10 +236,10 @@ void MainControlService::processFrontEndMessage(weak_ptr<WebSocket> webSocket, j
if (cmdstr == "shutdown") {
int delayms = jsonGet<int>(cmd["delayms"]);
logger->info("shutdown {} ms", delayms);
m_autoshutdownThread.reset(new Thread("autoShutdown", [delayms]() {
m_autoshutdownThread.reset(new Thread("autoShutdown", [delayms, this]() {
ThisThread thisThread;
thisThread.sleepForMs(delayms);
system("shutdown -h now");
dosystem("shutdown -h now");
}));
return;
}
@ -247,21 +252,39 @@ void MainControlService::processFrontEndMessage(weak_ptr<WebSocket> webSocket, j
"year":2023,
"month":8,
"day":25,
}
#endif
int32_t year = jsonGet<int>(cmd["year"]);
int32_t month = jsonGet<int>(cmd["month"]);
int32_t day = jsonGet<int>(cmd["day"]);
logger->info("updateDate {} {} {}", year, month, day);
// date -s "2023-01-02 02:32:32"
dosystem(fmt::format("date -s \"{}{}{} `date +%T`\"", year, month, day).c_str());
dosystem(fmt::format("hwclock -w").c_str());
return;
}
if (cmdstr == "updateTime") {
#if 0
{
"command":"updateTime",
"messageId":"1111222333444555",
"hour":11,
"min":12,
"second":13,
}
#endif
int32_t year = jsonGet<int>(cmd["year"]);
int32_t month = jsonGet<int>(cmd["month"]);
int32_t day = jsonGet<int>(cmd["day"]);
int32_t hour = jsonGet<int>(cmd["hour"]);
int32_t min = jsonGet<int>(cmd["min"]);
int32_t second = jsonGet<int>(cmd["second"]);
logger->info("updateDate {} {} {} {}:{}:{}", year, month, day, hour, min, second);
logger->info("updateDate {}:{}:{}", hour, min, second);
// date -s "2023-01-02 02:32:32"
dosystem(fmt::format("date -s \"`date +%Y-%m-%d` {}:{}:{}\"", hour, min, second).c_str());
dosystem(fmt::format("hwclock -w").c_str());
return;
}
/*******************************************************************************
* *
*******************************************************************************/

2
src/main_control_service.hpp

@ -90,5 +90,7 @@ class MainControlService : public enable_shared_from_this<MainControlService> {
void processFrontEndMessage(weak_ptr<WebSocket> webSocket, json& cmd, json& receipt);
json createSensorDataJson();
void dosystem(string order) ;
};
} // namespace iflytop
Loading…
Cancel
Save