From 9796b400c8053c553ee4bae0020c4e5cf4c49235 Mon Sep 17 00:00:00 2001 From: m0vse Date: Sat, 2 May 2020 21:40:55 +0100 Subject: [PATCH] Add enable/disable commands to RemoteCommand --- MMDVMHost.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++++++ MMDVMHost.h | 1 + Modem.cpp | 5 ++++ Modem.h | 1 + RemoteControl.cpp | 28 ++++++++++++++++++++++ RemoteControl.h | 13 ++++++++++ 6 files changed, 109 insertions(+) diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index 2134223..b9449e0 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -1975,6 +1975,58 @@ void CMMDVMHost::remoteControl() if (m_nxdn != NULL) processModeCommand(MODE_NXDN, m_nxdnRFModeHang); break; + case RCD_MODE_FM: + if (m_fmEnabled != false) + processModeCommand(MODE_FM, 0); + break; + case RCD_ENABLE_DSTAR: + if (m_dstar != NULL && m_dstarEnabled==false) + processEnableCommand(m_dstarEnabled, true); + break; + case RCD_ENABLE_DMR: + if (m_dmr != NULL && m_dmrEnabled==false) + processEnableCommand(m_dmrEnabled, true); + break; + case RCD_ENABLE_YSF: + if (m_ysf != NULL && m_ysfEnabled==false) + processEnableCommand(m_ysfEnabled, true); + break; + case RCD_ENABLE_P25: + if (m_p25 != NULL && m_p25Enabled==false) + processEnableCommand(m_p25Enabled, true); + break; + case RCD_ENABLE_NXDN: + if (m_nxdn != NULL && m_nxdnEnabled==false) + processEnableCommand(m_nxdnEnabled, true); + break; + case RCD_ENABLE_FM: + if (m_fmEnabled==false) + processEnableCommand(m_fmEnabled, true); + break; + case RCD_DISABLE_DSTAR: + if (m_dstar != NULL && m_dstarEnabled==true) + processEnableCommand(m_dstarEnabled, false); + break; + case RCD_DISABLE_DMR: + if (m_dmr != NULL && m_dmrEnabled==true) + processEnableCommand(m_dmrEnabled, false); + break; + case RCD_DISABLE_YSF: + if (m_ysf != NULL && m_ysfEnabled==true) + processEnableCommand(m_ysfEnabled, false); + break; + case RCD_DISABLE_P25: + if (m_p25 != NULL && m_p25Enabled==true) + processEnableCommand(m_p25Enabled, false); + break; + case RCD_DISABLE_NXDN: + if (m_nxdn != NULL && m_nxdnEnabled==true) + processEnableCommand(m_nxdnEnabled, false); + break; + case RCD_DISABLE_FM: + if (m_fmEnabled == true) + processEnableCommand(m_fmEnabled, false); + break; case RCD_PAGE: if (m_pocsag != NULL) { unsigned int ric = m_remoteControl->getArgUInt(0U); @@ -2008,3 +2060,12 @@ void CMMDVMHost::processModeCommand(unsigned char mode, unsigned int timeout) setMode(mode); } + +void CMMDVMHost::processEnableCommand(bool& mode, bool enabled) +{ + LogDebug("Setting mode current=%s new=%s",mode ? "true" : "false",enabled ? "true" : "false"); + mode=enabled; + m_modem->setModeParams(m_dstarEnabled, m_dmrEnabled, m_ysfEnabled, m_p25Enabled, m_nxdnEnabled, m_pocsagEnabled, m_fmEnabled); + if (!m_modem->writeConfig()) + LogError("Cannot write Config to MMDVM"); +} diff --git a/MMDVMHost.h b/MMDVMHost.h index de22de2..17d6786 100644 --- a/MMDVMHost.h +++ b/MMDVMHost.h @@ -117,6 +117,7 @@ private: void remoteControl(); void processModeCommand(unsigned char mode, unsigned int timeout); + void processEnableCommand(bool& mode, bool enabled); void setMode(unsigned char mode); diff --git a/Modem.cpp b/Modem.cpp index 729dd59..784aa3e 100644 --- a/Modem.cpp +++ b/Modem.cpp @@ -1491,6 +1491,11 @@ bool CModem::readStatus() return m_serial->write(buffer, 3U) == 3; } +bool CModem::writeConfig() +{ + return setConfig(); +} + bool CModem::setConfig() { assert(m_serial != NULL); diff --git a/Modem.h b/Modem.h index c12466f..0533fa1 100644 --- a/Modem.h +++ b/Modem.h @@ -75,6 +75,7 @@ public: virtual bool hasLockout() const; virtual bool hasError() const; + virtual bool writeConfig(); virtual bool writeDStarData(const unsigned char* data, unsigned int length); virtual bool writeDMRData1(const unsigned char* data, unsigned int length); virtual bool writeDMRData2(const unsigned char* data, unsigned int length); diff --git a/RemoteControl.cpp b/RemoteControl.cpp index afa1473..3a62213 100644 --- a/RemoteControl.cpp +++ b/RemoteControl.cpp @@ -25,6 +25,8 @@ #include const unsigned int SET_MODE_ARGS = 2U; +const unsigned int ENABLE_ARGS = 2U; +const unsigned int DISABLE_ARGS = 2U; const unsigned int PAGE_ARGS = 3U; const unsigned int BUFFER_LENGTH = 100U; @@ -86,6 +88,32 @@ REMOTE_COMMAND CRemoteControl::getCommand() m_command = RCD_MODE_P25; else if (m_args.at(1U) == "nxdn") m_command = RCD_MODE_NXDN; + } else if (m_args.at(0U) == "enable" && m_args.size() >= ENABLE_ARGS) { + if (m_args.at(1U) == "dstar") + m_command = RCD_ENABLE_DSTAR; + else if (m_args.at(1U) == "dmr") + m_command = RCD_ENABLE_DMR; + else if (m_args.at(1U) == "ysf") + m_command = RCD_ENABLE_YSF; + else if (m_args.at(1U) == "p25") + m_command = RCD_ENABLE_P25; + else if (m_args.at(1U) == "nxdn") + m_command = RCD_ENABLE_NXDN; + else if (m_args.at(1U) == "fm") + m_command = RCD_ENABLE_FM; + } else if (m_args.at(0U) == "disable" && m_args.size() >= DISABLE_ARGS) { + if (m_args.at(1U) == "dstar") + m_command = RCD_DISABLE_DSTAR; + else if (m_args.at(1U) == "dmr") + m_command = RCD_DISABLE_DMR; + else if (m_args.at(1U) == "ysf") + m_command = RCD_DISABLE_YSF; + else if (m_args.at(1U) == "p25") + m_command = RCD_DISABLE_P25; + else if (m_args.at(1U) == "nxdn") + m_command = RCD_DISABLE_NXDN; + else if (m_args.at(1U) == "fm") + m_command = RCD_DISABLE_FM; } else if (m_args.at(0U) == "page" && m_args.size() >= PAGE_ARGS) { // Page command is in the form of "page " m_command = RCD_PAGE; diff --git a/RemoteControl.h b/RemoteControl.h index 479987a..31d546d 100644 --- a/RemoteControl.h +++ b/RemoteControl.h @@ -33,6 +33,19 @@ enum REMOTE_COMMAND { RCD_MODE_YSF, RCD_MODE_P25, RCD_MODE_NXDN, + RCD_MODE_FM, + RCD_ENABLE_DSTAR, + RCD_ENABLE_DMR, + RCD_ENABLE_YSF, + RCD_ENABLE_P25, + RCD_ENABLE_NXDN, + RCD_ENABLE_FM, + RCD_DISABLE_DSTAR, + RCD_DISABLE_DMR, + RCD_DISABLE_YSF, + RCD_DISABLE_P25, + RCD_DISABLE_NXDN, + RCD_DISABLE_FM, RCD_PAGE };