import csv import pyModeS as pms from pyModeS.extra.tcpclient import TcpClient # define your custom class by extending the TcpClient # - implement your handle_messages() methods class ADSBClient(TcpClient): def __init__(self, host, port, rawtype): super(ADSBClient, self).__init__(host, port, rawtype) def handle_messages(self, messages): for msg, ts in messages: if len(msg) != 28: # wrong data length continue df = pms.df(msg) if df != 17: # not ADSB continue if pms.crc(msg) !=0: # CRC fail continue icao = pms.adsb.icao(msg) tc = pms.adsb.typecode(msg) # TODO: write you magic code here cs20 = pms.commb.cs20(msg) selalt40mcp = pms.commb.selalt40mcp(msg) # MCP/FCU selected altitude (ft) selalt40fms = pms.commb.selalt40fms(msg) # FMS selected altitude (ft) p40baro = pms.commb.p40baro(msg) # Barometric pressure (mb) # BDS 5,0 roll50 = pms.commb.roll50(msg) # Roll angle (deg) trk50 = pms.commb.trk50(msg) # True track angle (deg) gs50 = pms.commb.gs50(msg) # Ground speed (kt) rtrk50 = pms.commb.rtrk50(msg) # Track angle rate (deg/sec) tas50 = pms.commb.tas50(msg) # True airspeed (kt) # BDS 6,0 hdg60 = pms.commb.hdg60(msg) # Magnetic heading (deg) ias60 = pms.commb.ias60(msg) # Indicated airspeed (kt) mach60 = pms.commb.mach60(msg) # Mach number (-) vr60baro = pms.commb.vr60baro(msg) # Barometric altitude rate (ft/min) vr60ins = pms.commb.vr60ins(msg) # Inertial vertical speed (ft/min) if icao == 'AC6CD2': print(ts, icao, cs20, selalt40mcp, selalt40fms, p40baro, roll50, trk50, gs50, rtrk50, tas50, hdg60, ias60, mach60, vr60baro, vr60ins) with open('N90.csv', 'a') as n90: writer=csv.writer(n90) writer.writerow([ts, icao, cs20, selalt40mcp, selalt40fms, p40baro, roll50, trk50, gs50, rtrk50, tas50, hdg60, ias60, mach60, vr60baro, vr60ins]) # run new client, change the host, port, and rawtype if needed client = ADSBClient(host='192.168.0.140', port=30005, rawtype='beast') client.run()