convert RPTC to JSON;

Bryan Biedenkapp 4 years ago
parent 1a69a63626
commit b465829173

@ -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<std::string>(m_identity); // Identity
config["rxFrequency"].set<uint32_t>(m_rxFrequency); // Rx Frequency
config["txFrequency"].set<uint32_t>(m_txFrequency); // Tx Frequency
char longitude[11U];
::sprintf(longitude, "%09f", m_longitude);
// system info
json::object sysInfo = json::object();
sysInfo["latitude"].set<float>(m_latitude); // Latitude
sysInfo["longitude"].set<float>(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<int>(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<std::string>(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<int>(power); // Tx Power
config["info"].set<json::object>(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<float>(m_txOffsetMhz); // Tx Offset (Mhz)
channel["chBandwidthKhz"].set<float>(m_chBandwidthKhz); // Ch. Bandwidth (khz)
channel["channelId"].set<uint8_t>(m_channelId); // Channel ID
channel["channelNo"].set<uint32_t>(m_channelNo); // Channel No
config["channel"].set<json::object>(channel);
if (m_debug)
Utils::dump(1U, "Network Transmitted, Configuration", (uint8_t*)buffer, 176U);
// RCON
json::object rcon = json::object();
rcon["password"].set<std::string>(m_rconPassword); // RCON Password
rcon["port"].set<uint16_t>(m_rconPort); // RCON Port
config["rcon"].set<json::object>(rcon);
config["software"].set<std::string>(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);
}
/// <summary>

Loading…
Cancel
Save

Powered by TurnKey Linux.