added set time via ntp as command and retrieve all cron jobs
This commit is contained in:
@@ -67,7 +67,7 @@ const bool Cron::storeEvents()
|
||||
|
||||
ArduinoJson::JsonDocument thisJob;
|
||||
thisJob["name"] = eventName;
|
||||
thisJob["cronExpr"] = cron::to_cronstr(cronExpr);
|
||||
thisJob["cronExpr"] = cron::to_cronstr(cronExpr);
|
||||
thisJob["action"]["cmd"] = cmd;
|
||||
thisJob["action"]["params"] = cmdParams;
|
||||
|
||||
@@ -102,7 +102,7 @@ const bool Cron::addEvent(const std::string &name, const std::string &expr, cons
|
||||
const auto eventExpr(cron::make_cron(expr));
|
||||
const auto cmd = action["cmd"].as<std::string>();
|
||||
const auto params = action["params"];
|
||||
if (!commands::commandMap.contains(cmd))
|
||||
if (!commands::s_commandMap.contains(cmd))
|
||||
{
|
||||
LOG_ERROR("Cron unknown command [", cmd.c_str(), "]");
|
||||
return false;
|
||||
@@ -153,9 +153,14 @@ const bool Cron::delEvent(const std::string &name)
|
||||
return true;
|
||||
}
|
||||
|
||||
void cronLoop(void *dev)
|
||||
const Cron::CronEventMap &Cron::getAllEvents()
|
||||
{
|
||||
auto &cron = Cron::getInstance(*(devices_t *)dev);
|
||||
return m_cronMap;
|
||||
}
|
||||
|
||||
void cronLoop(void *cronPtr)
|
||||
{
|
||||
auto &cron = *(Cron *)cronPtr;
|
||||
while (true)
|
||||
{
|
||||
cron.processEvents();
|
||||
@@ -168,7 +173,7 @@ void Cron::startCron()
|
||||
if (!m_cronTaskHandle)
|
||||
{
|
||||
LOG_INFO("Cron starting loop");
|
||||
xTaskCreate(cronLoop, "cronLoop", STACK_DEPTH, (void *)&m_dev, PRIORITY, &m_cronTaskHandle);
|
||||
xTaskCreate(cronLoop, "cronLoop", STACK_DEPTH, this, PRIORITY, &m_cronTaskHandle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,7 +222,11 @@ const bool Cron::processEvents()
|
||||
next = cron::cron_next(cronexrp, nowTm); // update next execution time only if event was executed
|
||||
// otherwise time tracking is lost
|
||||
LOG_INFO("Cron running event [", eventName.c_str(), "] next execution time [", drivers::PCF85063::tm2str(next).c_str(), "]");
|
||||
commands::commandMap.at(cmd)(m_dev, cmdParams); // here the magic happens
|
||||
auto resp = commands::s_commandMap.at(cmd)(m_dev, cmdParams); // here the magic happens
|
||||
if (m_callback)
|
||||
{
|
||||
m_callback(resp);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user