예제 #1
0
파일: decode.py 프로젝트: jaimebw/traffic
    def altcode(self, args: Tuple[datetime, str]) -> None:
        t, msg = args
        from pyModeS import hex2bin

        if set(hex2bin(msg)[19:32]) in [{"0"}, {"1"}]:
            return
        self.alt = pms.common.altcode(msg)
        with self.lock:
            self.cumul.append(
                dict(timestamp=t, icao24=self.icao24, altitude=self.alt))
예제 #2
0
def adsb_flag(text):
    bits = []
    for i in text:  # i in range(len(text)): #text: #len(text):
        code = i[0:28]
        tc = pms.adsb.typecode(code)
        if tc is not None and 9 <= tc <= 18:  # 20-22??
            bit = pms.hex2bin(code)  # Convert hexadecimal string to binary string
            bit = bit[54 - 1]
            bit = pms.bin2int(bit)  # Convert binary string to integer # Or use just int(bit)
            if bit == 0 or bit == 1:
                bits.append(bit)
            # elif bit==1:
            else:
                print("Warning: No bit value!")
        else:
            bits.append('None')
    return bits
예제 #3
0
파일: adsb.py 프로젝트: luxair/lg-radar
    def correct(self, msg):
        crc = pms.bin2int(pms.crc(msg))
        result = msg

        if crc != 0:
            msg_bin = pms.hex2bin(msg)
            for i in range(len(msg_bin) - 24):
                if msg_bin[i] == '0':
                    msg_bin = self.replace(msg_bin, i, '1')
                else:
                    msg_bin = self.replace(msg_bin, i, '0')

                patched_msg = hex(int(msg_bin, 2))[2:]
                if pms.bin2int(pms.crc(patched_msg)) == 0:
                    result = patched_msg
                    break

                if msg_bin[i] == '0':
                    msg_bin = self.replace(msg_bin, i, '1')
                else:
                    msg_bin = self.replace(msg_bin, i, '0')

        return result
        pass
    try:
        data = s.recv(BUFFER_SIZE)
    except:
        continue

    data = data[data.find(char1) + 1:data.find(char2)]
    data_length = len(data)
    try:
        dl_format = pms.df(data)
    except:
        break

    #CHECK MESSAGE CORRUPTED
    try:
        MSG = pms.hex2bin(data)
    except:
        pass

    if data_length > 14:
        CRC = pms.crc(MSG, encode=False)

        if int(CRC, 2) == 0:
            #print "Received Data:", data
            #print 'MSG is CORRECT'
            message = data
            type_code = pms.adsb.typecode(message)
            velocity = ''
            icao = ''
            lon = ''
            lat = ''