From 1bbd29d09c8d4368242d170988ca8dbf7f8cedf9 Mon Sep 17 00:00:00 2001 From: Zack Moratto Date: Thu, 7 Jul 2011 10:42:19 -0700 Subject: [PATCH 1/5] Correct mode_sbs1 so that it runs Msg return output has changed. Time is now only a single variable. --- src/python/modes_sbs1.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/python/modes_sbs1.py b/src/python/modes_sbs1.py index c75508c..922887a 100644 --- a/src/python/modes_sbs1.py +++ b/src/python/modes_sbs1.py @@ -59,14 +59,12 @@ class modes_output_sbs1(modes_parse.modes_parse): #assembles a SBS-1-style output string from the received message #this version ignores anything that isn't Type 17 for now, because we just don't care - [msgtype, shortdata, longdata, parity, ecc, reference, time_secs, time_frac] = message.split() + [msgtype, shortdata, longdata, parity, ecc, reference, time] = message.split() shortdata = long(shortdata, 16) longdata = long(longdata, 16) parity = long(parity, 16) ecc = long(ecc, 16) -# reference = float(reference) - msgtype = int(msgtype) outmsg = None From 7f9574b7cd1b2bf4b95775eb2b0dc2888239ad86 Mon Sep 17 00:00:00 2001 From: Zack Moratto Date: Sat, 26 Mar 2011 19:01:12 -0700 Subject: [PATCH 2/5] Added missing MSGs 5,6,7,8 for SBS output These are the 56 bit ADS-B message about altitude and such. Not as cool as the the extended messages but still useful non the less. --- src/python/modes_sbs1.py | 82 +++++++++++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 14 deletions(-) diff --git a/src/python/modes_sbs1.py b/src/python/modes_sbs1.py index 922887a..71aee8a 100644 --- a/src/python/modes_sbs1.py +++ b/src/python/modes_sbs1.py @@ -54,34 +54,87 @@ class modes_output_sbs1(modes_parse.modes_parse): def __del__(self): self._s.close() - + + def current_time(self): + timenow = datetime.now() + return [timenow.strftime("%Y/%m/%d"), timenow.strftime("%H:%M:%S.000")] + + def decode_fs(self, fs): + if fs == 0: + return "0,0,0,0" + elif fs == 1: + return "0,0,0,1" + elif fs == 2: + return "1,0,0,0" + elif fs == 3: + return "1,0,0,1" + elif fs == 4: + return "1,0,0," + elif fs == 5: + return "0,0,0," + else: + return ",,," + def parse(self, message): #assembles a SBS-1-style output string from the received message - #this version ignores anything that isn't Type 17 for now, because we just don't care - [msgtype, shortdata, longdata, parity, ecc, reference, time] = message.split() + [msgtype, shortdata, longdata, parity, ecc, reference, timestamp] = message.split() shortdata = long(shortdata, 16) longdata = long(longdata, 16) parity = long(parity, 16) ecc = long(ecc, 16) msgtype = int(msgtype) - outmsg = None - if msgtype == 17: - outmsg = self.pp17(shortdata, longdata, parity, ecc) - + if msgtype == 0: + outmsg = self.pp0(shortdata, parity, ecc) + elif msgtype == 4: + outmsg = self.pp4(shortdata, parity, ecc) + elif msgtype == 5: + outmsg = self.pp5(shortdata, parity, ecc) + elif msgtype == 11: + outmsg = self.pp11(shortdata, parity, ecc) + elif msgtype == 17: + outmsg = self.pp17(shortdata, longdata, parity, ecc) return outmsg + def pp0(self, shortdata, parity, ecc): + [datestr, timestr] = self.current_time() + [vs, cc, sl, ri, altitude] = self.parse0(shortdata, parity, ecc) + retstr = "MSG,7,0,0,0,0,%s,%s,%s,%s,,%s,,,,,,,,,," % (datestr,timestr,datestr,timestr,altitude) + if vs: + retstr += "1\n" + else: + retstr += "0\n" + return retstr + + def pp4(self, shortdata, parity, ecc): + [datestr, timestr] = self.current_time() + [fs, dr, um, altitude] = self.parse4(shortdata, parity, ecc) + retstr = "MSG,5,0,0,0,0,%s,%s,%s,%s,,%s,,,,,,," % (datestr,timestr,datestr,timestr,altitude) + return retstr + self.decode_fs(fs) + "\n" + + def pp5(self, shortdata, parity, ecc): + # I'm not sure what to do with the identiifcation shortdata & 0x1FFF + [datestr, timestr] = self.current_time() + [fs, dr, um] = self.parse5(shortdata, parity, ecc) + retstr = "MSG,6,0,0,0,0,%s,%s,%s,%s,,,,,,,,," % (datestr,timestr,datestr,timestr) + return retstr + self.decode_fs(fs) + "\n" + + def pp11(self, shortdata, parity, ecc): + [datestr, timestr] = self.current_time() + [icao24, interrogator, ca] = self.parse11(shortdata, parity, ecc) + return "MSG,8,0,0,%X,0,%s,%s,%s,%s,,,,,,,,,,,,\n" % (icao24,datestr,timestr,datestr,timestr) + def pp17(self, shortdata, longdata, parity, ecc): icao24 = shortdata & 0xFFFFFF subtype = (longdata >> 51) & 0x1F retstr = None - timenow = datetime.now() - datestr = timenow.strftime("%Y/%m/%d") - timestr = timenow.strftime("%H:%M:%S.000") #we'll get better timestamps later, hopefully with actual VRT time in them + #we'll get better timestamps later, hopefully with actual VRT time + #in them + [datestr, timestr] = self.current_time() if subtype == 4: msg = self.parseBDS08(shortdata, longdata, parity, ecc) @@ -94,7 +147,10 @@ class modes_output_sbs1(modes_parse.modes_parse): else: retstr = "MSG,3,0,0,%X,0,%s,%s,%s,%s,,%i,,,%.5f,%.5f,,,,0,0,0\n" % (icao24, datestr, timestr, datestr, timestr, altitude, decoded_lat, decoded_lon) - elif subtype >= 9 and subtype <= 18 and subtype != 15: #i'm eliminating type 15 records because they don't appear to be valid position reports. + elif subtype >= 9 and subtype <= 18 and subtype != 15: + # WRONG (rnge, bearing) + # i'm eliminating type 15 records because they don't appear to be + # valid position reports. [altitude, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS05(shortdata, longdata, parity, ecc) if decoded_lat is None: #no unambiguously valid position available retstr = None @@ -102,6 +158,7 @@ class modes_output_sbs1(modes_parse.modes_parse): retstr = "MSG,3,0,0,%X,0,%s,%s,%s,%s,,%i,,,%.5f,%.5f,,,,0,0,0\n" % (icao24, datestr, timestr, datestr, timestr, altitude, decoded_lat, decoded_lon) elif subtype == 19: + # WRONG (heading, vert_spd) subsubtype = (longdata >> 48) & 0x07 if subsubtype == 0: [velocity, heading, vert_spd] = self.parseBDS09_0(shortdata, longdata, parity, ecc) @@ -111,7 +168,4 @@ class modes_output_sbs1(modes_parse.modes_parse): [velocity, heading, vert_spd] = self.parseBDS09_1(shortdata, longdata, parity, ecc) retstr = "MSG,4,0,0,%X,0,%s,%s,%s,%s,,,%.1f,%.1f,,,%i,,,,,\n" % (icao24, datestr, timestr, datestr, timestr, velocity, heading, vert_spd) - #else: - #print "debug (modes_sbs1): unknown subtype %i with data %x %x %x\n" % (subtype, shortdata, longdata, parity,) - return retstr From 422025590819199cf6ee1544b34ee62615b675cb Mon Sep 17 00:00:00 2001 From: Zack Moratto Date: Thu, 7 Jul 2011 11:14:05 -0700 Subject: [PATCH 3/5] Added comments and change surface reports to MSG2 2 important things happened here: -> Surface position reports where changed from MSG3 to MSG2. I believe this is what that SBS message means. -> MEs 1-4 are aircraft identification packets. Those should go to SBS MSG1. --- src/python/modes_sbs1.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/python/modes_sbs1.py b/src/python/modes_sbs1.py index 71aee8a..238b6ee 100644 --- a/src/python/modes_sbs1.py +++ b/src/python/modes_sbs1.py @@ -128,7 +128,7 @@ class modes_output_sbs1(modes_parse.modes_parse): return "MSG,8,0,0,%X,0,%s,%s,%s,%s,,,,,,,,,,,,\n" % (icao24,datestr,timestr,datestr,timestr) def pp17(self, shortdata, longdata, parity, ecc): - icao24 = shortdata & 0xFFFFFF + icao24 = shortdata & 0xFFFFFF subtype = (longdata >> 51) & 0x1F retstr = None @@ -136,19 +136,22 @@ class modes_output_sbs1(modes_parse.modes_parse): #in them [datestr, timestr] = self.current_time() - if subtype == 4: + if subtype >= 1 and subtype <= 4: + # Aircraft Identification msg = self.parseBDS08(shortdata, longdata, parity, ecc) retstr = "MSG,1,0,0,%X,0,%s,%s,%s,%s,%s,,,,,,,,,,,\n" % (icao24, datestr, timestr, datestr, timestr, msg) elif subtype >= 5 and subtype <= 8: + # Surface position measurement [altitude, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS06(shortdata, longdata, parity, ecc) if decoded_lat is None: #no unambiguously valid position available retstr = None else: - retstr = "MSG,3,0,0,%X,0,%s,%s,%s,%s,,%i,,,%.5f,%.5f,,,,0,0,0\n" % (icao24, datestr, timestr, datestr, timestr, altitude, decoded_lat, decoded_lon) + retstr = "MSG,2,0,0,%X,0,%s,%s,%s,%s,,%i,,,%.5f,%.5f,,,,0,0,0\n" % (icao24, datestr, timestr, datestr, timestr, altitude, decoded_lat, decoded_lon) elif subtype >= 9 and subtype <= 18 and subtype != 15: - # WRONG (rnge, bearing) + # Airborne position measurements + # WRONG (rnge, bearing), is this still true? # i'm eliminating type 15 records because they don't appear to be # valid position reports. [altitude, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS05(shortdata, longdata, parity, ecc) @@ -158,7 +161,8 @@ class modes_output_sbs1(modes_parse.modes_parse): retstr = "MSG,3,0,0,%X,0,%s,%s,%s,%s,,%i,,,%.5f,%.5f,,,,0,0,0\n" % (icao24, datestr, timestr, datestr, timestr, altitude, decoded_lat, decoded_lon) elif subtype == 19: - # WRONG (heading, vert_spd) + # Airborne velocity measurements + # WRONG (heading, vert_spd), Is this still true? subsubtype = (longdata >> 48) & 0x07 if subsubtype == 0: [velocity, heading, vert_spd] = self.parseBDS09_0(shortdata, longdata, parity, ecc) From f31e9e062f8709d42779d128bf062505b0f66b43 Mon Sep 17 00:00:00 2001 From: Zack Moratto Date: Thu, 7 Jul 2011 11:46:51 -0700 Subject: [PATCH 4/5] Added SBS support for aircraft and flight ID Looking at the SBS output, flight ID is just aircraft ID + 100. Aircraft ID is just a unique count to make parsing the output file easier. I'm not sure how useful this is but it makes us a step closer towards mimicking the SBS. I also pull out the ID for squitters 0, 4, and 5. --- src/python/modes_sbs1.py | 51 ++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/src/python/modes_sbs1.py b/src/python/modes_sbs1.py index 238b6ee..d5e9112 100644 --- a/src/python/modes_sbs1.py +++ b/src/python/modes_sbs1.py @@ -33,6 +33,31 @@ class modes_output_sbs1(modes_parse.modes_parse): self._s.listen(1) self._s.setblocking(0) #nonblocking self._conns = [] #list of active connections + self._aircraft_id_map = {} # dictionary of icao24 to aircraft IDs + self._aircraft_id_count = 0 # Current Aircraft ID count + + def __del__(self): + self._s.close() + + def get_aircraft_id(self, icao24): + if icao24 in self._aircraft_id_map: + return self._aircraft_id_map[icao24] + + # Adding this new ID to the dictionary + self._aircraft_id_count += 1 + self._aircraft_id_map[icao24] = self._aircraft_id_count + + # Checking to see if we need to clean up in the event that the + # dictionary is getting too large. + if len(self._aircraft_id_map) > 1e4: + minimum = ('', self._aircraft_id_count) + for pair in self._aircraft_id_map: + if pair[1] < minimum[1]: + minimum = pair + self._aircraft_id_map.pop(minimum[0]) + + # Finally return the new pair + return self._aircraft_id_count def output(self, msg): sbs1_msg = self.parse(msg) @@ -52,9 +77,6 @@ class modes_output_sbs1(modes_parse.modes_parse): except socket.error: pass - def __del__(self): - self._s.close() - def current_time(self): timenow = datetime.now() return [timenow.strftime("%Y/%m/%d"), timenow.strftime("%H:%M:%S.000")] @@ -102,7 +124,8 @@ class modes_output_sbs1(modes_parse.modes_parse): def pp0(self, shortdata, parity, ecc): [datestr, timestr] = self.current_time() [vs, cc, sl, ri, altitude] = self.parse0(shortdata, parity, ecc) - retstr = "MSG,7,0,0,0,0,%s,%s,%s,%s,,%s,,,,,,,,,," % (datestr,timestr,datestr,timestr,altitude) + aircraft_id = self.get_aircraft_id(ecc) + retstr = "MSG,7,0,%i,%X,%i,%s,%s,%s,%s,,%s,,,,,,,,,," % (aircraft_id, ecc, aircraft_id+100, datestr, timestr, datestr, timestr, altitude) if vs: retstr += "1\n" else: @@ -112,23 +135,27 @@ class modes_output_sbs1(modes_parse.modes_parse): def pp4(self, shortdata, parity, ecc): [datestr, timestr] = self.current_time() [fs, dr, um, altitude] = self.parse4(shortdata, parity, ecc) - retstr = "MSG,5,0,0,0,0,%s,%s,%s,%s,,%s,,,,,,," % (datestr,timestr,datestr,timestr,altitude) + aircraft_id = self.get_aircraft_id(ecc) + retstr = "MSG,5,0,%i,%X,%i,%s,%s,%s,%s,,%s,,,,,,," % (aircraft_id, ecc, aircraft_id+100, datestr, timestr, datestr, timestr, altitude) return retstr + self.decode_fs(fs) + "\n" def pp5(self, shortdata, parity, ecc): # I'm not sure what to do with the identiifcation shortdata & 0x1FFF [datestr, timestr] = self.current_time() [fs, dr, um] = self.parse5(shortdata, parity, ecc) - retstr = "MSG,6,0,0,0,0,%s,%s,%s,%s,,,,,,,,," % (datestr,timestr,datestr,timestr) + aircraft_id = self.get_aircraft_id(ecc) + retstr = "MSG,6,0,%i,%X,%i,%s,%s,%s,%s,,,,,,,,," % (aircraft_id, ecc, aircraft_id+100, datestr, timestr, datestr, timestr) return retstr + self.decode_fs(fs) + "\n" def pp11(self, shortdata, parity, ecc): [datestr, timestr] = self.current_time() [icao24, interrogator, ca] = self.parse11(shortdata, parity, ecc) - return "MSG,8,0,0,%X,0,%s,%s,%s,%s,,,,,,,,,,,,\n" % (icao24,datestr,timestr,datestr,timestr) + aircraft_id = self.get_aircraft_id(icao24) + return "MSG,8,0,%i,%X,%i,%s,%s,%s,%s,,,,,,,,,,,,\n" % (aircraft_id, icao24, aircraft_id+100, datestr, timestr, datestr, timestr) def pp17(self, shortdata, longdata, parity, ecc): icao24 = shortdata & 0xFFFFFF + aircraft_id = self.get_aircraft_id(icao24) subtype = (longdata >> 51) & 0x1F retstr = None @@ -139,7 +166,7 @@ class modes_output_sbs1(modes_parse.modes_parse): if subtype >= 1 and subtype <= 4: # Aircraft Identification msg = self.parseBDS08(shortdata, longdata, parity, ecc) - retstr = "MSG,1,0,0,%X,0,%s,%s,%s,%s,%s,,,,,,,,,,,\n" % (icao24, datestr, timestr, datestr, timestr, msg) + retstr = "MSG,1,0,%i,%X,%i,%s,%s,%s,%s,%s,,,,,,,,,,,\n" % (aircraft_id, icao24, aircraft_id+100, datestr, timestr, datestr, timestr, msg) elif subtype >= 5 and subtype <= 8: # Surface position measurement @@ -147,7 +174,7 @@ class modes_output_sbs1(modes_parse.modes_parse): if decoded_lat is None: #no unambiguously valid position available retstr = None else: - retstr = "MSG,2,0,0,%X,0,%s,%s,%s,%s,,%i,,,%.5f,%.5f,,,,0,0,0\n" % (icao24, datestr, timestr, datestr, timestr, altitude, decoded_lat, decoded_lon) + retstr = "MSG,2,0,%i,%X,%i,%s,%s,%s,%s,,%i,,,%.5f,%.5f,,,,0,0,0\n" % (aircraft_id, icao24, aircraft_id+100, datestr, timestr, datestr, timestr, altitude, decoded_lat, decoded_lon) elif subtype >= 9 and subtype <= 18 and subtype != 15: # Airborne position measurements @@ -158,7 +185,7 @@ class modes_output_sbs1(modes_parse.modes_parse): if decoded_lat is None: #no unambiguously valid position available retstr = None else: - retstr = "MSG,3,0,0,%X,0,%s,%s,%s,%s,,%i,,,%.5f,%.5f,,,,0,0,0\n" % (icao24, datestr, timestr, datestr, timestr, altitude, decoded_lat, decoded_lon) + retstr = "MSG,3,0,%i,%X,%i,%s,%s,%s,%s,,%i,,,%.5f,%.5f,,,,0,0,0\n" % (aircraft_id, icao24, aircraft_id+100, datestr, timestr, datestr, timestr, altitude, decoded_lat, decoded_lon) elif subtype == 19: # Airborne velocity measurements @@ -166,10 +193,10 @@ class modes_output_sbs1(modes_parse.modes_parse): subsubtype = (longdata >> 48) & 0x07 if subsubtype == 0: [velocity, heading, vert_spd] = self.parseBDS09_0(shortdata, longdata, parity, ecc) - retstr = "MSG,4,0,0,%X,0,%s,%s,%s,%s,,,%.1f,%.1f,,,%i,,,,,\n" % (icao24, datestr, timestr, datestr, timestr, velocity, heading, vert_spd) + retstr = "MSG,4,0,%i,%X,%i,%s,%s,%s,%s,,,%.1f,%.1f,,,%i,,,,,\n" % (aircraft_id, icao24, aircraft_id+100, datestr, timestr, datestr, timestr, velocity, heading, vert_spd) elif subsubtype == 1: [velocity, heading, vert_spd] = self.parseBDS09_1(shortdata, longdata, parity, ecc) - retstr = "MSG,4,0,0,%X,0,%s,%s,%s,%s,,,%.1f,%.1f,,,%i,,,,,\n" % (icao24, datestr, timestr, datestr, timestr, velocity, heading, vert_spd) + retstr = "MSG,4,0,%i,%X,%i,%s,%s,%s,%s,,,%.1f,%.1f,,,%i,,,,,\n" % (aircraft_id, icao24, aircraft_id+100, datestr, timestr, datestr, timestr, velocity, heading, vert_spd) return retstr From 616ab8362beea2d78753ad85d80e1a7c345a6e75 Mon Sep 17 00:00:00 2001 From: Zack Moratto Date: Sat, 9 Jul 2011 01:40:07 -0700 Subject: [PATCH 5/5] Have the SBS record milliseconds --- src/python/modes_sbs1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python/modes_sbs1.py b/src/python/modes_sbs1.py index d5e9112..27d2428 100644 --- a/src/python/modes_sbs1.py +++ b/src/python/modes_sbs1.py @@ -79,7 +79,7 @@ class modes_output_sbs1(modes_parse.modes_parse): def current_time(self): timenow = datetime.now() - return [timenow.strftime("%Y/%m/%d"), timenow.strftime("%H:%M:%S.000")] + return [timenow.strftime("%Y/%m/%d"), timenow.strftime("%H:%M:%S.%f")[0:-3]] def decode_fs(self, fs): if fs == 0: