mirror of
https://github.com/g4klx/MMDVMHost
synced 2025-12-22 08:05:49 +08:00
Regularise the UDP socket handling for DMR, POCSAG and the Remote Control port.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2015,2016,2017,2018,2020,2021 by Jonathan Naylor G4KLX
|
||||
* Copyright (C) 2015,2016,2017,2018,2020,2021,2024 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
|
||||
@@ -72,6 +72,9 @@ m_beacon(false)
|
||||
assert(id > 1000U);
|
||||
assert(!password.empty());
|
||||
|
||||
if (CUDPSocket::lookup(m_address, m_port, m_addr, m_addrLen) != 0)
|
||||
m_addrLen = 0U;
|
||||
|
||||
m_buffer = new unsigned char[BUFFER_LENGTH];
|
||||
m_salt = new unsigned char[sizeof(uint32_t)];
|
||||
m_id = new uint8_t[4U];
|
||||
@@ -121,18 +124,18 @@ void CDMRDirectNetwork::setConfig(const std::string& callsign, unsigned int rxFr
|
||||
|
||||
bool CDMRDirectNetwork::open()
|
||||
{
|
||||
if (CUDPSocket::lookup(m_address, m_port, m_addr, m_addrLen) != 0) {
|
||||
if (m_addrLen == 0U) {
|
||||
LogError("DMR, Could not lookup the address of the DMR Network");
|
||||
return false;
|
||||
}
|
||||
|
||||
LogMessage("Opening DMR Network");
|
||||
LogMessage("DMR, Opening DMR Network");
|
||||
|
||||
m_status = WAITING_CONNECT;
|
||||
m_timeoutTimer.stop();
|
||||
m_retryTimer.start();
|
||||
|
||||
return true;
|
||||
return m_socket.open(m_addr);
|
||||
}
|
||||
|
||||
void CDMRDirectNetwork::enable(bool enabled)
|
||||
@@ -323,7 +326,7 @@ bool CDMRDirectNetwork::isConnected() const
|
||||
|
||||
void CDMRDirectNetwork::close(bool sayGoodbye)
|
||||
{
|
||||
LogMessage("Closing DMR Network");
|
||||
LogMessage("DMR, Closing DMR Network");
|
||||
|
||||
if (sayGoodbye && (m_status == RUNNING)) {
|
||||
unsigned char buffer[9U];
|
||||
@@ -344,11 +347,8 @@ void CDMRDirectNetwork::clock(unsigned int ms)
|
||||
if (m_retryTimer.isRunning() && m_retryTimer.hasExpired()) {
|
||||
switch (m_status) {
|
||||
case WAITING_CONNECT:
|
||||
if (m_socket.open(m_addr)) {
|
||||
if (writeLogin()) {
|
||||
m_status = WAITING_LOGIN;
|
||||
}
|
||||
}
|
||||
writeLogin();
|
||||
m_status = WAITING_LOGIN;
|
||||
break;
|
||||
case WAITING_LOGIN:
|
||||
writeLogin();
|
||||
|
||||
@@ -105,7 +105,7 @@ void CDMRGatewayNetwork::setOptions(const std::string& options)
|
||||
bool CDMRGatewayNetwork::open()
|
||||
{
|
||||
if (m_addrLen == 0U) {
|
||||
LogError("Unable to resolve the address of the DMR Network");
|
||||
LogError("DMR, Unable to resolve the address of the DMR Network");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ bool CPOCSAGNetwork::open()
|
||||
|
||||
LogMessage("Opening POCSAG network connection");
|
||||
|
||||
return m_socket.open();
|
||||
return m_socket.open(m_addr);
|
||||
}
|
||||
|
||||
void CPOCSAGNetwork::clock(unsigned int ms)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019,2020,2021 by Jonathan Naylor G4KLX
|
||||
* Copyright (C) 2019,2020,2021,2024 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
|
||||
@@ -36,10 +36,15 @@ const unsigned int BUFFER_LENGTH = 100U;
|
||||
CRemoteControl::CRemoteControl(CMMDVMHost *host, const std::string address, unsigned int port) :
|
||||
m_host(host),
|
||||
m_socket(address, port),
|
||||
m_addr(),
|
||||
m_addrLen(0U),
|
||||
m_command(RCD_NONE),
|
||||
m_args()
|
||||
{
|
||||
assert(port > 0U);
|
||||
|
||||
if (CUDPSocket::lookup(address, port, m_addr, m_addrLen) != 0)
|
||||
m_addrLen = 0U;
|
||||
}
|
||||
|
||||
CRemoteControl::~CRemoteControl()
|
||||
@@ -48,7 +53,12 @@ CRemoteControl::~CRemoteControl()
|
||||
|
||||
bool CRemoteControl::open()
|
||||
{
|
||||
return m_socket.open();
|
||||
if (m_addrLen == 0U) {
|
||||
LogError("Unable to resolve the address of the remote control port");
|
||||
return false;
|
||||
}
|
||||
|
||||
return m_socket.open(m_addr);
|
||||
}
|
||||
|
||||
REMOTE_COMMAND CRemoteControl::getCommand()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019,2020,2021 by Jonathan Naylor G4KLX
|
||||
* Copyright (C) 2019,2020,2021,2024 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
|
||||
@@ -83,6 +83,8 @@ public:
|
||||
private:
|
||||
CMMDVMHost* m_host;
|
||||
CUDPSocket m_socket;
|
||||
sockaddr_storage m_addr;
|
||||
unsigned int m_addrLen;
|
||||
REMOTE_COMMAND m_command;
|
||||
std::vector<std::string> m_args;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user