Exemple #1
0
    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
Exemple #2
0
    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