def test_telnet_parse_complete(self, datetime_mock):
        # set the utcnow-mock near to the time in the test string
        datetime_mock.utcnow.return_value = datetime(2015, 1, 1, 10, 0, 55)

        message = parse('0.181sec:868.394MHz:   1:2:DDA411 103010: [ +50.86800, +12.15279]deg  988m  +0.1m/s  25.7m/s 085.4deg  -3.5deg/sec 5 03x04m 01f_-12.61kHz  5.8/15.5dB/2 10e   30.9km 099.5deg  +1.1deg + ?     R     B8949')

        self.assertEqual(message['pps_offset'], 0.181)
        self.assertEqual(message['frequency'], 868.394)
        self.assertEqual(message['aircraft_type'], 1)
        self.assertEqual(message['address_type'], 2)
        self.assertEqual(message['address'], 'DDA411')
        self.assertEqual(message['timestamp'], datetime(2015, 1, 1, 10, 30, 10))
        self.assertEqual(message['latitude'], 50.868)
        self.assertEqual(message['longitude'], 12.15279)
        self.assertEqual(message['altitude'], 988)
        self.assertEqual(message['climb_rate'], 0.1)
        self.assertEqual(message['ground_speed'], 25.7)
        self.assertEqual(message['track'], 85.4)
        self.assertEqual(message['turn_rate'], -3.5)
        self.assertEqual(message['magic_number'], 5)  # the '5' is a magic number... 1 if ground_speed is 0.0m/s an 3 or 5 if airborne. Do you have an idea what it is?
        self.assertEqual(message['gps_status'], '03x04')
        self.assertEqual(message['channel'], 1)
        self.assertEqual(message['flarm_timeslot'], True)
        self.assertEqual(message['ogn_timeslot'], False)
        self.assertEqual(message['frequency_offset'], -12.61)
        self.assertEqual(message['decode_quality'], 5.8)
        self.assertEqual(message['signal_quality'], 15.5)
        self.assertEqual(message['demodulator_type'], 2)
        self.assertEqual(message['error_count'], 10)
        self.assertEqual(message['distance'], 30.9)
        self.assertEqual(message['bearing'], 99.5)
        self.assertEqual(message['phi'], 1.1)
        self.assertEqual(message['multichannel'], True)
    def test_telnet_parse(self, datetime_mock):
        # set the utcnow-mock near to the time in the test string
        datetime_mock.utcnow.return_value = datetime(2015, 1, 1, 10, 0, 55)

        message = parse('0.867sec:868.398MHz:   1:2:DD9AB2 100050: [ +47.44356, +11.77856]deg 2749m  +3.2m/s  34.5m/s 082.7deg  -0.7deg/sec 5 03x03m  -1.6kHz  8.5dB  1e   50.6km 151.4deg  +1.9deg')

        self.assertEqual(message['pps_offset'], 0.867)
        self.assertEqual(message['frequency'], 868.398)
        self.assertEqual(message['aircraft_type'], 1)
        self.assertEqual(message['address_type'], 2)
        self.assertEqual(message['address'], 'DD9AB2')
        self.assertEqual(message['timestamp'], datetime(2015, 1, 1, 10, 0, 50))
        self.assertEqual(message['latitude'], 47.44356)
        self.assertEqual(message['longitude'], 11.77856)
        self.assertEqual(message['altitude'], 2749)
        self.assertEqual(message['climb_rate'], 3.2)
        self.assertEqual(message['ground_speed'], 34.5)
        self.assertEqual(message['track'], 82.7)
        self.assertEqual(message['turn_rate'], -0.7)
        self.assertEqual(message['magic_number'], 5)  # the '5' is a magic number... 1 if ground_speed is 0.0m/s an 3 or 5 if airborne. Do you have an idea what it is?
        self.assertEqual(message['gps_status'], '03x03')
        self.assertEqual(message['frequency_offset'], -1.6)
        self.assertEqual(message['signal_quality'], 8.5)
        self.assertEqual(message['error_count'], 1)
        self.assertEqual(message['distance'], 50.6)
        self.assertEqual(message['bearing'], 151.4)
        self.assertEqual(message['phi'], 1.9)
Esempio n. 3
0
    def process_beacon(self, raw_message):
        beacon = parse(raw_message)
        td = [self.th]
        if beacon:
            # fetch the device info from ogndb
            t = (beacon['address'], )
            c = self.conn.execute('SELECT * FROM t_ogndb WHERE DEVICE_ID=?', t)
            ogn_db_rec = c.fetchone()

            # update registration if in db else update device-id
            if ogn_db_rec is None:
                registration = beacon['address']
            else:
                registration = ogn_db_rec[3]  # registration

            self.gliders[registration] = beacon
            for g in self.gliders.items():
                td.append([
                    g[0], g[1]['frequency'], g[1]['distance'],
                    g[1]['ground_speed'], g[1]['altitude']
                ])

            if not 'no-logfile' in self.args:
                with open(self.output_file, mode='a') as f:
                    f.write(str(beacon))
        self.disp(td)
Esempio n. 4
0
    def callback(raw_message):
        message = parse(raw_message)
        if not message:
            if not raw_message.startswith('APRS'):
                print("Could not parse: {}".format(raw_message))
            return

        state_machine.add_message(message)
        message["timestamp"] = int(message["timestamp"].replace(tzinfo=timezone.utc).timestamp())
        socketio.emit("ogn_data", message, namespace="/ogn")
Esempio n. 5
0
def emit_test_data():
    """Emits test data from static file for testing purposes."""

    timestamp = None

    for line in open(os.path.join(here, "telnet_logfile.txt")):
        raw_message = line.rstrip("\n")
        message = parse(raw_message)

        if not message:
            if not raw_message.startswith('APRS'):
                print("Could not parse: {}".format(raw_message))
            continue

        state_machine.add_message(message)
        message["timestamp"] = int(message["timestamp"].replace(tzinfo=timezone.utc).timestamp())

        if timestamp is None:
            timestamp = message["timestamp"]

        socketio.emit("ogn_data", message, namespace="/ogn")
        if timestamp != message["timestamp"]:
            timestamp = message["timestamp"]
            socketio.sleep(1.0)
 def test_telnet_fail_corrupt(self):
     with self.assertRaises(ParseError):
         parse('This is rubbish')
    def test_telnet_parse_corrupt(self):
        message = parse('0.397sec:868.407MHz:  sA:1:784024 205656: [  +5.71003, +20.48951]deg 34012m +14.5m/s 109.7m/s 118.5deg +21.0deg/sec 0 27x40m 01_o +7.03kHz 17.2/27.0dB/2 12e 4719.5km 271.1deg  -8.5deg   ?     R     B34067')

        self.assertIsNone(message)