From 31043bcb53e86ed673369e67f20d7c8335a0ff41 Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Thu, 4 Aug 2022 22:52:46 -0400 Subject: [PATCH] [EXPERIMENTAL] implement support softpot in the firmware; --- Defines.h | 2 +- config.example.yml | 7 ++++ host/Host.cpp | 19 +++++++++-- host/calibrate/HostCal.cpp | 68 +++++++++++++++++++++++++++++++++++--- host/calibrate/HostCal.h | 7 ++++ modem/Modem.cpp | 58 ++++++++++++++++++++++++++++++-- modem/Modem.h | 9 +++++ 7 files changed, 159 insertions(+), 11 deletions(-) diff --git a/Defines.h b/Defines.h index 719d2528..83430766 100644 --- a/Defines.h +++ b/Defines.h @@ -103,7 +103,7 @@ typedef unsigned long long ulong64_t; #define __PROG_NAME__ "Digital Voice Modem Host" #define __NET_NAME__ "DVM_DMR_P25" #define __EXE_NAME__ "dvmhost" -#define __VER__ "R01.00.00 (" __GIT_VER__ ")" +#define __VER__ "R02.00.69 (" __GIT_VER__ ")" #define __BUILD__ __DATE__ " " __TIME__ #define HOST_SW_API diff --git a/config.example.yml b/config.example.yml index 2d60782d..1e11d306 100644 --- a/config.example.yml +++ b/config.example.yml @@ -150,6 +150,13 @@ system: p25SymLvl1Adj: 0 # Valid values between -128 and 128 nxdnSymLvl3Adj: 0 # Valid values between -128 and 128 nxdnSymLvl1Adj: 0 # Valid values between -128 and 128 + softpot: + rxCoarse: 127 + rxFine: 127 + txCoarse: 127 + txFine: 127 + rssiCoarse: 127 + rssiFine: 127 rxDCOffset: 0 # Valid values between -128 and 128 txDCOffset: 0 # Valid values between -128 and 128 txTuning: 0 # Freq offset for the hotspot, in hz diff --git a/host/Host.cpp b/host/Host.cpp index 3bd7cfde..d5b04029 100644 --- a/host/Host.cpp +++ b/host/Host.cpp @@ -1275,7 +1275,7 @@ int Host::run() } } - /** DMR */ + /** Digial Mobile Radio */ if (dmr != NULL) { if (m_dmrTSCCData && m_dmrCtrlChannel) { if (m_state != STATE_DMR) @@ -1342,7 +1342,7 @@ int Host::run() } } - /** P25 */ + /** Project 25 */ if (p25 != NULL) { if (m_p25CCData) { p25BcastIntervalTimer.clock(ms); @@ -1764,7 +1764,16 @@ bool Host::createModem() int p25SymLevel1Adj = repeaterParams["p25SymLvl1Adj"].as(0); int nxdnSymLevel3Adj = repeaterParams["nxdnSymLvl3Adj"].as(0); int nxdnSymLevel1Adj = repeaterParams["nxdnSymLvl1Adj"].as(0); - + + yaml::Node softpotParams = modemConf["softpot"]; + + uint8_t rxCoarse = (uint8_t)softpotParams["rxCoarse"].as(127U); + uint8_t rxFine = (uint8_t)softpotParams["rxFine"].as(127U); + uint8_t txCoarse = (uint8_t)softpotParams["txCoarse"].as(127U); + uint8_t txFine = (uint8_t)softpotParams["txFine"].as(127U); + uint8_t rssiCoarse = (uint8_t)softpotParams["rssiCoarse"].as(127U); + uint8_t rssiFine = (uint8_t)softpotParams["rssiFine"].as(127U); + float rxLevel = modemConf["rxLevel"].as(50.0F); float cwIdTXLevel = modemConf["cwIdTxLevel"].as(50.0F); float dmrTXLevel = modemConf["dmrTxLevel"].as(50.0F); @@ -1892,6 +1901,9 @@ bool Host::createModem() LogInfo(" TX Tuning Offset: %dhz", txTuning); LogInfo(" RX Effective Frequency: %uhz", m_rxFrequency + rxTuning); LogInfo(" TX Effective Frequency: %uhz", m_txFrequency + txTuning); + LogInfo(" RX Coarse: %u, Fine: %u", rxCoarse, rxFine); + LogInfo(" TX Coarse: %u, Fine: %u", txCoarse, txFine); + LogInfo(" RSSI Coarse: %u, Fine: %u", rssiCoarse, rssiFine); LogInfo(" RF Power Level: %u", rfPower); LogInfo(" RX Level: %.1f%%", rxLevel); LogInfo(" CW Id TX Level: %.1f%%", cwIdTXLevel); @@ -1925,6 +1937,7 @@ bool Host::createModem() m_modem->setDCOffsetParams(txDCOffset, rxDCOffset); m_modem->setRFParams(m_rxFrequency, m_txFrequency, rxTuning, txTuning, rfPower, dmrDiscBWAdj, p25DiscBWAdj, nxdnDiscBWAdj, dmrPostBWAdj, p25PostBWAdj, nxdnPostBWAdj, adfGainMode); + m_modem->setSoftPot(rxCoarse, rxFine, txCoarse, txFine, rssiCoarse, rssiFine); m_modem->setDMRColorCode(m_dmrColorCode); m_modem->setP25NAC(m_p25NAC); #if ENABLE_DFSI_SUPPORT diff --git a/host/calibrate/HostCal.cpp b/host/calibrate/HostCal.cpp index b7058562..60ba56f2 100644 --- a/host/calibrate/HostCal.cpp +++ b/host/calibrate/HostCal.cpp @@ -164,6 +164,12 @@ HostCal::HostCal(const std::string& confFile) : m_dmrSymLevel1Adj(0), m_p25SymLevel3Adj(0), m_p25SymLevel1Adj(0), + m_rxCoarsePot(127U), + m_rxFinePot(127U), + m_txCoarsePot(127U), + m_txFinePot(127U), + m_rssiCoarsePot(127U), + m_rssiFinePot(127U), m_fdmaPreamble(80U), m_dmrRxDelay(7U), m_p25CorrCount(5U), @@ -332,6 +338,15 @@ int HostCal::run() m_nxdnSymLevel3Adj = repeaterParams["nxdnSymLvl3Adj"].as(0); m_nxdnSymLevel1Adj = repeaterParams["nxdnSymLvl1Adj"].as(0); + yaml::Node softpotParams = modemConf["softpot"]; + + m_rxCoarsePot = (uint8_t)softpotParams["rxCoarse"].as(127U); + m_rxFinePot = (uint8_t)softpotParams["rxFine"].as(127U); + m_txCoarsePot = (uint8_t)softpotParams["txCoarse"].as(127U); + m_txFinePot = (uint8_t)softpotParams["txFine"].as(127U); + m_rssiCoarsePot = (uint8_t)softpotParams["rssiCoarse"].as(127U); + m_rssiFinePot = (uint8_t)softpotParams["rssiFine"].as(127U); + m_fdmaPreamble = (uint8_t)modemConf["fdmaPreamble"].as(80U); m_dmrRxDelay = (uint8_t)modemConf["dmrRxDelay"].as(7U); m_p25CorrCount = (uint8_t)modemConf["p25CorrCount"].as(5U); @@ -405,6 +420,9 @@ int HostCal::run() LogInfo(" TX Tuning Offset: %dhz", m_txTuning); LogInfo(" RX Effective Frequency: %uhz", m_rxAdjustedFreq); LogInfo(" TX Effective Frequency: %uhz", m_txAdjustedFreq); + LogInfo(" RX Coarse: %u, Fine: %u", m_rxCoarsePot, m_rxFinePot); + LogInfo(" TX Coarse: %u, Fine: %u", m_txCoarsePot, m_txFinePot); + LogInfo(" RSSI Coarse: %u, Fine: %u", m_rssiCoarsePot, m_rssiFinePot); LogInfo(" RX Level: %.1f%%", m_rxLevel); LogInfo(" TX Level: %.1f%%", m_txLevel); @@ -427,6 +445,7 @@ int HostCal::run() m_modem->setSymbolAdjust(m_dmrSymLevel3Adj, m_dmrSymLevel1Adj, m_p25SymLevel3Adj, m_p25SymLevel1Adj, m_nxdnSymLevel3Adj, m_nxdnSymLevel1Adj); m_modem->setDCOffsetParams(m_txDCOffset, m_rxDCOffset); m_modem->setRFParams(m_rxFrequency, m_txFrequency, m_rxTuning, m_txTuning, 100U, m_dmrDiscBWAdj, m_p25DiscBWAdj, m_nxdnDiscBWAdj, m_dmrPostBWAdj, m_p25PostBWAdj, m_nxdnPostBWAdj, m_adfGainMode); + m_modem->setSoftPot(m_rxCoarsePot, m_rxFinePot, m_txCoarsePot, m_txFinePot, m_rssiCoarsePot, m_rssiFinePot); m_modem->setOpenHandler(MODEM_OC_PORT_HANDLER_BIND(HostCal::portModemOpen, this)); m_modem->setCloseHandler(MODEM_OC_PORT_HANDLER_BIND(HostCal::portModemClose, this)); @@ -2236,8 +2255,8 @@ bool HostCal::writeConfig() /// True, if configuration is written, otherwise false. bool HostCal::writeConfig(uint8_t modeOverride) { - uint8_t buffer[20U]; - ::memset(buffer, 0x00U, 20U); + uint8_t buffer[25U]; + ::memset(buffer, 0x00U, 25U); buffer[0U] = DVM_FRAME_START; buffer[1U] = 17U; @@ -2306,12 +2325,19 @@ bool HostCal::writeConfig(uint8_t modeOverride) // are we on a protocol version 3 firmware? if (m_modem->getVersion() >= 3U) { - buffer[1U] = 18U; + buffer[1U] = 24U; if (m_nxdnEnabled) buffer[4U] |= 0x10U; buffer[18U] = (uint8_t)(m_txLevel * 2.55F + 0.5F); + + buffer[19U] = m_rxCoarsePot; + buffer[20U] = m_rxFinePot; + buffer[21U] = m_txCoarsePot; + buffer[22U] = m_txFinePot; + buffer[23U] = m_rssiCoarsePot; + buffer[24U] = m_rssiFinePot; } int ret = m_modem->write(buffer, buffer[1U]); @@ -2560,6 +2586,24 @@ void HostCal::processFlashConfig(const uint8_t *buffer) m_conf["system"]["modem"]["rxTuning"] = __INT_STR(m_rxTuning); m_rxAdjustedFreq = m_rxFrequency + m_rxTuning; + // are we on a protocol version 3 firmware? + if (m_modem->getVersion() >= 3U) { + m_rxCoarsePot = buffer[43U]; + m_conf["system"]["modem"]["softpot"]["rxCoarse"] = __INT_STR(m_rxCoarsePot); + m_rxFinePot = buffer[44U]; + m_conf["system"]["modem"]["softpot"]["rxFine"] = __INT_STR(m_rxFinePot); + + m_txCoarsePot = buffer[45U]; + m_conf["system"]["modem"]["softpot"]["txCoarse"] = __INT_STR(m_txCoarsePot); + m_txFinePot = buffer[46U]; + m_conf["system"]["modem"]["softpot"]["txFine"] = __INT_STR(m_txFinePot); + + m_rssiCoarsePot = buffer[47U]; + m_conf["system"]["modem"]["softpot"]["rssiCoarse"] = __INT_STR(m_rssiCoarsePot); + m_rssiFinePot = buffer[48U]; + m_conf["system"]["modem"]["softpot"]["rssiFine"] = __INT_STR(m_rssiFinePot); + } + writeRFParams(); sleep(500); } @@ -2671,17 +2715,33 @@ bool HostCal::writeFlash() buffer[42U] = (uint8_t)(m_nxdnSymLevel1Adj + 128); } + // are we on a protocol version 3 firmware? + if (m_modem->getVersion() >= 3U) { + buffer[43U] = m_rxCoarsePot; + buffer[44U] = m_rxFinePot; + + buffer[45U] = m_txCoarsePot; + buffer[46U] = m_txFinePot; + + buffer[47U] = m_rssiCoarsePot; + buffer[48U] = m_rssiFinePot; + } + // software signature std::string software; software.append(__NET_NAME__ " " __VER__ " (built " __BUILD__ ")"); for (uint8_t i = 0; i < software.length(); i++) { - buffer[192U + i] = software[i]; + buffer[176U + i] = software[i]; } // configuration version buffer[DVM_CONF_AREA_LEN] = DVM_CONF_AREA_VER; edac::CRC::addCCITT162(buffer + 3U, DVM_CONF_AREA_LEN); +#if DEBUG_MODEM_CAL + Utils::dump(1U, "HostCal::writeFlash(), Written", buffer, 249U); +#endif + int ret = m_modem->write(buffer, 249U); if (ret <= 0) return false; diff --git a/host/calibrate/HostCal.h b/host/calibrate/HostCal.h index 874c4370..82bc6d84 100644 --- a/host/calibrate/HostCal.h +++ b/host/calibrate/HostCal.h @@ -104,6 +104,13 @@ private: int m_nxdnSymLevel3Adj; // dedicated modem - +3/-3 NXDN symbol adjustment int m_nxdnSymLevel1Adj; // dedicated modem - +1/-1 NXDN symbol adjustment + uint8_t m_rxCoarsePot; // dedicated modem - with softpot + uint8_t m_rxFinePot; // dedicated modem - with softpot + uint8_t m_txCoarsePot; // dedicated modem - with softpot + uint8_t m_txFinePot; // dedicated modem - with softpot + uint8_t m_rssiCoarsePot; // dedicated modem - with softpot + uint8_t m_rssiFinePot; // dedicated modem - with softpot + uint8_t m_fdmaPreamble; uint8_t m_dmrRxDelay; uint8_t m_p25CorrCount; diff --git a/modem/Modem.cpp b/modem/Modem.cpp index b55b8015..85c24ae0 100644 --- a/modem/Modem.cpp +++ b/modem/Modem.cpp @@ -157,6 +157,12 @@ Modem::Modem(port::IModemPort* port, bool duplex, bool rxInvert, bool txInvert, m_p25SymLevel1Adj(0), m_nxdnSymLevel3Adj(0), m_nxdnSymLevel1Adj(0), + m_rxCoarsePot(127U), + m_rxFinePot(127U), + m_txCoarsePot(127U), + m_txFinePot(127U), + m_rssiCoarsePot(127U), + m_rssiFinePot(127U), m_adcOverFlowCount(0U), m_dacOverFlowCount(0U), m_modemState(STATE_IDLE), @@ -330,6 +336,27 @@ void Modem::setRFParams(uint32_t rxFreq, uint32_t txFreq, int rxTuning, int txTu m_nxdnPostBWAdj = nxdnPostBWAdj; } +/// +/// Sets the softpot parameters. +/// +/// +/// +/// +/// +/// +/// +void Modem::setSoftPot(uint8_t rxCoarse, uint8_t rxFine, uint8_t txCoarse, uint8_t txFine, uint8_t rssiCoarse, uint8_t rssiFine) +{ + m_rxCoarsePot = rxCoarse; + m_rxFinePot = rxFine; + + m_txCoarsePot = txCoarse; + m_txFinePot = txFine; + + m_rssiCoarsePot = rssiCoarse; + m_rssiFinePot = rssiFine; +} + /// /// Sets the DMR color code. /// @@ -1739,8 +1766,8 @@ bool Modem::getStatus() /// bool Modem::writeConfig() { - uint8_t buffer[20U]; - ::memset(buffer, 0x00U, 20U); + uint8_t buffer[25U]; + ::memset(buffer, 0x00U, 25U); buffer[0U] = DVM_FRAME_START; buffer[1U] = 17U; @@ -1799,12 +1826,19 @@ bool Modem::writeConfig() // are we on a protocol version 3 firmware? if (m_protoVer >= 3U) { - buffer[1U] = 18U; + buffer[1U] = 24U; if (m_nxdnEnabled) buffer[4U] |= 0x10U; buffer[18U] = (uint8_t)(m_nxdnTXLevel * 2.55F + 0.5F); + + buffer[19U] = m_rxCoarsePot; + buffer[20U] = m_rxFinePot; + buffer[21U] = m_txCoarsePot; + buffer[22U] = m_txFinePot; + buffer[23U] = m_rssiCoarsePot; + buffer[24U] = m_rssiFinePot; } #if DEBUG_MODEM @@ -2141,6 +2175,24 @@ void Modem::processFlashConfig(const uint8_t *buffer) int nxdnSymLevel1Adj = int(buffer[42U]) - 128; FLASH_VALUE_CHECK(m_nxdnSymLevel1Adj, nxdnSymLevel1Adj, 0, "nxdnSymLevel1Adj"); } + + // are we on a protocol version 3 firmware? + if (m_protoVer >= 3U) { + uint8_t rxCoarse = buffer[43U]; + FLASH_VALUE_CHECK(m_rxCoarsePot, rxCoarse, 7U, "rxCoarse"); + uint8_t rxFine = buffer[44U]; + FLASH_VALUE_CHECK(m_rxFinePot, rxFine, 7U, "rxFine"); + + uint8_t txCoarse = buffer[45U]; + FLASH_VALUE_CHECK(m_txCoarsePot, txCoarse, 7U, "txCoarse"); + uint8_t txFine = buffer[46U]; + FLASH_VALUE_CHECK(m_txFinePot, txFine, 7U, "txFine"); + + uint8_t rssiCoarse = buffer[47U]; + FLASH_VALUE_CHECK(m_rssiCoarsePot, rssiCoarse, 7U, "rssiCoarse"); + uint8_t rssiFine = buffer[48U]; + FLASH_VALUE_CHECK(m_rssiFinePot, rssiFine, 7U, "rssiFine"); + } } /// diff --git a/modem/Modem.h b/modem/Modem.h index b5e75caa..15f3665c 100644 --- a/modem/Modem.h +++ b/modem/Modem.h @@ -231,6 +231,8 @@ namespace modem /// Sets the RF parameters. void setRFParams(uint32_t rxFreq, uint32_t txFreq, int rxTuning, int txTuning, uint8_t rfPower, int8_t dmrDiscBWAdj, int8_t p25DiscBWAdj, int8_t nxdnDiscBWAdj, int8_t dmrPostBWAdj, int8_t p25PostBWAdj, int8_t nxdnPostBWAdj, ADF_GAIN_MODE gainMode); + /// Sets the softpot parameters. + void setSoftPot(uint8_t rxCoarse, uint8_t rxFine, uint8_t txCoarse, uint8_t txFine, uint8_t rssiCoarse, uint8_t rssiFine); /// Sets the DMR color code. void setDMRColorCode(uint32_t colorCode); /// Sets the P25 NAC. @@ -402,6 +404,13 @@ namespace modem int m_nxdnSymLevel3Adj; // dedicated modem - +3/-3 NXDN symbol adjustment int m_nxdnSymLevel1Adj; // dedicated modem - +1/-1 NXDN symbol adjustment + uint8_t m_rxCoarsePot; // dedicated modem - with softpot + uint8_t m_rxFinePot; // dedicated modem - with softpot + uint8_t m_txCoarsePot; // dedicated modem - with softpot + uint8_t m_txFinePot; // dedicated modem - with softpot + uint8_t m_rssiCoarsePot; // dedicated modem - with softpot + uint8_t m_rssiFinePot; // dedicated modem - with softpot + uint32_t m_adcOverFlowCount; // dedicated modem - ADC overflow count uint32_t m_dacOverFlowCount; // dedicated modem - DAC overflow count