Пример #1
0
    def post_telemetry(self, message):  # pylint: disable=no-self-use
        """End point for receiving telemetry readings. Some phones don't support
        websockets, so just use plain old POST.
        """
        try:
            message = json.loads(str(message))

            if 'latitude_d' in message:
                TelemetryProducer().gps_reading(
                    message['latitude_d'],
                    message['longitude_d'],
                    message['accuracy_m'],
                    message['heading_d'],
                    message['speed_m_s'],
                    message['timestamp_s'],
                    message['device_id'],
                )
            elif 'compass_d' in message:
                TelemetryProducer().compass_reading(
                    message['compass_d'],
                    message['confidence'],
                    message['device_id'],
                )
            else:
                AsyncLogger().error(
                    'Received unexpected web telemetry message: {}'.format(
                        message))

        except Exception as exc:  # pylint: disable=broad-except
            AsyncLogger().error(
                'Invalid POST telemetry message "{}": {} {}'.format(
                    message, type(exc), exc))
            return {'success': False, 'message': str(exc)}

        return {'success': True}
Пример #2
0
 def received_message(message):
     """Handler for receiving a message on the websocket."""
     try:
         if message.is_binary:
             # TODO(2016-08-13) Log an error
             return
         message = json.loads(str(message))
         if 'latitude_d' in message:
             TelemetryProducer().gps_reading(
                 message['latitude_d'],
                 message['longitude_d'],
                 message['accuracy_m'],
                 message['heading_d'],
                 message['speed_m_s'],
                 message['timestamp_s'],
                 message['device_id'],
             )
         elif 'compass_d' in message:
             TelemetryProducer().compass_reading(
                 message['compass_d'],
                 message['confidence'],
                 message['device_id'],
             )
         else:
             AsyncLogger().error(
                 'Received unexpected web telemetry message: "{}"'.format(
                     message))
     # We need to catch all exceptions because any that are raised will close
     # the websocket
     except Exception as exc:  # pylint: disable=broad-except
         AsyncLogger().error(
             'Error processing web telemetry message "{}": {} {}'.format(
                 message, type(exc), exc))
Пример #3
0
    def __init__(self, serial):
        """Create the TelemetryData thread."""
        super(Sup800fTelemetry, self).__init__()
        self.name = self.__class__.__name__

        self._telemetry = TelemetryProducer()
        self._serial = serial
        self._logger = AsyncLogger()
        self._run = True
        self._iterations = 0
        # These initial measurements are from a calibration observation
        self._compass_offsets = (-11.87, -5.97)
        self._magnitude_mean = 353.310
        self._magnitude_std_dev = 117.918

        self._calibrate_compass_end_time = None
        self._nmea_mode = True
        self._last_compass_heading_d = 0.0
        self._dropped_compass_messages = 0
        self._dropped_threshold = 10

        self._hdop = 5.0

        def handle_message(message):
            """Handles command messages. Only cares about calibrate compass;
            other messages are ignored.
            """
            if message == 'calibrate-compass':
                self.calibrate_compass(10)

        consume = lambda: consume_messages(config.COMMAND_FORWARDED_EXCHANGE,
                                           handle_message)
        thread = threading.Thread(target=consume)
        thread.name = '{}:consume_messages:{}'.format(
            self.__class__.__name__, config.COMMAND_FORWARDED_EXCHANGE)
        thread.start()