Merge branch 'mqtt' into mqtt_plus

This commit is contained in:
Jonathan Naylor
2023-06-16 15:45:17 +01:00
26 changed files with 1304 additions and 506 deletions

View File

@@ -117,15 +117,24 @@ int main(int argc, char** argv)
delete host;
if (m_signal == 2)
::LogInfo("MMDVMHost-%s exited on receipt of SIGINT", VERSION);
if (m_signal == 15)
::LogInfo("MMDVMHost-%s exited on receipt of SIGTERM", VERSION);
if (m_signal == 1)
::LogInfo("MMDVMHost-%s is restarting on receipt of SIGHUP", VERSION);
} while (m_signal == 1);
switch (m_signal) {
case 2:
::LogInfo("MMDVMHost-%s exited on receipt of SIGINT", VERSION);
break;
case 15:
::LogInfo("MMDVMHost-%s exited on receipt of SIGTERM", VERSION);
break;
case 1:
::LogInfo("MMDVMHost-%s exited on receipt of SIGHUP", VERSION);
break;
case 10:
::LogInfo("MMDVMHost-%s is restarting on receipt of SIGUSR1", VERSION);
break;
default:
::LogInfo("MMDVMHost-%s exited on receipt of an unknown signal", VERSION);
break;
}
} while (m_signal == 10);
::LogFinalise();
@@ -301,8 +310,8 @@ int CMMDVMHost::run()
LogInfo(HEADER3);
LogInfo(HEADER4);
LogMessage("MMDVMHost-%s is starting", VERSION);
LogMessage("Built %s %s (GitID #%.7s)", __TIME__, __DATE__, gitversion);
LogInfo("MMDVMHost-%s is starting", VERSION);
LogInfo("Built %s %s (GitID #%.7s)", __TIME__, __DATE__, gitversion);
readParams();
@@ -357,6 +366,9 @@ int CMMDVMHost::run()
m_display = CDisplay::createDisplay(m_conf, m_modem);
LogInfo("Opening network connections");
writeJSONMessage("Opening network connections");
if (m_dstarEnabled && m_conf.getDStarNetworkEnabled()) {
ret = createDStarNetwork();
if (!ret)
@@ -492,6 +504,9 @@ int CMMDVMHost::run()
m_dmrLookup->read();
}
LogInfo("Starting protocol handlers");
writeJSONMessage("Starting protocol handlers");
CStopWatch stopWatch;
stopWatch.start();
@@ -769,7 +784,8 @@ int CMMDVMHost::run()
setMode(MODE_IDLE);
LogMessage("MMDVMHost-%s is running", VERSION);
LogInfo("MMDVMHost-%s is running", VERSION);
writeJSONMessage("MMDVMHost is running");
while (!m_killed) {
bool lockout = m_modem->hasLockout();
@@ -1311,18 +1327,15 @@ int CMMDVMHost::run()
setMode(MODE_QUIT);
m_modem->close();
delete m_modem;
m_display->close();
delete m_display;
if (m_dmrLookup != NULL)
m_dmrLookup->stop();
if (m_nxdnLookup != NULL)
m_nxdnLookup->stop();
LogInfo("Closing network connections");
writeJSONMessage("Closing network connections");
if (m_dstarNetwork != NULL) {
m_dstarNetwork->close();
delete m_dstarNetwork;
@@ -1378,10 +1391,8 @@ int CMMDVMHost::run()
delete m_remoteControl;
}
if (m_mqtt != NULL) {
m_mqtt->close();
delete m_mqtt;
}
LogInfo("Stopping protocol handlers");
writeJSONMessage("Stopping protocol handlers");
delete m_dstar;
delete m_dmr;
@@ -1393,6 +1404,20 @@ int CMMDVMHost::run()
delete m_fm;
delete m_ax25;
LogInfo("MMDVMHost-%s has stopped", VERSION);
writeJSONMessage("MMDVMHost has stopped");
m_modem->close();
delete m_modem;
m_display->close();
delete m_display;
if (m_mqtt != NULL) {
m_mqtt->close();
delete m_mqtt;
}
return 0;
}
@@ -1994,7 +2019,7 @@ void CMMDVMHost::setMode(unsigned char mode)
m_modeTimer.start();
m_cwIdTimer.stop();
createLockFile("D-Star");
writeJSON("D-Star");
writeJSONMode("D-Star");
break;
case MODE_DMR:
@@ -2043,7 +2068,7 @@ void CMMDVMHost::setMode(unsigned char mode)
m_modeTimer.start();
m_cwIdTimer.stop();
createLockFile("DMR");
writeJSON("DMR");
writeJSONMode("DMR");
break;
case MODE_YSF:
@@ -2088,7 +2113,7 @@ void CMMDVMHost::setMode(unsigned char mode)
m_modeTimer.start();
m_cwIdTimer.stop();
createLockFile("System Fusion");
writeJSON("YSF");
writeJSONMode("YSF");
break;
case MODE_P25:
@@ -2133,7 +2158,7 @@ void CMMDVMHost::setMode(unsigned char mode)
m_modeTimer.start();
m_cwIdTimer.stop();
createLockFile("P25");
writeJSON("P25");
writeJSONMode("P25");
break;
case MODE_NXDN:
@@ -2178,7 +2203,7 @@ void CMMDVMHost::setMode(unsigned char mode)
m_modeTimer.start();
m_cwIdTimer.stop();
createLockFile("NXDN");
writeJSON("NXDN");
writeJSONMode("NXDN");
break;
case MODE_M17:
@@ -2223,7 +2248,7 @@ void CMMDVMHost::setMode(unsigned char mode)
m_modeTimer.start();
m_cwIdTimer.stop();
createLockFile("M17");
writeJSON("M17");
writeJSONMode("M17");
break;
case MODE_POCSAG:
@@ -2268,7 +2293,7 @@ void CMMDVMHost::setMode(unsigned char mode)
m_modeTimer.start();
m_cwIdTimer.stop();
createLockFile("POCSAG");
writeJSON("POCSAG");
writeJSONMode("POCSAG");
break;
case MODE_FM:
@@ -2318,7 +2343,7 @@ void CMMDVMHost::setMode(unsigned char mode)
m_modeTimer.start();
m_cwIdTimer.stop();
createLockFile("FM");
writeJSON("FM");
writeJSONMode("FM");
break;
case MODE_LOCKOUT:
@@ -2368,7 +2393,7 @@ void CMMDVMHost::setMode(unsigned char mode)
m_modeTimer.stop();
m_cwIdTimer.stop();
removeLockFile();
writeJSON("lockout");
writeJSONMode("lockout");
break;
case MODE_ERROR:
@@ -2418,7 +2443,7 @@ void CMMDVMHost::setMode(unsigned char mode)
m_modeTimer.stop();
m_cwIdTimer.stop();
removeLockFile();
writeJSON("error");
writeJSONMode("error");
break;
default:
@@ -2477,7 +2502,7 @@ void CMMDVMHost::setMode(unsigned char mode)
m_mode = MODE_IDLE;
m_modeTimer.stop();
removeLockFile();
writeJSON("idle");
writeJSONMode("idle");
break;
}
}
@@ -2768,7 +2793,7 @@ void CMMDVMHost::buildNetworkHostsString(std::string &str)
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;
@@ -2778,3 +2803,13 @@ void CMMDVMHost::writeJSON(const std::string& mode)
WriteJSON("MMDVM", json);
}
void CMMDVMHost::writeJSONMessage(const std::string& message)
{
nlohmann::json json;
json["timestamp"] = CUtils::createTimestamp();
json["message"] = message;
WriteJSON("MMDVM", json);
}