Skip to content

Commit

Permalink
Begin getting it to compile on Windows again.
Browse files Browse the repository at this point in the history
  • Loading branch information
g4klx committed Apr 22, 2024
1 parent 0e8788b commit ca2bff7
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 19 deletions.
1 change: 0 additions & 1 deletion Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "Timer.h"
#include "UserDBentry.h"
#include "UDPSocket.h"
#include "Modem.h"

#include <string>
Expand Down
39 changes: 27 additions & 12 deletions FMNetwork.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -28,7 +28,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

const unsigned int MMDVM_SAMPLERATE = 8000U;

Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion FMNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
11 changes: 8 additions & 3 deletions LCDproc.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -73,6 +73,7 @@
#include <stdarg.h>
#else
#include <ws2tcpip.h>
#include <WinSock2.h>
#endif

#define BUFFER_MAX_LEN 128
Expand Down Expand Up @@ -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';

Expand Down
1 change: 1 addition & 0 deletions LCDproc.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#if !defined(LCDproc_H)
#define LCDproc_H

#include "UDPSocket.h"
#include "Display.h"
#include "Timer.h"

Expand Down
4 changes: 4 additions & 0 deletions MMDVMHost.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>HAVE_LOG_H;WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\libsamplerate-0.1.9\src</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -102,6 +103,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>HAVE_LOG_H;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\libsamplerate-0.1.9\src</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -124,6 +126,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>HAVE_LOG_H;WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\libsamplerate-0.1.9\src</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -142,6 +145,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>HAVE_LOG_H;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\libsamplerate-0.1.9\src</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down
3 changes: 2 additions & 1 deletion NetworkInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
#include <net/route.h>
#endif
#elif defined(_WIN32) || defined(_WIN64)
#include <ws2tcpip.h>
// #include <ws2tcpip.h>
// #include <WinSock2.h>
#include <iphlpapi.h>
#pragma comment(lib, "iphlpapi.lib")
#ifndef NO_ERROR
Expand Down
2 changes: 2 additions & 0 deletions NetworkInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#if !defined(NETWORKINFO_H)
#define NETWORKINFO_H

#include "UDPSocket.h"

class CNetworkInfo {
public:
CNetworkInfo();
Expand Down
4 changes: 3 additions & 1 deletion UDPSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <errno.h>
#else
#include <ws2tcpip.h>
#include <Winsock2.h>
#endif

enum IPMATCHTYPE {
Expand Down Expand Up @@ -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

0 comments on commit ca2bff7

Please sign in to comment.