mirror of
https://github.com/g4klx/MMDVMHost
synced 2025-12-21 23:45:49 +08:00
Add support for passthrough of serial data from MQTT to the spare serial port on an MMDVM modem/hotspot.
This commit is contained in:
@@ -1191,6 +1191,10 @@ int CMMDVMHost::run()
|
|||||||
m_modem->writeTransparentData(data, len);
|
m_modem->writeTransparentData(data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
len = m_modem->readSerialData(data);
|
||||||
|
if (len > 0U)
|
||||||
|
m_mqtt->publish("display", data, len);
|
||||||
|
|
||||||
unsigned int ms = stopWatch.elapsed();
|
unsigned int ms = stopWatch.elapsed();
|
||||||
stopWatch.start();
|
stopWatch.start();
|
||||||
|
|
||||||
@@ -2784,6 +2788,13 @@ void CMMDVMHost::writeJSONMessage(const std::string& message)
|
|||||||
WriteJSON("MMDVM", json);
|
WriteJSON("MMDVM", json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CMMDVMHost::writeSerial(const std::string& message)
|
||||||
|
{
|
||||||
|
assert(m_modem != NULL);
|
||||||
|
|
||||||
|
m_modem->writeSerialData((unsigned char*)message.c_str(), message.length());
|
||||||
|
}
|
||||||
|
|
||||||
void CMMDVMHost::onCommand(const std::string& command)
|
void CMMDVMHost::onCommand(const std::string& command)
|
||||||
{
|
{
|
||||||
assert(host != NULL);
|
assert(host != NULL);
|
||||||
@@ -2793,5 +2804,8 @@ void CMMDVMHost::onCommand(const std::string& command)
|
|||||||
|
|
||||||
void CMMDVMHost::onDisplay(const std::string& message)
|
void CMMDVMHost::onDisplay(const std::string& message)
|
||||||
{
|
{
|
||||||
|
assert(host != NULL);
|
||||||
|
|
||||||
|
host->writeSerial(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -131,6 +131,8 @@ private:
|
|||||||
bool createFMNetwork();
|
bool createFMNetwork();
|
||||||
bool createAX25Network();
|
bool createAX25Network();
|
||||||
|
|
||||||
|
void writeSerial(const std::string& message);
|
||||||
|
|
||||||
void remoteControl(const std::string& commandString);
|
void remoteControl(const std::string& commandString);
|
||||||
void processModeCommand(unsigned char mode, unsigned int timeout);
|
void processModeCommand(unsigned char mode, unsigned int timeout);
|
||||||
void processEnableCommand(bool& mode, bool enabled);
|
void processEnableCommand(bool& mode, bool enabled);
|
||||||
|
|||||||
@@ -199,7 +199,6 @@
|
|||||||
<ClInclude Include="M17Utils.h" />
|
<ClInclude Include="M17Utils.h" />
|
||||||
<ClInclude Include="MMDVMHost.h" />
|
<ClInclude Include="MMDVMHost.h" />
|
||||||
<ClInclude Include="ModemPort.h" />
|
<ClInclude Include="ModemPort.h" />
|
||||||
<ClInclude Include="ModemSerialPort.h" />
|
|
||||||
<ClInclude Include="Mutex.h" />
|
<ClInclude Include="Mutex.h" />
|
||||||
<ClInclude Include="NullController.h" />
|
<ClInclude Include="NullController.h" />
|
||||||
<ClInclude Include="NXDNAudio.h" />
|
<ClInclude Include="NXDNAudio.h" />
|
||||||
@@ -299,7 +298,6 @@
|
|||||||
<ClCompile Include="M17Utils.cpp" />
|
<ClCompile Include="M17Utils.cpp" />
|
||||||
<ClCompile Include="MMDVMHost.cpp" />
|
<ClCompile Include="MMDVMHost.cpp" />
|
||||||
<ClCompile Include="ModemPort.cpp" />
|
<ClCompile Include="ModemPort.cpp" />
|
||||||
<ClCompile Include="ModemSerialPort.cpp" />
|
|
||||||
<ClCompile Include="Mutex.cpp" />
|
<ClCompile Include="Mutex.cpp" />
|
||||||
<ClCompile Include="NullController.cpp" />
|
<ClCompile Include="NullController.cpp" />
|
||||||
<ClCompile Include="NXDNAudio.cpp" />
|
<ClCompile Include="NXDNAudio.cpp" />
|
||||||
|
|||||||
@@ -188,9 +188,6 @@
|
|||||||
<ClInclude Include="SerialPort.h">
|
<ClInclude Include="SerialPort.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="ModemSerialPort.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="Mutex.h">
|
<ClInclude Include="Mutex.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@@ -478,9 +475,6 @@
|
|||||||
<ClCompile Include="SerialPort.cpp">
|
<ClCompile Include="SerialPort.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="ModemSerialPort.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Mutex.cpp">
|
<ClCompile Include="Mutex.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|||||||
@@ -99,6 +99,26 @@ bool CMQTTConnection::publish(const char* topic, const char* text)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CMQTTConnection::publish(const char* topic, const unsigned char* data, unsigned int len)
|
||||||
|
{
|
||||||
|
assert(topic != NULL);
|
||||||
|
assert(data != NULL);
|
||||||
|
|
||||||
|
if (!m_connected)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
char topicEx[100U];
|
||||||
|
::sprintf(topicEx, "%s/%s", m_name.c_str(), topic);
|
||||||
|
|
||||||
|
int rc = ::mosquitto_publish(m_mosq, NULL, topicEx, len, data, static_cast<int>(m_qos), false);
|
||||||
|
if (rc != MOSQ_ERR_SUCCESS) {
|
||||||
|
::fprintf(stderr, "MQTT Error publishing: %s\n", ::mosquitto_strerror(rc));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void CMQTTConnection::close()
|
void CMQTTConnection::close()
|
||||||
{
|
{
|
||||||
if (m_mosq != NULL) {
|
if (m_mosq != NULL) {
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ public:
|
|||||||
bool open();
|
bool open();
|
||||||
|
|
||||||
bool publish(const char* topic, const char* text);
|
bool publish(const char* topic, const char* text);
|
||||||
|
bool publish(const char* topic, const unsigned char* data, unsigned int len);
|
||||||
|
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -11,7 +11,7 @@ OBJECTS = \
|
|||||||
DMREMB.o DMREmbeddedData.o DMRFullLC.o DMRLookup.o DMRLC.o DMRNetwork.o DMRShortLC.o DMRSlot.o DMRSlotType.o \
|
DMREMB.o DMREmbeddedData.o DMRFullLC.o DMRLookup.o DMRLC.o DMRNetwork.o DMRShortLC.o DMRSlot.o DMRSlotType.o \
|
||||||
DMRAccessControl.o DMRTA.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o FMControl.o FMNetwork.o Golay2087.o Golay24128.o \
|
DMRAccessControl.o DMRTA.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o FMControl.o FMNetwork.o Golay2087.o Golay24128.o \
|
||||||
Hamming.o I2CController.o IIRDirectForm1Filter.o Log.o M17Control.o M17Convolution.o M17CRC.o M17LSF.o M17Network.o M17Utils.o MMDVMHost.o \
|
Hamming.o I2CController.o IIRDirectForm1Filter.o Log.o M17Control.o M17Convolution.o M17CRC.o M17LSF.o M17Network.o M17Utils.o MMDVMHost.o \
|
||||||
MQTTConnection.o Modem.o ModemPort.o ModemSerialPort.o Mutex.o NullController.o NXDNAudio.o NXDNControl.o \
|
MQTTConnection.o Modem.o ModemPort.o Mutex.o NullController.o NXDNAudio.o NXDNControl.o \
|
||||||
NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNIcomNetwork.o NXDNKenwoodNetwork.o NXDNLayer3.o NXDNLICH.o NXDNLookup.o NXDNNetwork.o NXDNSACCH.o \
|
NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNIcomNetwork.o NXDNKenwoodNetwork.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 PseudoTTYController.o POCSAGControl.o \
|
NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o P25Trellis.o P25Utils.o PseudoTTYController.o POCSAGControl.o \
|
||||||
POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o SerialPort.o StopWatch.o Sync.o SHA256.o Thread.o \
|
POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o SerialPort.o StopWatch.o Sync.o SHA256.o Thread.o \
|
||||||
|
|||||||
31
Modem.cpp
31
Modem.cpp
@@ -898,10 +898,15 @@ void CModem::clock(unsigned int ms)
|
|||||||
printDebug();
|
printDebug();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MMDVM_SERIAL_DATA:
|
case MMDVM_SERIAL_DATA: {
|
||||||
if (m_trace)
|
if (m_trace)
|
||||||
CUtils::dump(1U, "RX Serial Data", m_buffer, m_length);
|
CUtils::dump(1U, "RX Serial Data", m_buffer, m_length);
|
||||||
m_rxSerialData.addData(m_buffer + m_offset, m_length - m_offset);
|
|
||||||
|
unsigned char data = m_length - m_offset;
|
||||||
|
m_rxSerialData.addData(&data, 1U);
|
||||||
|
|
||||||
|
m_rxSerialData.addData(m_buffer + m_offset, m_length - m_offset);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -1301,18 +1306,18 @@ unsigned int CModem::readTransparentData(unsigned char* data)
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int CModem::readSerial(unsigned char* data, unsigned int length)
|
unsigned int CModem::readSerialData(unsigned char* data)
|
||||||
{
|
{
|
||||||
assert(data != NULL);
|
assert(data != NULL);
|
||||||
assert(length > 0U);
|
|
||||||
|
|
||||||
unsigned int n = 0U;
|
if (m_rxSerialData.isEmpty())
|
||||||
while (!m_rxSerialData.isEmpty() && n < length) {
|
return 0U;
|
||||||
m_rxSerialData.getData(data + n, 1U);
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return n;
|
unsigned char len = 0U;
|
||||||
|
m_rxSerialData.getData(&len, 1U);
|
||||||
|
m_rxSerialData.getData(data, len);
|
||||||
|
|
||||||
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CModem::hasDStarSpace() const
|
bool CModem::hasDStarSpace() const
|
||||||
@@ -1879,7 +1884,7 @@ bool CModem::writeIPInfo(const std::string& address)
|
|||||||
return ret != int(length + 4U);
|
return ret != int(length + 4U);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CModem::writeSerial(const unsigned char* data, unsigned int length)
|
bool CModem::writeSerialData(const unsigned char* data, unsigned int length)
|
||||||
{
|
{
|
||||||
assert(m_port != NULL);
|
assert(m_port != NULL);
|
||||||
assert(data != NULL);
|
assert(data != NULL);
|
||||||
|
|||||||
6
Modem.h
6
Modem.h
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2011-2018,2020,2021 by Jonathan Naylor G4KLX
|
* Copyright (C) 2011-2018,2020,2021,2023 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
|
||||||
@@ -131,8 +131,8 @@ public:
|
|||||||
bool writeTransparentData(const unsigned char* data, unsigned int length);
|
bool writeTransparentData(const unsigned char* data, unsigned int length);
|
||||||
unsigned int readTransparentData(unsigned char* data);
|
unsigned int readTransparentData(unsigned char* data);
|
||||||
|
|
||||||
bool writeSerial(const unsigned char* data, unsigned int length);
|
bool writeSerialData(const unsigned char* data, unsigned int length);
|
||||||
unsigned int readSerial(unsigned char* data, unsigned int length);
|
unsigned int readSerialData(unsigned char* data);
|
||||||
|
|
||||||
unsigned char getMode() const;
|
unsigned char getMode() const;
|
||||||
bool setMode(unsigned char mode);
|
bool setMode(unsigned char mode);
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016,2020,2021 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 "ModemSerialPort.h"
|
|
||||||
|
|
||||||
#include <cstdio>
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
IModemSerialPort::IModemSerialPort(CModem* modem) :
|
|
||||||
m_modem(modem)
|
|
||||||
{
|
|
||||||
assert(modem != NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
IModemSerialPort::~IModemSerialPort()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IModemSerialPort::open()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int IModemSerialPort::write(const unsigned char* data, unsigned int length)
|
|
||||||
{
|
|
||||||
assert(data != NULL);
|
|
||||||
assert(length > 0U);
|
|
||||||
|
|
||||||
bool ret = m_modem->writeSerial(data, length);
|
|
||||||
|
|
||||||
return ret ? int(length) : -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int IModemSerialPort::read(unsigned char* data, unsigned int length)
|
|
||||||
{
|
|
||||||
assert(data != NULL);
|
|
||||||
assert(length > 0U);
|
|
||||||
|
|
||||||
return m_modem->readSerial(data, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
void IModemSerialPort::close()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016,2020,2021 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 ModemSerialPort_H
|
|
||||||
#define ModemSerialPort_H
|
|
||||||
|
|
||||||
#include "SerialPort.h"
|
|
||||||
#include "Modem.h"
|
|
||||||
|
|
||||||
class IModemSerialPort : public ISerialPort {
|
|
||||||
public:
|
|
||||||
IModemSerialPort(CModem* modem);
|
|
||||||
virtual ~IModemSerialPort();
|
|
||||||
|
|
||||||
virtual bool open();
|
|
||||||
|
|
||||||
virtual int read(unsigned char* buffer, unsigned int length);
|
|
||||||
|
|
||||||
virtual int write(const unsigned char* buffer, unsigned int length);
|
|
||||||
|
|
||||||
virtual void close();
|
|
||||||
|
|
||||||
private:
|
|
||||||
CModem* m_modem;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Reference in New Issue
Block a user