Fix FlightGear and SBS1 outputs.

This commit is contained in:
Nick Foster 2014-02-07 16:59:34 -08:00
parent 27e0f87361
commit 42bf16ffc4
2 changed files with 14 additions and 16 deletions

View File

@ -18,7 +18,6 @@ class output_flightgear:
def __init__(self, cprdec, hostname, port, pub): def __init__(self, cprdec, hostname, port, pub):
self.hostname = hostname self.hostname = hostname
self.port = port self.port = port
self.localpos = localpos
self.positions = {} self.positions = {}
self.velocities = {} self.velocities = {}
self.callsigns = {} self.callsigns = {}
@ -26,36 +25,35 @@ class output_flightgear:
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.sock.connect((self.hostname, self.port)) self.sock.connect((self.hostname, self.port))
pub.subscribe("type17_dl", output) pub.subscribe("type17_dl", self.output)
def output(self, msg): def output(self, msg):
try: try:
msgtype = msg.data["df"] msgtype = msg.data["df"]
if msgtype == 17: #ADS-B report if msgtype == 17: #ADS-B report
icao24 = msg.data["aa"] icao24 = msg.data["aa"]
bdsreg = msg.data["me"].get_type() bdsreg = msg.data["me"].get_type()
if bdsreg == 0x08: #ident packet if bdsreg == 0x08: #ident packet
(ident, actype) = air_modes.parseBDS08(data) (ident, actype) = air_modes.parseBDS08(msg.data)
#select model based on actype #select model based on actype
self.callsigns[icao24] = [ident, actype] self.callsigns[icao24] = [ident, actype]
elif bdsreg == 0x06: #BDS0,6 pos elif bdsreg == 0x06: #BDS0,6 pos
[ground_track, decoded_lat, decoded_lon, rnge, bearing] = air_modes.parseBDS06(data, self._cpr) [ground_track, decoded_lat, decoded_lon, rnge, bearing] = air_modes.parseBDS06(msg.data, self._cpr)
self.positions[icao24] = [decoded_lat, decoded_lon, 0] self.positions[icao24] = [decoded_lat, decoded_lon, 0]
self.update(icao24) self.update(icao24)
elif bdsreg == 0x05: #BDS0,5 pos elif bdsreg == 0x05: #BDS0,5 pos
[altitude, decoded_lat, decoded_lon, rnge, bearing] = air_modes.parseBDS05(data, self._cpr) [altitude, decoded_lat, decoded_lon, rnge, bearing] = air_modes.parseBDS05(msg.data, self._cpr)
self.positions[icao24] = [decoded_lat, decoded_lon, altitude] self.positions[icao24] = [decoded_lat, decoded_lon, altitude]
self.update(icao24) self.update(icao24)
elif bdsreg == 0x09: #velocity elif bdsreg == 0x09: #velocity
subtype = data["bds09"].get_type() subtype = msg.data["bds09"].get_type()
if subtype == 0: if subtype == 0:
[velocity, heading, vert_spd, turnrate] = air_modes.parseBDS09_0(data) [velocity, heading, vert_spd, turnrate] = air_modes.parseBDS09_0(msg.data)
elif subtype == 1: elif subtype == 1:
[velocity, heading, vert_spd] = air_modes.parseBDS09_1(data) [velocity, heading, vert_spd] = air_modes.parseBDS09_1(msg.data)
turnrate = 0 turnrate = 0
else: else:
return return

View File

@ -23,7 +23,7 @@
import time, os, sys, socket import time, os, sys, socket
from string import split, join from string import split, join
import air_modes import air_modes
from datetime import * import datetime
from air_modes.exceptions import * from air_modes.exceptions import *
import threading import threading
@ -63,7 +63,7 @@ class output_sbs1:
#it could be cleaner if there were separate output_* fns #it could be cleaner if there were separate output_* fns
#but this works #but this works
for i in (0, 4, 5, 11, 17): for i in (0, 4, 5, 11, 17):
pub.subscribe("type%i_dl" % i, output) pub.subscribe("type%i_dl" % i, self.output)
#spawn thread to add new connections as they come in #spawn thread to add new connections as they come in
self._runner = dumb_task_runner(self.add_pending_conns, 0.1) self._runner = dumb_task_runner(self.add_pending_conns, 0.1)
@ -111,7 +111,7 @@ class output_sbs1:
pass pass
def current_time(self): def current_time(self):
timenow = datetime.now() timenow = datetime.datetime.now()
return [timenow.strftime("%Y/%m/%d"), timenow.strftime("%H:%M:%S.%f")[0:-3]] return [timenow.strftime("%Y/%m/%d"), timenow.strftime("%H:%M:%S.%f")[0:-3]]
def decode_fs(self, fs): def decode_fs(self, fs):
@ -154,7 +154,7 @@ class output_sbs1:
[datestr, timestr] = self.current_time() [datestr, timestr] = self.current_time()
aircraft_id = self.get_aircraft_id(ecc) aircraft_id = self.get_aircraft_id(ecc)
retstr = "MSG,7,0,%i,%06X,%i,%s,%s,%s,%s,,%s,,,,,,,,,," % (aircraft_id, ecc, aircraft_id+100, datestr, timestr, datestr, timestr, air_modes.decode_alt(shortdata["ac"], True)) retstr = "MSG,7,0,%i,%06X,%i,%s,%s,%s,%s,,%s,,,,,,,,,," % (aircraft_id, ecc, aircraft_id+100, datestr, timestr, datestr, timestr, air_modes.decode_alt(shortdata["ac"], True))
if vs: if shortdata["vs"]:
retstr += "1\r\n" retstr += "1\r\n"
else: else:
retstr += "0\r\n" retstr += "0\r\n"
@ -174,7 +174,7 @@ class output_sbs1:
def pp11(self, shortdata, ecc): def pp11(self, shortdata, ecc):
[datestr, timestr] = self.current_time() [datestr, timestr] = self.current_time()
aircraft_id = self.get_aircraft_id(icao24) aircraft_id = self.get_aircraft_id(shortdata["aa"])
return "MSG,8,0,%i,%06X,%i,%s,%s,%s,%s,,,,,,,,,,,,\r\n" % (aircraft_id, shortdata["aa"], aircraft_id+100, datestr, timestr, datestr, timestr) return "MSG,8,0,%i,%06X,%i,%s,%s,%s,%s,,,,,,,,,,,,\r\n" % (aircraft_id, shortdata["aa"], aircraft_id+100, datestr, timestr, datestr, timestr)
def pp17(self, data): def pp17(self, data):