diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dc5a440..874a833 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,6 +50,7 @@ jobs: run: | python3 tools/check.py python3 tools/test_radar.py + python3 tools/test_radar_schedule.py python3 tools/test_motion.py python3 tools/test_policy.py python3 tools/test_chunked.py diff --git a/CHANGELOG.md b/CHANGELOG.md index ed9f2bd..510d755 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Änderungen +## v0.5.4.3-dev + +- **Radar fragt wieder Positionen ab:** In v0.5.4 schob jede wiederholte Routenabfrage für dasselbe Flugzeug den nächsten Positionsabruf um ein ganzes Intervall nach hinten. Weil diese Wiederholungen alle 2–5 Minuten kamen und das Kontingent-Intervall länger war, kam nie wieder ein Positionsabruf – das Radar blieb beim alten Flugzeug stehen (nachgestellt: 1 Positionsabruf in 2 Stunden). Jetzt gilt: höchstens eine adsb.lol-Routenabfrage zwischen zwei Positionsabrufen, und nur für ein neues Flugzeug. +- **Wiederholte Abfragen für dasselbe Flugzeug** laufen nur noch über adsbdb (ohne adsb.lol-Kontingent), alle 10 statt alle 2–5 Minuten, und behalten Route und Airline, statt sie bis zur Antwort zu löschen. +- **Flug-Tracker im Kontingent:** Die Live-Abfragen bei adsb.lol (bisher fest alle 15 s) folgen derselben Planung wie das Radar. +- **Hochrechnung bis 10 Minuten** (vorher 4), passend zu den längeren Intervallen. +- **Neue Prüfung** `tools/test_radar_schedule.py`: simuliert zwei Stunden mit den echten Planungsfunktionen (gleiches Flugzeug, neue Flugzeuge, Rotation) und schlägt bei v0.5.4 an. + ## v0.5.4.2-dev - **Netzwerk-Wächter repariert:** In v0.5.4 setzte er sich jede Sekunde selbst zurück, sobald seit dem Start irgendeine Antwort kam. Löste er aus, verband er das WLAN jede Sekunde neu – der Würfel kam nie wieder ins Netz, und der geplante Neustart wurde nie erreicht. Jetzt beendet nur eine *neue* Antwort nach dem Neuverbinden den Alarm; bleibt sie aus, folgt nach 5 Minuten der Neustart. Logik in `src/NetWatch.h` mit Tests. diff --git a/README.en.md b/README.en.md index ff72e43..2915c7d 100644 --- a/README.en.md +++ b/README.en.md @@ -6,9 +6,9 @@ Bought as a small Wi-Fi cube with a rather modest stock firmware – and from day one with the plan to turn it into something of my own. [![Build](https://github.com/du13500/pixelstop/actions/workflows/build.yml/badge.svg)](https://github.com/du13500/pixelstop/actions/workflows/build.yml) -![Version](https://img.shields.io/badge/version-v0.5.4.2--dev-orange) +![Version](https://img.shields.io/badge/version-v0.5.4.3--dev-orange) ![Hardware](https://img.shields.io/badge/hardware-ESP8266%20%C2%B7%20SmallTV--Ultra-blue) -![Hardware test](https://img.shields.io/badge/hardware%20test-v0.5.4.2%20pending-yellow) +![Hardware test](https://img.shields.io/badge/hardware%20test-v0.5.4.3%20pending-yellow) ![Hobby project](https://img.shields.io/badge/hobby%20project-non--commercial-lightgrey) ![License](https://img.shields.io/badge/license-MIT-green) ![Mission](https://img.shields.io/badge/mission-Know%20before%20you%20go-ff5d56) @@ -59,7 +59,7 @@ Plus night mode, brightness down to 1 %, place search with a map, Greek and Cyri -## Status: v0.5.4.2-dev +## Status: v0.5.4.3-dev | Area | Status | | --- | --- | diff --git a/README.md b/README.md index 27bf9e1..81546b4 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,9 @@ Gekauft als kleiner WLAN-Würfel mit eher bescheidener Werksfirmware – und von Anfang an mit dem Plan, etwas Eigenes daraus zu machen. [![Build](https://github.com/du13500/pixelstop/actions/workflows/build.yml/badge.svg)](https://github.com/du13500/pixelstop/actions/workflows/build.yml) -![Version](https://img.shields.io/badge/version-v0.5.4.2--dev-orange) +![Version](https://img.shields.io/badge/version-v0.5.4.3--dev-orange) ![Hardware](https://img.shields.io/badge/hardware-ESP8266%20%C2%B7%20SmallTV--Ultra-blue) -![Hardwaretest](https://img.shields.io/badge/hardwaretest-v0.5.4.2%20offen-yellow) +![Hardwaretest](https://img.shields.io/badge/hardwaretest-v0.5.4.3%20offen-yellow) ![Hobbyprojekt](https://img.shields.io/badge/hobbyprojekt-nicht%20kommerziell-lightgrey) ![Lizenz](https://img.shields.io/badge/lizenz-MIT-green) ![Mission](https://img.shields.io/badge/mission-Know%20before%20you%20go-ff5d56) @@ -59,7 +59,7 @@ Dazu kommen Nachtmodus, Helligkeit ab 1 %, Ortssuche mit Karte, griechische und -## Entwicklungsstand: v0.5.4.2-dev +## Entwicklungsstand: v0.5.4.3-dev | Bereich | Stand | | --- | --- | diff --git a/TESTPLAN.md b/TESTPLAN.md index 781b356..db03898 100644 --- a/TESTPLAN.md +++ b/TESTPLAN.md @@ -1,8 +1,10 @@ # Testplan -Stand: v0.5.4.2-dev (10.11.2026). Dieser Plan wird mit jeder Version aktualisiert; frühere Pläne stehen in der Git-Historie, Änderungen in [`CHANGELOG.md`](CHANGELOG.md). +Stand: v0.5.4.3-dev (10.11.2026). Dieser Plan wird mit jeder Version aktualisiert; frühere Pläne stehen in der Git-Historie, Änderungen in [`CHANGELOG.md`](CHANGELOG.md). -## Hardwaretest v0.5.4.2-dev +## Hardwaretest v0.5.4.3-dev + +0b. **v0.5.4.3:** Radar über eine Stunde: Im Log kommen regelmäßig „Radar.Position | OK“-Zeilen (Abstand ≈ „Radar-Intervall“ im Status); höchstens eine „Radar.Route“ zwischen zwei Positionen; spätere Prüfungen desselben Flugzeugs nur als „Radar.Metadata“. 0a. **v0.5.4.2:** Im Log nach jedem Start eine Zeile „WLAN | verbunden“ (HTTP-Feld = Funkverbindung nach ms, Wert = IP nach ms). Bei Problemen „WLAN | Fehler“ mit Status. Anzeigename: Ort um mehr als 5 km verschieben → Dialog mit Leeren/Behalten. @@ -49,6 +51,7 @@ Dieselben Prüfungen führt der Workflow [`build.yml`](.github/workflows/build.y ```sh python3 tools/check.py python3 tools/test_radar.py +python3 tools/test_radar_schedule.py python3 tools/test_motion.py python3 tools/test_policy.py python3 tools/test_chunked.py diff --git a/package.json b/package.json index ecb77bb..f3fefb7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixelstop-checks", - "version": "0.5.4.2-dev", + "version": "0.5.4.3-dev", "private": true, "scripts": { "test:webui": "node tests/webui.cjs" diff --git a/src/Flight.cpp b/src/Flight.cpp index 1f8c87a..a3eaf24 100644 --- a/src/Flight.cpp +++ b/src/Flight.cpp @@ -19,6 +19,8 @@ static FlightSnapshot g_f = {}; static uint32_t g_lastPollMs = 0; +// At most one adsb.lol route lookup between two position requests (never starve positions). +static bool g_routeSincePoll = false; static bool g_hasPolled = false; static uint32_t g_lastOkMs = 0; // A provider cooldown retains the last aircraft until a new request completes. @@ -90,7 +92,7 @@ static bool lookupRouteAdsbLol(const FlightSnapshot& f,RoutePoint pos,Enrichment // A route lookup takes the place of the next position request (savings mode). uint8_t skip=adsbLolQuotaWaitMs()?1:(serviceWaitMs(SERVICE_ADSB_LOL)?2:(!tlsHeapReady(adsbLolRx())?4:0)); if(skip){diagLookup(f.hex,f.callsign);diagEvent(D_RADAR_ROUTE,DS_SKIPPED,0,skip);return false;} - g_lastPollMs=millis(); + g_lastPollMs=millis();g_routeSincePoll=true; DiagRequest trace(D_RADAR_ROUTE);diagLookup(f.hex,f.callsign);trace.stage(DS_TLS); BearSSL::WiFiClientSecure client;makeSecure(client,&g_routeSession,adsbLolRx()); HTTPClient http;http.setTimeout(5000);http.setReuse(false); @@ -217,7 +219,8 @@ static void enrichFlight(FlightSnapshot& f,RoutePoint pos) { char brand[19]; if(entry->airline[0]&&!airlineBrand(f.callsign,brand,sizeof(brand)))strlcpy(f.airline,entry->airline,sizeof(f.airline)); if(entry->type[0]&&metadataTypeMatches(f.typeCode,f.category,entry->typeCode))strlcpy(f.typeName,entry->type,sizeof(f.typeName)); - if(entry->route.count && (uint32_t)(now-entry->checked)<300000UL && + // Routes stay valid between the 10-minute checks; the position check still applies. + if(entry->route.count && (uint32_t)(now-entry->checked)<900000UL && routePositionPlausible(pos,entry->airports,entry->airportCount,f.onGround,f.altitudeKnown,f.altitudeFt)){ f.route=entry->route;strlcpy(f.origin,f.route.airports[0],sizeof(f.origin)); strlcpy(f.destination,f.route.airports[f.route.count-1],sizeof(f.destination)); @@ -232,7 +235,7 @@ static Enrichment* currentEnrichment(){ // The adsb.lol route lookup replaces a position request: it needs a free slot // in the quota and keeps the minimum distance after a provider limit. static bool routeSlotFree(){ - if(adsbLolWaitMs())return false; + if(g_routeSincePoll||adsbLolWaitMs())return false; uint32_t minimum=serviceMinIntervalMs(SERVICE_ADSB_LOL); return !minimum||(uint32_t)(millis()-g_lastPollMs)>=minimum; } @@ -240,17 +243,20 @@ bool flightEnrichmentDue(){ if(!g_f.valid||g_f.error||!routePointValid(g_position)||!g_f.callsign[0])return false; Enrichment* e=currentEnrichment(); if(e&&e->phase<3)return e->phase==0?routeSlotFree():!serviceWaitMs(SERVICE_ADSB_DB); - return (!e||(uint32_t)(millis()-e->checked)>=(e->route.count?300000UL:120000UL)) && - (!g_lastEnrichmentMs||(uint32_t)(millis()-g_lastEnrichmentMs)>=60000UL) && routeSlotFree(); + if(g_lastEnrichmentMs&&(uint32_t)(millis()-g_lastEnrichmentMs)<60000UL)return false; + // New aircraft: full lookup including adsb.lol. The same aircraft later: adsbdb + // only (no adsb.lol quota), every 10 minutes, keeping what was found. + if(!e)return routeSlotFree(); + return (uint32_t)(millis()-e->checked)>=600000UL&&!serviceWaitMs(SERVICE_ADSB_DB); } void flightEnrich(){ if(!flightEnrichmentDue())return; Enrichment* e=currentEnrichment(); - if(!e||e->phase>=3){ - if(!e){e=&g_cache[g_cacheNext];g_cacheNext=(g_cacheNext+1)%3;} + if(!e){ + e=&g_cache[g_cacheNext];g_cacheNext=(g_cacheNext+1)%3; *e={};e->used=true;e->checked=millis();g_lastEnrichmentMs=e->checked; strlcpy(e->hex,g_f.hex,sizeof(e->hex));strlcpy(e->callsign,g_f.callsign,sizeof(e->callsign)); - } + }else if(e->phase>=3){e->phase=1;e->checked=millis();g_lastEnrichmentMs=e->checked;} if(e->phase==0)lookupRouteAdsbLol(g_f,g_position,*e); else if(e->phase==1)lookupMetadata(g_f,g_position,*e); else lookupAirline(g_f,*e); @@ -274,8 +280,8 @@ void flightReset() { bool flightPollDue(uint16_t pollSec, float visibleShare) { if(adsbLolWaitMs())return false; - // A pending route lookup for the shown aircraft goes first and takes this slot. - if(flightEnrichmentDue())return false; + // The first route lookup of a new aircraft goes first and takes this slot. + {Enrichment* e=currentEnrichment();if((!e||e->phase==0)&&flightEnrichmentDue())return false;} if (!g_hasPolled) return true; if(pollSec= (uint32_t)pollMinutes * 60000UL; } -bool trackedFlightLivePollDue(uint16_t pollSeconds) { +bool trackedFlightLivePollDue(uint16_t pollSeconds, float visibleShare) { if (adsbLolWaitMs()||!g_t.valid || g_t.terminal || !g_t.flightIcao[0]) return false; if (g_lastLivePollMs == 0) return true; - return (uint32_t)(millis() - g_lastLivePollMs) >= (uint32_t)pollSeconds * 1000UL; + // Same quota planning as the radar (AdsbQuota.h): spread over every window. + uint32_t interval = (uint32_t)pollSeconds * 1000UL, budget = adsbLolBudgetIntervalMs(visibleShare); + if (interval < budget) interval = budget; + return (uint32_t)(millis() - g_lastLivePollMs) >= interval; } const TrackedFlightSnapshot& trackedFlightData() { return g_t; } diff --git a/src/TrackFlight.h b/src/TrackFlight.h index 46bf79f..187168f 100644 --- a/src/TrackFlight.h +++ b/src/TrackFlight.h @@ -34,7 +34,7 @@ struct TrackedFlightSnapshot { void trackedFlightReset(); bool trackedFlightStatusPollDue(uint16_t pollMinutes); -bool trackedFlightLivePollDue(uint16_t pollSeconds = 15); +bool trackedFlightLivePollDue(uint16_t pollSeconds = 15, float visibleShare = 1.0f); bool trackedFlightFetchStatus(const String& apiKey, const String& flightNumber); bool trackedFlightFetchLive(); const TrackedFlightSnapshot& trackedFlightData(); diff --git a/src/Version.h b/src/Version.h index ce9fcc0..4a4612f 100644 --- a/src/Version.h +++ b/src/Version.h @@ -1,6 +1,6 @@ #pragma once // Single place for name and version; every User-Agent is built from it. #define FW_NAME "PixelStop" -#define FW_VERSION "0.5.4.2-dev" +#define FW_VERSION "0.5.4.3-dev" #define FW_REPO "github.com/du13500/pixelstop" #define FW_USER_AGENT FW_NAME "/" FW_VERSION " (+https://" FW_REPO ")" diff --git a/src/main.cpp b/src/main.cpp index c32bfc9..2574fa2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -366,14 +366,15 @@ static bool radarActive() { uint32_t shown=(uint32_t)(millis()-lastModeSwitchMs); return shown+RADAR_PREFETCH_MS>=stayMs; } -// Share of the rotation the radar is visible; used to spread the daily budget. -static float radarVisibleShare() { +// Share of the rotation a view is visible (radar incl. prefetch); used to spread the quota. +static float modeVisibleShare(uint8_t mode,uint32_t extraSec) { if(enabledModeCount()<=1) return 1.0f; uint32_t total=0; for(uint8_t i=0;iquotaWait?waits[SERVICE_ADSB_LOL]:quotaWait;}uint32_t serviceMinIntervalMs(int){return minInterval;} +static uint32_t quotaWait=0,minInterval=0,g_lastPollMs=0;static bool g_routeSincePoll=false;uint32_t adsbLolWaitMs(){return waits[SERVICE_ADSB_LOL]>quotaWait?waits[SERVICE_ADSB_LOL]:quotaWait;}uint32_t serviceMinIntervalMs(int){return minInterval;} static int calls[3]={}; static bool pauseRoute=false; static bool lookupRouteAdsbLol(const FlightSnapshot&,RoutePoint,Enrichment&){calls[0]++;if(pauseRoute)waits[SERVICE_ADSB_LOL]=30000;return false;} @@ -42,13 +42,16 @@ def fn(name): strcpy(g_f.typeCode,"B39M");strcpy(g_f.typeName,"Boeing 737 MAX 9");enrichFlight(g_f,g_position);assert(!strcmp(g_f.typeName,"Boeing 737 MAX 9")); flightEnrich();assert(calls[0]==1&&calls[1]==1&&calls[2]==0); waits[SERVICE_ADSB_DB]=30000;assert(!flightEnrichmentDue());waits[SERVICE_ADSB_DB]=0; - flightEnrich();assert(calls[2]==1);assert(!flightEnrichmentDue());now=120999;assert(!flightEnrichmentDue());now=121000;assert(flightEnrichmentDue()); + flightEnrich();assert(calls[2]==1);assert(!flightEnrichmentDue());now=600999;assert(!flightEnrichmentDue());now=601000;assert(flightEnrichmentDue()); + // The same aircraft later: adsbdb only (no adsb.lol quota), found data is kept. + strcpy(currentEnrichment()->airline,"Kept Air");flightEnrich();assert(calls[0]==1&&calls[1]==2&&!strcmp(currentEnrichment()->airline,"Kept Air"));flightEnrich();flightEnrich();assert(calls[0]==1&&!flightEnrichmentDue()); g_f.error=true;assert(!flightEnrichmentDue());g_f.error=false; - g_f.callsign[0]='A';now=2000;assert(!flightEnrichmentDue());now=61000;assert(flightEnrichmentDue()); + g_f.callsign[0]='A';now=602000;assert(!flightEnrichmentDue());now=662000;assert(flightEnrichmentDue()); // The route lookup needs a free quota slot and keeps the minimum distance after a 429. g_cache[0]={};g_cache[1]={};g_cache[2]={};g_lastEnrichmentMs=0; quotaWait=5000;assert(!flightEnrichmentDue());quotaWait=0; minInterval=20000;g_lastPollMs=now-19999;assert(!flightEnrichmentDue());g_lastPollMs=now-20000;assert(flightEnrichmentDue());minInterval=0; + g_routeSincePoll=true;assert(!flightEnrichmentDue());g_routeSincePoll=false; g_position.lat=NAN;assert(!flightEnrichmentDue()); // A route request can impose the shared provider pause as well. g_position={51,13};g_f.error=false;g_cache[0]={};g_cache[1]={};g_cache[2]={};g_lastEnrichmentMs=0;pauseRoute=true; diff --git a/tools/test_motion.py b/tools/test_motion.py index 1b5b2d0..fcc310a 100644 --- a/tools/test_motion.py +++ b/tools/test_motion.py @@ -37,7 +37,7 @@ m.hasRate=true;m.rateFpm=600;m.sampleMs=0xFFFFF000U;assert(radarMotionAltitudeFt(m,1000,0xFFFFF000U+6000U,lim)==1060); m.sampleMs=5000;assert(radarMotionAltitudeFt(m,1000,4000,lim)==1000); // Limits follow the interval: at least 60 s, at most 4 min. - assert(radarMotionLimitMs(5000)==60000&&radarMotionLimitMs(120000)==135000&&radarMotionLimitMs(900000)==240000); + assert(radarMotionLimitMs(5000)==60000&&radarMotionLimitMs(120000)==135000&&radarMotionLimitMs(420000)==435000&&radarMotionLimitMs(900000)==600000); // Status dot. assert(radarDotState(500,30000,false)==RADAR_DOT_NEW); assert(radarDotState(500,30000,true)==RADAR_DOT_ESTIMATED); diff --git a/tools/test_radar.py b/tools/test_radar.py index 3404872..9755309 100644 --- a/tools/test_radar.py +++ b/tools/test_radar.py @@ -35,6 +35,7 @@ def function(name): const int SERVICE_ADSB_LOL=0; static uint32_t quotaWait=0;uint32_t adsbLolWaitMs(){return quotaWait;} static bool enrichDue=false;bool flightEnrichmentDue(){return enrichDue;} +struct Enrichment{uint8_t phase;};static Enrichment pending={0};static Enrichment* currentEnrichment(){return &pending;}static bool g_routeSincePoll=false; struct Snapshot {bool valid,error;} g_f={}; static uint32_t g_lastPollMs=0,g_lastOkMs=0,g_firstFailureMs=0,g_intervalMs=0; static bool g_hasPolled=false,g_providerPaused=false; @@ -58,7 +59,9 @@ def function(name): // 5 s is no longer selectable: the radar asks at most every 10 s. assert(!flightPollDue(5,1.0f));clockMs=24999;assert(!flightPollDue(5,1.0f));clockMs=25000;assert(flightPollDue(5,1.0f)&&g_intervalMs==10000); // The quota (AdsbQuota.h) and a pending route lookup take precedence. - quotaWait=1000;assert(!flightPollDue(10,1.0f));quotaWait=0;enrichDue=true;assert(!flightPollDue(10,1.0f));enrichDue=false; + quotaWait=1000;assert(!flightPollDue(10,1.0f));quotaWait=0;enrichDue=true;assert(!flightPollDue(10,1.0f)); + // Only the first lookup of a new aircraft goes first; later checks never block positions. + pending.phase=3;assert(flightPollDue(10,1.0f));pending.phase=0;enrichDue=false; minimumInterval=15000;clockMs=29999;assert(!flightPollDue(5,1.0f));clockMs=30000;assert(flightPollDue(5,1.0f));minimumInterval=0; budgetInterval=12000;clockMs=26999;assert(!flightPollDue(5,0.25f)&&lastShare==0.25f);clockMs=27000;assert(flightPollDue(5,0.25f)&&g_intervalMs==12000);budgetInterval=0; clockMs=39999;assert(!flightExpire());clockMs=40000;assert(flightExpire());assert(!g_f.valid&&g_f.error);assert(!flightExpire()); diff --git a/tools/test_radar_schedule.py b/tools/test_radar_schedule.py new file mode 100644 index 0000000..4b8bd74 --- /dev/null +++ b/tools/test_radar_schedule.py @@ -0,0 +1,137 @@ +#!/usr/bin/env python3 +"""Simulates the radar scheduler for hours with the real scheduling functions of +src/Flight.cpp (flightPollDue, flightEnrichmentDue, flightEnrich, routeSlotFree and +the skip/slot lines of lookupRouteAdsbLol) and the real quota (AdsbQuota.h). +Transfers are stubs that only take time and count requests; the main loop's task +order and pause after each request are modelled like main.cpp. + +Regression for v0.5.4: route re-checks pushed every position request back, so the +radar never asked for positions again (one position in two hours).""" +from pathlib import Path +import re, subprocess, tempfile +root = Path(__file__).resolve().parents[1] +source = (root / 'src/Flight.cpp').read_text() + +def fn(name): + m = re.search(r'^(?:static )?[^\n]+\b' + name + r'\([^\n]*\)\s*\{', source, re.M); assert m, name + a = m.start(); i = source.index('{', a) + 1; depth = 1 + while depth: + depth += (source[i] == '{') - (source[i] == '}'); i += 1 + return source[a:i] + +route = fn('lookupRouteAdsbLol') +head = route[route.index(' uint8_t skip='):route.index('\n', route.index('g_lastPollMs=millis();'))] +head = head.replace('!tlsHeapReady(adsbLolRx())?4:0', '0') +HARNESS = r''' +#include +#include +#include +#include +#include +#include +#include "AdsbQuota.h" +#define strlcpy simStrlcpy +inline size_t simStrlcpy(char*d,const char*s,size_t n){size_t l=strlen(s);if(n){size_t k=l0?providerUntil-now:0;} +uint32_t serviceMinIntervalMs(int s){return s==SERVICE_ADSB_LOL&&(int32_t)(minIntervalUntil-now)>0?minInterval:0;} +// quota (real AdsbQuota.h, simulated clock) +static QuotaState Q={};static bool hasKey=true; +static const uint16_t* use(){return hasKey?ADSB_QUOTA_KEY:ADSB_QUOTA_NOKEY;} +uint32_t adsbLolQuotaWaitMs(){return quotaWaitMs(Q,epoch(),use());} +uint32_t adsbLolWaitMs(){uint32_t a=serviceWaitMs(SERVICE_ADSB_LOL),b=adsbLolQuotaWaitMs();return a>b?a:b;} +uint32_t adsbLolBudgetIntervalMs(float share){return quotaIntervalMs(Q,epoch(),use(),share);} +// v0.5.3.1 helpers +static uint16_t today=0; +bool adsbLolBudgetLow(){return false;} +// counters +static std::vector positionAt,lolAt,routeAt;static int routeCalls=0,metaCalls=0,airlineCalls=0,skips=0; +static void countLol(){quotaCount(Q,epoch());lolAt.push_back(now);} +// scene: callsign shown at time t (set by scenario) +static int scenario=0; +static void sceneAircraft(FlightSnapshot& f){ + uint32_t min=now/60000;char cs[12]; + if(scenario==1){strcpy(cs,"SAS88C");} // same aircraft for hours + else if(scenario==2){snprintf(cs,sizeof cs,"DLH%u",min/3);} // new aircraft every 3 min + else {snprintf(cs,sizeof cs,"EWG%u",min/15);} // new aircraft every 15 min + f.valid=true;f.error=false;strcpy(f.callsign,cs);strcpy(f.hex,cs); +} +static void lookupMetadata(const FlightSnapshot&,RoutePoint,Enrichment&){metaCalls++;now+=400;} +static void lookupAirline(const FlightSnapshot&,Enrichment&){airlineCalls++;now+=300;} +static void enrichFlight(FlightSnapshot&,RoutePoint){} +static bool tlsHeapReady(uint16_t){return true;} +static uint16_t adsbLolRx(){return 4096;} +static void diagLookup(const char*,const char*){} +static void diagEvent(int,int,int,int){} +enum {D_RADAR_ROUTE,DS_SKIPPED}; +// route lookup: real skip/slot lines are patched in by the script +static bool lookupRouteAdsbLol(const FlightSnapshot& f,RoutePoint pos,Enrichment& out){ + (void)f;(void)pos;(void)out; +ROUTE_HEAD + routeCalls++;routeAt.push_back(now);countLol();now+=1300;return false; +} +static void flightFetch(){ + g_lastPollMs=now;g_hasPolled=true;g_routeSincePoll=false;countLol();now+=1300; + sceneAircraft(g_f);g_lastOkMs=now;g_lastPollMs=now;positionAt.push_back(now); +} +FUNCTIONS +int main(int argc,char**argv){ + scenario=atoi(argv[1]);int rotation=atoi(argv[2]);int poll=atoi(argv[3]);uint32_t hours=atoi(argv[4]); + int monthUsed=atoi(argv[5]);hasKey=atoi(argv[6]); + quotaRoll(Q,epoch());Q.used[Q_MONTH]=monthUsed;Q.used[Q_WEEK]=monthUsed>350?350:monthUsed;Q.used[Q_DAY]=0; + // rotation: radar visible `rotation` s out of 60 s (0 = radar only) + float share=rotation?std::min(1.0f,(rotation+10)/60.0f):1.0f; + uint32_t deferUntil=0;uint8_t cursor=0;uint32_t end=hours*3600000UL; + while(now=50;} // visible + 10 s prefetch + if((int32_t)(now-deferUntil)>=0){ + for(uint8_t n=0;n<6;n++){uint8_t task=cursor;cursor=(cursor+1)%6;bool ran=false; + if(task==2&&active&&flightPollDue(poll,share)){flightFetch();ran=true;} + else if(task==3&&active&&flightEnrichmentDue()){flightEnrich();ran=true;} + if(ran){deferUntil=now+750;break;}} + } + now+=100; + } + // metrics + uint32_t maxGap=0;for(size_t i=1;i routes=routeAt; + for(uint32_t r:routes){while(p= minPositions and gap <= maxGap, ctx # positions keep coming + assert between <= 1, ctx # never two routes in a row + assert max30 <= 4 and maxHour <= 135, ctx # adsb.lol windows + if scenario == 1: assert routes == 1, ctx # re-checks without adsb.lol +print('Radar schedule (2 h simulated): positions keep coming, one route per new aircraft, re-checks via adsbdb, quota windows kept OK')