예제 #1
0
파일: Emulator.py 프로젝트: snegulak/SoftRF
 def process_e(self):
     type = 1
     status = 323
     vs = vsmult = no_track = stealth = 0
     out_bytes = pack_values(self.myId, vs, status, type, self.mylat, self.mylon, self.myalt, vsmult, no_track, stealth)
     #print timestamp, out_bytes
     key = make_key(self.mytstamp, (out_bytes[1] << 16) | (out_bytes[0] << 8))
     enc_bytes = encrypt_packet(out_bytes, key)
     self.d.sendto(bytearray(enc_bytes), (self.dst_host, self.dst_port))
예제 #2
0
    def process_d(self):

        try:
            message = self.s.recv(8192)

            timestamp_d = time()

            page = message.split("\n")
            for record in page:
                if len(record) > 0:
                    bits = hex_to_bits(record)

                    in_bytes = numpy.packbits(bits)

                    raw_hex = "".join(
                        ["{0:02x}".format(byte) for byte in in_bytes])
                    if (in_bytes[3] == 0x20 or (in_bytes[3] == 0x22)):
                        key = make_key(int(timestamp_d), (in_bytes[1] << 16) |
                                       (in_bytes[0] << 8))
                        #print "Key: " + str(key)
                        bytes = decrypt_packet(in_bytes, key)
                        #print bytes
                        icao, lat, lon, alt, vs, no_track, stealth, typ, ns, ew, status, unk = extract_values(
                            bytes[0:24])

                        parity = 0
                        for sym in bytes:
                            parity ^= parityOf(sym)
                        if (parity & 0x1) == 0:
                            lat = recover_lat(lat, int(self.mylat * 1e7))
                            lon = recover_lon(lon, int(self.mylon * 1e7))
                            if False:  # True:
                                print "Timestamp: " + str(timestamp_d),
                                print "ICAO: " + icao,
                                print "Lat: " + str(lat),
                                print "Lon: " + str(lon),
                                print "Alt: " + str(alt) + "m",
                                print "VS: " + str(vs),
                                print "No-track: " + str(no_track),
                                print "Stealth: " + str(stealth),
                                print "Type: " + str(typ),
                                print "GPS status: " + str(status),
                                print "North/South speeds: {0},{1},{2},{3}".format(
                                    *ns),
                                print "East/West speeds: {0},{1},{2},{3}".format(
                                    *ew),
                                print "Unknown: {0:04x}".format(unk),
                                print "Raw: {0:02x}".format(bytes[3]),
                                print "{0:02x}{1:02x}{2:02x}{3:02x}{4:02x}{5:02x}{6:02x}{7:02x}".format(
                                    *bytes[4:12]),
                                print "{0:02x}{1:02x}{2:02x}{3:02x}{4:02x}{5:02x}{6:02x}{7:02x}".format(
                                    *bytes[12:20]),
                                print "{0:02x}{1:02x}{2:02x}{3:02x}".format(
                                    *bytes[20:24]),

                                print
                            #else:
                            #  print raw_hex

                            trlat = lat / 1e7
                            trlgt = lon / 1e7
                            return (icao, trlat, trlgt, alt)

                    else:
                        print "Don't know how to decrypt packet type {0:02x}".format(
                            in_bytes[3])
                        icao, _, _, _, _, _, _, _, _, _, _, _ = extract_values(
                            in_bytes[0:24])
                        lat, lon, alt = -1, -1, -1

                    return (0, 0, 0, 0)  # ""

        except error, e:
            if e.args[0] == errno.EWOULDBLOCK:
                #print 'EWOULDBLOCK'
                #time.sleep(1)           # short delay, no tight loops
                return (0, 0, 0, 0)  # ""
            else:
                print e
            return (0, 0, 0, 0)  # "" # "$FLM\r\n"