From ac8082328501b0edc7d6fd4211d8d267dbdf9890 Mon Sep 17 00:00:00 2001 From: nzkarit Date: Sun, 6 May 2018 21:21:19 +1200 Subject: [PATCH] WOrk on >50175 feet altitudes and generating all altitudes --- .gitignore | 2 ++ ADSB_Encoder.py | 2 +- ModeS.py | 2 +- ModeSLocation.py | 11 ++++++- generateAllAlt.py | 79 +++++++++++++++++++++++++++++++++++++++++++++++ generateAllLat.py | 1 - 6 files changed, 93 insertions(+), 4 deletions(-) create mode 100755 generateAllAlt.py diff --git a/.gitignore b/.gitignore index 7e6a5b1..5fdf849 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ allICAO.py hackRFAllICAO.sh allLat.py hackRFAllLat.sh +allAlt.py +hackRFAllAlt.sh diff --git a/ADSB_Encoder.py b/ADSB_Encoder.py index 7e1e12a..637f295 100755 --- a/ADSB_Encoder.py +++ b/ADSB_Encoder.py @@ -56,7 +56,7 @@ def argParser(): parser.add_argument('--tc', '--typecode', action='store', type=int, dest='typecode', default=cfg.getint('plane', 'typecode'), help='The type for the ADS-B message. 11 is an air position message. See https://adsb-decode-guide.readthedocs.io/en/latest/content/introduction.html#ads-b-message-types for more information. 5 bits. Default: %(default)s') parser.add_argument('--ss', '--surveillancestatus', action='store', type=int, dest='surveillancestatus', default=cfg.getint('plane', 'surveillancestatus'), help='The surveillance status. (Think this is always 0 from ADS-B messages. More info would be appreciated). Default: %(default)s') parser.add_argument('--nicsb', '--nicsupplementb', action='store', type=int, dest='nicsupplementb', default=cfg.getint('plane', 'nicsupplementb'), help='The NIC supplement-B.(Think this is always 0 from ADS-B messages. More info would be appreciated). Default: %(default)s') - parser.add_argument('--time', action='store', type=int, dest='time', default=cfg.getint('plane', 'time'), help='The time. (Think this is always 0 from ADS-B messages. More info would be appreciated). Default: %(default)s') + parser.add_argument('--time', action='store', type=int, dest='time', default=cfg.getint('plane', 'time'), help='0 indicates the time is not synchronous with UTC. 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('-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') diff --git a/ModeS.py b/ModeS.py index 417f3e0..da5250d 100644 --- a/ModeS.py +++ b/ModeS.py @@ -17,7 +17,7 @@ class ModeS: location = ModeSLocation() enc_alt = location.encode_alt_modes(alt, surface) #print "Alt(%r): %X " % (surface, enc_alt) - + #encode that position (evenenclat, evenenclon) = location.cpr_encode(lat, lon, False, surface) (oddenclat, oddenclon) = location.cpr_encode(lat, lon, True, surface) diff --git a/ModeSLocation.py b/ModeSLocation.py index 93717fc..f954b49 100644 --- a/ModeSLocation.py +++ b/ModeSLocation.py @@ -30,9 +30,18 @@ class ModeSLocation: # Further work on fork # Copyright (C) 2017 David Robinson def encode_alt_modes(self, alt, bit13): + # need to better understand as the >50175 feet not working + # TODO >50175 feet mbit = False qbit = True - encalt = int((int(alt) + 1000) / 25) + # For altitudes -1000<=X<=50175 feet, set bit 8 AKA the Q bit to true which means 25 feet resoulution + # For >50175 set the qbit to False and use 100 feet resoultion + if alt > 50175: + qbit = False + encalt = int((int(alt) + 1000) / 100) + else: + qbit = True + encalt = int((int(alt) + 1000) / 25) if bit13 is True: tmp1 = (encalt & 0xfe0) << 2 diff --git a/generateAllAlt.py b/generateAllAlt.py new file mode 100755 index 0000000..678d935 --- /dev/null +++ b/generateAllAlt.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python3 +# +# Will generate a CSV with all Latitudes +import csv +import os + +def writeFile(directory, filename, filenameExtension, data, count): + csvFilename = os.path.join(directory, "%s-%s.%s"%(filename, count, filenameExtension)) + with open(csvFilename, 'w', newline='') as csvfile: + output = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) + output.writerow(['altitude']) + for row in data: + output.writerow([row]) + csvfile.close() + return "{'csv':'%s', 'out':'%s-%s.iq8s'},"%(csvFilename, filename, count) + +def main(): + directory = 'generated' + filename = 'allAlt' + filenameExtension = 'csv' + scriptFilename = 'allAlt.py' + hackRFScriptFilename = 'hackRFAllAlt.sh' + + minAlt = -1100 + maxAlt = 100000 + splitNumber = 1000 + step = 1 + + try: + os.stat(directory) + except: + os.mkdir(directory) + + script = open(scriptFilename, 'w') + script.write('#!/usr/bin/env python3\n') + script.write('import time\n') + script.write('import threading\n') + script.write('from ADSB_Encoder import *\n') + + hackRFScript = open(hackRFScriptFilename, 'w') + hackRFScript.write('#!/bin/bash\n') + + + i = minAlt + j = 0 + k = 0 + data = [] + + files = '' + while i <= maxAlt: + if j == splitNumber: + files += writeFile(directory, filename, filenameExtension, data, k) + data = [] + hackRFScript.write("hackrf_transfer -t %s-%s.iq8s -f 915000000 -s 2000000 -x 10\n" % (filename, k)) + k += 1 + j = 0 + data.append(i) + i += step + j += 1 + files += writeFile(directory, filename, filenameExtension, data, k) + data = [] + hackRFScript.write("hackrf_transfer -t %s-%s.iq8s -f 915000000 -s 2000000 -x 10\n" % (filename, k)) + k += 1 + j = 0 + files = files[:-1] + script.write('files = [%s]\n' % (files)) + script.write('for file in files:\n') + script.write(' t = threading.Thread(target=threadingCSV, args=(file,))\n') + script.write(' t.start()\n') + script.write(' print(file)\n') + script.write(' time.sleep(1)\n') + script.close() + hackRFScript.close() + +if __name__ == "__main__": + main() + + + diff --git a/generateAllLat.py b/generateAllLat.py index 7865e4c..adbc968 100755 --- a/generateAllLat.py +++ b/generateAllLat.py @@ -23,7 +23,6 @@ def main(): minLat = -90 maxLat = 90 - # If the number of lat is less than the split it doesn't work splitNumber = 1000 step = 0.1