def on_hexLineEdit_textChanged(self): c = self.hexLineEdit.cursorPosition() t = unicode(self.hexLineEdit.text()).upper() self.hexLineEdit.setText(t) self.hexLineEdit.setCursorPosition(c) self.hexLineEdit.setSelection(c, 1) hexcode = unicode(self.hexLineEdit.text()) self._lasthex = hexcode if len(hexcode) == 63 or len(hexcode) == 51 or len(hexcode) == 75 or len(hexcode)==23: self._beacon = Gen2.SecondGen(hexcode) else: self._beacon = decodehex2.BeaconHex() try: self._beacon.processHex(hexcode) ctry = self._beacon.country() mid = unicode(ctry[0][1]) name = unicode(ctry[1][1]) self.tableWidget.clear() for n, lrow in enumerate(self._beacon.tablebin): for m, item in enumerate(lrow): newitem = QTableWidgetItem(item) newitem.setFlags(Qt.ItemIsEnabled) self.tableWidget.setItem(n, m, newitem) self.tableWidget.setHorizontalHeaderLabels(['Bit range', 'Bit value', 'Name', 'Decoded']) self.tableWidget.resizeColumnsToContents() self.tableWidget.resizeRowsToContents() except Gen2.Gen2Error as e: self.tableWidget.clear() qb = QMessageBox.critical(self, e.value, e.message) except decodehex2.HexError as e: self.tableWidget.clear() qb = QMessageBox.critical(self, e.value, e.message) finally: pass
def output(): ## output will only process if hexcode has been validated. outputdata = "dummy" if request.method == 'GET': hexcode = str(request.args.get('hexcode')) username = str(request.args.get('username')) if len(hexcode) == 63 or len(hexcode) == 51 or len( hexcode) == 75 or len(hexcode) == 23: beacon = Gen2.SecondGen(hexcode) else: beacon = decodehex2.BeaconHex(hexcode) print(hexcode) beacon.processHex(hexcode) ctry = beacon.country() mid = str(ctry[0][1]) name = str(ctry[1][1]) print(name) decoded = beacon.tablebin return render_template('output.html', hexcode=hexcode, decoded=decoded) else: return render_template('child.html', title='Home', user="")
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() print count hexcodes = open(self.filename) decoded = open(self.filesave, 'w') decodedtxt = open(self.filetxt,'w') i = 0 ###SECOND GENERATION EXPORT if self.secgen == True: c = Gen2.SecondGen() decoded.write("""Input Message,Self Test,23 Hex ID,BCH Errors,Vessel ID,TAC,Country Code,Country Name,Latitude,Longitude\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.processHex(str(line)) ##Self Test decoded.write('{},'.format(c.bits[42])) ##23 Hex ID decoded.write('{},'.format(c.beaconHexID)) ##BCH Errors decoded.write('{},'.format(c.BCHerrors)) ##Vessel ID decoded.write('{},'.format(Gen2functions.bin2dec(c.vesselID))) ##TAC decoded.write('{},'.format(c.tac)) ##Country Code decoded.write('{},'.format(c.countryCode)) ##Country Name decoded.write('{},'.format(c.countryName)) ##Latitude decoded.write('{},'.format(c.latitude[1])) ##Longitude decoded.write('{},'.format(c.longitude[1])) except Gen2.Gen2Error as e2: decoded.write(e2.value) decoded.write('\n') ##FIRST GENERATION EXPORT else: c = decodehex2.BeaconHex() decoded.write("""Input Message,Self Test,15 Hex ID,Complete,Test Coded,Beacon Type,TAC,Country Code,Country Name,Location Type,Position Source,Course Lat,Course Long,Final Lat,Final Long,Fixed Bits,binary complete\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.processHex(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] if c._btype == 'Test': testcode = '1' else: testcode = '0' decoded.write('{},'.format(str(c.testmsg))) decoded.write('{},'.format(c.hex15)) decoded.write('{},'.format(c.bch.complete)) decoded.write('{},'.format(testcode)) decoded.write('{},'.format(c._btype)) decoded.write('{},'.format(c.tac)) decoded.write('{},'.format(c.countrydetail.mid)) decoded.write('{},'.format(c.countrydetail.cname)) decoded.write('{},'.format(c._loctype)) decoded.write('{},'.format(c.encpos)) decoded.write('{},'.format(courselat)) decoded.write('{},'.format(courselong)) decoded.write('{},'.format(finallat)) decoded.write('{},'.format(finallong)) decoded.write('{},'.format(c.fixedbits)) except decodehex2.HexError as e: decoded.write(e.value) decoded.write('\n') decodedtxt.write('\n{} {} {} {} {} {}'.format(str(c.bin[25:37]),str(c.bin[37:86]),str(c.bch.bch[0]),c.bin[107:115],c.bin[115:133],c.bch.bch[1])) decoded.close() self.emit(SIGNAL('EXPORT'), 100)
print BCH print bch2 testhex = Func2.bin2hex(bchbase + BCH + '00') printtxt('\nYour complete beacon message is: ' + testhex) fhex.write('\n'+testhex) try: x=raw_input("Done") except EOFError: x='' newBeacon1 = Gen2.SecondGen(testhex) newBeacon1.processHex(testhex) ##Add Hex message to export file newBeacon1.tablebin.append(['Beacon message:', testhex,'','']) for i in newBeacon1.tablebin: x='"'+i[1] i[1]=x with open('my_beacon_excel.csv', 'w') as csvfile: writer = csv.writer(csvfile)