Adding a pause between message pairs. Currently set to make one pair a second

master
nzkarit 6 years ago
parent 6a9cf210bb
commit 46a3ca9dd2

@ -60,11 +60,9 @@ def argParser():
parser.add_argument('-s', '--surface', action='store', default=cfg.getboolean('plane', 'surface'), type=auto_bool, dest='surface', help='If the plane is on the ground or not. Default: %(default)s') parser.add_argument('-s', '--surface', action='store', default=cfg.getboolean('plane', 'surface'), type=auto_bool, dest='surface', help='If the plane is on the ground or not. Default: %(default)s')
parser.add_argument('-o', '--out', '--output', action='store', type=str, default=cfg.get('general', 'outputfilename'), dest='outputfilename', help='The iq8s output filename. This is the file which you will feed into the hackRF. Default: %(default)s') parser.add_argument('-o', '--out', '--output', action='store', type=str, default=cfg.get('general', 'outputfilename'), dest='outputfilename', help='The iq8s output filename. This is the file which you will feed into the hackRF. Default: %(default)s')
parser.add_argument('-r', '--repeats', action='store', dest='repeats', type=int, default=cfg.getint('general', 'repeats'), help='How many repeats of the data to perform. Default: %(default)s') parser.add_argument('-r', '--repeats', action='store', dest='repeats', type=int, default=cfg.getint('general', 'repeats'), help='How many repeats of the data to perform. Default: %(default)s')
parser.add_argument('--csv', '--csvfile', '--in', '--input', action='store', type=str, default=cfg.get('general', 'csvfile'), dest='csvfile', help='Import a CSV file with the plane data in it. Default: %(default)s') parser.add_argument('--csv', '--csvfile', '--in', '--input', action='store', type=str, default=cfg.get('general', 'csvfile'), dest='csvfile', help='Import a CSV file with the plane data in it. Default: %(default)s')
parser.add_argument('--intermessagegap', action='store', type=int, default=cfg.get('general', 'intermessagegap'), dest='intermessagegap', help='When repeating or reading a CSV the number of microseconds between messages. Default: %(default)s')
# TODO Make it so it can do a static checksum # TODO Make it so it can do a static checksum
# TODO Get pause between messages
# TODO Get pause between repeats
# TODO Do a pause function
return parser.parse_args() return parser.parse_args()
def singlePlane(arguments): def singlePlane(arguments):
@ -81,16 +79,19 @@ def singlePlane(arguments):
hackrf = HackRF() hackrf = HackRF()
samples_array = hackrf.hackrf_raw_IQ_format(df17_array) samples_array = hackrf.hackrf_raw_IQ_format(df17_array)
samples = samples+samples_array samples = samples+samples_array
gap_array = ppm.addGap(arguments.intermessagegap)
samples_array = hackrf.hackrf_raw_IQ_format(gap_array)
samples = samples+samples_array
return samples return samples
def manyPlanes(arguments): def manyPlanes(arguments):
logger.info('Processing CSV file: %s' % (arguments.csvfile)) logger.info('Processing CSV file: %s' % (arguments.csvfile))
samples = bytearray() samples = bytearray()
logger.info('Repeating the message %s times' % (arguments.repeats)) logger.info('Repeating the message %s times' % (arguments.repeats))
for i in range(0, arguments.repeats): for i in range(0, arguments.repeats):
with open(arguments.csvfile, newline='') as csvfile: with open(arguments.csvfile, newline='') as csvfile:
reader = csv.DictReader(csvfile, delimiter=',') reader = csv.DictReader(csvfile, delimiter=',')
for row in reader: for row in reader:
if not 'icao' in row.keys(): if not 'icao' in row.keys():
row['icao'] = arguments.icao row['icao'] = arguments.icao
else: else:
@ -129,6 +130,9 @@ def manyPlanes(arguments):
hackrf = HackRF() hackrf = HackRF()
samples_array = hackrf.hackrf_raw_IQ_format(df17_array) samples_array = hackrf.hackrf_raw_IQ_format(df17_array)
samples = samples+samples_array samples = samples+samples_array
gap_array = ppm.addGap(arguments.intermessagegap)
samples_array = hackrf.hackrf_raw_IQ_format(gap_array)
samples = samples+samples_array
return samples return samples
def writeOutputFile(filename, data): def writeOutputFile(filename, data):
@ -138,11 +142,11 @@ def writeOutputFile(filename, data):
SamplesFile.write(data) SamplesFile.write(data)
SamplesFile.close() SamplesFile.close()
os.system('sync') os.system('sync')
os.system('rm %s' % (filename)) os.system('rm %s' % (filename))
logger.info('dd for file: %s' % (filename)) logger.info('dd for file: %s' % (filename))
os.system("dd if=%s of=%s bs=4k seek=63 > /dev/null 2>&1" % (tmpfile, filename)) os.system("dd if=%s of=%s bs=4k seek=63 > /dev/null 2>&1" % (tmpfile, filename))
os.system('sync') os.system('sync')
os.system('rm %s'%(tmpfile)) os.system('rm %s'%(tmpfile))
def main(): def main():
global cfg global cfg
@ -188,6 +192,3 @@ def threadingCSV(csv):
if __name__ == "__main__": if __name__ == "__main__":
main() main()

