From 512f53e05f2f738657d30a8cae2f142939cf9a40 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Mon, 22 Apr 2024 13:36:44 +0100 Subject: [PATCH] Allow the programs to build on Windows again. --- P25Gateway/P25Gateway.cpp | 9 ++++++-- P25Gateway/P25Gateway.vcxproj | 12 ++++++++++ P25Gateway/UDPSocket.h | 3 ++- P25Gateway/prebuild.cmd | 38 ++++++++++++++++++++++++++++++++ P25Parrot/P25Parrot.cpp | 41 ++++++++++++++++++++++------------- P25Parrot/P25Parrot.vcxproj | 12 ++++++++++ P25Parrot/UDPSocket.h | 3 ++- P25Parrot/prebuild.cmd | 38 ++++++++++++++++++++++++++++++++ 8 files changed, 137 insertions(+), 19 deletions(-) create mode 100644 P25Gateway/prebuild.cmd create mode 100644 P25Parrot/prebuild.cmd diff --git a/P25Gateway/P25Gateway.cpp b/P25Gateway/P25Gateway.cpp index 6a00e8a..b96bfd1 100644 --- a/P25Gateway/P25Gateway.cpp +++ b/P25Gateway/P25Gateway.cpp @@ -28,6 +28,7 @@ #include "Timer.h" #include "Utils.h" #include "Log.h" +#include "GitVersion.h"" #if defined(_WIN32) || defined(_WIN64) #include @@ -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::const_iterator it = staticTGs.cbegin(); it != staticTGs.cend(); ++it) { if (CUDPSocket::match(addr, (*it).m_addr)) { diff --git a/P25Gateway/P25Gateway.vcxproj b/P25Gateway/P25Gateway.vcxproj index 5589d3b..b1d7769 100644 --- a/P25Gateway/P25Gateway.vcxproj +++ b/P25Gateway/P25Gateway.vcxproj @@ -94,6 +94,9 @@ true ws2_32.lib;%(AdditionalDependencies) + + prebuild.cmd + @@ -108,6 +111,9 @@ true ws2_32.lib;%(AdditionalDependencies) + + prebuild.cmd + @@ -126,6 +132,9 @@ true ws2_32.lib;%(AdditionalDependencies) + + prebuild.cmd + @@ -144,6 +153,9 @@ true ws2_32.lib;%(AdditionalDependencies) + + prebuild.cmd + diff --git a/P25Gateway/UDPSocket.h b/P25Gateway/UDPSocket.h index 28e350c..75228a3 100644 --- a/P25Gateway/UDPSocket.h +++ b/P25Gateway/UDPSocket.h @@ -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 diff --git a/P25Gateway/prebuild.cmd b/P25Gateway/prebuild.cmd new file mode 100644 index 0000000..697fde9 --- /dev/null +++ b/P25Gateway/prebuild.cmd @@ -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... diff --git a/P25Parrot/P25Parrot.cpp b/P25Parrot/P25Parrot.cpp index 37aaf70..20f7a2e 100644 --- a/P25Parrot/P25Parrot.cpp +++ b/P25Parrot/P25Parrot.cpp @@ -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 #include @@ -30,21 +31,31 @@ int main(int argc, char** argv) { - if (argc == 1) { - ::fprintf(stderr, "Usage: P25Parrot \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] \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) : diff --git a/P25Parrot/P25Parrot.vcxproj b/P25Parrot/P25Parrot.vcxproj index 56171eb..79efb78 100644 --- a/P25Parrot/P25Parrot.vcxproj +++ b/P25Parrot/P25Parrot.vcxproj @@ -94,6 +94,9 @@ true ws2_32.lib;%(AdditionalDependencies) + + prebuild.cmd + @@ -108,6 +111,9 @@ true ws2_32.lib;%(AdditionalDependencies) + + prebuild.cmd + @@ -126,6 +132,9 @@ true ws2_32.lib;%(AdditionalDependencies) + + prebuild.cmd + @@ -144,6 +153,9 @@ true ws2_32.lib;%(AdditionalDependencies) + + prebuild.cmd + diff --git a/P25Parrot/UDPSocket.h b/P25Parrot/UDPSocket.h index 28e350c..75228a3 100644 --- a/P25Parrot/UDPSocket.h +++ b/P25Parrot/UDPSocket.h @@ -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 diff --git a/P25Parrot/prebuild.cmd b/P25Parrot/prebuild.cmd new file mode 100644 index 0000000..697fde9 --- /dev/null +++ b/P25Parrot/prebuild.cmd @@ -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...