Skip to content

Commit

Permalink
Add remote control interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Naylor committed Jan 7, 2019
1 parent 5de3bee commit 42a4820
Show file tree
Hide file tree
Showing 15 changed files with 187 additions and 12 deletions.
25 changes: 22 additions & 3 deletions Conf.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015,2016,2017,2018 by Jonathan Naylor G4KLX
* Copyright (C) 2015-2019 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 @@ -56,7 +56,8 @@ enum SECTION {
SECTION_OLED,
SECTION_LCDPROC,
SECTION_LOCK_FILE,
SECTION_MOBILE_GPS
SECTION_MOBILE_GPS,
SECTION_REMOTE_CONTROL
};

CConf::CConf(const std::string& file) :
Expand Down Expand Up @@ -246,7 +247,9 @@ m_lockFileEnabled(false),
m_lockFileName(),
m_mobileGPSEnabled(false),
m_mobileGPSAddress(),
m_mobileGPSPort(0U)
m_mobileGPSPort(0U),
m_remoteControlEnabled(false),
m_remoteControlPort(0U)
{
}

Expand Down Expand Up @@ -326,6 +329,8 @@ bool CConf::read()
section = SECTION_LOCK_FILE;
else if (::strncmp(buffer, "[Mobile GPS]", 12U) == 0)
section = SECTION_MOBILE_GPS;
else if (::strncmp(buffer, "[Remote Control]", 16U) == 0)
section = SECTION_REMOTE_CONTROL;
else
section = SECTION_NONE;

Expand Down Expand Up @@ -813,6 +818,11 @@ bool CConf::read()
m_mobileGPSAddress = value;
else if (::strcmp(key, "Port") == 0)
m_mobileGPSPort = (unsigned int)::atoi(value);
} else if (section == SECTION_REMOTE_CONTROL) {
if (::strcmp(key, "Enable") == 0)
m_remoteControlEnabled = ::atoi(value) == 1;
else if (::strcmp(key, "Port") == 0)
m_remoteControlPort = (unsigned int)::atoi(value);
}
}

Expand Down Expand Up @@ -1756,3 +1766,12 @@ unsigned int CConf::getMobileGPSPort() const
return m_mobileGPSPort;
}

bool CConf::getRemoteControlEnabled() const
{
return m_remoteControlEnabled;
}

unsigned int CConf::getRemoteControlPort() const
{
return m_remoteControlPort;
}
9 changes: 8 additions & 1 deletion Conf.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015,2016,2017,2018 by Jonathan Naylor G4KLX
* Copyright (C) 2015-2019 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 @@ -273,6 +273,10 @@ class CConf
std::string getMobileGPSAddress() const;
unsigned int getMobileGPSPort() const;

// The Remote Control section
bool getRemoteControlEnabled() const;
unsigned int getRemoteControlPort() const;

private:
std::string m_file;
std::string m_callsign;
Expand Down Expand Up @@ -489,6 +493,9 @@ class CConf
bool m_mobileGPSEnabled;
std::string m_mobileGPSAddress;
unsigned int m_mobileGPSPort;

bool m_remoteControlEnabled;
unsigned int m_remoteControlPort;
};

#endif
3 changes: 3 additions & 0 deletions MMDVM.ini
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,6 @@ Enable=0
Address=127.0.0.1
Port=7834

[Remote Control]
Enable=0
Port=7642
36 changes: 35 additions & 1 deletion MMDVMHost.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015,2016,2017,2018 by Jonathan Naylor G4KLX
* Copyright (C) 2015-2019 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 @@ -28,6 +28,7 @@
#include "P25Control.h"
#include "NXDNControl.h"
#include "POCSAGControl.h"
#include "RemoteControl.h"
#include "Thread.h"
#include "Log.h"
#include "GitVersion.h"
Expand Down Expand Up @@ -582,6 +583,23 @@ int CMMDVMHost::run()
pocsagTimer.start();
}

CRemoteControl* remoteControl = NULL;
bool remoteControlEnabled = m_conf.getRemoteControlEnabled();
if (remoteControlEnabled) {
unsigned int port = m_conf.getRemoteControlPort();

LogInfo("Remote Control Parameters");
LogInfo(" Port; %u", port);

remoteControl = new CRemoteControl(port);

ret = remoteControl->open();
if (!ret) {
delete remoteControl;
remoteControl = NULL;
}
}

setMode(MODE_IDLE);

LogMessage("MMDVMHost-%s is running", VERSION);
Expand Down Expand Up @@ -908,6 +926,17 @@ int CMMDVMHost::run()
m_modem->writeTransparentData(data, len);
}

if (remoteControl != NULL) {
REMOTE_COMMAND command = remoteControl->getCommand();
switch(command) {
case RC_FORCE_IDLE:
setMode(MODE_IDLE);
break;
default:
break;
}
}