@ -1,57 +1,57 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# #
# Will take a FR24 CSV and make a ADSB_Encoder CSV # Will take a FR24 CSV and make a ADSB_Encoder CSV
import csv import csv
import os import os
import argparse import argparse
import configparser import configparser
def auto_int(x): def auto_int(x):
"""Parses HEX into for argParser""" """Parses HEX into for argParser"""
return int(x, 0) return int(x, 0)
def argParser(): def argParser():
description = 'This script will take a FR24 CSV file and convert it into a format for FR24csv.py' description = 'This script will take a FR24 CSV file and convert it into a format for FR24csv.py'
parser = argparse.ArgumentParser(description=description) parser = argparse.ArgumentParser(description=description)
parser.add_argument('-i', '--icao', action='store', type=auto_int, dest='icao', default=cfg.get('plane', 'icao'), help='The ICAO number for the plane in hex. Ensure the ICAO is prefixed with \'0x\' to ensure this is parsed as a hex number. This is 24 bits long. Default: %(default)s') parser.add_argument('-i', '--icao', action='store', type=auto_int, dest='icao', default=cfg.get('plane', 'icao'), help='The ICAO number for the plane in hex. Ensure the ICAO is prefixed with \'0x\' to ensure this is parsed as a hex number. This is 24 bits long. Default: %(default)s')
parser.add_argument('--csv', '--csvfile', '--in', '--input', action='store', type=str, dest='csvfile', help='The name of the FR24 CSV file', required=True) parser.add_argument('--csv', '--csvfile', '--in', '--input', action='store', type=str, dest='csvfile', help='The name of the FR24 CSV file', required=True)
return parser.parse_args() return parser.parse_args()
def reverseCSV(csvfile): def reverseCSV(csvfile):
"""Reverse a CSV. Returns a dictionary of the CSV""" """Reverse a CSV. Returns a dictionary of the CSV"""
data = [] data = []
with open(csvfile, newline='') as csvfilein: with open(csvfile, newline='') as csvfilein:
reader = csv.DictReader(csvfilein, delimiter=',') reader = csv.DictReader(csvfilein, delimiter=',')
for row in reader: for row in reader:
data.append(row) data.append(row)
csvfilein.close() csvfilein.close()
return reversed(data) return reversed(data)
def main(): def main():
global cfg global cfg
cfg = configparser.ConfigParser() cfg = configparser.ConfigParser()
cfg.read('config.cfg') cfg.read('config.cfg')
arguments = argParser() arguments = argParser()
csvFilename = 'fr24.csv' csvFilename = 'fr24.csv'
time = 0 time = 0
#Need to reverse the FR24 CSV as it is in reverse order i.e. the most recent record is row 2 and the first ADS-B message of the flight is the last row in the CSV #Need to reverse the FR24 CSV as it is in reverse order i.e. the most recent record is row 2 and the first ADS-B message of the flight is the last row in the CSV
data = reverseCSV(arguments.csvfile) data = reverseCSV(arguments.csvfile)
with open(csvFilename, 'w', newline='') as csvfileout: with open(csvFilename, 'w', newline='') as csvfileout:
fieldnames = ['timestamp', 'icao', 'latitude', 'longitude', 'altitude'] fieldnames = ['timestamp', 'icao', 'latitude', 'longitude', 'altitude']
output = csv.DictWriter(csvfileout, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL, fieldnames=fieldnames) output = csv.DictWriter(csvfileout, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL, fieldnames=fieldnames)
output.writeheader() output.writeheader()
for row in data: for row in data:
if time == 0: if time == 0:
time = int(row['Timestamp']) time = int(row['Timestamp'])
rowtime = int(row['Timestamp']) - time rowtime = int(row['Timestamp']) - time
position = row['Position'].split(',') position = row['Position'].split(',')
newrow = {'timestamp':rowtime, 'icao':hex(arguments.icao), 'latitude':position[0], 'longitude':position[1], 'altitude':row['Altitude']} newrow = {'timestamp':rowtime, 'icao':hex(arguments.icao), 'latitude':position[0], 'longitude':position[1], 'altitude':row['Altitude']}
output.writerow(newrow) output.writerow(newrow)
csvfileout.close() csvfileout.close()
if __name__ == "__main__": if __name__ == "__main__":
main() main()

@ -46,3 +46,16 @@ class PPM:
#print '[{}]'.format(', '.join(hex(x) for x in ppm)) #print '[{}]'.format(', '.join(hex(x) for x in ppm))
return bytearray(ppm) return bytearray(ppm)
def addGap(self, gap):
"""
This function will add dead air as a gap between messages
Args:
gap: The number of microseconds to have as a gap
Returns:
The bytearray of the PPM data
"""
ppm = [ ]
for i in range(gap): # pause
ppm.append( 0 )
return bytearray(ppm)

@ -1,7 +1,9 @@
[general] [general]
outputfilename = Samples_256K.iq8s outputfilename = Samples_256K.iq8s
repeats = 1 repeats = 1
csvfile = csvfile =
# Currently in PPM.py one message is 48 dead air, 8 preamble, 112 message, 100 dead air, 8 preamble, 112 message, 48 dead air leaves us with 99564 microseconds to make a second
intermessagegap = 99564
[plane] [plane]
icao = 0x75008F icao = 0x75008F

Loading…
Cancel
Save