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 4a3c5e8
Show file tree
Hide file tree
Showing 2 changed files with 17 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 $@

18 changes: 16 additions & 2 deletions track.c
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,20 @@ static void setPosition(struct aircraft *a, struct modesMessage *mm, int64_t now
}
}

static int64_t cpr_global_airborne_max_elapsed(int64_t now, struct aircraft *a) {
if (trackDataAge(now, &a->gs_valid) > 20 * 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);
//fprintf(stderr, "%lld\n", (long long) ival);
return ival;
}

static void updatePosition(struct aircraft *a, struct modesMessage *mm, int64_t now) {
int location_result = -1;
int globalCPR = 0;
Expand All @@ -1247,8 +1261,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 4a3c5e8

Please sign in to comment.