diff --git a/Log.cpp b/Log.cpp index 516c3d5b..c0ce9177 100644 --- a/Log.cpp +++ b/Log.cpp @@ -79,6 +79,7 @@ static char LEVELS[] = " DMIWEF"; // --------------------------------------------------------------------------- // Global Functions // --------------------------------------------------------------------------- + /// /// Helper to open the detailed log file, file handle. /// @@ -146,6 +147,17 @@ static bool ActivityLogOpen() return m_actFpLog != NULL; } +/// +/// Sets the instance of the Network class to transfer the activity log with. +/// +/// Instance of the Network class. +void LogSetNetwork(void* network) +{ + // note: The Network class is passed here as a void so we can avoid including the Network.h + // header in Log.h. This is dirty and probably terrible... + m_network = (network::Network*)network; +} + /// /// Initializes the activity log. /// @@ -229,18 +241,7 @@ void ActivityLog(const char *mode, const bool sourceRf, const char* msg, ...) } /// -/// Sets the instance of the Network class to transfer the activity log with. -/// -/// Instance of the Network class. -void ActivityLogSetNetwork(void* network) -{ - // Note: The Network class is passed here as a void so we can avoid including the Network.h - // header in Log.h. This is dirty and probably terrible... - m_network = (network::Network*)network; -} - -/// -/// Initializes the detailed log. +/// Initializes the diagnostics log. /// /// Full-path to the detailed log file. /// Prefix of the detailed log file name. @@ -256,7 +257,7 @@ bool LogInitialise(const std::string& filePath, const std::string& fileRoot, uin } /// -/// Finalizes the detailed log. +/// Finalizes the diagnostics log. /// void LogFinalise() { @@ -265,7 +266,7 @@ void LogFinalise() } /// -/// Writes a new entry to the detailed log. +/// Writes a new entry to the diagnostics log. /// /// Log level. /// Module name the log entry was genearted from. @@ -306,6 +307,13 @@ void Log(uint32_t level, const char *module, const char* fmt, ...) va_end(vl); + if (m_network != NULL) { + // don't transfer debug data... + if (level > 1U) { + m_network->writeDiagLog(buffer); + } + } + if (level >= m_fileLevel && m_fileLevel != 0U) { bool ret = ::LogOpen(); if (!ret) diff --git a/Log.h b/Log.h index d6396ec2..aece653e 100644 --- a/Log.h +++ b/Log.h @@ -62,6 +62,8 @@ // --------------------------------------------------------------------------- // Global Functions // --------------------------------------------------------------------------- +/// Sets the instance of the Network class to transfer the activity log with. +extern HOST_SW_API void LogSetNetwork(void* network); /// Initializes the activity log. extern HOST_SW_API bool ActivityLogInitialise(const std::string& filePath, const std::string& fileRoot); @@ -69,14 +71,12 @@ extern HOST_SW_API bool ActivityLogInitialise(const std::string& filePath, const extern HOST_SW_API void ActivityLogFinalise(); /// Writes a new entry to the activity log. extern HOST_SW_API void ActivityLog(const char* mode, const bool sourceRf, const char* msg, ...); -/// Sets the instance of the Network class to transfer the activity log with. -extern HOST_SW_API void ActivityLogSetNetwork(void* network); -/// Initializes the detailed log. +/// Initializes the diagnostics log. extern HOST_SW_API bool LogInitialise(const std::string& filePath, const std::string& fileRoot, uint32_t fileLevel, uint32_t displayLevel); -/// Finalizes the detailed log. +/// Finalizes the diagnostics log. extern HOST_SW_API void LogFinalise(); -/// Writes a new entry to the detailed log. +/// Writes a new entry to the diagnostics log. extern HOST_SW_API void Log(uint32_t level, const char* module, const char* fmt, ...); #endif // __LOG_H__ diff --git a/config.yml b/config.yml index a773a86f..e88a081a 100644 --- a/config.yml +++ b/config.yml @@ -16,8 +16,9 @@ network: password: "PASSWORD" slot1: true slot2: true - transferActivityLog: false updateLookups: false + allowActivityTransfer: false + allowDiagnosticTransfer: false debug: false protocols: dmr: diff --git a/host/Host.cpp b/host/Host.cpp index 888f585f..4d0d6989 100644 --- a/host/Host.cpp +++ b/host/Host.cpp @@ -1284,7 +1284,8 @@ bool Host::createNetwork() std::string password = networkConf["password"].as(); bool slot1 = networkConf["slot1"].as(true); bool slot2 = networkConf["slot2"].as(true); - bool transferActivityLog = networkConf["transferActivityLog"].as(false); + bool allowActivityTransfer = networkConf["allowActivityTransfer"].as(false); + bool allowDiagnosticTransfer = networkConf["allowDiagnosticTransfer"].as(false); bool updateLookup = networkConf["updateLookups"].as(false); bool debug = networkConf["debug"].as(false); @@ -1303,14 +1304,15 @@ bool Host::createNetwork() LogInfo(" DMR Jitter: %ums", jitter); LogInfo(" Slot 1: %s", slot1 ? "enabled" : "disabled"); LogInfo(" Slot 2: %s", slot2 ? "enabled" : "disabled"); - LogInfo(" Transfer Activity Log: %s", transferActivityLog ? "enabled" : "disabled"); + LogInfo(" Allow Activity Log Transfer: %s", allowActivityTransfer ? "enabled" : "disabled"); + LogInfo(" Allow Diagnostic Log Transfer: %s", allowDiagnosticTransfer ? "enabled" : "disabled"); LogInfo(" Update Lookups: %s", updateLookup ? "enabled" : "disabled"); if (debug) { LogInfo(" Debug: yes"); } - m_network = new Network(address, port, local, id, password, m_duplex, debug, slot1, slot2, transferActivityLog, updateLookup); + m_network = new Network(address, port, local, id, password, m_duplex, debug, slot1, slot2, allowActivityTransfer, allowDiagnosticTransfer, updateLookup); m_network->setLookups(m_ridLookup, m_tidLookup); m_network->setConfig(m_identity, m_rxFrequency, m_txFrequency, entry.txOffsetMhz(), entry.chBandwidthKhz(), m_power, @@ -1325,7 +1327,7 @@ bool Host::createNetwork() } m_network->enable(true); - ::ActivityLogSetNetwork(m_network); + ::LogSetNetwork(m_network); // initialize network remote command m_remoteControl = new RemoteControl(rconAddress, rconPort); diff --git a/network/BaseNetwork.cpp b/network/BaseNetwork.cpp index 55a56eb0..bded6ac8 100644 --- a/network/BaseNetwork.cpp +++ b/network/BaseNetwork.cpp @@ -52,12 +52,14 @@ using namespace network; /// /// Flag indicating whether DMR slot 1 is enabled for network traffic. /// Flag indicating whether DMR slot 2 is enabled for network traffic. -/// Flag indicating that the system activity log will be sent to the network. -BaseNetwork::BaseNetwork(uint32_t localPort, uint32_t id, bool duplex, bool debug, bool slot1, bool slot2, bool transferActivityLog) : +/// Flag indicating that the system activity logs will be sent to the network. +/// Flag indicating that the system diagnostic logs will be sent to the network. +BaseNetwork::BaseNetwork(uint32_t localPort, uint32_t id, bool duplex, bool debug, bool slot1, bool slot2, bool allowActivityTransfer, bool allowDiagnosticTransfer) : m_id(id), m_slot1(slot1), m_slot2(slot2), - m_transferActivityLog(transferActivityLog), + m_allowActivityTransfer(allowActivityTransfer), + m_allowDiagnosticTransfer(allowDiagnosticTransfer), m_duplex(duplex), m_debug(debug), m_socket(localPort), @@ -381,7 +383,7 @@ bool BaseNetwork::writeP25PDU(const uint32_t llId, const uint8_t dataType, const /// bool BaseNetwork::writeActLog(const char* message) { - if (!m_transferActivityLog) + if (!m_allowActivityTransfer) return false; if (m_status != NET_STAT_RUNNING) return false; @@ -391,13 +393,37 @@ bool BaseNetwork::writeActLog(const char* message) char buffer[DATA_PACKET_LENGTH]; uint32_t len = ::strlen(message); - ::memcpy(buffer + 0U, TAG_REPEATER_LOG, 7U); + ::memcpy(buffer + 0U, TAG_TRANSFER_ACT_LOG, 7U); __SET_UINT32(m_id, buffer, 7U); ::strcpy(buffer + 11U, message); return write((uint8_t*)buffer, (uint32_t)len + 12U); } +/// +/// Writes the local diagnostics log to the network. +/// +/// +/// +bool BaseNetwork::writeDiagLog(const char* message) +{ + if (!m_allowDiagnosticTransfer) + return false; + if (m_status != NET_STAT_RUNNING) + return false; + + assert(message != NULL); + + char buffer[DATA_PACKET_LENGTH]; + uint32_t len = ::strlen(message); + + ::memcpy(buffer + 0U, TAG_TRANSFER_DIAG_LOG, 8U); + __SET_UINT32(m_id, buffer, 8U); + ::strcpy(buffer + 12U, message); + + return write((uint8_t*)buffer, (uint32_t)len + 13U); +} + /// /// Resets the DMR ring buffer for the given slot. /// diff --git a/network/BaseNetwork.h b/network/BaseNetwork.h index c59dd425..598bb52e 100644 --- a/network/BaseNetwork.h +++ b/network/BaseNetwork.h @@ -74,7 +74,8 @@ #define TAG_REPEATER_CLOSING "RPTCL" #define TAG_REPEATER_PING "RPTPING" -#define TAG_REPEATER_LOG "TRNSLOG"//"RPTALOG" +#define TAG_TRANSFER_ACT_LOG "TRNSLOG" +#define TAG_TRANSFER_DIAG_LOG "TRNSDIAG" namespace network { @@ -173,7 +174,7 @@ namespace network class HOST_SW_API BaseNetwork { public: /// Initializes a new instance of the BaseNetwork class. - BaseNetwork(uint32_t localPort, uint32_t id, bool duplex, bool debug, bool slot1, bool slot2, bool transferActivityLog); + BaseNetwork(uint32_t localPort, uint32_t id, bool duplex, bool debug, bool slot1, bool slot2, bool transferActivityLog, bool transferDiagnosticLog); /// Finalizes a instance of the BaseNetwork class. virtual ~BaseNetwork(); @@ -201,6 +202,9 @@ namespace network /// Writes the local activity log to the network. virtual bool writeActLog(const char* message); + /// Writes the local activity log to the network. + virtual bool writeDiagLog(const char* message); + /// Updates the timer by the passed number of milliseconds. virtual void clock(uint32_t ms) = 0; @@ -221,7 +225,8 @@ namespace network bool m_slot1; bool m_slot2; - bool m_transferActivityLog; + bool m_allowActivityTransfer; + bool m_allowDiagnosticTransfer; bool m_duplex; bool m_debug; diff --git a/network/Network.cpp b/network/Network.cpp index 1316af1c..9bf916b6 100644 --- a/network/Network.cpp +++ b/network/Network.cpp @@ -55,11 +55,12 @@ using namespace network; /// Flag indicating full-duplex operation. /// Flag indicating whether DMR slot 1 is enabled for network traffic. /// Flag indicating whether DMR slot 2 is enabled for network traffic. -/// Flag indicating that the system activity log will be sent to the network. +/// Flag indicating that the system activity logs will be sent to the network. +/// Flag indicating that the system diagnostic logs will be sent to the network. /// Flag indicating that the system will accept radio ID and talkgroup ID lookups from the network. Network::Network(const std::string& address, uint32_t port, uint32_t local, uint32_t id, const std::string& password, - bool duplex, bool debug, bool slot1, bool slot2, bool transferActivityLog, bool updateLookup) : - BaseNetwork(local, id, duplex, debug, slot1, slot2, transferActivityLog), + bool duplex, bool debug, bool slot1, bool slot2, bool allowActivityTransfer, bool allowDiagnosticTransfer, bool updateLookup) : + BaseNetwork(local, id, duplex, debug, slot1, slot2, allowActivityTransfer, allowDiagnosticTransfer), m_addressStr(address), m_address(), m_port(port), @@ -275,16 +276,13 @@ void Network::clock(uint32_t ms) } else if (::memcmp(m_buffer, TAG_MASTER_NAK, 6U) == 0) { if (m_status == NET_STAT_RUNNING) { - LogWarning(LOG_NET, "Login to the master has failed, retrying login ..."); + LogWarning(LOG_NET, "Master returned a NAK; attemping to relogin ..."); m_status = NET_STAT_WAITING_LOGIN; m_timeoutTimer.start(); m_retryTimer.start(); } else { - // Once the modem death spiral has been prevented in Modem.cpp - // the Network sometimes times out and reaches here. - // We want it to reconnect so... - LogError(LOG_NET, "Login to the master has failed, retrying network ..."); + LogError(LOG_NET, "Master returned a NAK; network reconnect ..."); close(); open(); return; diff --git a/network/Network.h b/network/Network.h index 1f69e49e..33bcdf9e 100644 --- a/network/Network.h +++ b/network/Network.h @@ -50,7 +50,7 @@ namespace network public: /// Initializes a new instance of the Network class. Network(const std::string& address, uint32_t port, uint32_t local, uint32_t id, const std::string& password, - bool duplex, bool debug, bool slot1, bool slot2, bool transferActivityLog, bool updateLookup); + bool duplex, bool debug, bool slot1, bool slot2, bool transferActivityLog, bool transferDiagnosticLog, bool updateLookup); /// Finalizes a instance of the Network class. ~Network();