Skip to content

Commit

Permalink
airborne CPR: allow bigger time interval for lower speeds
Browse files Browse the repository at this point in the history
  • Loading branch information
wiedehopf committed Jun 10, 2024
1 parent 692d412 commit f8c24ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions nogrind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ source /etc/default/test
cp -f readsb /tmp/test123

#gdb -ex=run --args /tmp/test123 --quiet $RECEIVER_OPTIONS $DECODER_OPTIONS $NET_OPTIONS $JSON_OPTIONS $@
#gdb -batch -ex 'set confirm off' -ex 'handle SIGTERM nostop print pass' -ex 'handle SIGINT nostop print pass' -ex run -ex 'bt full' --args \
/tmp/test123 --quiet $RECEIVER_OPTIONS $DECODER_OPTIONS $NET_OPTIONS $JSON_OPTIONS $@
#sudo -u readsb ./readsb --quiet $RECEIVER_OPTIONS $DECODER_OPTIONS $NET_OPTIONS $JSON_OPTIONS --net-connector 127.0.0.1,50006,beast_in $@

17 changes: 15 additions & 2 deletions track.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ static uint16_t simpleHash(uint64_t receiverId) {
return simpleHash;
}

static int64_t cpr_global_airborne_max_elapsed(int64_t now, struct aircraft *a) {
if (trackDataAge(now, &a->gs_valid) > 10 * SECONDS) {
return 10 * SECONDS;
}
int speed = imax((int64_t) a->gs, 1);
// max time for 500 knots gs
int64_t ref = 19 * SECONDS; // empirically tested
int64_t ival = (ref * 500) / speed;
// never return more than 30 seconds
ival = imin(30 * SECONDS, ival);
return ival;
}

static float knots_to_meterpersecond = (1852.0 / 3600.0);

static void calculateMessageRateGlobal(int64_t now) {
Expand Down Expand Up @@ -1247,8 +1260,8 @@ static void updatePosition(struct aircraft *a, struct modesMessage *mm, int64_t
if (mm->source != SOURCE_MLAT)
Modes.stats_current.cpr_airborne++;

// Airborne: 10 seconds
max_elapsed = 10000;
// Airborne: determine depending on speed, fallback 10 seconds
max_elapsed = cpr_global_airborne_max_elapsed(now, a);
}

// If we have enough recent data, try global CPR
Expand Down

0 comments on commit f8c24ac

Please sign in to comment.