def erase_firmware(device, mcu_id): '''erase a firmware''' cmd = GDB logger.info("Erasing firmware for '%s'" % mcu_id) try: util.kill_processes([GDB]) gdb = pexpect.spawn(cmd, logfile=sys.stdout, timeout=10) gdb.expect("(gdb)") gdb.send("target extended %s\n" % device) gdb.expect("Remote debugging using") gdb.expect("(gdb)") gdb.send("monitor swdp_scan\n") cpu = gdb.expect([CPUID_IO, CPUID_FMU]) if cpu == 0: if mcu_id != CPUID_IO: util.failure("Incorrect CPU ID '%s' - expected '%s'" % (CPUID_IO, mcu_id)) else: if mcu_id != CPUID_FMU: util.failure("Incorrect CPU ID '%s' - expected '%s'" % (CPUID_FMU, mcu_id)) gdb.expect("(gdb)") gdb.send("attach 1\n") gdb.expect("(gdb)") gdb.send("set mem inaccessible-by-default off\n") gdb.expect("(gdb)") gdb.send("monitor erase\n") gdb.expect("(gdb)", timeout=20) gdb.send('quit\n') gdb.expect('Quit anyway') gdb.send('y\n') gdb.expect("Detached from remote") gdb.close() logger.info("closed") except Exception as ex: util.show_error('Erasing firmware', ex) logger.info("Erase done")
def load_firmware(device, firmware, mcu_id, run=False): '''load a given firmware''' cmd = "%s %s" % (GDB, firmware) logger.info("Loading firmware %s" % firmware) log = StringIO() try: gdb = pexpect.spawn(cmd, logfile=log, timeout=10) gdb.expect("Reading symbols from") gdb.expect("done") gdb.expect("(gdb)") gdb.send("target extended %s\n" % device) gdb.expect("Remote debugging using") gdb.expect("(gdb)") gdb.send("monitor swdp_scan\n") ids = CPUID_IO + CPUID_FMU cpu = gdb.expect(ids) if ids[cpu] not in mcu_id: util.failure("Incorrect CPU ID '%s' - expected '%s'" % (ids[cpu], mcu_id)) gdb.expect("(gdb)") gdb.send("attach 1\n") gdb.expect("(gdb)") gdb.send("set mem inaccessible-by-default off\n") gdb.expect("(gdb)") gdb.send("load\n") gdb.expect("Loading section .text", timeout=20) gdb.expect("Loading section .data", timeout=30) gdb.expect("Start address", timeout=10) gdb.expect("Transfer rate", timeout=10) gdb.expect("(gdb)") if run: gdb.send("run\n") gdb.expect("Start it from the beginning?") gdb.send("y\n") except Exception as ex: util.show_error('Loading firmware %s' % firmware, ex, log)
def erase_firmware(device, mcu_id): '''erase a firmware''' cmd = GDB logger.info("Erasing firmware for '%s'" % mcu_id) try: util.kill_processes([GDB]) gdb = pexpect.spawn(cmd, logfile=sys.stdout, timeout=10) gdb.expect("(gdb)") gdb.send("target extended %s\n" % device) gdb.expect("Remote debugging using") gdb.expect("(gdb)") gdb.send("monitor swdp_scan\n") ids = CPUID_IO + CPUID_FMU cpu = gdb.expect(ids) if ids[cpu] not in mcu_id: util.failure("Incorrect CPU ID '%s' - expected '%s'" % (ids[cpu], mcu_id)) gdb.expect("(gdb)") gdb.send("attach 1\n") gdb.expect("(gdb)") gdb.send("set mem inaccessible-by-default off\n") gdb.expect("(gdb)") gdb.send("monitor erase\n") gdb.expect("(gdb)", timeout=20) gdb.send('quit\n') gdb.expect('Quit anyway') gdb.send('y\n') gdb.expect("Detached from remote") gdb.close() logger.info("closed") except Exception as ex: util.show_error('Erasing firmware', ex) logger.info("Erase done")
def validate(self, data): """ :data: config record, almost, this method makes some changes. Validates the config record Rraises error if their is a problem with it. MAKES CHANGES TO RECORD RETURNS updated record, ready to be saved. """ if not data['project_name'].strip(): raise ValidationError, LANG.lookup('errors.no_name') if data['project_name'] != self.project.get('project_name'): # it has changed if data['project_name'] in self.config.get('projects'): # and that name is used dlg = wx.MessageDialog(self, message=LANG.lookup('warning.overwrite'), caption=LANG.lookup('errors.warning'), style= wx.YES_NO| wx.ICON_QUESTION ) if dlg.ShowModal() == wx.ID_YES: pass else: self.name_box.SetValue(self.project.get('project_name','')) return False dlg.Destroy() if not os.path.isfile(os.path.abspath(data['nsi_file'])): UTL.show_error(LANG.lookup('errors.warning'), LANG.lookup('warning.nsifile'), self.config, wx.ICON_INFORMATION) return data
def __init__(self, parent, title, pos=(-1,-1), size=(512,530)): self.parent = parent BF.__init__(self, parent, title, pos, size) try: self.SetIcon(IMG.getPytisIcon()) finally: pass self.Show(False) self.Programs = MP(self) self.Programs.Show(True) self.Settings = SETTINGS(self) self.Settings.Show(False) if UTL.emergency_bug[0]: UTL.show_error(LANG.lookup('errors.config'), LANG.lookup('errors.config_long'), self.config) self.Show(True)
def _(evt): try: return subprocess.Popen(args=cmd) except WindowsError, e: UTL.show_error(LANG.lookup('errors.default'), "%s \n %s" %(str(e), cmd), self.config, wx.ICON_STOP)
def _(*notused): #self.Minimize(None) try: ret = subprocess.Popen(args=str(path)) except: #self.Restore(None) UTL.show_error(LANG.lookup('errors.missing_child_title'), LANG.lookup('errors.missing_child') % path, wx.ICON_ERROR)
def EndModal(self, event): id = event.GetId() if id != wx.ID_OK and id != wx.ID_CANCEL: # double clicked id = wx.ID_OK if id == wx.ID_OK and not self.name: UTL.show_error(LANG.lookup('load.errors.nofile'), LANG.lookup('load.errors.nofile_long'), self.config) event.Skip() return elif id == wx.ID_OK: self.parent.load(self.name) return wx.Dialog.EndModal(self, id)
def load_firmware_USB(device, firmware): '''load a given firmware via USB''' cmd = "%s --port %s %s" % (PX_UPLOADER, device, firmware) logger.info("Loading firmware %s via USB" % firmware) log = StringIO() try: gdb = pexpect.spawn(cmd, logfile=log, timeout=20) gdb.expect("Found board") gdb.expect("Erase") gdb.expect("Program") gdb.expect("Verify") gdb.expect("Rebooting") except Exception as ex: util.show_error('Loading firmware %s' % firmware, ex, log)
def run(self): tracks = None if not self.discid: try: info = get_disc_info() self.discid = info.discid tracks = info.track_count except Exception as e: util.show_error(e, message="Error reading disc information") return self.dlg.message.emit("Getting data from musicbrainz...") try: self.releases = get_releases(self.discid) except Exception: util.show_error("Could not find CD info in musicbrainz") if not tracks: # Happens during testing only. Just set a bogus number tracks = 5 # This isn't very good, especially if the not found disc has multiple # artists. UI needs to handle this case properly. self.releases = [ CDInfo( artist="Unknown", album="Unknown", discno=1, year=1980, multi_artist=False, set_size=1, cover_art=None, tracks=[ TrackInfo( artist="Unknown", album="Unknown", title="Unknown", trackno=i, ) for i in range(1, tracks + 1) ], ), ]
def save(self, data): # Language stuff if self.config.get('language') != data.get('language'): try: LANG.setLanguage(data['language']) except LanguageError, e: return UTL.show_error(LANG.lookup('errors.sorry'), LANG.lookup('errors.language'), wx.ICON_ERROR) else: self.local()
def onSave(self, evt): data = {'nsis_path' : self.nsis_path.GetValue(), 'vpatch_path' : self.vpatch_path.GetValue(), 'language' : self.language.GetValue(), } try: data = self.validate(data) except ValidationError, e: return UTL.show_error(LANG.lookup('errors.sorry'), str(e), self.config, wx.ICON_EXCLAMATION)
def load_firmware(device, firmware, mcu_id, run=False): '''load a given firmware''' cmd = "%s %s" % (GDB, firmware) logger.info("Loading firmware %s" % firmware) log = StringIO() try: gdb = pexpect.spawn(cmd, logfile=log, timeout=10) gdb.expect("Reading symbols from") gdb.expect("done") gdb.expect("(gdb)") gdb.send("target extended %s\n" % device) gdb.expect("Remote debugging using") gdb.expect("(gdb)") gdb.send("monitor swdp_scan\n") cpu = gdb.expect([CPUID_IO, CPUID_FMU]) if cpu == 0: if mcu_id != CPUID_IO: util.failure("Incorrect CPU ID '%s' - expected '%s'" % (CPUID_IO, mcu_id)) else: if mcu_id != CPUID_FMU: util.failure("Incorrect CPU ID '%s' - expected '%s'" % (CPUID_FMU, mcu_id)) gdb.expect("(gdb)") gdb.send("attach 1\n") gdb.expect("(gdb)") gdb.send("set mem inaccessible-by-default off\n") gdb.expect("(gdb)") gdb.send("load\n") gdb.expect("Loading section .text", timeout=20) gdb.expect("Loading section .data", timeout=30) gdb.expect("Start address", timeout=10) gdb.expect("Transfer rate", timeout=10) gdb.expect("(gdb)") if run: gdb.send("run\n") gdb.expect("Start it from the beginning?") gdb.send("y\n") except Exception as ex: util.show_error('Loading firmware %s' % firmware, ex, log)
def onGenUnsh(self,e): if not self.unsh_file.GetValue().endswith('.nsh') or \ os.path.isdir(os.path.abspath(self.unsh_file.GetValue())): return UTL.show_error(LANG.lookup('errors.file_not_found '), LANG.lookup('errors.file_not_found_long') % self.unsh_file.GetValue(), self.config) self.config['walker_options']['-m0'] = False self.config['walker_options']['-m1'] = True self.config['walker_options']['-m2'] = False self.config.save() dlg = WalkerDLG(self, -1, LANG.lookup('unsh.title')) if dlg.ShowModal() == wx.ID_OK: pass dlg.Destroy()
def accel_calibrate(): '''run full accel calibration''' logger.info("Starting accel cal at %s" % time.ctime()) conn = connection.Connection() logger.info("FW version: %s" % conn.fw_version) logger.info("PX4 version: %s" % conn.px4_version) logger.info("NuttX version: %s" % conn.nuttx_version) logger.info("STM32 serial: %s" % conn.stm32_serial) # lock the two telemetry ports to prevent the COMMAND_ACK messages in accel cal # from looping back between the two telemetry ports logger.info("Locking telemetry ports") util.lock_serial_port(conn.testmav, mavutil.mavlink.SERIAL_CONTROL_DEV_TELEM1) util.lock_serial_port(conn.testmav, mavutil.mavlink.SERIAL_CONTROL_DEV_TELEM2) try: accel_calibrate_run(conn) test_sensors.check_accel_cal(conn) test_sensors.check_gyro_cal(conn) except Exception as ex: conn.close() util.show_error('Accel calibration complete???', ex) try: # we run the sensor checks from here to avoid re-opening the links test_sensors.check_all_sensors(conn) except Exception as ex: conn.close() util.show_error('Test sensors failed', ex) try: logger.info("Loading factory parameters") conn.test.send('param load %s\n' % FACTORY_PARM) conn.test.expect('Loaded \d+ parameters from') logger.info("Parameters loaded OK") except Exception as ex: conn.close() util.show_error('Parameter load failed', ex) logger.info("Resetting AHRS_ORIENTATION to 0") util.param_set(conn.test, 'AHRS_ORIENTATION', 0) time.sleep(1) if ETE == 0: rotate.center_servos(conn) conn.close()
def onSave(self, evt): data = {'project_name' : self.name_box.GetValue(), 'nsi_file' : self.nsi_file.GetValue(), 'insh_file' : self.insh_file.GetValue(), 'unsh_file' : self.unsh_file.GetValue(), 'md5_file' : self.md5_file.GetValue(), 'project_dir' : self.project_dir.GetValue(), 'saved_date' : datetime.datetime.now(), 'display_date' : datetime.datetime.now().strftime("%I:%M%%s %m %b, %Y") % datetime.datetime.now().strftime("%p").lower(), 'inst_var' : self.project['install_var'] } try: data = self.validate(data) if not data: return except ValidationError, e: return UTL.show_error(LANG.lookup('errors.sorry'), str(e), self.config, wx.ICON_EXCLAMATION)
def accel_calibrate(): '''run full accel calibration''' logger.info("Starting accel cal at %s" % time.ctime()) conn = connection.Connection() # lock the two telemetry ports to prevent the COMMAND_ACK messages in accel cal # from looping back between the two telemetry ports logger.info("Locking telemetry ports") util.lock_serial_port(conn.testmav, mavutil.mavlink.SERIAL_CONTROL_DEV_TELEM1) util.lock_serial_port(conn.testmav, mavutil.mavlink.SERIAL_CONTROL_DEV_TELEM2) try: accel_calibrate_run(conn) test_sensors.check_accel_cal(conn) test_sensors.check_gyro_cal(conn) except Exception as ex: conn.close() util.show_error('Accel calibration complete???', ex) try: # we run the sensor checks from here to avoid re-opening the links test_sensors.check_all_sensors(conn) except Exception as ex: conn.close() util.show_error('Test sensors failed', ex) try: logger.info("Loading factory parameters") conn.test.send('param load %s\n' % FACTORY_PARM) conn.test.expect('Loaded \d+ parameters from') logger.info("Parameters loaded OK") except Exception as ex: conn.close() util.show_error('Parameter load failed', ex) conn.close()
# fix for ugly font on 7+ font = QFont("Segoe UI", 9) app.setFont(font) # noinspection PyUnresolvedReferences import turing_rc splash = QSplashScreen(QPixmap(":/icon/media/icon_128.png"), Qt.WindowStaysOnTopHint) splash.show() app.processEvents() try: theming.themes["custom"] = (theming.themes["custom"][0], util.settings.value("custom_theme", [], type=list)) except: pass from forms import mainwindow mainwindow.init_main(splash) try: exitCode = app.exec_() except: show_error() exitCode = 1 mainwindow.clean_exit()
def _(evt): try: return subprocess.Popen(args=cmd) except WindowsError, e: UTL.show_error("ERROR", "%s \n %s" %(str(e), cmd), wx.ICON_STOP)
def __init__(self, ref_only=False): util.kill_processes(['mavproxy.py', GDB]) self.reflog = StringIO() self.testlog = StringIO() self.ref = None self.test = None self.nsh = None self.refmav = None self.testmav = None try: if not ref_only: self.nsh = nsh_console.nsh_console() except Exception as ex: self.close() util.show_error('Connecting to nsh console', ex, self.testlog) try: self.ref = mav_reference.mav_reference(self.reflog) except Exception as ex: self.close() util.show_error('Connecting to reference board1', ex, self.reflog) try: if not ref_only: self.test = mav_test.mav_test(self.testlog) except Exception as ex: self.close() util.show_error('Connecting to test board1', ex, self.testlog) try: logger.info("CONNECTING MAVLINK TO REFERENCE BOARD") self.refmav = mavutil.mavlink_connection('127.0.0.1:14550') util.wait_heartbeat(self.refmav, timeout=30) util.wait_mode(self.refmav, IDLE_MODES) except Exception as ex: self.close() util.show_error('Connecting to reference board2', ex, self.reflog) try: if not ref_only: logger.info("CONNECTING MAVLINK TO TEST BOARD") self.testmav = mavutil.mavlink_connection('127.0.0.1:14551') util.wait_heartbeat(self.testmav, timeout=30) logger.info("got heartbeat") util.wait_mode(self.testmav, IDLE_MODES) logger.info("Waiting for 'Ready to FLY'") self.fw_version = None self.px4_version = None self.nuttx_version = None self.stm32_serial = None ready = False self.test.send("param fetch\n") # log version information for later reference while (self.fw_version is None or self.px4_version is None or self.nuttx_version is None or self.stm32_serial is None or not ready): i = self.test.expect([ 'APM: ([^\r\n]*Copter[^\r\n]*)\r\n', 'APM: PX4: ([0-9a-f]+) NuttX: ([0-9a-f]+)\r\n', 'APM: PX4v2 ([0-9A-F]+ [0-9A-F]+ [0-9A-F]+)\r\n', '(Ready to FLY)' ], timeout=20) if i == 3: ready = True elif i == 0: self.fw_version = self.test.match.group(1) elif i == 1: self.px4_version = self.test.match.group(1) self.nuttx_version = self.test.match.group(2) elif i == 2: self.stm32_serial = self.test.match.group(1) except Exception as ex: self.close() util.show_error('Connecting to test board2', ex, self.testlog) if self.nsh is not None: # log any extra nsh data logger.debug("Draining nsh") try: self.nsh.read_nonblocking(4096, 1) except Exception as ex: pass try: if not ref_only and not ref_gyro_offset_ok(self.refmav): self.close() util.failure("Bad reference gyro - FAILED") except Exception as ex: self.close() util.show_error('testing reference gyros', ex) logger.info("Setting rotation level") try: rotate.set_rotation(self, 'level', wait=False) except Exception as ex: self.close() util.show_error("unable to set safety off", ex)
def __init__(self, ref_only=False): util.kill_processes(['mavproxy.py', GDB]) self.reflog = StringIO() self.testlog = StringIO() self.ref = None self.test = None self.nsh = None self.refmav = None self.testmav = None try: if not ref_only: self.nsh = nsh_console.nsh_console() except Exception as ex: self.close() util.show_error('Connecting to nsh console', ex, self.testlog) try: self.ref = mav_reference.mav_reference(self.reflog) except Exception as ex: self.close() util.show_error('Connecting to reference board1', ex, self.reflog) try: if not ref_only: self.test = mav_test.mav_test(self.testlog) except Exception as ex: self.close() util.show_error('Connecting to test board1', ex, self.testlog) try: logger.info("CONNECTING MAVLINK TO REFERENCE BOARD") self.refmav = mavutil.mavlink_connection('127.0.0.1:14550') util.wait_heartbeat(self.refmav, timeout=30) util.wait_mode(self.refmav, IDLE_MODES) except Exception as ex: self.close() util.show_error('Connecting to reference board2', ex, self.reflog) try: if not ref_only: logger.info("CONNECTING MAVLINK TO TEST BOARD at %s" % time.ctime()) self.testmav = mavutil.mavlink_connection('127.0.0.1:14551') util.wait_heartbeat(self.testmav, timeout=30) logger.info("got heartbeat at %s" % time.ctime()) util.wait_mode(self.testmav, IDLE_MODES) logger.info("Waiting for 'Ready to FLY'") self.test.expect('Ready to FLY', timeout=20) except Exception as ex: self.close() util.show_error('Connecting to test board2 at %s' % time.ctime(), ex, self.testlog) if self.nsh is not None: # log any extra nsh data logger.debug("Draining nsh") try: self.nsh.read_nonblocking(4096, 1) except Exception as ex: pass try: if not ref_only and not ref_gyro_offset_ok(self.refmav): self.close() util.failure("Bad reference gyro - FAILED") except Exception as ex: self.close() util.show_error('testing reference gyros', ex) logger.info("Setting rotation level") try: rotate.set_rotation(self, 'level', wait=False) except Exception as ex: self.close() util.show_error("unable to set safety off", ex)
def futureFeature(self, evt): return UTL.show_error(LANG.lookup('errors.comming_soon'), LANG.lookup('errors.not_implemented'), self.config, wx.ICON_INFORMATION)
def __init__(self, ref_only=False): util.kill_processes(['mavproxy.py', GDB]) self.reflog = StringIO() self.testlog = StringIO() self.ref = None self.test = None self.nsh = None self.refmav = None self.testmav = None try: if not ref_only: self.nsh = nsh_console.nsh_console() except Exception as ex: self.close() util.show_error('Connecting to nsh console', ex, self.testlog) try: self.ref = mav_reference.mav_reference(self.reflog) except Exception as ex: self.close() util.show_error('Connecting to reference board1', ex, self.reflog) try: if not ref_only: self.test = mav_test.mav_test(self.testlog) except Exception as ex: self.close() util.show_error('Connecting to test board1', ex, self.testlog) try: logger.info("CONNECTING MAVLINK TO REFERENCE BOARD") self.refmav = mavutil.mavlink_connection('127.0.0.1:14550') util.wait_heartbeat(self.refmav, timeout=30) util.wait_mode(self.refmav, IDLE_MODES) except Exception as ex: self.close() util.show_error('Connecting to reference board2', ex, self.reflog) try: if not ref_only: logger.info("CONNECTING MAVLINK TO TEST BOARD") self.testmav = mavutil.mavlink_connection('127.0.0.1:14551') util.wait_heartbeat(self.testmav, timeout=30) logger.info("got heartbeat") util.wait_mode(self.testmav, IDLE_MODES) logger.info("Waiting for 'Ready to FLY'") self.fw_version = None self.px4_version = None self.nuttx_version = None self.stm32_serial = None ready = False self.test.send("param fetch\n") # log version information for later reference while (self.fw_version is None or self.px4_version is None or self.nuttx_version is None or self.stm32_serial is None or not ready): i = self.test.expect(['APM: ([^\r\n]*Copter[^\r\n]*)\r\n', 'APM: PX4: ([0-9a-f]+) NuttX: ([0-9a-f]+)\r\n', 'APM: PX4v2 ([0-9A-F]+ [0-9A-F]+ [0-9A-F]+)\r\n', '(Ready to FLY)'], timeout=20) if i == 3: ready = True elif i == 0: self.fw_version = self.test.match.group(1) elif i == 1: self.px4_version = self.test.match.group(1) self.nuttx_version = self.test.match.group(2) elif i == 2: self.stm32_serial = self.test.match.group(1) except Exception as ex: self.close() util.show_error('Connecting to test board2', ex, self.testlog) if self.nsh is not None: # log any extra nsh data logger.debug("Draining nsh") try: self.nsh.read_nonblocking(4096, 1) except Exception as ex: pass try: if not ref_only and not ref_gyro_offset_ok(self.refmav): self.close() util.failure("Bad reference gyro - FAILED") except Exception as ex: self.close() util.show_error('testing reference gyros', ex) logger.info("Setting rotation level") try: rotate.set_rotation(self, 'level', wait=False) except Exception as ex: self.close() util.show_error("unable to set safety off", ex)
if not data['vpatch_path'].strip(): raise ValidationError, LANG.lookup('errors.no_vpatch') if not data['vpatch_path'].lower().endswith('genpat.exe'): raise ValidationError, LANG.lookup('errors.invalid_vpatch') if not os.path.isfile(data['vpatch_path']): raise ValidationError, LANG.lookup('errors.vpatch_path') return data def save(self, data): # Language stuff if self.config.get('language') != data.get('language'): try: LANG.setLanguage(data['language']) except LanguageError, e: return UTL.show_error(LANG.lookup('errors.sorry'), LANG.lookup('errors.language'), wx.ICON_ERROR) else: self.local() self.config.update(data) self.config.save() return UTL.show_error(LANG.lookup('errors.success'), LANG.lookup('errors.settings_updated'), self.config, wx.ICON_EXCLAMATION)
def except_hook(type, value, tback): show_error() sys.__excepthook__(type, value, tback)