Merge branch 'master' into mqtt

This commit is contained in:
Jonathan Naylor
2025-03-15 17:23:14 +00:00
63 changed files with 792 additions and 791 deletions

18
Log.cpp
View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015,2016,2020,2022,2023 by Jonathan Naylor G4KLX
* Copyright (C) 2015,2016,2020,2022,2023,2025 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
@@ -34,7 +34,7 @@
#include <cassert>
#include <cstring>
CMQTTConnection* m_mqtt = NULL;
CMQTTConnection* m_mqtt = nullptr;
static unsigned int m_mqttLevel = 2U;
@@ -50,16 +50,16 @@ void LogInitialise(unsigned int displayLevel, unsigned int mqttLevel)
void LogFinalise()
{
if (m_mqtt != NULL) {
if (m_mqtt != nullptr) {
m_mqtt->close();
delete m_mqtt;
m_mqtt = NULL;
m_mqtt = nullptr;
}
}
void Log(unsigned int level, const char* fmt, ...)
{
assert(fmt != NULL);
assert(fmt != nullptr);
char buffer[501U];
#if defined(_WIN32) || defined(_WIN64)
@@ -69,7 +69,7 @@ void Log(unsigned int level, const char* fmt, ...)
::sprintf(buffer, "%c: %04u-%02u-%02u %02u:%02u:%02u.%03u ", LEVELS[level], st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
#else
struct timeval now;
::gettimeofday(&now, NULL);
::gettimeofday(&now, nullptr);
struct tm* tm = ::gmtime(&now.tv_sec);
@@ -79,11 +79,11 @@ void Log(unsigned int level, const char* fmt, ...)
va_list vl;
va_start(vl, fmt);
::vsnprintf(buffer + ::strlen(buffer), 500, fmt, vl);
::vsnprintf(buffer + ::strlen(buffer), 500 - ::strlen(buffer), fmt, vl);
va_end(vl);
if (m_mqtt != NULL && level >= m_mqttLevel && m_mqttLevel != 0U)
if (m_mqtt != nullptr && level >= m_mqttLevel && m_mqttLevel != 0U)
m_mqtt->publish("log", buffer);
if (level >= m_displayLevel && m_displayLevel != 0U) {
@@ -107,7 +107,7 @@ void WriteJSONStatus(const std::string& status)
void WriteJSON(const std::string& topLevel, nlohmann::json& json)
{
if (m_mqtt != NULL) {
if (m_mqtt != nullptr) {
nlohmann::json top;
top[topLevel] = json;