Exemplo n.º 1
0
def encodelongFGB(hex_code, latitude, southnorth, longitude, eastwest,
                  suppdata):

    latitude = round(float(latitude) * 1000, 0)
    longitude = round(float(longitude) * 1000, 0)

    c = decodehex2.BeaconFGB()
    try:
        c.processHex(str(hex_code.strip()))

        if c.protocolflag() == 'User':
            binstr = c.bin[0:25] + '1' + c.bin[26:86]

            bch1 = calcbch(binstr, "1001101101100111100011", 25, 86, 107)
            binstr = binstr + bch1 + suppdata

            binstr = binstr + str(southnorth) + dec2bin(int(float(latitude/1000)),7) + \
                     dec2bin( round(( float(latitude/1000) - int(float(latitude/1000))) * 15,0) ,4) + str(eastwest) + \
                     dec2bin(int(float(longitude / 1000)), 8) + \
                     dec2bin(round((float(longitude / 1000) - int(float(longitude / 1000))) * 15, 0), 4)
            bch2 = calcbch(binstr, '1010100111001', 107, 133, 145)
            binstr = binstr + bch2

        elif c.protocolflag() == 'Location' and c.loctype() in [
                'Standard Location', 'Standard Location Protocol - Test'
        ]:
            bincoord = stdloc(latitude, longitude)
            binstr = c.bin[0:25] + '1' + c.bin[26:65] + str(
                southnorth) + bincoord[0] + str(eastwest) + bincoord[1]
            bch1 = calcbch(binstr, "1001101101100111100011", 25, 86, 107)
            binstr = binstr + bch1 + suppdata + bincoord[2] + bincoord[3]
            bch2 = calcbch(binstr, '1010100111001', 107, 133, 145)
            binstr = binstr + bch2

        elif c.protocolflag() == 'Location' and c.loctype() in [
                'ELT-DT Location', 'RLS Location'
        ]:
            bincoord = eltdt_rls(latitude, longitude)
            binstr = c.bin[0:25] + '1' + c.bin[26:67] + str(
                southnorth) + bincoord[0] + str(eastwest) + bincoord[1]
            bch1 = calcbch(binstr, "1001101101100111100011", 25, 86, 107)
            binstr = binstr + bch1 + suppdata + bincoord[2] + bincoord[3]
            bch2 = calcbch(binstr, '1010100111001', 107, 133, 145)
            binstr = binstr + bch2

        elif c.protocolflag() == 'Location' and c.loctype(
        ) == 'National Location':
            bincoord = natloc(latitude, longitude)
            binstr = c.bin[0:25] + '1' + c.bin[26:59] + str(
                southnorth) + bincoord[0] + str(eastwest) + bincoord[1]
            bch1 = calcbch(binstr, "1001101101100111100011", 25, 86, 107)
            binstr = binstr + bch1 + suppdata + bincoord[2] + bincoord[
                3] + '000000'
            bch2 = calcbch(binstr, '1010100111001', 107, 133, 145)
            binstr = binstr + bch2

        return bin2hex(binstr[1:])

    except decodehex2.HexError as e:
        print(e.value, e.message)
