From dd857bcadc5bbe2d4d33c664390d3375d0769315 Mon Sep 17 00:00:00 2001 From: nzkarit Date: Sat, 9 Sep 2017 00:09:27 +1200 Subject: [PATCH] Adding an options parser and some copyright notes --- ADSB_Encoder.py | 55 ++++++++++++++++++++++-------------------------- Encoder.py | 4 +++- HackRF.py | 4 +++- ModeS.py | 4 +++- ModeSLocation.py | 4 +++- PPM.py | 4 +++- README.md | 47 ++++++++++++++++++++++++++++++++++++----- 7 files changed, 82 insertions(+), 40 deletions(-) diff --git a/ADSB_Encoder.py b/ADSB_Encoder.py index 30b97b7..2ed62ea 100755 --- a/ADSB_Encoder.py +++ b/ADSB_Encoder.py @@ -5,6 +5,7 @@ from HackRF import HackRF from PPM import PPM from ModeS import ModeS from sys import argv, exit +from optparse import OptionParser import os ############################################################### @@ -24,46 +25,40 @@ import os # You should have received a copy of the GNU General Public License # along with this program. If not, see . - +############################################################### +# Further work on fork +# Copyright (C) 2017 David Robinson +def optionParser(): + usage = 'usage: %prog [options]' + parser = OptionParser(usage=usage) + parser.add_option('-i', '--icao', action='store', type='int', dest='icao', default='0xABCDEF', 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. Default: %default') + parser.add_option('--lat', '--latitude', action='store', type='float', dest='latitude', default='12.34', help='Latitude for the plane in decminal degrees. Default: %default') + parser.add_option('--lon', '--long', '--longitude', action='store', type='float', dest='longitude', default='56.78', help='Longitude for the place in decminal degrees. Default: %default') + parser.add_option('-a', '--alt', '--altitude', action='store', type='float', dest='altitude', default='9876.5', help='Altitude in decminal feet. Default: %default') + parser.add_option('--ca', '--capability', action='store', type='int', dest='capability', default=5, help='The capability. (Think this is always 5 from ADSB messages. More info would be appreciate). Default: %default') + parser.add_option('--tc', '--typecode', action='store', type='int', dest='typecode', default=11, help='The type for the ADSB messsage. See https://adsb-decode-guide.readthedocs.io/en/latest/content/introduction.html#ads-b-message-types for more information. Default: %default') + parser.add_option('--ss', '--surveillancestatus', action='store', type='int', dest='surveillancestatus', default=0, help='The surveillance status. (Think this is always 0 from ADSB messages. More info would be appreciate). Default: %default') + parser.add_option('--nicsb', '--nicsupplementb', action='store', type='int', dest='nicsupplementb', default=0, help='The NIC supplement-B.(Think this is always 0 from ADSB messages. More info would be appreciate). Default: %default') + parser.add_option('--time', action='store', type='int', dest='time', default=0, help='The time. (Think this is always 0 from ADSB messages. More info would be appreciate). Default: %default') + parser.add_option('-s', '--surface', action='store', default=False, dest='surface', help='If the plane is on the ground or not. Default: %default') + parser.add_option('-o', '--out', '--output', action='store', type='string', default='Samples_256K.iq8s', dest='outputfilename', help='The iq8s output filename. This is the file which you will feed into the hackRF. Default: %default') + return parser.parse_args() if __name__ == "__main__": - argc = len(argv) - if argc != 5: - print - print 'Usage: '+ argv[0] +' ' - print - print ' Example: '+ argv[0] +' 0xABCDEF 12.34 56.78 9999.0' - print - exit(2) - - icao = int(argv[1], 16) - lat = float(argv[2]) - lon = float(argv[3]) - alt = float(argv[4]) - - ca = 5 # Capability - tc = 11 # Type Code see: https://adsb-decode-guide.readthedocs.io/en/latest/content/introduction.html#ads-b-message-types - ss = 0 # Surveillance status - nicsb = 0 # NIC supplement-B - time = 0 - surface = False + options, arguments = optionParser() + print options modes = ModeS() - (df17_even, df17_odd) = modes.df17_pos_rep_encode(ca, icao, tc, ss, nicsb, alt, time, lat, lon, surface) + (df17_even, df17_odd) = modes.df17_pos_rep_encode(options.capability, options.icao, options.typecode, options.surveillancestatus, options.nicsupplementb, options.altitude, options.time, options.latitude, options.longitude, options.surface) - #print ''.join(format(x, '02x') for x in df17_even) - #print ''.join(format(x, '02x') for x in df17_odd) ppm = PPM() df17_array = ppm.frame_1090es_ppm_modulate(df17_even, df17_odd) - #OutFile = open("filename.bin", "wb") - #OutFile.write(df17_array) - hackrf = HackRF() samples_array = hackrf.hackrf_raw_IQ_format(df17_array) - SamplesFile = open("Samples.iq8s", "wb") # TODO make this a function and take the file name. Also have the option to run dd on it. - # TODO make it empty the file first. + SamplesFile = open('tmp.iq8s', 'wb') SamplesFile.write(samples_array) - os.system("dd if=Samples.iq8s of=Samples_256K.iq8s bs=4k seek=63") # TODO make this a flag, also make it take the file name + os.system("dd if=tmp.iq8s of=%s bs=4k seek=63" % (options.outputfilename)) + os.system('rm tmp.iq8s') diff --git a/Encoder.py b/Encoder.py index 21466c3..162decc 100644 --- a/Encoder.py +++ b/Encoder.py @@ -10,7 +10,9 @@ class Encoder: Manchester encoding and decoding is also included, and by default will use least bit ordering for the byte that is to be included in the array. """ - +############################################################### +# Further work on fork +# Copyright (C) 2017 David Robinson def extract_bit(self, byte, pos): """ Extract a bit from a given byte using MS ordering. diff --git a/HackRF.py b/HackRF.py index 8e97f26..61753d9 100644 --- a/HackRF.py +++ b/HackRF.py @@ -1,5 +1,7 @@ import numpy - +############################################################### +# Further work on fork +# Copyright (C) 2017 David Robinson class HackRF: """The HackRF class has functions from converting data into a format into which the hackrf can process """ diff --git a/ModeS.py b/ModeS.py index 2589add..417f3e0 100644 --- a/ModeS.py +++ b/ModeS.py @@ -1,6 +1,8 @@ from ModeSLocation import ModeSLocation import math - +############################################################### +# Further work on fork +# Copyright (C) 2017 David Robinson class ModeS: """This class handles the ModeS ADSB manipulation """ diff --git a/ModeSLocation.py b/ModeSLocation.py index e87febe..9261af5 100644 --- a/ModeSLocation.py +++ b/ModeSLocation.py @@ -26,7 +26,9 @@ class ModeSLocation: # the Free Software Foundation, Inc., 51 Franklin Street, # Boston, MA 02110-1301, USA. # - +############################################################### +# Further work on fork +# Copyright (C) 2017 David Robinson def encode_alt_modes(self, alt, bit13): mbit = False qbit = True diff --git a/PPM.py b/PPM.py index 6faee71..f3eaad2 100644 --- a/PPM.py +++ b/PPM.py @@ -1,6 +1,8 @@ import numpy from Encoder import Encoder - +############################################################### +# Further work on fork +# Copyright (C) 2017 David Robinson class PPM: """The PPM class contains functions about PPM manipulation """ diff --git a/README.md b/README.md index a1e971a..48e4fd9 100644 --- a/README.md +++ b/README.md @@ -9,12 +9,49 @@ open source "ADS-B In" solutions. One known good example is [Stratux](https://gi The source code is published for academic purpose only. ## Instructions -1. Execute *ADSB_Encoder.py* script with `` `` `` `` arguments: +1. Execute *ADSB_Encoder.py* all the options have defaults so none are needed to generate with defaults. Running help will show you the optiosn you can change: ``` -$ ADSB_Encoder.py 0xABCDEF 12.34 56.78 9999.0 -$ ls Samples.iq8s -Samples.iq8s -$ +$ ADSB_Encoder.py + +$ ADSB_Encoder.py -h +Usage: ADSB_Encoder.py [options] + +Options: + -h, --help show this help message and exit + -i ICAO, --icao=ICAO The ICAO number for the plane in hex. Ensure the ICAO + is prefixed with '0x' to ensure this is parsed as a + hex number. Default: 0xABCDEF + --lat=LATITUDE, --latitude=LATITUDE + Latitude for the plane in decminal degrees. Default: + 12.34 + --lon=LONGITUDE, --long=LONGITUDE, --longitude=LONGITUDE + Longitude for the place in decminal degrees. Default: + 56.78 + -a ALTITUDE, --alt=ALTITUDE, --altitude=ALTITUDE + Altitude in decminal feet. Default: 9876.5 + --ca=CAPABILITY, --capability=CAPABILITY + The capability. (Think this is always 5 from ADSB + messages. More info would be appreciate). Default: 5 + --tc=TYPECODE, --typecode=TYPECODE + The type for the ADSB messsage. See https://adsb- + decode-guide.readthedocs.io/en/latest/content/introduc + tion.html#ads-b-message-types for more information. + Default: 11 + --ss=SURVEILLANCESTATUS, --surveillancestatus=SURVEILLANCESTATUS + The surveillance status. (Think this is always 0 from + ADSB messages. More info would be appreciate). + Default: 0 + --nicsb=NICSUPPLEMENTB, --nicsupplementb=NICSUPPLEMENTB + The NIC supplement-B.(Think this is always 0 from + ADSB messages. More info would be appreciate). + Default: 0 + --time=TIME The time. (Think this is always 0 from ADSB messages. + More info would be appreciate). Default: 0 + -s SURFACE, --surface=SURFACE + If the plane is on the ground or not. Default: False + -o OUTPUTFILENAME, --out=OUTPUTFILENAME, --output=OUTPUTFILENAME + The iq8s output filename. This is the file which you + will feed into the hackRF. Default: Samples_256K.iq8s ``` 2. Transmit the signal into air: ```