unsigned int ms = stopWatch.elapsed();
stopWatch.start();

Expand Down Expand Up @@ -1051,6 +1080,11 @@ int CMMDVMHost::run()
delete transparentSocket;
}

if (remoteControl != NULL) {
remoteControl->close();
delete remoteControl;
}

delete dstar;
delete dmr;
delete ysf;
Expand Down
2 changes: 2 additions & 0 deletions MMDVMHost.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@
<ClInclude Include="POCSAGDefines.h" />
<ClInclude Include="POCSAGNetwork.h" />
<ClInclude Include="QR1676.h" />
<ClInclude Include="RemoteControl.h" />
<ClInclude Include="RingBuffer.h" />
<ClInclude Include="RS129.h" />
<ClInclude Include="RS241213.h" />
Expand Down Expand Up @@ -308,6 +309,7 @@
<ClCompile Include="POCSAGControl.cpp" />
<ClCompile Include="POCSAGNetwork.cpp" />
<ClCompile Include="QR1676.cpp" />
<ClCompile Include="RemoteControl.cpp" />
<ClCompile Include="RS129.cpp" />
<ClCompile Include="RS241213.cpp" />
<ClCompile Include="RSSIInterpolator.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions MMDVMHost.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
<ClInclude Include="QR1676.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RemoteControl.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RingBuffer.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -331,6 +334,9 @@
<ClCompile Include="QR1676.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="RemoteControl.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="RS129.cpp">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ OBJECTS = \
DStarSlowData.o Golay2087.o Golay24128.o Hamming.o I2CController.o LCDproc.o Log.o MMDVMHost.o MobileGPS.o Modem.o ModemSerialPort.o Mutex.o \
NetworkInfo.o Nextion.o NullDisplay.o NullModem.o NXDNAudio.o NXDNControl.o NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNLayer3.o NXDNLICH.o \
NXDNLookup.o NXDNNetwork.o NXDNSACCH.o NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o P25Trellis.o P25Utils.o \
POCSAGControl.o POCSAGNetwork.o QR1676.o RS129.o RS241213.o RSSIInterpolator.o SerialController.o SerialPort.o SHA256.o StopWatch.o Sync.o TFTSerial.o \
POCSAGControl.o POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o SerialController.o SerialPort.o SHA256.o StopWatch.o Sync.o TFTSerial.o \
Thread.o Timer.o UDPSocket.o UMP.o Utils.o YSFControl.o YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o

all: MMDVMHost
Expand Down
2 changes: 1 addition & 1 deletion Makefile.Pi
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ OBJECTS = \
DStarSlowData.o Golay2087.o Golay24128.o Hamming.o I2CController.o LCDproc.o Log.o MMDVMHost.o MobileGPS.o Modem.o ModemSerialPort.o Mutex.o \
NetworkInfo.o Nextion.o NullDisplay.o NullModem.o NXDNAudio.o NXDNControl.o NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNLayer3.o NXDNLICH.o NXDNLookup.o \
NXDNNetwork.o NXDNSACCH.o NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o P25Trellis.o P25Utils.o POCSAGControl.o \
POCSAGNetwork.o QR1676.o RS129.o RS241213.o RSSIInterpolator.o SerialController.o SerialPort.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o Timer.o \
POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o SerialController.o SerialPort.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o Timer.o \
UDPSocket.o UMP.o Utils.o YSFControl.o YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o

all: MMDVMHost
Expand Down
2 changes: 1 addition & 1 deletion Makefile.Pi.Adafruit
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ OBJECTS = \
DStarSlowData.o Golay2087.o Golay24128.o Hamming.o HD44780.o I2CController.o LCDproc.o Log.o MMDVMHost.o MobileGPS.o Modem.o ModemSerialPort.o Mutex.o \
NetworkInfo.o Nextion.o NullDisplay.o NullModem.o NXDNAudio.o NXDNControl.o NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNLayer3.o NXDNLICH.o NXDNLookup.o \
NXDNNetwork.o NXDNSACCH.o NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o P25Trellis.o P25Utils.o POCSAGControl.o \
POCSAGNetwork.o QR1676.o RS129.o RS241213.o RSSIInterpolator.o SerialController.o SerialPort.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o \
POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o SerialController.o SerialPort.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o \
Timer.o UDPSocket.o UMP.o Utils.o YSFControl.o YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o

all: MMDVMHost
Expand Down
2 changes: 1 addition & 1 deletion Makefile.Pi.HD44780
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ OBJECTS = \
DStarSlowData.o Golay2087.o Golay24128.o Hamming.o HD44780.o I2CController.o LCDproc.o Log.o MMDVMHost.o MobileGPS.o Modem.o ModemSerialPort.o Mutex.o \
NetworkInfo.o Nextion.o NullDisplay.o NullModem.o NXDNAudio.o NXDNControl.o NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNLayer3.o NXDNLICH.o NXDNLookup.o \
NXDNNetwork.o NXDNSACCH.o NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o P25Trellis.o P25Utils.o POCSAGControl.o \
POCSAGNetwork.o QR1676.o RS129.o RS241213.o RSSIInterpolator.o SerialController.o SerialPort.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o \
POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o SerialController.o SerialPort.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o \
Timer.o UDPSocket.o UMP.o Utils.o YSFControl.o YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o

