add enum for scan status
This commit is contained in:
+10
-2
@@ -40,6 +40,14 @@ using std::map;
|
|||||||
class UserInfo;
|
class UserInfo;
|
||||||
class DataHandler;
|
class DataHandler;
|
||||||
|
|
||||||
|
/** type for scan status. */
|
||||||
|
enum scanStatus_t {
|
||||||
|
SCAN_STATUS_NONE = 0, //!< no scan status (never started before)
|
||||||
|
SCAN_STATUS_RUNNING = 1, //!< scan is currently running
|
||||||
|
SCAN_STATUS_FINISHED = 2, //!< scan is finished
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function for getting the argp definition for all known @a DataHandler instances.
|
* Helper function for getting the argp definition for all known @a DataHandler instances.
|
||||||
* @return a pointer to the argp_child structure, or nullptr.
|
* @return a pointer to the argp_child structure, or nullptr.
|
||||||
@@ -162,9 +170,9 @@ class DataSink : virtual public DataHandler {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify the sink of the latest scan status.
|
* Notify the sink of the latest scan status.
|
||||||
* @param scanStatus a string describing the scan status.
|
* @param scanStatus the scan status.
|
||||||
*/
|
*/
|
||||||
virtual void notifyScanStatus(const string& scanStatus) {}
|
virtual void notifyScanStatus(scanStatus_t scanStatus) {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** the allowed access levels. */
|
/** the allowed access levels. */
|
||||||
|
|||||||
@@ -218,7 +218,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 = ".";
|
scanStatus_t lastScanStatus = SCAN_STATUS_NONE;
|
||||||
time(&now);
|
time(&now);
|
||||||
start = now;
|
start = now;
|
||||||
lastTaskRun = now;
|
lastTaskRun = now;
|
||||||
@@ -254,7 +254,7 @@ void MainLoop::run() {
|
|||||||
}
|
}
|
||||||
if (m_scanConfig) {
|
if (m_scanConfig) {
|
||||||
bool loadDelay = false;
|
bool loadDelay = false;
|
||||||
string scanStatus = lastScanStatus;
|
scanStatus_t 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;
|
||||||
@@ -262,7 +262,7 @@ void MainLoop::run() {
|
|||||||
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) {
|
if (result == RESULT_OK) {
|
||||||
scanStatus = "running";
|
scanStatus = SCAN_STATUS_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");
|
||||||
@@ -286,7 +286,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";
|
scanStatus = SCAN_STATUS_RUNNING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (result != RESULT_OK) {
|
if (result != RESULT_OK) {
|
||||||
@@ -301,11 +301,9 @@ void MainLoop::run() {
|
|||||||
if (lastScanAddress == SYN) {
|
if (lastScanAddress == SYN) {
|
||||||
taskDelay = 5;
|
taskDelay = 5;
|
||||||
lastScanAddress = 0;
|
lastScanAddress = 0;
|
||||||
scanStatus = "finished";
|
scanStatus = SCAN_STATUS_FINISHED;
|
||||||
} else {
|
} else {
|
||||||
if (scanStatus != "running") {
|
scanStatus = SCAN_STATUS_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;
|
||||||
|
|||||||
@@ -479,7 +479,7 @@ void splitFields(const string& str, vector<string>* row);
|
|||||||
|
|
||||||
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_lastScanStatus("."), m_lastErrorLogTime(0) {
|
m_initialConnectFailed(false), m_lastUpdateCheckResult("."), m_lastScanStatus(SCAN_STATUS_NONE), m_lastErrorLogTime(0) {
|
||||||
m_definitionsSince = 0;
|
m_definitionsSince = 0;
|
||||||
m_mosquitto = nullptr;
|
m_mosquitto = nullptr;
|
||||||
bool hasIntegration = false;
|
bool hasIntegration = false;
|
||||||
@@ -831,12 +831,23 @@ void MqttHandler::notifyUpdateCheckResult(const string& checkResult) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MqttHandler::notifyScanStatus(const string& scanStatus) {
|
void MqttHandler::notifyScanStatus(scanStatus_t scanStatus) {
|
||||||
if (scanStatus != m_lastScanStatus) {
|
if (scanStatus != m_lastScanStatus) {
|
||||||
m_lastScanStatus = scanStatus;
|
m_lastScanStatus = scanStatus;
|
||||||
if (m_globalTopic.has("name")) {
|
if (m_globalTopic.has("name")) {
|
||||||
const string sep = (g_publishFormat & OF_JSON) ? "\"" : "";
|
const string sep = (g_publishFormat & OF_JSON) ? "\"" : "";
|
||||||
publishTopic(m_globalTopic.get("", "scan"), sep + (scanStatus.empty() ? "OK" : scanStatus) + sep, true);
|
string message;
|
||||||
|
switch (scanStatus) {
|
||||||
|
case SCAN_STATUS_RUNNING:
|
||||||
|
message = "running";
|
||||||
|
break;
|
||||||
|
case SCAN_STATUS_FINISHED:
|
||||||
|
message = "finished";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
message = "OK";
|
||||||
|
}
|
||||||
|
publishTopic(m_globalTopic.get("", "scan"), sep + message + sep, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ class MqttHandler : public DataSink, public DataSource, public WaitThread {
|
|||||||
void notifyUpdateCheckResult(const string& checkResult) override;
|
void notifyUpdateCheckResult(const string& checkResult) override;
|
||||||
|
|
||||||
// @copydoc
|
// @copydoc
|
||||||
void notifyScanStatus(const string& scanStatus) override;
|
void notifyScanStatus(scanStatus_t scanStatus) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// @copydoc
|
// @copydoc
|
||||||
@@ -209,7 +209,7 @@ class MqttHandler : public DataSink, public DataSource, public WaitThread {
|
|||||||
string m_lastUpdateCheckResult;
|
string m_lastUpdateCheckResult;
|
||||||
|
|
||||||
/** the last scan status. */
|
/** the last scan status. */
|
||||||
string m_lastScanStatus;
|
scanStatus_t 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