python模式s和ads-b解码器
pyModeS的Python项目详细描述
如果您觉得这个项目对您的研究有用,请引用我们的工作(bibtex格式):
@article{sun2019pymodes, author={J. {Sun} and H. {V\^u} and J. {Ellerbroek} and J. M. {Hoekstra}}, journal={IEEE Transactions on Intelligent Transportation Systems}, title={pyModeS: Decoding Mode-S Surveillance Data for Open Air Transportation Research}, year={2019}, doi={10.1109/TITS.2019.2914770}, ISSN={1524-9050}, }
简介
pymodes是一个python库,用于解码mode-s(包括ads-b)消息。 支持以下下行格式的消息:
df17/df18:自动相关监视-广播(ads-b)
- tc=1-4/bds 0,8:飞机识别和分类
- tc=5-8/bds 0,6:表面位置
- tc=9-18/bds 0,5:机载位置
- tc=19/bds 0,9:空降速度
- tc=28/bds 6,1:机载状态[待实施]
- tc=29/bds 6,2:目标状态和状态信息[待实现]
- TC=31/BDS 6,5:飞机运行状态[待实施]
df20/df21:mode-s comm-b应答
- BDS 1,0:数据链路能力报告
- BDS 1,7:通用GICB能力报告
- BDS 2,0:飞机识别
- BDS 3,0:ACAS主动解决方案咨询
- BDS 4,0:选定的垂直意图
- BDS 4,4:气象常规空气报告(实验)
- BDS 4,5:气象危害报告(实验)
- BDS 5,0:轨道和转弯报告
- BDS 6,0:航向和速度报告
df4/df20:高度代码
df5/df21:标识码(squawk码)
资源
签出并参与此开源项目: https://github.com/junzis/pyModeS
S模式解码详细手册发布于: https://mode-s.org/decode。
pymodes的api文档位于: http://pymodes.readthedocs.io
安装
从github安装最新版本:
pip install git+https://github.com/junzis/pyModeS
从pip安装稳定版本(2.0):
pip install pyModeS
实时查看流量(modeslive)
支持mode-s beast和avr原始流
modeslive --server [server_address] --port [tcp_port] --rawtype [beast,avr,skysense] --latlon [lat] [lon] --dumpto [folder] Arguments: -h, --help show this help message and exit --server SERVER server address or IP --port PORT raw data port --rawtype RAWTYPE beast, avr or skysense --latlon LAT LON receiver position --show-uncertainty display uncertaint values, default off --dumpto folder to dump decoded output
如果您有rtl-sdr接收器或mode-s beast,请使用modesmixer2(http://xdeco.org/?page_id=48)创建原始beast tcp流:
$ modesmixer2 --inSeriel port[:speed[:flow_control]] --outServer beast:[tcp_port]
屏幕截图示例:
使用库
importpyModeSaspms
公共功能
pms.df(msg)# Downlink Formatpms.icao(msg)# Infer the ICAO address from the messagepms.crc(msg,encode=False)# Perform CRC or generate parity bitpms.hex2bin(str)# Convert hexadecimal string to binary stringpms.bin2int(str)# Convert binary string to integerpms.hex2int(str)# Convert hexadecimal string to integerpms.gray2int(str)# Convert grey code to interger
ADS-B解码的核心功能
pms.adsb.icao(msg)pms.adsb.typecode(msg)# Typecode 1-4pms.adsb.callsign(msg)# Typecode 5-8 (surface), 9-18 (airborne, barometric height), and 9-18 (airborne, GNSS height)pms.adsb.position(msg_even,msg_odd,t_even,t_odd,lat_ref=None,lon_ref=None)pms.adsb.airborne_position(msg_even,msg_odd,t_even,t_odd)pms.adsb.surface_position(msg_even,msg_odd,t_even,t_odd,lat_ref,lon_ref)pms.adsb.position_with_ref(msg,lat_ref,lon_ref)pms.adsb.airborne_position_with_ref(msg,lat_ref,lon_ref)pms.adsb.surface_position_with_ref(msg,lat_ref,lon_ref)pms.adsb.altitude(msg)# Typecode: 19pms.adsb.velocity(msg)# Handles both surface & airborne messagespms.adsb.speed_heading(msg)# Handles both surface & airborne messagespms.adsb.surface_velocity(msg)pms.adsb.airborne_velocity(msg)
注:当您有飞机的固定位置时,可以方便地 使用position_with_ref()方法解码只有一条位置消息 (奇数或偶数)。这对空中和地面位置都有效 信息。但参考位置应为180nm(机载) 或45纳米(表面)的真实位置。
解码DF4/DF20中的高度应答
pms.common.altcode(msg)# Downlink format must be 4 or 20
解码df5/df21中的身份回复
pms.common.idcode(msg)# Downlink format must be 5 or 21
共模-s函数
pms.icao(msg)# Infer the ICAO address from the messagepms.bds.infer(msg)# Infer the Modes-S BDS register# Check if BDS is 5,0 or 6,0, give reference speed, track, altitude (from ADS-B)pms.bds.is50or60(msg,spd_ref,trk_ref,alt_ref)# Check each BDS explicitlypms.bds.bds10.is10(msg)pms.bds.bds17.is17(msg)pms.bds.bds20.is20(msg)pms.bds.bds30.is30(msg)pms.bds.bds40.is40(msg)pms.bds.bds44.is44(msg)pms.bds.bds50.is50(msg)pms.bds.bds60.is60(msg)
S模式基本监视(ELS)
pms.commb.ovc10(msg)# Overlay capability, BDS 1,0pms.commb.cap17(msg)# GICB capability, BDS 1,7pms.commb.cs20(msg)# Callsign, BDS 2,0
S模式增强监视(ehs)
# BDS 4,0pms.commb.selalt40mcp(msg)# MCP/FCU selected altitude (ft)pms.commb.selalt40fms(msg)# FMS selected altitude (ft)pms.commb.p40baro(msg)# Barometric pressure (mb)# BDS 5,0pms.commb.roll50(msg)# Roll angle (deg)pms.commb.trk50(msg)# True track angle (deg)pms.commb.gs50(msg)# Ground speed (kt)pms.commb.rtrk50(msg)# Track angle rate (deg/sec)pms.commb.tas50(msg)# True airspeed (kt)# BDS 6,0pms.commb.hdg60(msg)# Magnetic heading (deg)pms.commb.ias60(msg)# Indicated airspeed (kt)pms.commb.mach60(msg)# Mach number (-)pms.commb.vr60baro(msg)# Barometric altitude rate (ft/min)pms.commb.vr60ins(msg)# Inertial vertical speed (ft/min)
气象常规空气报告(MRAR)[实验]
# BDS 4,4pms.commb.wind44(msg)# Wind speed (kt) and direction (true) (deg)pms.commb.temp44(msg)# Static air temperature (C)pms.commb.p44(msg)# Average static pressure (hPa)pms.commb.hum44(msg)# Humidity (%)
气象危害空气报告(MHR)[实验]
# BDS 4,5pms.commb.turb45(msg)# Turbulence level (0-3)pms.commb.ws45(msg)# Wind shear level (0-3)pms.commb.mb45(msg)# Microburst level (0-3)pms.commb.ic45(msg)# Icing level (0-3)pms.commb.wv45(msg)# Wake vortex level (0-3)pms.commb.temp45(msg)# Static air temperature (C)pms.commb.p45(msg)# Average static pressure (hPa)pms.commb.rh45(msg)# Radio height (ft)
定制流媒体模块
pymodes中的tcp客户端模块可用于流式传输和处理mode-s 你喜欢的数据。您需要从中重新实现handle_messages()函数 用BaseClient类编写自己的逻辑来处理消息。
下面是一个示例:
frompyModeS.extra.tcpclientimportBaseClient# define your custom class by extending the BaseClient# - implement your handle_messages() methodsclassADSBClient(BaseClient):def__init__(self,host,port,rawtype):super(ModesClient,self).__init__(host,port,rawtype)defhandle_messages(self,messages):formsg,tsinmessages:iflen(msg)<28:# wrong data lengthcontinuedf=pms.df(msg)ifdf!=17:# not ADSBcontinueif'1'inpms.crc(msg):# CRC failcontinueicao=pms.adsb.icao(msg)tc=pms.adsb.typecode(msg)# TODO: write you magic code hereprintts,icao,tc,msg# run new client, change the host, port, and rawtype if neededclient=ADSBClient(host='127.0.0.1',port=30334,rawtype='beast')client.run()
单元测试
执行单元测试。首先通过pip安装tox,然后运行以下命令:
$ tox