Exemple #1
0
    def read_message(self, msg, ts):
        """
        Process ADSB messages
        """

        if len(msg) < 28:
            return

        df = decoder.get_df(msg)

        if df == 17:
            addr = decoder.get_icao_addr(msg)
            tc = decoder.get_tc(msg)

            if tc >= 1 and tc <= 4:
                # aircraft identification
                callsign = decoder.get_callsign(msg)
                self.update_callsign(addr, callsign)
            if tc >= 9 and tc <= 18:
                # airbone postion frame
                alt = decoder.get_alt(msg)
                oe = decoder.get_oe_flag(msg)  # odd or even frame
                cprlat = decoder.get_cprlat(msg)
                cprlon = decoder.get_cprlon(msg)
                self.update_cprpos(addr, oe, ts, alt, cprlat, cprlon)
            elif tc == 19:  # airbone velocity frame
                sh = decoder.get_speed_heading(msg)
                if len(sh) == 2:
                    spd = sh[0]
                    hdg = sh[1]
                    self.update_spd_hdg(addr, spd, hdg)
        return
Exemple #2
0
    def read_message(self, msg, ts):
        """
        Process ADSB messages
        """

        if len(msg) < 28:
            return

        df = decoder.get_df(msg)

        if df == 17:
            addr = decoder.get_icao_addr(msg)
            tc = decoder.get_tc(msg)

            if tc >= 1 and tc <= 4:
                # aircraft identification
                callsign = decoder.get_callsign(msg)
                self.update_callsign(addr, callsign)
            if tc >= 9 and tc <= 18:
                # airbone postion frame
                alt = decoder.get_alt(msg)
                oe = decoder.get_oe_flag(msg)  # odd or even frame
                cprlat = decoder.get_cprlat(msg)
                cprlon = decoder.get_cprlon(msg)
                self.update_cprpos(addr, oe, ts, alt, cprlat, cprlon)
            elif tc == 19:        # airbone velocity frame
                sh = decoder.get_speed_heading(msg)
                if len(sh) == 2:
                    spd = sh[0]
                    hdg = sh[1]
                    self.update_spd_hdg(addr, spd, hdg)
        return
Exemple #3
0
    def read_message(self, msgtype, data, datalen):
        ''' Process the message that received from remote TCP server '''  
        if msgtype == 3:
            # get time from the Aircraft
            t_sec_ac = 0
            t_sec_ac |= data[0] << 24
            t_sec_ac |= data[1] << 16
            t_sec_ac |= data[2] << 8
            t_sec_ac |= data[3]

            # get receiver timestamp
            t_sec_receiver = 0
            t_sec_receiver |= data[4] << 24
            t_sec_receiver |= data[5] << 16
            t_sec_receiver |= data[6] << 8
            t_sec_receiver |= data[7]

            # ignor receiver id, data[8]
            # ignor data[9], for now

            mlat = 0
            mlat |= data[10] << 24
            mlat |= data[11] << 16
            mlat |= data[12] << 8
            mlat |= data[13]

            power = 0
            power |= data[14] << 8
            power |= data[15]
            power &= 0x3FFF  
            power = power >> 6

            # process msg in the data frame
            msg = ''
            msglen = 14     # type 3 data length is 14
            msgstart = 16
            msgend = msgstart + msglen
            for i in data[msgstart : msgend] :
                msg += "%02X" % i

            # print "Type:%d | Len:%d | AcTime:%d | ReceiverTime:%d | Power:%d | MSG: %s"  % \
            #     (msgtype, datalen, t_sec_ac, t_sec_receiver, power, msg)

            df = adsb_decoder.get_df(msg)
            tc = adsb_decoder.get_tc(msg)
            ca = adsb_decoder.get_ca(msg)

            if df == 17:
                addr = adsb_decoder.get_icao_addr(msg)

                if tc>=1 and tc<=4:                     # aircraft identification
                    callsign = adsb_decoder.get_callsign(msg)
                    self.datafeed.update_callsign_data(addr, callsign)
                if tc>=9 and tc<=18:                    # airbone postion frame
                    alt = adsb_decoder.get_alt(msg)
                    oe = adsb_decoder.get_oe_flag(msg)  # odd or even frame
                    cprlat = adsb_decoder.get_cprlat(msg)
                    cprlon = adsb_decoder.get_cprlon(msg)
                    dataset = {'addr':addr, 'oe':oe, 'time':t_sec_ac, 'alt':alt,
                            'cprlat':cprlat, 'cprlon':cprlon}
                    # print dataset
                    self.datafeed.push_cprpos_data(dataset)
                elif tc==19:        # airbone velocity frame
                    sh = adsb_decoder.get_speed_heading(msg)
                    if sh:
                        dataset = {'addr':addr, 'speed':sh[0], 'heading':sh[1]}
                        self.datafeed.push_speed_heading_data(dataset)

            return
