def bootload_12(paddr, hex_file, power_communicator, verbose=False): """ Bootload a 12 port power module. :param paddr: The address of a power module (integer). :param hex_file: The filename of the hex file to write. :param power_communicator: Communication with the power modules. :param verbose: Show serial command on output if verbose is True. """ reader = HexReader(hex_file) print "E%d - Going to bootloader" % paddr power_communicator.do_command(paddr, bootloader_goto(), 10) print "E%d - Erasing code" % paddr for page in range(6, 64): power_communicator.do_command(paddr, bootloader_erase_code(), page) print "E%d - Writing code" % paddr for address in range(0x1D006000, 0x1D03FFFB, 128): bytes = reader.get_bytes_12(address) power_communicator.do_command( paddr, bootloader_write_code(POWER_API_12_PORTS), *bytes) print "E%d - Jumping to application" % paddr power_communicator.do_command(paddr, bootloader_jump_application())
def bootload_12(module_address, hex_file, power_communicator): """ Bootload a 12 port power module. :param module_address: The address of a power module (integer). :param hex_file: The filename of the hex file to write. :param power_communicator: Communication with the power modules. """ logger.info('E{0} - Version: {1}'.format( module_address, get_module_firmware_version(module_address, power_communicator))) logger.info('E{0} - Start bootloading'.format(module_address)) try: logger.info('E{0} - Reading calibration data'.format(module_address)) calibration_data = list( power_communicator.do_command(module_address, read_eeprom(12, 100), *[256, 100])) logger.info('E{0} - Calibration data: {1}'.format( module_address, ','.join([str(d) for d in calibration_data]))) except Exception as ex: logger.info('E{0} - Could not read calibration data: {1}'.format( module_address, ex)) calibration_data = None reader = HexReader(hex_file) logger.info('E{0} - Going to bootloader'.format(module_address)) power_communicator.do_command(module_address, bootloader_goto(), 10) try: logger.info('E{0} - Erasing code...'.format(module_address)) for page in range(6, 64): power_communicator.do_command(module_address, bootloader_erase_code(), page) logger.info('E{0} - Writing code...'.format(module_address)) for address in range(0x1D006000, 0x1D03FFFB, 128): data = reader.get_bytes_version_12(address) power_communicator.do_command( module_address, bootloader_write_code(POWER_API_12_PORTS), *data) finally: logger.info('E{0} - Jumping to application'.format(module_address)) power_communicator.do_command(module_address, bootloader_jump_application()) if calibration_data is not None: time.sleep(1) logger.info('E{0} - Restoring calibration data'.format(module_address)) power_communicator.do_command(module_address, write_eeprom(12, 100), *([256] + calibration_data)) logger.info('E{0} - Done'.format(module_address))
def bootload_12(paddr, hex_file, power_communicator): """ Bootload a 12 port power module. :param paddr: The address of a power module (integer). :param hex_file: The filename of the hex file to write. :param power_communicator: Communication with the power modules. """ reader = HexReader(hex_file) print "E%d - Going to bootloader" % paddr power_communicator.do_command(paddr, bootloader_goto(), 10) print "E%d - Erasing code" % paddr for page in range(6, 64): power_communicator.do_command(paddr, bootloader_erase_code(), page) print "E%d - Writing code" % paddr for address in range(0x1D006000, 0x1D03FFFB, 128): bytes = reader.get_bytes_12(address) power_communicator.do_command(paddr, bootloader_write_code(POWER_API_12_PORTS), *bytes) print "E%d - Jumping to application" % paddr power_communicator.do_command(paddr, bootloader_jump_application())
def bootload_energy_module(module_address, hex_file, power_communicator, version): """ Bootload a 12 port power module. :param module_address: The address of a power module (integer). :param hex_file: The filename of the hex file to write. :param power_communicator: Communication with the power modules. :param version: Version of the provided hexfile """ firmware_version, hardware_version = get_module_firmware_version( module_address, power_api.ENERGY_MODULE, power_communicator) logger.info('E{0} - Version: {1} ({2})'.format(module_address, firmware_version, hardware_version)) if firmware_version == version: logger.info('E{0} - Already up-to-date. Skipping') return logger.info('E{0} - Start bootloading'.format(module_address)) try: logger.info('E{0} - Reading calibration data'.format(module_address)) calibration_data = list( power_communicator.do_command(module_address, power_api.read_eeprom(12, 100), *[256, 100])) logger.info('E{0} - Calibration data: {1}'.format( module_address, ','.join([str(d) for d in calibration_data]))) except Exception as ex: logger.info('E{0} - Could not read calibration data: {1}'.format( module_address, ex)) calibration_data = None reader = HexReader(hex_file) logger.info('E{0} - Going to bootloader'.format(module_address)) power_communicator.do_command( module_address, power_api.bootloader_goto(power_api.ENERGY_MODULE), 10) logger.info('E{0} - Bootloader version: {1}'.format( module_address, get_module_firmware_version(module_address, power_api.ENERGY_MODULE, power_communicator))) try: logger.info('E{0} - Erasing code...'.format(module_address)) for page in range(6, 64): power_communicator.do_command(module_address, power_api.bootloader_erase_code(), page) logger.info('E{0} - Writing code...'.format(module_address)) for address in range(0x1D006000, 0x1D03FFFB, 128): data = reader.get_bytes_version_12(address) power_communicator.do_command( module_address, power_api.bootloader_write_code(power_api.ENERGY_MODULE), *data) finally: logger.info('E{0} - Jumping to application'.format(module_address)) power_communicator.do_command(module_address, power_api.bootloader_jump_application()) tries = 0 while True: try: tries += 1 logger.info( 'E{0} - Waiting for application...'.format(module_address)) logger.info('E{0} - Version: {1}'.format( module_address, get_module_firmware_version(module_address, power_api.ENERGY_MODULE, power_communicator))) break except Exception: if tries >= 3: raise time.sleep(1) if calibration_data is not None: time.sleep(1) logger.info('E{0} - Restoring calibration data'.format(module_address)) power_communicator.do_command(module_address, power_api.write_eeprom(12, 100), *([256] + calibration_data)) logger.info('E{0} - Done'.format(module_address))