Begin getting it to compile on Windows again.

This commit is contained in:
Jonathan Naylor 2024-04-22 12:48:44 +01:00
parent 0e8788bdbe
commit ca2bff7e9e
10 changed files with 49 additions and 19 deletions

View file

@ -22,7 +22,6 @@
#include "ModemSerialPort.h" #include "ModemSerialPort.h"
#include "NullDisplay.h" #include "NullDisplay.h"
#include "TFTSurenoo.h" #include "TFTSurenoo.h"
#include "UDPSocket.h"
#include "LCDproc.h" #include "LCDproc.h"
#include "Nextion.h" #include "Nextion.h"
#include "CASTInfo.h" #include "CASTInfo.h"

View file

@ -21,6 +21,7 @@
#include "Timer.h" #include "Timer.h"
#include "UserDBentry.h" #include "UserDBentry.h"
#include "UDPSocket.h"
#include "Modem.h" #include "Modem.h"
#include <string> #include <string>

View file

@ -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 * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -28,7 +28,6 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h>
const unsigned int MMDVM_SAMPLERATE = 8000U; const unsigned int MMDVM_SAMPLERATE = 8000U;
@ -48,7 +47,7 @@ m_buffer(2000U, "FM Network"),
m_seqNo(0U), m_seqNo(0U),
m_resampler(NULL), m_resampler(NULL),
m_error(0), m_error(0),
m_fd(-1) m_fp(NULL)
{ {
assert(!callsign.empty()); assert(!callsign.empty());
assert(gatewayPort > 0U); assert(gatewayPort > 0U);
@ -86,9 +85,13 @@ bool CFMNetwork::open()
LogMessage("Opening FM network connection"); LogMessage("Opening FM network connection");
if (!m_squelchFile.empty()) { if (!m_squelchFile.empty()) {
m_fd = ::open(m_squelchFile.c_str(), O_WRONLY | O_SYNC); m_fp = ::fopen(m_squelchFile.c_str(), "wb");
if (m_fd == -1) { 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());
#endif
return false; return false;
} }
} }
@ -316,12 +319,18 @@ bool CFMNetwork::writeRawEnd()
{ {
m_seqNo = 0U; m_seqNo = 0U;
if (m_fd != -1) { if (m_fp != NULL) {
size_t n = ::write(m_fd, "Z", 1); size_t n = ::fwrite("Z", 1, 1, m_fp);
if (n != 1) { if (n != 1) {
#if !defined(_WIN32) && !defined(_WIN64)
LogError("Cannot write to the squelch file: %s, errno=%d", m_squelchFile.c_str(), errno); 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; return false;
} }
::fflush(m_fp);
} }
return true; return true;
@ -442,9 +451,9 @@ void CFMNetwork::close()
{ {
m_socket.close(); m_socket.close();
if (m_fd != -1) { if (m_fp != NULL) {
::close(m_fd); ::fclose(m_fp);
m_fd = -1; m_fp = NULL;
} }
LogMessage("Closing FM network connection"); LogMessage("Closing FM network connection");
@ -559,12 +568,18 @@ bool CFMNetwork::writeUSRPStart()
bool CFMNetwork::writeRawStart() bool CFMNetwork::writeRawStart()
{ {
if (m_fd != -1) { if (m_fp != NULL) {
size_t n = ::write(m_fd, "O", 1); size_t n = ::fwrite("O", 1, 1, m_fp);
if (n != 1) { if (n != 1) {
#if !defined(_WIN32) && !defined(_WIN64)
LogError("Cannot write to the squelch file: %s, errno=%d", m_squelchFile.c_str(), errno); 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; return false;
} }
::fflush(m_fp);
} }
return true; return true;

View file

@ -67,7 +67,7 @@ private:
unsigned int m_seqNo; unsigned int m_seqNo;
SRC_STATE* m_resampler; SRC_STATE* m_resampler;
int m_error; int m_error;
int m_fd; FILE* m_fp;
bool writeUSRPStart(); bool writeUSRPStart();
bool writeRawStart(); bool writeRawStart();

View file

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2016,2017,2018 by Tony Corbett G0WFV * 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 * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -73,6 +73,7 @@
#include <stdarg.h> #include <stdarg.h>
#else #else
#include <ws2tcpip.h> #include <ws2tcpip.h>
#include <WinSock2.h>
#endif #endif
#define BUFFER_MAX_LEN 128 #define BUFFER_MAX_LEN 128
@ -670,15 +671,19 @@ void CLCDproc::clockInt(unsigned int ms)
* exceptfds = we are not waiting for exception fds * 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"); LogError("LCDproc, error on select");
return;
}
// If something was received from the server... // If something was received from the server...
if (FD_ISSET(m_socketfd, &m_readfds)) { if (FD_ISSET(m_socketfd, &m_readfds)) {
m_recvsize = recv(m_socketfd, m_buffer, BUFFER_MAX_LEN, 0); m_recvsize = recv(m_socketfd, m_buffer, BUFFER_MAX_LEN, 0);
if (m_recvsize == -1) if (m_recvsize == -1) {
LogError("LCDproc, cannot receive information"); LogError("LCDproc, cannot receive information");
return;
}
m_buffer[m_recvsize] = '\0'; m_buffer[m_recvsize] = '\0';

View file

@ -20,6 +20,7 @@
#if !defined(LCDproc_H) #if !defined(LCDproc_H)
#define LCDproc_H #define LCDproc_H
#include "UDPSocket.h"
#include "Display.h" #include "Display.h"
#include "Timer.h" #include "Timer.h"

View file

@ -88,6 +88,7 @@
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>HAVE_LOG_H;WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>HAVE_LOG_H;WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\libsamplerate-0.1.9\src</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
@ -102,6 +103,7 @@
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>HAVE_LOG_H;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>HAVE_LOG_H;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\libsamplerate-0.1.9\src</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
@ -124,6 +126,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>HAVE_LOG_H;WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>HAVE_LOG_H;WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\libsamplerate-0.1.9\src</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
@ -142,6 +145,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>HAVE_LOG_H;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>HAVE_LOG_H;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\libsamplerate-0.1.9\src</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>

View file

@ -38,7 +38,8 @@
#include <net/route.h> #include <net/route.h>
#endif #endif
#elif defined(_WIN32) || defined(_WIN64) #elif defined(_WIN32) || defined(_WIN64)
#include <ws2tcpip.h> // #include <ws2tcpip.h>
// #include <WinSock2.h>
#include <iphlpapi.h> #include <iphlpapi.h>
#pragma comment(lib, "iphlpapi.lib") #pragma comment(lib, "iphlpapi.lib")
#ifndef NO_ERROR #ifndef NO_ERROR

View file

@ -19,6 +19,8 @@
#if !defined(NETWORKINFO_H) #if !defined(NETWORKINFO_H)
#define NETWORKINFO_H #define NETWORKINFO_H
#include "UDPSocket.h"
class CNetworkInfo { class CNetworkInfo {
public: public:
CNetworkInfo(); CNetworkInfo();

View file

@ -33,6 +33,7 @@
#include <errno.h> #include <errno.h>
#else #else
#include <ws2tcpip.h> #include <ws2tcpip.h>
#include <Winsock2.h>
#endif #endif
enum IPMATCHTYPE { enum IPMATCHTYPE {
@ -69,10 +70,11 @@ private:
unsigned short m_localPort; unsigned short m_localPort;
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
SOCKET m_fd; SOCKET m_fd;
int m_af;
#else #else
int m_fd; int m_fd;
#endif
sa_family_t m_af; sa_family_t m_af;
#endif
}; };
#endif #endif