def __init__(self, *args, **kw): dealGenericOptions() super(buildCommand, self).__init__(*args, **kw) self.parser.insert_option_group(0, self.cmd_opts) index_opts = cmdoptions.make_option_group( cmdoptions.index_group, self.parser, ) self.serial = SerialUtils() self.parser.insert_option_group(0, index_opts) self.srcfile = [] self.headers = "" self.headerlist = [] self.buildParm = "" self.gcc = "" self.cpp = "" self.objcopy = "" self.sizetool = "" self.ld = "" self.board_id = -1 self.gcc_cmd = "" self.cpp_cmd = "" self.objcopy_cmd = "" self.sizetool_cmd = "" self.ld_cmd = "" self._verbose = False
def __init__(self, *args, **kw): dealGenericOptions() super(flashCommand, self).__init__(*args, **kw) self.cmd_opts.add_option('-p', '--port', dest='port', action='store', default="", help='The port of the ArduPy board.') self.cmd_opts.add_option('-o', '--origin', dest='origin', action='store_true', default=False, help='flash latest version firmware') self.parser.insert_option_group(0, self.cmd_opts) self.serial = SerialUtils() self.port = ""
def run(self, options, args): ser = SerialUtils() if options.scan: if options.desc == "": print(ser.listAvailableBoard()) else: print(ser.listDesignatedBoard(options.desc)) return SUCCESS if options.list == True: print(ser.listBoard()) return SUCCESS if options.port == "": port, desc, hwid, isbootloader = ser.getAvailableBoard() else: port = options.port if port == None: log.error("Sorry, the device you should have is not plugged in.") return ERROR try: if options.baudrate != "": baudrate = int(options.baudrate) else: baudrate = 115200 self.serial = serial.Serial(port, baudrate=baudrate, interCharTimeout=1) print(self.get_version()) except Exception as e: log.error(e) return ERROR return SUCCESS
def run(self, options, args): if options.list == True: ser = SerialUtils() print(ser.listBoard()) return SUCCESS if 'clean' in args: self.clean() return SUCCESS if options.board != "": self.board = options.board session = self.get_default_session(options) # setup deploy dir deploydir = str(Path(user_config_dir, "deploy")) if not os.path.exists(deploydir): os.makedirs(deploydir) # create build dir, This folder will be deleted after compilation builddir = mktemp() os.makedirs(builddir) self.downloadAll(session) self.get_arduinocore_version() # Converts the header file to the absolute path of the current system for h in ardupycore_headers: # add Arduino Core version if h[0:35] == "/ardupycore/Seeeduino/hardware/samd": h = h.format(self.arduinoCoreVersion) self.headerlist.append(str(Path(user_config_dir + h))) self.headerlist.append( str(Path(user_config_dir + board_headers + self.board))) # setup ardupy modules dir moduledir = str(Path(user_config_dir, "modules")) if not os.path.exists(moduledir): os.makedirs(moduledir) modules = os.listdir(moduledir) if modules: for m in modules: # Gets the source files for all modules for f in self.fileEndWith( os.path.join(user_config_dir + "/modules/", m), '.cpp', '.c'): self.srcfile.append(str(Path(f))) # Sets the root directory of the module to be where the header file is found for r, d, f in os.walk( str(Path(user_config_dir + "/modules/" + m))): if r.find('.git') == -1 and r.find("examples") == -1: self.headerlist.append(r) # Convert the necessary files in ardupycore into the absolute path of the system. for mp_file in mp_needful_file: self.srcfile.append(str(Path(user_config_dir + mp_file))) self.generatedInitfile(builddir) # Convert to the required format for GCC self.generatedQstrdefs(builddir) self.headers = "-I" + " -I".join(self.headerlist) # Compile all source files self.buildFarm(builddir) firmware_path = str(Path(str(deploydir) + "/Ardupy.bin")) #remove the old firmware if os.path.exists(firmware_path): os.remove(firmware_path) # Convert ELF files to binary files objcopy_cmd = str(Path(user_config_dir + gcc_48_objcopy)) + "-O binary " \ + str(Path(builddir + "/Ardupy")) + " " \ + firmware_path log.debug(objcopy_cmd) os.system(objcopy_cmd) # Print size information os.system( str(Path(user_config_dir + gcc_48_size)) + " -A " + str(Path(builddir + "/Ardupy"))) # delete build dir shutil.rmtree(builddir) if os.path.exists(firmware_path): log.info('Firmware path: ' + firmware_path) log.info('Usage:\n\r aip flash') else: raise Exception(print('compile error')) #return ERRO return SUCCESS
def run(self, options, args): if len(args) >= 1: board = args[0] else: board = None ser = SerialUtils() if options.port == "": if board == None: board, desc, hwid, isbootloader = ser.getAvailableBoard() else: board = options.port format = "%(asctime)s\t%(levelname)s\t%(message)s" if options.logfile is not None: logging.basicConfig(format=format, filename=options.logfile, level=options.loglevel) else: logging.basicConfig(format=format, level=logging.CRITICAL) mpfs = mpf.MpFileShell(not options.nocolor, not options.nocache, options.reset, options.nohelp) if options.open is not None: if board is None: if not mpfs.do_open(options.open): return ERROR else: print( "Positional argument ({}) takes precedence over --open.".format( board ) ) if board is not None: mpfs.do_open(board) if options.command is not None: for acmd in "".join(options.command).split(";"): scmd = acmd.strip() if len(scmd) > 0 and not scmd.startswith("#"): mpfs.onecmd(scmd) elif options.script is not None: f = open(options.script, "r") script = "" for line in f: sline = line.strip() if len(sline) > 0 and not sline.startswith("#"): script += sline + "\n" if sys.version_info < (3, 0): sys.stdin = io.StringIO(script.decode("utf-8")) else: sys.stdin = io.StringIO(script) mpfs.intro = "" mpfs.prompt = "" if not options.noninteractive: try: mpfs.cmdloop() except KeyboardInterrupt: print("") return SUCCESS