Adding an options parser and some copyright notes

This commit is contained in:
nzkarit
2017-09-09 00:09:27 +12:00
parent 0fbe579dfe
commit dd857bcadc
7 changed files with 82 additions and 40 deletions

View File

@@ -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 <http://www.gnu.org/licenses/>.
###############################################################
# 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] +' <ICAO> <Latitude> <Longtitude> <Altitude>'
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')