示例#1
0
 def receive(self, message):
     """implement ITelemetryObject"""
     self.__last_heard_time = message.receive_time
     for fact in message.facts:
         if isinstance(fact, KillObject):
             # Kill by pretending the object is ancient.
             self.__last_heard_time = 0
         if isinstance(fact, Position):
             self.__track = self.__track._replace(
                 latitude=TelemetryItem(fact.latitude, message.receive_time),
                 longitude=TelemetryItem(fact.longitude, message.receive_time),
             )
         if isinstance(fact, Altitude):
             conversion = _FEET_TO_METERS if fact.feet_not_meters else 1
             self.__track = self.__track._replace(
                 altitude=TelemetryItem(fact.value * conversion, message.receive_time),
             )
         if isinstance(fact, Velocity):
             self.__track = self.__track._replace(
                 h_speed=TelemetryItem(fact.speed_knots * _KNOTS_TO_METERS_PER_SECOND, message.receive_time),
                 track_angle=TelemetryItem(fact.course_degrees, message.receive_time),
             )
         elif isinstance(fact, Status):
             # TODO: Empirically, not always ASCII. Move this implicit decoding off into parse stages.
             self.__status = unicode(fact.text)
         elif isinstance(fact, Symbol):
             self.__symbol = unicode(fact.id)
         else:
             # TODO: Warn somewhere in this case (recognized by parser but not here)
             pass
     self.__last_comment = unicode(message.comment)
     if len(message.errors) > 0:
         self.__last_parse_error = '; '.join(message.errors)
     self.state_changed()
示例#2
0
 def test_track(self):
     self.assertEqual(empty_track, self.s.get_track())
     self.s.receive(self.__message([Position(31, -42)]))
     self.assertEqual(
         empty_track._replace(
             latitude=TelemetryItem(31, _dummy_receive_time),
             longitude=TelemetryItem(-42, _dummy_receive_time),
         ), self.s.get_track())
示例#3
0
 def get_track(self):
     if self.__grid:
         latitude, longitude = grid_to_lat_long(self.__grid)
         track = Track(latitude=TelemetryItem(latitude, self.__last_heard),
                       longitude=TelemetryItem(longitude,
                                               self.__last_heard))
         return track
     else:
         return empty_track
示例#4
0
 def test_init_from_partial_json(self):
     self.assertEquals(
         empty_track._replace(
             latitude=TelemetryItem(1, 1000),
             longitude=TelemetryItem(2, 1000)),
         Track({
             u'latitude': {u'value': 1, u'timestamp': 1000},
             u'longitude': {u'value': 2, u'timestamp': 1000},
         }))
示例#5
0
 def __init__(self, latitude, longitude):
     self.__track = empty_track._replace(
         latitude=TelemetryItem(float(latitude), None),
         longitude=TelemetryItem(float(longitude), None))
示例#6
0
 def receive(self, message_wrapper):
     message = message_wrapper.message
     cpr_decoder = message_wrapper.cpr_decoder
     receive_time = message_wrapper.receive_time
     self.__last_heard_time = receive_time
     # Unfortunately, gr-air-modes doesn't provide a function to implement this gunk -- imitating its output_flightgear code which
     data = message.data
     t = data.get_type()
     if t == 0:
         self.__track = self.__track._replace(altitude=TelemetryItem(
             air_modes.decode_alt(data['ac'], True) *
             _METERS_PER_FEET, receive_time))
         # TODO more info available here
     elif t == 4:
         self.__track = self.__track._replace(altitude=TelemetryItem(
             air_modes.decode_alt(data['ac'], True) *
             _METERS_PER_FEET, receive_time))
         # TODO more info available here
     elif t == 5:
         self.__ident = air_modes.decode_id(data['id'])
         # TODO more info available here
     elif t == 17:  # ADS-B
         bdsreg = data['me'].get_type()
         if bdsreg == 0x05:
             # TODO use unused info
             (altitude_feet, latitude, longitude, _range,
              _bearing) = air_modes.parseBDS05(data, cpr_decoder)
             self.__track = self.__track._replace(
                 altitude=TelemetryItem(altitude_feet * _METERS_PER_FEET,
                                        receive_time),
                 latitude=TelemetryItem(latitude, receive_time),
                 longitude=TelemetryItem(longitude, receive_time),
             )
         elif bdsreg == 0x06:
             # TODO use unused info
             (_ground_track, latitude, longitude, _range,
              _bearing) = air_modes.parseBDS06(data, cpr_decoder)
             self.__track = self.__track._replace(
                 latitude=TelemetryItem(latitude, receive_time),
                 longitude=TelemetryItem(longitude, receive_time),
             )
         elif bdsreg == 0x08:
             (self.__call,
              self.__aircraft_type) = air_modes.parseBDS08(data)
         elif bdsreg == 0x09:
             subtype = data['bds09'].get_type()
             if subtype == 0:
                 (velocity, heading, vertical_speed,
                  _turn_rate) = air_modes.parseBDS09_0(data)
                 # TODO: note we're stuffing the heading in as track angle. Is there something better to do?
                 self.__track = self.__track._replace(
                     h_speed=TelemetryItem(
                         velocity * _KNOTS_TO_METERS_PER_SECOND,
                         receive_time),
                     heading=TelemetryItem(heading, receive_time),
                     track_angle=TelemetryItem(heading, receive_time),
                     v_speed=TelemetryItem(vertical_speed, receive_time),
                     # TODO add turn rate
                 )
             elif subtype == 1:
                 (velocity, heading,
                  vertical_speed) = air_modes.parseBDS09_1(data)
                 self.__track = self.__track._replace(
                     h_speed=TelemetryItem(
                         velocity * _KNOTS_TO_METERS_PER_SECOND,
                         receive_time),
                     heading=TelemetryItem(heading, receive_time),
                     track_angle=TelemetryItem(heading, receive_time),
                     v_speed=TelemetryItem(vertical_speed, receive_time),
                     # TODO reset turn rate?
                 )
             else:
                 # TODO report
                 pass
         else:
             # TODO report
             pass
     else:
         # TODO report
         pass
     self.state_changed()