DMR networking code cleanup.
This commit is contained in:
parent
5d8d1a3fb9
commit
79fc7623dc
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2015,2016,2017,2018,2020 by Jonathan Naylor G4KLX
|
* Copyright (C) 2015,2016,2017,2018,2020,2021 by Jonathan Naylor G4KLX
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -18,7 +18,6 @@
|
||||||
|
|
||||||
#include "DMRDirectNetwork.h"
|
#include "DMRDirectNetwork.h"
|
||||||
|
|
||||||
#include "StopWatch.h"
|
|
||||||
#include "SHA256.h"
|
#include "SHA256.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
@ -91,9 +90,6 @@ m_beacon(false)
|
||||||
std::uniform_int_distribution<uint32_t> dist(0x00000001, 0xfffffffe);
|
std::uniform_int_distribution<uint32_t> dist(0x00000001, 0xfffffffe);
|
||||||
m_streamId[0U] = dist(m_random);
|
m_streamId[0U] = dist(m_random);
|
||||||
m_streamId[1U] = dist(m_random);
|
m_streamId[1U] = dist(m_random);
|
||||||
|
|
||||||
CStopWatch stopWatch;
|
|
||||||
::srand(stopWatch.start());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CDMRDirectNetwork::~CDMRDirectNetwork()
|
CDMRDirectNetwork::~CDMRDirectNetwork()
|
||||||
|
@ -340,25 +336,38 @@ void CDMRDirectNetwork::close()
|
||||||
|
|
||||||
void CDMRDirectNetwork::clock(unsigned int ms)
|
void CDMRDirectNetwork::clock(unsigned int ms)
|
||||||
{
|
{
|
||||||
if (m_status == WAITING_CONNECT) {
|
|
||||||
m_retryTimer.clock(ms);
|
m_retryTimer.clock(ms);
|
||||||
if (m_retryTimer.isRunning() && m_retryTimer.hasExpired()) {
|
if (m_retryTimer.isRunning() && m_retryTimer.hasExpired()) {
|
||||||
bool ret = m_socket.open(m_addr);
|
switch (m_status) {
|
||||||
if (ret) {
|
case WAITING_CONNECT:
|
||||||
ret = writeLogin();
|
if (m_socket.open(m_addr.ss_family)) {
|
||||||
if (!ret)
|
if (writeLogin()) {
|
||||||
return;
|
|
||||||
|
|
||||||
m_status = WAITING_LOGIN;
|
m_status = WAITING_LOGIN;
|
||||||
m_timeoutTimer.start();
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case WAITING_LOGIN:
|
||||||
|
writeLogin();
|
||||||
|
break;
|
||||||
|
case WAITING_AUTHORISATION:
|
||||||
|
writeAuthorisation();
|
||||||
|
break;
|
||||||
|
case WAITING_OPTIONS:
|
||||||
|
writeOptions();
|
||||||
|
break;
|
||||||
|
case WAITING_CONFIG:
|
||||||
|
writeConfig();
|
||||||
|
break;
|
||||||
|
case RUNNING:
|
||||||
|
writePing();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_retryTimer.start();
|
m_retryTimer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sockaddr_storage address;
|
sockaddr_storage address;
|
||||||
unsigned int addrlen;
|
unsigned int addrlen;
|
||||||
int length = m_socket.read(m_buffer, BUFFER_LENGTH, address, addrlen);
|
int length = m_socket.read(m_buffer, BUFFER_LENGTH, address, addrlen);
|
||||||
|
@ -369,14 +378,16 @@ void CDMRDirectNetwork::clock(unsigned int ms)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_debug && length > 0)
|
if (length > 0) {
|
||||||
CUtils::dump(1U, "Network Received", m_buffer, length);
|
if (!CUDPSocket::match(m_addr, address)) {
|
||||||
|
LogMessage("DMR, packet received from an invalid source");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (length > 0 && CUDPSocket::match(m_addr, address)) {
|
|
||||||
if (::memcmp(m_buffer, "DMRD", 4U) == 0) {
|
|
||||||
if (m_debug)
|
if (m_debug)
|
||||||
CUtils::dump(1U, "DMR Network Received", m_buffer, length);
|
CUtils::dump(1U, "DMR, Network Received", m_buffer, length);
|
||||||
|
|
||||||
|
if (::memcmp(m_buffer, "DMRD", 4U) == 0) {
|
||||||
if (m_enabled) {
|
if (m_enabled) {
|
||||||
unsigned char len = length;
|
unsigned char len = length;
|
||||||
m_rxData.addData(&len, 1U);
|
m_rxData.addData(&len, 1U);
|
||||||
|
@ -444,37 +455,10 @@ void CDMRDirectNetwork::clock(unsigned int ms)
|
||||||
} else if (::memcmp(m_buffer, "RPTSBKN", 7U) == 0) {
|
} else if (::memcmp(m_buffer, "RPTSBKN", 7U) == 0) {
|
||||||
m_beacon = true;
|
m_beacon = true;
|
||||||
} else {
|
} else {
|
||||||
char buffer[100U];
|
CUtils::dump("DMR, Unknown packet from the master", m_buffer, length);
|
||||||
::sprintf(buffer, "DMR, Unknown packet from the master");
|
|
||||||
CUtils::dump(buffer, m_buffer, length);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_retryTimer.clock(ms);
|
|
||||||
if (m_retryTimer.isRunning() && m_retryTimer.hasExpired()) {
|
|
||||||
switch (m_status) {
|
|
||||||
case WAITING_LOGIN:
|
|
||||||
writeLogin();
|
|
||||||
break;
|
|
||||||
case WAITING_AUTHORISATION:
|
|
||||||
writeAuthorisation();
|
|
||||||
break;
|
|
||||||
case WAITING_OPTIONS:
|
|
||||||
writeOptions();
|
|
||||||
break;
|
|
||||||
case WAITING_CONFIG:
|
|
||||||
writeConfig();
|
|
||||||
break;
|
|
||||||
case RUNNING:
|
|
||||||
writePing();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_retryTimer.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_timeoutTimer.clock(ms);
|
m_timeoutTimer.clock(ms);
|
||||||
if (m_timeoutTimer.isRunning() && m_timeoutTimer.hasExpired()) {
|
if (m_timeoutTimer.isRunning() && m_timeoutTimer.hasExpired()) {
|
||||||
LogError("DMR, Connection to the master has timed out, retrying connection");
|
LogError("DMR, Connection to the master has timed out, retrying connection");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2015-2020 by Jonathan Naylor G4KLX
|
* Copyright (C) 2015-2021 by Jonathan Naylor G4KLX
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -18,7 +18,6 @@
|
||||||
|
|
||||||
#include "DMRGatewayNetwork.h"
|
#include "DMRGatewayNetwork.h"
|
||||||
|
|
||||||
#include "StopWatch.h"
|
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue