Skip to content

Commit

Permalink
More sane modem port protocol handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
g4klx committed Feb 16, 2021
1 parent ff9712b commit 8ace65b
Show file tree
Hide file tree
Showing 22 changed files with 453 additions and 180 deletions.
70 changes: 51 additions & 19 deletions Conf.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015-2020 by Jonathan Naylor G4KLX
* Copyright (C) 2015-2021 by Jonathan Naylor G4KLX
*
* 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
Expand Down Expand Up @@ -93,10 +93,14 @@ m_dmrIdLookupFile(),
m_dmrIdLookupTime(0U),
m_nxdnIdLookupFile(),
m_nxdnIdLookupTime(0U),
m_modemPort(),
m_modemProtocol("uart"),
m_modemSpeed(115200U),
m_modemAddress(0x22),
m_modemUARTPort(),
m_modemUARTSpeed(115200U),
m_modemI2CPort(),
m_modemI2CAddress(0x22U),
m_modemModemAddress(),
m_modemModemPort(0U),
m_modemLocalPort(0U),
m_modemRXInvert(false),
m_modemTXInvert(false),
m_modemPTTInvert(false),
Expand Down Expand Up @@ -514,14 +518,22 @@ bool CConf::read()
else if (::strcmp(key, "Time") == 0)
m_nxdnIdLookupTime = (unsigned int)::atoi(value);
} else if (section == SECTION_MODEM) {
if (::strcmp(key, "Port") == 0)
m_modemPort = value;
else if (::strcmp(key, "Protocol") == 0)
if (::strcmp(key, "Protocol") == 0)
m_modemProtocol = value;
else if (::strcmp(key, "Speed") == 0)
m_modemSpeed = (unsigned int)::atoi(value);
else if (::strcmp(key, "Address") == 0)
m_modemAddress = (unsigned int)::strtoul(value, NULL, 16);
else if (::strcmp(key, "UARTPort") == 0)
m_modemUARTPort = value;
else if (::strcmp(key, "UARTSpeed") == 0)
m_modemUARTSpeed = (unsigned int)::atoi(value);
else if (::strcmp(key, "I2CPort") == 0)
m_modemI2CPort = value;
else if (::strcmp(key, "I2CAddress") == 0)
m_modemI2CAddress = (unsigned int)::strtoul(value, NULL, 16);
else if (::strcmp(key, "ModemAddress") == 0)
m_modemModemAddress = value;
else if (::strcmp(key, "ModemPort") == 0)
m_modemModemPort = (unsigned int)::atoi(value);
else if (::strcmp(key, "LocalPort") == 0)
m_modemLocalPort = (unsigned int)::atoi(value);
else if (::strcmp(key, "RXInvert") == 0)
m_modemRXInvert = ::atoi(value) == 1;
else if (::strcmp(key, "TXInvert") == 0)
Expand Down Expand Up @@ -1232,24 +1244,44 @@ unsigned int CConf::getNXDNIdLookupTime() const
return m_nxdnIdLookupTime;
}

std::string CConf::getModemPort() const
std::string CConf::getModemProtocol() const
{
return m_modemPort;
return m_modemProtocol;
}

std::string CConf::getModemProtocol() const
std::string CConf::getModemUARTPort() const
{
return m_modemProtocol;
return m_modemUARTPort;
}

unsigned int CConf::getModemUARTSpeed() const
{
return m_modemUARTSpeed;
}

std::string CConf::getModemI2CPort() const
{
return m_modemI2CPort;
}

unsigned int CConf::getModemI2CAddress() const
{
return m_modemI2CAddress;
}

std::string CConf::getModemModemAddress() const
{
return m_modemModemAddress;
}

unsigned int CConf::getModemSpeed() const
unsigned int CConf::getModemModemPort() const
{
return m_modemSpeed;
return m_modemModemPort;
}

unsigned int CConf::getModemAddress() const
unsigned int CConf::getModemLocalPort() const
{
return m_modemAddress;
return m_modemLocalPort;
}

bool CConf::getModemRXInvert() const
Expand Down
22 changes: 15 additions & 7 deletions Conf.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015-2020 by Jonathan Naylor G4KLX
* Copyright (C) 2015-2021 by Jonathan Naylor G4KLX
*
* 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
Expand Down Expand Up @@ -70,10 +70,14 @@ class CConf
unsigned int getNXDNIdLookupTime() const;

