Add DMR Master logging-in to the JSON status messages.

This commit is contained in:
Jonathan Naylor
2023-07-23 14:30:49 +01:00
parent 852caca96e
commit 8ca1bb8d72
6 changed files with 23 additions and 16 deletions

View File

@@ -384,7 +384,7 @@ int CDMRGateway::run()
LogInfo("DMRGateway-%s is starting", VERSION);
LogInfo("Built %s %s (GitID #%.7s)", __TIME__, __DATE__, gitversion);
writeJSONStatus("DMRGateway is starting");
WriteJSONStatus("DMRGateway is starting");
ret = createMMDVM();
if (!ret)
@@ -1267,7 +1267,7 @@ int CDMRGateway::run()
}
LogInfo("DMRGateway is stopping");
writeJSONStatus("DMRGateway is stopping");
WriteJSONStatus("DMRGateway is stopping");
delete m_xlxVoice;
@@ -2648,16 +2648,6 @@ void CDMRGateway::buildNetworkHostNetworkString(std::string &str, const std::str
}
}
void CDMRGateway::writeJSONStatus(const std::string& status)
{
nlohmann::json json;
json["timestamp"] = CUtils::createTimestamp();
json["message"] = status;
WriteJSON("status", json);
}
void CDMRGateway::onDynamic(const unsigned char* message, unsigned int length)
{
assert(gateway != NULL);

View File

@@ -157,8 +157,6 @@ private:
void buildNetworkStatusNetworkString(std::string &str, const std::string& name, CDMRNetwork* network, bool enabled);
void buildNetworkHostNetworkString(std::string &str, const std::string& name, CDMRNetwork* network);
void writeJSONStatus(const std::string& status);
static void onCommand(const unsigned char* message, unsigned int length);
static void onDynamic(const unsigned char* message, unsigned int length);
};

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015,2016,2017,2018,2020,2021 by Jonathan Naylor G4KLX
* Copyright (C) 2015,2016,2017,2018,2020,2021,2023 by Jonathan Naylor G4KLX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -101,6 +101,7 @@ bool CDMRNetwork::open()
}
LogMessage("%s, Opening DMR Network", m_name.c_str());
WriteJSONStatus("Opening DMR Network: " + m_name);
m_status = WAITING_CONNECT;
m_timeoutTimer.stop();
@@ -367,6 +368,7 @@ void CDMRNetwork::clock(unsigned int ms)
} else if (::memcmp(m_buffer, "MSTNAK", 6U) == 0) {
if (m_status == RUNNING) {
LogWarning("%s, Login to the master has failed, retrying login ...", m_name.c_str());
WriteJSONStatus("Failed login into DMR Network: " + m_name);
m_status = WAITING_LOGIN;
m_timeoutTimer.start();
m_retryTimer.start();
@@ -375,6 +377,7 @@ void CDMRNetwork::clock(unsigned int ms)
the Network sometimes times out and reaches here.
We want it to reconnect so... */
LogError("%s, Login to the master has failed, retrying network ...", m_name.c_str());
WriteJSONStatus("Failed login into DMR Network: " + m_name);
close(false);
open();
return;
@@ -399,6 +402,7 @@ void CDMRNetwork::clock(unsigned int ms)
case WAITING_CONFIG:
if (m_options.empty()) {
LogMessage("%s, Logged into the master successfully", m_name.c_str());
WriteJSONStatus("Logged into DMR Network: " + m_name);
m_status = RUNNING;
} else {
LogDebug("%s, Sending options", m_name.c_str());
@@ -410,6 +414,7 @@ void CDMRNetwork::clock(unsigned int ms)
break;
case WAITING_OPTIONS:
LogMessage("%s, Logged into the master successfully", m_name.c_str());
WriteJSONStatus("Logged into DMR Network: " + m_name);
m_status = RUNNING;
m_timeoutTimer.start();
m_retryTimer.start();
@@ -419,6 +424,7 @@ void CDMRNetwork::clock(unsigned int ms)
}
} else if (::memcmp(m_buffer, "MSTCL", 5U) == 0) {
LogError("%s, Master is closing down", m_name.c_str());
WriteJSONStatus("Connection closing into DMR Network: " + m_name);
close(false);
open();
} else if (::memcmp(m_buffer, "MSTPONG", 7U) == 0) {
@@ -460,6 +466,7 @@ void CDMRNetwork::clock(unsigned int ms)
m_timeoutTimer.clock(ms);
if (m_timeoutTimer.isRunning() && m_timeoutTimer.hasExpired()) {
LogError("%s, Connection to the master has timed out, retrying connection", m_name.c_str());
WriteJSONStatus("Failed connection into DMR Network: " + m_name);
close(false);
open();
}

11
Log.cpp
View File

@@ -18,6 +18,7 @@
#include "Log.h"
#include "MQTTConnection.h"
#include "Utils.h"
#if defined(_WIN32) || defined(_WIN64)
#include <Windows.h>
@@ -94,6 +95,16 @@ void Log(unsigned int level, const char* fmt, ...)
exit(1);
}
void WriteJSONStatus(const std::string& status)
{
nlohmann::json json;
json["timestamp"] = CUtils::createTimestamp();
json["message"] = status;
WriteJSON("status", json);
}
void WriteJSON(const std::string& topLevel, nlohmann::json& json)
{
if (m_mqtt != NULL) {

1
Log.h
View File

@@ -35,6 +35,7 @@ extern void Log(unsigned int level, const char* fmt, ...);
extern void LogInitialise(unsigned int displayLevel, unsigned int mqttLevel);
extern void LogFinalise();
extern void WriteJSONStatus(const std::string& status);
extern void WriteJSON(const std::string& topLevel, nlohmann::json& json);
#endif

View File

@@ -19,6 +19,6 @@
#if !defined(VERSION_H)
#define VERSION_H
const char* VERSION = "20230711";
const char* VERSION = "20230723";
#endif