add global/scan topic revealing status of --scanconfig option initiated scan (fixes #304)
This commit is contained in:
@@ -160,6 +160,12 @@ class DataSink : virtual public DataHandler {
|
|||||||
*/
|
*/
|
||||||
virtual void notifyUpdateCheckResult(const string& checkResult) {}
|
virtual void notifyUpdateCheckResult(const string& checkResult) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notify the sink of the latest scan status.
|
||||||
|
* @param scanStatus a string describing the scan status.
|
||||||
|
*/
|
||||||
|
virtual void notifyScanStatus(const string& scanStatus) {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** the allowed access levels. */
|
/** the allowed access levels. */
|
||||||
string m_levels;
|
string m_levels;
|
||||||
|
|||||||
@@ -217,6 +217,7 @@ void MainLoop::run() {
|
|||||||
time_t lastTaskRun, now, start, lastSignal = 0, since, sinkSince = 1, nextCheckRun;
|
time_t lastTaskRun, now, start, lastSignal = 0, since, sinkSince = 1, nextCheckRun;
|
||||||
int taskDelay = 5;
|
int taskDelay = 5;
|
||||||
symbol_t lastScanAddress = 0; // 0 is known to be a master
|
symbol_t lastScanAddress = 0; // 0 is known to be a master
|
||||||
|
string lastScanStatus = ".";
|
||||||
time(&now);
|
time(&now);
|
||||||
start = now;
|
start = now;
|
||||||
lastTaskRun = now;
|
lastTaskRun = now;
|
||||||
@@ -252,12 +253,16 @@ void MainLoop::run() {
|
|||||||
}
|
}
|
||||||
if (m_scanConfig) {
|
if (m_scanConfig) {
|
||||||
bool loadDelay = false;
|
bool loadDelay = false;
|
||||||
|
string scanStatus = lastScanStatus;
|
||||||
if (m_initialScan != ESC && reload && m_busHandler->hasSignal()) {
|
if (m_initialScan != ESC && reload && m_busHandler->hasSignal()) {
|
||||||
loadDelay = true;
|
loadDelay = true;
|
||||||
result_t result;
|
result_t result;
|
||||||
if (m_initialScan == SYN) {
|
if (m_initialScan == SYN) {
|
||||||
logNotice(lf_main, "starting initial full scan");
|
logNotice(lf_main, "starting initial full scan");
|
||||||
result = m_busHandler->startScan(true, "*");
|
result = m_busHandler->startScan(true, "*");
|
||||||
|
if (result == RESULT_OK) {
|
||||||
|
scanStatus = "running";
|
||||||
|
}
|
||||||
} else if (m_initialScan == BROADCAST) {
|
} else if (m_initialScan == BROADCAST) {
|
||||||
logNotice(lf_main, "starting initial broadcast scan");
|
logNotice(lf_main, "starting initial broadcast scan");
|
||||||
Message* message = m_messages->getScanMessage(BROADCAST);
|
Message* message = m_messages->getScanMessage(BROADCAST);
|
||||||
@@ -280,6 +285,7 @@ void MainLoop::run() {
|
|||||||
if (m_busHandler->formatScanResult(m_initialScan, false, &ret)) {
|
if (m_busHandler->formatScanResult(m_initialScan, false, &ret)) {
|
||||||
logNotice(lf_main, "initial scan result: %s", ret.str().c_str());
|
logNotice(lf_main, "initial scan result: %s", ret.str().c_str());
|
||||||
}
|
}
|
||||||
|
scanStatus = "running";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (result != RESULT_OK) {
|
if (result != RESULT_OK) {
|
||||||
@@ -294,7 +300,11 @@ void MainLoop::run() {
|
|||||||
if (lastScanAddress == SYN) {
|
if (lastScanAddress == SYN) {
|
||||||
taskDelay = 5;
|
taskDelay = 5;
|
||||||
lastScanAddress = 0;
|
lastScanAddress = 0;
|
||||||
|
scanStatus = "finished";
|
||||||
} else {
|
} else {
|
||||||
|
if (scanStatus!="running") {
|
||||||
|
scanStatus = "running";
|
||||||
|
}
|
||||||
nextCheckRun = now + CHECK_INITIAL_DELAY;
|
nextCheckRun = now + CHECK_INITIAL_DELAY;
|
||||||
result_t result = m_busHandler->scanAndWait(lastScanAddress, true);
|
result_t result = m_busHandler->scanAndWait(lastScanAddress, true);
|
||||||
taskDelay = (result == RESULT_ERR_NO_SIGNAL) ? 10 : 1;
|
taskDelay = (result == RESULT_ERR_NO_SIGNAL) ? 10 : 1;
|
||||||
@@ -305,6 +315,12 @@ void MainLoop::run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (scanStatus != lastScanStatus && !dataSinks.empty()) {
|
||||||
|
lastScanStatus = scanStatus;
|
||||||
|
for (const auto dataSink : dataSinks) {
|
||||||
|
dataSink->notifyScanStatus(scanStatus);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (reload && m_busHandler->hasSignal()) {
|
} else if (reload && m_busHandler->hasSignal()) {
|
||||||
reload = false;
|
reload = false;
|
||||||
// execute initial instructions
|
// execute initial instructions
|
||||||
|
|||||||
Regular → Executable
+10
-1
@@ -435,7 +435,7 @@ void on_message(
|
|||||||
|
|
||||||
MqttHandler::MqttHandler(UserInfo* userInfo, BusHandler* busHandler, MessageMap* messages)
|
MqttHandler::MqttHandler(UserInfo* userInfo, BusHandler* busHandler, MessageMap* messages)
|
||||||
: DataSink(userInfo, "mqtt"), DataSource(busHandler), WaitThread(), m_messages(messages), m_connected(false),
|
: DataSink(userInfo, "mqtt"), DataSource(busHandler), WaitThread(), m_messages(messages), m_connected(false),
|
||||||
m_initialConnectFailed(false), m_lastUpdateCheckResult("."), m_lastErrorLogTime(0) {
|
m_initialConnectFailed(false), m_lastUpdateCheckResult("."), m_lastScanStatus("."), m_lastErrorLogTime(0) {
|
||||||
m_publishByField = false;
|
m_publishByField = false;
|
||||||
m_mosquitto = nullptr;
|
m_mosquitto = nullptr;
|
||||||
if (g_topicFields.empty()) {
|
if (g_topicFields.empty()) {
|
||||||
@@ -711,6 +711,14 @@ void MqttHandler::notifyUpdateCheckResult(const string& checkResult) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MqttHandler::notifyScanStatus(const string& scanStatus) {
|
||||||
|
if (scanStatus != m_lastScanStatus) {
|
||||||
|
m_lastScanStatus = scanStatus;
|
||||||
|
const string sep = (g_publishFormat & OF_JSON) ? "\"" : "";
|
||||||
|
publishTopic(m_globalTopic+"scan", sep + (scanStatus.empty() ? "OK" : scanStatus) + sep, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MqttHandler::run() {
|
void MqttHandler::run() {
|
||||||
time_t lastTaskRun, now, start, lastSignal = 0, lastUpdates = 0;
|
time_t lastTaskRun, now, start, lastSignal = 0, lastUpdates = 0;
|
||||||
bool signal = false;
|
bool signal = false;
|
||||||
@@ -787,6 +795,7 @@ void MqttHandler::run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
publishTopic(signalTopic, "false", true);
|
publishTopic(signalTopic, "false", true);
|
||||||
|
publishTopic(m_globalTopic+"scan", "", true); // clear retain of scan status
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MqttHandler::handleTraffic(bool allowReconnect) {
|
bool MqttHandler::handleTraffic(bool allowReconnect) {
|
||||||
|
|||||||
@@ -91,7 +91,10 @@ class MqttHandler : public DataSink, public DataSource, public WaitThread {
|
|||||||
// @copydoc
|
// @copydoc
|
||||||
void notifyUpdateCheckResult(const string& checkResult) override;
|
void notifyUpdateCheckResult(const string& checkResult) override;
|
||||||
|
|
||||||
protected:
|
// @copydoc
|
||||||
|
void notifyScanStatus(const string& scanStatus) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
// @copydoc
|
// @copydoc
|
||||||
void run() override;
|
void run() override;
|
||||||
|
|
||||||
@@ -159,6 +162,9 @@ class MqttHandler : public DataSink, public DataSource, public WaitThread {
|
|||||||
/** the last update check result. */
|
/** the last update check result. */
|
||||||
string m_lastUpdateCheckResult;
|
string m_lastUpdateCheckResult;
|
||||||
|
|
||||||
|
/** the last scan status. */
|
||||||
|
string m_lastScanStatus;
|
||||||
|
|
||||||
/** the last system time when a communication error was logged. */
|
/** the last system time when a communication error was logged. */
|
||||||
time_t m_lastErrorLogTime;
|
time_t m_lastErrorLogTime;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user