From a4a7f823d7bbb15cac1cadd8b54f58d752bf50d1 Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Wed, 1 Dec 2021 01:36:06 +0000 Subject: [PATCH] cleanup setup utility mode; fix issue with \r\n for interactive console; clamp DMR color code and P25 NAC values properly during host startup; --- host/Host.cpp | 14 +++++++ host/calibrate/Console.cpp | 1 + host/setup/HostSetup.cpp | 80 +++++++++++++++++++++++++++++++------- host/setup/HostSetup.h | 3 -- 4 files changed, 81 insertions(+), 17 deletions(-) diff --git a/host/Host.cpp b/host/Host.cpp index e9a986f3..a914b514 100644 --- a/host/Host.cpp +++ b/host/Host.cpp @@ -1418,6 +1418,13 @@ bool Host::readParams() } m_dmrColorCode = rfssConfig["colorCode"].as(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("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("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("FFFF").c_str(), NULL, 16); m_p25NetId = (uint32_t)::strtoul(rfssConfig["netId"].as("BB800").c_str(), NULL, 16); if (m_p25NetId == 0U) { // clamp to 1 diff --git a/host/calibrate/Console.cpp b/host/calibrate/Console.cpp index b674e05a..74cd6982 100644 --- a/host/calibrate/Console.cpp +++ b/host/calibrate/Console.cpp @@ -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); diff --git a/host/setup/HostSetup.cpp b/host/setup/HostSetup.cpp index 9d3df641..77af597a 100644 --- a/host/setup/HostSetup.cpp +++ b/host/setup/HostSetup.cpp @@ -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(); - ::LogInfo(" Identity: %s", m_identity.c_str()); + std::string identity = systemConf["identity"].as(); + ::LogInfo(" Identity: %s", identity.c_str()); yaml::Node cwId = systemConf["cwId"]; - uint32_t time = systemConf["cwId"].as(10U); - m_callsign = systemConf["cwId"].as(); + bool cwEnabled = cwId["enable"].as(false); + uint32_t cwTime = cwId["time"].as(10U); + std::string callsign = cwId["callsign"].as(); LogInfo("CW Id Parameters"); - LogInfo(" Time: %u mins", time); - LogInfo(" Callsign: %s", m_callsign.c_str()); - - m_callsign = cwId["callsign"].as(); + 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(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(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() /// True, if configuration is written, otherwise false. 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) /// void HostSetup::printStatus() { + yaml::Node systemConf = m_conf["system"]; + std::string identity = systemConf["identity"].as(); + 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(false); + uint32_t cwTime = cwId["time"].as(10U); + std::string callsign = cwId["callsign"].as(); + + LogMessage(LOG_SETUP, " - Callsign: %s, CW Interval: %u mins, CW Enabled: %u", callsign.c_str(), cwTime, enabled); + } } diff --git a/host/setup/HostSetup.h b/host/setup/HostSetup.h index a9501fb2..d20f57af 100644 --- a/host/setup/HostSetup.h +++ b/host/setup/HostSetup.h @@ -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;