all: MMDVMHost
Expand Down
2 changes: 1 addition & 1 deletion Makefile.Pi.OLED
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ OBJECTS = \
DStarSlowData.o Golay2087.o Golay24128.o Hamming.o I2CController.o OLED.o LCDproc.o Log.o MMDVMHost.o MobileGPS.o Modem.o ModemSerialPort.o Mutex.o \
NetworkInfo.o Nextion.o NullDisplay.o NullModem.o NXDNAudio.o NXDNControl.o NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNLayer3.o NXDNLICH.o NXDNLookup.o \
NXDNNetwork.o NXDNSACCH.o NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o P25Trellis.o P25Utils.o POCSAGControl.o \
POCSAGNetwork.o QR1676.o RS129.o RS241213.o RSSIInterpolator.o SerialController.o SerialPort.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o \
POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o SerialController.o SerialPort.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o \
Timer.o UDPSocket.o UMP.o Utils.o YSFControl.o YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o

all: MMDVMHost
Expand Down
2 changes: 1 addition & 1 deletion Makefile.Pi.PCF8574
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ OBJECTS = \
DStarSlowData.o Golay2087.o Golay24128.o Hamming.o HD44780.o I2CController.o LCDproc.o Log.o MMDVMHost.o MobileGPS.o Modem.o ModemSerialPort.o Mutex.o \
NetworkInfo.o Nextion.o NullDisplay.o NullModem.o NXDNAudio.o NXDNControl.o NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNLayer3.o NXDNLICH.o NXDNLookup.o \
NXDNNetwork.o NXDNSACCH.o NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o P25Trellis.o P25Utils.o POCSAGControl.o \
POCSAGNetwork.o QR1676.o RS129.o RS241213.o RSSIInterpolator.o SerialController.o SerialPort.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o \
POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o SerialController.o SerialPort.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o \
Timer.o UDPSocket.o UMP.o Utils.o YSFControl.o YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o

all: MMDVMHost
Expand Down
2 changes: 1 addition & 1 deletion Makefile.Solaris
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ OBJECTS = \
DStarSlowData.o Golay2087.o Golay24128.o Hamming.o LCDproc.o Log.o MMDVMHost.o MobileGPS.o Modem.o ModemSerialPort.o Mutex.o NetworkInfo.o Nextion.o \
NullDisplay.o NullModem.o NXDNAudio.o NXDNControl.o NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNLayer3.o NXDNLICH.o NXDNLookup.o NXDNNetwork.o \
NXDNSACCH.o NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o P25Trellis.o P25Utils.o POCSAGControl.o POCSAGNetwork.o \
QR1676.o RS129.o RS241213.o RSSIInterpolator.o SerialController.o SerialPort.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o Timer.o UDPSocket.o \
QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o SerialController.o SerialPort.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o Timer.o UDPSocket.o \
UMP.o Utils.o YSFControl.o YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o

all: MMDVMHost
Expand Down
60 changes: 60 additions & 0 deletions RemoteControl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2019 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "RemoteControl.h"

#include <cstdio>
#include <cassert>

const unsigned int BUFFER_LENGTH = 100U;

CRemoteControl::CRemoteControl(unsigned int port) :
m_socket(port)
{
assert(port > 0U);
}

CRemoteControl::~CRemoteControl()
{
}

bool CRemoteControl::open()
{
return m_socket.open();
}

REMOTE_COMMAND CRemoteControl::getCommand()
{
REMOTE_COMMAND command = RC_NONE;

unsigned char buffer[BUFFER_LENGTH];
in_addr address;
unsigned int port;
int ret = m_socket.read(buffer, BUFFER_LENGTH, address, port);
if (ret > 0) {
if (::memcmp(buffer, "0", 1U) == 0)
command = RC_FORCE_IDLE;
}

return command;
}

void CRemoteControl::close()
{
m_socket.close();
}
44 changes: 44 additions & 0 deletions RemoteControl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2019 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef RemoteControl_H
#define RemoteControl_H

#include "UDPSocket.h"

enum REMOTE_COMMAND {
RC_NONE,
RC_FORCE_IDLE
};

class CRemoteControl {
public:
CRemoteControl(unsigned int port);
~CRemoteControl();

bool open();

REMOTE_COMMAND getCommand();

void close();

private:
CUDPSocket m_socket;
};

#endif

0 comments on commit 42a4820

Please sign in to comment.