Skip to content

Commit

Permalink
cli - fix gpspassthrouh when GPS port is not open (betaflight#13878)
Browse files Browse the repository at this point in the history
- return status from gpsPassthrough
- test gpsPort
  • Loading branch information
ledvinap authored Sep 6, 2024
1 parent f0e1deb commit 952ccb6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/main/cli/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 13 additions & 2 deletions src/main/io/gps.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/io/gps.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 952ccb6

Please sign in to comment.