From ca2bff7e9ed78a422202f1ba8628aceee9768e43 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Mon, 22 Apr 2024 12:48:44 +0100 Subject: [PATCH] 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 ab0c0bb8d..c09111d2f 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 314c9dbcf..af067b938 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 02ff5bf23..10891ef56 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 9940f9009..6380d6f01 100644 --- a/FMNetwork.h +++ b/FMNetwork.h @@ -67,7 +67,7 @@ class CFMNetwork { 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 43595a800..7167eedce 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 b702493d9..5a74bfb57 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 dc7a76b2c..50d7684a2 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 78f608049..10a9d620b 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 2febcde90..a58cef81e 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 28e350c09..abc943606 100644 --- a/UDPSocket.h +++ b/UDPSocket.h @@ -33,6 +33,7 @@ #include #else #include +#include #endif enum IPMATCHTYPE { @@ -69,10 +70,11 @@ class CUDPSocket { 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