Skip to content

Commit

Permalink
improve receiver count logic
Browse files Browse the repository at this point in the history
set to zero when no position has been received for 5 seconds
  • Loading branch information
wiedehopf committed Jan 4, 2025
1 parent ae987a9 commit 8c82ea5
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions track.c
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,8 @@ static void setPosition(struct aircraft *a, struct modesMessage *mm, int64_t now
}
}

int64_t elapsed_pos = now - a->seen_pos;

// Update aircraft state
a->prev_lat = a->lat;
a->prev_lon = a->lon;
Expand All @@ -1072,22 +1074,32 @@ static void setPosition(struct aircraft *a, struct modesMessage *mm, int64_t now

a->pos_surface = trackDataValid(&a->airground_valid) && a->airground == AG_GROUND;

// due to accept_data / beast_reduce forwarding we can't put receivers
// due to the position deduplication logic we won't put receivers
// into the receiver list which aren't the first ones to send us the position
if (!Modes.netReceiverId) {
a->receiverCount = 1;
} else {
a->receiverIdsNext = (a->receiverIdsNext + 1) % RECEIVERIDBUFFER;
a->receiverIds[a->receiverIdsNext] = simpleHash(mm->receiverId);
if (0 && a->addr == Modes.cpr_focus) {
fprintf(stderr, "%u\n", simpleHash(mm->receiverId));
}

if (mm->source == SOURCE_MLAT && mm->receiverCountMlat) {
a->receiverCount = mm->receiverCountMlat;
} else if (a->position_valid.source < SOURCE_TISB) {
a->receiverCount = 1;
} else {
a->receiverIdsNext = (a->receiverIdsNext + 1) % RECEIVERIDBUFFER;
a->receiverIds[a->receiverIdsNext] = simpleHash(mm->receiverId);
int64_t advance = imax(RECEIVERIDBUFFER * 500, elapsed_pos);
while (advance > 750) {
// ADS-B positions nominally come in every 500 ms receiver id
// buffer has 12 positions, if the positions don't come in
// often enough we zero them so it's only roughly the receiver
// ids for the last 6 seconds
advance -= 500;
a->receiverIdsNext = (a->receiverIdsNext + 1) % RECEIVERIDBUFFER;
a->receiverIds[a->receiverIdsNext] = 0;
}
if (0 && a->addr == Modes.cpr_focus) {
fprintf(stderr, "%u\n", simpleHash(mm->receiverId));
}

uint16_t *set1 = a->receiverIds;
uint16_t set2[RECEIVERIDBUFFER] = { 0 };
int div = 0;
Expand Down Expand Up @@ -3557,10 +3569,13 @@ static const char *source_string(datasource_t source) {
void updateValidities(struct aircraft *a, int64_t now) {

int64_t elapsed_seen_global = now - a->seenPosGlobal;
int64_t elapsed_pos = now - a->seen_pos;

if (Modes.json_globe_index && elapsed_seen_global < 45 * MINUTES) {
a->receiverIdsNext = (a->receiverIdsNext + 1) % RECEIVERIDBUFFER;
a->receiverIds[a->receiverIdsNext] = 0;
if (elapsed_pos > 5 * SECONDS && a->receiverCount > 0) {
a->receiverCount = 0;
for (int i = 0; i < RECEIVERIDBUFFER; i++) {
a->receiverIds[i] = 0;
}
}

if (a->globe_index >= 0 && now > a->seen_pos + Modes.trackExpireMax) {
Expand Down

0 comments on commit 8c82ea5

Please sign in to comment.