fix(gps): correct UBX NAV-SVINFO and NAV-SAT satellite decoding#524
Open
mrosseel wants to merge 3 commits into
Open
fix(gps): correct UBX NAV-SVINFO and NAV-SAT satellite decoding#524mrosseel wants to merge 3 commits into
mrosseel wants to merge 3 commits into
Conversation
The repeated block in UBX-NAV-SVINFO is chn, svid, flags, quality, cno, elev, azim — but the parser started reading at chn, so every field was shifted one byte: satellite IDs were channel numbers, the used flag was svid bit 0, and the C/N0 was the 0-7 quality indicator. Because "cno" was really the quality indicator (>=1 even for idle SBAS/QZSS channels still searching), the sats-seen count was inflated to near the full channel count, and the per-satellite used flags were random — which is why uSat was previously treated as stale and ignored. With the offsets fixed: - nSat only counts satellites with an actual signal (cno > 0) - uSat from SVINFO is valid, so report it as the used count instead of relying solely on NAV-SOL - elevation/azimuth are decoded as signed values per the spec Also update the used count from NAV-PVT numSV, which was parsed but never surfaced — on protVer >= 15 receivers gpsd enables NAV-PVT instead of NAV-SOL, so the used count stayed 0 forever despite a valid fix. And actually set got_sat_update when NAV-SAT arrives so the SVINFO fallback defers to it as intended. Verified against a live MAX-M8 (PROTVER 14) stream: SVINFO uSat now matches NAV-SOL numSV, and IDs/C-N0 match gpsd's own SKY decode. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NrdGJ1s3jmA9qzV8HAsdZs
Newer u-blox receivers (later M8 firmware, M9, M10) get NAV-PVT + NAV-SAT from gpsd instead of NAV-SOL + NAV-SVINFO, so this path is what recent PiFinder GPS units actually exercise. - take "used" from the dedicated svUsed flag (bit 3) instead of inferring it from the quality indicator - only count satellites with an actual signal: NAV-SAT lists every known satellite, so nSat was inflated by idle entries - decode elevation/azimuth as signed values Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NrdGJ1s3jmA9qzV8HAsdZs
During cold start the receiver reports an estimated C/N0 for almanac-predicted satellites it is still trying to confirm, so a cno > 0 filter makes the seen count start around 20+ and sink to the real value as candidates fail to confirm. Gate on the quality indicator instead: only code-locked signals (quality >= 4) count as seen, in both NAV-SVINFO and NAV-SAT. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NrdGJ1s3jmA9qzV8HAsdZs
be023f6 to
3071268
Compare
Owner
|
@mrosseel is this still waiting on some additional commits, or is it ready to merge? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The satellite counts shown by PiFinder (e.g.
GPS 20/0on the status screen) were wrong on all GPS receiver generations, in two different ways:_parse_nav_svinforead every per-satellite field one byte off. The UBX repeated block ischn, svid, flags, quality, cno, elev, azim, but parsing started atchn. So satellite IDs were channel numbers, the per-sat used flag wassvid & 1(random), and "C/N0" was really the 0–7 quality indicator. Since quality is ≥1 even for idle SBAS/QZSS channels still searching, the seen count was inflated to near the full channel count (the mysterious "20 seen" with nothing tracked), anduSatwas garbage — which is presumably why it was treated as stale and ignored in favour of NAV-SOL.numSVwas parsed but never surfaced, and NAV-SOL never arrives on these units.Fix
_parse_nav_svinfo: shift field offsets by one per the u-blox spec; decode elev/azim as signed; count only satellites with an actual signal as seen. With correct offsets thesvUsedflag is valid, so SVINFO now reports a trustworthyuSat.gps_ubx.py: reportuSatfrom SVINFO instead of the stale-info workaround; update the used count from NAV-PVTnumSV; actually setgot_sat_updatewhen NAV-SAT arrives so the SVINFO fallback defers to it as intended._parse_nav_sat: take used from the dedicatedsvUsedbit (bit 3) instead of the quality heuristic (which also counts tracked-but-unused sats); don't count zero-signal entries as seen; decode elev/azim as signed.Verification
tests/test_gps_ubx_parser.py) with spec-built payloads for both message types, including the idle-channel inflation case.nSat 11 / uSat 6, PRNs, C/N0) exactly matches NAV-SOLnumSVand gpsd's own SKY decode; the old code produced the inflated counts on the same stream.The NAV-PVT/NAV-SAT path is verified against the spec and unit tests only — a sanity check on a unit with a newer (M9/M10) module would be welcome.
🤖 Generated with Claude Code
https://claude.ai/code/session_01NrdGJ1s3jmA9qzV8HAsdZs