From 8ca1bb8d728dd737e3bb787fdeb4beac77783c06 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Sun, 23 Jul 2023 14:30:49 +0100 Subject: [PATCH] Add DMR Master logging-in to the JSON status messages. --- DMRGateway.cpp | 14 ++------------ DMRGateway.h | 2 -- DMRNetwork.cpp | 9 ++++++++- Log.cpp | 11 +++++++++++ Log.h | 1 + Version.h | 2 +- 6 files changed, 23 insertions(+), 16 deletions(-) diff --git a/DMRGateway.cpp b/DMRGateway.cpp index 16f3682..8f7c759 100644 --- a/DMRGateway.cpp +++ b/DMRGateway.cpp @@ -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); diff --git a/DMRGateway.h b/DMRGateway.h index 9b669bb..0f97728 100644 --- a/DMRGateway.h +++ b/DMRGateway.h @@ -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); }; diff --git a/DMRNetwork.cpp b/DMRNetwork.cpp index c9f8ca5..48ac551 100644 --- a/DMRNetwork.cpp +++ b/DMRNetwork.cpp @@ -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(); } diff --git a/Log.cpp b/Log.cpp index 4537544..0680352 100644 --- a/Log.cpp +++ b/Log.cpp @@ -18,6 +18,7 @@ #include "Log.h" #include "MQTTConnection.h" +#include "Utils.h" #if defined(_WIN32) || defined(_WIN64) #include @@ -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) { diff --git a/Log.h b/Log.h index 7392164..736dfdb 100644 --- a/Log.h +++ b/Log.h @@ -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 diff --git a/Version.h b/Version.h index 05ca373..7b0d708 100644 --- a/Version.h +++ b/Version.h @@ -19,6 +19,6 @@ #if !defined(VERSION_H) #define VERSION_H -const char* VERSION = "20230711"; +const char* VERSION = "20230723"; #endif