diff --git a/Conf.cpp b/Conf.cpp index b8888f9..30c03d1 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -332,6 +332,8 @@ m_nextionUTC(false), m_nextionIdleBrightness(20U), m_nextionScreenLayout(0U), m_nextionTempInFahrenheit(false), +m_nextionOutput(false), +m_nextionUDPPort(6759), m_oledType(3U), m_oledBrightness(0U), m_oledInvert(false), @@ -1137,6 +1139,10 @@ bool CConf::read() m_nextionScreenLayout = (unsigned int)::strtoul(value, NULL, 0); else if (::strcmp(key, "DisplayTempInFahrenheit") == 0) m_nextionTempInFahrenheit = ::atoi(value) == 1; + else if (::strcmp(key, "NextionOutput") == 0) + m_nextionOutput = ::atoi(value) == 1; + else if (::strcmp(key, "NextionUDPPort") == 0) + m_nextionUDPPort = (unsigned short)::atoi(value); } else if (section == SECTION_OLED) { if (::strcmp(key, "Type") == 0) m_oledType = (unsigned char)::atoi(value); @@ -2501,6 +2507,21 @@ unsigned int CConf::getNextionScreenLayout() const return m_nextionScreenLayout; } +bool CConf::getNextionTempInFahrenheit() const +{ + return m_nextionTempInFahrenheit; +} + +bool CConf::getNextionOutput() const +{ + return m_nextionOutput; +} + +unsigned short CConf::getNextionUDPPort() const +{ + return m_nextionUDPPort; +} + unsigned char CConf::getOLEDType() const { return m_oledType; @@ -2561,11 +2582,6 @@ bool CConf::getLCDprocDimOnIdle() const return m_lcdprocDimOnIdle; } -bool CConf::getNextionTempInFahrenheit() const -{ - return m_nextionTempInFahrenheit; -} - bool CConf::getLockFileEnabled() const { return m_lockFileEnabled; diff --git a/Conf.h b/Conf.h index 660f0e8..1c6e75c 100644 --- a/Conf.h +++ b/Conf.h @@ -347,13 +347,15 @@ public: bool getHD44780UTC() const; // The Nextion section - std::string getNextionPort() const; - unsigned int getNextionBrightness() const; - bool getNextionDisplayClock() const; - bool getNextionUTC() const; - unsigned int getNextionIdleBrightness() const; - unsigned int getNextionScreenLayout() const; - bool getNextionTempInFahrenheit() const; + std::string getNextionPort() const; + unsigned int getNextionBrightness() const; + bool getNextionDisplayClock() const; + bool getNextionUTC() const; + unsigned int getNextionIdleBrightness() const; + unsigned int getNextionScreenLayout() const; + bool getNextionTempInFahrenheit() const; + bool getNextionOutput() const; + unsigned short getNextionUDPPort() const; // The OLED section unsigned char getOLEDType() const; @@ -669,13 +671,15 @@ private: bool m_hd44780DisplayClock; bool m_hd44780UTC; - std::string m_nextionPort; - unsigned int m_nextionBrightness; - bool m_nextionDisplayClock; - bool m_nextionUTC; - unsigned int m_nextionIdleBrightness; - unsigned int m_nextionScreenLayout; - bool m_nextionTempInFahrenheit; + std::string m_nextionPort; + unsigned int m_nextionBrightness; + bool m_nextionDisplayClock; + bool m_nextionUTC; + unsigned int m_nextionIdleBrightness; + unsigned int m_nextionScreenLayout; + bool m_nextionTempInFahrenheit; + bool m_nextionOutput; + unsigned short m_nextionUDPPort; unsigned char m_oledType; unsigned char m_oledBrightness; diff --git a/DStarNetwork.cpp b/DStarNetwork.cpp index dbb6a2c..67099d6 100644 --- a/DStarNetwork.cpp +++ b/DStarNetwork.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2014,2016,2019,2020,2021 by Jonathan Naylor G4KLX + * Copyright (C) 2009-2014,2016,2019,2020,2021,2024 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 @@ -164,7 +164,7 @@ bool CDStarNetwork::writePoll(const char* text) buffer[2] = 'R'; buffer[3] = 'P'; - buffer[4] = 0x0A; // Poll with text + buffer[4] = 0x0AU; // Poll with text unsigned int length = ::strlen(text); @@ -226,6 +226,7 @@ void CDStarNetwork::clock(unsigned int ms) case 0x01U: // NETWORK_TEMPTEXT; case 0x04U: // NETWORK_STATUS1..5 + case 0x0AU: // POLL case 0x24U: // NETWORK_DD_DATA return; diff --git a/Display.cpp b/Display.cpp index 9d20773..ab0c0bb 100644 --- a/Display.cpp +++ b/Display.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016,2017,2018,2020,2021,2023 by Jonathan Naylor G4KLX + * Copyright (C) 2016,2017,2018,2020,2021,2023,2024 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 @@ -22,6 +22,7 @@ #include "ModemSerialPort.h" #include "NullDisplay.h" #include "TFTSurenoo.h" +#include "UDPSocket.h" #include "LCDproc.h" #include "Nextion.h" #include "CASTInfo.h" @@ -604,8 +605,35 @@ CDisplay* CDisplay::createDisplay(const CConf& conf, CModem* modem) } if (port == "modem") { - ISerialPort* serial = new IModemSerialPort(modem); - display = new CNextion(conf.getCallsign(), dmrid, serial, brightness, displayClock, utc, idleBrightness, screenLayout, txFrequency, rxFrequency, displayTempInF); + CUDPSocket* socket = NULL; + struct sockaddr_storage addr; + unsigned int addrLength = 0U; + + bool nextionOutput = conf.getNextionOutput(); + if (nextionOutput) { + unsigned short nextionUDPPort = conf.getNextionUDPPort(); + + LogInfo(" Output Port: %u", nextionUDPPort); + + CUDPSocket::lookup("127.0.0.1", nextionUDPPort, addr, addrLength); + + if (addrLength > 0U) { + socket = new CUDPSocket("127.0.0.1", nextionUDPPort - 1U); + bool ret = socket->open(addr); + if (!ret) { + delete socket; + socket = NULL; + } + } + } + + if (socket == NULL) { + ISerialPort* serial = new IModemSerialPort(modem); + display = new CNextion(conf.getCallsign(), dmrid, serial, brightness, displayClock, utc, idleBrightness, screenLayout, txFrequency, rxFrequency, displayTempInF); + } else { + ISerialPort* serial = new IModemSerialPort(modem); + display = new CNextion(conf.getCallsign(), dmrid, serial, brightness, displayClock, utc, idleBrightness, screenLayout, txFrequency, rxFrequency, displayTempInF, socket, addr, addrLength); + } } else { unsigned int baudrate = 9600U; if (screenLayout == 4U) diff --git a/FMNetwork.cpp b/FMNetwork.cpp index 02ff5bf..5545967 100644 --- a/FMNetwork.cpp +++ b/FMNetwork.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020,2021,2023 by Jonathan Naylor G4KLX + * Copyright (C) 2020,2021,2023,2024 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 @@ -28,7 +28,6 @@ #include #include #include -#include const unsigned int MMDVM_SAMPLERATE = 8000U; @@ -46,9 +45,11 @@ m_debug(debug), m_enabled(false), m_buffer(2000U, "FM Network"), m_seqNo(0U), +#if defined(HAS_SRC) m_resampler(NULL), +#endif m_error(0), -m_fd(-1) +m_fp(NULL) { assert(!callsign.empty()); assert(gatewayPort > 0U); @@ -68,12 +69,16 @@ m_fd(-1) else m_protocol = FMNP_USRP; +#if defined(HAS_SRC) m_resampler = ::src_new(SRC_SINC_FASTEST, 1, &m_error); +#endif } CFMNetwork::~CFMNetwork() { +#if defined(HAS_SRC) ::src_delete(m_resampler); +#endif } bool CFMNetwork::open() @@ -85,14 +90,25 @@ bool CFMNetwork::open() LogMessage("Opening FM network connection"); - if (!m_squelchFile.empty()) { - m_fd = ::open(m_squelchFile.c_str(), O_WRONLY | O_SYNC); - if (m_fd == -1) { - LogError("Cannot open the squelch file: %s, errno=%d", m_squelchFile.c_str(), errno); - return false; + if (m_protocol == FMNP_RAW) { + if (!m_squelchFile.empty()) { + m_fp = ::fopen(m_squelchFile.c_str(), "wb"); + if (m_fp == NULL) { +#if !defined(_WIN32) && !defined(_WIN64) + LogError("Cannot open the squelch file: %s, errno=%d", m_squelchFile.c_str(), errno); +#else + LogError("Cannot open the squelch file: %s, errno=%lu", m_squelchFile.c_str(), ::GetLastError()); +#endif + return false; + } } } + if ((m_protocol == FMNP_RAW) && (m_sampleRate != MMDVM_SAMPLERATE)) { + LogError("The resampler needed for non-native sample rates has not been included"); + return false; + } + return m_socket.open(m_addr); } @@ -198,6 +214,7 @@ bool CFMNetwork::writeRawData(const float* in, unsigned int nIn) unsigned int length = 0U; +#if defined(HAS_SRC) if (m_sampleRate != MMDVM_SAMPLERATE) { unsigned int nOut = (nIn * m_sampleRate) / MMDVM_SAMPLERATE; @@ -224,13 +241,16 @@ bool CFMNetwork::writeRawData(const float* in, unsigned int nIn) buffer[length++] = (val >> 8) & 0xFFU; } } else { +#endif for (unsigned int i = 0U; i < nIn; i++) { short val = short(in[i] * 32767.0F + 0.5F); // Changing audio format from float to S16LE buffer[length++] = (val >> 0) & 0xFFU; buffer[length++] = (val >> 8) & 0xFFU; } +#if defined(HAS_SRC) } +#endif if (m_debug) CUtils::dump(1U, "FM Network Data Sent", buffer, length); @@ -316,12 +336,18 @@ bool CFMNetwork::writeRawEnd() { m_seqNo = 0U; - if (m_fd != -1) { - size_t n = ::write(m_fd, "Z", 1); + if (m_fp != NULL) { + size_t n = ::fwrite("Z", 1, 1, m_fp); if (n != 1) { +#if !defined(_WIN32) && !defined(_WIN64) LogError("Cannot write to the squelch file: %s, errno=%d", m_squelchFile.c_str(), errno); +#else + LogError("Cannot write to the squelch file: %s, errno=%lu", m_squelchFile.c_str(), ::GetLastError()); +#endif return false; } + + ::fflush(m_fp); } return true; @@ -386,6 +412,7 @@ unsigned int CFMNetwork::readData(float* out, unsigned int nOut) if (bytes == 0U) return 0U; +#if defined(HAS_SRC) if ((m_protocol == FMNP_RAW) && (m_sampleRate != MMDVM_SAMPLERATE)) { unsigned int nIn = (nOut * m_sampleRate) / MMDVM_SAMPLERATE; @@ -418,6 +445,7 @@ unsigned int CFMNetwork::readData(float* out, unsigned int nOut) return false; } } else { +#endif if (bytes < nOut) nOut = bytes; @@ -428,7 +456,9 @@ unsigned int CFMNetwork::readData(float* out, unsigned int nOut) short val = ((buffer[i * 2U + 0U] & 0xFFU) << 0) + ((buffer[i * 2U + 1U] & 0xFFU) << 8); out[i] = float(val) / 65536.0F; } +#if defined(HAS_SRC) } +#endif return nOut; } @@ -442,9 +472,9 @@ void CFMNetwork::close() { m_socket.close(); - if (m_fd != -1) { - ::close(m_fd); - m_fd = -1; + if (m_fp != NULL) { + ::fclose(m_fp); + m_fp = NULL; } LogMessage("Closing FM network connection"); @@ -559,12 +589,18 @@ bool CFMNetwork::writeUSRPStart() bool CFMNetwork::writeRawStart() { - if (m_fd != -1) { - size_t n = ::write(m_fd, "O", 1); + if (m_fp != NULL) { + size_t n = ::fwrite("O", 1, 1, m_fp); if (n != 1) { +#if !defined(_WIN32) && !defined(_WIN64) LogError("Cannot write to the squelch file: %s, errno=%d", m_squelchFile.c_str(), errno); +#else + LogError("Cannot write to the squelch file: %s, errno=%lu", m_squelchFile.c_str(), ::GetLastError()); +#endif return false; } + + ::fflush(m_fp); } return true; diff --git a/FMNetwork.h b/FMNetwork.h index 9940f90..60042cf 100644 --- a/FMNetwork.h +++ b/FMNetwork.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020,2021,2023 by Jonathan Naylor G4KLX + * Copyright (C) 2020,2021,2023,2024 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 @@ -16,13 +16,15 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifndef FMNetwork_H +#if !defined(FMNetwork_H) #define FMNetwork_H #include "RingBuffer.h" #include "UDPSocket.h" +#if defined(HAS_SRC) #include +#endif #include #include @@ -65,9 +67,11 @@ private: bool m_enabled; CRingBuffer m_buffer; unsigned int m_seqNo; +#if defined(HAS_SRC) SRC_STATE* m_resampler; +#endif int m_error; - int m_fd; + FILE* m_fp; bool writeUSRPStart(); bool writeRawStart(); diff --git a/LCDproc.cpp b/LCDproc.cpp index 43595a8..7167eed 100644 --- a/LCDproc.cpp +++ b/LCDproc.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2016,2017,2018 by Tony Corbett G0WFV - * Copyright (C) 2018,2020 by Jonathan Naylor G4KLX + * Copyright (C) 2018,2020,2024 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 @@ -73,6 +73,7 @@ #include #else #include +#include #endif #define BUFFER_MAX_LEN 128 @@ -670,15 +671,19 @@ void CLCDproc::clockInt(unsigned int ms) * exceptfds = we are not waiting for exception fds */ - if (select(m_socketfd + 1, &m_readfds, NULL, NULL, &m_timeout) == -1) + if (select(m_socketfd + 1, &m_readfds, NULL, NULL, &m_timeout) == -1) { LogError("LCDproc, error on select"); + return; + } // If something was received from the server... if (FD_ISSET(m_socketfd, &m_readfds)) { m_recvsize = recv(m_socketfd, m_buffer, BUFFER_MAX_LEN, 0); - if (m_recvsize == -1) + if (m_recvsize == -1) { LogError("LCDproc, cannot receive information"); + return; + } m_buffer[m_recvsize] = '\0'; diff --git a/MMDVM.ini b/MMDVM.ini index 35a5606..2808343 100644 --- a/MMDVM.ini +++ b/MMDVM.ini @@ -352,6 +352,9 @@ UTC=0 #Screen Layout: 0=G4KLX 2=ON7LDS ScreenLayout=2 IdleBrightness=20 +# Output data from the Nextion +NextionOutput=0 +NextionPort=6759 [OLED] Type=3 diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index 9e50fbc..cf5d4c4 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -82,7 +82,7 @@ static void sigHandler2(int signum) const char* HEADER1 = "This software is for use on amateur radio networks only,"; const char* HEADER2 = "it is to be used for educational purposes only. Its use on"; const char* HEADER3 = "commercial networks is strictly prohibited."; -const char* HEADER4 = "Copyright(C) 2015-2023 by Jonathan Naylor, G4KLX and others"; +const char* HEADER4 = "Copyright(C) 2015-2024 by Jonathan Naylor, G4KLX and others"; int main(int argc, char** argv) { diff --git a/MMDVMHost.vcxproj b/MMDVMHost.vcxproj index dc7a76b..0b29f63 100644 --- a/MMDVMHost.vcxproj +++ b/MMDVMHost.vcxproj @@ -87,12 +87,15 @@ Level3 Disabled - HAVE_LOG_H;WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + HAVE_LOG_H;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + Console true kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;%(AdditionalDependencies) + %(AdditionalLibraryDirectories) @@ -101,12 +104,15 @@ Level3 Disabled - HAVE_LOG_H;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + HAVE_LOG_H;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + Console true kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;%(AdditionalDependencies) + %(AdditionalLibraryDirectories) "$(ProjectDir)prebuild.cmd" $(ProjectDir) @@ -123,7 +129,9 @@ MaxSpeed true true - HAVE_LOG_H;WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + HAVE_LOG_H;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + Console @@ -131,6 +139,7 @@ true true kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;%(AdditionalDependencies) + %(AdditionalLibraryDirectories) @@ -141,7 +150,9 @@ MaxSpeed true true - HAVE_LOG_H;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + HAVE_LOG_H;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + Console @@ -149,6 +160,7 @@ true true kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;%(AdditionalDependencies) + %(AdditionalLibraryDirectories) diff --git a/Makefile b/Makefile index c884e9b..2ba52eb 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ # This makefile is for all platforms, but doesn't include support for the HD44780, OLED, or PCF8574 displays on the Raspberry Pi. +# If you have the resampler library installed, add -DHAS_SRC to the CFLAGS line, and -lsamplerate to the LIBS line. + CC = cc CXX = c++ CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHAVE_LOG_H -I/usr/local/include diff --git a/Makefile.Pi.Adafruit b/Makefile.Pi.Adafruit index 2ae7bfb..652bf38 100644 --- a/Makefile.Pi.Adafruit +++ b/Makefile.Pi.Adafruit @@ -1,6 +1,8 @@ # This makefile is for use with the Raspberry Pi when using an HD44780 compatible display. The wiringpi library is needed. # Support for the Adafruit i2c 16 x 2 RGB LCD Pi Plate +# If you have the resampler library installed, add -DHAS_SRC to the CFLAGS line, and -lsamplerate to the LIBS line. + CC = cc CXX = c++ CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHAVE_LOG_H -DHD44780 -DADAFRUIT_DISPLAY -I/usr/local/include diff --git a/Makefile.Pi.HD44780 b/Makefile.Pi.HD44780 index 5b68768..9782e23 100644 --- a/Makefile.Pi.HD44780 +++ b/Makefile.Pi.HD44780 @@ -1,5 +1,7 @@ # This makefile is for use with the Raspberry Pi when using an HD44780 compatible display. The wiringpi library is needed. +# If you have the resampler library installed, add -DHAS_SRC to the CFLAGS line, and -lsamplerate to the LIBS line. + CC = cc CXX = c++ CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHAVE_LOG_H -DHD44780 -I/usr/local/include diff --git a/Makefile.Pi.I2C b/Makefile.Pi.I2C index 1da6c36..afc6b80 100644 --- a/Makefile.Pi.I2C +++ b/Makefile.Pi.I2C @@ -1,5 +1,7 @@ # This makefile is for use with the Raspberry Pi. The wiringpi library is needed. +# If you have the resampler library installed, add -DHAS_SRC to the CFLAGS line, and -lsamplerate to the LIBS line. + CC = cc CXX = c++ CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHAVE_LOG_H -DRASPBERRY_PI -I/usr/local/include diff --git a/Makefile.Pi.OLED b/Makefile.Pi.OLED index b9554db..b619687 100644 --- a/Makefile.Pi.OLED +++ b/Makefile.Pi.OLED @@ -1,5 +1,7 @@ # This makefile is for use with the Raspberry Pi when using an OLED display. The wiringpi library is not needed. +# If you have the resampler library installed, add -DHAS_SRC to the CFLAGS line, and -lsamplerate to the LIBS line. + CC = cc CXX = c++ CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHAVE_LOG_H -DOLED -I/usr/local/include diff --git a/Makefile.Pi.PCF8574 b/Makefile.Pi.PCF8574 index 036ce50..6514a51 100644 --- a/Makefile.Pi.PCF8574 +++ b/Makefile.Pi.PCF8574 @@ -1,6 +1,8 @@ # This makefile is for use with the Raspberry Pi when using an HD44780 compatible display. The wiringpi library is needed. # Support for the HD44780 connected via a PCF8574 8-bit GPIO expander IC +# If you have the resampler library installed, add -DHAS_SRC to the CFLAGS line, and -lsamplerate to the LIBS line. + CC = cc CXX = c++ CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHAVE_LOG_H -DHD44780 -DPCF8574_DISPLAY -I/usr/local/include diff --git a/NetworkInfo.cpp b/NetworkInfo.cpp index 78f6080..b85e8a6 100644 --- a/NetworkInfo.cpp +++ b/NetworkInfo.cpp @@ -39,6 +39,7 @@ #endif #elif defined(_WIN32) || defined(_WIN64) #include +#include #include #pragma comment(lib, "iphlpapi.lib") #ifndef NO_ERROR diff --git a/Nextion.cpp b/Nextion.cpp index a48aa71..8956304 100644 --- a/Nextion.cpp +++ b/Nextion.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016,2017,2018,2020,2023 by Jonathan Naylor G4KLX + * Copyright (C) 2016,2017,2018,2020,2023,2024 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 @@ -49,6 +49,59 @@ const unsigned int M17_BER_COUNT = 28U; // 28 * 40ms = 1120ms // 00:low, others:high-speed. bit[2] is overlapped with LAYOUT_COMPAT_MASK. #define LAYOUT_HIGHSPEED (3 << 2) +CNextion::CNextion(const std::string& callsign, unsigned int dmrid, ISerialPort* serial, unsigned int brightness, bool displayClock, bool utc, unsigned int idleBrightness, unsigned int screenLayout, unsigned int txFrequency, unsigned int rxFrequency, bool displayTempInF, CUDPSocket* socket, struct sockaddr_storage& addr, unsigned int addrLength) : +CDisplay(), +m_callsign(callsign), +m_ipaddress("(ip unknown)"), +m_dmrid(dmrid), +m_serial(serial), +m_brightness(brightness), +m_mode(MODE_IDLE), +m_displayClock(displayClock), +m_utc(utc), +m_idleBrightness(idleBrightness), +m_screenLayout(0), +m_clockDisplayTimer(1000U, 0U, 400U), +m_rssiAccum1(0U), +m_rssiAccum2(0U), +m_berAccum1(0.0F), +m_berAccum2(0.0F), +m_rssiCount1(0U), +m_rssiCount2(0U), +m_berCount1(0U), +m_berCount2(0U), +m_txFrequency(txFrequency), +m_rxFrequency(rxFrequency), +m_fl_txFrequency(0.0F), +m_fl_rxFrequency(0.0F), +m_displayTempInF(displayTempInF), +m_socket(socket), +m_addr(addr), +m_addrLength(addrLength) +{ + assert(serial != NULL); + assert(brightness >= 0U && brightness <= 100U); + assert(socket != NULL); + assert(addrLength > 0U); + + static const unsigned int feature_set[] = { + 0, // 0: G4KLX + 0, // 1: (reserved, low speed) + // 2: ON7LDS + LAYOUT_TA_ENABLE | LAYOUT_TA_COLOUR | LAYOUT_TA_FONTSIZE, + LAYOUT_TA_ENABLE | LAYOUT_DIY, // 3: ON7LDS-DIY + LAYOUT_TA_ENABLE | LAYOUT_DIY, // 4: ON7LDS-DIY (high speed) + 0, // 5: (reserved, high speed) + 0, // 6: (reserved, high speed) + 0, // 7: (reserved, high speed) + }; + + if (screenLayout & ~LAYOUT_COMPAT_MASK) + m_screenLayout = screenLayout & ~LAYOUT_COMPAT_MASK; + else + m_screenLayout = feature_set[screenLayout]; +} + CNextion::CNextion(const std::string& callsign, unsigned int dmrid, ISerialPort* serial, unsigned int brightness, bool displayClock, bool utc, unsigned int idleBrightness, unsigned int screenLayout, unsigned int txFrequency, unsigned int rxFrequency, bool displayTempInF) : CDisplay(), m_callsign(callsign), @@ -74,7 +127,10 @@ m_txFrequency(txFrequency), m_rxFrequency(rxFrequency), m_fl_txFrequency(0.0F), m_fl_rxFrequency(0.0F), -m_displayTempInF(displayTempInF) +m_displayTempInF(displayTempInF), +m_socket(NULL), +m_addr(), +m_addrLength(0U) { assert(serial != NULL); assert(brightness >= 0U && brightness <= 100U); @@ -968,12 +1024,25 @@ void CNextion::clockInt(unsigned int ms) m_clockDisplayTimer.start(); // restart the clock display timer } + + if (m_socket != NULL) { + unsigned char buffer[200U]; + + int len = m_serial->read(buffer, 200U); + if (len > 0) + m_socket->write(buffer, len, m_addr, m_addrLength); + } } void CNextion::close() { m_serial->close(); delete m_serial; + + if (m_socket != NULL) { + m_socket->close(); + delete m_socket; + } } void CNextion::sendCommandAction(unsigned int status) diff --git a/Nextion.h b/Nextion.h index 2782097..d488c8e 100644 --- a/Nextion.h +++ b/Nextion.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016,2017,2018,2020,2023 by Jonathan Naylor G4KLX + * Copyright (C) 2016,2017,2018,2020,2023,2024 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 @@ -22,6 +22,7 @@ #include "Display.h" #include "Defines.h" #include "SerialPort.h" +#include "UDPSocket.h" #include "Timer.h" #include "Thread.h" #include @@ -29,6 +30,7 @@ class CNextion : public CDisplay { public: + CNextion(const std::string& callsign, unsigned int dmrid, ISerialPort* serial, unsigned int brightness, bool displayClock, bool utc, unsigned int idleBrightness, unsigned int screenLayout, unsigned int txFrequency, unsigned int rxFrequency, bool displayTempInF, CUDPSocket* socket, struct sockaddr_storage& addr, unsigned int addrLength); CNextion(const std::string& callsign, unsigned int dmrid, ISerialPort* serial, unsigned int brightness, bool displayClock, bool utc, unsigned int idleBrightness, unsigned int screenLayout, unsigned int txFrequency, unsigned int rxFrequency, bool displayTempInF); virtual ~CNextion(); @@ -107,6 +109,9 @@ private: double m_fl_txFrequency; double m_fl_rxFrequency; bool m_displayTempInF; + CUDPSocket* m_socket; + struct sockaddr_storage m_addr; + unsigned int m_addrLength; void sendCommand(const char* command); void sendCommandAction(unsigned int status); diff --git a/UARTController.cpp b/UARTController.cpp index 0d636d8..2400c33 100644 --- a/UARTController.cpp +++ b/UARTController.cpp @@ -295,7 +295,6 @@ bool CUARTController::setRaw() termios.c_cc[VTIME] = 10; #endif -#if !defined(B38400) || (B38400 != 38400) switch (m_speed) { #if defined(B1200) case 1200U: @@ -368,10 +367,6 @@ bool CUARTController::setRaw() ::close(m_fd); return false; } -#else - ::cfsetospeed(&termios, m_speed); - ::cfsetispeed(&termios, m_speed); -#endif if (::tcsetattr(m_fd, TCSANOW, &termios) < 0) { LogError("Cannot set the attributes for %s", m_device.c_str()); diff --git a/UDPSocket.h b/UDPSocket.h index 28e350c..07bf274 100644 --- a/UDPSocket.h +++ b/UDPSocket.h @@ -16,7 +16,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifndef UDPSocket_H +#if !defined(UDPSocket_H) #define UDPSocket_H #include @@ -33,6 +33,7 @@ #include #else #include +#include #endif enum IPMATCHTYPE { @@ -69,10 +70,11 @@ private: unsigned short m_localPort; #if defined(_WIN32) || defined(_WIN64) SOCKET m_fd; + int m_af; #else int m_fd; -#endif sa_family_t m_af; +#endif }; #endif diff --git a/Version.h b/Version.h index 85c1d9f..5478441 100644 --- a/Version.h +++ b/Version.h @@ -19,6 +19,6 @@ #if !defined(VERSION_H) #define VERSION_H -const char* VERSION = "20240207"; +const char* VERSION = "20240429"; #endif