summaryrefslogtreecommitdiff
path: root/webserver.py
diff options
context:
space:
mode:
Diffstat (limited to 'webserver.py')
-rwxr-xr-xwebserver.py46
1 files changed, 46 insertions, 0 deletions
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