Skip to content

Commit

Permalink
Regularise the UDP socket handling for DMR, POCSAG and the Remote Con…
Browse files Browse the repository at this point in the history
…trol port.
  • Loading branch information
g4klx committed Feb 1, 2024
1 parent fe95642 commit da38264
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 16 deletions.
20 changes: 10 additions & 10 deletions DMRDirectNetwork.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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];
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion DMRGatewayNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion POCSAGNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 12 additions & 2 deletions RemoteControl.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion RemoteControl.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -83,6 +83,8 @@ class CRemoteControl {
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;
};
Expand Down
2 changes: 1 addition & 1 deletion Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
#if !defined(VERSION_H)
#define VERSION_H

const char* VERSION = "20240129";
const char* VERSION = "20240201";

#endif

0 comments on commit da38264

Please sign in to comment.