def reset_QCC_chip(self): ELF_path = r"C:\Projects\loop\apps\applications\dev_board_loopback_download\qcc512x_qcc302x\common\depend_debug_qcc512x_qcc302x\dev_board_loopback_download.elf" m_globals = '-d trb:usb2trb -f apps1:%s' % ELF_path # Adding arguemtns so that pydbg will connect to the chip - it reads the arguments from argv sys.argv.extend(m_globals.split()) PydbgFrontEnd.main_wrapper(shell=globals()) device = csr.dev.attached_device device.reset()
def attach_to_device(self): from csr.front_end.pydbg_front_end import PydbgFrontEnd print('Attaching to Device @ "trb:scar"...') sys.stdout.flush() device, _ = PydbgFrontEnd.attach({"firmware_builds" : None, "device_url" : "trb:scar"}, shell=None) return device
def attach(self, image_type=None, image_path=None): from csr.front_end.pydbg_front_end import PydbgFrontEnd config = { "firmware_builds": self.get_firmware_builds(image_type, image_path), "device_url": self.transport_uri } device, _ = PydbgFrontEnd.attach(config) return device
def _attach_to_device(self): from csr.front_end.pydbg_front_end import PydbgFrontEnd if self._device_uri is None: print("Attach to Device failed, no device URI supplied") return None device_uri = self._device_uri target_list = device_uri.split('://')[1].split('/')[:-1] transport = target_list[1] trans_id = "trb:scar" if transport == "usb2tc": trans_id = "usb" print('Attaching to Device @ "%s"...' % trans_id) sys.stdout.flush() device, _ = PydbgFrontEnd.attach({"firmware_builds" : None, "device_url" : trans_id}, shell=None) return device
def check_device(pydbg_device_url): """ Attaches to a device using pydbg and checks if the device is readable """ from csr.front_end.pydbg_front_end import PydbgFrontEnd from csr.transport.tctrans import TcError try: device, _ = PydbgFrontEnd.attach({"device_url": pydbg_device_url}, interactive=False) except TcError: print("Connection failed") return False print("Connected to device") print("Checking if device is readable...") try: device_is_readable = device.chip.curator_subsystem.core.data[0x8000] return True except RuntimeError: print("Device not readable") return False
primary_device_url = get_pylib_target(args.debug) # Only interested in secondary device in Pydbg tab if args.tab_type is None: secondary_device_url = prompt_secondary_device_selection( args.kit, primary_device_url) else: secondary_device_url = None #Setup the calling string for pydbg command_line = [args.pydbg_path] command_line += ["-d", primary_device_url] if secondary_device_url: command_line[-1] += "," + secondary_device_url if firmware_args: command_line += ["-f", ",".join(firmware_args)] if args.tab_type: command_line.append(args.tab_type) if args.passOn: command_line += args.passOn sys.argv = command_line fw_tools_path = os.path.realpath(os.path.dirname(args.pydbg_path)) sys.path = [fw_tools_path, os.path.join(fw_tools_path, "pylib")] + sys.path os.environ["PYDBG_RUNNING_IN_SUBPROCESS"] = "1" sys.stderr = sys.stdout # reassing Python's notion of stderr so everything # goes to stdout. This seems to work better wtih the QMDE process handling from csr.front_end.pydbg_front_end import PydbgFrontEnd PydbgFrontEnd.main_wrapper()
def pkg_main(): # default mode of executing pydbg doesn't work # when running from a package; use alternative from csr.front_end.pydbg_front_end import PydbgRlCodeInteractFrontEnd PydbgFrontEnd = PydbgRlCodeInteractFrontEnd PydbgFrontEnd.main_wrapper(shell=globals())
def main(): """ A simple routine entry point that setuptools:setup.py can provide as an executable entry point when project is built via setup.py """ PydbgFrontEnd.main_wrapper(shell=globals())
def burn(self, image_type, image_path, reset_device=True): from csr.front_end.pydbg_front_end import PydbgFrontEnd success = False sys.stdout.flush() subsys_id = subsys_numbers.SubsystemNumbers.get_subsystem_number_from_name( image_type) if subsys_id != -1: firmware_builds = self.get_firmware_builds(image_type, image_path) device, _ = PydbgFrontEnd.attach({ "firmware_builds": firmware_builds, "device_url": self.transport_uri, "preload": True }) siflash = device.chip.curator_subsystem.siflash apps_fw = device.chip.apps_subsystem.p0.fw apps1_fw = device.chip.apps_subsystem.p1.fw if image_type != "curator": # Disable Curator USB interrupts to avoid flashing problems with USB attached disable_curator_usb_interrupts(device) # Try to disable deep sleep, unless it's the Curator itself that's being set up. disable_deep_sleep_if_possible(device) if image_type == "curator": print("Flash curator") image_dir = os.path.dirname(image_path) siflash.register_program_curator(dir_xuv=image_dir) elif image_type == "btss": # Special method which deals with the continuous read mode gubbins siflash.reprogram_bt(image_path, show_progress=True) elif image_type == "curator_fs": siflash.identify(subsys_id, 0) apps_fw.load_curator_fs(image_path) elif image_type == "p0_rw_config": siflash.identify(subsys_id, 0) apps_fw.load_rw_config(image_path) elif image_type == "p0_ro_cfg_fs": siflash.identify(subsys_id, 0) apps_fw.load_config_fs(image_path) elif image_type == "p0_ro_fs": siflash.identify(subsys_id, 0) apps_fw.load_fs(image_path) elif image_type == "p0_device_ro_fs": siflash.identify(subsys_id, 0) apps_fw.load_device_config_fs(image_path) elif image_type == "apps0": siflash.identify(subsys_id, 0) apps_fw.loader.load_custom("apps_p0", image_path) elif image_type == "apps1": siflash.identify(subsys_id, 0) apps1_fw.load() else: siflash.reprogram(subsys_id, 0, image_path) if reset_device == True: device.reset() # Give the hardware a couple of seconds prior to being run time.sleep(2) success = True return success
def run(self): global continue_QCC_listening, RECOGNIZED_PHRASE_QCC, INFO_PHRASE_QCC, ENERGY_PHRASE_QCC, DEBUG_PRINTING DEBUG_PRINTING = False if DEBUG_PRINTING == True: print("entered QCCLogging --> run") continue_QCC_listening = True print("starting the QCC listner") """ A simple routine entry point that setuptools:setup.py can provide as an executable entry point when project is built via setup.py """ try: ELF_path = r"C:\Projects\loop\apps\applications\dev_board_loopback_download\qcc512x_qcc302x\common\depend_debug_qcc512x_qcc302x\dev_board_loopback_download.elf" m_globals = '-dtrb:usb2trb -fapps1:%s log' % ELF_path # Adding arguemtns so that pydbg will connect to the chip - it reads the arguments from argv sys.argv = m_globals.split() file_path = os.path.abspath(__file__) file_dir = os.path.dirname(file_path) cur_pythonpath = os.getenv("PYTHONPATH", None) if cur_pythonpath: os.environ["PYTHONPATH"] = cur_pythonpath + ";" + file_dir else: os.environ["PYTHONPATH"] = file_dir # print os.getenv("PYTHONPATH", None) PydbgFrontEnd.main_wrapper(shell=globals()) device = csr.dev.attached_device apps1 = device.chip.apps_subsystem.p1 apps1.fw.env.load = True apps1.get_log = lambda: apps1.fw.debug_log.generate_decoded_event_report(return_str=True) # First time clears log apps1.get_log() print("Listening") vad = "" listening = "" while continue_QCC_listening: messaage_array = [] time.sleep(0.01) new_log = apps1.get_log() if new_log: # print new_log messaage_array = new_log.split("\n") # print(messaage_array) prev_ENERGY_PHRASE_QCC = "" for message in messaage_array: if message.strip(" ") != "": # print("Message is: " + message) if message.lower().find("listen") > -1: # Message is only clipping # print("Message contains Listen state") if listening == "" or not listening in message: pos_listen = message.lower().find("listen") INFO_PHRASE_QCC = message[pos_listen:].strip("\n")# .strip("\n----.--- apps1: ASR_START OK") listening = INFO_PHRASE_QCC self.emit(QtCore.SIGNAL('Info_QCC')) # else: # print("founf LISTEN message but value is same as before: " +listening + ", " + message) if message.find("MEAN ENERGY") > -1: # Message is TIMEOUT # print("Message contains MEAN ENERGY state") pos_energy = message.find("MEAN ENERGY") ENERGY_PHRASE_QCC = message[pos_energy:].strip("\n") if ENERGY_PHRASE_QCC != prev_ENERGY_PHRASE_QCC: self.emit(QtCore.SIGNAL('Energy_QCC')) prev_ENERGY_PHRASE_QCC = ENERGY_PHRASE_QCC if message.lower().find("timeout") > -1: # Message is TIMEOUT # print("Message contains timout state") pos_tout = message.lower().find("timeout") INFO_PHRASE_QCC = message[pos_tout:].strip("\n") self.emit(QtCore.SIGNAL('Info_QCC')) pos_tout = -1 if message.lower().find("unknown cmd") > -1: # Message is TIMEOUT # print("Message contains unknown cmd state") pos_ucmd = message.lower().find("unknown cmd") INFO_PHRASE_QCC = message[pos_ucmd:].strip("\n") self.emit(QtCore.SIGNAL('Info_QCC')) if message.lower().find("vad") > -1: # Message is only clipping # print("Message contains VAD state") pos_vad = message.lower().find("vad") INFO_PHRASE_QCC = message[pos_vad:].strip("\n")#.strip("\n----.--- apps1: ASR_START OK") self.emit(QtCore.SIGNAL('Info_QCC')) pos = message.lower().find("recognized") pos1 = message.lower().find("clipping") if pos1 > -1 and pos == -1: # Message is only clipping # print("Message is only clipping") INFO_PHRASE_QCC = message[pos1:].strip("\n").strip("\n----.--- apps1: ASR_START OK") self.emit(QtCore.SIGNAL('Info_QCC')) elif pos > -1 and pos1 == -1: # message contains recognized but NOT clipping # print("message contains recognized but NOT clipping") # RECOGNIZED_PHRASE_QCC = new_log[pos:].strip("\n").strip('\n----.--- apps1: ASR_START OK') RECOGNIZED_PHRASE_QCC = message[pos:].strip("\n") self.emit(QtCore.SIGNAL('recognized_QCC')) elif pos > -1 and pos1 > -1: # Message contains both Recognition and clipping # print("Message contains both Recognition and clipping") temp_str = message.split("\n") RECOGNIZED_PHRASE_QCC = temp_str[0][pos:].strip("\n") INFO_PHRASE_QCC = temp_str[1][pos1:].strip("\n").strip("\n----.--- apps1: ASR_START OK") self.emit(QtCore.SIGNAL('recognized_QCC')) self.emit(QtCore.SIGNAL('Info_QCC')) #print RECOGNIZED_PHRASE_QCC print("END Listening") except Exception as e: print("couldn't activate listening to QCC: " + str(e)) self.stop()
def start_listening_to_QCC_log(): """ A simple routine entry point that setuptools:setup.py can provide as an executable entry point when project is built via setup.py """ ELF_path = r"C:\Projects\loop\apps\applications\dev_board_loopback_download\qcc512x_qcc302x\common\depend_debug_qcc512x_qcc302x\dev_board_loopback_download.elf" m_globals = '-d trb:usb2trb -f apps1:%s log' % ELF_path # Adding arguemtns so that pydbg will connect to the chip - it reads the arguments from argv sys.argv.extend(m_globals.split()) file_path = os.path.abspath(__file__) file_dir = os.path.dirname(file_path) cur_pythonpath = os.getenv("PYTHONPATH", None) if cur_pythonpath: os.environ["PYTHONPATH"] = cur_pythonpath + ";" + file_dir else: os.environ["PYTHONPATH"] = file_dir print os.getenv("PYTHONPATH", None) now = datetime.datetime.now() timestamp = now.strftime("%a %d/%m/%Y %H:%M:%S") timestamp_for_filename = timestamp.replace(" ","_").replace("/","-").replace(":","-") log_file_path ="C:\\AutomationEnvironment\\Logs\QCC_Log_" + timestamp_for_filename + ".txt" f = open(log_file_path, 'w+') PydbgFrontEnd.main_wrapper(shell=globals()) device = csr.dev.attached_device apps1 = device.chip.apps_subsystem.p1 apps1.fw.env.load = True f.write(timestamp + " - Attached & Listening\n") f.close() apps1.get_log = lambda: apps1.fw.debug_log.generate_decoded_event_report(return_str=True) # First time clears log apps1.get_log() while True: time.sleep(0.01) new_log = apps1.get_log() if new_log: # print new_log now = datetime.datetime.now() timestamp = now.strftime("%a %d/%m/%Y %H:%M:%S") + ('.%03d' % (now.microsecond / 10000)) messaage_array = new_log.split("\n") # print(messaage_array) for message in messaage_array: if message.strip(" ") != "": # print("Message is: " + message) # if "recognized" in new_log.lower() or "clipping" in new_log.lower() or "vad" in new_log.lower() or "listen" in new_log.lower(): # print("RECOGNIZED!!") f = open(log_file_path, 'a') if message.lower().find("listen") > -1: # Message is only clipping # print("Message contains Listen state") if listening == "" or not listening in message: pos = message.lower().find("listen") INFO_PHRASE_QCC = message[pos:].strip("\n") # .strip("\n----.--- apps1: ASR_START OK") listening = INFO_PHRASE_QCC print INFO_PHRASE_QCC f.write(timestamp + " - " + INFO_PHRASE_QCC + "\n") if message.lower().find("timeout") > -1: # Message is TIMEOUT # print("Message contains VAD state") pos = message.lower().find("timeout") INFO_PHRASE_QCC = message[pos:].strip("\n")# .strip("\n----.--- apps1: ASR_START OK") print INFO_PHRASE_QCC f.write(timestamp + " - " + INFO_PHRASE_QCC + "\n") if message.lower().find("vad") > -1: # Message is only clipping # print("Message contains VAD state") pos = message.lower().find("vad") INFO_PHRASE_QCC = message[pos:].strip("\n").strip("\n----.--- apps1: ASR_START OK") print INFO_PHRASE_QCC f.write(timestamp + " - " + INFO_PHRASE_QCC + "\n") if message.lower().find("unknown cmd") > -1: # Message is only clipping # print("Message contains VAD state") pos = message.lower().find("unknown cmd") INFO_PHRASE_QCC = message[pos:].strip("\n").strip("\n----.--- apps1: ASR_START OK") print INFO_PHRASE_QCC f.write(timestamp + " - " + INFO_PHRASE_QCC + "\n") pos = message.lower().find("recognized") pos1 = message.lower().find("clipping") if pos1 > -1 and pos == -1: # Message is only clipping # print("Message is only clipping") INFO_PHRASE_QCC = message[pos1:].strip("\n").strip("\n----.--- apps1: ASR_START OK") print INFO_PHRASE_QCC f.write(timestamp + " - " + INFO_PHRASE_QCC + "\n") elif pos > -1 and pos1 == -1: # message contains recognized but NOT clipping # print("message contains recognized but NOT clipping") # RECOGNIZED_PHRASE_QCC = new_log[pos:].strip("\n").strip('\n----.--- apps1: ASR_START OK') RECOGNIZED_PHRASE_QCC = message[pos:].strip("\n") print RECOGNIZED_PHRASE_QCC f.write(timestamp + " - " + RECOGNIZED_PHRASE_QCC + "\n") elif pos > -1 and pos1 > -1: # Message contains both Recognition and clipping # print("Message contains both Recognition and clipping") temp_str = message.split("\n") RECOGNIZED_PHRASE_QCC = temp_str[0][pos:].strip("\n") INFO_PHRASE_QCC = temp_str[1][pos1:].strip("\n").strip("\n----.--- apps1: ASR_START OK") print RECOGNIZED_PHRASE_QCC f.write(timestamp + " - " + RECOGNIZED_PHRASE_QCC + "\n") print INFO_PHRASE_QCC f.write(timestamp + " - " + INFO_PHRASE_QCC + "\n") f.close()