First version of the remote commands handler.

This commit is contained in:
Jonathan Naylor 2020-04-03 17:59:40 +01:00
parent 031d47816c
commit 785faa7ad9
5 changed files with 128 additions and 10 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2015,2016,2017,2018 by Jonathan Naylor G4KLX
* Copyright (C) 2015,2016,2017,2018,2020 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
@ -35,7 +35,8 @@ enum SECTION {
SECTION_LOG,
SECTION_APRS_FI,
SECTION_NETWORK,
SECTION_MOBILE_GPS
SECTION_MOBILE_GPS,
SECTION_REMOTE_COMMANDS
};
CConf::CConf(const std::string& file) :
@ -81,7 +82,9 @@ m_networkInactivityTimeout(0U),
m_networkDebug(false),
m_mobileGPSEnabled(false),
m_mobileGPSAddress(),
m_mobileGPSPort(0U)
m_mobileGPSPort(0U),
m_remoteCommandsEnabled(false),
m_remoteCommandsPort(6075U)
{
}
@ -121,6 +124,8 @@ bool CConf::read()
section = SECTION_NETWORK;
else if (::strncmp(buffer, "[Mobile GPS]", 12U) == 0)
section = SECTION_MOBILE_GPS;
else if (::strncmp(buffer, "[Remote Commands]", 17U) == 0)
section = SECTION_REMOTE_COMMANDS;
else
section = SECTION_NONE;
@ -230,6 +235,11 @@ bool CConf::read()
m_mobileGPSAddress = value;
else if (::strcmp(key, "Port") == 0)
m_mobileGPSPort = (unsigned int)::atoi(value);
} else if (section == SECTION_REMOTE_COMMANDS) {
if (::strcmp(key, "Enable") == 0)
m_remoteCommandsEnabled = ::atoi(value) == 1;
else if (::strcmp(key, "Port") == 0)
m_remoteCommandsPort = (unsigned int)::atoi(value);
}
}
@ -448,3 +458,12 @@ unsigned int CConf::getMobileGPSPort() const
return m_mobileGPSPort;
}
bool CConf::getRemoteCommandsEnabled() const
{
return m_remoteCommandsEnabled;
}
unsigned int CConf::getRemoteCommandsPort() const
{
return m_remoteCommandsPort;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2015,2016,2017,2018 by Jonathan Naylor G4KLX
* Copyright (C) 2015,2016,2017,2018,2020 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
@ -84,9 +84,13 @@ public:
bool getNetworkDebug() const;
// The Mobile GPS section
bool getMobileGPSEnabled() const;
std::string getMobileGPSAddress() const;
unsigned int getMobileGPSPort() const;
bool getMobileGPSEnabled() const;
std::string getMobileGPSAddress() const;
unsigned int getMobileGPSPort() const;
// The Remote Commands section
bool getRemoteCommandsEnabled() const;
unsigned int getRemoteCommandsPort() const;
private:
std::string m_file;
@ -139,6 +143,9 @@ private:
bool m_mobileGPSEnabled;
std::string m_mobileGPSAddress;
unsigned int m_mobileGPSPort;
bool m_remoteCommandsEnabled;
unsigned int m_remoteCommandsPort;
};
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016,2017,2018 by Jonathan Naylor G4KLX
* Copyright (C) 2016,2017,2018,2020 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
@ -27,6 +27,7 @@
#include "Thread.h"
#include "Voice.h"
#include "Timer.h"
#include "Utils.h"
#include "Log.h"
#if defined(_WIN32) || defined(_WIN64)
@ -179,6 +180,16 @@ void CNXDNGateway::run()
createGPS();
CUDPSocket* remoteSocket = NULL;
if (m_conf.getRemoteCommandsEnabled()) {
remoteSocket = new CUDPSocket(m_conf.getRemoteCommandsPort());
ret = remoteSocket->open();
if (!ret) {
delete remoteSocket;
remoteSocket = NULL;
}
}
CIcomNetwork localNetwork(m_conf.getMyPort(), m_conf.getRptDebug());
ret = localNetwork.open();
if (!ret) {
@ -389,6 +400,79 @@ startupId = 9999U;
reflectors.clock(ms);
if (remoteSocket != NULL) {
int res = remoteSocket->read(buffer, 200U, address, port);
if (res > 0) {
buffer[res] = '\0';
if (::memcmp(buffer + 0U, "TalkGroup", 9U) == 0) {
unsigned int tg = (unsigned int)::atoi((char*)(buffer + 9U));
CNXDNReflector* reflector = NULL;
if (tg != 9999U)
reflector = reflectors.find(tg);
if (reflector == NULL && currentId != 9999U) {
LogMessage("Unlinked from reflector %u by remote command", currentId);
if (voice != NULL)
voice->unlinked();
remoteNetwork.writeUnlink(currentAddr, currentPort, currentId);
remoteNetwork.writeUnlink(currentAddr, currentPort, currentId);
remoteNetwork.writeUnlink(currentAddr, currentPort, currentId);
inactivityTimer.stop();
pollTimer.stop();
lostTimer.stop();
currentId = 9999U;
} else if (reflector != NULL && currentId == 9999U) {
currentId = tg;
currentAddr = reflector->m_address;
currentPort = reflector->m_port;
LogMessage("Linked to reflector %u by remote command", currentId);
if (voice != NULL)
voice->linkedTo(currentId);
remoteNetwork.writePoll(currentAddr, currentPort, currentId);
remoteNetwork.writePoll(currentAddr, currentPort, currentId);
remoteNetwork.writePoll(currentAddr, currentPort, currentId);
inactivityTimer.start();
pollTimer.start();
lostTimer.start();
} else if (reflector != NULL && currentId != 9999U) {
LogMessage("Unlinked from reflector %u by remote command", currentId);
remoteNetwork.writeUnlink(currentAddr, currentPort, currentId);
remoteNetwork.writeUnlink(currentAddr, currentPort, currentId);
remoteNetwork.writeUnlink(currentAddr, currentPort, currentId);
currentId = tg;
currentAddr = reflector->m_address;
currentPort = reflector->m_port;
LogMessage("Linked to reflector %u by remote command", currentId);
if (voice != NULL)
voice->linkedTo(currentId);
remoteNetwork.writePoll(currentAddr, currentPort, currentId);
remoteNetwork.writePoll(currentAddr, currentPort, currentId);
remoteNetwork.writePoll(currentAddr, currentPort, currentId);
inactivityTimer.start();
pollTimer.start();
lostTimer.start();
}
} else {
CUtils::dump("Invalid remote command received", buffer, res);
}
}
}
if (voice != NULL)
voice->clock(ms);
@ -469,6 +553,11 @@ startupId = 9999U;
delete voice;
if (remoteSocket != NULL) {
remoteSocket->close();
delete remoteSocket;
}
localNetwork.close();
remoteNetwork.close();

View File

@ -57,3 +57,6 @@ Enable=0
Address=127.0.0.1
Port=7834
[Remote Commands]
Enable=0
Port=6075

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2015,2016,2017,2018 by Jonathan Naylor G4KLX
* Copyright (C) 2015,2016,2017,2018,2020 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
@ -19,6 +19,6 @@
#if !defined(VERSION_H)
#define VERSION_H
const char* VERSION = "20180524";
const char* VERSION = "20200403";
#endif