From b465829173570e7744a3468aa9d5bc23144ef596 Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Tue, 22 Feb 2022 17:56:35 -0500 Subject: [PATCH] convert RPTC to JSON; --- network/Network.cpp | 77 +++++++++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 27 deletions(-) diff --git a/network/Network.cpp b/network/Network.cpp index b76a3c5d..0abae3d6 100644 --- a/network/Network.cpp +++ b/network/Network.cpp @@ -31,6 +31,7 @@ #include "Defines.h" #include "edac/SHA256.h" #include "network/Network.h" +#include "network/json/json.h" #include "Log.h" #include "StopWatch.h" #include "Utils.h" @@ -493,48 +494,70 @@ bool Network::writeAuthorisation() bool Network::writeConfig() { const char* software = "DVM_DMR_P25"; - char buffer[176U]; - ::memcpy(buffer + 0U, TAG_REPEATER_CONFIG, 4U); - __SET_UINT32(m_id, buffer, 4U); + json::object config = json::object(); - char latitude[11U]; - ::sprintf(latitude, "%08f", m_latitude); + // identity and frequency + config["identity"].set(m_identity); // Identity + config["rxFrequency"].set(m_rxFrequency); // Rx Frequency + config["txFrequency"].set(m_txFrequency); // Tx Frequency - char longitude[11U]; - ::sprintf(longitude, "%09f", m_longitude); + // system info + json::object sysInfo = json::object(); + sysInfo["latitude"].set(m_latitude); // Latitude + sysInfo["longitude"].set(m_longitude); // Longitude - char chBandwidthKhz[6U]; - ::sprintf(chBandwidthKhz, "%02.02f", m_chBandwidthKhz); + int height = m_height; + if (m_height > 999) + height = 999; - char txOffsetMhz[6U]; - ::sprintf(txOffsetMhz, "%02.02f", m_txOffsetMhz); + sysInfo["height"].set(height); // Height - char channelId[4U]; - ::sprintf(channelId, "%d", m_channelId); + // clamp location to 20 characters + if (m_location.length() > 20) { + std::string location = m_location; + m_location = location.substr(0, 20); + } - char channelNo[5U]; - ::sprintf(channelNo, "%d", m_channelNo); + sysInfo["location"].set(m_location); // Location int power = m_power; if (m_power > 99U) power = 99U; - int height = m_height; - if (m_height > 999) - height = 999; + sysInfo["power"].set(power); // Tx Power + config["info"].set(sysInfo); - // IdntRX TX RsrvLatLngHghtLoctnRsrvTxOfChBnChIdChNoPowrSftwrRsrvRcnPsRcPt - ::sprintf(buffer + 8U, "%-8s%09u%09u%10s%8s%9s%03d%-20s%10s%-5s%-5s%-3s%-4s%02d%-16s%10s%-20s%05d", - m_identity.c_str(), m_rxFrequency, m_txFrequency, - "", latitude, longitude, height, m_location.c_str(), - "", txOffsetMhz, chBandwidthKhz, channelId, channelNo, power, software, - "", m_rconPassword.c_str(), m_rconPort); + // channel data + json::object channel = json::object(); + channel["txOffsetMhz"].set(m_txOffsetMhz); // Tx Offset (Mhz) + channel["chBandwidthKhz"].set(m_chBandwidthKhz); // Ch. Bandwidth (khz) + channel["channelId"].set(m_channelId); // Channel ID + channel["channelNo"].set(m_channelNo); // Channel No + config["channel"].set(channel); - if (m_debug) - Utils::dump(1U, "Network Transmitted, Configuration", (uint8_t*)buffer, 176U); + // RCON + json::object rcon = json::object(); + rcon["password"].set(m_rconPassword); // RCON Password + rcon["port"].set(m_rconPort); // RCON Port + config["rcon"].set(rcon); + + config["software"].set(std::string(software)); // Software ID + + json::value v = json::value(config); + std::string json = v.serialize(); + + char buffer[json.length() + 8U]; + + ::memcpy(buffer + 0U, TAG_REPEATER_CONFIG, 4U); + __SET_UINT32(m_id, buffer, 4U); + ::sprintf(buffer + 8U, "%s", json.c_str()); + + if (m_debug) { + Utils::dump(1U, "Network Transmitted, Configuration", (uint8_t*)buffer, json.length() + 8U); + } - return write((uint8_t*)buffer, 176U); + return write((uint8_t*)buffer, json.length() + 8U); } ///