Minor rework of JSON creation.

This commit is contained in:
Jonathan Naylor
2023-01-19 10:08:50 +00:00
parent d6fe3f0cac
commit 0ecf2dec39
6 changed files with 147 additions and 109 deletions

View File

@@ -110,10 +110,10 @@ bool CYSFControl::writeModem(unsigned char *data, unsigned int len)
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", "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("lost", m_rfSource, dgid, 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", "voice_dn", m_rfSource, dgid, 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));
}
writeEndRF();
return false;
@@ -951,7 +951,7 @@ void CYSFControl::writeNetwork()
if (::memcmp(m_netSource, " ", 10U) != 0 && ::memcmp(m_netDest, " ", 10U) != 0) {
m_display->writeFusion((char*)m_netSource, (char*)m_netDest, dgid, "N", (char*)(data + 4U));
LogMessage("YSF, received network data from %10.10s to DG-ID %u at %10.10s", m_netSource, dgid, data + 4U);
writeJSONNet("start", "voice_dn", m_netSource, dgid, data + 4U);
writeJSONNet("start", m_netSource, dgid, data + 4U);
}
m_netTimeoutTimer.start();
@@ -1064,7 +1064,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", "voice_dn", 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);
writeEndNet();
}
}
@@ -1083,7 +1083,7 @@ void CYSFControl::clock(unsigned int 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", "voice_dn", m_netSource, dgid, 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);
writeEndNet();
}
}
@@ -1210,7 +1210,7 @@ void CYSFControl::processNetCallsigns(const unsigned char* data, unsigned char d
if (::memcmp(m_netSource, " ", 10U) != 0 && ::memcmp(m_netDest, " ", 10U) != 0) {
m_display->writeFusion((char*)m_netSource, (char*)m_netDest, dgid, "N", (char*)(data + 4U));
LogMessage("YSF, received network data from %10.10s to DG-ID %u at %10.10s", m_netSource, dgid, data + 4U);
writeJSONNet("start", "voice_dn", m_netSource, dgid, data + 4U);
writeJSONNet("start", m_netSource, dgid, data + 4U);
}
}
}
@@ -1256,7 +1256,24 @@ void CYSFControl::writeJSONRF(const char* action, const char* mode, const unsign
nlohmann::json json;
writeJSONRF(json, action, mode, source, dgid);
writeJSONRF(json, action, source, dgid);
json["mode"] = mode;
WriteJSON("YSF", json);
}
void CYSFControl::writeJSONRF(const char* action, const unsigned char* source, unsigned char dgid, float duration, float ber)
{
assert(action != NULL);
assert(source != NULL);
nlohmann::json json;
writeJSONRF(json, action, source, dgid);
json["duration"] = duration;
json["ber"] = ber;
WriteJSON("YSF", json);
}
@@ -1269,23 +1286,23 @@ void CYSFControl::writeJSONRF(const char* action, const char* mode, const unsign
nlohmann::json json;
writeJSONRF(json, action, mode, source, dgid);
writeJSONRF(json, action, source, dgid);
json["mode"] = mode;
json["duration"] = duration;
json["ber"] = ber;
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)
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(mode != NULL);
assert(source != NULL);
nlohmann::json json;
writeJSONRF(json, action, mode, source, dgid);
writeJSONRF(json, action, source, dgid);
json["duration"] = duration;
json["ber"] = ber;
@@ -1300,31 +1317,53 @@ void CYSFControl::writeJSONRF(const char* action, const char* mode, const unsign
WriteJSON("YSF", json);
}
void CYSFControl::writeJSONNet(const char* action, const char* mode, const unsigned char* source, unsigned char dgid, const unsigned char* reflector)
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;
nlohmann::json rssi;
rssi["min"] = -int(minRSSI);
rssi["max"] = -int(maxRSSI);
rssi["ave"] = -int(aveRSSI);
json["rssi"] = rssi;
WriteJSON("YSF", json);
}
void CYSFControl::writeJSONNet(const char* action, const unsigned char* source, unsigned char dgid, const unsigned char* reflector)
{
assert(action != NULL);
assert(source != NULL);
assert(reflector != NULL);
nlohmann::json json;
writeJSONNet(json, action, mode, source, dgid);
writeJSONNet(json, action, source, dgid);
json["reflector"] = convertBuffer(reflector);
WriteJSON("YSF", json);
}
void CYSFControl::writeJSONNet(const char* action, const char* mode, const unsigned char* source, unsigned char dgid, float duration, unsigned int loss)
void CYSFControl::writeJSONNet(const char* action, const unsigned char* source, unsigned char dgid, float duration, unsigned int loss)
{
assert(action != NULL);
assert(mode != NULL);
assert(source != NULL);
nlohmann::json json;
writeJSONNet(json, action, mode, source, dgid);
writeJSONNet(json, action, source, dgid);
json["duration"] = duration;
json["loss"] = loss;
@@ -1332,16 +1371,15 @@ void CYSFControl::writeJSONNet(const char* action, const char* mode, const unsig
WriteJSON("YSF", json);
}
void CYSFControl::writeJSONNet(const char* action, const char* mode, const unsigned char* source, unsigned char dgid, const unsigned char* reflector, float duration, unsigned int loss)
void CYSFControl::writeJSONNet(const char* action, const unsigned char* source, unsigned char dgid, const unsigned char* reflector, float duration, unsigned int loss)
{
assert(action != NULL);
assert(mode != NULL);
assert(source != NULL);
assert(reflector != NULL);
nlohmann::json json;
writeJSONNet(json, action, mode, source, dgid);
writeJSONNet(json, action, source, dgid);
json["reflector"] = convertBuffer(reflector);
@@ -1351,10 +1389,9 @@ void CYSFControl::writeJSONNet(const char* action, const char* mode, const unsig
WriteJSON("YSF", json);
}
void CYSFControl::writeJSONRF(nlohmann::json& json, const char* action, const char* mode, const unsigned char* source, unsigned char dgid)
void CYSFControl::writeJSONRF(nlohmann::json& json, const char* action, const unsigned char* source, unsigned char dgid)
{
assert(action != NULL);
assert(mode != NULL);
assert(source != NULL);
json["timestamp"] = CUtils::createTimestamp();
@@ -1363,14 +1400,12 @@ void CYSFControl::writeJSONRF(nlohmann::json& json, const char* action, const ch
json["source"] = "rf";
json["action"] = action;
json["mode"] = mode;
json["dg-id"] = int(dgid);
}
void CYSFControl::writeJSONNet(nlohmann::json& json, const char* action, const char* mode, const unsigned char* source, unsigned char dgid)
void CYSFControl::writeJSONNet(nlohmann::json& json, const char* action, const unsigned char* source, unsigned char dgid)
{
assert(action != NULL);
assert(mode != NULL);
assert(source != NULL);
json["timestamp"] = CUtils::createTimestamp();
@@ -1379,7 +1414,6 @@ void CYSFControl::writeJSONNet(nlohmann::json& json, const char* action, const c
json["source"] = "network";
json["action"] = action;
json["mode"] = mode;
json["dg-id"] = int(dgid);
}