From 661184deeec78d1d8a58bdcc9ed9d7698626e675 Mon Sep 17 00:00:00 2001 From: DogKing Date: Tue, 30 Sep 2025 19:43:31 +0800 Subject: simple adsb --- webserver.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 webserver.py (limited to 'webserver.py') diff --git a/webserver.py b/webserver.py new file mode 100755 index 0000000..cc17d70 --- /dev/null +++ b/webserver.py @@ -0,0 +1,46 @@ +import zmq +import pmt + +def zmq_pdu_subscriber(): + context = zmq.Context() + socket = context.socket(zmq.SUB) + + # 连接到GNU Radio的ZMQ Pub Sink + # 地址和端口需要与GNU Radio流图中的配置一致 + socket.connect("tcp://localhost:5001") + socket.setsockopt_string(zmq.SUBSCRIBE, "") + + print("等待接收ADS-B PDU消息...") + + try: + while True: + # 接收二进制PDU数据 + pdu_bin = socket.recv() + + # 反序列化PDU + pdu = pmt.deserialize_str(pdu_bin) + + # 提取数据部分(pmt.car获取PDU的数据) + plane = pmt.to_python(pmt.car(pdu)) + + # 处理ADS-B飞机数据 + print("收到飞机数据:") + print(f" ICAO地址: {plane.get('icao', 'N/A')}") + print(f" 时间: {plane.get('datetime', 'N/A')}") + print(f" 经度: {plane.get('longitude', 'N/A')}") + print(f" 纬度: {plane.get('latitude', 'N/A')}") + print(f" 高度: {plane.get('altitude', 'N/A')} 英尺") + print(f" 速度: {plane.get('speed', 'N/A')} 节") + print(f" 航向: {plane.get('heading', 'N/A')}°") + print("-" * 50) + + except KeyboardInterrupt: + print("\n接收端停止") + except Exception as e: + print(f"处理数据时出错: {e}") + finally: + socket.close() + context.term() + +if __name__ == "__main__": + zmq_pdu_subscriber() \ No newline at end of file -- cgit v1.2.3