First version of the remote commands handler.
This commit is contained in:
parent
031d47816c
commit
785faa7ad9
|
@ -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
|
* 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
|
||||||
|
@ -35,7 +35,8 @@ enum SECTION {
|
||||||
SECTION_LOG,
|
SECTION_LOG,
|
||||||
SECTION_APRS_FI,
|
SECTION_APRS_FI,
|
||||||
SECTION_NETWORK,
|
SECTION_NETWORK,
|
||||||
SECTION_MOBILE_GPS
|
SECTION_MOBILE_GPS,
|
||||||
|
SECTION_REMOTE_COMMANDS
|
||||||
};
|
};
|
||||||
|
|
||||||
CConf::CConf(const std::string& file) :
|
CConf::CConf(const std::string& file) :
|
||||||
|
@ -81,7 +82,9 @@ m_networkInactivityTimeout(0U),
|
||||||
m_networkDebug(false),
|
m_networkDebug(false),
|
||||||
m_mobileGPSEnabled(false),
|
m_mobileGPSEnabled(false),
|
||||||
m_mobileGPSAddress(),
|
m_mobileGPSAddress(),
|
||||||
m_mobileGPSPort(0U)
|
m_mobileGPSPort(0U),
|
||||||
|
m_remoteCommandsEnabled(false),
|
||||||
|
m_remoteCommandsPort(6075U)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,6 +124,8 @@ bool CConf::read()
|
||||||
section = SECTION_NETWORK;
|
section = SECTION_NETWORK;
|
||||||
else if (::strncmp(buffer, "[Mobile GPS]", 12U) == 0)
|
else if (::strncmp(buffer, "[Mobile GPS]", 12U) == 0)
|
||||||
section = SECTION_MOBILE_GPS;
|
section = SECTION_MOBILE_GPS;
|
||||||
|
else if (::strncmp(buffer, "[Remote Commands]", 17U) == 0)
|
||||||
|
section = SECTION_REMOTE_COMMANDS;
|
||||||
else
|
else
|
||||||
section = SECTION_NONE;
|
section = SECTION_NONE;
|
||||||
|
|
||||||
|
@ -230,6 +235,11 @@ bool CConf::read()
|
||||||
m_mobileGPSAddress = value;
|
m_mobileGPSAddress = value;
|
||||||
else if (::strcmp(key, "Port") == 0)
|
else if (::strcmp(key, "Port") == 0)
|
||||||
m_mobileGPSPort = (unsigned int)::atoi(value);
|
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;
|
return m_mobileGPSPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CConf::getRemoteCommandsEnabled() const
|
||||||
|
{
|
||||||
|
return m_remoteCommandsEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int CConf::getRemoteCommandsPort() const
|
||||||
|
{
|
||||||
|
return m_remoteCommandsPort;
|
||||||
|
}
|
||||||
|
|
|
@ -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
|
* 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
|
||||||
|
@ -84,9 +84,13 @@ public:
|
||||||
bool getNetworkDebug() const;
|
bool getNetworkDebug() const;
|
||||||
|
|
||||||
// The Mobile GPS section
|
// The Mobile GPS section
|
||||||
bool getMobileGPSEnabled() const;
|
bool getMobileGPSEnabled() const;
|
||||||
std::string getMobileGPSAddress() const;
|
std::string getMobileGPSAddress() const;
|
||||||
unsigned int getMobileGPSPort() const;
|
unsigned int getMobileGPSPort() const;
|
||||||
|
|
||||||
|
// The Remote Commands section
|
||||||
|
bool getRemoteCommandsEnabled() const;
|
||||||
|
unsigned int getRemoteCommandsPort() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_file;
|
std::string m_file;
|
||||||
|
@ -139,6 +143,9 @@ private:
|
||||||
bool m_mobileGPSEnabled;
|
bool m_mobileGPSEnabled;
|
||||||
std::string m_mobileGPSAddress;
|
std::string m_mobileGPSAddress;
|
||||||
unsigned int m_mobileGPSPort;
|
unsigned int m_mobileGPSPort;
|
||||||
|
|
||||||
|
bool m_remoteCommandsEnabled;
|
||||||
|
unsigned int m_remoteCommandsPort;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -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
|
* 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
|
||||||
|
@ -27,6 +27,7 @@
|
||||||
#include "Thread.h"
|
#include "Thread.h"
|
||||||
#include "Voice.h"
|
#include "Voice.h"
|
||||||
#include "Timer.h"
|
#include "Timer.h"
|
||||||
|
#include "Utils.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
|
@ -179,6 +180,16 @@ void CNXDNGateway::run()
|
||||||
|
|
||||||
createGPS();
|
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());
|
CIcomNetwork localNetwork(m_conf.getMyPort(), m_conf.getRptDebug());
|
||||||
ret = localNetwork.open();
|
ret = localNetwork.open();
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
|
@ -389,6 +400,79 @@ startupId = 9999U;
|
||||||
|
|
||||||
reflectors.clock(ms);
|
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)
|
if (voice != NULL)
|
||||||
voice->clock(ms);
|
voice->clock(ms);
|
||||||
|
|
||||||
|
@ -469,6 +553,11 @@ startupId = 9999U;
|
||||||
|
|
||||||
delete voice;
|
delete voice;
|
||||||
|
|
||||||
|
if (remoteSocket != NULL) {
|
||||||
|
remoteSocket->close();
|
||||||
|
delete remoteSocket;
|
||||||
|
}
|
||||||
|
|
||||||
localNetwork.close();
|
localNetwork.close();
|
||||||
|
|
||||||
remoteNetwork.close();
|
remoteNetwork.close();
|
||||||
|
|
|
@ -57,3 +57,6 @@ Enable=0
|
||||||
Address=127.0.0.1
|
Address=127.0.0.1
|
||||||
Port=7834
|
Port=7834
|
||||||
|
|
||||||
|
[Remote Commands]
|
||||||
|
Enable=0
|
||||||
|
Port=6075
|
||||||
|
|
|
@ -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
|
* 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
|
||||||
|
@ -19,6 +19,6 @@
|
||||||
#if !defined(VERSION_H)
|
#if !defined(VERSION_H)
|
||||||
#define VERSION_H
|
#define VERSION_H
|
||||||
|
|
||||||
const char* VERSION = "20180524";
|
const char* VERSION = "20200403";
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue