#!/usr/bin/python # -*- coding: utf-8 -*- import math import time import os #fonction hex2bin: convertit hexa en bin def hex2bin(hexstr): scale = 16 num_of_bits = len(hexstr) * math.log(scale, 2) binstr = bin(int(hexstr, scale))[2:].zfill(int(num_of_bits)) return binstr # fonction bin2dec: convertit bin en decimal def bin2dec(buf): if 0 == len(buf): return -1 return int(buf, 2) # fonction pour générer le CRC (vérification) GENERATOR = "1111111111111010000001001" def crc(message): ''' D'après pyModeS/util.py''' msgbin = list(hex2bin(message)) # loop all bits, except last 24 piraty bits for i in range(len(msgbin)-24): # if 1, perform modulo 2 multiplication, if msgbin[i] == '1': for j in range(len(GENERATOR)): # modulo 2 multiplication = XOR msgbin[i+j] = str((int(msgbin[i+j]) ^ int(GENERATOR[j]))) # last 24 bits reminder = ''.join(msgbin[-24:]) return reminder #Chemin des dossiers home et adsb Chemin_home='/home/lavarenne' Chemin_dossier_adsb='/home/lavarenne/gnuradio/adsb' while(True): time.sleep(2) #déplacer les fichiers trames dans le dossier adsb os.system('mv {0}/file* {1}/'.format(Chemin_home,Chemin_dossier_adsb)) #lecture du nom des fichiers et insertion dans la liste fichier fichier=[] for files in os.listdir(Chemin_dossier_adsb): fichier.append(files) # boucle sur le nbr de fichiers dans le dossier adsb for k in range(0,len(fichier)): # Ouvrir le fichier binaire et afficher la trame with open('{0}/{1}'.format(Chemin_dossier_adsb,fichier[k]), "rb") as binary_file: data = binary_file.read() byte = map(ord,data[:107*2]) trame=[] trame_dec="" try: for i in range(0,107): trame.append(byte[2*i]) trame_dec+=str(trame[i]) except: pass print '' print '***********************************************************************************************************************' print '' print "la trame binaire est:" msg= "10001"+trame_dec print msg ########################################"" CHECK PARITY ""############################################################################ print crc(msg) if crc(msg) != '000000000000000000000000': print "TRAME INCOMPLÈTE ----- BAD PARITY" os.system('rm {0}/{1}'.format(Chemin_dossier_adsb,fichier[k])) else: print 'CRC check OK --- Données valides' ################################################" ICAO "############################################################################ # Afficher les 24 bits suivants concernant l'addresse ICAO de l'appareil: icao=msg[8:32] print "ICAO BIN:", icao icao_decimal=bin2dec(icao) print "ICAO HEX:", hex(icao_decimal)[2:] ######################################################## TYPE DE DONNÉES ############################################################## # Les 5 bits suivants ICAO constituent le Type Code TC qui définit le type de données dans les DATA: TC=msg[32:37] print "TC=", TC print "TC=", bin2dec(TC) ######################################################## IDENTIFICATION VOL ################################################################################################################# if 1 <= bin2dec(TC) <= 4: print "Aircraft identification" CHARSET = '#ABCDEFGHIJKLMNOPQRSTUVWXYZ#####################0123456789######' volbin = msg[40:88] vol = '' for i in range(0,7): vol += CHARSET[bin2dec(volbin[6*i:6*(i+1)])] vol = vol.replace('#', '') print 'Vol =', vol ######################################################## SURFACE POSITION ######################################################################################################################## if 5 <= bin2dec(TC) <= 8: print "Surface Position" ######################################################## AIRBORNE POSITION (w/ Baro Altitude) ###################################################################################################### if 9 <= bin2dec(TC) <= 18: print "Airborne position (w/ Baro Altitude) " #ALtitude Alt=msg[40:47]+msg[48:52] Alt_decimal = bin2dec(Alt) print "Alt=",int(round((Alt_decimal*25-1000)*0.3046)),'m' ######################################################## VITESSE ############################################################################################################################### if bin2dec(TC) == 19: print "Airborne velocities" Sew=msg[45] Sns=msg[56] print "Sew=",Sew print "Sns=",Sns if Sew == 1: print "Flying East -----> West" else: print "Flying West -----> East" if Sns == 1: print "Flying North -----> South" else: print "Flying South -----> North" #Vitesse East-West Vew=msg[46:56] print "Vew=",Vew Vew_dec=bin2dec(Vew)-1 if Sew==1: print "Vwe=", int(round(-Vew_dec*1.852)) ,"km/h" else: print "Vwe=", int(round(Vew_dec*1.852)) ,"km/h" #Vitesse North - South Vns=msg[57:67] print "Vns=",Vns Vns_dec=bin2dec(Vns)-1 if Sns==1: print "Vsn=", int(round(-Vns_dec*1.852)) ,"km/h" else: print "Vsn=", int(round(Vns_dec*1.852)) ,"km/h" # Vitesse: print "V=", int(round(math.sqrt(Vns_dec*1.852*Vns_dec*1.852+Vew_dec*1.852*Vew_dec*1.852))), "km/h" #Vertical Rate Svr=msg[68] if Svr==1: print "Svr=", Svr, "DOWN, descending..." else: print "Svr=", Svr, "UP, ascending..." Vr=msg[69:78] Vr_dec=bin2dec(Vr)-1 print "Vr=",Vr print "Vr=",int(round(Vr_dec*64*0.3048)),"m/min" ######################################################## AIRBORNE POSITION (w/ GNSS Height) ###################################################################################################### if 20 <= bin2dec(TC) <= 22: print "Les données indiquent: Airborne position (w/ GNSS Height" ######################################################## OTHER USES ###################################################################################################### if 23 <= bin2dec(TC) <= 31: print "Les données indiquent: Reserved for other uses" ########################################################################################################################################################################## #Suppression des fichiers dans adsb os.system('rm {0}/{1}'.format(Chemin_dossier_adsb,fichier[k]))