diff --git a/Defines.h b/Defines.h index 716b9b84..05c2469c 100644 --- a/Defines.h +++ b/Defines.h @@ -130,10 +130,6 @@ typedef unsigned long long ulong64_t; #define NULL_PORT "null" #define UART_PORT "uart" #define PTY_PORT "pty" -#define UDP_PORT "udp" - -#define UDP_MODE_MASTER "master" -#define UDP_MODE_PEER "peer" const uint32_t REMOTE_MODEM_PORT = 3334; const uint32_t TRAFFIC_DEFAULT_PORT = 62031; diff --git a/HostMain.cpp b/HostMain.cpp index 963f917d..d624bdce 100644 --- a/HostMain.cpp +++ b/HostMain.cpp @@ -91,6 +91,10 @@ std::string g_lockFile = std::string(DEFAULT_LOCK_FILE); bool g_foreground = false; bool g_killed = false; +bool g_remoteModemMode = false; +std::string g_remoteAddress = std::string("127.0.0.1"); +uint16_t g_remotePort = REMOTE_MODEM_PORT; + bool g_fireDMRBeacon = false; bool g_fireP25Control = false; bool g_fireNXDNControl = false; @@ -136,11 +140,15 @@ void usage(const char* message, const char* arg) ::fprintf(stderr, "\n\n"); } - ::fprintf(stdout, "usage: %s [-v] [-f] [--cal] [--setup] [-c ]\n\n" + ::fprintf(stdout, "usage: %s [-v] [-f] [--cal] [--setup] [-c ] [--remote [-a
] [-p ]]\n\n" " -f foreground mode\n" " --cal calibration mode\n" " --setup setup mode\n" "\n" + " --remote remote modem mode\n" + " -a remote modem command address\n" + " -p remote modem command port\n" + "\n" " -v show version information\n" " -h show this screen\n" " -- stop handling options\n", @@ -185,6 +193,29 @@ int checkArgs(int argc, char* argv[]) p += 2; } + else if (IS("--remote")) { + g_remoteModemMode = true; + } + else if (IS("-a")) { + if ((argc - 1) <= 0) + usage("error: %s", "must specify the address to connect to"); + g_remoteAddress = std::string(argv[++i]); + + if (g_remoteAddress == "") + usage("error: %s", "remote address cannot be blank!"); + + p += 2; + } + else if (IS("-p")) { + if ((argc - 1) <= 0) + usage("error: %s", "must specify the port to connect to"); + g_remotePort = (uint16_t)::atoi(argv[++i]); + + if (g_remotePort == 0) + usage("error: %s", "remote port number cannot be blank or 0!"); + + p += 2; + } else if (IS("-v")) { ::fprintf(stdout, __PROG_NAME__ " %s (" DESCR_DMR DESCR_P25 DESCR_NXDN "CW Id, Network) (built %s)\n", __VER__, __BUILD__); ::fprintf(stdout, "Copyright (c) 2017-2022 Bryan Biedenkapp, N2PLL and DVMProject (https://github.com/dvmproject) Authors.\n"); diff --git a/HostMain.h b/HostMain.h index 5e979024..12c33401 100644 --- a/HostMain.h +++ b/HostMain.h @@ -47,6 +47,10 @@ extern std::string g_lockFile; extern bool g_foreground; extern bool g_killed; +extern bool g_remoteModemMode; +extern std::string g_remoteAddress; +extern uint16_t g_remotePort; + extern bool g_fireDMRBeacon; extern bool g_fireP25Control; extern bool g_fireNXDNControl; diff --git a/config.example.yml b/config.example.yml index 239849e0..25720877 100644 --- a/config.example.yml +++ b/config.example.yml @@ -130,14 +130,10 @@ system: siteId: 1 modem: protocol: - type: "null" # Valid values are "null", "uart", and "udp" + type: "null" # Valid values are "null", and "uart" uart: port: /dev/ttyUSB0 speed: 115200 - udp: - mode: master # Valid values are "master", and "peer" - endpointAddress: 0.0.0.0 - port: 3334 rxInvert: false txInvert: false pttInvert: false diff --git a/host/Host.cpp b/host/Host.cpp index 46d70d51..e463d3a5 100644 --- a/host/Host.cpp +++ b/host/Host.cpp @@ -1738,7 +1738,7 @@ bool Host::readParams() bool udpMasterMode = false; std::transform(portType.begin(), portType.end(), portType.begin(), ::tolower); - if (portType == UDP_PORT && udpMode == UDP_MODE_MASTER) { + if ((portType == UART_PORT || portType == PTY_PORT) && g_remoteModemMode) { udpMasterMode = true; } @@ -1987,11 +1987,6 @@ bool Host::createModem() std::string uartPort = uartProtocol["port"].as(); uint32_t uartSpeed = uartProtocol["speed"].as(115200); - yaml::Node udpProtocol = modemProtocol["udp"]; - std::string udpMode = udpProtocol["mode"].as("master"); - std::string udpAddress = udpProtocol["endpointAddress"].as(); - uint16_t udpPort = (uint16_t)udpProtocol["port"].as(REMOTE_MODEM_PORT); - bool rxInvert = modemConf["rxInvert"].as(false); bool txInvert = modemConf["txInvert"].as(false); bool pttInvert = modemConf["pttInvert"].as(false); @@ -2068,7 +2063,7 @@ bool Host::createModem() if (portType == NULL_PORT) { modemPort = new port::ModemNullPort(); } - else if (portType == UART_PORT || portType == UDP_PORT || portType == PTY_PORT) { + else if (portType == UART_PORT || portType == PTY_PORT) { port::SERIAL_SPEED serialSpeed = port::SERIAL_115200; switch (uartSpeed) { case 1200: @@ -2126,25 +2121,21 @@ bool Host::createModem() return false; } - if (portType == UDP_PORT) { - std::transform(udpMode.begin(), udpMode.end(), udpMode.begin(), ::tolower); - if (udpMode == UDP_MODE_MASTER) { - m_modemRemotePort = new port::UDPPort(udpAddress, udpPort); + if (g_remoteModemMode) { + if (portType == UART_PORT || portType == PTY_PORT) { + m_modemRemotePort = new port::UDPPort(g_remoteAddress, g_remotePort); m_modemRemote = true; + } - else if (udpMode == UDP_MODE_PEER) { + else { delete modemPort; - modemPort = new port::UDPPort(udpAddress, udpPort); + modemPort = new port::UDPPort(g_remoteAddress, g_remotePort); m_modemRemote = false; } - else { - LogError(LOG_HOST, "Invalid UDP mode, %s!", udpMode.c_str()); - return false; - } - LogInfo(" UDP Mode: %s", udpMode.c_str()); - LogInfo(" UDP Address: %s", udpAddress.c_str()); - LogInfo(" UDP Port: %u", udpPort); + LogInfo(" UDP Mode: %s", m_modemRemote ? "master" : "peer"); + LogInfo(" UDP Address: %s", g_remoteAddress.c_str()); + LogInfo(" UDP Port: %u", g_remotePort); } LogInfo(" RX Invert: %s", rxInvert ? "yes" : "no"); diff --git a/host/calibrate/HostCal.cpp b/host/calibrate/HostCal.cpp index d4b092ba..1e0de877 100644 --- a/host/calibrate/HostCal.cpp +++ b/host/calibrate/HostCal.cpp @@ -430,7 +430,7 @@ int HostCal::run() LogInfo(" Ignore Modem Configuration Area: yes"); } } - else if (portType == UDP_PORT) { + else if (g_remoteModemMode) { ::LogError(LOG_HOST, "Calibration mode is unsupported with a remote modem!"); return 2; }