From 952ccb68c47198ff23ef64e841cdfd2b09f14d0e Mon Sep 17 00:00:00 2001 From: Petr Ledvina Date: Fri, 6 Sep 2024 09:46:51 +0200 Subject: [PATCH] cli - fix gpspassthrouh when GPS port is not open (#13878) - return status from gpsPassthrough - test gpsPort --- src/main/cli/cli.c | 4 +++- src/main/io/gps.c | 15 +++++++++++++-- src/main/io/gps.h | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/cli/cli.c b/src/main/cli/cli.c index b380e2c47c8..993b77ad208 100644 --- a/src/main/cli/cli.c +++ b/src/main/cli/cli.c @@ -3603,7 +3603,9 @@ static void cliGpsPassthrough(const char *cmdName, char *cmdline) UNUSED(cmdName); UNUSED(cmdline); - gpsEnablePassthrough(cliPort); + if (!gpsPassthrough(cliPort)) { + cliPrintErrorLinef(cmdName, "GPS forwarding failed"); + } } #endif diff --git a/src/main/io/gps.c b/src/main/io/gps.c index 883ec7952cc..299e594b65b 100644 --- a/src/main/io/gps.c +++ b/src/main/io/gps.c @@ -2486,13 +2486,22 @@ static void gpsHandlePassthrough(uint8_t data) #endif } -void gpsEnablePassthrough(serialPort_t *gpsPassthroughPort) +// forward GPS data to specified port (used by CLI) +// return false if forwarding failed +// curently only way to stop forwarding is to reset the board +bool gpsPassthrough(serialPort_t *gpsPassthroughPort) { + if (!gpsPort) { + // GPS port is not open for some reason - no GPS, MSP GPS, .. + return false; + } waitForSerialPortToFinishTransmitting(gpsPort); waitForSerialPortToFinishTransmitting(gpsPassthroughPort); - if (!(gpsPort->mode & MODE_TX)) + if (!(gpsPort->mode & MODE_TX)) { + // try to switch TX mode on serialSetMode(gpsPort, gpsPort->mode | MODE_TX); + } #ifdef USE_DASHBOARD if (featureIsEnabled(FEATURE_DASHBOARD)) { @@ -2502,6 +2511,8 @@ void gpsEnablePassthrough(serialPort_t *gpsPassthroughPort) #endif serialPassthrough(gpsPort, gpsPassthroughPort, &gpsHandlePassthrough, NULL); + // allow exitting passthrough mode in future + return true; } float GPS_cosLat = 1.0f; // this is used to offset the shrinking longitude as we go towards the poles diff --git a/src/main/io/gps.h b/src/main/io/gps.h index fbfa12fb1e0..66153393d40 100644 --- a/src/main/io/gps.h +++ b/src/main/io/gps.h @@ -386,7 +386,7 @@ void gpsUpdate(timeUs_t currentTimeUs); bool gpsNewFrame(uint8_t c); bool gpsIsHealthy(void); // Returns true when the gps state is RECEIVING_DATA struct serialPort_s; -void gpsEnablePassthrough(struct serialPort_s *gpsPassthroughPort); +bool gpsPassthrough(struct serialPort_s *gpsPassthroughPort); void onGpsNewData(void); void GPS_reset_home_position(void); void GPS_calc_longitude_scaling(int32_t lat);