From 6dc9122fe45cca123c4b9acfbd0252e470d75dd9 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Wed, 14 Feb 2024 13:26:29 +0000 Subject: [PATCH 1/5] Remove some serial port oddities. --- UARTController.cpp | 5 ----- 1 file changed, 5 deletions(-) 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()); From 0e8788bdbec3314695fe367b4d9a85c7ba4b9738 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Fri, 23 Feb 2024 15:44:54 +0000 Subject: [PATCH 2/5] Insert a back channel to Nextion displays running via the modem. --- Conf.cpp | 26 +++++++++++++++---- Conf.h | 32 +++++++++++++---------- Display.cpp | 34 ++++++++++++++++++++++--- MMDVM.ini | 3 +++ Nextion.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++-- Nextion.h | 7 ++++- Version.h | 2 +- 7 files changed, 151 insertions(+), 26 deletions(-) diff --git a/Conf.cpp b/Conf.cpp index ca686db..03e881a 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -326,6 +326,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), @@ -1118,6 +1120,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); @@ -2457,6 +2463,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; @@ -2517,11 +2538,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 2cd756b..e3d9d1e 100644 --- a/Conf.h +++ b/Conf.h @@ -340,13 +340,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; @@ -656,13 +658,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/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/MMDVM.ini b/MMDVM.ini index 7883cf4..6b5697e 100644 --- a/MMDVM.ini +++ b/MMDVM.ini @@ -345,6 +345,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/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/Version.h b/Version.h index 85c1d9f..20b0fc6 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 = "20240223"; #endif From ca2bff7e9ed78a422202f1ba8628aceee9768e43 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Mon, 22 Apr 2024 12:48:44 +0100 Subject: [PATCH 3/5] Begin getting it to compile on Windows again. --- Display.cpp | 1 - Display.h | 1 + FMNetwork.cpp | 39 +++++++++++++++++++++++++++------------ FMNetwork.h | 2 +- LCDproc.cpp | 11 ++++++++--- LCDproc.h | 1 + MMDVMHost.vcxproj | 4 ++++ NetworkInfo.cpp | 3 ++- NetworkInfo.h | 2 ++ UDPSocket.h | 4 +++- 10 files changed, 49 insertions(+), 19 deletions(-) diff --git a/Display.cpp b/Display.cpp index ab0c0bb..c09111d 100644 --- a/Display.cpp +++ b/Display.cpp @@ -22,7 +22,6 @@ #include "ModemSerialPort.h" #include "NullDisplay.h" #include "TFTSurenoo.h" -#include "UDPSocket.h" #include "LCDproc.h" #include "Nextion.h" #include "CASTInfo.h" diff --git a/Display.h b/Display.h index 314c9db..af067b9 100644 --- a/Display.h +++ b/Display.h @@ -21,6 +21,7 @@ #include "Timer.h" #include "UserDBentry.h" +#include "UDPSocket.h" #include "Modem.h" #include diff --git a/FMNetwork.cpp b/FMNetwork.cpp index 02ff5bf..10891ef 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; @@ -48,7 +47,7 @@ m_buffer(2000U, "FM Network"), m_seqNo(0U), m_resampler(NULL), m_error(0), -m_fd(-1) +m_fp(NULL) { assert(!callsign.empty()); assert(gatewayPort > 0U); @@ -86,9 +85,13 @@ 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) { + 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; } } @@ -316,12 +319,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; @@ -442,9 +451,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 +568,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..6380d6f 100644 --- a/FMNetwork.h +++ b/FMNetwork.h @@ -67,7 +67,7 @@ private: unsigned int m_seqNo; SRC_STATE* m_resampler; 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/LCDproc.h b/LCDproc.h index b702493..5a74bfb 100644 --- a/LCDproc.h +++ b/LCDproc.h @@ -20,6 +20,7 @@ #if !defined(LCDproc_H) #define LCDproc_H +#include "UDPSocket.h" #include "Display.h" #include "Timer.h" diff --git a/MMDVMHost.vcxproj b/MMDVMHost.vcxproj index dc7a76b..50d7684 100644 --- a/MMDVMHost.vcxproj +++ b/MMDVMHost.vcxproj @@ -88,6 +88,7 @@ Level3 Disabled HAVE_LOG_H;WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + ..\..\libsamplerate-0.1.9\src Console @@ -102,6 +103,7 @@ Level3 Disabled HAVE_LOG_H;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + ..\..\libsamplerate-0.1.9\src Console @@ -124,6 +126,7 @@ true true HAVE_LOG_H;WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + ..\..\libsamplerate-0.1.9\src Console @@ -142,6 +145,7 @@ true true HAVE_LOG_H;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + ..\..\libsamplerate-0.1.9\src Console diff --git a/NetworkInfo.cpp b/NetworkInfo.cpp index 78f6080..10a9d62 100644 --- a/NetworkInfo.cpp +++ b/NetworkInfo.cpp @@ -38,7 +38,8 @@ #include #endif #elif defined(_WIN32) || defined(_WIN64) -#include +// #include +// #include #include #pragma comment(lib, "iphlpapi.lib") #ifndef NO_ERROR diff --git a/NetworkInfo.h b/NetworkInfo.h index 2febcde..a58cef8 100644 --- a/NetworkInfo.h +++ b/NetworkInfo.h @@ -19,6 +19,8 @@ #if !defined(NETWORKINFO_H) #define NETWORKINFO_H +#include "UDPSocket.h" + class CNetworkInfo { public: CNetworkInfo(); diff --git a/UDPSocket.h b/UDPSocket.h index 28e350c..abc9436 100644 --- a/UDPSocket.h +++ b/UDPSocket.h @@ -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 From 738c82d7b959aaf05096eb5216f3baa693f01e89 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Mon, 22 Apr 2024 19:12:33 +0100 Subject: [PATCH 4/5] Fix the Winsock compilation errors. --- Display.cpp | 1 + Display.h | 1 - LCDproc.h | 1 - MMDVMHost.cpp | 2 +- MMDVMHost.vcxproj | 20 ++++++++++++-------- NetworkInfo.cpp | 4 ++-- NetworkInfo.h | 2 -- UDPSocket.h | 2 +- 8 files changed, 17 insertions(+), 16 deletions(-) diff --git a/Display.cpp b/Display.cpp index c09111d..ab0c0bb 100644 --- a/Display.cpp +++ b/Display.cpp @@ -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" diff --git a/Display.h b/Display.h index af067b9..314c9db 100644 --- a/Display.h +++ b/Display.h @@ -21,7 +21,6 @@ #include "Timer.h" #include "UserDBentry.h" -#include "UDPSocket.h" #include "Modem.h" #include diff --git a/LCDproc.h b/LCDproc.h index 5a74bfb..b702493 100644 --- a/LCDproc.h +++ b/LCDproc.h @@ -20,7 +20,6 @@ #if !defined(LCDproc_H) #define LCDproc_H -#include "UDPSocket.h" #include "Display.h" #include "Timer.h" diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index c01cbf5..937967f 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -75,7 +75,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 50d7684..c0fba94 100644 --- a/MMDVMHost.vcxproj +++ b/MMDVMHost.vcxproj @@ -87,13 +87,14 @@ 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) ..\..\libsamplerate-0.1.9\src 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) + 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;libsamplerate-0.lib;%(AdditionalDependencies) + ..\..\libsamplerate\Debug;%(AdditionalLibraryDirectories) @@ -102,13 +103,14 @@ 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) ..\..\libsamplerate-0.1.9\src 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) + 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;libsamplerate-0.lib;%(AdditionalDependencies) + ..\..\libsamplerate\x64\Debug;%(AdditionalLibraryDirectories) "$(ProjectDir)prebuild.cmd" $(ProjectDir) @@ -125,7 +127,7 @@ 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) ..\..\libsamplerate-0.1.9\src @@ -133,7 +135,8 @@ true 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) + 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;libsamplerate-0.lib;%(AdditionalDependencies) + ..\..\libsamplerate\Release;%(AdditionalLibraryDirectories) @@ -144,7 +147,7 @@ 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) ..\..\libsamplerate-0.1.9\src @@ -152,7 +155,8 @@ true 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) + 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;libsamplerate-0.lib;%(AdditionalDependencies) + ..\..\libsamplerate\x64\Release;%(AdditionalLibraryDirectories) diff --git a/NetworkInfo.cpp b/NetworkInfo.cpp index 10a9d62..b85e8a6 100644 --- a/NetworkInfo.cpp +++ b/NetworkInfo.cpp @@ -38,8 +38,8 @@ #include #endif #elif defined(_WIN32) || defined(_WIN64) -// #include -// #include +#include +#include #include #pragma comment(lib, "iphlpapi.lib") #ifndef NO_ERROR diff --git a/NetworkInfo.h b/NetworkInfo.h index a58cef8..2febcde 100644 --- a/NetworkInfo.h +++ b/NetworkInfo.h @@ -19,8 +19,6 @@ #if !defined(NETWORKINFO_H) #define NETWORKINFO_H -#include "UDPSocket.h" - class CNetworkInfo { public: CNetworkInfo(); diff --git a/UDPSocket.h b/UDPSocket.h index abc9436..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 From 3f2a5d794d9f643f5b00dad3882eedc960b7f19f Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Mon, 29 Apr 2024 15:09:20 +0100 Subject: [PATCH 5/5] Make the FM resampler optional. --- DStarNetwork.cpp | 5 +++-- FMNetwork.cpp | 33 +++++++++++++++++++++++++++------ FMNetwork.h | 8 ++++++-- MMDVMHost.vcxproj | 28 ++++++++++++++++------------ Makefile | 4 +++- Makefile.Pi.Adafruit | 4 +++- Makefile.Pi.HD44780 | 4 +++- Makefile.Pi.I2C | 4 +++- Makefile.Pi.OLED | 4 +++- Makefile.Pi.PCF8574 | 4 +++- Version.h | 2 +- 11 files changed, 71 insertions(+), 29 deletions(-) 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/FMNetwork.cpp b/FMNetwork.cpp index 10891ef..5545967 100644 --- a/FMNetwork.cpp +++ b/FMNetwork.cpp @@ -45,7 +45,9 @@ 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_fp(NULL) { @@ -67,12 +69,16 @@ m_fp(NULL) 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() @@ -84,18 +90,25 @@ bool CFMNetwork::open() LogMessage("Opening FM network connection"); - if (!m_squelchFile.empty()) { - m_fp = ::fopen(m_squelchFile.c_str(), "wb"); - if (m_fp == NULL) { + 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); + 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()); + LogError("Cannot open the squelch file: %s, errno=%lu", m_squelchFile.c_str(), ::GetLastError()); #endif - return false; + 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); } @@ -201,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; @@ -227,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); @@ -395,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; @@ -427,6 +445,7 @@ unsigned int CFMNetwork::readData(float* out, unsigned int nOut) return false; } } else { +#endif if (bytes < nOut) nOut = bytes; @@ -437,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; } diff --git a/FMNetwork.h b/FMNetwork.h index 6380d6f..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,7 +67,9 @@ private: bool m_enabled; CRingBuffer m_buffer; unsigned int m_seqNo; +#if defined(HAS_SRC) SRC_STATE* m_resampler; +#endif int m_error; FILE* m_fp; diff --git a/MMDVMHost.vcxproj b/MMDVMHost.vcxproj index c0fba94..0b29f63 100644 --- a/MMDVMHost.vcxproj +++ b/MMDVMHost.vcxproj @@ -88,13 +88,14 @@ Level3 Disabled HAVE_LOG_H;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - ..\..\libsamplerate-0.1.9\src + + 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;libsamplerate-0.lib;%(AdditionalDependencies) - ..\..\libsamplerate\Debug;%(AdditionalLibraryDirectories) + 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) @@ -104,13 +105,14 @@ Level3 Disabled HAVE_LOG_H;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - ..\..\libsamplerate-0.1.9\src + + 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;libsamplerate-0.lib;%(AdditionalDependencies) - ..\..\libsamplerate\x64\Debug;%(AdditionalLibraryDirectories) + 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) @@ -128,15 +130,16 @@ true true HAVE_LOG_H;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - ..\..\libsamplerate-0.1.9\src + + Console true 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;libsamplerate-0.lib;%(AdditionalDependencies) - ..\..\libsamplerate\Release;%(AdditionalLibraryDirectories) + 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) @@ -148,15 +151,16 @@ true true HAVE_LOG_H;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - ..\..\libsamplerate-0.1.9\src + + Console true 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;libsamplerate-0.lib;%(AdditionalDependencies) - ..\..\libsamplerate\x64\Release;%(AdditionalLibraryDirectories) + 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 aa7dec7..495a862 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,11 @@ # 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 -LIBS = -lpthread -lutil -lsamplerate +LIBS = -lpthread -lutil LDFLAGS = -g -L/usr/local/lib OBJECTS = \ diff --git a/Makefile.Pi.Adafruit b/Makefile.Pi.Adafruit index 1b4e15b..4214758 100644 --- a/Makefile.Pi.Adafruit +++ b/Makefile.Pi.Adafruit @@ -1,10 +1,12 @@ # 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 -LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil -lsamplerate +LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil LDFLAGS = -g -L/usr/local/lib OBJECTS = \ diff --git a/Makefile.Pi.HD44780 b/Makefile.Pi.HD44780 index 31a3159..ae98870 100644 --- a/Makefile.Pi.HD44780 +++ b/Makefile.Pi.HD44780 @@ -1,9 +1,11 @@ # 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 -LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil -lsamplerate +LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil LDFLAGS = -g -L/usr/local/lib OBJECTS = \ diff --git a/Makefile.Pi.I2C b/Makefile.Pi.I2C index 44f436d..4c3e2b4 100644 --- a/Makefile.Pi.I2C +++ b/Makefile.Pi.I2C @@ -1,9 +1,11 @@ # 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 -LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil -lsamplerate +LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil LDFLAGS = -g -L/usr/local/lib OBJECTS = \ diff --git a/Makefile.Pi.OLED b/Makefile.Pi.OLED index 538ff64..8fdb050 100644 --- a/Makefile.Pi.OLED +++ b/Makefile.Pi.OLED @@ -1,9 +1,11 @@ # 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 -LIBS = -lArduiPi_OLED -lpthread -lutil -lsamplerate +LIBS = -lArduiPi_OLED -lpthread -lutil # If you use NetBSD, add following CFLAGS #CFLAGS += -L/usr/local/lib -Wl,-rpath=/usr/local/lib diff --git a/Makefile.Pi.PCF8574 b/Makefile.Pi.PCF8574 index c1aa3d1..86a3351 100644 --- a/Makefile.Pi.PCF8574 +++ b/Makefile.Pi.PCF8574 @@ -1,10 +1,12 @@ # 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 -LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil -lsamplerate +LIBS = -lwiringPi -lwiringPiDev -lpthread -lutil LDFLAGS = -g -L/usr/local/lib OBJECTS = \ diff --git a/Version.h b/Version.h index 20b0fc6..5478441 100644 --- a/Version.h +++ b/Version.h @@ -19,6 +19,6 @@ #if !defined(VERSION_H) #define VERSION_H -const char* VERSION = "20240223"; +const char* VERSION = "20240429"; #endif