Skip to content

Commit

Permalink
Merge pull request #62 from iNavFlight/homepos
Browse files Browse the repository at this point in the history
fix max fields define, home index
  • Loading branch information
stronnag authored Jan 30, 2023
2 parents f419ff0 + 216cdb0 commit 6748326
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ typedef struct flightLogPrivate_t
// When 32-bit time values roll over to zero, we add 2^32 to this accumulator so it can be added to the time:
int64_t timeRolloverAccumulator;

int64_t gpsHomeHistory[2][FLIGHT_LOG_MAX_FIELDS]; // 0 - space to decode new frames into, 1 - previous frame
int64_t gpsHomeHistory[2][2]; // 0 - space to decode new frames into, 1 - previous frame
bool gpsHomeIsValid;

//Because these events don't depend on previous events, we don't keep copies of the old state, just the current one:
Expand Down Expand Up @@ -602,15 +602,13 @@ static int64_t applyPrediction(flightLog_t *log, int fieldIndex, int predictor,
fprintf(stderr, "Attempted to base prediction on GPS home position without GPS home frame definition\n");
exit(-1);
}

value += private->gpsHomeHistory[1][log->gpsHomeFieldIndexes.GPS_home[0]];
break;
case FLIGHT_LOG_FIELD_PREDICTOR_HOME_COORD_1:
if (log->gpsHomeFieldIndexes.GPS_home[1] < 1) {
fprintf(stderr, "Attempted to base prediction on GPS home position without GPS home frame definition\n");
exit(-1);
}

value += private->gpsHomeHistory[1][log->gpsHomeFieldIndexes.GPS_home[1]];
break;
case FLIGHT_LOG_FIELD_PREDICTOR_LAST_MAIN_FRAME_TIME:
Expand Down Expand Up @@ -1342,7 +1340,13 @@ static bool completeGPSHomeFrame(flightLog_t *log, mmapStream_t *stream, uint8_t
(void) raw;

//Copy the decoded frame into the "last state" entry of gpsHomeHistory to publish it:
memcpy(&log->private->gpsHomeHistory[1], &log->private->gpsHomeHistory[0], sizeof(*log->private->gpsHomeHistory));
// memcpy(&log->private->gpsHomeHistory[1], &log->private->gpsHomeHistory[0], sizeof(*log->private->gpsHomeHistory));

log->private->gpsHomeHistory[1][log->gpsHomeFieldIndexes.GPS_home[0]] =
log->private->gpsHomeHistory[0][log->gpsHomeFieldIndexes.GPS_home[0]];
log->private->gpsHomeHistory[1][log->gpsHomeFieldIndexes.GPS_home[1]] =
log->private->gpsHomeHistory[0][log->gpsHomeFieldIndexes.GPS_home[1]];

log->private->gpsHomeIsValid = log->private->mainStreamIsValid;

if (log->private->onFrameReady) {
Expand Down Expand Up @@ -1604,10 +1608,11 @@ void flightLogDestroy(flightLog_t *log)
bool getHomeCoordinates(flightLog_t *log, double *lat, double *lon)
{
if (log->private->gpsHomeIsValid) {
*lat = log->private->gpsHomeHistory[0][log->gpsHomeFieldIndexes.GPS_home[0]] / 1e7;
*lon = log->private->gpsHomeHistory[0][log->gpsHomeFieldIndexes.GPS_home[1]] / 1e7;
*lat = log->private->gpsHomeHistory[1][log->gpsHomeFieldIndexes.GPS_home[0]] / 1e7;
*lon = log->private->gpsHomeHistory[1][log->gpsHomeFieldIndexes.GPS_home[1]] / 1e7;
} else {
*lat = *lon = 0;
}

return log->private->gpsHomeIsValid;
}
2 changes: 1 addition & 1 deletion src/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "blackbox_fielddefs.h"

#define FLIGHT_LOG_MAX_LOGS_IN_FILE 128
#define FLIGHT_LOG_MAX_FIELDS 128
#define FLIGHT_LOG_MAX_FIELDS 256
#define FLIGHT_LOG_MAX_FRAME_LENGTH 256

#define FLIGHT_LOG_FIELD_INDEX_ITERATION 0
Expand Down

0 comments on commit 6748326

Please sign in to comment.