From 86fb3b6944299f2ec9de66d8fd70d48830f463f6 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 13 Aug 2018 20:39:16 +0200 Subject: [PATCH] New option SendFrameType so one can send transparent data also to the modem serial port. If set, one then has to specify the frame type (0x80 for modem serial of 0x90 for transparent data) as first byte af the message. --- Conf.cpp | 8 ++++++++ Conf.h | 2 ++ MMDVMHost.cpp | 5 ++++- Modem.cpp | 16 ++++++++++++++-- Modem.h | 2 +- 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Conf.cpp b/Conf.cpp index 06e3cb4..8629341 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -114,6 +114,7 @@ m_transparentEnabled(false), m_transparentRemoteAddress(), m_transparentRemotePort(0U), m_transparentLocalPort(0U), +m_transparentSendFrameType(0U), m_umpEnabled(false), m_umpPort(), m_dstarEnabled(false), @@ -464,6 +465,8 @@ bool CConf::read() m_transparentRemotePort = (unsigned int)::atoi(value); else if (::strcmp(key, "LocalPort") == 0) m_transparentLocalPort = (unsigned int)::atoi(value); + else if (::strcmp(key, "SendFrameType") == 0) + m_transparentSendFrameType = (unsigned int)::atoi(value); } else if (section == SECTION_UMP) { if (::strcmp(key, "Enable") == 0) m_umpEnabled = ::atoi(value) == 1; @@ -1054,6 +1057,11 @@ unsigned int CConf::getTransparentLocalPort() const return m_transparentLocalPort; } +unsigned int CConf::getTransparentSendFrameType() const +{ + return m_transparentSendFrameType; +} + bool CConf::getUMPEnabled() const { return m_umpEnabled; diff --git a/Conf.h b/Conf.h index 8243cd6..8b7d16c 100644 --- a/Conf.h +++ b/Conf.h @@ -99,6 +99,7 @@ public: std::string getTransparentRemoteAddress() const; unsigned int getTransparentRemotePort() const; unsigned int getTransparentLocalPort() const; + unsigned int getTransparentSendFrameType() const; // The UMP section bool getUMPEnabled() const; @@ -322,6 +323,7 @@ private: std::string m_transparentRemoteAddress; unsigned int m_transparentRemotePort; unsigned int m_transparentLocalPort; + unsigned int m_transparentSendFrameType; bool m_umpEnabled; std::string m_umpPort; diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index 054d113..54ff394 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -315,15 +315,18 @@ int CMMDVMHost::run() unsigned int transparentPort = 0U; CUDPSocket* transparentSocket = NULL; + unsigned int sendFrameType = 0U; if (m_conf.getTransparentEnabled()) { std::string remoteAddress = m_conf.getTransparentRemoteAddress(); unsigned int remotePort = m_conf.getTransparentRemotePort(); unsigned int localPort = m_conf.getTransparentLocalPort(); + sendFrameType = m_conf.getTransparentSendFrameType(); LogInfo("Transparent Data"); LogInfo(" Remote Address: %s", remoteAddress.c_str()); LogInfo(" Remote Port: %u", remotePort); LogInfo(" Local Port: %u", localPort); + LogInfo(" Send Frame Type: %u", sendFrameType); transparentAddress = CUDPSocket::lookup(remoteAddress); transparentPort = remotePort; @@ -884,7 +887,7 @@ int CMMDVMHost::run() unsigned int port = 0U; len = transparentSocket->read(data, 200U, address, port); if (len > 0U) - m_modem->writeTransparentData(data, len); + m_modem->writeTransparentData(data, len, sendFrameType); } unsigned int ms = stopWatch.elapsed(); diff --git a/Modem.cpp b/Modem.cpp index 06bf916..e15ae7a 100644 --- a/Modem.cpp +++ b/Modem.cpp @@ -1085,7 +1085,7 @@ bool CModem::writePOCSAGData(const unsigned char* data, unsigned int length) return true; } -bool CModem::writeTransparentData(const unsigned char* data, unsigned int length) +bool CModem::writeTransparentData(const unsigned char* data, unsigned int length, unsigned int sendFrameType) { assert(data != NULL); assert(length > 0U); @@ -1096,7 +1096,19 @@ bool CModem::writeTransparentData(const unsigned char* data, unsigned int length buffer[1U] = length + 3U; buffer[2U] = MMDVM_TRANSPARENT; - ::memcpy(buffer + 3U, data, length); + if (sendFrameType>0) { + ::memcpy(buffer + 2U, data, length); + length--; + buffer[1U]--; + //when sendFrameType==1 , only 0x80 and 0x90 (MMDVM_SERIAL and MMDVM_TRANSPARENT) are allowed + // and reverted to default (MMDVM_TRANSPARENT) for any other value + //when >1, frame type is not checked + if (sendFrameType==1) { + if ((buffer[2U] & 0xE0) != 0x80) buffer[2U] = MMDVM_TRANSPARENT; + } + } else { + ::memcpy(buffer + 3U, data, length); + } unsigned char len = length + 3U; m_txTransparentData.addData(&len, 1U); diff --git a/Modem.h b/Modem.h index 52d2780..ef9c415 100644 --- a/Modem.h +++ b/Modem.h @@ -77,7 +77,7 @@ public: bool writeP25Data(const unsigned char* data, unsigned int length); bool writeNXDNData(const unsigned char* data, unsigned int length); bool writePOCSAGData(const unsigned char* data, unsigned int length); - bool writeTransparentData(const unsigned char* data, unsigned int length); + bool writeTransparentData(const unsigned char* data, unsigned int length, unsigned int sendFrameType); bool writeDMRStart(bool tx); bool writeDMRShortLC(const unsigned char* lc);