Skip to content

Commit

Permalink
allow rough receiver location to wander gradually
Browse files Browse the repository at this point in the history
only if receiver extent becomes quite large
  • Loading branch information
wiedehopf committed Jun 6, 2024
1 parent 28a67c0 commit 692d412
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
2 changes: 1 addition & 1 deletion net_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -5486,7 +5486,7 @@ void modesNetPeriodicWork(void) {

if (Modes.receiverTable) {
static uint32_t upcount;
int nParts = 5 * MINUTES / free_client_interval;
int nParts = RECEIVER_MAINTENANCE_INTERVAL / free_client_interval;
receiverTimeout((upcount % nParts), nParts, now);
upcount++;
}
Expand Down
41 changes: 38 additions & 3 deletions receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,35 @@ struct receiver *receiverCreate(uint64_t id) {
fprintf(stderr, "receiverCount: %"PRIu64"\n", Modes.receiverCount);
return r;
}
//static void receiverMaintenance(struct receiver *re) {
//}
static void receiverDebugPrint(struct receiver *r, char *message) {
if (1) {
return;
}
fprintf(stderr, "%016"PRIx64" %9lld %6.1f %6.1f %6.1f %6.1f %s\n",
r->id, (long long) r->positionCounter,
r->latMin, r->latMax, r->lonMin, r->lonMax,
message);
}
static void receiverMaintenance(struct receiver *r) {
double decay = 0.005 * RECEIVER_MAINTENANCE_INTERVAL / SECONDS;

receiverDebugPrint(r, "beforeDecay");

// only decay if extent is pretty large

if (r->latMax - r->latMin > 10) {
r->latMax -= decay;
r->latMin += decay;
}

if (r->lonMax - r->lonMin > 10) {
r->lonMax -= decay;
r->lonMin += decay;
}

receiverDebugPrint(r, "afterDecay");

}
void receiverTimeout(int part, int nParts, int64_t now) {
if (!Modes.receiverTable) {
return;
Expand Down Expand Up @@ -78,7 +105,7 @@ void receiverTimeout(int part, int nParts, int64_t now) {
Modes.receiverCount--;
free(del);
} else {
//receiverMaintenance(*r);
receiverMaintenance(*r);
r = &(*r)->next;
}
}
Expand Down Expand Up @@ -158,6 +185,14 @@ int receiverPositionReceived(struct aircraft *a, struct modesMessage *mm, double

r->lonMax = fmax(r->lonMax, lon);
r->latMax = fmax(r->latMax, lat);
if (
before.latMin != r->latMin
|| before.latMax != r->latMax
|| before.lonMin != r->lonMin
|| before.lonMax != r->lonMax
) {
//receiverDebugPrint(r, "growingExtent");
}
r->goodCounter++;
r->badCounter = fmax(0, r->badCounter - 0.5);
}
Expand Down
2 changes: 2 additions & 0 deletions receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#define RECEIVER_RANGE_BAD (-7)
#define RECEIVER_RANGE_UNCLEAR (-1)

#define RECEIVER_MAINTENANCE_INTERVAL (5 * MINUTES)

struct bad_ac {
uint32_t addr;
int64_t ts;
Expand Down

0 comments on commit 692d412

Please sign in to comment.