From f8f08ecd373053f237ae576c3d3354e759c7a4bb Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Tue, 18 Jun 2013 19:06:30 -0700 Subject: [PATCH] Flightgear plugin modified for new parser interface. --- apps/modes_rx | 3 +-- python/flightgear.py | 27 +++++++++++++-------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/apps/modes_rx b/apps/modes_rx index 9293f22..b47a9c0 100755 --- a/apps/modes_rx +++ b/apps/modes_rx @@ -98,8 +98,7 @@ def main(): if options.multiplayer is not None: [fghost, fgport] = options.multiplayer.split(':') - fgout = air_modes.output_flightgear(my_position, fghost, int(fgport)) - relay.subscribe("dl_data", fgout.output) + fgout = air_modes.output_flightgear(cpr_dec, fghost, int(fgport), publisher) if options.sbs1 is True: sbs1port = air_modes.output_sbs1(cpr_dec, 30003, publisher) diff --git a/python/flightgear.py b/python/flightgear.py index b28c3c6..ebfed94 100755 --- a/python/flightgear.py +++ b/python/flightgear.py @@ -14,49 +14,48 @@ from Quaternion import Quat import numpy from air_modes.exceptions import * -class output_flightgear(air_modes.parse): - def __init__(self, localpos, hostname, port): - air_modes.parse.__init__(self, localpos) +class output_flightgear: + def __init__(self, cprdec, hostname, port, pub): self.hostname = hostname self.port = port self.localpos = localpos self.positions = {} self.velocities = {} self.callsigns = {} + self._cpr = cprdec self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.sock.connect((self.hostname, self.port)) + pub.subscribe("type17_dl", output) - def output(self, message): - [data, ecc, reference, timestamp] = message.split() - data = air_modes.modes_reply(long(data, 16)) + def output(self, msg): try: - msgtype = data["df"] + msgtype = msg.data["df"] if msgtype == 17: #ADS-B report - icao24 = data["aa"] - bdsreg = data["me"].get_type() + icao24 = msg.data["aa"] + bdsreg = msg.data["me"].get_type() if bdsreg == 0x08: #ident packet - (ident, actype) = self.parseBDS08(data) + (ident, actype) = air_modes.parseBDS08(data) #select model based on actype self.callsigns[icao24] = [ident, actype] elif bdsreg == 0x06: #BDS0,6 pos - [ground_track, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS06(data) + [ground_track, decoded_lat, decoded_lon, rnge, bearing] = air_modes.parseBDS06(data, self._cpr) self.positions[icao24] = [decoded_lat, decoded_lon, 0] self.update(icao24) elif bdsreg == 0x05: #BDS0,5 pos - [altitude, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS05(data) + [altitude, decoded_lat, decoded_lon, rnge, bearing] = air_modes.parseBDS05(data, self._cpr) self.positions[icao24] = [decoded_lat, decoded_lon, altitude] self.update(icao24) elif bdsreg == 0x09: #velocity subtype = data["bds09"].get_type() if subtype == 0: - [velocity, heading, vert_spd, turnrate] = self.parseBDS09_0(data) + [velocity, heading, vert_spd, turnrate] = air_modes.parseBDS09_0(data) elif subtype == 1: - [velocity, heading, vert_spd] = self.parseBDS09_1(data) + [velocity, heading, vert_spd] = air_modes.parseBDS09_1(data) turnrate = 0 else: return