Exemplo n.º 2
0
def longfirstgen():
    hexcodeUIN = str(request.args.get('hex_code'))
    error = None
    beacon = decodehex2.BeaconFGB(hexcodeUIN)
    ptype = beacon.loctype()
    if ptype == 'National User':
        return redirect(url_for('decoded', hexcode=hexcodeUIN + '0' * 15))

    if beacon.protocolflag() == 'User':
        ptype = 'User'

    forms = {
        'User': FirstGenForm(request.form),
        'Standard Location': FirstGenStd(request.form),
        'National Location': FirstGenStd(request.form),
        'RLS Location': FirstGenRLS(request.form),
        'ELT-DT Location': FirstGenELTDT(request.form)
    }
    form = forms[ptype]

    if request.method == 'POST' and form.validate():

        lat = request.form['latitude']
        latdir = request.form['northsouth']
        long = request.form['longitude']
        longdir = request.form['eastwest']
        if ptype == 'User':
            suppdata = request.form['encodepos']

        elif ptype in ['Standard Location', 'National Location']:
            suppdata = '1101' + request.form['encodepos'] + request.form[
                'auxdevice']
        elif ptype == 'RLS Location':
            suppdata = request.form['encodepos'] + \
                       request.form['auxdevice'] + \
                       request.form['rlmtypeone'] + \
                       request.form['rlmtypetwo'] + \
                       request.form['feedbacktype1'] + \
                       request.form['feedbacktype2'] + \
                       request.form['rlsprovider']
        elif ptype == 'ELT-DT Location':
            suppdata = request.form['meansactivation'] + request.form[
                'encodedaltitude']
            if form.data.get('freshness') == True:
                suppdata = suppdata + '11'
            else:
                suppdata = suppdata + '00'

        hexcodelong = encodelongFGB(hexcodeUIN, lat, latdir, long, longdir,
                                    suppdata)
        print('hex', hexcodelong)
        return redirect(url_for('decoded', hexcode=hexcodelong))

    return render_template('encodelongfirstentryform.html',
                           hexcode=hexcodeUIN,
                           ptype=ptype,
                           form=form,
                           error=error)
Exemplo n.º 3
0
def longfirstgen():
    hexcodeUIN = str(request.args.get('hex_code'))
    error = None
    beacon = decodehex2.BeaconFGB(hexcodeUIN)
    ptype = beacon.loctype()
    print(ptype)

    if ptype == 'National User':
        hexcodelong = encodelongFGB(hexcodeUIN, '')
        return redirect(url_for('decoded', hexcode=hexcodelong))

    if beacon.protocolflag() == 'User':
        ptype = 'User'
    print(ptype)
    forms = {
        'User': (FirstGenForm(request.form), 'encodelongfirstentryform.html'),
        'Standard Location': (FirstGenStd(request.form),
                              'encodelongfirstentryform.html'),
        'Location: Standard Location Protocol - ELT (Serial)':
        (FirstGenStd(request.form), 'encodelongfirstentryform.html'),
        'Standard Location Protocol - Test': (FirstGenStd(request.form),
                                              'encodelongfirstentryform.html'),
        'Standard Location Protocol - PLB (Serial)':
        (FirstGenStd(request.form), 'encodelongfirstentryform.html'),
        'Standard Location Protocol - EPIRB (Serial)':
        (FirstGenStd(request.form), 'encodelongfirstentryform.html'),
        'Std Loc. Serial ELT - Aircraft Operator Designator Protocol':
        (FirstGenStd(request.form), 'encodelongfirstentryform.html'),
        'National Location': (FirstGenNatLoc(request.form),
                              'encodelongNATLOC.html'),
        definitions.RLS_LOC: (FirstGenRLS(request.form),
                              'encodelongfirstRLS.html'),
        definitions.ELT_DT_LOC: (FirstGenELTDT(request.form),
                                 'encodelongELTDT.html')
    }
    form = forms[ptype][0]

    renderform = forms[ptype][1]

    if request.method == 'POST' and form.validate():

        hexcodelong = encodelongFGB(hexcodeUIN, request.form)

        return redirect(url_for('decoded', hexcode=hexcodelong))

    return render_template(renderform,
                           hexcode=hexcodeUIN,
                           ptype=ptype,
                           form=form,
                           error=error,
                           showmenu=MENU)
Exemplo n.º 4
0
            b = '0'
        else:
            b = '1'

        binstr = binstr + b
    return binstr


preamble = '000000000000000000101111'

short_long = '1'
user_location = '1'
countrycode = '0100111100'  #316 - Canada