// The Modem section
std::string getModemPort() const;
std::string getModemProtocol() const;
unsigned int getModemSpeed() const;
unsigned int getModemAddress() const;
std::string getModemUARTPort() const;
unsigned int getModemUARTSpeed() const;
std::string getModemI2CPort() const;
unsigned int getModemI2CAddress() const;
std::string getModemModemAddress() const;
unsigned int getModemModemPort() const;
unsigned int getModemLocalPort() const;
bool getModemRXInvert() const;
bool getModemTXInvert() const;
bool getModemPTTInvert() const;
Expand Down Expand Up @@ -391,10 +395,14 @@ class CConf
std::string m_nxdnIdLookupFile;
unsigned int m_nxdnIdLookupTime;

std::string m_modemPort;
std::string m_modemProtocol;
unsigned int m_modemSpeed;
unsigned int m_modemAddress;
std::string m_modemUARTPort;
unsigned int m_modemUARTSpeed;
std::string m_modemI2CPort;
unsigned int m_modemI2CAddress;
std::string m_modemModemAddress;
unsigned int m_modemModemPort;
unsigned int m_modemLocalPort;
bool m_modemRXInvert;
bool m_modemTXInvert;
bool m_modemPTTInvert;
Expand Down
5 changes: 3 additions & 2 deletions I2CController.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2002-2004,2007-2009,2011-2013,2015-2017,2020 by Jonathan Naylor G4KLX
* Copyright (C) 2002-2004,2007-2009,2011-2013,2015-2017,2020,2021 by Jonathan Naylor G4KLX
* Copyright (C) 1999-2001 by Thomas Sailor HB9JNX
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -22,11 +22,12 @@

#if defined(__linux__)

#include "MMDVMModemPort.h"
#include "SerialPort.h"

#include <string>

