cleanup setup utility mode; fix issue with \r\n for interactive console; clamp DMR color code and P25 NAC values properly during host startup;

pull/12/head
Bryan Biedenkapp 4 years ago
parent 338a3344ea
commit a4a7f823d7

@ -1418,6 +1418,13 @@ bool Host::readParams()
}
m_dmrColorCode = rfssConfig["colorCode"].as<uint32_t>(2U);
if (m_dmrColorCode < 0U) { // clamp to 0
m_dmrColorCode = 0U;
}
if (m_dmrColorCode > 15U) { // clamp to 15
m_dmrColorCode = 15U;
}
m_dmrNetId = (uint32_t)::strtoul(rfssConfig["dmrNetId"].as<std::string>("1").c_str(), NULL, 16);
if (m_dmrNetId == 0U) { // clamp to 1
m_dmrNetId = 1U;
@ -1427,6 +1434,13 @@ bool Host::readParams()
}
m_p25NAC = (uint32_t)::strtoul(rfssConfig["nac"].as<std::string>("293").c_str(), NULL, 16);
if (m_p25NAC < 0U) { // clamp to $000
m_p25NAC = 0U;
}
if (m_p25NAC > 0xF7DU) { // clamp to $F7D
m_p25NAC = 0xF7DU;
}
m_p25PatchSuperGroup = (uint32_t)::strtoul(rfssConfig["pSuperGroup"].as<std::string>("FFFF").c_str(), NULL, 16);
m_p25NetId = (uint32_t)::strtoul(rfssConfig["netId"].as<std::string>("BB800").c_str(), NULL, 16);
if (m_p25NetId == 0U) { // clamp to 1

@ -236,6 +236,7 @@ int Console::getLine(char line[], int max, char mask)
if (c == EOF && nch == 0)
return EOF;
::fputc('\r', stdout);
::fputc('\n', stdout);
::fflush(stdout);

@ -53,8 +53,6 @@ HostSetup::HostSetup(const std::string& confFile) :
m_conf(),
m_console(),
m_duplex(true),
m_identity("ABCD123"),
m_callsign("ABCD123"),
m_rxFrequency(0U),
m_txFrequency(0U),
m_channelId(0U),
@ -115,18 +113,18 @@ int HostSetup::run()
LogInfo("General Parameters");
m_identity = systemConf["identity"].as<std::string>();
::LogInfo(" Identity: %s", m_identity.c_str());
std::string identity = systemConf["identity"].as<std::string>();
::LogInfo(" Identity: %s", identity.c_str());
yaml::Node cwId = systemConf["cwId"];
uint32_t time = systemConf["cwId"].as<uint32_t>(10U);
m_callsign = systemConf["cwId"].as<std::string>();
bool cwEnabled = cwId["enable"].as<bool>(false);
uint32_t cwTime = cwId["time"].as<uint32_t>(10U);
std::string callsign = cwId["callsign"].as<std::string>();
LogInfo("CW Id Parameters");
LogInfo(" Time: %u mins", time);
LogInfo(" Callsign: %s", m_callsign.c_str());
m_callsign = cwId["callsign"].as<std::string>();
LogInfo(" Enabled: %s", cwEnabled ? "enabled" : "disabled");
LogInfo(" Time: %u mins", cwTime);
LogInfo(" Callsign: %s", callsign.c_str());
yaml::Node rfssConfig = systemConf["config"];
m_channelId = (uint8_t)rfssConfig["channelId"].as<uint32_t>(0U);
@ -181,7 +179,49 @@ int HostSetup::run()
::fflush(stdout);
m_console.getLine(value, 9, 0);
m_identity = std::string(value);
std::string identity = std::string(value);
if (identity.length() > 0) {
m_conf["system"]["identity"] = identity;
}
writeConfig();
}
break;
case 'C':
{
bool enabled = cwId["enable"].as<bool>(false);
char value[9] = { '\0' };
::fprintf(stdout, "> Callsign ? ");
::fflush(stdout);
m_console.getLine(value, 9, 0);
std::string callsign = std::string(value);
if (callsign.length() > 0) {
m_conf["system"]["cwId"]["callsign"] = callsign;
}
::fprintf(stdout, "> CW Enabled (Y/N) ? ");
::fflush(stdout);
m_console.getLine(value, 2, 0);
if (toupper(value[0]) == 'Y' || toupper(value[0]) == 'N') {
enabled = value[0] == 'Y' ? true : false;
}
m_conf["system"]["cwId"]["enable"] = __BOOL_STR(enabled);
::fprintf(stdout, "> CW Interval (minutes) ? ");
::fflush(stdout);
m_console.getLine(value, 4, 0);
uint32_t time = cwTime;
sscanf(value, "%u", &time);
if (value > 0) {
m_conf["system"]["cwId"]["time"] = __INT_STR(time);
}
writeConfig();
}
break;
@ -333,6 +373,7 @@ void HostSetup::displayHelp()
LogMessage(LOG_SETUP, " Q/q Quit");
LogMessage(LOG_SETUP, "Setup Commands:");
LogMessage(LOG_SETUP, " I Set identity (logical name)");
LogMessage(LOG_SETUP, " C Set callsign and CW configuration");
LogMessage(LOG_SETUP, " i Set logical channel ID");
LogMessage(LOG_SETUP, " c Set logical channel number (by channel number)");
LogMessage(LOG_SETUP, " f Set logical channel number (by Tx frequency)");
@ -384,8 +425,6 @@ bool HostSetup::calculateRxTxFreq()
/// <returns>True, if configuration is written, otherwise false.</returns>
bool HostSetup::writeConfig()
{
m_conf["system"]["identity"] = m_identity;
m_conf["system"]["config"]["channelId"] = __INT_STR(m_channelId);
m_conf["system"]["config"]["channelNo"] = __INT_STR(m_channelNo);
@ -411,6 +450,9 @@ void HostSetup::sleep(uint32_t ms)
/// </summary>
void HostSetup::printStatus()
{
yaml::Node systemConf = m_conf["system"];
std::string identity = systemConf["identity"].as<std::string>();
IdenTable entry = m_idenTable->find(m_channelId);
if (entry.baseFrequency() == 0U) {
::LogError(LOG_HOST, "Channel Id %u has an invalid base frequency.", m_channelId);
@ -418,7 +460,17 @@ void HostSetup::printStatus()
calculateRxTxFreq();
LogMessage(LOG_SETUP, " - Identity: %s", identity.c_str());
LogMessage(LOG_SETUP, " - Channel ID: %u, Channel No: %u", m_channelId, m_channelNo);
LogMessage(LOG_SETUP, " - Base Freq: %uHz, TX Offset: %fMHz, Bandwidth: %fKHz, Channel Spacing: %fKHz", entry.baseFrequency(), entry.txOffsetMhz(), entry.chBandwidthKhz(), entry.chSpaceKhz());
LogMessage(LOG_SETUP, " - Rx Freq: %uHz, Tx Freq: %uHz, Identity: %s, Callsign: %s", m_rxFrequency, m_txFrequency, m_identity.c_str(), m_callsign.c_str());
LogMessage(LOG_SETUP, " - Rx Freq: %uHz, Tx Freq: %uHz", m_rxFrequency, m_txFrequency);
{
yaml::Node cwId = systemConf["cwId"];
bool enabled = cwId["enable"].as<bool>(false);
uint32_t cwTime = cwId["time"].as<uint32_t>(10U);
std::string callsign = cwId["callsign"].as<std::string>();
LogMessage(LOG_SETUP, " - Callsign: %s, CW Interval: %u mins, CW Enabled: %u", callsign.c_str(), cwTime, enabled);
}
}

@ -61,9 +61,6 @@ private:
bool m_duplex;
std::string m_identity;
std::string m_callsign;
uint32_t m_rxFrequency;
uint32_t m_txFrequency;
uint8_t m_channelId;

Loading…
Cancel
Save

Powered by TurnKey Linux.