File: adsb_kml.py

package info (click to toggle)
gr-satellites 5.8.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,836 kB
  • sloc: python: 29,546; cpp: 5,448; ansic: 1,247; sh: 118; makefile: 24
file content (59 lines) | stat: -rw-r--r-- 1,632 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright 2016 Daniel Estevez <daniel@destevez.net>
#
# This file is part of gr-satellites
#
# SPDX-License-Identifier: GPL-3.0-or-later
#

from gnuradio import gr
import numpy
import pmt

from .telemetry import gomx_3 as tlm


class adsb_kml(gr.basic_block):
    """docstring for block adsb_kml"""
    def __init__(self):
        gr.basic_block.__init__(
            self,
            name='adsb_kml',
            in_sig=None,
            out_sig=None)

        self.message_port_register_in(pmt.intern('in'))
        self.set_msg_handler(pmt.intern('in'), self.handle_msg)

    def handle_msg(self, msg_pmt):
        msg = pmt.cdr(msg_pmt)
        if not pmt.is_u8vector(msg):
            print('[ERROR] Received invalid message type. Expected u8vector')
            return

        packet = bytes(pmt.u8vector_elements(msg))
        beacon = tlm.parse(packet)

        # check that message is beacon
        if (beacon.csp_header.destination != 10
                or beacon.csp_header.destination_port != 30):
            return

        if beacon.csp_header.source != 1 or beacon.beacon_type != 0:
            return

        adsb = beacon.beacon.adsb

        print("""<Placemark>
        <name>{}</name>
        <description>Altitude: {}ft Time: {}</description>
        <styleUrl>#plane</styleUrl>
        <Point><coordinates>{},{}</coordinates></Point>
</Placemark>""".format(
             hex(adsb.last_icao),
             adsb.last_alt,
             adsb.last_time,
             adsb.last_lon if adsb.last_lon <= 180 else adsb.last_lon - 360,
             adsb.last_lat))