for n in range(10000):

    ident = randombinary(49)
    pdf1 = preamble + short_long + user_location + countrycode + ident
    bch1 = Fcn.calcbch(('_' + pdf1 + '0' * 59), "1001101101100111100011", 25,
                       86, 107)
    newbin = pdf1 + bch1
    supdata = randombinary(26)
    bch2 = Fcn.calcbch('_' + newbin + supdata + '0' * 12, '1010100111001', 107,
                       133, 145)
    finalbin = newbin + supdata + bch2
    # print(Fcn.bin2hex(finalbin))
    hexcheck = Fcn.bin2hex(finalbin)
    if decodehex2.BeaconFGB(hexcheck).errors == []:
        decoded.write(hexcheck + '\n')
decoded.close()
Exemplo n.º 5
0
def encodelongFGB(hex_code, formdata):
    for e in formdata:
        print('form control' , e, formdata[e])


    c = decodehex2.BeaconFGB()
    pad24='1'*16 +'000101111'
    try:
        c.processHex(str(hex_code.strip()))
        if c.loctype()!='National User':
            latitude = round(float(formdata['latitude']) * 1000, 0)
            longitude = round(float(formdata['longitude']) * 1000, 0)
            southnorth = formdata['northsouth']
            eastwest = formdata['eastwest']

        if c.protocolflag() == 'User' and c.loctype()!='National User':
            suppdata= formdata['encodepos']
            binstr = pad24 + '1' + c.bin[26:86]

            bch1 = calcbch(binstr, "1001101101100111100011", 25, 86, 107)
            binstr = binstr  + bch1 + suppdata

            binstr = binstr + str(southnorth) + dec2bin(int(float(latitude/1000)),7) + \
                     dec2bin( round(( float(latitude/1000) - int(float(latitude/1000))) * 15,0) ,4) + str(eastwest) + \
                     dec2bin(int(float(longitude / 1000)), 8) + \
                     dec2bin(round((float(longitude / 1000) - int(float(longitude / 1000))) * 15, 0), 4)
            bch2 = calcbch(binstr, '1010100111001', 107, 133, 145)
            binstr = binstr + bch2

        elif c.loctype() == 'National User':
            binstr = '_'+ '1'*15 + '000101111' + '1'  + c.bin[26:86]
            bch1 = calcbch(binstr, "1001101101100111100011", 25, 86, 107)
            binstr = binstr + bch1 +'0' *26
            bch2 = calcbch(binstr, '1010100111001', 107, 133, 145)
            binstr = binstr + bch2


        elif c.protocolflag() == 'Location' and c.loctype()  in \
                ['Location: Standard Location Protocol - ELT (Serial)','Standard Location','Standard Location Protocol - Test','Standard Location Protocol - PLB (Serial)','Standard Location Protocol - EPIRB (Serial)','Std Loc. Serial ELT - Aircraft Operator Designator Protocol']:
            bincoord = stdloc(latitude, longitude)
            suppdata = '1101' + formdata['encodepos'] + formdata['auxdevice']
            binstr = pad24 + '1' + c.bin[26:65] + str(southnorth) + bincoord[0] + str(eastwest) + bincoord[1]
            bch1 = calcbch(binstr, "1001101101100111100011", 25, 86, 107)
            binstr = binstr + bch1 + suppdata + bincoord[2] + bincoord[3]
            bch2 = calcbch(binstr, '1010100111001', 107, 133, 145)
            binstr = binstr + bch2



        elif c.protocolflag() == 'Location' and c.loctype() == 'RLS Location Protocol':
            # bit 115=132 are 18 bit location offset

            suppdata = formdata['encodepos'] + \
                        formdata['auxdevice'] + \
                        formdata['rlmtypeone'] + \
                        formdata['rlmtypetwo'] + \
                        formdata['feedbacktype1'] + \
                        formdata['feedbacktype2'] + \
                        formdata['rlsprovider']



            bincoord = eltdt_rls(latitude, longitude)
            binstr = pad24 + '1' + c.bin[26:67] + str(southnorth) + bincoord[0] + str(eastwest) + bincoord[1]
            bch1 = calcbch(binstr, "1001101101100111100011", 25, 86, 107)
            binstr = binstr + bch1 + suppdata + bincoord[2] + bincoord[3]
            bch2 = calcbch(binstr, '1010100111001', 107, 133, 145)
            binstr = binstr + bch2

        elif c.protocolflag() == 'Location' and c.loctype() == definitions.ELT_DT_LOC:
            suppdata = formdata['meansactivation'] + formdata['encodedaltitude'] + formdata['freshness']
            aircraft3letter = formdata['aircraft_3ld']
            if suppdata[-2:] != '00':
                # bit 115=132 are 18 bit location offset

                bincoord= eltdt_rls(latitude, longitude)
                binstr ='_'+ '1'*15 + '000101111' + '1' + c.bin[26:67] + str(southnorth) + bincoord[0] + str(eastwest) + bincoord[1]
                bch1 = calcbch(binstr, "1001101101100111100011", 25, 86, 107)
                binstr = binstr + bch1 + suppdata + bincoord[2] + bincoord[3]
                bch2 = calcbch(binstr, '1010100111001', 107, 133, 145)
                binstr = binstr + bch2

            else:
                # bits 115-132 are aircraft 3 letter designators 000 and 3 segments of 5 bit modified baudot for each letter designator
                bincoord = eltdt_rls(latitude, longitude)
                binstr = '_' + '1'*15 + '000101111' + '1' + c.bin[26:67] + str(southnorth) + bincoord[0] + str(eastwest) +   bincoord[1]
                bch1 = calcbch(binstr, "1001101101100111100011", 25, 86, 107)
                aircraft3letterbin=''
                for letter in aircraft3letter.strip():
                    try:
                        key = next(key for key, value in definitions.baudot.items() if value == letter.upper())
                    except StopIteration:
                        key = '111111'
                    key = key[1:]
                    aircraft3letterbin = aircraft3letterbin + key
                aircraft3letterbin = aircraft3letterbin + '11111' * (3 - len(aircraft3letter.strip()))
                binstr = binstr + bch1 + suppdata + '000' +  aircraft3letterbin
                bch2 = calcbch(binstr, '1010100111001', 107, 133, 145)
                binstr = binstr + bch2

        elif c.protocolflag() == 'Location' and c.loctype() == 'National Location':
            bincoord= natloc(latitude, longitude)
            suppdata = '110' + formdata['nationalassign']+ formdata['encodepos'] + formdata['auxdevice']
            binstr = pad24 + '1' + c.bin[26:59] + str(southnorth) + bincoord[0] + str(eastwest) + bincoord[1]
            bch1 = calcbch(binstr, "1001101101100111100011", 25, 86, 107)
            if formdata['nationalassign'] == '0':
                refine = '0'*14
            else:
                refine =  bincoord[2] + bincoord[3]
            binstr = binstr + bch1 + suppdata + refine + '000000'
            bch2 = calcbch(binstr, '1010100111001', 107, 133, 145)
            binstr = binstr + bch2

        return bin2hex(binstr[1:])

    except decodehex2.HexError as e:
        print(e.value, e.message)