Exemple #4
0
def decode_adsb(fs_msg):
    """
    decode message

    @param fs_msg: message to decode
    """
    # logger
    # M_LOG.info(">> decode_adsb")

    # invalid message ?
    if not (fs_msg.startswith('*') and fs_msg.endswith(';')):
        # logger
        M_LOG.warning("decode_adsb:<E01: invalid message [{}]".format(fs_msg))

        # return
        return

    # obtém a mensagem em hexadecimal
    ls_hex_message = fs_msg[1:-2]
    M_LOG.debug("ls_hex_message: {}".format(ls_hex_message))

    #if not dcdr.checksum(ls_hex_message):
        #M_LOG.debug("decode_adsb:Erro de checksum !!!")
        #return

    # calcula o tamanho da mensagem em binário
    ln_bits = 4 * len(ls_hex_message)

    # obtém a mensagem em binário
    ls_bin_message = bin(int(ls_hex_message, 16))[2:].zfill(ln_bits)

    # downlink format
    li_df = int(ls_bin_message[0:5], 2)

    # mensagem ADS-B tratável ?
    if li_df not in [ 17 ]:
        # logger
        M_LOG.warning("decode_adsb:<E02: tipo de mensagem não tratada.")

        # return
        return

    # message subtype / capability (3 bits) (get_cap)
    li_cap = int(ls_bin_message[5:8], 2)

    # ICAO aircraft address (get_icao_addr)
    ls_icao_addr = ls_hex_message[2:8]

    # CRC (error check)
    ls_crc = ls_hex_message[-6:]
    M_LOG.debug("ls_crc: {}".format(ls_crc))

    # extended squitter type (get_tc)
    li_type_code = int(ls_bin_message[32:37], 2)

    try:
        # aircraft identification
        if li_type_code in xrange(1, 5):

            M_LOG.debug("aircraft identification")

            # aircraft category (3 bits)
            li_type = int(ls_bin_message[38:40], 2)
            M_LOG.debug("li_type: {}".format(li_type))

            # atualiza o callsign na aeronave
            s_callsign = dcdr.get_callsign(ls_bin_message)

        # surface position
        elif li_type_code in xrange(5, 9):
            M_LOG.debug("surface position")
            pass

        # airborne position
        elif li_type_code in xrange(9, 19):

            M_LOG.debug("airborne position (Baro Alt)")

            # surveillance status (2 bits)
            #
            # - 0 no emergency or other Mode 3/A code information
            # - 1 permanent alert (emergency code)
            # - 2 temporary alert (change of Mode 3/A code other than emergency)
            # - 3 special position indicator (SPI) condition

            sv_status = int(ls_bin_message[37:39], 2)
            M_LOG.debug("sv_status: {}".format(sv_status))

            # altitude (12 bits) (get_alt)
            altitude = dcdr.get_alt(ls_bin_message)
            M_LOG.debug("altitude: {}".format(altitude))

            # CPR odd/even flag (1 bit) (get_oe_flag)
            cpr_format_flag = int(ls_bin_message[53])

            if 1 == cpr_format_flag:
                if (ls_icao_addr in dct_cpr) and (dct_cpr[ls_icao_addr] is not None):
                    lat, lng = dcdr.cpr2position(dcdr.get_cprlat(dct_cpr[ls_icao_addr]),
                                                 dcdr.get_cprlat(ls_bin_message),
                                                 dcdr.get_cprlng(dct_cpr[ls_icao_addr]),
                                                 dcdr.get_cprlng(ls_bin_message), 0, 1)
                    M_LOG.debug(">>>>>>>>>>>>>>  lat, lng: {}".format((lat, lng)))

                dct_cpr[ls_icao_addr] = None

            elif 0 == cpr_format_flag:
                dct_cpr[ls_icao_addr] = ls_bin_message

        # airborne velocities ?
        elif 19 == li_type_code:

            M_LOG.debug("airborne velocities")

            # extended squitter subtype
            es_subtype = int(ls_bin_message[38:40], 2)
            M_LOG.debug("es_subtype: {}".format(es_subtype))

            # obtém a velocidade e a proa
            l_vel, l_proa = dcdr.get_speed_heading(ls_bin_message)
            M_LOG.debug("speed, heading: {}".format((l_vel, l_proa)))

            # turn indicator (2-bit)
            turn_indicator = int(ls_bin_message[78:79], 2)
            M_LOG.debug("turn_indicator: {}".format(turn_indicator))

        # airborne position (GNSS height) ?
        elif li_type_code in xrange(20, 23):
            M_LOG.debug("airborne position (GNSS height)")
            pass

        # test message ?
        elif 23 == li_type_code:
            M_LOG.debug("test message")
            pass

        # surface system status ?
        elif 24 == li_type_code:
            M_LOG.debug("surface system status")
            pass

        # reserved ?
        elif li_type_code in xrange(25, 28):
            M_LOG.debug("reserved")
            pass

        # extended squitter AC status ?
        elif 28 == li_type_code:
            M_LOG.debug("extended squitter AC status")
            pass

        # target state and status (V.2) ?
        elif 29 == li_type_code:
            M_LOG.debug("target state and status (V.2)")
            pass

        # reserved ?
        elif 30 == li_type_code:
            M_LOG.debug("reserved")
            pass

        # aircraft operation status ?
        elif 31 == li_type_code:
            M_LOG.debug("aircraft operation status")
            pass

        # senão,...
        else:
            # logger
            l_log = logging.getLogger("CEmulaVisADSB::decode_adsb")
            l_log.setLevel(logging.NOTSET)
            l_log.warning("E01: mensagem não reconhecida ou não tratada.")

    except: pass