mirror of
https://github.com/g4klx/MMDVMHost
synced 2025-12-23 16:55:52 +08:00
Add host startup and closedown messages to JSON/MQTT.
This commit is contained in:
@@ -369,6 +369,7 @@ int CMMDVMHost::run()
|
|||||||
m_display = CDisplay::createDisplay(m_conf, m_modem);
|
m_display = CDisplay::createDisplay(m_conf, m_modem);
|
||||||
|
|
||||||
LogInfo("Opening network connections");
|
LogInfo("Opening network connections");
|
||||||
|
writeJSONMessage("Opening network connections");
|
||||||
|
|
||||||
if (m_dstarEnabled && m_conf.getDStarNetworkEnabled()) {
|
if (m_dstarEnabled && m_conf.getDStarNetworkEnabled()) {
|
||||||
ret = createDStarNetwork();
|
ret = createDStarNetwork();
|
||||||
@@ -506,6 +507,7 @@ int CMMDVMHost::run()
|
|||||||
}
|
}
|
||||||
|
|
||||||
LogInfo("Starting protocol handlers");
|
LogInfo("Starting protocol handlers");
|
||||||
|
writeJSONMessage("Starting protocol handlers");
|
||||||
|
|
||||||
CStopWatch stopWatch;
|
CStopWatch stopWatch;
|
||||||
stopWatch.start();
|
stopWatch.start();
|
||||||
@@ -785,6 +787,7 @@ int CMMDVMHost::run()
|
|||||||
setMode(MODE_IDLE);
|
setMode(MODE_IDLE);
|
||||||
|
|
||||||
LogInfo("MMDVMHost-%s is running", VERSION);
|
LogInfo("MMDVMHost-%s is running", VERSION);
|
||||||
|
writeJSONMessage("MMDVMHost is running");
|
||||||
|
|
||||||
while (!m_killed) {
|
while (!m_killed) {
|
||||||
bool lockout = m_modem->hasLockout();
|
bool lockout = m_modem->hasLockout();
|
||||||
@@ -1333,6 +1336,7 @@ int CMMDVMHost::run()
|
|||||||
m_nxdnLookup->stop();
|
m_nxdnLookup->stop();
|
||||||
|
|
||||||
LogInfo("Closing network connections");
|
LogInfo("Closing network connections");
|
||||||
|
writeJSONMessage("Closing network connections");
|
||||||
|
|
||||||
if (m_dstarNetwork != NULL) {
|
if (m_dstarNetwork != NULL) {
|
||||||
m_dstarNetwork->close();
|
m_dstarNetwork->close();
|
||||||
@@ -1390,6 +1394,7 @@ int CMMDVMHost::run()
|
|||||||
}
|
}
|
||||||
|
|
||||||
LogInfo("Stopping protocol handlers");
|
LogInfo("Stopping protocol handlers");
|
||||||
|
writeJSONMessage("Stopping protocol handlers");
|
||||||
|
|
||||||
delete m_dstar;
|
delete m_dstar;
|
||||||
delete m_dmr;
|
delete m_dmr;
|
||||||
@@ -1402,6 +1407,7 @@ int CMMDVMHost::run()
|
|||||||
delete m_ax25;
|
delete m_ax25;
|
||||||
|
|
||||||
LogInfo("MMDVMHost-%s has stopped", VERSION);
|
LogInfo("MMDVMHost-%s has stopped", VERSION);
|
||||||
|
writeJSONMessage("MMDVMHost has stopped");
|
||||||
|
|
||||||
m_modem->close();
|
m_modem->close();
|
||||||
delete m_modem;
|
delete m_modem;
|
||||||
@@ -2047,7 +2053,7 @@ void CMMDVMHost::setMode(unsigned char mode)
|
|||||||
m_modeTimer.start();
|
m_modeTimer.start();
|
||||||
m_cwIdTimer.stop();
|
m_cwIdTimer.stop();
|
||||||
createLockFile("D-Star");
|
createLockFile("D-Star");
|
||||||
writeJSON("D-Star");
|
writeJSONMode("D-Star");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MODE_DMR:
|
case MODE_DMR:
|
||||||
@@ -2096,7 +2102,7 @@ void CMMDVMHost::setMode(unsigned char mode)
|
|||||||
m_modeTimer.start();
|
m_modeTimer.start();
|
||||||
m_cwIdTimer.stop();
|
m_cwIdTimer.stop();
|
||||||
createLockFile("DMR");
|
createLockFile("DMR");
|
||||||
writeJSON("DMR");
|
writeJSONMode("DMR");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MODE_YSF:
|
case MODE_YSF:
|
||||||
@@ -2141,7 +2147,7 @@ void CMMDVMHost::setMode(unsigned char mode)
|
|||||||
m_modeTimer.start();
|
m_modeTimer.start();
|
||||||
m_cwIdTimer.stop();
|
m_cwIdTimer.stop();
|
||||||
createLockFile("System Fusion");
|
createLockFile("System Fusion");
|
||||||
writeJSON("YSF");
|
writeJSONMode("YSF");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MODE_P25:
|
case MODE_P25:
|
||||||
@@ -2186,7 +2192,7 @@ void CMMDVMHost::setMode(unsigned char mode)
|
|||||||
m_modeTimer.start();
|
m_modeTimer.start();
|
||||||
m_cwIdTimer.stop();
|
m_cwIdTimer.stop();
|
||||||
createLockFile("P25");
|
createLockFile("P25");
|
||||||
writeJSON("P25");
|
writeJSONMode("P25");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MODE_NXDN:
|
case MODE_NXDN:
|
||||||
@@ -2231,7 +2237,7 @@ void CMMDVMHost::setMode(unsigned char mode)
|
|||||||
m_modeTimer.start();
|
m_modeTimer.start();
|
||||||
m_cwIdTimer.stop();
|
m_cwIdTimer.stop();
|
||||||
createLockFile("NXDN");
|
createLockFile("NXDN");
|
||||||
writeJSON("NXDN");
|
writeJSONMode("NXDN");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MODE_M17:
|
case MODE_M17:
|
||||||
@@ -2276,7 +2282,7 @@ void CMMDVMHost::setMode(unsigned char mode)
|
|||||||
m_modeTimer.start();
|
m_modeTimer.start();
|
||||||
m_cwIdTimer.stop();
|
m_cwIdTimer.stop();
|
||||||
createLockFile("M17");
|
createLockFile("M17");
|
||||||
writeJSON("M17");
|
writeJSONMode("M17");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MODE_POCSAG:
|
case MODE_POCSAG:
|
||||||
@@ -2321,7 +2327,7 @@ void CMMDVMHost::setMode(unsigned char mode)
|
|||||||
m_modeTimer.start();
|
m_modeTimer.start();
|
||||||
m_cwIdTimer.stop();
|
m_cwIdTimer.stop();
|
||||||
createLockFile("POCSAG");
|
createLockFile("POCSAG");
|
||||||
writeJSON("POCSAG");
|
writeJSONMode("POCSAG");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MODE_FM:
|
case MODE_FM:
|
||||||
@@ -2371,7 +2377,7 @@ void CMMDVMHost::setMode(unsigned char mode)
|
|||||||
m_modeTimer.start();
|
m_modeTimer.start();
|
||||||
m_cwIdTimer.stop();
|
m_cwIdTimer.stop();
|
||||||
createLockFile("FM");
|
createLockFile("FM");
|
||||||
writeJSON("FM");
|
writeJSONMode("FM");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MODE_LOCKOUT:
|
case MODE_LOCKOUT:
|
||||||
@@ -2421,7 +2427,7 @@ void CMMDVMHost::setMode(unsigned char mode)
|
|||||||
m_modeTimer.stop();
|
m_modeTimer.stop();
|
||||||
m_cwIdTimer.stop();
|
m_cwIdTimer.stop();
|
||||||
removeLockFile();
|
removeLockFile();
|
||||||
writeJSON("lockout");
|
writeJSONMode("lockout");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MODE_ERROR:
|
case MODE_ERROR:
|
||||||
@@ -2471,7 +2477,7 @@ void CMMDVMHost::setMode(unsigned char mode)
|
|||||||
m_modeTimer.stop();
|
m_modeTimer.stop();
|
||||||
m_cwIdTimer.stop();
|
m_cwIdTimer.stop();
|
||||||
removeLockFile();
|
removeLockFile();
|
||||||
writeJSON("error");
|
writeJSONMode("error");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -2530,7 +2536,7 @@ void CMMDVMHost::setMode(unsigned char mode)
|
|||||||
m_mode = MODE_IDLE;
|
m_mode = MODE_IDLE;
|
||||||
m_modeTimer.stop();
|
m_modeTimer.stop();
|
||||||
removeLockFile();
|
removeLockFile();
|
||||||
writeJSON("idle");
|
writeJSONMode("idle");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2821,7 +2827,7 @@ void CMMDVMHost::buildNetworkHostsString(std::string &str)
|
|||||||
str += std::string(" fm:\"") + ((m_fmEnabled && (m_fmNetwork != NULL)) ? m_conf.getFMGatewayAddress() : "NONE") + "\"";
|
str += std::string(" fm:\"") + ((m_fmEnabled && (m_fmNetwork != NULL)) ? m_conf.getFMGatewayAddress() : "NONE") + "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMMDVMHost::writeJSON(const std::string& mode)
|
void CMMDVMHost::writeJSONMode(const std::string& mode)
|
||||||
{
|
{
|
||||||
nlohmann::json json;
|
nlohmann::json json;
|
||||||
|
|
||||||
@@ -2831,3 +2837,13 @@ void CMMDVMHost::writeJSON(const std::string& mode)
|
|||||||
WriteJSON("MMDVM", json);
|
WriteJSON("MMDVM", json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CMMDVMHost::writeJSONMessage(const std::string& message)
|
||||||
|
{
|
||||||
|
nlohmann::json json;
|
||||||
|
|
||||||
|
json["timestamp"] = CUtils::createTimestamp();
|
||||||
|
json["message"] = message;
|
||||||
|
|
||||||
|
WriteJSON("MMDVM", json);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -142,7 +142,8 @@ private:
|
|||||||
void createLockFile(const char* mode) const;
|
void createLockFile(const char* mode) const;
|
||||||
void removeLockFile() const;
|
void removeLockFile() const;
|
||||||
|
|
||||||
void writeJSON(const std::string& mode);
|
void writeJSONMode(const std::string& mode);
|
||||||
|
void writeJSONMessage(const std::string& message);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -35,7 +35,8 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"timestamp": {"$ref": "#/$defs/timestamp"},
|
"timestamp": {"$ref": "#/$defs/timestamp"},
|
||||||
"mode": {"$ref": "#/$defs/mmdvm_mode"},
|
"mode": {"$ref": "#/$defs/mmdvm_mode"},
|
||||||
"required": ["timestamp", "mode"]
|
"message": {"type": "string"},
|
||||||
|
"required": ["timestamp"]
|
||||||
},
|
},
|
||||||
|
|
||||||
"D-Star": {
|
"D-Star": {
|
||||||
|
|||||||
Reference in New Issue
Block a user