Exemplo n.º 6
0
    serialuser = '******'
    eltdt ='2792E26E3DBFDFF'
    std = '4CAB4C48F6FFBFF'
    rls='279A8180103FDFF'
    nat ='A79000000000000'
    nat_loc='27942D56BF81FE0'
    hex_code = std
    #suppdat='11111110'
    suppdat = '110111'
    latitude = randint(0, 89999)
    longitude = randint(0, 179999)
    southnorth = randint(0, 1)
    eastwest = randint(0, 1)
    tsouthnorth = ('North', 'South')[southnorth]
    teastwest = ('East', 'West')[eastwest]


    longhex=encodelongFGB(hex_code,latitude/1000,southnorth,longitude/1000,eastwest,suppdat)

    c = decodehex2.BeaconFGB(longhex)

    newline = '\n{l} {beacon}\n{sn} {deglat}-{ew} {deglong}. \nHex: {longh} {m}.\n15 Hex:{h15}:{test}\n'.format(
        m=c.type, l=c.loctype(), sn=tsouthnorth, ew=teastwest, deglat=latitude / 1000,
        deglong=longitude / 1000, longh=longhex, h15=c.hex15, oldh=hex_code, test=c.hex15 == hex_code.upper(),
        beacon=c.btype())

    print(newline)
    print(c.protocoldata() + '\n')
    print(c.countrydetail.countrydata() + '\n')
    print('{bch1}\n{bch2}\n'.format(mtype=c.type, bch1=c.bch.writebch1(), bch2=c.bch.writebch2()))
