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