Skip to content

Commit

Permalink
Add modem transparent modem data mode. Not used on the MMDVM currently.
Browse files Browse the repository at this point in the history
  • Loading branch information
g4klx committed Mar 22, 2018
1 parent 0ce2c9a commit 52ec2f2
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ enum SECTION {
SECTION_DMRID_LOOKUP,
SECTION_NXDNID_LOOKUP,
SECTION_MODEM,
SECTION_TRANSPARENT,
SECTION_UMP,
SECTION_DSTAR,
SECTION_DMR,
Expand Down Expand Up @@ -104,6 +105,10 @@ m_modemNXDNTXLevel(50.0F),
m_modemRSSIMappingFile(),
m_modemTrace(false),
m_modemDebug(false),
m_transparentEnabled(false),
m_transparentRemoteAddress(),
m_transparentRemotePort(0U),
m_transparentLocalPort(0U),
m_umpEnabled(false),
m_umpPort(),
m_dstarEnabled(false),
Expand Down Expand Up @@ -253,6 +258,8 @@ bool CConf::read()
section = SECTION_NXDNID_LOOKUP;
else if (::strncmp(buffer, "[Modem]", 7U) == 0)
section = SECTION_MODEM;
else if (::strncmp(buffer, "[Transparent Data]", 18U) == 0)
section = SECTION_TRANSPARENT;
else if (::strncmp(buffer, "[UMP]", 5U) == 0)
section = SECTION_UMP;
else if (::strncmp(buffer, "[D-Star]", 8U) == 0)
Expand Down Expand Up @@ -423,6 +430,15 @@ bool CConf::read()
m_modemTrace = ::atoi(value) == 1;
else if (::strcmp(key, "Debug") == 0)
m_modemDebug = ::atoi(value) == 1;
} else if (section == SECTION_TRANSPARENT) {
if (::strcmp(key, "Enable") == 0)
m_transparentEnabled = ::atoi(value) == 1;
else if (::strcmp(key, "RemoteAddress") == 0)
m_transparentRemoteAddress = value;
else if (::strcmp(key, "RemotePort") == 0)
m_transparentRemotePort = (unsigned int)::atoi(value);
else if (::strcmp(key, "LocalPort") == 0)
m_transparentLocalPort = (unsigned int)::atoi(value);
} else if (section == SECTION_UMP) {
if (::strcmp(key, "Enable") == 0)
m_umpEnabled = ::atoi(value) == 1;
Expand Down Expand Up @@ -956,6 +972,26 @@ bool CConf::getModemDebug() const
return m_modemDebug;
}

bool CConf::getTransparentEnabled() const
{
return m_transparentEnabled;
}

std::string CConf::getTransparentRemoteAddress() const
{
return m_transparentRemoteAddress;
}

unsigned int CConf::getTransparentRemotePort() const
{
return m_transparentRemotePort;
}

unsigned int CConf::getTransparentLocalPort() const
{
return m_transparentLocalPort;
}

bool CConf::getUMPEnabled() const
{
return m_umpEnabled;
Expand Down
11 changes: 11 additions & 0 deletions Conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ class CConf
bool getModemTrace() const;
bool getModemDebug() const;

// The Transparent Data section
bool getTransparentEnabled() const;
std::string getTransparentRemoteAddress() const;
unsigned int getTransparentRemotePort() const;
unsigned int getTransparentLocalPort() const;

// The UMP section
bool getUMPEnabled() const;
std::string getUMPPort() const;
Expand Down Expand Up @@ -292,6 +298,11 @@ class CConf
bool m_modemTrace;
bool m_modemDebug;

bool m_transparentEnabled;
std::string m_transparentRemoteAddress;
unsigned int m_transparentRemotePort;
unsigned int m_transparentLocalPort;

bool m_umpEnabled;
std::string m_umpPort;

Expand Down
6 changes: 6 additions & 0 deletions MMDVM.ini
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ RSSIMappingFile=RSSI.dat
Trace=0
Debug=0

[Transparent Data]
Enable=0
RemoteAddress=127.0.0.1
RemotePort=40094
LocalPort=40095

[UMP]
Enable=0
# Port=\\.\COM4
Expand Down
43 changes: 43 additions & 0 deletions MMDVMHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,32 @@ int CMMDVMHost::run()
return 1;
}

in_addr transparentAddress;
unsigned int transparentPort = 0U;
CUDPSocket* transparentSocket = NULL;

if (m_conf.getTransparentEnabled()) {
std::string remoteAddress = m_conf.getTransparentRemoteAddress();
unsigned int remotePort = m_conf.getTransparentRemotePort();
unsigned int localPort = m_conf.getTransparentLocalPort();

LogInfo("Transparent Data");
LogInfo(" Remote Address: %s", remoteAddress.c_str());
LogInfo(" Remote Port: %u", remotePort);
LogInfo(" Local Port: %u", localPort);

transparentAddress = CUDPSocket::lookup(remoteAddress);
transparentPort = remotePort;

transparentSocket = new CUDPSocket(localPort);
ret = transparentSocket->open();
if (!ret) {
LogWarning("Could not open the Transparent data socket, disabling");
delete transparentSocket;
transparentSocket = NULL;
}
}

if (m_conf.getCWIdEnabled()) {
unsigned int time = m_conf.getCWIdTime();
m_cwCallsign = m_conf.getCWIdCallsign();
Expand Down Expand Up @@ -686,6 +712,10 @@ int CMMDVMHost::run()
}
}

len = m_modem->readTransparentData(data);
if (transparentSocket != NULL && len > 0U)
transparentSocket->write(data, len, transparentAddress, transparentPort);

