Fix the top level JSON category.

This commit is contained in:
Jonathan Naylor
2023-01-01 18:54:21 +00:00
parent 38a6dbbdeb
commit 2090432a6a
4 changed files with 53 additions and 43 deletions

11
Log.cpp
View File

@@ -200,9 +200,14 @@ void Log(unsigned int level, const char* fmt, ...)
} }
} }
void WriteJSON(const std::string& json) void WriteJSON(const std::string& topLevel, nlohmann::json& json)
{ {
if (m_mqtt != NULL) if (m_mqtt != NULL) {
m_mqtt->publish("json", json.c_str()); nlohmann::json top;
top[topLevel] = json;
m_mqtt->publish("json", top.dump().c_str());
}
} }

4
Log.h
View File

@@ -21,6 +21,8 @@
#include <string> #include <string>
#include <nlohmann/json.hpp>
#define LogDebug(fmt, ...) Log(1U, fmt, ##__VA_ARGS__) #define LogDebug(fmt, ...) Log(1U, fmt, ##__VA_ARGS__)
#define LogMessage(fmt, ...) Log(2U, fmt, ##__VA_ARGS__) #define LogMessage(fmt, ...) Log(2U, fmt, ##__VA_ARGS__)
#define LogInfo(fmt, ...) Log(3U, fmt, ##__VA_ARGS__) #define LogInfo(fmt, ...) Log(3U, fmt, ##__VA_ARGS__)
@@ -33,6 +35,6 @@ extern void Log(unsigned int level, const char* fmt, ...);
extern bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel, unsigned int mqttLevel, bool rotate); extern bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel, unsigned int mqttLevel, bool rotate);
extern void LogFinalise(); extern void LogFinalise();
extern void WriteJSON(const std::string& json); extern void WriteJSON(const std::string& topLevel, nlohmann::json& json);
#endif #endif

View File