Exemplo n.º 7
0
    def run(self):
        count = 0
        thefile = open(self.filename, 'rb')
        while 1:
            buffer = thefile.read(8192 * 1024)
            if not buffer: break
            count += buffer.count('\n')
        thefile.close()
        hexcodes = open(self.filename)
        decoded = open(self.filesave, 'w')

        i = 0
        decoded.write(
            """Input Message,Message Type,Self Test,Self Test,15 Hex ID,BCH-2 match,Protocol Type,Test Beacon,Beacon Type,TAC,Country Code,Country Name,Message protocol,Position Source,Course Lat,Course Long,Final Lat,Final Long,Fixed Bits\n"""
        )

        for line in hexcodes.readlines():
            i += 1
            #print i, count, i/float(count),i/float(count)*100
            self.emit(SIGNAL('EXPORT'), i / float(count) * 100)
            line = str(line.strip())
            decoded.write('{h},'.format(h=str(line)))
            try:
                c = decodehex2.Beacon(str(line))
                if c.gentype == 'first':
                    c = decodehex2.BeaconFGB(str(line))
                    if str(c.location[0]).find('Error') != -1:
                        finallat = courselat = 'error'
                    elif str(c.location[0]).find('Default') != -1:
                        finallat = courselat = 'default'
                    else:
                        finallat = c.location[0]
                        courselat = c.courseloc[0]
                    if str(c.location[1]).find('Error') != -1:
                        finallong = courselong = 'error'
                    elif str(c.location[1]).find('Default') != -1:
                        finallong = courselong = 'default'
                    else:
                        finallong = c.location[1]
                        courselong = c.courseloc[1]

                    selftest = c.testmsg()
                    if 'Self-test' in selftest:
                        s = 'True'
                    else:
                        s = 'False'
                    decoded.write('{},'.format(c.getmtype()))
                    decoded.write('{},'.format(s))
                    decoded.write('{},'.format(selftest))
                    decoded.write('{},'.format(c.hexuin()))
                    decoded.write('{},'.format(c.bch2match()))
                    decoded.write('{},'.format(c.protocolflag()))
                    btype = c.btype()
                    if 'Test' in btype:
                        t = 'True'
                    else:
                        t = 'False'
                    decoded.write('{},'.format(t))
                    decoded.write('{},'.format(btype))

                    decoded.write('{},'.format(c.gettac()))
                    decoded.write('{},'.format(c.get_mid()))
                    decoded.write('{},'.format(c.get_country()))
                    decoded.write('{},'.format(c.loctype()))
                    decoded.write('{},'.format(c.getencpos()))
                    decoded.write('{},'.format(courselat))
                    decoded.write('{},'.format(courselong))
                    decoded.write('{},'.format(finallat))
                    decoded.write('{},'.format(finallong))
                    decoded.write('{},'.format(c.fbits()))
                else:
                    decoded.write('Not an FGB long message')

            except decodehex2.HexError as e:

                decoded.write(e.value)

            decoded.write('\n')

        decoded.close()
        self.emit(SIGNAL('EXPORT'), 100)