if (m_modeTimer.isRunning() && m_modeTimer.hasExpired())
setMode(MODE_IDLE);

Expand Down Expand Up @@ -811,6 +841,14 @@ int CMMDVMHost::run()
}
}

if (transparentSocket != NULL) {
in_addr address;
unsigned int port = 0U;
len = transparentSocket->read(data, 200U, address, port);
if (len > 0U)
m_modem->writeTransparentData(data, len);
}

unsigned int ms = stopWatch.elapsed();
stopWatch.start();

Expand Down Expand Up @@ -925,6 +963,11 @@ int CMMDVMHost::run()
delete m_nxdnNetwork;
}

if (transparentSocket != NULL) {
transparentSocket->close();
delete transparentSocket;
}

delete dstar;
delete dmr;
delete ysf;
Expand Down
62 changes: 62 additions & 0 deletions Modem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ const unsigned char MMDVM_NAK = 0x7FU;

const unsigned char MMDVM_SERIAL = 0x80U;

const unsigned char MMDVM_TRANSPARENT = 0x90U;

const unsigned char MMDVM_DEBUG1 = 0xF1U;
const unsigned char MMDVM_DEBUG2 = 0xF2U;
const unsigned char MMDVM_DEBUG3 = 0xF3U;
Expand Down Expand Up @@ -131,6 +133,8 @@ m_rxP25Data(1000U, "Modem RX P25"),
m_txP25Data(1000U, "Modem TX P25"),
m_rxNXDNData(1000U, "Modem RX NXDN"),
m_txNXDNData(1000U, "Modem TX NXDN"),
m_rxTransparentData(1000U, "Modem RX Transparent"),
m_txTransparentData(1000U, "Modem TX Transparent"),
m_statusTimer(1000U, 0U, 250U),
m_inactivityTimer(1000U, 2U),
m_playoutTimer(1000U, 0U, 10U),
Expand Down Expand Up @@ -504,6 +508,17 @@ void CModem::clock(unsigned int ms)
}
break;

case MMDVM_TRANSPARENT: {
if (m_trace)
CUtils::dump(1U, "RX Transparent Data", m_buffer, m_length);

unsigned char data = m_length - 3U;
m_rxTransparentData.addData(&data, 1U);

m_rxTransparentData.addData(m_buffer + 3U, m_length - 3U);
}
break;

// These should not be received, but don't complain if we do
case MMDVM_GET_VERSION:
case MMDVM_ACK:
Expand Down Expand Up @@ -658,6 +673,19 @@ void CModem::clock(unsigned int ms)

m_nxdnSpace--;
}

if (!m_txTransparentData.isEmpty()) {
unsigned char len = 0U;
m_txTransparentData.getData(&len, 1U);
m_txTransparentData.getData(m_buffer, len);

if (m_trace)
CUtils::dump(1U, "TX Transparent Data", m_buffer, len);

int ret = m_serial.write(m_buffer, len);
if (ret != int(len))
LogWarning("Error when writing Transparent data to the MMDVM");
}
}

void CModem::close()
Expand Down Expand Up @@ -751,6 +779,20 @@ unsigned int CModem::readNXDNData(unsigned char* data)
return len;
}

unsigned int CModem::readTransparentData(unsigned char* data)
{
assert(data != NULL);

if (m_rxTransparentData.isEmpty())
return 0U;

unsigned char len = 0U;
m_rxTransparentData.getData(&len, 1U);
m_rxTransparentData.getData(data, len);

return len;
}

// To be implemented later if needed
unsigned int CModem::readSerial(unsigned char* data, unsigned int length)
{
Expand Down Expand Up @@ -951,6 +993,26 @@ bool CModem::writeNXDNData(const unsigned char* data, unsigned int length)
return true;
}

bool CModem::writeTransparentData(const unsigned char* data, unsigned int length)
{
assert(data != NULL);
assert(length > 0U);

unsigned char buffer[250U];

buffer[0U] = MMDVM_FRAME_START;
buffer[1U] = length + 3U;
buffer[2U] = MMDVM_TRANSPARENT;

::memcpy(buffer + 3U, data, length);

unsigned char len = length + 3U;
m_txTransparentData.addData(&len, 1U);
m_txTransparentData.addData(buffer, len);

return true;
}

bool CModem::writeSerial(const unsigned char* data, unsigned int length)
{
assert(data != NULL);
Expand Down
4 changes: 4 additions & 0 deletions Modem.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class CModem {
unsigned int readYSFData(unsigned char* data);
unsigned int readP25Data(unsigned char* data);
unsigned int readNXDNData(unsigned char* data);
unsigned int readTransparentData(unsigned char* data);

unsigned int readSerial(unsigned char* data, unsigned int length);

Expand All @@ -73,6 +74,7 @@ class CModem {
bool writeYSFData(const unsigned char* data, unsigned int length);
bool writeP25Data(const unsigned char* data, unsigned int length);
bool writeNXDNData(const unsigned char* data, unsigned int length);
bool writeTransparentData(const unsigned char* data, unsigned int length);

bool writeDMRStart(bool tx);
bool writeDMRShortLC(const unsigned char* lc);
Expand Down Expand Up @@ -135,6 +137,8 @@ class CModem {
CRingBuffer<unsigned char> m_txP25Data;
CRingBuffer<unsigned char> m_rxNXDNData;
CRingBuffer<unsigned char> m_txNXDNData;
CRingBuffer<unsigned char> m_rxTransparentData;
CRingBuffer<unsigned char> m_txTransparentData;
CTimer m_statusTimer;
CTimer m_inactivityTimer;
CTimer m_playoutTimer;
Expand Down

0 comments on commit 52ec2f2

Please sign in to comment.