diff --git a/POCSAGControl.cpp b/POCSAGControl.cpp index 5695510..2313e55 100644 --- a/POCSAGControl.cpp +++ b/POCSAGControl.cpp @@ -1,5 +1,5 @@ /* -* Copyright (C) 2018,2019,2020 Jonathan Naylor, G4KLX +* Copyright (C) 2018,2019,2020,2023 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 @@ -113,6 +113,7 @@ void CPOCSAGControl::sendPage(unsigned int ric, const std::string& text) addAddress(FUNCTIONAL_ALPHANUMERIC, ric, output->m_buffer); LogDebug("Local message to %07u, func Alphanumeric: \"%s\"", ric, text.c_str()); + writeJSON("local", ric, "alphanumeric", text); packASCII(text, output->m_buffer); @@ -137,6 +138,7 @@ void CPOCSAGControl::sendPageBCD(unsigned int ric, const std::string& text) addAddress(FUNCTIONAL_NUMERIC, ric, output->m_buffer); LogDebug("Local message to %07u, func NUMERIC: \"%s\"", ric, text.c_str()); + writeJSON("local", ric, "numeric", text); packNumeric(text, output->m_buffer); @@ -160,6 +162,7 @@ void CPOCSAGControl::sendPageAlert1(unsigned int ric) addAddress(FUNCTIONAL_ALERT1, ric, output->m_buffer); LogDebug("Local message to %07u, func Alert1", ric); + writeJSON("local", ric, "alert_1"); // Ensure data is an even number of words if ((output->m_buffer.size() % 2U) == 1U) @@ -182,6 +185,7 @@ void CPOCSAGControl::sendPageAlert2(unsigned int ric, const std::string& text) addAddress(FUNCTIONAL_ALERT2, ric, output->m_buffer); LogDebug("Local message to %07u, func Alert2: \"%s\"", ric, text.c_str()); + writeJSON("local", ric, "alert_2", text); packASCII(text, output->m_buffer); @@ -238,22 +242,26 @@ bool CPOCSAGControl::readNetwork() break; } LogDebug("Message to %07u, func Alphanumeric: %s", output->m_ric, output->m_display.c_str()); + writeJSON("network", output->m_ric, "alphanumeric", output->m_display); packASCII(output->m_text, output->m_buffer); break; case FUNCTIONAL_NUMERIC: output->m_text = std::string((char*)(data + 4U), length - 4U); output->m_display = output->m_text; LogDebug("Message to %07u, func Numeric: \"%s\"", output->m_ric, output->m_display.c_str()); + writeJSON("network", output->m_ric, "numeric", output->m_display); packNumeric(output->m_text, output->m_buffer); break; case FUNCTIONAL_ALERT1: output->m_display = "Func alert 1"; LogDebug("Message to %07u, func Alert 1", output->m_ric); + writeJSON("network", output->m_ric, "alert_1"); break; case FUNCTIONAL_ALERT2: output->m_text = std::string((char*)(data + 4U), length - 4U); output->m_display = "Func alert 2: " + output->m_text; LogDebug("Message to %07u, func Alert 2: \"%s\"", output->m_ric, output->m_display.c_str()); + writeJSON("network", output->m_ric, "alert_2", output->m_display); packASCII(output->m_text, output->m_buffer); break; default: @@ -579,3 +587,30 @@ void CPOCSAGControl::decodeROT1(const std::string& in, unsigned int start, std:: for (size_t i = start; i < in.length(); i++) out += in.at(i) - 1U; } + +void CPOCSAGControl::writeJSON(const std::string& source, unsigned int ric, const std::string& functional) +{ + nlohmann::json json; + + json["timestamp"] = CUtils::createTimestamp(); + json["source"] = source; + json["ric"] = int(ric); + json["functional"] = functional; + + WriteJSON("POCSAG", json); +} + +void CPOCSAGControl::writeJSON(const std::string& source, unsigned int ric, const std::string& functional, const std::string& message) +{ + nlohmann::json json; + + json["timestamp"] = CUtils::createTimestamp(); + json["source"] = source; + json["ric"] = int(ric); + json["functional"] = functional; + json["message"] = message; + + WriteJSON("POCSAG", json); +} + + diff --git a/POCSAGControl.h b/POCSAGControl.h index 42fed7e..e85d4ae 100644 --- a/POCSAGControl.h +++ b/POCSAGControl.h @@ -1,5 +1,5 @@ /* -* Copyright (C) 2018,2019,2020 by Jonathan Naylor G4KLX +* Copyright (C) 2018,2019,2020,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 @@ -87,6 +87,9 @@ private: void closeFile(); void decodeROT1(const std::string& in, unsigned int start, std::string& out) const; + + void writeJSON(const std::string& source, unsigned int ric, const std::string& functional); + void writeJSON(const std::string& source, unsigned int ric, const std::string& functional, const std::string& message); }; #endif diff --git a/schema.json b/schema.json index 4d9f0da..ad9934d 100644 --- a/schema.json +++ b/schema.json @@ -20,7 +20,7 @@ "m17_traffic_type": {"type": "string", "enum": ["audio", "audio_data", "data"]}, "ax25_pid": {"type": "string"}, "pocsag_source": {"type": "string", "enum": ["local", "network"]}, - "pocsag_function": {"type": "string", "enum": ["numeric", "alphanumeric", "alert_1", "alert_2"]}, + "pocsag_functional": {"type": "string", "enum": ["numeric", "alphanumeric", "alert_1", "alert_2"]}, "action": {"type": "string", "enum": ["invalid", "rejected", "header", "late_entry", "end", "lost"]}, "duration": {"type": "number", "minimum": 0.0}, "loss": {"type": "number", "minimum": 0.0}, @@ -141,10 +141,10 @@ "type": "object", "timestamp": {"$ref": "#/$defs/timestamp"}, "ric": {"$ref": "#/$defs/pocsag_ric"}, - "function": {"$ref": "#/$defs/pocsag_function"}, + "functional": {"$ref": "#/$defs/pocsag_functional"}, "source": {"$ref": "#/$defs/pocsag_source"}, - "data": {"type": "string"}, - "required": ["timestamp", "ric", "function", "source", "data"] + "message": {"type": "string"}, + "required": ["timestamp", "ric", "functional", "source"] }, "FM": {