MCPcopy
hub / github.com/smittix/intercept / _adsb_sbs_reader

Method _adsb_sbs_reader

intercept_agent.py:1426–1468  ·  view source on GitHub ↗

Read and parse SBS data from dump1090.

(self, host: str, port: int)

Source from the content-addressed store, hash-verified

1424 }
1425
1426 def _adsb_sbs_reader(self, host: str, port: int):
1427 """Read and parse SBS data from dump1090."""
1428 mode = 'adsb'
1429 stop_event = self.stop_events.get(mode)
1430 retry_count = 0
1431 max_retries = 5
1432
1433 while not (stop_event and stop_event.is_set()):
1434 try:
1435 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1436 sock.settimeout(5.0)
1437 sock.connect((host, port))
1438 logger.info(f"Connected to SBS at {host}:{port}")
1439 retry_count = 0
1440
1441 buffer = ""
1442 sock.settimeout(1.0)
1443
1444 while not (stop_event and stop_event.is_set()):
1445 try:
1446 data = sock.recv(4096).decode('utf-8', errors='ignore')
1447 if not data:
1448 break
1449 buffer += data
1450
1451 while '\n' in buffer:
1452 line, buffer = buffer.split('\n', 1)
1453 self._parse_sbs_line(line.strip())
1454
1455 except socket.timeout:
1456 continue
1457
1458 sock.close()
1459
1460 except Exception as e:
1461 logger.warning(f"SBS connection error: {e}")
1462 retry_count += 1
1463 if retry_count >= max_retries:
1464 logger.error("Max SBS retries reached, stopping")
1465 break
1466 time.sleep(2)
1467
1468 logger.info("ADS-B SBS reader stopped")
1469
1470 def _parse_sbs_line(self, line: str):
1471 """Parse SBS format line and update aircraft dict."""

Callers

nothing calls this directly

Calls 5

_parse_sbs_lineMethod · 0.95
getMethod · 0.80
connectMethod · 0.45
closeMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected