diff --git a/Conf.cpp b/Conf.cpp index 2aaa34b..b5cc8d0 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -30,37 +30,35 @@ enum SECTION { SECTION_NONE, SECTION_GENERAL, SECTION_LOG, - SECTION_MMDVM, SECTION_DMR_NETWORK, - SECTION_XLX_NETWORK + SECTION_XLX_NETWORK }; CConf::CConf(const std::string& file) : m_file(file), m_daemon(false), m_xlxSlot(2U), +m_rptAddress("127.0.0.1"), +m_rptPort(62032U), +m_localAddress("127.0.0.1"), +m_localPort(62031U), m_timeout(10U), +m_debug(false), m_logDisplayLevel(0U), m_logFileLevel(0U), m_logFilePath(), m_logFileRoot(), -m_mmdvmAddress(), -m_mmdvmPort(0U), -m_mmdvmLocal(0U), -m_mmdvmDebug(false), +m_dmrNetworkAddress(), +m_dmrNetworkPort(0U), +m_dmrNetworkLocal(0U), +m_dmrNetworkPassword(), +m_dmrNetworkDebug(false), m_xlxNetworkAddress(), m_xlxNetworkPort(0U), m_xlxNetworkLocal(0U), m_xlxNetworkPassword(), m_xlxNetworkOptions(), -m_xlxNetworkSlot(1U), -m_xlxNetworkTG(9U), -m_xlxNetworkDebug(false), -m_dmrNetworkAddress(), -m_dmrNetworkPort(0U), -m_dmrNetworkLocal(0U), -m_dmrNetworkPassword(), -m_dmrNetworkDebug(false) +m_xlxNetworkDebug(false) { } @@ -88,13 +86,11 @@ bool CConf::read() section = SECTION_GENERAL; else if (::strncmp(buffer, "[Log]", 5U) == 0) section = SECTION_LOG; - else if (::strncmp(buffer, "[MMDVM]", 13U) == 0) - section = SECTION_MMDVM; - else if (::strncmp(buffer, "[XLX Network]", 13U) == 0) - section = SECTION_XLX_NETWORK; - else if (::strncmp(buffer, "[DMR Network]", 13U) == 0) - section = SECTION_DMR_NETWORK; - else + else if (::strncmp(buffer, "[XLX Network]", 13U) == 0) + section = SECTION_XLX_NETWORK; + else if (::strncmp(buffer, "[DMR Network]", 13U) == 0) + section = SECTION_DMR_NETWORK; + else section = SECTION_NONE; continue; @@ -115,6 +111,16 @@ bool CConf::read() m_xlxSlot = (unsigned int)::atoi(value); else if (::strcmp(key, "Timeout") == 0) m_timeout = (unsigned int)::atoi(value); + else if (::strcmp(key, "RptAddress") == 0) + m_rptAddress = value; + else if (::strcmp(key, "RptPort") == 0) + m_rptPort = (unsigned int)::atoi(value); + else if (::strcmp(key, "LocalAddress") == 0) + m_localAddress = value; + else if (::strcmp(key, "LocalPort") == 0) + m_localPort = (unsigned int)::atoi(value); + else if (::strcmp(key, "Debug") == 0) + m_debug = ::atoi(value) == 1; } else if (section == SECTION_LOG) { if (::strcmp(key, "FilePath") == 0) m_logFilePath = value; @@ -124,15 +130,6 @@ bool CConf::read() m_logFileLevel = (unsigned int)::atoi(value); else if (::strcmp(key, "DisplayLevel") == 0) m_logDisplayLevel = (unsigned int)::atoi(value); - } else if (section == SECTION_MMDVM) { - if (::strcmp(key, "Address") == 0) - m_mmdvmAddress = value; - else if (::strcmp(key, "Port") == 0) - m_mmdvmPort = (unsigned int)::atoi(value); - else if (::strcmp(key, "Local") == 0) - m_mmdvmLocal = (unsigned int)::atoi(value); - else if (::strcmp(key, "Debug") == 0) - m_mmdvmDebug = ::atoi(value) == 1; } else if (section == SECTION_XLX_NETWORK) { if (::strcmp(key, "Address") == 0) m_xlxNetworkAddress = value; @@ -144,10 +141,6 @@ bool CConf::read() m_xlxNetworkPassword = value; else if (::strcmp(key, "Options") == 0) m_xlxNetworkOptions = value; - else if (::strcmp(key, "Slot") == 0) - m_xlxNetworkSlot = (unsigned int)::atoi(value); - else if (::strcmp(key, "TG") == 0) - m_xlxNetworkTG = (unsigned int)::atoi(value); else if (::strcmp(key, "Debug") == 0) m_xlxNetworkDebug = ::atoi(value) == 1; } else if (section == SECTION_DMR_NETWORK) { @@ -179,11 +172,36 @@ unsigned int CConf::getXLXSlot() const return m_xlxSlot; } +std::string CConf::getRptAddress() const +{ + return m_rptAddress; +} + +unsigned int CConf::getRptPort() const +{ + return m_rptPort; +} + +std::string CConf::getLocalAddress() const +{ + return m_localAddress; +} + +unsigned int CConf::getLocalPort() const +{ + return m_localPort; +} + unsigned int CConf::getTimeout() const { return m_timeout; } +bool CConf::getDebug() const +{ + return m_debug; +} + unsigned int CConf::getLogDisplayLevel() const { return m_logDisplayLevel; @@ -204,26 +222,6 @@ std::string CConf::getLogFileRoot() const return m_logFileRoot; } -std::string CConf::getMMDVMAddress() const -{ - return m_mmdvmAddress; -} - -unsigned int CConf::getMMDVMPort() const -{ - return m_mmdvmPort; -} - -unsigned int CConf::getMMDVMLocal() const -{ - return m_mmdvmLocal; -} - -bool CConf::getMMDVMDebug() const -{ - return m_mmdvmDebug; -} - std::string CConf::getXLXNetworkAddress() const { return m_xlxNetworkAddress; @@ -249,16 +247,6 @@ std::string CConf::getXLXNetworkOptions() const return m_xlxNetworkOptions; } -unsigned int CConf::getXLXNetworkSlot() const -{ - return m_xlxNetworkSlot; -} - -unsigned int CConf::getXLXNetworkTG() const -{ - return m_xlxNetworkTG; -} - bool CConf::getXLXNetworkDebug() const { return m_xlxNetworkDebug; diff --git a/Conf.h b/Conf.h index ea0ac70..47f5e02 100644 --- a/Conf.h +++ b/Conf.h @@ -25,34 +25,33 @@ class CConf { public: - CConf(const std::string& file); - ~CConf(); + CConf(const std::string& file); + ~CConf(); - bool read(); + bool read(); - // The General section - bool getDaemon() const; + // The General section + bool getDaemon() const; unsigned int getXLXSlot() const; unsigned int getTimeout() const; + std::string getRptAddress() const; + unsigned int getRptPort() const; + std::string getLocalAddress() const; + unsigned int getLocalPort() const; + bool getDebug() const; - // The Log section - unsigned int getLogDisplayLevel() const; - unsigned int getLogFileLevel() const; - std::string getLogFilePath() const; - std::string getLogFileRoot() const; - - // The MMDVM Network section - std::string getMMDVMAddress() const; - unsigned int getMMDVMPort() const; - unsigned int getMMDVMLocal() const; - bool getMMDVMDebug() const; + // The Log section + unsigned int getLogDisplayLevel() const; + unsigned int getLogFileLevel() const; + std::string getLogFilePath() const; + std::string getLogFileRoot() const; // The DMR Network section - std::string getDMRNetworkAddress() const; - unsigned int getDMRNetworkPort() const; - unsigned int getDMRNetworkLocal() const; - std::string getDMRNetworkPassword() const; - bool getDMRNetworkDebug() const; + std::string getDMRNetworkAddress() const; + unsigned int getDMRNetworkPort() const; + unsigned int getDMRNetworkLocal() const; + std::string getDMRNetworkPassword() const; + bool getDMRNetworkDebug() const; // The XLX Network section std::string getXLXNetworkAddress() const; @@ -60,39 +59,35 @@ public: unsigned int getXLXNetworkLocal() const; std::string getXLXNetworkPassword() const; std::string getXLXNetworkOptions() const; - unsigned int getXLXNetworkSlot() const; - unsigned int getXLXNetworkTG() const; bool getXLXNetworkDebug() const; private: - std::string m_file; - bool m_daemon; + std::string m_file; + bool m_daemon; unsigned int m_xlxSlot; + std::string m_rptAddress; + unsigned int m_rptPort; + std::string m_localAddress; + unsigned int m_localPort; unsigned int m_timeout; + bool m_debug; - unsigned int m_logDisplayLevel; - unsigned int m_logFileLevel; - std::string m_logFilePath; - std::string m_logFileRoot; - - std::string m_mmdvmAddress; - unsigned int m_mmdvmPort; - unsigned int m_mmdvmLocal; - bool m_mmdvmDebug; + unsigned int m_logDisplayLevel; + unsigned int m_logFileLevel; + std::string m_logFilePath; + std::string m_logFileRoot; std::string m_dmrNetworkAddress; - unsigned int m_dmrNetworkPort; - unsigned int m_dmrNetworkLocal; - std::string m_dmrNetworkPassword; - bool m_dmrNetworkDebug; + unsigned int m_dmrNetworkPort; + unsigned int m_dmrNetworkLocal; + std::string m_dmrNetworkPassword; + bool m_dmrNetworkDebug; std::string m_xlxNetworkAddress; unsigned int m_xlxNetworkPort; unsigned int m_xlxNetworkLocal; std::string m_xlxNetworkPassword; std::string m_xlxNetworkOptions; - unsigned int m_xlxNetworkSlot; - unsigned int m_xlxNetworkTG; bool m_xlxNetworkDebug; }; diff --git a/DMRGateway.cpp b/DMRGateway.cpp index 5e470d4..3396438 100644 --- a/DMRGateway.cpp +++ b/DMRGateway.cpp @@ -39,6 +39,9 @@ const char* DEFAULT_INI_FILE = "DMRGateway.ini"; const char* DEFAULT_INI_FILE = "/etc/DMRGateway.ini"; #endif +const unsigned int XLX_SLOT = 2U; +const unsigned int XLX_TG = 9U; + static bool m_killed = false; static int m_signal = 0; @@ -222,14 +225,10 @@ int CDMRGateway::run() LogMessage("MMDVM has connected"); unsigned int xlxSlot = m_conf.getXLXSlot(); - unsigned int xlxNetworkSlot = m_conf.getXLXNetworkSlot(); - unsigned int xlxNetworkTG = m_conf.getXLXNetworkTG(); unsigned int timeout = m_conf.getTimeout(); LogInfo("Id: %u", m_mmdvm->getId()); LogInfo("XLX Local Slot: %u", xlxSlot); - LogInfo("XLX Reflector Slot: %u", xlxNetworkSlot); - LogInfo("XLX TG: %u", xlxNetworkTG); LogInfo("Timeout: %us", timeout); @@ -260,8 +259,8 @@ int CDMRGateway::run() FLCO flco = data.getFLCO(); unsigned int id = data.getDstId(); - if (flco == FLCO_GROUP && id == xlxNetworkTG) { - data.setSlotNo(xlxNetworkSlot); + if (flco == FLCO_GROUP && id == XLX_TG) { + data.setSlotNo(XLX_SLOT); m_xlxNetwork->write(data); status = DMRGWS_REFLECTOR; timer.start(); @@ -272,7 +271,7 @@ int CDMRGateway::run() m_reflector = reflector; } - data.setSlotNo(xlxNetworkSlot); + data.setSlotNo(XLX_SLOT); m_xlxNetwork->write(data); status = DMRGWS_REFLECTOR; timer.start(); @@ -290,7 +289,7 @@ int CDMRGateway::run() if (ret) { if (status == DMRGWS_NONE || status == DMRGWS_REFLECTOR) { unsigned int slotNo = data.getSlotNo(); - if (slotNo == xlxNetworkSlot) { + if (slotNo == XLX_SLOT) { data.setSlotNo(xlxSlot); m_mmdvm->write(data); status = DMRGWS_REFLECTOR; @@ -306,7 +305,7 @@ int CDMRGateway::run() // Stop BM from using the same TG as XLX unsigned int dstId = data.getDstId(); FLCO flco = data.getFLCO(); - if (flco != FLCO_GROUP || dstId != xlxNetworkTG) { + if (flco != FLCO_GROUP || dstId != XLX_TG) { if (status == DMRGWS_NONE || status == DMRGWS_NETWORK) { m_mmdvm->write(data); status = DMRGWS_NETWORK; @@ -351,20 +350,19 @@ int CDMRGateway::run() bool CDMRGateway::createMMDVM() { - std::string address = m_conf.getMMDVMAddress(); - unsigned int port = m_conf.getMMDVMPort(); - unsigned int local = m_conf.getMMDVMLocal(); - bool debug = m_conf.getMMDVMDebug(); + std::string rptAddress = m_conf.getRptAddress(); + unsigned int rptPort = m_conf.getRptPort(); + std::string localAddress = m_conf.getLocalAddress(); + unsigned int localPort = m_conf.getLocalPort(); + bool debug = m_conf.getDebug(); LogInfo("MMDVM Network Parameters"); - LogInfo(" Address: %s", address.c_str()); - LogInfo(" Port: %u", port); - if (local > 0U) - LogInfo(" Local: %u", local); - else - LogInfo(" Local: random"); + LogInfo(" Rpt Address: %s", rptAddress.c_str()); + LogInfo(" Rpt Port: %u", rptPort); + LogInfo(" Local Address: %s", localAddress.c_str()); + LogInfo(" Local Port: %u", localPort); - m_mmdvm = new CMMDVMNetwork(address, port, local, debug); + m_mmdvm = new CMMDVMNetwork(rptAddress, rptPort, localAddress, localPort, debug); bool ret = m_mmdvm->open(); if (!ret) { diff --git a/DMRGateway.ini b/DMRGateway.ini index 01ff5d8..6bd9734 100644 --- a/DMRGateway.ini +++ b/DMRGateway.ini @@ -1,7 +1,12 @@ [General] XLXSlot=2 Timeout=10 +RptAddress=127.0.0.1 +RptPort=62032 +LocalAddress=127.0.0.1 +LocalPort=62031 Daemon=0 +Debug=0 [Log] # Logging levels, 0=No logging @@ -10,20 +15,12 @@ FileLevel=1 FilePath=. FileRoot=DMRGateway -[MMDVM] -Address=44.131.4.1 -Port=62031 -# Local=3350 -Debug=0 - [XLX Network] Address=xlx950.epf.lu Port=55555 # Local=3351 # Options= Password=passw0rd -Slot=2 -TG=9 Debug=0 [DMR Network] diff --git a/MMDVMNetwork.cpp b/MMDVMNetwork.cpp index d6e49df..9f36809 100644 --- a/MMDVMNetwork.cpp +++ b/MMDVMNetwork.cpp @@ -31,23 +31,23 @@ const unsigned int BUFFER_LENGTH = 500U; const unsigned int HOMEBREW_DATA_PACKET_LENGTH = 55U; -CMMDVMNetwork::CMMDVMNetwork(const std::string& address, unsigned int port, unsigned int local, bool debug) : -m_address(), -m_port(port), +CMMDVMNetwork::CMMDVMNetwork(const std::string& rptAddress, unsigned int rptPort, const std::string& localAddress, unsigned int localPort, bool debug) : +m_rptAddress(), +m_rptPort(rptPort), m_id(0U), m_netId(NULL), m_debug(debug), -m_socket(local), +m_socket(localAddress, localPort), m_buffer(NULL), m_rxData(1000U, "MMDVM Network"), m_options(), m_configData(NULL), m_configLen(0U) { - assert(!address.empty()); - assert(port > 0U); + assert(!rptAddress.empty()); + assert(rptPort > 0U); - m_address = CUDPSocket::lookup(address); + m_rptAddress = CUDPSocket::lookup(rptAddress); m_buffer = new unsigned char[BUFFER_LENGTH]; m_netId = new unsigned char[4U]; @@ -198,7 +198,7 @@ bool CMMDVMNetwork::write(const CDMRData& data) if (m_debug) CUtils::dump(1U, "Network Transmitted", buffer, HOMEBREW_DATA_PACKET_LENGTH); - m_socket.write(buffer, HOMEBREW_DATA_PACKET_LENGTH, m_address, m_port); + m_socket.write(buffer, HOMEBREW_DATA_PACKET_LENGTH, m_rptAddress, m_rptPort); return true; } @@ -225,7 +225,7 @@ void CMMDVMNetwork::clock(unsigned int ms) // if (m_debug && length > 0) // CUtils::dump(1U, "Network Received", m_buffer, length); - if (length > 0 && m_address.s_addr == address.s_addr && m_port == port) { + if (length > 0 && m_rptAddress.s_addr == address.s_addr && m_rptPort == port) { if (::memcmp(m_buffer, "DMRD", 4U) == 0) { if (m_debug) CUtils::dump(1U, "Network Received", m_buffer, length); @@ -233,8 +233,7 @@ void CMMDVMNetwork::clock(unsigned int ms) unsigned char len = length; m_rxData.addData(&len, 1U); m_rxData.addData(m_buffer, len); - } - else if (::memcmp(m_buffer, "RPTL", 4U) == 0) { + } else if (::memcmp(m_buffer, "RPTL", 4U) == 0) { m_id = (m_buffer[4U] << 24) | (m_buffer[5U] << 16) | (m_buffer[6U] << 8) | (m_buffer[7U] << 0); ::memcpy(m_netId, m_buffer + 4U, 4U); @@ -244,35 +243,30 @@ void CMMDVMNetwork::clock(unsigned int ms) uint32_t salt = 1U; ::memcpy(ack + 6U, &salt, sizeof(uint32_t)); - m_socket.write(ack, 10U, m_address, m_port); - } - else if (::memcmp(m_buffer, "RPTK", 4U) == 0) { + m_socket.write(ack, 10U, m_rptAddress, m_rptPort); + } else if (::memcmp(m_buffer, "RPTK", 4U) == 0) { unsigned char ack[6U]; ::memcpy(ack, "RPTACK", 6U); - m_socket.write(ack, 6U, m_address, m_port); - } - else if (::memcmp(m_buffer, "RPTC", 4U) == 0) { + m_socket.write(ack, 6U, m_rptAddress, m_rptPort); + } else if (::memcmp(m_buffer, "RPTC", 4U) == 0) { m_configLen = length - 8U; m_configData = new unsigned char[m_configLen]; ::memcpy(m_configData, m_buffer + 8U, m_configLen); unsigned char ack[6U]; ::memcpy(ack, "RPTACK", 6U); - m_socket.write(ack, 6U, m_address, m_port); - } - else if (::memcmp(m_buffer, "RPTO", 4U) == 0) { + m_socket.write(ack, 6U, m_rptAddress, m_rptPort); + } else if (::memcmp(m_buffer, "RPTO", 4U) == 0) { m_options = std::string((char*)(m_buffer + 8U), length - 8U); unsigned char ack[6U]; ::memcpy(ack, "RPTACK", 6U); - m_socket.write(ack, 6U, m_address, m_port); - } - else if (::memcmp(m_buffer, "RPTPING", 7U) == 0) { + m_socket.write(ack, 6U, m_rptAddress, m_rptPort); + } else if (::memcmp(m_buffer, "RPTPING", 7U) == 0) { unsigned char pong[7U]; ::memcpy(pong, "MSTPONG", 6U); - m_socket.write(pong, 7U, m_address, m_port); - } - else { + m_socket.write(pong, 7U, m_rptAddress, m_rptPort); + } else { CUtils::dump("Unknown packet from the master", m_buffer, length); } } diff --git a/MMDVMNetwork.h b/MMDVMNetwork.h index 0027975..6abc252 100644 --- a/MMDVMNetwork.h +++ b/MMDVMNetwork.h @@ -30,7 +30,7 @@ class CMMDVMNetwork { public: - CMMDVMNetwork(const std::string& address, unsigned int port, unsigned int local, bool debug); + CMMDVMNetwork(const std::string& rptAddress, unsigned int rptPort, const std::string& localAddress, unsigned int localPort, bool debug); ~CMMDVMNetwork(); std::string getOptions() const; @@ -50,8 +50,8 @@ public: void close(); private: - in_addr m_address; - unsigned int m_port; + in_addr m_rptAddress; + unsigned int m_rptPort; unsigned int m_id; unsigned char* m_netId; bool m_debug;