From c0dea736ff9fb73b2ffa05bab854306dbc9a5a0e Mon Sep 17 00:00:00 2001 From: AlaEddine-Zoghlami Date: Tue, 23 Jun 2026 16:10:04 +0200 Subject: [PATCH 1/2] StreamTxDemo: fix mingw/Windows-GCC build and binary stdin Building the stream-link TX demo with mingw (GCC on Windows) was broken two ways: 1. The Windows include block (io.h/fcntl.h) and the `_setmode(_fileno(stdin), _O_BINARY)` call were gated on `_MSC_VER`, but mingw/GCC defines `_WIN32`, not `_MSC_VER`. So mingw fell into the POSIX `#else` branch, left stdin in TEXT mode, and a 0x1A or CRLF byte in the binary length-prefixed PSDU stream truncated the first record ("short read on stdin (76/269); record truncated mid-PSDU") before a single frame was transmitted. Add a `__MINGW32__/__MINGW64__` include branch (io.h + fcntl.h + unistd.h + libusb) and gate `_setmode` on `_WIN32` (identical on MSVC, now also correct on mingw). 2. CMakeLists unconditionally set CMAKE_TOOLCHAIN_FILE to "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" on WIN32; with VCPKG_ROOT unset (the mingw/pkg-config case) it expands to the bogus "/scripts/buildsystems/vcpkg.cmake" and configuration aborts. Only set it when VCPKG_ROOT is non-empty. Verified on mingw-w64 (libusb 1.0.28 via pkg-config): StreamTxDemo.exe now reads the full binary stream and radiates every frame ("TX #N ok=1 ... done; sent 512 PSDUs"). Co-Authored-By: Claude Opus 4.8 (1M context) --- CMakeLists.txt | 5 +++-- txdemo/stream_tx_demo/main.cpp | 9 ++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b4e274c..cadf7ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,8 @@ cmake_minimum_required(VERSION 3.15) -# Set the toolchain file for vcpkg on Windows. -if(WIN32) +# Set the toolchain file for vcpkg on Windows (only if VCPKG_ROOT is set; +# on mingw we get libusb from pkg-config directly). +if(WIN32 AND NOT "$ENV{VCPKG_ROOT}" STREQUAL "") set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake") endif() diff --git a/txdemo/stream_tx_demo/main.cpp b/txdemo/stream_tx_demo/main.cpp index 7dc1279..c67d485 100644 --- a/txdemo/stream_tx_demo/main.cpp +++ b/txdemo/stream_tx_demo/main.cpp @@ -46,6 +46,12 @@ #include typedef int pid_t; #define sleep(seconds) Sleep((seconds)*1000) +#elif defined(__MINGW32__) || defined(__MINGW64__) + // mingw builds: POSIX libusb/unistd PLUS io.h/fcntl.h for binary stdin. + #include + #include + #include + #include #elif defined(__ANDROID__) #include #include @@ -134,8 +140,9 @@ int main(int argc, char **argv) { } } -#if defined(_MSC_VER) +#if defined(_WIN32) // Make stdin binary so a 0x1A or CRLF doesn't corrupt PSDU bytes. + // (mingw/GCC defines _WIN32 but not _MSC_VER, yet still has _setmode.) _setmode(_fileno(stdin), _O_BINARY); #endif From 2880c0d9bd723a137f042ddbcfd9faf6dcfb9b28 Mon Sep 17 00:00:00 2001 From: AlaEddine-Zoghlami Date: Tue, 23 Jun 2026 22:37:31 +0200 Subject: [PATCH 2/2] StreamDuplexDemo: same mingw binary-stdin + include fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Per review: stream_duplex_demo/main.cpp had the byte-identical _MSC_VER-gated include block + _setmode and reads the same binary stream, so it hit the same first-frame text-mode truncation — and this PR's CMake guard is what makes it buildable under mingw in the first place. Mirror the StreamTxDemo fix (__MINGW32__/__MINGW64__ include branch + _setmode gated on _WIN32) so the two stdin-driven stream demos stay in lockstep. Verified on mingw-w64: StreamDuplexDemo now reads all 512 length-prefixed FEC PSDUs from stdin without truncation ("tx #1..#500 ok=1 ... tx EOF after 512"). Co-Authored-By: Claude Opus 4.8 (1M context) --- txdemo/stream_duplex_demo/main.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/txdemo/stream_duplex_demo/main.cpp b/txdemo/stream_duplex_demo/main.cpp index 400cfe1..d7ff0e2 100644 --- a/txdemo/stream_duplex_demo/main.cpp +++ b/txdemo/stream_duplex_demo/main.cpp @@ -41,6 +41,12 @@ #include typedef int pid_t; #define sleep(seconds) Sleep((seconds)*1000) +#elif defined(__MINGW32__) || defined(__MINGW64__) + // mingw builds: POSIX libusb/unistd PLUS io.h/fcntl.h for binary stdin. + #include + #include + #include + #include #elif defined(__ANDROID__) #include #include @@ -233,7 +239,9 @@ int main(int argc, char **argv) { } } -#if defined(_MSC_VER) +#if defined(_WIN32) + // mingw/GCC defines _WIN32 but not _MSC_VER, yet still has _setmode — make + // stdin binary so a 0x1A/CRLF doesn't corrupt the length-prefixed PSDU stream. _setmode(_fileno(stdin), _O_BINARY); #endif