From d778367583aab1497e25afca9b3c2f890d2eeb17 Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Wed, 1 Dec 2021 16:18:47 +0000 Subject: [PATCH] make MSVS compiler happy about W4834, we don't care about [[nodiscard]]; fix bad handling of argument strings and buffer deletions in RemoteControl; implement support for DMR CC dedicated and DMR CC broadcast RCON commands; fix converting from float to uint32_t, we know about the precision loss; --- host/setup/HostSetup.cpp | 4 ++-- lookups/LookupTable.h | 6 +++++- network/RemoteControl.cpp | 45 ++++++++++++++++++++++++++++++++++----- 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/host/setup/HostSetup.cpp b/host/setup/HostSetup.cpp index 77af597a..1a53852b 100644 --- a/host/setup/HostSetup.cpp +++ b/host/setup/HostSetup.cpp @@ -297,13 +297,13 @@ int HostSetup::run() uint32_t prevTxFrequency = m_txFrequency; m_txFrequency = txFrequency; uint32_t prevRxFrequency = m_rxFrequency; - m_rxFrequency = m_txFrequency + (entry.txOffsetMhz() * 1000000); + m_rxFrequency = m_txFrequency + (uint32_t)(entry.txOffsetMhz() * 1000000); float spaceHz = entry.chSpaceKhz() * 1000; uint32_t rootFreq = m_txFrequency - entry.baseFrequency(); uint8_t prevChannelNo = m_channelNo; - m_channelNo = rootFreq / spaceHz; + m_channelNo = (uint32_t)(rootFreq / spaceHz); if (m_channelNo < 0 || m_channelNo > 4096) { ::LogError(LOG_SETUP, "Channel No %u is invalid.", m_channelNo); diff --git a/lookups/LookupTable.h b/lookups/LookupTable.h index c4c15709..dd213637 100644 --- a/lookups/LookupTable.h +++ b/lookups/LookupTable.h @@ -11,7 +11,7 @@ // Licensed under the GPLv2 License (https://opensource.org/licenses/GPL-2.0) // /* -* Copyright (C) 2018-2019 by Bryan Biedenkapp N2PLL +* Copyright (C) 2018-2019,2021 by Bryan Biedenkapp N2PLL * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,6 +30,10 @@ #if !defined(__LOOKUP_TABLE_H__) #define __LOOKUP_TABLE_H__ +#if _MSC_VER > 1910 +#pragma warning(disable : 4834) // [[nodiscard]] warning -- we don't care about this here +#endif + #include "Defines.h" #include "Log.h" #include "Thread.h" diff --git a/network/RemoteControl.cpp b/network/RemoteControl.cpp index 39b4161a..6dfb9033 100644 --- a/network/RemoteControl.cpp +++ b/network/RemoteControl.cpp @@ -12,7 +12,7 @@ // /* * Copyright (C) 2019 by Jonathan Naylor G4KLX -* Copyright (C) 2019 by Bryan Biedenkapp N2PLL +* Copyright (C) 2019,2021 by Bryan Biedenkapp N2PLL * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -86,6 +86,9 @@ using namespace modem; #define RCD_P25_RELEASE_GRANTS_CMD "p25-rel-grnts" #define RCD_P25_RELEASE_AFFS_CMD "p25-rel-affs" +#define RCD_DMR_CC_DEDICATED_CMD "dmr-cc-dedicated" +#define RCD_DMR_CC_BCAST_CMD "dmr-cc-bcast" + #define RCD_P25_CC_DEDICATED_CMD "p25-cc-dedicated" #define RCD_P25_CC_BCAST_CMD "p25-cc-bcast" @@ -316,7 +319,8 @@ void RemoteControl::process(Host* host, dmr::Control* dmr, p25::Control* p25) // Command is in the form of: "dmrd-mdm-inj if (dmr != NULL) { uint8_t slot = getArgUInt32(args, 0U); - const char* fileName = getArgString(args, 1U).c_str(); + std::string argString = getArgString(args, 1U); + const char* fileName = argString.c_str(); if (fileName != NULL) { FILE* file = ::fopen(fileName, "r"); if (file != NULL) { @@ -365,7 +369,7 @@ void RemoteControl::process(Host* host, dmr::Control* dmr, p25::Control* p25) LogError(LOG_RCON, CMD_FAILED_STR "DMR failed to open DMR data!"); } - delete buffer; + delete[] buffer; } ::fclose(file); @@ -379,7 +383,8 @@ void RemoteControl::process(Host* host, dmr::Control* dmr, p25::Control* p25) else if (rcom == RCD_P25D_MDM_INJ_CMD && argCnt >= 1U) { // Command is in the form of: "p25d-mdm-inj if (p25 != NULL) { - const char* fileName = getArgString(args, 0U).c_str(); + std::string argString = getArgString(args, 0U); + const char* fileName = argString.c_str(); if (fileName != NULL) { FILE* file = ::fopen(fileName, "r"); if (file != NULL) { @@ -420,7 +425,7 @@ void RemoteControl::process(Host* host, dmr::Control* dmr, p25::Control* p25) LogError(LOG_RCON, CMD_FAILED_STR "P25 failed to open P25 data!"); } - delete buffer; + delete[] buffer; } ::fclose(file); @@ -672,6 +677,36 @@ void RemoteControl::process(Host* host, dmr::Control* dmr, p25::Control* p25) LogError(LOG_RCON, CMD_FAILED_STR "P25 mode is not enabled!"); } } + else if (rcom == RCD_DMR_CC_DEDICATED_CMD) { + // Command is in the form of: "dmr-cc-dedicated" + if (dmr != NULL) { + if (host->m_dmrTSCCData) { + if (p25 != NULL) { + LogError(LOG_RCON, CMD_FAILED_STR "Can't enable DMR control channel while P25 is enabled!"); + } + else { + host->m_dmrCtrlChannel = !host->m_dmrCtrlChannel; + LogInfoEx(LOG_RCON, "DMR CC is %s", host->m_p25CtrlChannel ? "enabled" : "disabled"); + } + } + else { + LogError(LOG_RCON, CMD_FAILED_STR "DMR control data is not enabled!"); + } + } + else { + LogError(LOG_RCON, CMD_FAILED_STR "DMR mode is not enabled!"); + } + } + else if (rcom == RCD_DMR_CC_BCAST_CMD) { + // Command is in the form of: "dmr-cc-bcast" + if (dmr != NULL) { + host->m_dmrTSCCData = !host->m_dmrTSCCData; + LogInfoEx(LOG_RCON, "DMR CC broadcast is %s", host->m_dmrTSCCData ? "enabled" : "disabled"); + } + else { + LogError(LOG_RCON, CMD_FAILED_STR "DMR mode is not enabled!"); + } + } else if (rcom == RCD_P25_CC_DEDICATED_CMD) { // Command is in the form of: "p25-cc-dedicated" if (p25 != NULL) {