From d62f4153bfa4424ac07a830c3f88b916704e2c0f Mon Sep 17 00:00:00 2001 From: James Smith Date: Mon, 22 Dec 2025 13:02:21 +0000 Subject: [PATCH] Improve SBS parser with better error handling and debug output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add try/except for value conversion - Add position debug output - Fix MSG,5 to extract callsign and altitude 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- intercept.py | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/intercept.py b/intercept.py index bb02ded..7f3723b 100755 --- a/intercept.py +++ b/intercept.py @@ -12103,29 +12103,50 @@ def parse_sbs_stream(service_addr): if callsign: aircraft['callsign'] = callsign - # MSG,3: position (alt, speed, heading, lat, lon) + # MSG,3: position (alt, lat, lon) elif msg_type == '3' and len(parts) > 15: if parts[11]: - aircraft['altitude'] = int(float(parts[11])) - if parts[12]: - aircraft['speed'] = int(float(parts[12])) - if parts[13]: - aircraft['heading'] = int(float(parts[13])) + try: + aircraft['altitude'] = int(float(parts[11])) + except: + pass if parts[14] and parts[15]: - aircraft['lat'] = float(parts[14]) - aircraft['lon'] = float(parts[15]) + try: + lat = float(parts[14]) + lon = float(parts[15]) + aircraft['lat'] = lat + aircraft['lon'] = lon + print(f"[ADS-B] Position: {icao} at {lat:.4f}, {lon:.4f}") + except: + pass # MSG,4: velocity (speed, heading) elif msg_type == '4' and len(parts) > 13: if parts[12]: - aircraft['speed'] = int(float(parts[12])) + try: + aircraft['speed'] = int(float(parts[12])) + except: + pass if parts[13]: - aircraft['heading'] = int(float(parts[13])) + try: + aircraft['heading'] = int(float(parts[13])) + except: + pass - # MSG,5/6: altitude and squawk - elif msg_type in ('5', '6') and len(parts) > 17: + # MSG,5: callsign and altitude + elif msg_type == '5' and len(parts) > 11: + if parts[10]: + callsign = parts[10].strip() + if callsign: + aircraft['callsign'] = callsign if parts[11]: - aircraft['altitude'] = int(float(parts[11])) + try: + aircraft['altitude'] = int(float(parts[11])) + except: + pass + + # MSG,6: squawk + elif msg_type == '6' and len(parts) > 17: if parts[17]: aircraft['squawk'] = parts[17]