diff --git a/Log.cpp b/Log.cpp index 6a3655c..8d093de 100644 --- a/Log.cpp +++ b/Log.cpp @@ -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) - m_mqtt->publish("json", json.c_str()); + if (m_mqtt != NULL) { + nlohmann::json top; + + top[topLevel] = json; + + m_mqtt->publish("json", top.dump().c_str()); + } } diff --git a/Log.h b/Log.h index 71a51a2..a3fb7f6 100644 --- a/Log.h +++ b/Log.h @@ -21,6 +21,8 @@ #include +#include + #define LogDebug(fmt, ...) Log(1U, fmt, ##__VA_ARGS__) #define LogMessage(fmt, ...) Log(2U, 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 void LogFinalise(); -extern void WriteJSON(const std::string& json); +extern void WriteJSON(const std::string& topLevel, nlohmann::json& json); #endif diff --git a/M17Control.cpp b/M17Control.cpp index 1f75da1..eee7c83 100644 --- a/M17Control.cpp +++ b/M17Control.cpp @@ -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.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) @@ -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.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) @@ -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); nlohmann::json rssi; - rssi["minimumm"] = minRSSI; - rssi["maximumm"] = maxRSSI; - rssi["average"] = aveRSSI; + rssi["min"] = minRSSI; + rssi["max"] = maxRSSI; + rssi["ave"] = aveRSSI; 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) @@ -972,7 +972,7 @@ void CM17Control::writeJSON(const char* action, RPT_NET_STATE state, const std:: 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) @@ -985,7 +985,7 @@ void CM17Control::writeJSON(const char* action, RPT_NET_STATE state, const std:: 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) @@ -994,8 +994,8 @@ void CM17Control::writeJSON(nlohmann::json& json, const char* action, RPT_RF_STA json["timestamp"] = CUtils::createTimestamp(); - json["source_callsign"] = source; - json["destination_callsign"] = dest; + json["source_cs"] = source; + json["destination_cs"] = dest; json["source"] = "rf"; json["action"] = action; @@ -1032,8 +1032,8 @@ void CM17Control::writeJSON(nlohmann::json& json, const char* action, RPT_NET_ST json["timestamp"] = CUtils::createTimestamp(); - json["source_callsign"] = source; - json["destination_callsign"] = dest; + json["source_cs"] = source; + json["destination_cs"] = dest; json["source"] = "network"; json["action"] = action; diff --git a/schema.json b/schema.json index 09fc5a0..0db9afd 100644 --- a/schema.json +++ b/schema.json @@ -38,26 +38,27 @@ "D-Star": { "type": "object", "timestamp": {"$ref": "#/$defs/timestamp"}, - "source_callsign": {"$ref": "#/$defs/dstar_callsign"}, + "source_cs": {"$ref": "#/$defs/dstar_callsign"}, "source_ext": {"$ref": "#/$defs/dstar_extension"}, - "destination_callsign": {"$ref": "#/$defs/dstar_callsign"}, + "destination_cs": {"$ref": "#/$defs/dstar_callsign"}, "source": {"$ref": "#/$defs/source"}, "action": {"$ref": "#/$defs/action"}, "duration": {"$ref": "#/$defs/duration"}, "loss": {"$ref": "#/$defs/loss"}, "ber": {"$ref": "#/$defs/ber"}, "rssi": { - "minimum": {"$ref": "#/$defs/rssi"}, - "maximum": {"$ref": "#/$defs/rssi"}, - "average": {"$ref": "#/$defs/rssi"} + "min": {"$ref": "#/$defs/rssi"}, + "max": {"$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": { "type": "object", "timestamp": {"$ref": "#/$defs/timestamp"}, "source_id": {"$ref": "#/$defs/dmr_id"}, + "source_info": {"type": "string"}, "destination_id": {"$ref": "#/$defs/dmr_id"}, "destination_type": {"$ref": "#/$defs/id_type"}, "slot": {"$ref": "#/$defs/dmr_slot"}, @@ -67,9 +68,9 @@ "loss": {"$ref": "#/$defs/loss"}, "ber": {"$ref": "#/$defs/ber"}, "rssi": { - "minimum": {"$ref": "#/$defs/rssi"}, - "maximum": {"$ref": "#/$defs/rssi"}, - "average": {"$ref": "#/$defs/rssi"} + "min": {"$ref": "#/$defs/rssi"}, + "max": {"$ref": "#/$defs/rssi"}, + "ave": {"$ref": "#/$defs/rssi"} }, "required": ["timestamp", "source_id", "destination_id", "destination_type", "slot", "source", "action"] }, @@ -77,8 +78,8 @@ "YSF": { "type": "object", "timestamp": {"$ref": "#/$defs/timestamp"}, - "source_callsign": {"$ref": "#/$defs/ysf_callsign"}, - "destination_callsign": {"$ref": "#/$defs/ysf_callsign"}, + "source_cs": {"$ref": "#/$defs/ysf_callsign"}, + "destination_cs": {"$ref": "#/$defs/ysf_callsign"}, "source": {"$ref": "#/$defs/source"}, "action": {"$ref": "#/$defs/action"}, "mode": {"$ref": "#/$defs/ysf_mode"}, @@ -86,17 +87,18 @@ "loss": {"$ref": "#/$defs/loss"}, "ber": {"$ref": "#/$defs/ber"}, "rssi": { - "minimum": {"$ref": "#/$defs/rssi"}, - "maximum": {"$ref": "#/$defs/rssi"}, - "average": {"$ref": "#/$defs/rssi"} + "min": {"$ref": "#/$defs/rssi"}, + "max": {"$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": { "type": "object", "timestamp": {"$ref": "#/$defs/timestamp"}, "source_id": {"$ref": "#/$defs/dmr_id"}, + "source_info": {"type": "string"}, "destination_id": {"$ref": "#/$defs/p25_id"}, "destination_type": {"$ref": "#/$defs/id_type"}, "source": {"$ref": "#/$defs/source"}, @@ -105,9 +107,9 @@ "loss": {"$ref": "#/$defs/loss"}, "ber": {"$ref": "#/$defs/ber"}, "rssi": { - "minimum": {"$ref": "#/$defs/rssi"}, - "maximum": {"$ref": "#/$defs/rssi"}, - "average": {"$ref": "#/$defs/rssi"} + "min": {"$ref": "#/$defs/rssi"}, + "max": {"$ref": "#/$defs/rssi"}, + "ave": {"$ref": "#/$defs/rssi"} }, "required": ["timestamp", "source_id", "destination_id", "destination_type", "source", "action"] }, @@ -116,6 +118,7 @@ "type": "object", "timestamp": {"$ref": "#/$defs/timestamp"}, "source_id": {"$ref": "#/$defs/nxdn_id"}, + "source_info": {"type": "string"}, "destination_id": {"$ref": "#/$defs/nxdn_id"}, "destination_type": {"$ref": "#/$defs/id_type"}, "source": {"$ref": "#/$defs/source"}, @@ -124,9 +127,9 @@ "loss": {"$ref": "#/$defs/loss"}, "ber": {"$ref": "#/$defs/ber"}, "rssi": { - "minimum": {"$ref": "#/$defs/rssi"}, - "maximum": {"$ref": "#/$defs/rssi"}, - "average": {"$ref": "#/$defs/rssi"} + "min": {"$ref": "#/$defs/rssi"}, + "max": {"$ref": "#/$defs/rssi"}, + "ave": {"$ref": "#/$defs/rssi"} }, "required": ["timestamp", "source_id", "destination_id", "destination_type", "source", "action"] }, @@ -167,18 +170,18 @@ "M17": { "type": "object", "timestamp": {"$ref": "#/$defs/timestamp"}, - "source_callsign": {"$ref": "#/$defs/m17_callsign"}, - "destination_callsign": {"$ref": "#/$defs/m17_callsign"}, + "source_cs": {"$ref": "#/$defs/m17_callsign"}, + "destination_cs": {"$ref": "#/$defs/m17_callsign"}, "source": {"$ref": "#/$defs/source"}, "action": {"$ref": "#/$defs/action"}, "traffic_type": {"$ref": "#/$defs/m17_traffic_type"}, "duration": {"$ref": "#/$defs/duration"}, "ber": {"$ref": "#/$defs/ber"}, "rssi": { - "minimum": {"$ref": "#/$defs/rssi"}, - "maximum": {"$ref": "#/$defs/rssi"}, - "average": {"$ref": "#/$defs/rssi"} + "min": {"$ref": "#/$defs/rssi"}, + "max": {"$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"] } }