From 8d941db7b1f7ea1f8b8d1ef4cc6773f8fdedced1 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Fri, 9 Jun 2023 15:46:29 +0100 Subject: [PATCH] Simplify the end of transmission JSON for all DV modes. --- DMRSlot.cpp | 98 ++++++++++++++++++++++++-------------------- DMRSlot.h | 9 ++-- DStarControl.cpp | 92 +++++++++++++++-------------------------- DStarControl.h | 10 ++--- M17Control.cpp | 48 +++++++++++++++------- M17Control.h | 10 +++-- NXDNControl.cpp | 54 +++++++++++++++--------- NXDNControl.h | 8 ++-- P25Control.cpp | 38 +++++++++-------- P25Control.h | 7 ++-- YSFControl.cpp | 104 ++++++++++++++--------------------------------- YSFControl.h | 12 +++--- schema.json | 12 +++--- 13 files changed, 243 insertions(+), 259 deletions(-) diff --git a/DMRSlot.cpp b/DMRSlot.cpp index 1f5e627..eed76ac 100644 --- a/DMRSlot.cpp +++ b/DMRSlot.cpp @@ -151,10 +151,10 @@ bool CDMRSlot::writeModem(unsigned char *data, unsigned int len) if (m_rssi != 0U) { LogMessage("DMR Slot %u, RF voice transmission lost from %s to %s%s, %.1f seconds, BER: %.1f%%, RSSI: -%u/-%u/-%u dBm", m_slotNo, src.c_str(), flco == FLCO_GROUP ? "TG " : "", dst.c_str(), float(m_rfFrames) / 16.667F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); - writeJSONRF("lost", srcId, src, flco == FLCO_GROUP, dstId, float(m_rfFrames) / 16.667F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); + writeJSONRF("lost", float(m_rfFrames) / 16.667F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); } else { LogMessage("DMR Slot %u, RF voice transmission lost from %s to %s%s, %.1f seconds, BER: %.1f%%", m_slotNo, src.c_str(), flco == FLCO_GROUP ? "TG " : "", dst.c_str(), float(m_rfFrames) / 16.667F, float(m_rfErrs * 100U) / float(m_rfBits)); - writeJSONRF("lost", srcId, src, flco == FLCO_GROUP, dstId, float(m_rfFrames) / 16.667F, float(m_rfErrs * 100U) / float(m_rfBits)); + writeJSONRF("lost", float(m_rfFrames) / 16.667F, float(m_rfErrs * 100U) / float(m_rfBits)); } if (m_rfTimeout) { @@ -174,7 +174,7 @@ bool CDMRSlot::writeModem(unsigned char *data, unsigned int len) FLCO flco = m_rfLC->getFLCO(); LogMessage("DMR Slot %u, RF data transmission lost from %s to %s%s", m_slotNo, src.c_str(), flco == FLCO_GROUP ? "TG " : "", dst.c_str()); - writeJSONRF("lost", srcId, src, flco == FLCO_GROUP, dstId); + writeJSONRF("lost"); writeEndRF(); return false; } @@ -371,10 +371,10 @@ bool CDMRSlot::writeModem(unsigned char *data, unsigned int len) if (m_rssi != 0U) { LogMessage("DMR Slot %u, received RF end of voice transmission from %s to %s%s, %.1f seconds, BER: %.1f%%, RSSI: -%u/-%u/-%u dBm", m_slotNo, src.c_str(), flco == FLCO_GROUP ? "TG " : "", dst.c_str(), float(m_rfFrames) / 16.667F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); - writeJSONRF("end", srcId, src, flco == FLCO_GROUP, dstId, float(m_rfFrames) / 16.667F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); + writeJSONRF("end", float(m_rfFrames) / 16.667F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); } else { LogMessage("DMR Slot %u, received RF end of voice transmission from %s to %s%s, %.1f seconds, BER: %.1f%%", m_slotNo, src.c_str(), flco == FLCO_GROUP ? "TG " : "", dst.c_str(), float(m_rfFrames) / 16.667F, float(m_rfErrs * 100U) / float(m_rfBits)); - writeJSONRF("end", srcId, src, flco == FLCO_GROUP, dstId, float(m_rfFrames) / 16.667F, float(m_rfErrs * 100U) / float(m_rfBits)); + writeJSONRF("end", float(m_rfFrames) / 16.667F, float(m_rfErrs * 100U) / float(m_rfBits)); } m_display->writeDMRTA(m_slotNo, NULL, " "); @@ -449,7 +449,7 @@ bool CDMRSlot::writeModem(unsigned char *data, unsigned int len) if (m_rfFrames == 0U) { LogMessage("DMR Slot %u, ended RF data transmission from %s to %s%s", m_slotNo, src.c_str(), gi ? "TG " : "", dst.c_str()); - writeJSONRF("end", srcId, src, gi, dstId); + writeJSONRF("end"); writeEndRF(); } @@ -559,11 +559,6 @@ bool CDMRSlot::writeModem(unsigned char *data, unsigned int len) if (m_rfState != RS_RF_DATA || m_rfFrames == 0U) return false; - unsigned int srcId = m_rfLC->getSrcId(); - unsigned int dstId = m_rfLC->getDstId(); - std::string src = m_lookup->find(srcId); - FLCO flco = m_rfLC->getFLCO(); - // Regenerate the rate 1/2 payload if (dataType == DT_RATE_12_DATA) { CBPTC19696 bptc; @@ -600,7 +595,7 @@ bool CDMRSlot::writeModem(unsigned char *data, unsigned int len) if (m_rfFrames == 0U) { LogMessage("DMR Slot %u, ended RF data transmission", m_slotNo); - writeJSONRF("end", srcId, src, flco == FLCO_GROUP, dstId); + writeJSONRF("end"); writeEndRF(); } @@ -1324,7 +1319,7 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) // We've received the voice header and terminator haven't we? m_netFrames += 2U; LogMessage("DMR Slot %u, received network end of voice transmission from %s to %s%s, %.1f seconds, %u%% packet loss, BER: %.1f%%", m_slotNo, src.c_str(), flco == FLCO_GROUP ? "TG " : "", dst.c_str(), float(m_netFrames) / 16.667F, (m_netLost * 100U) / m_netFrames, float(m_netErrs * 100U) / float(m_netBits)); - writeJSONNet("end", srcId, src, flco == FLCO_GROUP, dstId, float(m_netFrames) / 16.667F, (m_netLost * 100U) / m_netFrames, float(m_netErrs * 100U) / float(m_netBits)); + writeJSONNet("end", float(m_netFrames) / 16.667F, (m_netLost * 100U) / m_netFrames, float(m_netErrs * 100U) / float(m_netBits)); m_display->writeDMRTA(m_slotNo, NULL, " "); writeEndNet(); } else if (dataType == DT_DATA_HEADER) { @@ -1379,7 +1374,7 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) if (m_netFrames == 0U) { LogMessage("DMR Slot %u, ended network data transmission from %s to %s%s", m_slotNo, src.c_str(), gi ? "TG " : "", dst.c_str()); - writeJSONNet("end", srcId, src, gi, dstId); + writeJSONNet("end"); writeEndNet(); } } else if (dataType == DT_VOICE_SYNC) { @@ -1805,12 +1800,8 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) writeQueueNet(data); if (m_netFrames == 0U) { - unsigned int srcId = m_netLC->getSrcId(); - unsigned int dstId = m_netLC->getDstId(); - std::string src = m_lookup->find(srcId); - LogMessage("DMR Slot %u, ended network data transmission", m_slotNo); - writeJSONNet("end", srcId, src, m_netLC->getFLCO() == FLCO_GROUP, dstId); + writeJSONNet("end"); writeEndNet(); } } else { @@ -1874,12 +1865,8 @@ void CDMRSlot::clock() m_rfTimeoutTimer.clock(ms); if (m_rfTimeoutTimer.isRunning() && m_rfTimeoutTimer.hasExpired()) { if (!m_rfTimeout) { - unsigned int srcId = m_rfLC->getSrcId(); - unsigned int dstId = m_rfLC->getDstId(); - std::string src = m_lookup->find(srcId); - LogMessage("DMR Slot %u, RF user has timed out", m_slotNo); - writeJSONRF("timeout", srcId, src, m_rfLC->getFLCO() == FLCO_GROUP, dstId); + writeJSONRF("timeout"); m_rfTimeout = true; } } @@ -1887,12 +1874,8 @@ void CDMRSlot::clock() m_netTimeoutTimer.clock(ms); if (m_netTimeoutTimer.isRunning() && m_netTimeoutTimer.hasExpired()) { if (!m_netTimeout) { - unsigned int srcId = m_netLC->getSrcId(); - unsigned int dstId = m_netLC->getDstId(); - std::string src = m_lookup->find(srcId); - LogMessage("DMR Slot %u, network user has timed out", m_slotNo); - writeJSONNet("timeout", srcId, src, m_netLC->getFLCO() == FLCO_GROUP, dstId); + writeJSONNet("timeout"); m_netTimeout = true; } } @@ -1902,25 +1885,17 @@ void CDMRSlot::clock() if (m_networkWatchdog.hasExpired()) { if (m_netState == RS_NET_AUDIO) { - unsigned int srcId = m_netLC->getSrcId(); - unsigned int dstId = m_netLC->getDstId(); - std::string src = m_lookup->find(srcId); - // We've received the voice header haven't we? m_netFrames += 1U; LogMessage("DMR Slot %u, network watchdog has expired, %.1f seconds, %u%% packet loss, BER: %.1f%%", m_slotNo, float(m_netFrames) / 16.667F, (m_netLost * 100U) / m_netFrames, float(m_netErrs * 100U) / float(m_netBits)); - writeJSONNet("lost", srcId, src, m_netLC->getFLCO() == FLCO_GROUP, dstId, float(m_netFrames) / 16.667F, (m_netLost * 100U) / m_netFrames, float(m_netErrs * 100U) / float(m_netBits)); + writeJSONNet("lost", float(m_netFrames) / 16.667F, (m_netLost * 100U) / m_netFrames, float(m_netErrs * 100U) / float(m_netBits)); writeEndNet(true); #if defined(DUMP_DMR) closeFile(); #endif } else { - unsigned int srcId = m_netLC->getSrcId(); - unsigned int dstId = m_netLC->getDstId(); - std::string src = m_lookup->find(srcId); - LogMessage("DMR Slot %u, network watchdog has expired", m_slotNo); - writeJSONNet("lost", srcId, src, m_netLC->getFLCO() == FLCO_GROUP, dstId); + writeJSONNet("lost"); writeEndNet(); #if defined(DUMP_DMR) closeFile(); @@ -2314,6 +2289,17 @@ void CDMRSlot::enable(bool enabled) m_enabled = enabled; } +void CDMRSlot::writeJSONRF(const char* action) +{ + assert(action != NULL); + + nlohmann::json json; + + writeJSON(json, "rf", action); + + WriteJSON("DMR", json); +} + void CDMRSlot::writeJSONRF(const char* action, unsigned int srcId, const std::string& srcInfo, bool grp, unsigned int dstId) { assert(action != NULL); @@ -2352,13 +2338,13 @@ void CDMRSlot::writeJSONRF(const char* action, unsigned int srcId, const std::st WriteJSON("DMR", json); } -void CDMRSlot::writeJSONRF(const char* action, unsigned int srcId, const std::string& srcInfo, bool grp, unsigned int dstId, float duration, float ber) +void CDMRSlot::writeJSONRF(const char* action, float duration, float ber) { assert(action != NULL); nlohmann::json json; - writeJSON(json, "rf", action, srcId, srcInfo, grp, dstId); + writeJSON(json, "rf", action); json["duration"] = duration; json["ber"] = ber; @@ -2366,13 +2352,13 @@ void CDMRSlot::writeJSONRF(const char* action, unsigned int srcId, const std::st WriteJSON("DMR", json); } -void CDMRSlot::writeJSONRF(const char* action, unsigned int srcId, const std::string& srcInfo, bool grp, unsigned int dstId, float duration, float ber, unsigned char minRSSI, unsigned char maxRSSI, unsigned int aveRSSI) +void CDMRSlot::writeJSONRF(const char* action, float duration, float ber, unsigned char minRSSI, unsigned char maxRSSI, unsigned int aveRSSI) { assert(action != NULL); nlohmann::json json; - writeJSON(json, "rf", action, srcId, srcInfo, grp, dstId); + writeJSON(json, "rf", action); json["duration"] = duration; json["ber"] = ber; @@ -2387,6 +2373,17 @@ void CDMRSlot::writeJSONRF(const char* action, unsigned int srcId, const std::st WriteJSON("DMR", json); } +void CDMRSlot::writeJSONNet(const char* action) +{ + assert(action != NULL); + + nlohmann::json json; + + writeJSON(json, "network", action); + + WriteJSON("DMR", json); +} + void CDMRSlot::writeJSONNet(const char* action, unsigned int srcId, const std::string& srcInfo, bool grp, unsigned int dstId) { assert(action != NULL); @@ -2425,13 +2422,13 @@ void CDMRSlot::writeJSONNet(const char* action, unsigned int srcId, const std::s WriteJSON("DMR", json); } -void CDMRSlot::writeJSONNet(const char* action, unsigned int srcId, const std::string& srcInfo, bool grp, unsigned int dstId, float duration, float loss, float ber) +void CDMRSlot::writeJSONNet(const char* action, float duration, float loss, float ber) { assert(action != NULL); nlohmann::json json; - writeJSON(json, "network", action, srcId, srcInfo, grp, dstId); + writeJSON(json, "network", action); json["duration"] = duration; json["loss"] = loss; @@ -2440,6 +2437,17 @@ void CDMRSlot::writeJSONNet(const char* action, unsigned int srcId, const std::s WriteJSON("DMR", json); } +void CDMRSlot::writeJSON(nlohmann::json& json, const char* source, const char* action) +{ + assert(source != NULL); + assert(action != NULL); + + json["timestamp"] = CUtils::createTimestamp(); + json["source"] = source; + json["action"] = action; + json["slot"] = int(m_slotNo); +} + void CDMRSlot::writeJSON(nlohmann::json& json, const char* source, const char* action, unsigned int srcId, const std::string& srcInfo, bool grp, unsigned int dstId) { assert(source != NULL); diff --git a/DMRSlot.h b/DMRSlot.h index 18fadd2..42888e0 100644 --- a/DMRSlot.h +++ b/DMRSlot.h @@ -161,17 +161,20 @@ private: static void setShortLC(unsigned int slotNo, unsigned int id, FLCO flco = FLCO_GROUP, ACTIVITY_TYPE type = ACTIVITY_NONE); + void writeJSONRF(const char* action); void writeJSONRF(const char* action, unsigned int srcId, const std::string& srcInfo, bool grp, unsigned int dstId); void writeJSONRF(const char* action, unsigned int srcId, const std::string& srcInfo, bool grp, unsigned int dstId, unsigned int frames); void writeJSONRF(const char* action, const char* desc, unsigned int srcId, const std::string& srcInfo, bool grp, unsigned int dstId); - void writeJSONRF(const char* action, unsigned int srcId, const std::string& srcInfo, bool grp, unsigned int dstId, float duration, float ber); - void writeJSONRF(const char* action, unsigned int srcId, const std::string& srcInfo, bool grp, unsigned int dstId, float duration, float ber, unsigned char minRSSI, unsigned char maxRSSI, unsigned int aveRSSI); + void writeJSONRF(const char* action, float duration, float ber); + void writeJSONRF(const char* action, float duration, float ber, unsigned char minRSSI, unsigned char maxRSSI, unsigned int aveRSSI); + void writeJSONNet(const char* action); void writeJSONNet(const char* action, unsigned int srcId, const std::string& srcInfo, bool grp, unsigned int dstId); void writeJSONNet(const char* action, unsigned int srcId, const std::string& srcInfo, bool grp, unsigned int dstId, unsigned int frames); - void writeJSONNet(const char* action, unsigned int srcId, const std::string& srcInfo, bool grp, unsigned int dstId, float duration, float loss, float ber); + void writeJSONNet(const char* action, float duration, float loss, float ber); void writeJSONNet(const char* action, const char* desc, unsigned int srcId, const std::string& srcInfo, bool grp, unsigned int dstId); + void writeJSON(nlohmann::json& json, const char* source, const char* action); void writeJSON(nlohmann::json& json, const char* source, const char* action, unsigned int srcId, const std::string& srcInfo, bool grp, unsigned int dstId); }; diff --git a/DStarControl.cpp b/DStarControl.cpp index b44375c..c1577ab 100644 --- a/DStarControl.cpp +++ b/DStarControl.cpp @@ -227,10 +227,10 @@ bool CDStarControl::writeModem(unsigned char *data, unsigned int len) if (m_rssi != 0U) { LogMessage("D-Star, transmission lost from %8.8s/%4.4s to %8.8s, %.1f seconds, BER: %.1f%%, RSSI: -%u/-%u/-%u dBm", my1, my2, your, float(m_rfFrames) / 50.0F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); - writeJSONRF("lost", my1, my2, your, float(m_rfFrames) / 50.0F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); + writeJSONRF("lost", float(m_rfFrames) / 50.0F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); } else { LogMessage("D-Star, transmission lost from %8.8s/%4.4s to %8.8s, %.1f seconds, BER: %.1f%%", my1, my2, your, float(m_rfFrames) / 50.0F, float(m_rfErrs * 100U) / float(m_rfBits)); - writeJSONRF("lost", my1, my2, your, float(m_rfFrames) / 50.0F, float(m_rfErrs * 100U) / float(m_rfBits)); + writeJSONRF("lost", float(m_rfFrames) / 50.0F, float(m_rfErrs * 100U) / float(m_rfBits)); } writeEndRF(); return false; @@ -433,10 +433,10 @@ bool CDStarControl::writeModem(unsigned char *data, unsigned int len) if (m_rssi != 0U) { LogMessage("D-Star, received RF end of transmission from %8.8s/%4.4s to %8.8s, %.1f seconds, BER: %.1f%%, RSSI: -%u/-%u/-%u dBm", my1, my2, your, float(m_rfFrames) / 50.0F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); - writeJSONRF("end", my1, my2, your, float(m_rfFrames) / 50.0F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); + writeJSONRF("end", float(m_rfFrames) / 50.0F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); } else { LogMessage("D-Star, received RF end of transmission from %8.8s/%4.4s to %8.8s, %.1f seconds, BER: %.1f%%", my1, my2, your, float(m_rfFrames) / 50.0F, float(m_rfErrs * 100U) / float(m_rfBits)); - writeJSONRF("end", my1, my2, your, float(m_rfFrames) / 50.0F, float(m_rfErrs * 100U) / float(m_rfBits)); + writeJSONRF("end", float(m_rfFrames) / 50.0F, float(m_rfErrs * 100U) / float(m_rfBits)); } writeEndRF(); @@ -795,7 +795,7 @@ void CDStarControl::writeNetwork() // We've received the header and EOT haven't we? m_netFrames += 2U; LogMessage("D-Star, received network end of transmission from %8.8s/%4.4s to %8.8s, %.1f seconds, %u%% packet loss", my1, my2, your, float(m_netFrames) / 50.0F, (m_netLost * 100U) / m_netFrames); - writeJSONNet("end", my1, my2, your, float(m_netFrames) / 50.0F, (m_netLost * 100U) / m_netFrames); + writeJSONNet("end", float(m_netFrames) / 50.0F, (m_netLost * 100U) / m_netFrames); writeEndNet(); } else if (type == TAG_DATA) { @@ -877,7 +877,7 @@ void CDStarControl::clock() m_netFrames += 1U; LogMessage("D-Star, network watchdog has expired, %.1f seconds, %u%% packet loss", float(m_netFrames) / 50.0F, (m_netLost * 100U) / m_netFrames); - writeJSONNet("lost", my1, my2, your, float(m_netFrames) / 50.0F, (m_netLost * 100U) / m_netFrames); + writeJSONNet("lost", float(m_netFrames) / 50.0F, (m_netLost * 100U) / m_netFrames); writeEndNet(); #if defined(DUMP_DSTAR) closeFile(); @@ -1347,35 +1347,36 @@ void CDStarControl::writeJSONRF(const char* action, const unsigned char* my1, co nlohmann::json json; - writeJSONRF(json, action, my1, my2, your); + json["timestamp"] = CUtils::createTimestamp(); + + json["source_cs"] = convertBuffer(my1, DSTAR_LONG_CALLSIGN_LENGTH); + json["source_ext"] = convertBuffer(my2, DSTAR_SHORT_CALLSIGN_LENGTH); + json["destination_cs"] = convertBuffer(your, DSTAR_LONG_CALLSIGN_LENGTH); + + json["source"] = "rf"; + json["action"] = action; WriteJSON("D-Star", json); } -void CDStarControl::writeJSONRF(const char* action, const unsigned char* my1, const unsigned char* my2, const unsigned char* your, float duration, float ber) +void CDStarControl::writeJSONRF(const char* action, float duration, float ber) { assert(action != NULL); - assert(my1 != NULL); - assert(my2 != NULL); - assert(your != NULL); nlohmann::json json; - writeJSONRF(json, action, my1, my2, your, duration, ber); + writeJSONRF(json, action, duration, ber); WriteJSON("D-Star", json); } -void CDStarControl::writeJSONRF(const char* action, const unsigned char* my1, const unsigned char* my2, const unsigned char* your, float duration, float ber, unsigned char minRSSI, unsigned char maxRSSI, unsigned int aveRSSI) +void CDStarControl::writeJSONRF(const char* action, float duration, float ber, unsigned char minRSSI, unsigned char maxRSSI, unsigned int aveRSSI) { assert(action != NULL); - assert(my1 != NULL); - assert(my2 != NULL); - assert(your != NULL); nlohmann::json json; - writeJSONRF(json, action, my1, my2, your, duration, ber); + writeJSONRF(json, action, duration, ber); nlohmann::json rssi; rssi["min"] = -int(minRSSI); @@ -1396,7 +1397,14 @@ void CDStarControl::writeJSONNet(const char* action, const unsigned char* my1, c nlohmann::json json; - writeJSONNet(json, action, my1, my2, your); + json["timestamp"] = CUtils::createTimestamp(); + + json["source_cs"] = convertBuffer(my1, DSTAR_LONG_CALLSIGN_LENGTH); + json["source_ext"] = convertBuffer(my2, DSTAR_SHORT_CALLSIGN_LENGTH); + json["destination_cs"] = convertBuffer(your, DSTAR_LONG_CALLSIGN_LENGTH); + + json["source"] = "network"; + json["action"] = action; if (reflector != NULL) json["reflector"] = convertBuffer(reflector, DSTAR_LONG_CALLSIGN_LENGTH); @@ -1404,67 +1412,33 @@ void CDStarControl::writeJSONNet(const char* action, const unsigned char* my1, c WriteJSON("D-Star", json); } -void CDStarControl::writeJSONNet(const char* action, const unsigned char* my1, const unsigned char* my2, const unsigned char* your, float duration, float loss) +void CDStarControl::writeJSONNet(const char* action, float duration, float loss) { assert(action != NULL); - assert(my1 != NULL); - assert(my2 != NULL); - assert(your != NULL); nlohmann::json json; - writeJSONNet(json, action, my1, my2, your); + json["timestamp"] = CUtils::createTimestamp(); json["duration"] = duration; json["loss"] = loss; + json["source"] = "network"; + json["action"] = action; + WriteJSON("D-Star", json); } -void CDStarControl::writeJSONRF(nlohmann::json& json, const char* action, const unsigned char* my1, const unsigned char* my2, const unsigned char* your) +void CDStarControl::writeJSONRF(nlohmann::json& json, const char* action, float duration, float ber) { assert(action != NULL); - assert(my1 != NULL); - assert(my2 != NULL); - assert(your != NULL); json["timestamp"] = CUtils::createTimestamp(); - json["source_cs"] = convertBuffer(my1, DSTAR_LONG_CALLSIGN_LENGTH); - json["source_ext"] = convertBuffer(my2, DSTAR_SHORT_CALLSIGN_LENGTH); - json["destination_cs"] = convertBuffer(your, DSTAR_LONG_CALLSIGN_LENGTH); - - json["source"] = "rf"; - json["action"] = action; -} - -void CDStarControl::writeJSONRF(nlohmann::json& json, const char* action, const unsigned char* my1, const unsigned char* my2, const unsigned char* your, float duration, float ber) -{ - assert(action != NULL); - assert(my1 != NULL); - assert(my2 != NULL); - assert(your != NULL); - - writeJSONRF(json, action, my1, my2, your); - json["duration"] = duration; json["ber"] = ber; -} -void CDStarControl::writeJSONNet(nlohmann::json& json, const char* action, const unsigned char* my1, const unsigned char* my2, const unsigned char* your) -{ - assert(action != NULL); - assert(my1 != NULL); - assert(my2 != NULL); - assert(your != NULL); - - json["timestamp"] = CUtils::createTimestamp(); - - json["source_cs"] = convertBuffer(my1, DSTAR_LONG_CALLSIGN_LENGTH); - json["source_ext"] = convertBuffer(my2, DSTAR_SHORT_CALLSIGN_LENGTH); - json["destination_cs"] = convertBuffer(your, DSTAR_LONG_CALLSIGN_LENGTH); - - json["source"] = "network"; + json["source"] = "rf"; json["action"] = action; } diff --git a/DStarControl.h b/DStarControl.h index f7e6bec..dc6202f 100644 --- a/DStarControl.h +++ b/DStarControl.h @@ -136,14 +136,12 @@ private: void writeEndNet(); void writeJSONRF(const char* action, const unsigned char* my1, const unsigned char* my2, const unsigned char* your); - void writeJSONRF(const char* action, const unsigned char* my1, const unsigned char* my2, const unsigned char* your, float duration, float ber); - void writeJSONRF(const char* action, const unsigned char* my1, const unsigned char* my2, const unsigned char* your, float duration, float ber, unsigned char minRSSI, unsigned char maxRSSI, unsigned int aveRSSI); + void writeJSONRF(const char* action, float duration, float ber); + void writeJSONRF(const char* action, float duration, float ber, unsigned char minRSSI, unsigned char maxRSSI, unsigned int aveRSSI); void writeJSONNet(const char* action, const unsigned char* my1, const unsigned char* my2, const unsigned char* your, const unsigned char* reflector = NULL); - void writeJSONNet(const char* action, const unsigned char* my1, const unsigned char* my2, const unsigned char* your, float duration, float loss); + void writeJSONNet(const char* action, float duration, float loss); - void writeJSONRF(nlohmann::json& json, const char* action, const unsigned char* my1, const unsigned char* my2, const unsigned char* your); - void writeJSONRF(nlohmann::json& json, const char* action, const unsigned char* my1, const unsigned char* my2, const unsigned char* your, float duration, float ber); - void writeJSONNet(nlohmann::json& json, const char* action, const unsigned char* my1, const unsigned char* my2, const unsigned char* your); + void writeJSONRF(nlohmann::json& json, const char* action, float duration, float ber); std::string convertBuffer(const unsigned char* buffer, unsigned int length) const; diff --git a/M17Control.cpp b/M17Control.cpp index a2f2bc8..7909b52 100644 --- a/M17Control.cpp +++ b/M17Control.cpp @@ -115,10 +115,10 @@ bool CM17Control::writeModem(unsigned char* data, unsigned int len) if (type == TAG_LOST && (m_rfState == RS_RF_AUDIO || m_rfState == RS_RF_DATA_AUDIO)) { if (m_rssi != 0U) { LogMessage("M17, transmission lost from %s to %s, %.1f seconds, BER: %.1f%%, RSSI: -%u/-%u/-%u dBm", m_source.c_str(), m_dest.c_str(), float(m_rfFrames) / 25.0F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); - writeJSONRF("lost", m_rfState, m_source, m_dest, float(m_rfFrames) / 25.0F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); + writeJSONRF("lost", float(m_rfFrames) / 25.0F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); } else { LogMessage("M17, transmission lost from %s to %s, %.1f seconds, BER: %.1f%%", m_source.c_str(), m_dest.c_str(), float(m_rfFrames) / 25.0F, float(m_rfErrs * 100U) / float(m_rfBits)); - writeJSONRF("lost", m_rfState, m_source, m_dest, float(m_rfFrames) / 25.0F, float(m_rfErrs * 100U) / float(m_rfBits)); + writeJSONRF("lost", float(m_rfFrames) / 25.0F, float(m_rfErrs * 100U) / float(m_rfBits)); } writeEndRF(); return false; @@ -423,10 +423,10 @@ bool CM17Control::writeModem(unsigned char* data, unsigned int len) if (m_rssi != 0U) { LogMessage("M17, received RF end of transmission from %s to %s, %.1f seconds, BER: %.1f%%, RSSI: -%u/-%u/-%u dBm", m_source.c_str(), m_dest.c_str(), float(m_rfFrames) / 25.0F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); - writeJSONRF("end", m_rfState, m_source, m_dest, float(m_rfFrames) / 25.0F, float(m_rfErrs * 100U) / float(m_rfBits)); + writeJSONRF("end", float(m_rfFrames) / 25.0F, float(m_rfErrs * 100U) / float(m_rfBits)); } else { LogMessage("M17, received RF end of transmission from %s to %s, %.1f seconds, BER: %.1f%%", m_source.c_str(), m_dest.c_str(), float(m_rfFrames) / 25.0F, float(m_rfErrs * 100U) / float(m_rfBits)); - writeJSONRF("end", m_rfState, m_source, m_dest, float(m_rfFrames) / 25.0F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); + writeJSONRF("end", float(m_rfFrames) / 25.0F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); } writeEndRF(); @@ -646,7 +646,7 @@ void CM17Control::writeNetwork() uint16_t fn = (netData[28U] << 8) + (netData[29U] << 0); if ((fn & 0x8000U) == 0x8000U) { LogMessage("M17, received network end of transmission from %s to %s, %.1f seconds", m_source.c_str(), m_dest.c_str(), float(m_netFrames) / 25.0F); - writeJSONNet("end", m_netState, m_source, m_dest, float(m_netFrames) / 25.0F); + writeJSONNet("end", float(m_netFrames) / 25.0F); unsigned char data[M17_FRAME_LENGTH_BYTES + 2U]; @@ -781,7 +781,7 @@ void CM17Control::clock(unsigned int ms) if (m_networkWatchdog.hasExpired()) { LogMessage("M17, network watchdog has expired, %.1f seconds", float(m_netFrames) / 25.0F); - writeJSONNet("lost", m_netState, m_source, m_dest, float(m_netFrames) / 25.0F); + writeJSONNet("lost", float(m_netFrames) / 25.0F); writeEndNet(); } } @@ -936,24 +936,24 @@ void CM17Control::writeJSONRF(const char* action, RPT_RF_STATE state, const std: WriteJSON("M17", json); } -void CM17Control::writeJSONRF(const char* action, RPT_RF_STATE state, const std::string& source, const std::string& dest, float duration, float ber) +void CM17Control::writeJSONRF(const char* action, float duration, float ber) { assert(action != NULL); nlohmann::json json; - writeJSONRF(json, action, state, source, dest, duration, ber); + writeJSONRF(json, action, duration, ber); WriteJSON("M17", json); } -void CM17Control::writeJSONRF(const char* action, RPT_RF_STATE state, const std::string& source, const std::string& dest, float duration, float ber, unsigned char minRSSI, unsigned char maxRSSI, unsigned int aveRSSI) +void CM17Control::writeJSONRF(const char* action, float duration, float ber, unsigned char minRSSI, unsigned char maxRSSI, unsigned int aveRSSI) { assert(action != NULL); nlohmann::json json; - writeJSONRF(json, action, state, source, dest, duration, ber); + writeJSONRF(json, action, duration, ber); nlohmann::json rssi; rssi["min"] = -int(minRSSI); @@ -976,19 +976,29 @@ void CM17Control::writeJSONNet(const char* action, RPT_NET_STATE state, const st WriteJSON("M17", json); } -void CM17Control::writeJSONNet(const char* action, RPT_NET_STATE state, const std::string& source, const std::string& dest, float duration) +void CM17Control::writeJSONNet(const char* action, float duration) { assert(action != NULL); nlohmann::json json; - writeJSONNet(json, action, state, source, dest); + writeJSONNet(json, action); json["duration"] = duration; WriteJSON("M17", json); } +void CM17Control::writeJSONRF(nlohmann::json& json, const char* action) +{ + assert(action != NULL); + + json["timestamp"] = CUtils::createTimestamp(); + + json["source"] = "rf"; + json["action"] = action; +} + void CM17Control::writeJSONRF(nlohmann::json& json, const char* action, RPT_RF_STATE state, const std::string& source, const std::string& dest) { assert(action != NULL); @@ -1017,16 +1027,26 @@ void CM17Control::writeJSONRF(nlohmann::json& json, const char* action, RPT_RF_S } } -void CM17Control::writeJSONRF(nlohmann::json& json, const char* action, RPT_RF_STATE state, const std::string& source, const std::string& dest, float duration, float ber) +void CM17Control::writeJSONRF(nlohmann::json& json, const char* action, float duration, float ber) { assert(action != NULL); - writeJSONRF(json, action, state, source, dest); + writeJSONRF(json, action); json["duration"] = duration; json["ber"] = ber; } +void CM17Control::writeJSONNet(nlohmann::json& json, const char* action) +{ + assert(action != NULL); + + json["timestamp"] = CUtils::createTimestamp(); + + json["source"] = "network"; + json["action"] = action; +} + void CM17Control::writeJSONNet(nlohmann::json& json, const char* action, RPT_NET_STATE state, const std::string& source, const std::string& dest) { assert(action != NULL); diff --git a/M17Control.h b/M17Control.h index ae505c2..731f987 100644 --- a/M17Control.h +++ b/M17Control.h @@ -106,14 +106,16 @@ private: void writeEndNet(); void writeJSONRF(const char* action, RPT_RF_STATE state, const std::string& source, const std::string& dest); - void writeJSONRF(const char* action, RPT_RF_STATE state, const std::string& source, const std::string& dest, float duration, float ber); - void writeJSONRF(const char* action, RPT_RF_STATE state, const std::string& source, const std::string& dest, float duration, float ber, unsigned char minRSSI, unsigned char maxRSSI, unsigned int aveRSSI); + void writeJSONRF(const char* action, float duration, float ber); + void writeJSONRF(const char* action, float duration, float ber, unsigned char minRSSI, unsigned char maxRSSI, unsigned int aveRSSI); void writeJSONNet(const char* action, RPT_NET_STATE state, const std::string& source, const std::string& dest); - void writeJSONNet(const char* action, RPT_NET_STATE state, const std::string& source, const std::string& dest, float duration); + void writeJSONNet(const char* action, float duration); void writeJSONRF(nlohmann::json& json, const char* action, RPT_RF_STATE state, const std::string& source, const std::string& dest); - void writeJSONRF(nlohmann::json& json, const char* action, RPT_RF_STATE state, const std::string& source, const std::string& dest, float duration, float ber); + void writeJSONRF(nlohmann::json& json, const char* action); + void writeJSONRF(nlohmann::json& json, const char* action, float duration, float ber); + void writeJSONNet(nlohmann::json& json, const char* action); void writeJSONNet(nlohmann::json& json, const char* action, RPT_NET_STATE state, const std::string& source, const std::string& dest); bool openFile(); diff --git a/NXDNControl.cpp b/NXDNControl.cpp index b904b24..22b159f 100644 --- a/NXDNControl.cpp +++ b/NXDNControl.cpp @@ -100,10 +100,10 @@ bool CNXDNControl::writeModem(unsigned char *data, unsigned int len) if (m_rssi != 0U) { LogMessage("NXDN, transmission lost from %s to %s%u, %.1f seconds, BER: %.1f%%, RSSI: -%u/-%u/-%u dBm", source.c_str(), grp ? "TG " : "", dstId, float(m_rfFrames) / 12.5F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); - writeJSONRF("lost", srcId, source, grp, dstId, float(m_rfFrames) / 12.5F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); + writeJSONRF("lost", float(m_rfFrames) / 12.5F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); } else { LogMessage("NXDN, transmission lost from %s to %s%u, %.1f seconds, BER: %.1f%%", source.c_str(), grp ? "TG " : "", dstId, float(m_rfFrames) / 12.5F, float(m_rfErrs * 100U) / float(m_rfBits)); - writeJSONRF("lost", srcId, source, grp, dstId, float(m_rfFrames) / 12.5F, float(m_rfErrs * 100U) / float(m_rfBits)); + writeJSONRF("lost", float(m_rfFrames) / 12.5F, float(m_rfErrs * 100U) / float(m_rfBits)); } writeEndRF(); return false; @@ -275,10 +275,10 @@ bool CNXDNControl::processVoice(unsigned char usc, unsigned char option, unsigne m_rfFrames++; if (m_rssi != 0U) { LogMessage("NXDN, received RF end of transmission from %s to %s%u, %.1f seconds, BER: %.1f%%, RSSI: -%u/-%u/-%u dBm", source.c_str(), grp ? "TG " : "", dstId, float(m_rfFrames) / 12.5F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); - writeJSONRF("end", srcId, source, grp, dstId, float(m_rfFrames) / 12.5F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); + writeJSONRF("end", float(m_rfFrames) / 12.5F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); } else { LogMessage("NXDN, received RF end of transmission from %s to %s%u, %.1f seconds, BER: %.1f%%", source.c_str(), grp ? "TG " : "", dstId, float(m_rfFrames) / 12.5F, float(m_rfErrs * 100U) / float(m_rfBits)); - writeJSONRF("end", srcId, source, grp, dstId, float(m_rfFrames) / 12.5F, float(m_rfErrs * 100U) / float(m_rfBits)); + writeJSONRF("end", float(m_rfFrames) / 12.5F, float(m_rfErrs * 100U) / float(m_rfBits)); } writeEndRF(); } else { @@ -688,7 +688,7 @@ bool CNXDNControl::processData(unsigned char option, unsigned char *data) std::string source = m_lookup->find(srcId); LogMessage("NXDN, ended RF data transmission from %s to %s%u", source.c_str(), grp ? "TG " : "", dstId); - writeJSONNet("end", srcId, source, grp, dstId); + writeJSONNet("end"); writeEndRF(); } @@ -858,7 +858,7 @@ void CNXDNControl::writeNetwork() if (type == NXDN_MESSAGE_TYPE_TX_REL) { m_netFrames++; LogMessage("NXDN, received network end of transmission from %s to %s%u, %.1f seconds", source.get(keyCALLSIGN).c_str(), grp ? "TG " : "", dstId, float(m_netFrames) / 12.5F); - writeJSONNet("end", srcId, source.get(keyCALLSIGN), grp, dstId, float(m_netFrames) / 12.5F); + writeJSONNet("end", float(m_netFrames) / 12.5F); writeEndNet(); } else if (type == NXDN_MESSAGE_TYPE_VCALL) { LogMessage("NXDN, received network transmission from %s to %s%u", source.get(keyCALLSIGN).c_str(), grp ? "TG " : "", dstId); @@ -1016,15 +1016,8 @@ void CNXDNControl::clock(unsigned int ms) m_networkWatchdog.clock(ms); if (m_networkWatchdog.hasExpired()) { - unsigned short srcId = m_netLayer3.getSourceUnitId(); - unsigned short dstId = m_netLayer3.getDestinationGroupId(); - bool grp = m_netLayer3.getIsGroup(); - - class CUserDBentry source; - m_lookup->findWithName(srcId, &source); - LogMessage("NXDN, network watchdog has expired, %.1f seconds", float(m_netFrames) / 12.5F); - writeJSONNet("lost", srcId, source.get(keyCALLSIGN), grp, dstId, float(m_netFrames) / 12.5F); + writeJSONNet("lost", float(m_netFrames) / 12.5F); writeEndNet(); } } @@ -1177,13 +1170,13 @@ void CNXDNControl::writeJSONRF(const char* action, unsigned short srcId, const s WriteJSON("NXDN", json); } -void CNXDNControl::writeJSONRF(const char* action, unsigned short srcId, const std::string& srcInfo, bool grp, unsigned short dstId, float duration, float ber) +void CNXDNControl::writeJSONRF(const char* action, float duration, float ber) { assert(action != NULL); nlohmann::json json; - writeJSON(json, "rf", action, srcId, srcInfo, grp, dstId); + writeJSON(json, "rf", action); json["duration"] = duration; json["ber"] = ber; @@ -1191,13 +1184,13 @@ void CNXDNControl::writeJSONRF(const char* action, unsigned short srcId, const s WriteJSON("NXDN", json); } -void CNXDNControl::writeJSONRF(const char* action, unsigned short srcId, const std::string& srcInfo, bool grp, unsigned short dstId, float duration, float ber, unsigned char minRSSI, unsigned char maxRSSI, unsigned int aveRSSI) +void CNXDNControl::writeJSONRF(const char* action, float duration, float ber, unsigned char minRSSI, unsigned char maxRSSI, unsigned int aveRSSI) { assert(action != NULL); nlohmann::json json; - writeJSON(json, "rf", action, srcId, srcInfo, grp, dstId); + writeJSON(json, "rf", action); json["duration"] = duration; json["ber"] = ber; @@ -1212,6 +1205,17 @@ void CNXDNControl::writeJSONRF(const char* action, unsigned short srcId, const s WriteJSON("NXDN", json); } +void CNXDNControl::writeJSONNet(const char* action) +{ + assert(action != NULL); + + nlohmann::json json; + + writeJSON(json, "network", action); + + WriteJSON("NXDN", json); +} + void CNXDNControl::writeJSONNet(const char* action, unsigned short srcId, const std::string& srcInfo, bool grp, unsigned short dstId) { assert(action != NULL); @@ -1236,19 +1240,29 @@ void CNXDNControl::writeJSONNet(const char* action, unsigned short srcId, const WriteJSON("NXDN", json); } -void CNXDNControl::writeJSONNet(const char* action, unsigned short srcId, const std::string& srcInfo, bool grp, unsigned short dstId, float duration) +void CNXDNControl::writeJSONNet(const char* action, float duration) { assert(action != NULL); nlohmann::json json; - writeJSON(json, "network", action, srcId, srcInfo, grp, dstId); + writeJSON(json, "network", action); json["duration"] = duration; WriteJSON("NXDN", json); } +void CNXDNControl::writeJSON(nlohmann::json& json, const char* source, const char* action) +{ + assert(source != NULL); + assert(action != NULL); + + json["timestamp"] = CUtils::createTimestamp(); + json["source"] = source; + json["action"] = action; +} + void CNXDNControl::writeJSON(nlohmann::json& json, const char* source, const char* action, unsigned short srcId, const std::string& srcInfo, bool grp, unsigned short dstId) { assert(source != NULL); diff --git a/NXDNControl.h b/NXDNControl.h index 7fdbb66..efdabf8 100644 --- a/NXDNControl.h +++ b/NXDNControl.h @@ -104,13 +104,15 @@ private: void closeFile(); void writeJSONRF(const char* action, unsigned short srcId, const std::string& srcInfo, bool grp, unsigned short dstId); - void writeJSONRF(const char* action, unsigned short srcId, const std::string& srcInfo, bool grp, unsigned short dstId, float duration, float ber); - void writeJSONRF(const char* action, unsigned short srcId, const std::string& srcInfo, bool grp, unsigned short dstId, float duration, float ber, unsigned char minRSSI, unsigned char maxRSSI, unsigned int aveRSSI); + void writeJSONRF(const char* action, float duration, float ber); + void writeJSONRF(const char* action, float duration, float ber, unsigned char minRSSI, unsigned char maxRSSI, unsigned int aveRSSI); void writeJSONNet(const char* action, unsigned short srcId, const std::string& srcInfo, bool grp, unsigned short dstId); void writeJSONNet(const char* action, unsigned short srcId, const std::string& srcInfo, bool grp, unsigned short dstId, unsigned char frames); - void writeJSONNet(const char* action, unsigned short srcId, const std::string& srcInfo, bool grp, unsigned short dstId, float duration); + void writeJSONNet(const char* action); + void writeJSONNet(const char* action, float duration); + void writeJSON(nlohmann::json& json, const char* source, const char* action); void writeJSON(nlohmann::json& json, const char* source, const char* action, unsigned short srcId, const std::string& srcInfo, bool grp, unsigned short dstId); }; diff --git a/P25Control.cpp b/P25Control.cpp index 0c45e60..a208021 100644 --- a/P25Control.cpp +++ b/P25Control.cpp @@ -129,10 +129,10 @@ bool CP25Control::writeModem(unsigned char* data, unsigned int len) if (m_rssi != 0U) { LogMessage("P25, transmission lost from %s to %s%u, %.1f seconds, BER: %.1f%%, RSSI: -%u/-%u/-%u dBm", source.c_str(), grp ? "TG " : "", dstId, float(m_rfFrames) / 5.56F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); - writeJSONRF("lost", srcId, source, grp, dstId, float(m_rfFrames) / 5.56F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); + writeJSONRF("lost", float(m_rfFrames) / 5.56F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); } else { LogMessage("P25, transmission lost from %s to %s%u, %.1f seconds, BER: %.1f%%", source.c_str(), grp ? "TG " : "", dstId, float(m_rfFrames) / 5.56F, float(m_rfErrs * 100U) / float(m_rfBits)); - writeJSONRF("lost", srcId, source, grp, dstId, float(m_rfFrames) / 5.56F, float(m_rfErrs * 100U) / float(m_rfBits)); + writeJSONRF("lost", float(m_rfFrames) / 5.56F, float(m_rfErrs * 100U) / float(m_rfBits)); } if (m_netState == RS_NET_IDLE) @@ -470,10 +470,10 @@ bool CP25Control::writeModem(unsigned char* data, unsigned int len) if (m_rssi != 0U) { LogMessage("P25, received RF end of voice transmission from %s to %s%u, %.1f seconds, BER: %.1f%%, RSSI: -%u/-%u/-%u dBm", source.c_str(), grp ? "TG " : "", dstId, float(m_rfFrames) / 5.56F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); - writeJSONRF("end", srcId, source, grp, dstId, float(m_rfFrames) / 5.56F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); + writeJSONRF("end", float(m_rfFrames) / 5.56F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); } else { LogMessage("P25, received RF end of voice transmission from %s to %s%u, %.1f seconds, BER: %.1f%%", source.c_str(), grp ? "TG " : "", dstId, float(m_rfFrames) / 5.56F, float(m_rfErrs * 100U) / float(m_rfBits)); - writeJSONRF("end", srcId, source, grp, dstId, float(m_rfFrames) / 5.56F, float(m_rfErrs * 100U) / float(m_rfBits)); + writeJSONRF("end", float(m_rfFrames) / 5.56F, float(m_rfErrs * 100U) / float(m_rfBits)); } m_display->clearP25(); @@ -734,12 +734,8 @@ void CP25Control::clock(unsigned int ms) m_networkWatchdog.clock(ms); if (m_networkWatchdog.hasExpired()) { - unsigned int dstId = m_netData.getDstId(); - unsigned int srcId = m_netData.getSrcId(); - std::string source = m_lookup->find(srcId); - LogMessage("P25, network watchdog has expired, %.1f seconds, %u%% packet loss", float(m_netFrames) / 50.0F, (m_netLost * 100U) / m_netFrames); - writeJSONNet("lost", srcId, source, m_netData.getLCF() == P25_LCF_GROUP, dstId, float(m_netFrames) / 50.0F, float(m_netLost * 100U) / float(m_netFrames)); + writeJSONNet("lost", float(m_netFrames) / 50.0F, float(m_netLost * 100U) / float(m_netFrames)); m_display->clearP25(); m_networkWatchdog.stop(); @@ -1141,7 +1137,7 @@ void CP25Control::createNetTerminator() std::string source = m_lookup->find(srcId); LogMessage("P25, network end of transmission from %s to %s%u, %.1f seconds, %u%% packet loss", source.c_str(), m_netData.getLCF() == P25_LCF_GROUP ? "TG " : "", dstId, float(m_netFrames) / 50.0F, (m_netLost * 100U) / m_netFrames); - writeJSONNet("end", srcId, source, m_netData.getLCF() == P25_LCF_GROUP, dstId, float(m_netFrames) / 50.0F, float(m_netLost * 100U) / float(m_netFrames)); + writeJSONNet("end", float(m_netFrames) / 50.0F, float(m_netLost * 100U) / float(m_netFrames)); m_display->clearP25(); m_netTimeout.stop(); @@ -1228,13 +1224,13 @@ void CP25Control::writeJSONRF(const char* action, unsigned int srcId, const std: WriteJSON("P25", json); } -void CP25Control::writeJSONRF(const char* action, unsigned int srcId, const std::string& srcInfo, bool grp, unsigned int dstId, float duration, float ber) +void CP25Control::writeJSONRF(const char* action, float duration, float ber) { assert(action != NULL); nlohmann::json json; - writeJSON(json, "rf", action, srcId, srcInfo, grp, dstId); + writeJSON(json, "rf", action); json["duration"] = duration; json["ber"] = ber; @@ -1242,13 +1238,13 @@ void CP25Control::writeJSONRF(const char* action, unsigned int srcId, const std: WriteJSON("P25", json); } -void CP25Control::writeJSONRF(const char* action, unsigned int srcId, const std::string& srcInfo, bool grp, unsigned int dstId, float duration, float ber, unsigned char minRSSI, unsigned char maxRSSI, unsigned int aveRSSI) +void CP25Control::writeJSONRF(const char* action, float duration, float ber, unsigned char minRSSI, unsigned char maxRSSI, unsigned int aveRSSI) { assert(action != NULL); nlohmann::json json; - writeJSON(json, "rf", action, srcId, srcInfo, grp, dstId); + writeJSON(json, "rf", action); json["duration"] = duration; json["ber"] = ber; @@ -1274,13 +1270,13 @@ void CP25Control::writeJSONNet(const char* action, unsigned int srcId, const std WriteJSON("P25", json); } -void CP25Control::writeJSONNet(const char* action, unsigned int srcId, const std::string& srcInfo, bool grp, unsigned int dstId, float duration, float loss) +void CP25Control::writeJSONNet(const char* action, float duration, float loss) { assert(action != NULL); nlohmann::json json; - writeJSON(json, "network", action, srcId, srcInfo, grp, dstId); + writeJSON(json, "network", action); json["duration"] = duration; json["loss"] = loss; @@ -1288,6 +1284,16 @@ void CP25Control::writeJSONNet(const char* action, unsigned int srcId, const std WriteJSON("P25", json); } +void CP25Control::writeJSON(nlohmann::json& json, const char* source, const char* action) +{ + assert(source != NULL); + assert(action != NULL); + + json["timestamp"] = CUtils::createTimestamp(); + json["source"] = source; + json["action"] = action; +} + void CP25Control::writeJSON(nlohmann::json& json, const char* source, const char* action, unsigned int srcId, const std::string& srcInfo, bool grp, unsigned int dstId) { assert(source != NULL); diff --git a/P25Control.h b/P25Control.h index 4e7dfb8..d927da3 100644 --- a/P25Control.h +++ b/P25Control.h @@ -122,12 +122,13 @@ private: void closeFile(); void writeJSONRF(const char* action, unsigned int srcId, const std::string& srcInfo, bool grp, unsigned int dstId); - void writeJSONRF(const char* action, unsigned int srcId, const std::string& srcInfo, bool grp, unsigned int dstId, float duration, float ber); - void writeJSONRF(const char* action, unsigned int srcId, const std::string& srcInfo, bool grp, unsigned int dstId, float duration, float ber, unsigned char minRSSI, unsigned char maxRSSI, unsigned int aveRSSI); + void writeJSONRF(const char* action, float duration, float ber); + void writeJSONRF(const char* action, float duration, float ber, unsigned char minRSSI, unsigned char maxRSSI, unsigned int aveRSSI); void writeJSONNet(const char* action, unsigned int srcId, const std::string& srcInfo, bool grp, unsigned int dstId); - void writeJSONNet(const char* action, unsigned int srcId, const std::string& srcInfo, bool grp, unsigned int dstId, float duration, float loss); + void writeJSONNet(const char* action, float duration, float loss); + void writeJSON(nlohmann::json& json, const char* source, const char* action); void writeJSON(nlohmann::json& json, const char* source, const char* action, unsigned int srcId, const std::string& srcInfo, bool grp, unsigned int dstId); }; diff --git a/YSFControl.cpp b/YSFControl.cpp index 874a602..a11b690 100644 --- a/YSFControl.cpp +++ b/YSFControl.cpp @@ -105,15 +105,14 @@ bool CYSFControl::writeModem(unsigned char *data, unsigned int len) return false; unsigned char type = data[0U]; - unsigned char dgid = m_lastFICH.getDGId(); if (type == TAG_LOST && m_rfState == RS_RF_AUDIO) { if (m_rssi != 0U) { LogMessage("YSF, transmission lost from %10.10s to %10.10s, %.1f seconds, BER: %.1f%%, RSSI: -%u/-%u/-%u dBm", m_rfSource, m_rfDest, float(m_rfFrames) / 10.0F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); - writeJSONRF("lost", m_rfSource, dgid, float(m_rfFrames) / 10.0F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); + writeJSONRF("lost", float(m_rfFrames) / 10.0F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); } else { LogMessage("YSF, transmission lost from %10.10s to %10.10s, %.1f seconds, BER: %.1f%%", m_rfSource, m_rfDest, float(m_rfFrames) / 10.0F, float(m_rfErrs * 100U) / float(m_rfBits)); - writeJSONRF("lost", m_rfSource, dgid, float(m_rfFrames) / 10.0F, float(m_rfErrs * 100U) / float(m_rfBits)); + writeJSONRF("lost", float(m_rfFrames) / 10.0F, float(m_rfErrs * 100U) / float(m_rfBits)); } writeEndRF(); return false; @@ -324,10 +323,10 @@ bool CYSFControl::processVWData(bool valid, unsigned char *data) if (m_rssi != 0U) { LogMessage("YSF, received RF end of transmission from %10.10s to DG-ID %u, %.1f seconds, BER: %.1f%%, RSSI: -%u/-%u/-%u dBm", m_rfSource, dgid, float(m_rfFrames) / 10.0F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); - writeJSONRF("end", "voice_vw", m_rfSource, dgid, float(m_rfFrames) / 10.0F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); + writeJSONRF("end", float(m_rfFrames) / 10.0F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); } else { LogMessage("YSF, received RF end of transmission from %10.10s to DG-ID %u, %.1f seconds, BER: %.1f%%", m_rfSource, dgid, float(m_rfFrames) / 10.0F, float(m_rfErrs * 100U) / float(m_rfBits)); - writeJSONRF("end", "voice_vw", m_rfSource, dgid, float(m_rfFrames) / 10.0F, float(m_rfErrs * 100U) / float(m_rfBits)); + writeJSONRF("end", float(m_rfFrames) / 10.0F, float(m_rfErrs * 100U) / float(m_rfBits)); } writeEndRF(); @@ -498,10 +497,10 @@ bool CYSFControl::processDNData(bool valid, unsigned char *data) if (m_rssi != 0U) { LogMessage("YSF, received RF end of transmission from %10.10s to DG-ID %u, %.1f seconds, BER: %.1f%%, RSSI: -%u/-%u/-%u dBm", m_rfSource, dgid, float(m_rfFrames) / 10.0F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); - writeJSONRF("end", "voice_dn", m_rfSource, dgid, float(m_rfFrames) / 10.0F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); + writeJSONRF("end", float(m_rfFrames) / 10.0F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); } else { LogMessage("YSF, received RF end of transmission from %10.10s to DG-ID %u, %.1f seconds, BER: %.1f%%", m_rfSource, dgid, float(m_rfFrames) / 10.0F, float(m_rfErrs * 100U) / float(m_rfBits)); - writeJSONRF("end", "voice_dn", m_rfSource, dgid, float(m_rfFrames) / 10.0F, float(m_rfErrs * 100U) / float(m_rfBits)); + writeJSONRF("end", float(m_rfFrames) / 10.0F, float(m_rfErrs * 100U) / float(m_rfBits)); } writeEndRF(); @@ -803,10 +802,10 @@ bool CYSFControl::processFRData(bool valid, unsigned char *data) if (m_rssi != 0U) { LogMessage("YSF, received RF end of transmission from %10.10s to DG-ID %u, %.1f seconds, RSSI: -%u/-%u/-%u dBm", m_rfSource, dgid, float(m_rfFrames) / 10.0F, m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); - writeJSONRF("end", "data_fr", m_rfSource, dgid, float(m_rfFrames) / 10.0F, 0.0F, m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); + writeJSONRF("end", float(m_rfFrames) / 10.0F, 0.0F, m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); } else { LogMessage("YSF, received RF end of transmission from %10.10s to DG-ID %u, %.1f seconds", m_rfSource, dgid, float(m_rfFrames) / 10.0F); - writeJSONRF("end", "data_fr", m_rfSource, dgid, float(m_rfFrames) / 10.0F, 0.0F); + writeJSONRF("end", float(m_rfFrames) / 10.0F, 0.0F); } writeEndRF(); @@ -1064,7 +1063,7 @@ void CYSFControl::writeNetwork() if (end) { LogMessage("YSF, received network end of transmission from %10.10s to DG-ID %u at %10.10s, %.1f seconds, %u%% packet loss", m_netSource, dgid, data + 4U, float(m_netFrames) / 10.0F, (m_netLost * 100U) / m_netFrames); - writeJSONNet("end", m_netSource, dgid, data + 4U, float(m_netFrames) / 10.0F, (m_netLost * 100U) / m_netFrames); + writeJSONNet("end", float(m_netFrames) / 10.0F, (m_netLost * 100U) / m_netFrames); writeEndNet(); } } @@ -1081,9 +1080,8 @@ void CYSFControl::clock(unsigned int ms) m_networkWatchdog.clock(ms); if (m_networkWatchdog.hasExpired()) { - unsigned char dgid = m_lastFICH.getDGId(); LogMessage("YSF, network watchdog has expired, %.1f seconds, %u%% packet loss", float(m_netFrames) / 10.0F, (m_netLost * 100U) / m_netFrames); - writeJSONNet("lost", m_netSource, dgid, float(m_netFrames) / 10.0F, (m_netLost * 100U) / m_netFrames); + writeJSONNet("lost", float(m_netFrames) / 10.0F, (m_netLost * 100U) / m_netFrames); writeEndNet(); } } @@ -1263,14 +1261,13 @@ void CYSFControl::writeJSONRF(const char* action, const char* mode, const unsign WriteJSON("YSF", json); } -void CYSFControl::writeJSONRF(const char* action, const unsigned char* source, unsigned char dgid, float duration, float ber) +void CYSFControl::writeJSONRF(const char* action, float duration, float ber) { assert(action != NULL); - assert(source != NULL); nlohmann::json json; - writeJSONRF(json, action, source, dgid); + writeJSONRF(json, action); json["duration"] = duration; json["ber"] = ber; @@ -1278,56 +1275,14 @@ void CYSFControl::writeJSONRF(const char* action, const unsigned char* source, u WriteJSON("YSF", json); } -void CYSFControl::writeJSONRF(const char* action, const char* mode, const unsigned char* source, unsigned char dgid, float duration, float ber) +void CYSFControl::writeJSONRF(const char* action, float duration, float ber, unsigned char minRSSI, unsigned char maxRSSI, unsigned int aveRSSI) { assert(action != NULL); - assert(mode != NULL); - assert(source != NULL); nlohmann::json json; - writeJSONRF(json, action, source, dgid); + writeJSONRF(json, action); - json["mode"] = mode; - json["duration"] = duration; - json["ber"] = ber; - - WriteJSON("YSF", json); -} - -void CYSFControl::writeJSONRF(const char* action, const unsigned char* source, unsigned char dgid, float duration, float ber, unsigned char minRSSI, unsigned char maxRSSI, unsigned int aveRSSI) -{ - assert(action != NULL); - assert(source != NULL); - - nlohmann::json json; - - writeJSONRF(json, action, source, dgid); - - json["duration"] = duration; - json["ber"] = ber; - - nlohmann::json rssi; - rssi["min"] = -int(minRSSI); - rssi["max"] = -int(maxRSSI); - rssi["ave"] = -int(aveRSSI); - - json["rssi"] = rssi; - - WriteJSON("YSF", json); -} - -void CYSFControl::writeJSONRF(const char* action, const char* mode, const unsigned char* source, unsigned char dgid, float duration, float ber, unsigned char minRSSI, unsigned char maxRSSI, unsigned int aveRSSI) -{ - assert(action != NULL); - assert(mode != NULL); - assert(source != NULL); - - nlohmann::json json; - - writeJSONRF(json, action, source, dgid); - - json["mode"] = mode; json["duration"] = duration; json["ber"] = ber; @@ -1356,14 +1311,13 @@ void CYSFControl::writeJSONNet(const char* action, const unsigned char* source, WriteJSON("YSF", json); } -void CYSFControl::writeJSONNet(const char* action, const unsigned char* source, unsigned char dgid, float duration, unsigned int loss) +void CYSFControl::writeJSONNet(const char* action, float duration, unsigned int loss) { assert(action != NULL); - assert(source != NULL); nlohmann::json json; - writeJSONNet(json, action, source, dgid); + writeJSONNet(json, action); json["duration"] = duration; json["loss"] = loss; @@ -1371,22 +1325,14 @@ void CYSFControl::writeJSONNet(const char* action, const unsigned char* source, WriteJSON("YSF", json); } -void CYSFControl::writeJSONNet(const char* action, const unsigned char* source, unsigned char dgid, const unsigned char* reflector, float duration, unsigned int loss) +void CYSFControl::writeJSONRF(nlohmann::json& json, const char* action) { assert(action != NULL); - assert(source != NULL); - assert(reflector != NULL); - nlohmann::json json; + json["timestamp"] = CUtils::createTimestamp(); - writeJSONNet(json, action, source, dgid); - - json["reflector"] = convertBuffer(reflector); - - json["duration"] = duration; - json["loss"] = loss; - - WriteJSON("YSF", json); + json["source"] = "rf"; + json["action"] = action; } void CYSFControl::writeJSONRF(nlohmann::json& json, const char* action, const unsigned char* source, unsigned char dgid) @@ -1403,6 +1349,16 @@ void CYSFControl::writeJSONRF(nlohmann::json& json, const char* action, const un json["dg-id"] = int(dgid); } +void CYSFControl::writeJSONNet(nlohmann::json& json, const char* action) +{ + assert(action != NULL); + + json["timestamp"] = CUtils::createTimestamp(); + + json["source"] = "network"; + json["action"] = action; +} + void CYSFControl::writeJSONNet(nlohmann::json& json, const char* action, const unsigned char* source, unsigned char dgid) { assert(action != NULL); diff --git a/YSFControl.h b/YSFControl.h index 1fe92ad..fba0378 100644 --- a/YSFControl.h +++ b/YSFControl.h @@ -103,16 +103,16 @@ private: void writeEndNet(); void writeJSONRF(const char* action, const char* mode, const unsigned char* source, unsigned char dgid); - void writeJSONRF(const char* action, const unsigned char* source, unsigned char dgid, float duration, float ber); - void writeJSONRF(const char* action, const char* mode, const unsigned char* source, unsigned char dgid, float duration, float ber); - void writeJSONRF(const char* action, const unsigned char* source, unsigned char dgid, float duration, float ber, unsigned char minRSSI, unsigned char maxRSSI, unsigned int aveRSSI); - void writeJSONRF(const char* action, const char* mode, const unsigned char* source, unsigned char dgid, float duration, float ber, unsigned char minRSSI, unsigned char maxRSSI, unsigned int aveRSSI); + void writeJSONRF(const char* action, float duration, float ber); + void writeJSONRF(const char* action, float duration, float ber, unsigned char minRSSI, unsigned char maxRSSI, unsigned int aveRSSI); void writeJSONNet(const char* action, const unsigned char* source, unsigned char dgid, const unsigned char* reflector); - void writeJSONNet(const char* action, const unsigned char* source, unsigned char dgid, float duration, unsigned int loss); - void writeJSONNet(const char* action, const unsigned char* source, unsigned char dgid, const unsigned char* reflector, float duration, unsigned int loss); + void writeJSONNet(const char* action, float duration, unsigned int loss); + void writeJSONRF(nlohmann::json& json, const char* action); void writeJSONRF(nlohmann::json& json, const char* action, const unsigned char* source, unsigned char dgid); + + void writeJSONNet(nlohmann::json& json, const char* action); void writeJSONNet(nlohmann::json& json, const char* action, const unsigned char* source, unsigned char dgid); std::string convertBuffer(const unsigned char* buffer) const; diff --git a/schema.json b/schema.json index 4dd9a15..2d10c0a 100644 --- a/schema.json +++ b/schema.json @@ -56,7 +56,7 @@ "max": {"$ref": "#/$defs/rssi"}, "ave": {"$ref": "#/$defs/rssi"} }, - "required": ["timestamp", "source_cs", "source_ext", "destination_cs", "source", "action"] + "required": ["timestamp", "source", "action"] }, "DMR": { @@ -79,7 +79,7 @@ "max": {"$ref": "#/$defs/rssi"}, "ave": {"$ref": "#/$defs/rssi"} }, - "required": ["timestamp", "source_id", "destination_id", "destination_type", "slot", "source", "action"] + "required": ["timestamp", "slot", "source", "action"] }, "YSF": { @@ -99,7 +99,7 @@ "max": {"$ref": "#/$defs/rssi"}, "ave": {"$ref": "#/$defs/rssi"} }, - "required": ["timestamp", "source_cs", "dg-id", "source", "action"] + "required": ["timestamp", "source", "action"] }, "P25": { @@ -119,7 +119,7 @@ "max": {"$ref": "#/$defs/rssi"}, "ave": {"$ref": "#/$defs/rssi"} }, - "required": ["timestamp", "source_id", "destination_id", "destination_type", "source", "action"] + "required": ["timestamp", "source", "action"] }, "NXDN": { @@ -138,7 +138,7 @@ "max": {"$ref": "#/$defs/rssi"}, "ave": {"$ref": "#/$defs/rssi"} }, - "required": ["timestamp", "source_id", "destination_id", "destination_type", "source", "action"] + "required": ["timestamp", "source", "action"] }, "POCSAG": { @@ -190,6 +190,6 @@ "max": {"$ref": "#/$defs/rssi"}, "ave": {"$ref": "#/$defs/rssi"} }, - "required": ["timestamp", "source_cs", "destination_cs", "source", "action", "traffic_type"] + "required": ["timestamp", "source", "action"] } }