diff --git a/MMDVM.ini b/MMDVM.ini
index b31416ad4..31ed9f44b 100644
--- a/MMDVM.ini
+++ b/MMDVM.ini
@@ -125,6 +125,7 @@ LocalPort=20013
Debug=0
[TFT Serial]
+# Port=modem
Port=/dev/ttyAMA0
Brightness=50
@@ -149,6 +150,7 @@ DisplayClock=1
UTC=0
[Nextion]
+# Port=modem
Port=/dev/ttyAMA0
Brightness=50
DisplayClock=1
diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp
index a54a8ae83..38650968a 100644
--- a/MMDVMHost.cpp
+++ b/MMDVMHost.cpp
@@ -17,7 +17,8 @@
*/
#include "MMDVMHost.h"
-#include "Log.h"
+#include "SerialController.h"
+#include "ModemSerialPort.h"
#include "Version.h"
#include "StopWatch.h"
#include "Defines.h"
@@ -30,6 +31,7 @@
#include "P25Control.h"
#include "Nextion.h"
#include "Thread.h"
+#include "Log.h"
#if defined(HD44780)
#include "HD44780.h"
@@ -974,7 +976,7 @@ void CMMDVMHost::readParams()
void CMMDVMHost::createDisplay()
{
- std::string type = m_conf.getDisplay();
+ std::string type = m_conf.getDisplay();
unsigned int dmrid = m_conf.getDMRId();
LogInfo("Display Parameters");
@@ -987,7 +989,13 @@ void CMMDVMHost::createDisplay()
LogInfo(" Port: %s", port.c_str());
LogInfo(" Brightness: %u", brightness);
- m_display = new CTFTSerial(m_callsign, dmrid, port, brightness);
+ ISerialPort* serial = NULL;
+ if (port == "modem")
+ serial = new CModemSerialPort(m_modem);
+ else
+ serial = new CSerialController(port, SERIAL_9600);
+
+ m_display = new CTFTSerial(m_callsign, dmrid, serial, brightness);
} else if (type == "Nextion") {
std::string port = m_conf.getNextionPort();
unsigned int brightness = m_conf.getNextionBrightness();
@@ -1002,7 +1010,13 @@ void CMMDVMHost::createDisplay()
LogInfo(" Display UTC: %s", utc ? "yes" : "no");
LogInfo(" Idle Brightness: %u", idleBrightness);
- m_display = new CNextion(m_callsign, dmrid, port, brightness, displayClock, utc, idleBrightness);
+ ISerialPort* serial = NULL;
+ if (port == "modem")
+ serial = new CModemSerialPort(m_modem);
+ else
+ serial = new CSerialController(port, SERIAL_9600);
+
+ m_display = new CNextion(m_callsign, dmrid, serial, brightness, displayClock, utc, idleBrightness);
#if defined(HD44780)
} else if (type == "HD44780") {
unsigned int rows = m_conf.getHD44780Rows();
diff --git a/MMDVMHost.vcxproj b/MMDVMHost.vcxproj
index 87db1a4c8..2f4fadd0d 100644
--- a/MMDVMHost.vcxproj
+++ b/MMDVMHost.vcxproj
@@ -180,6 +180,7 @@
+
@@ -195,6 +196,7 @@
+
@@ -243,6 +245,7 @@
+
@@ -256,6 +259,7 @@
+
diff --git a/MMDVMHost.vcxproj.filters b/MMDVMHost.vcxproj.filters
index a189600ee..7aafe1338 100644
--- a/MMDVMHost.vcxproj.filters
+++ b/MMDVMHost.vcxproj.filters
@@ -203,6 +203,12 @@
Header Files
+
+ Header Files
+
+
+ Header Files
+
@@ -376,5 +382,11 @@
Source Files
+
+ Source Files
+
+
+ Source Files
+
\ No newline at end of file
diff --git a/Makefile b/Makefile
index ca7d2ade9..423ce9706 100644
--- a/Makefile
+++ b/Makefile
@@ -9,9 +9,9 @@ LDFLAGS = -g
OBJECTS = \
AMBEFEC.o BCH.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedLC.o DMRFullLC.o DMRLookup.o DMRLC.o \
DMRNetwork.o DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o \
- Golay24128.o Hamming.o Log.o MMDVMHost.o Modem.o Nextion.o NullDisplay.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o P25Utils.o \
- QR1676.o RS129.o RS241213.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o Timer.o UDPSocket.o Utils.o YSFControl.o YSFConvolution.o \
- YSFFICH.o YSFNetwork.o YSFPayload.o
+ Golay24128.o Hamming.o Log.o MMDVMHost.o Modem.o ModemSerialPort.o Nextion.o NullDisplay.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o \
+ P25NID.o P25Utils.o QR1676.o RS129.o RS241213.o SerialController.o SerialPort.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o Timer.o UDPSocket.o Utils.o \
+ YSFControl.o YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o
all: MMDVMHost
diff --git a/Makefile.Pi.Adafruit b/Makefile.Pi.Adafruit
index f1802d9a0..05a8fbdd0 100644
--- a/Makefile.Pi.Adafruit
+++ b/Makefile.Pi.Adafruit
@@ -9,9 +9,9 @@ LDFLAGS = -g -L/usr/local/lib
OBJECTS = \
AMBEFEC.o BCH.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedLC.o DMRFullLC.o DMRLookup.o DMRLC.o \
DMRNetwork.o DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o \
- Golay24128.o Hamming.o HD44780.o Log.o MMDVMHost.o Modem.o Nextion.o NullDisplay.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o \
- P25Utils.o QR1676.o RS129.o RS241213.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o Timer.o UDPSocket.o Utils.o YSFControl.o \
- YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o
+ Golay24128.o Hamming.o HD44780.o Log.o MMDVMHost.o Modem.o ModemSerialPort.o Nextion.o NullDisplay.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o \
+ P25Network.o P25NID.o P25Utils.o QR1676.o RS129.o RS241213.o SerialController.o SerialPort.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o Timer.o UDPSocket.o \
+ Utils.o YSFControl.o YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o
all: MMDVMHost
diff --git a/Makefile.Pi.HD44780 b/Makefile.Pi.HD44780
index 6a778d50c..dc07a5183 100644
--- a/Makefile.Pi.HD44780
+++ b/Makefile.Pi.HD44780
@@ -9,9 +9,9 @@ LDFLAGS = -g -L/usr/local/lib
OBJECTS = \
AMBEFEC.o BCH.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedLC.o DMRFullLC.o DMRLookup.o DMRLC.o \
DMRNetwork.o DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o \
- Golay24128.o Hamming.o HD44780.o Log.o MMDVMHost.o Modem.o Nextion.o NullDisplay.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o \
- P25Utils.o QR1676.o RS129.o RS241213.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o Timer.o UDPSocket.o Utils.o YSFControl.o \
- YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o
+ Golay24128.o Hamming.o HD44780.o Log.o MMDVMHost.o Modem.o ModemSerialPort.o Nextion.o NullDisplay.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o \
+ P25Network.o P25NID.o P25Utils.o QR1676.o RS129.o RS241213.o SerialController.o SerialPort.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o Timer.o UDPSocket.o \
+ Utils.o YSFControl.o YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o
all: MMDVMHost
diff --git a/Makefile.Pi.OLED b/Makefile.Pi.OLED
index a0a599ce4..e1bb144c3 100644
--- a/Makefile.Pi.OLED
+++ b/Makefile.Pi.OLED
@@ -9,9 +9,9 @@ LDFLAGS = -g -L/usr/local/lib
OBJECTS = \
AMBEFEC.o BCH.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedLC.o DMRFullLC.o DMRLookup.o DMRLC.o \
DMRNetwork.o DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o \
- Golay24128.o Hamming.o OLED.o Log.o MMDVMHost.o Modem.o Nextion.o NullDisplay.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o \
- P25Utils.o QR1676.o RS129.o RS241213.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o Timer.o UDPSocket.o Utils.o YSFControl.o \
- YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o
+ Golay24128.o Hamming.o OLED.o Log.o MMDVMHost.o Modem.o ModemSerialPort.o Nextion.o NullDisplay.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o \
+ P25NID.o P25Utils.o QR1676.o RS129.o RS241213.o SerialController.o SerialPort.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o Timer.o UDPSocket.o Utils.o \
+ YSFControl.o YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o
all: MMDVMHost
diff --git a/Makefile.Pi.PCF8574 b/Makefile.Pi.PCF8574
index c0f0ab503..3ec933884 100644
--- a/Makefile.Pi.PCF8574
+++ b/Makefile.Pi.PCF8574
@@ -9,9 +9,9 @@ LDFLAGS = -g -L/usr/local/lib
OBJECTS = \
AMBEFEC.o BCH.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedLC.o DMRFullLC.o DMRLookup.o DMRLC.o \
DMRNetwork.o DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o \
- Golay24128.o Hamming.o HD44780.o Log.o MMDVMHost.o Modem.o Nextion.o NullDisplay.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o \
- P25Utils.o QR1676.o RS129.o RS241213.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o Timer.o UDPSocket.o Utils.o YSFControl.o \
- YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o
+ Golay24128.o Hamming.o HD44780.o Log.o MMDVMHost.o Modem.o ModemSerialPort.o Nextion.o NullDisplay.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o \
+ P25Network.o P25NID.o P25Utils.o QR1676.o RS129.o RS241213.o SerialController.o SerialPort.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o Timer.o UDPSocket.o \
+ Utils.o YSFControl.o YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o
all: MMDVMHost
diff --git a/Makefile.Solaris b/Makefile.Solaris
index c0d6836ea..f47cdf428 100644
--- a/Makefile.Solaris
+++ b/Makefile.Solaris
@@ -9,9 +9,9 @@ LDFLAGS = -g
OBJECTS = \
AMBEFEC.o BCH.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedLC.o DMRFullLC.o DMRLookup.o DMRLC.o \
DMRNetwork.o DMRShortLC.o DMRSlot.o DMRSlotType.o DMRAccessControl.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o \
- Golay24128.o Hamming.o Log.o MMDVMHost.o Modem.o Nextion.o NullDisplay.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o P25Utils.o \
- QR1676.o RS129.o RS241213.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o Timer.o UDPSocket.o Utils.o YSFControl.o YSFConvolution.o \
- YSFFICH.o YSFNetwork.o YSFPayload.o
+ Golay24128.o Hamming.o Log.o MMDVMHost.o Modem.o ModemSerialPort.o Nextion.o NullDisplay.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o \
+ P25NID.o P25Utils.o QR1676.o RS129.o RS241213.o SerialController.o SerialPort.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o Timer.o UDPSocket.o Utils.o \
+ YSFControl.o YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o
all: MMDVMHost
diff --git a/Modem.cpp b/Modem.cpp
index c27262625..587247ab4 100644
--- a/Modem.cpp
+++ b/Modem.cpp
@@ -69,6 +69,8 @@ const unsigned char MMDVM_P25_LOST = 0x32U;
const unsigned char MMDVM_ACK = 0x70U;
const unsigned char MMDVM_NAK = 0x7FU;
+const unsigned char MMDVM_SERIAL = 0x80U;
+
const unsigned char MMDVM_DEBUG1 = 0xF1U;
const unsigned char MMDVM_DEBUG2 = 0xF2U;
const unsigned char MMDVM_DEBUG3 = 0xF3U;
@@ -655,6 +657,15 @@ unsigned int CModem::readP25Data(unsigned char* data)
return len;
}
+// To be implemented later if needed
+unsigned int CModem::readSerial(unsigned char* data, unsigned int length)
+{
+ assert(data != NULL);
+ assert(length > 0U);
+
+ return 0U;
+}
+
bool CModem::hasDStarSpace() const
{
unsigned int space = m_txDStarData.freeSpace() / (DSTAR_FRAME_LENGTH_BYTES + 4U);
@@ -816,6 +827,24 @@ bool CModem::writeP25Data(const unsigned char* data, unsigned int length)
return true;
}
+bool CModem::writeSerial(const unsigned char* data, unsigned int length)
+{
+ assert(data != NULL);
+ assert(length > 0U);
+
+ unsigned char buffer[250U];
+
+ buffer[0U] = MMDVM_FRAME_START;
+ buffer[1U] = length + 3U;
+ buffer[2U] = MMDVM_SERIAL;
+
+ ::memcpy(buffer + 3U, data, length);
+
+ int ret = m_serial.write(buffer, length + 3U);
+
+ return ret != int(length + 3U);
+}
+
bool CModem::hasTX() const
{
return m_tx;
@@ -1088,6 +1117,7 @@ RESP_TYPE_MMDVM CModem::getResponse()
case MMDVM_GET_VERSION:
case MMDVM_ACK:
case MMDVM_NAK:
+ case MMDVM_SERIAL:
case MMDVM_DEBUG1:
case MMDVM_DEBUG2:
case MMDVM_DEBUG3:
diff --git a/Modem.h b/Modem.h
index 97b1cb59c..96cba0c71 100644
--- a/Modem.h
+++ b/Modem.h
@@ -50,6 +50,8 @@ class CModem {
unsigned int readYSFData(unsigned char* data);
unsigned int readP25Data(unsigned char* data);
+ unsigned int readSerial(unsigned char* data, unsigned int length);
+
bool hasDStarSpace() const;
bool hasDMRSpace1() const;
bool hasDMRSpace2() const;
@@ -71,6 +73,8 @@ class CModem {
bool writeDMRShortLC(const unsigned char* lc);
bool writeDMRAbort(unsigned int slotNo);
+ bool writeSerial(const unsigned char* data, unsigned int length);
+
bool setMode(unsigned char mode);
bool sendCWId(const std::string& callsign);
diff --git a/ModemSerialPort.cpp b/ModemSerialPort.cpp
new file mode 100644
index 000000000..51ba01dad
--- /dev/null
+++ b/ModemSerialPort.cpp
@@ -0,0 +1,59 @@
+/*
+* Copyright (C) 2016 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
+#include
+
+CModemSerialPort::CModemSerialPort(CModem* modem) :
+m_modem(modem)
+{
+ assert(modem != NULL);
+}
+
+CModemSerialPort::~CModemSerialPort()
+{
+}
+
+bool CModemSerialPort::open()
+{
+ return true;
+}
+
+int CModemSerialPort::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 CModemSerialPort::read(unsigned char* data, unsigned int length)
+{
+ assert(data != NULL);
+ assert(length > 0U);
+
+ return m_modem->readSerial(data, length);
+}
+
+void CModemSerialPort::close()
+{
+}
diff --git a/ModemSerialPort.h b/ModemSerialPort.h
new file mode 100644
index 000000000..d6761cec7
--- /dev/null
+++ b/ModemSerialPort.h
@@ -0,0 +1,42 @@
+/*
+* Copyright (C) 2016 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 CModemSerialPort : public ISerialPort {
+public:
+ CModemSerialPort(CModem* modem);
+ virtual ~CModemSerialPort();
+
+ 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
diff --git a/Nextion.cpp b/Nextion.cpp
index e5689012e..a1b4a472c 100644
--- a/Nextion.cpp
+++ b/Nextion.cpp
@@ -25,11 +25,11 @@
#include
#include
-CNextion::CNextion(const std::string& callsign, unsigned int dmrid, const std::string& port, unsigned int brightness, bool displayClock, bool utc, unsigned int idleBrightness) :
+CNextion::CNextion(const std::string& callsign, unsigned int dmrid, ISerialPort* serial, unsigned int brightness, bool displayClock, bool utc, unsigned int idleBrightness) :
CDisplay(),
m_callsign(callsign),
m_dmrid(dmrid),
-m_serial(port, SERIAL_9600),
+m_serial(serial),
m_brightness(brightness),
m_mode(MODE_IDLE),
m_displayClock(displayClock),
@@ -37,6 +37,7 @@ m_utc(utc),
m_idleBrightness(idleBrightness),
m_clockDisplayTimer(1000U, 0U, 400U)
{
+ assert(serial != NULL);
assert(brightness >= 0U && brightness <= 100U);
}
@@ -46,9 +47,10 @@ CNextion::~CNextion()
bool CNextion::open()
{
- bool ret = m_serial.open();
+ bool ret = m_serial->open();
if (!ret) {
LogError("Cannot open the port for the Nextion display");
+ delete m_serial;
return false;
}
@@ -302,13 +304,14 @@ void CNextion::clockInt(unsigned int ms)
void CNextion::close()
{
- m_serial.close();
+ m_serial->close();
+ delete m_serial;
}
void CNextion::sendCommand(const char* command)
{
assert(command != NULL);
- m_serial.write((unsigned char*)command, ::strlen(command));
- m_serial.write((unsigned char*)"\xFF\xFF\xFF", 3U);
+ m_serial->write((unsigned char*)command, ::strlen(command));
+ m_serial->write((unsigned char*)"\xFF\xFF\xFF", 3U);
}
diff --git a/Nextion.h b/Nextion.h
index 06ae9c4fc..0e4496d6b 100644
--- a/Nextion.h
+++ b/Nextion.h
@@ -21,7 +21,7 @@
#include "Display.h"
#include "Defines.h"
-#include "SerialController.h"
+#include "SerialPort.h"
#include "Timer.h"
#include
@@ -29,7 +29,7 @@
class CNextion : public CDisplay
{
public:
- CNextion(const std::string& callsign, unsigned int dmrid, const std::string& port, unsigned int brightness, bool displayClock, bool utc, unsigned int idleBrightness);
+ CNextion(const std::string& callsign, unsigned int dmrid, ISerialPort* serial, unsigned int brightness, bool displayClock, bool utc, unsigned int idleBrightness);
virtual ~CNextion();
virtual bool open();
@@ -59,15 +59,15 @@ class CNextion : public CDisplay
virtual void clockInt(unsigned int ms);
private:
- std::string m_callsign;
- unsigned int m_dmrid;
- CSerialController m_serial;
- unsigned int m_brightness;
- unsigned char m_mode;
- bool m_displayClock;
- bool m_utc;
- unsigned int m_idleBrightness;
- CTimer m_clockDisplayTimer;
+ std::string m_callsign;
+ unsigned int m_dmrid;
+ ISerialPort* m_serial;
+ unsigned int m_brightness;
+ unsigned char m_mode;
+ bool m_displayClock;
+ bool m_utc;
+ unsigned int m_idleBrightness;
+ CTimer m_clockDisplayTimer;
void sendCommand(const char* command);
};
diff --git a/SerialController.h b/SerialController.h
index ade0ad62c..f34342ce3 100644
--- a/SerialController.h
+++ b/SerialController.h
@@ -20,6 +20,8 @@
#ifndef SerialController_H
#define SerialController_H
+#include "SerialPort.h"
+
#include
#if defined(_WIN32) || defined(_WIN64)
@@ -38,17 +40,18 @@ enum SERIAL_SPEED {
SERIAL_230400 = 230400
};
-class CSerialController {
+class CSerialController : public ISerialPort {
public:
CSerialController(const std::string& device, SERIAL_SPEED speed, bool assertRTS = false);
- ~CSerialController();
+ virtual ~CSerialController();
+
+ virtual bool open();
- bool open();
+ virtual int read(unsigned char* buffer, unsigned int length);
- int read(unsigned char* buffer, unsigned int length);
- int write(const unsigned char* buffer, unsigned int length);
+ virtual int write(const unsigned char* buffer, unsigned int length);
- void close();
+ virtual void close();
private:
std::string m_device;
diff --git a/SerialPort.cpp b/SerialPort.cpp
new file mode 100644
index 000000000..a2867dcfd
--- /dev/null
+++ b/SerialPort.cpp
@@ -0,0 +1,23 @@
+/*
+* Copyright (C) 2016 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 "SerialPort.h"
+
+ISerialPort::~ISerialPort()
+{
+}
diff --git a/SerialPort.h b/SerialPort.h
new file mode 100644
index 000000000..2b633b671
--- /dev/null
+++ b/SerialPort.h
@@ -0,0 +1,37 @@
+/*
+* Copyright (C) 2016 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 SerialPort_H
+#define SerialPort_H
+
+class ISerialPort {
+public:
+ virtual ~ISerialPort() = 0;
+
+ virtual bool open() = 0;
+
+ virtual int read(unsigned char* buffer, unsigned int length) = 0;
+
+ virtual int write(const unsigned char* buffer, unsigned int length) = 0;
+
+ virtual void close() = 0;
+
+private:
+};
+
+#endif
diff --git a/TFTSerial.cpp b/TFTSerial.cpp
index a84473b4b..b03991581 100644
--- a/TFTSerial.cpp
+++ b/TFTSerial.cpp
@@ -44,14 +44,15 @@ const unsigned char FONT_LARGE = 3U;
// x = 0 to 159, y = 0 to 127 - Landscape
// x = 0 to 127, y = 0 to 159 - Portrait
-CTFTSerial::CTFTSerial(const std::string& callsign, unsigned int dmrid, const std::string& port, unsigned int brightness) :
+CTFTSerial::CTFTSerial(const std::string& callsign, unsigned int dmrid, ISerialPort* serial, unsigned int brightness) :
CDisplay(),
m_callsign(callsign),
m_dmrid(dmrid),
-m_serial(port, SERIAL_9600),
+m_serial(serial),
m_brightness(brightness),
m_mode(MODE_IDLE)
{
+ assert(serial != NULL);
assert(brightness >= 0U && brightness <= 100U);
}
@@ -61,9 +62,10 @@ CTFTSerial::~CTFTSerial()
bool CTFTSerial::open()
{
- bool ret = m_serial.open();
+ bool ret = m_serial->open();
if (!ret) {
LogError("Cannot open the port for the TFT Serial");
+ delete m_serial;
return false;
}
@@ -368,131 +370,132 @@ void CTFTSerial::clearCWInt()
void CTFTSerial::close()
{
- m_serial.close();
+ m_serial->close();
+ delete m_serial;
}
void CTFTSerial::clearScreen()
{
- m_serial.write((unsigned char*)"\x1B\x00\xFF", 3U);
+ m_serial->write((unsigned char*)"\x1B\x00\xFF", 3U);
}
void CTFTSerial::setForeground(unsigned char colour)
{
assert(colour >= 0U && colour <= 7U);
- m_serial.write((unsigned char*)"\x1B\x01", 2U);
- m_serial.write(&colour, 1U);
- m_serial.write((unsigned char*)"\xFF", 1U);
+ m_serial->write((unsigned char*)"\x1B\x01", 2U);
+ m_serial->write(&colour, 1U);
+ m_serial->write((unsigned char*)"\xFF", 1U);
}
void CTFTSerial::setBackground(unsigned char colour)
{
assert(colour >= 0U && colour <= 7U);
- m_serial.write((unsigned char*)"\x1B\x02", 2U);
- m_serial.write(&colour, 1U);
- m_serial.write((unsigned char*)"\xFF", 1U);
+ m_serial->write((unsigned char*)"\x1B\x02", 2U);
+ m_serial->write(&colour, 1U);
+ m_serial->write((unsigned char*)"\xFF", 1U);
}
void CTFTSerial::setRotation(unsigned char rotation)
{
assert(rotation >= 0U && rotation <= 3U);
- m_serial.write((unsigned char*)"\x1B\x03", 2U);
- m_serial.write(&rotation, 1U);
- m_serial.write((unsigned char*)"\xFF", 1U);
+ m_serial->write((unsigned char*)"\x1B\x03", 2U);
+ m_serial->write(&rotation, 1U);
+ m_serial->write((unsigned char*)"\xFF", 1U);
}
void CTFTSerial::setFontSize(unsigned char size)
{
assert(size >= 1U && size <= 3U);
- m_serial.write((unsigned char*)"\x1B\x04", 2U);
- m_serial.write(&size, 1U);
- m_serial.write((unsigned char*)"\xFF", 1U);
+ m_serial->write((unsigned char*)"\x1B\x04", 2U);
+ m_serial->write(&size, 1U);
+ m_serial->write((unsigned char*)"\xFF", 1U);
}
void CTFTSerial::gotoBegOfLine()
{
- m_serial.write((unsigned char*)"\x1B\x05\xFF", 3U);
+ m_serial->write((unsigned char*)"\x1B\x05\xFF", 3U);
}
void CTFTSerial::gotoPosText(unsigned char x, unsigned char y)
{
- m_serial.write((unsigned char*)"\x1B\x06", 2U);
- m_serial.write(&x, 1U);
- m_serial.write(&y, 1U);
- m_serial.write((unsigned char*)"\xFF", 1U);
+ m_serial->write((unsigned char*)"\x1B\x06", 2U);
+ m_serial->write(&x, 1U);
+ m_serial->write(&y, 1U);
+ m_serial->write((unsigned char*)"\xFF", 1U);
}
void CTFTSerial::gotoPosPixel(unsigned char x, unsigned char y)
{
- m_serial.write((unsigned char*)"\x1B\x07", 2U);
- m_serial.write(&x, 1U);
- m_serial.write(&y, 1U);
- m_serial.write((unsigned char*)"\xFF", 1U);
+ m_serial->write((unsigned char*)"\x1B\x07", 2U);
+ m_serial->write(&x, 1U);
+ m_serial->write(&y, 1U);
+ m_serial->write((unsigned char*)"\xFF", 1U);
}
void CTFTSerial::drawLine(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2)
{
- m_serial.write((unsigned char*)"\x1B\x08", 2U);
- m_serial.write(&x1, 1U);
- m_serial.write(&y1, 1U);
- m_serial.write(&x2, 1U);
- m_serial.write(&y2, 1U);
- m_serial.write((unsigned char*)"\xFF", 1U);
+ m_serial->write((unsigned char*)"\x1B\x08", 2U);
+ m_serial->write(&x1, 1U);
+ m_serial->write(&y1, 1U);
+ m_serial->write(&x2, 1U);
+ m_serial->write(&y2, 1U);
+ m_serial->write((unsigned char*)"\xFF", 1U);
}
void CTFTSerial::drawBox(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, bool filled)
{
if (filled)
- m_serial.write((unsigned char*)"\x1B\x0A", 2U);
+ m_serial->write((unsigned char*)"\x1B\x0A", 2U);
else
- m_serial.write((unsigned char*)"\x1B\x09", 2U);
+ m_serial->write((unsigned char*)"\x1B\x09", 2U);
- m_serial.write(&x1, 1U);
- m_serial.write(&y1, 1U);
- m_serial.write(&x2, 1U);
- m_serial.write(&y2, 1U);
- m_serial.write((unsigned char*)"\xFF", 1U);
+ m_serial->write(&x1, 1U);
+ m_serial->write(&y1, 1U);
+ m_serial->write(&x2, 1U);
+ m_serial->write(&y2, 1U);
+ m_serial->write((unsigned char*)"\xFF", 1U);
}
void CTFTSerial::drawCircle(unsigned char x, unsigned char y, unsigned char radius, bool filled)
{
if (filled)
- m_serial.write((unsigned char*)"\x1B\x0C", 2U);
+ m_serial->write((unsigned char*)"\x1B\x0C", 2U);
else
- m_serial.write((unsigned char*)"\x1B\x0B", 2U);
+ m_serial->write((unsigned char*)"\x1B\x0B", 2U);
- m_serial.write(&x, 1U);
- m_serial.write(&y, 1U);
- m_serial.write(&radius, 1U);
- m_serial.write((unsigned char*)"\xFF", 1U);
+ m_serial->write(&x, 1U);
+ m_serial->write(&y, 1U);
+ m_serial->write(&radius, 1U);
+ m_serial->write((unsigned char*)"\xFF", 1U);
}
void CTFTSerial::displayBitmap(unsigned char x, unsigned char y, const char* filename)
{
assert(filename != NULL);
- m_serial.write((unsigned char*)"\x1B\x0D", 2U);
- m_serial.write(&x, 1U);
- m_serial.write(&y, 1U);
- m_serial.write((unsigned char*)filename, ::strlen(filename));
- m_serial.write((unsigned char*)"\xFF", 1U);
+ m_serial->write((unsigned char*)"\x1B\x0D", 2U);
+ m_serial->write(&x, 1U);
+ m_serial->write(&y, 1U);
+ m_serial->write((unsigned char*)filename, ::strlen(filename));
+ m_serial->write((unsigned char*)"\xFF", 1U);
}
void CTFTSerial::setBrightness(unsigned char brightness)
{
assert(brightness >= 0U && brightness <= 100U);
- m_serial.write((unsigned char*)"\x1B\x0E", 2U);
- m_serial.write(&brightness, 1U);
- m_serial.write((unsigned char*)"\xFF", 1U);
+ m_serial->write((unsigned char*)"\x1B\x0E", 2U);
+ m_serial->write(&brightness, 1U);
+ m_serial->write((unsigned char*)"\xFF", 1U);
}
void CTFTSerial::displayText(const char* text)
{
assert(text != NULL);
- m_serial.write((unsigned char*)text, ::strlen(text));
+ m_serial->write((unsigned char*)text, ::strlen(text));
}
diff --git a/TFTSerial.h b/TFTSerial.h
index 1fb3cf52a..116b787d3 100644
--- a/TFTSerial.h
+++ b/TFTSerial.h
@@ -21,14 +21,14 @@
#include "Display.h"
#include "Defines.h"
-#include "SerialController.h"
+#include "SerialPort.h"
#include
class CTFTSerial : public CDisplay
{
public:
- CTFTSerial(const std::string& callsign, unsigned int dmrid, const std::string& port, unsigned int brightness);
+ CTFTSerial(const std::string& callsign, unsigned int dmrid, ISerialPort* serial, unsigned int brightness);
virtual ~CTFTSerial();
virtual bool open();
@@ -56,11 +56,11 @@ class CTFTSerial : public CDisplay
virtual void clearCWInt();
private:
- std::string m_callsign;
- unsigned int m_dmrid;
- CSerialController m_serial;
- unsigned int m_brightness;
- unsigned char m_mode;
+ std::string m_callsign;
+ unsigned int m_dmrid;
+ ISerialPort* m_serial;
+ unsigned int m_brightness;
+ unsigned char m_mode;
void clearScreen();
void setBackground(unsigned char colour);