class CI2CController : public ISerialPort {
class CI2CController : public ISerialPort, public IMMDVMModemPort {
public:
CI2CController(const std::string& device, unsigned int address = 0x22U);
virtual ~CI2CController();
Expand Down
16 changes: 11 additions & 5 deletions MMDVM.ini
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,18 @@ File=NXDN.csv
Time=24

[Modem]
# Port=/dev/ttyACM0
Port=/dev/ttyAMA0
# Port=\\.\COM4
# Valid values are "uart", "udp", and (on Linux) "i2c"
Protocol=uart
Speed=460800
# Address=0x22
# The port and speed used for a UART connection
# UARTPort=\\.\COM4
# UARTPort=/dev/ttyACM0
UARTPort=/dev/ttyAMA0
UARTSpeed=460800
# The port and address for an I2C connection
I2CPort=/dev/i2c
I2CAddress=0x22
# IP parameters for UDP connection

TXInvert=1
RXInvert=0
PTTInvert=0
Expand Down
53 changes: 40 additions & 13 deletions MMDVMHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "NXDNIcomNetwork.h"
#include "RSSIInterpolator.h"
#include "UARTController.h"
#include "UDPController.h"
#include "MMDVMModem.h"
#include "NullModem.h"
#include "Version.h"
Expand Down Expand Up @@ -1315,10 +1316,14 @@ int CMMDVMHost::run()

bool CMMDVMHost::createModem()
{
std::string port = m_conf.getModemPort();
std::string protocol = m_conf.getModemProtocol();
unsigned int speed = m_conf.getModemSpeed();
unsigned int address = m_conf.getModemAddress();
std::string protocol = m_conf.getModemProtocol();
std::string uartPort = m_conf.getModemUARTPort();
unsigned int uartSpeed = m_conf.getModemUARTSpeed();
std::string i2cPort = m_conf.getModemI2CPort();
unsigned int i2cAddress = m_conf.getModemI2CAddress();
std::string modemAddress = m_conf.getModemModemAddress();
unsigned int modemPort = m_conf.getModemModemPort();
unsigned int localPort = m_conf.getModemLocalPort();
bool rxInvert = m_conf.getModemRXInvert();
bool txInvert = m_conf.getModemTXInvert();
bool pttInvert = m_conf.getModemPTTInvert();
Expand Down Expand Up @@ -1358,14 +1363,23 @@ bool CMMDVMHost::createModem()
bool useCOSAsLockout = m_conf.getModemUseCOSAsLockout();

LogInfo("Modem Parameters");
LogInfo(" Port: %s", port.c_str());
#if defined(__linux__)
LogInfo(" Protocol: %s", protocol.c_str());
if (protocol == "i2c")
LogInfo(" I2C Address: %02X", address);
else

if (protocol == "uart") {
LogInfo(" UART Port: %s", uartPort.c_str());
LogInfo(" UART Speed: %u", uartSpeed);
} else if (protocol == "udp") {
LogInfo(" Modem Address: %s", modemAddress.c_str());
LogInfo(" Modem Port: %u", modemPort);
LogInfo(" Local Port: %u", localPort);
}
#if defined(__linux__)
else if (protocol == "i2c") {
LogInfo(" I2C Port: %s", i2cPort.c_str());
LogInfo(" I2C Address: %02X", i2cAddress);
}
#endif
LogInfo(" Speed: %u", speed);

LogInfo(" RX Invert: %s", rxInvert ? "yes" : "no");
LogInfo(" TX Invert: %s", txInvert ? "yes" : "no");
LogInfo(" PTT Invert: %s", pttInvert ? "yes" : "no");
Expand All @@ -1390,11 +1404,24 @@ bool CMMDVMHost::createModem()
LogInfo(" TX Frequency: %uHz (%uHz)", txFrequency, txFrequency + txOffset);
LogInfo(" Use COS as Lockout: %s", useCOSAsLockout ? "yes" : "no");

if (port == "NullModem")
if (protocol == "null")
m_modem = new CNullModem;
else
m_modem = new CMMDVMModem(port, m_duplex, rxInvert, txInvert, pttInvert, txDelay, dmrDelay, useCOSAsLockout, trace, debug);
m_modem->setSerialParams(protocol, address, speed);
m_modem = new CMMDVMModem(m_duplex, rxInvert, txInvert, pttInvert, txDelay, dmrDelay, useCOSAsLockout, trace, debug);

IMMDVMModemPort* modem = NULL;
if (protocol == "uart")
modem = new CUARTController(uartPort, uartSpeed, true);
else if (protocol == "udp")
modem = new CUDPController(modemAddress, modemPort, localPort);
#if defined(__linux__)
else if (protocol == "i2c")
modem = new CI2CController(i2cPort, i2cAddress);
#endif
else
return false;

m_modem->setModem(modem);
m_modem->setModeParams(m_dstarEnabled, m_dmrEnabled, m_ysfEnabled, m_p25Enabled, m_nxdnEnabled, m_m17Enabled, m_pocsagEnabled, m_fmEnabled, m_ax25Enabled);
m_modem->setLevels(rxLevel, cwIdTXLevel, dstarTXLevel, dmrTXLevel, ysfTXLevel, p25TXLevel, nxdnTXLevel, m17TXLevel, pocsagTXLevel, fmTXLevel, ax25TXLevel);
m_modem->setRFParams(rxFrequency, rxOffset, txFrequency, txOffset, txDCOffset, rxDCOffset, rfLevel, pocsagFrequency);
Expand Down
4 changes: 4 additions & 0 deletions MMDVMHost.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
<ClInclude Include="M17Network.h" />
<ClInclude Include="M17Utils.h" />
<ClInclude Include="MMDVMHost.h" />
<ClInclude Include="MMDVMModemPort.h" />
<ClInclude Include="Modem.h" />
<ClInclude Include="ModemSerialPort.h" />
<ClInclude Include="Mutex.h" />
Expand Down Expand Up @@ -252,6 +253,7 @@
<ClInclude Include="TFTSurenoo.h" />
<ClInclude Include="Thread.h" />
<ClInclude Include="Timer.h" />
<ClInclude Include="UDPController.h" />
<ClInclude Include="UDPSocket.h" />
<ClInclude Include="UserDB.h" />
<ClInclude Include="UserDBentry.h" />
Expand Down Expand Up @@ -311,6 +313,7 @@
<ClCompile Include="M17Network.cpp" />
<ClCompile Include="M17Utils.cpp" />
<ClCompile Include="MMDVMHost.cpp" />
<ClCompile Include="MMDVMModemPort.cpp" />
<ClCompile Include="Modem.cpp" />
<ClCompile Include="ModemSerialPort.cpp" />
<ClCompile Include="Mutex.cpp" />
Expand Down Expand Up @@ -356,6 +359,7 @@
<ClCompile Include="TFTSurenoo.cpp" />
<ClCompile Include="Thread.cpp" />
<ClCompile Include="Timer.cpp" />
<ClCompile Include="UDPController.cpp" />
<ClCompile Include="UDPSocket.cpp" />
<ClCompile Include="UserDB.cpp" />
<ClCompile Include="UserDBentry.cpp" />
Expand Down
12 changes: 12 additions & 0 deletions MMDVMHost.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,12 @@
<ClInclude Include="UARTController.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MMDVMModemPort.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="UDPController.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="BPTC19696.cpp">
Expand Down Expand Up @@ -646,5 +652,11 @@
<ClCompile Include="UARTController.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MMDVMModemPort.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="UDPController.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
Loading

0 comments on commit 8ace65b

Please sign in to comment.