From ba0f775bb9bcb4397544d8c2a8a5820cf902ab0c Mon Sep 17 00:00:00 2001 From: Scott Penrose Date: Tue, 7 Jul 2026 11:54:46 +1000 Subject: [PATCH] Passthrough version --- app/wii5_passthrough/wii5_passthrough.ino | 76 +++++++++++++++++++++++ pio_main_passthrough.cpp | 21 +++++++ platformio.ini | 11 ++++ 3 files changed, 108 insertions(+) create mode 100644 app/wii5_passthrough/wii5_passthrough.ino create mode 100644 pio_main_passthrough.cpp diff --git a/app/wii5_passthrough/wii5_passthrough.ino b/app/wii5_passthrough/wii5_passthrough.ino new file mode 100644 index 0000000..8baaa88 --- /dev/null +++ b/app/wii5_passthrough/wii5_passthrough.ino @@ -0,0 +1,76 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright (c) 2012-2024 Scott Penrose and WII5 Buoy contributors +// +// This file is part of WII5 Buoy firmware. +// See LICENSE for full terms. + +/** + * @file wii5_passthrough.ino + * @brief Minimal firmware: keeps the Maths CPU powered on and provides + * bidirectional raw serial passthrough to the Iridium modem. + * + * The AVR becomes a transparent bridge between the USB console and the + * Iridium 9602/9603 modem (Serial3 @ 19200 baud). AT commands typed on + * the console go directly to the modem; modem responses are echoed back. + * + * Maths CPU (Raspberry Pi) is kept alive indefinitely via the hold timer + * and the MATHS_RETURNLINE hardware signal. + * + * Build (PlatformIO): + * pio run -e wii5_passthrough + */ + +#include +#include + +elapsedMillis wdtWait; +elapsedMillis holdCheckWait; + +void setup() { + wii5Setup.beginSafe(); + wii5Setup.setupConsole(); + + // Maths CPU — start and hold on indefinitely + wii5Maths.begin(); + wii5Maths.start(WII5MATHSMODE_COMMS); + wii5Maths.setHold(MATHS_MAXHOLD); + wii5Maths.setReturnLine(); + + // Iridium modem — initialise, then power on with passthrough + wii5Iridium.begin(); + wii5Iridium.setPassthrough(true); + wii5Iridium.powerOn(true); + + wdtWait = 0; + holdCheckWait = 0; +} + +void loop() { + // ---- external watchdog ---- +#ifdef WDT_RESET + if (wdtWait > 5100) { + digitalWrite(WDT_RESET, LOW); + wdtWait = 0; + } else if (wdtWait > 5000) { + digitalWrite(WDT_RESET, HIGH); + } +#endif + + // ---- Maths CPU keep-alive ---- + wii5Maths.loop(); + if (holdCheckWait > 30000) { + holdCheckWait = 0; + if (wii5Maths.remainingHold() < 600) { + wii5Maths.setHold(MATHS_MAXHOLD); + } + wii5Maths.setReturnLine(); + } + + // ---- Modem → Console (passthrough echo) ---- + wii5Iridium.WII5SerialManager::loop(); + + // ---- Console → Modem (raw forwarding) ---- + while (SerialConsole.available()) { + SerialComms.write(SerialConsole.read()); + } +} diff --git a/pio_main_passthrough.cpp b/pio_main_passthrough.cpp new file mode 100644 index 0000000..76fec75 --- /dev/null +++ b/pio_main_passthrough.cpp @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright (c) 2012-2024 Scott Penrose and WII5 Buoy contributors +// +// This file is part of WII5 Buoy firmware. +// See LICENSE for full terms. + +/** + * @file pio_main_passthrough.cpp + * @brief PlatformIO entry shim for the wii5_passthrough sketch. + * + * PlatformIO only auto-detects a sketch at the top level of its source + * directory. This shim pulls wii5_passthrough.ino into the PlatformIO + * build (where setup() / loop() are defined). + * + * It is gated on PLATFORMIO so that the arduino-cli build never sees a + * second definition of setup() / loop(). + */ + +#if defined(PLATFORMIO) +#include "app/wii5_passthrough/wii5_passthrough.ino" +#endif diff --git a/platformio.ini b/platformio.ini index e2b39a8..dec39f0 100644 --- a/platformio.ini +++ b/platformio.ini @@ -36,6 +36,7 @@ monitor_speed = 230400 ; The entry sketch (app/wii5_buoy/wii5_buoy.ino) is pulled in by pio_main.cpp. build_src_filter = +<*.cpp> + - ; The project's own headers are included with angle brackets (, ...), ; so the repo root must be on the include path. Software version/commit are @@ -65,6 +66,16 @@ lib_deps = arduino-libraries/SD adafruit/RTClib +; Lean pass-through variant: keeps the Maths CPU powered on and provides +; bidirectional raw serial passthrough to the Iridium modem from the USB +; console. Excludes the full wii5_buoy main (pio_main.cpp) so setup()/loop() +; come from pio_main_passthrough.cpp instead. +[env:wii5_passthrough] +extends = env:wii5_buoy +build_src_filter = + +<*.cpp> + - + ; LoRa-enabled variant (experimental). This path additionally depends on the ; Sh3dNode networking stack (sh3dNodeNetwork / SH3D_NODE_Packet_* / RH_RF95), ; which is NOT bundled in this repository, so the env does not build as-is.