Allow the programs to build on Windows again.

This commit is contained in:
Jonathan Naylor 2024-04-22 13:36:44 +01:00
parent eb26a6233e
commit 512f53e05f
8 changed files with 137 additions and 19 deletions

View File

@ -28,6 +28,7 @@
#include "Timer.h"
#include "Utils.h"
#include "Log.h"
#include "GitVersion.h""
#if defined(_WIN32) || defined(_WIN64)
#include <WS2tcpip.h>
@ -73,7 +74,7 @@ int main(int argc, char** argv)
for (int currentArg = 1; currentArg < argc; ++currentArg) {
std::string arg = argv[currentArg];
if ((arg == "-v") || (arg == "--version")) {
::fprintf(stdout, "P25Gateway version %s\n", VERSION);
::fprintf(stdout, "P25Gateway version %s git #%.7s\n", VERSION, gitversion);
return 0;
} else if (arg.substr(0, 1) == "-") {
::fprintf(stderr, "Usage: P25Gateway [-v|--version] [filename]\n");
@ -313,7 +314,11 @@ void CP25Gateway::run()
pollReply[i + 1U] = callsign.at(i);
// Don't pass reflector control data through to the MMDVM
if ((buffer[0U] != 0xF0U && buffer[0U] != 0xF1U) || (poll = (::memcmp(buffer, pollReply, std::min(11U, len)) == 0))) {
unsigned int pollLen = 11U;
if (len < pollLen)
pollLen = len;
if ((buffer[0U] != 0xF0U && buffer[0U] != 0xF1U) || (poll = (::memcmp(buffer, pollReply, pollLen) == 0))) {
// Find the static TG that this audio data belongs to
for (std::vector<CStaticTG>::const_iterator it = staticTGs.cbegin(); it != staticTGs.cend(); ++it) {
if (CUDPSocket::match(addr, (*it).m_addr)) {

View File

@ -94,6 +94,9 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>prebuild.cmd</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
@ -108,6 +111,9 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>prebuild.cmd</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
@ -126,6 +132,9 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>prebuild.cmd</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
@ -144,6 +153,9 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>prebuild.cmd</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="Conf.h" />

View File

@ -69,10 +69,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

38
P25Gateway/prebuild.cmd Normal file
View File

@ -0,0 +1,38 @@
@echo off
REM This pre-build file is for MSVS VC++. It parses the git master hash and
REM converts it into GitVersion.h for compiling into builds. [George M1GEO]
cd %1
setlocal enabledelayedexpansion
set HEADFILE=..\.git\HEAD
set HASHFILE=0
if exist %HEADFILE% (
for /F "tokens=4 delims=/:" %%a in ('type %HEADFILE%') do set HEADBRANCH=%%a
set HASHFILE=.git\refs\heads\!HEADBRANCH!
echo Found Git HEAD file: %HEADFILE%
echo Git HEAD branch: !HEADBRANCH!
echo Git HASH file: !HASHFILE!
call :USEHASH
) else (
echo No head file :(
call :USENULL
)
goto :EOF
:USENULL
set GITHASH=0000000000000000000000000000000000000000
goto :WRITEGITVERSIONHEADER
:USEHASH
for /f %%i in ('type !HASHFILE!') do set GITHASH=%%i
goto :WRITEGITVERSIONHEADER
:WRITEGITVERSIONHEADER
echo // File contains Git commit ID SHA1 present at buildtime (prebuild.cmd) > GitVersion.h
echo const char *gitversion = "%GITHASH%"; >> GitVersion.h
echo Current Git HASH: %GITHASH%
goto :FINISHED
:FINISHED
echo GitVersion.h written...

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016,2018,2020 by Jonathan Naylor G4KLX
* Copyright (C) 2016,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
@ -23,6 +23,7 @@
#include "Version.h"
#include "Thread.h"
#include "Timer.h"
#include "GitVersion.h"
#include <cstdio>
#include <cstdlib>
@ -30,21 +31,31 @@
int main(int argc, char** argv)
{
if (argc == 1) {
::fprintf(stderr, "Usage: P25Parrot <port>\n");
return 1;
if (argc > 1) {
for (int currentArg = 1; currentArg < argc; ++currentArg) {
std::string arg = argv[currentArg];
if ((arg == "-v") || (arg == "--version")) {
::fprintf(stdout, "P25Parrot version %s git #%.7s\n", VERSION, gitversion);
return 0;
}
else if (arg.substr(0, 1) == "-") {
::fprintf(stderr, "Usage: P25Parrot [-v|--version] [-d|--debug] <port>\n");
return 1;
}
else {
unsigned short port = (unsigned short)::atoi(argv[1U]);
if (port == 0U) {
::fprintf(stderr, "P25Parrot: invalid port number - %s\n", argv[1U]);
return 1;
}
CP25Parrot parrot(port);
parrot.run();
return 0;
}
}
}
unsigned short port = (unsigned short)::atoi(argv[1U]);
if (port == 0U) {
::fprintf(stderr, "P25Parrot: invalid port number - %s\n", argv[1U]);
return 1;
}
CP25Parrot parrot(port);
parrot.run();
return 0;
}
CP25Parrot::CP25Parrot(unsigned short port) :

View File

@ -94,6 +94,9 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>prebuild.cmd</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
@ -108,6 +111,9 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>prebuild.cmd</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
@ -126,6 +132,9 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>prebuild.cmd</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
@ -144,6 +153,9 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>prebuild.cmd</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="Network.h" />

View File

@ -69,10 +69,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

38
P25Parrot/prebuild.cmd Normal file
View File

@ -0,0 +1,38 @@
@echo off
REM This pre-build file is for MSVS VC++. It parses the git master hash and
REM converts it into GitVersion.h for compiling into builds. [George M1GEO]
cd %1
setlocal enabledelayedexpansion
set HEADFILE=..\.git\HEAD
set HASHFILE=0
if exist %HEADFILE% (
for /F "tokens=4 delims=/:" %%a in ('type %HEADFILE%') do set HEADBRANCH=%%a
set HASHFILE=.git\refs\heads\!HEADBRANCH!
echo Found Git HEAD file: %HEADFILE%
echo Git HEAD branch: !HEADBRANCH!
echo Git HASH file: !HASHFILE!
call :USEHASH
) else (
echo No head file :(
call :USENULL
)
goto :EOF
:USENULL
set GITHASH=0000000000000000000000000000000000000000
goto :WRITEGITVERSIONHEADER
:USEHASH
for /f %%i in ('type !HASHFILE!') do set GITHASH=%%i
goto :WRITEGITVERSIONHEADER
:WRITEGITVERSIONHEADER
echo // File contains Git commit ID SHA1 present at buildtime (prebuild.cmd) > GitVersion.h
echo const char *gitversion = "%GITHASH%"; >> GitVersion.h
echo Current Git HASH: %GITHASH%
goto :FINISHED
:FINISHED
echo GitVersion.h written...