@@ -932,7 +932,7 @@ void CM17Control::writeJSON(const char* action, RPT_RF_STATE state, const std::s
writeJSON(json, action, state, source, dest); writeJSON(json, action, state, source, dest);
WriteJSON(json.dump()); WriteJSON("M17", json);
} }
void CM17Control::writeJSON(const char* action, RPT_RF_STATE state, const std::string& source, const std::string& dest, float duration, float ber) void CM17Control::writeJSON(const char* action, RPT_RF_STATE state, const std::string& source, const std::string& dest, float duration, float ber)
@@ -943,7 +943,7 @@ void CM17Control::writeJSON(const char* action, RPT_RF_STATE state, const std::s
writeJSON(json, action, state, source, dest, duration, ber); writeJSON(json, action, state, source, dest, duration, ber);
WriteJSON(json.dump()); WriteJSON("M17", json);
} }
void CM17Control::writeJSON(const char* action, RPT_RF_STATE state, const std::string& source, const std::string& dest, float duration, float ber, float minRSSI, float maxRSSI, float aveRSSI) void CM17Control::writeJSON(const char* action, RPT_RF_STATE state, const std::string& source, const std::string& dest, float duration, float ber, float minRSSI, float maxRSSI, float aveRSSI)
@@ -955,13 +955,13 @@ void CM17Control::writeJSON(const char* action, RPT_RF_STATE state, const std::s
writeJSON(json, action, state, source, dest, duration, ber); writeJSON(json, action, state, source, dest, duration, ber);
nlohmann::json rssi; nlohmann::json rssi;
rssi["minimumm"] = minRSSI; rssi["min"] = minRSSI;
rssi["maximumm"] = maxRSSI; rssi["max"] = maxRSSI;
rssi["average"] = aveRSSI; rssi["ave"] = aveRSSI;
json["rssi"] = rssi; json["rssi"] = rssi;
WriteJSON(json.dump()); WriteJSON("M17", json);
} }
void CM17Control::writeJSON(const char* action, RPT_NET_STATE state, const std::string& source, const std::string& dest) void CM17Control::writeJSON(const char* action, RPT_NET_STATE state, const std::string& source, const std::string& dest)
@@ -972,7 +972,7 @@ void CM17Control::writeJSON(const char* action, RPT_NET_STATE state, const std::
writeJSON(action, state, source, dest); writeJSON(action, state, source, dest);
WriteJSON(json.dump()); WriteJSON("M17", json);
} }
void CM17Control::writeJSON(const char* action, RPT_NET_STATE state, const std::string& source, const std::string& dest, float duration) void CM17Control::writeJSON(const char* action, RPT_NET_STATE state, const std::string& source, const std::string& dest, float duration)
@@ -985,7 +985,7 @@ void CM17Control::writeJSON(const char* action, RPT_NET_STATE state, const std::
json["duration"] = duration; json["duration"] = duration;
WriteJSON(json.dump()); WriteJSON("M17", json);
} }
void CM17Control::writeJSON(nlohmann::json& json, const char* action, RPT_RF_STATE state, const std::string& source, const std::string& dest) void CM17Control::writeJSON(nlohmann::json& json, const char* action, RPT_RF_STATE state, const std::string& source, const std::string& dest)
@@ -994,8 +994,8 @@ void CM17Control::writeJSON(nlohmann::json& json, const char* action, RPT_RF_STA
json["timestamp"] = CUtils::createTimestamp(); json["timestamp"] = CUtils::createTimestamp();
json["source_callsign"] = source; json["source_cs"] = source;
json["destination_callsign"] = dest; json["destination_cs"] = dest;
json["source"] = "rf"; json["source"] = "rf";
json["action"] = action; json["action"] = action;
@@ -1032,8 +1032,8 @@ void CM17Control::writeJSON(nlohmann::json& json, const char* action, RPT_NET_ST
json["timestamp"] = CUtils::createTimestamp(); json["timestamp"] = CUtils::createTimestamp();
json["source_callsign"] = source; json["source_cs"] = source;
json["destination_callsign"] = dest; json["destination_cs"] = dest;
json["source"] = "network"; json["source"] = "network";
json["action"] = action; json["action"] = action;

View File

@@ -38,26 +38,27 @@
"D-Star": { "D-Star": {
"type": "object", "type": "object",
"timestamp": {"$ref": "#/$defs/timestamp"}, "timestamp": {"$ref": "#/$defs/timestamp"},
"source_callsign": {"$ref": "#/$defs/dstar_callsign"}, "source_cs": {"$ref": "#/$defs/dstar_callsign"},
"source_ext": {"$ref": "#/$defs/dstar_extension"}, "source_ext": {"$ref": "#/$defs/dstar_extension"},
"destination_callsign": {"$ref": "#/$defs/dstar_callsign"}, "destination_cs": {"$ref": "#/$defs/dstar_callsign"},
"source": {"$ref": "#/$defs/source"}, "source": {"$ref": "#/$defs/source"},
"action": {"$ref": "#/$defs/action"}, "action": {"$ref": "#/$defs/action"},
"duration": {"$ref": "#/$defs/duration"}, "duration": {"$ref": "#/$defs/duration"},
"loss": {"$ref": "#/$defs/loss"}, "loss": {"$ref": "#/$defs/loss"},
"ber": {"$ref": "#/$defs/ber"}, "ber": {"$ref": "#/$defs/ber"},
"rssi": { "rssi": {
"minimum": {"$ref": "#/$defs/rssi"}, "min": {"$ref": "#/$defs/rssi"},
"maximum": {"$ref": "#/$defs/rssi"}, "max": {"$ref": "#/$defs/rssi"},
"average": {"$ref": "#/$defs/rssi"} "ave": {"$ref": "#/$defs/rssi"}
}, },
"required": ["timestamp", "source_callsign", "source_ext", "destination_callsign", "source", "action"] "required": ["timestamp", "source_cs", "source_ext", "destination_cs", "source", "action"]
}, },
"DMR": { "DMR": {
"type": "object", "type": "object",
"timestamp": {"$ref": "#/$defs/timestamp"}, "timestamp": {"$ref": "#/$defs/timestamp"},
"source_id": {"$ref": "#/$defs/dmr_id"}, "source_id": {"$ref": "#/$defs/dmr_id"},
"source_info": {"type": "string"},
"destination_id": {"$ref": "#/$defs/dmr_id"}, "destination_id": {"$ref": "#/$defs/dmr_id"},
"destination_type": {"$ref": "#/$defs/id_type"}, "destination_type": {"$ref": "#/$defs/id_type"},
"slot": {"$ref": "#/$defs/dmr_slot"}, "slot": {"$ref": "#/$defs/dmr_slot"},
@@ -67,9 +68,9 @@
"loss": {"$ref": "#/$defs/loss"}, "loss": {"$ref": "#/$defs/loss"},
"ber": {"$ref": "#/$defs/ber"}, "ber": {"$ref": "#/$defs/ber"},
"rssi": { "rssi": {
"minimum": {"$ref": "#/$defs/rssi"}, "min": {"$ref": "#/$defs/rssi"},
"maximum": {"$ref": "#/$defs/rssi"}, "max": {"$ref": "#/$defs/rssi"},
"average": {"$ref": "#/$defs/rssi"} "ave": {"$ref": "#/$defs/rssi"}
}, },
"required": ["timestamp", "source_id", "destination_id", "destination_type", "slot", "source", "action"] "required": ["timestamp", "source_id", "destination_id", "destination_type", "slot", "source", "action"]
}, },
@@ -77,8 +78,8 @@
"YSF": { "YSF": {
"type": "object", "type": "object",
"timestamp": {"$ref": "#/$defs/timestamp"}, "timestamp": {"$ref": "#/$defs/timestamp"},
"source_callsign": {"$ref": "#/$defs/ysf_callsign"}, "source_cs": {"$ref": "#/$defs/ysf_callsign"},
"destination_callsign": {"$ref": "#/$defs/ysf_callsign"}, "destination_cs": {"$ref": "#/$defs/ysf_callsign"},
"source": {"$ref": "#/$defs/source"}, "source": {"$ref": "#/$defs/source"},
"action": {"$ref": "#/$defs/action"}, "action": {"$ref": "#/$defs/action"},
"mode": {"$ref": "#/$defs/ysf_mode"}, "mode": {"$ref": "#/$defs/ysf_mode"},
@@ -86,17 +87,18 @@
"loss": {"$ref": "#/$defs/loss"}, "loss": {"$ref": "#/$defs/loss"},
"ber": {"$ref": "#/$defs/ber"}, "ber": {"$ref": "#/$defs/ber"},
"rssi": { "rssi": {
"minimum": {"$ref": "#/$defs/rssi"}, "min": {"$ref": "#/$defs/rssi"},
"maximum": {"$ref": "#/$defs/rssi"}, "max": {"$ref": "#/$defs/rssi"},
"average": {"$ref": "#/$defs/rssi"} "ave": {"$ref": "#/$defs/rssi"}
}, },
"required": ["timestamp", "source_callsign", "destination_callsign", "source", "action", "mode"] "required": ["timestamp", "source_cs", "destination_cs", "source", "action", "mode"]
}, },
"P25": { "P25": {
"type": "object", "type": "object",
"timestamp": {"$ref": "#/$defs/timestamp"}, "timestamp": {"$ref": "#/$defs/timestamp"},
"source_id": {"$ref": "#/$defs/dmr_id"}, "source_id": {"$ref": "#/$defs/dmr_id"},
"source_info": {"type": "string"},
"destination_id": {"$ref": "#/$defs/p25_id"}, "destination_id": {"$ref": "#/$defs/p25_id"},
"destination_type": {"$ref": "#/$defs/id_type"}, "destination_type": {"$ref": "#/$defs/id_type"},
"source": {"$ref": "#/$defs/source"}, "source": {"$ref": "#/$defs/source"},
@@ -105,9 +107,9 @@
"loss": {"$ref": "#/$defs/loss"}, "loss": {"$ref": "#/$defs/loss"},
"ber": {"$ref": "#/$defs/ber"}, "ber": {"$ref": "#/$defs/ber"},
"rssi": { "rssi": {
"minimum": {"$ref": "#/$defs/rssi"}, "min": {"$ref": "#/$defs/rssi"},
"maximum": {"$ref": "#/$defs/rssi"}, "max": {"$ref": "#/$defs/rssi"},
"average": {"$ref": "#/$defs/rssi"} "ave": {"$ref": "#/$defs/rssi"}
}, },
"required": ["timestamp", "source_id", "destination_id", "destination_type", "source", "action"] "required": ["timestamp", "source_id", "destination_id", "destination_type", "source", "action"]
}, },
@@ -116,6 +118,7 @@
"type": "object", "type": "object",
"timestamp": {"$ref": "#/$defs/timestamp"}, "timestamp": {"$ref": "#/$defs/timestamp"},
"source_id": {"$ref": "#/$defs/nxdn_id"}, "source_id": {"$ref": "#/$defs/nxdn_id"},
"source_info": {"type": "string"},
"destination_id": {"$ref": "#/$defs/nxdn_id"}, "destination_id": {"$ref": "#/$defs/nxdn_id"},
"destination_type": {"$ref": "#/$defs/id_type"}, "destination_type": {"$ref": "#/$defs/id_type"},
"source": {"$ref": "#/$defs/source"}, "source": {"$ref": "#/$defs/source"},
@@ -124,9 +127,9 @@
"loss": {"$ref": "#/$defs/loss"}, "loss": {"$ref": "#/$defs/loss"},
"ber": {"$ref": "#/$defs/ber"}, "ber": {"$ref": "#/$defs/ber"},
"rssi": { "rssi": {
"minimum": {"$ref": "#/$defs/rssi"}, "min": {"$ref": "#/$defs/rssi"},
"maximum": {"$ref": "#/$defs/rssi"}, "max": {"$ref": "#/$defs/rssi"},
"average": {"$ref": "#/$defs/rssi"} "ave": {"$ref": "#/$defs/rssi"}
}, },
"required": ["timestamp", "source_id", "destination_id", "destination_type", "source", "action"] "required": ["timestamp", "source_id", "destination_id", "destination_type", "source", "action"]
}, },
@@ -167,18 +170,18 @@
"M17": { "M17": {
"type": "object", "type": "object",
"timestamp": {"$ref": "#/$defs/timestamp"}, "timestamp": {"$ref": "#/$defs/timestamp"},
"source_callsign": {"$ref": "#/$defs/m17_callsign"}, "source_cs": {"$ref": "#/$defs/m17_callsign"},
"destination_callsign": {"$ref": "#/$defs/m17_callsign"}, "destination_cs": {"$ref": "#/$defs/m17_callsign"},
"source": {"$ref": "#/$defs/source"}, "source": {"$ref": "#/$defs/source"},
"action": {"$ref": "#/$defs/action"}, "action": {"$ref": "#/$defs/action"},
"traffic_type": {"$ref": "#/$defs/m17_traffic_type"}, "traffic_type": {"$ref": "#/$defs/m17_traffic_type"},
"duration": {"$ref": "#/$defs/duration"}, "duration": {"$ref": "#/$defs/duration"},
"ber": {"$ref": "#/$defs/ber"}, "ber": {"$ref": "#/$defs/ber"},
"rssi": { "rssi": {
"minimum": {"$ref": "#/$defs/rssi"}, "min": {"$ref": "#/$defs/rssi"},
"maximum": {"$ref": "#/$defs/rssi"}, "max": {"$ref": "#/$defs/rssi"},
"average": {"$ref": "#/$defs/rssi"} "ave": {"$ref": "#/$defs/rssi"}
}, },
"required": ["timestamp", "source_callsign", "destination_callsign", "source", "action", "traffic_type"] "required": ["timestamp", "source_cs", "destination_cs", "source", "action", "traffic_type"]
} }
} }