def executeBinary(): abspath = os.path.abspath(__file__) dname = os.path.dirname(abspath) os.chdir(dname) killFW() out = commonLib.exec_command("(st-util > stLog 2>&1)&") time.sleep(4) with open("stLog") as output: log = output.read() status = True if 'error' in log.lower(): status = False assert status, ('ERROR - \n{}'.format(log)) dirContent = os.listdir(".") currDir = os.getcwd() if "gdbCommands" not in dirContent: assert "gdbCommands" in dirContent,\ "Error - missing gdbCommands file in dir\n{}".format(currDir) out = commonLib.exec_command("(arm-none-eabi-gdb -x gdbCommands)&") if "error" in out.lower(): raise AssertionError("ERROR: executeBinary() - failed" "\n\n{}".format(out)) return out
def isUARTSessionRunning(logger, device): out = commonLib.exec_command("ps -ef | grep {}".format(device)) logger.info(out) if "grep" not in out: return True else: return False
def main(): try: ssh = None logger = commonLib.configLogger() fileName = "killFW.sh" currentDir = os.getcwd() sftp = commonLib.sftpConnect() logger.info("Uploading {} to remote host...".format(fileName)) src = currentDir + "/{}".format(fileName) dest = "/home/pi/{}".format(fileName) commonLib.sftpPut(sftp, src, dest) logger.info("Done.") commonLib.sftpClose(sftp) if argVars.build: out = commonLib.exec_command("python ../../build/buildAll.py") assert not ("err" in out.lower()), "Error: command failed to execute.\n{}"\ .format(out) if argVars.execute_local: out = executeBinary() if argVars.fwup: out = fwupload(logger) if argVars.execute_remote: ssh = commonLib.sshOpen() killFW_remote(ssh, logger) readUART_remote(logger, ssh) executeBinaryRemote(ssh, logger) if argVars.killrfw: ssh = commonLib.sshOpen() killFW_remote(ssh, logger) if argVars.power_cycle: ssh = commonLib.sshOpen() rebootRemoteUSBDevice(ssh, logger) except: traceback.print_exc() killFW_remote(ssh, logger) finally: logger.critical("Cleanning up open ssh session...\n") commonLib.sshClose(ssh)
def readUART_local(logger): logger.info("\n-----------Printing serial console logs-----------\n") if not commonLib.isStUtilRunning(): out = commonLib.exec_command("(st-util > stLog 2>&1)&") logger.info(os.getcwd()) with open("config.json", "r") as jfile: jdata = json.load(jfile) serialDevice = jdata["device"] killUART(serialDevice) ser = serial.Serial(serialDevice, 9600) while True: data = ser.readline().rstrip()[2:].lstrip() if data: logger.info(data) logger.info("Serial output - " + data)
def killFW(): if commonLib.isStUtilRunning(): out = commonLib.exec_command("sudo pkill -f -9 st-util").split('\n')
def killUART(device): if isUARTSessionRunning(device): out = commonLib.exec_command("sudo kill {}".format(device))
import json import shutil import time if not os.path.exists("logs/"): os.makedirs("logs/") else: shutil.rmtree("logs/") os.makedirs("logs/") sys.path.append(os.getcwd()) sys.path.append(os.path.abspath("../common")) import commonLib path = commonLib.exec_command("pwd") path = path.strip("\n") # DEBUG: Suppressed, remove later if 0: commonLib.findDevice() def isUARTSessionRunning(logger, device): out = commonLib.exec_command("ps -ef | grep {}".format(device)) logger.info(out) if "grep" not in out: return True else: return False def isUARTSessionRunning_remote(logger, device, ssh):