def flash(self, firmware_path=None): """ Flash the given firmware on Leonardo node :param firmware_path: Path to the firmware to be flashed on `node`. If None, flash 'idle' firmware """ if AvrDude.trigger_bootloader(self.TTY, self.TTY_PROG, timeout=15): LOGGER.error("FLASH : Leonardo's jtag port not available") return 1 ret_val = 0 firmware_path = firmware_path or self.FW_IDLE LOGGER.info('Flash firmware on Leonardo: %s', firmware_path) ret_val += self.avrdude.flash(firmware_path) ret_val += common.wait_tty(self.TTY, LOGGER, self.TTY_RESTORE_TIME) return ret_val
def flash(self, firmware_path=None, binary=False, offset=0): """ Flash the given firmware on Leonardo node :param firmware_path: Path to the firmware to be flashed on `node`. If None, flash 'idle' firmware :param binary: whether to flash a binary file :param offset: at which offset to flash the binary file """ if AvrDude.trigger_bootloader(self.TTY, self.TTY_PROG, timeout=15): LOGGER.error("FLASH : Leonardo's jtag port not available") return 1 if binary: LOGGER.error('FLASH: binary mode not supported with Leonardo') return 1 if offset != 0: LOGGER.error('FLASH: flash offset is not supported with Leonardo') return 1 ret_val = 0 firmware_path = firmware_path or self.FW_IDLE LOGGER.info('Flash firmware on Leonardo: %s', firmware_path) ret_val += self.avrdude.flash(firmware_path) ret_val += common.wait_tty(self.TTY, LOGGER, self.TTY_RESTORE_TIME) return ret_val
def __init__(self): self.serial_redirection = SerialRedirection(self.TTY, self.BAUDRATE) self.avrdude = AvrDude(self.AVRDUDE_CONF)
class NodeZigduino(OpenNodeBase): """Open node Zigduino implementation.""" TYPE = "zigduino" ELF_TARGET = ('ELFCLASS32', 'EM_AVR') TTY = '/dev/iotlab/ttyON_ZIGDUINO' BAUDRATE = 57600 FW_IDLE = static_path('zigduino_idle.elf') FW_AUTOTEST = static_path('zigduino_autotest.elf') AVRDUDE_CONF = { 'tty': TTY, 'baudrate': 57600, 'model': 'atmega128rfa1', 'programmer': 'arduino', } AUTOTEST_AVAILABLE = [ 'echo', 'get_time' # mandatory ] ALIM = '5V' def __init__(self): self.serial_redirection = SerialRedirection(self.TTY, self.BAUDRATE) self.avrdude = AvrDude(self.AVRDUDE_CONF) def disable_dtr(self): """ Disable serial port DTR in order to avoid board autoreset at first connection """ # Check if Zigduino is up before DTR reset try: ser = serial.Serial(self.TTY, self.BAUDRATE) except SerialException: LOGGER.error("No serial port found") return 1 with open(self.TTY) as ser: attrs = termios.tcgetattr(ser) attrs[2] = attrs[2] & ~termios.HUPCL termios.tcsetattr(ser, termios.TCSAFLUSH, attrs) return 0 @logger_call("Setup of Zigduino node") def setup(self, firmware_path): """ Flash open node, create serial redirection """ ret_val = 0 # it appears that /dev/ttyON_ZIGDUINO need some time to be detected common.wait_no_tty(self.TTY, timeout=common.TTY_DETECT_TIME) ret_val += common.wait_tty(self.TTY, LOGGER, timeout=common.TTY_DETECT_TIME) ret_val += self.flash(firmware_path, redirect=False) ret_val += self.disable_dtr() ret_val += self.serial_redirection.start() return ret_val @logger_call("Teardown of Zigduino node") def teardown(self): """ Stop serial redirection and flash idle firmware """ ret_val = 0 common.wait_no_tty(self.TTY, timeout=common.TTY_DETECT_TIME) ret_val += common.wait_tty(self.TTY, LOGGER, timeout=common.TTY_DETECT_TIME) ret_val += self.serial_redirection.stop() # Reboot needs 8 seconds before ending linux sees it in < 2 seconds ret_val += common.wait_tty(self.TTY, LOGGER, timeout=10) ret_val += self.flash(None, redirect=False) return ret_val @logger_call("Flash of Zigduino node") def flash(self, firmware_path=None, redirect=True): """ Flash the given firmware on Zigduino node :param firmware_path: Path to the firmware to be flashed on `node`. If None, flash 'idle' firmware """ ret_val = 0 firmware_path = firmware_path or self.FW_IDLE LOGGER.info('Flash firmware on Zigduino: %s', firmware_path) # First stop serial redirection, flash hangup if an # user session is openened on port 20000 common.wait_no_tty(self.TTY, timeout=common.TTY_DETECT_TIME) ret_val += common.wait_tty(self.TTY, LOGGER, timeout=common.TTY_DETECT_TIME) if redirect: ret_val += self.serial_redirection.stop() # Then flash ret_val += self.avrdude.flash(firmware_path) ret_val += common.wait_tty(self.TTY, LOGGER, timeout=10) # Finally restore serial redirection if redirect: ret_val += self.disable_dtr() ret_val += self.serial_redirection.start() LOGGER.info("end flash") return ret_val @logger_call("Reset of Zigduino node") def reset(self): """ Reset the Zigduino node using DTR""" ret_val = 0 # Check if Zigduino is up before DTR reset try: ser = serial.Serial(self.TTY, self.BAUDRATE) except SerialException: LOGGER.error("No serial port found") return 1 try: ser.setDTR(False) time.sleep(0.5) ser.setDTR(True) time.sleep(0.5) ser.close() except OSError: LOGGER.warning("Nothing to reset") ret_val += common.wait_tty(self.TTY, LOGGER, timeout=10) return ret_val @staticmethod def status(): """ Check Zigduino node status """ # It's impossible for us to check the status of the zigduino node return 0
class NodeLeonardo(OpenNodeBase): """ Open node Leonardo implementation """ TYPE = 'leonardo' ELF_TARGET = ('ELFCLASS32', 'EM_AVR') TTY = '/dev/iotlab/ttyON_LEONARDO' # The Leonardo node need a special open/close and then appear on a new TTY TTY_PROG = '/dev/ttyON_LEONARDO_PROG' # Regular TTY will be restored after 8 seconds TTY_RESTORE_TIME = 8 + common.TTY_DETECT_TIME TTY_READY_DELAY = 1 BAUDRATE = 9600 FW_IDLE = static_path('leonardo_idle.elf') FW_AUTOTEST = static_path('leonardo_autotest.elf') AVRDUDE_CONF = { 'tty': TTY_PROG, 'baudrate': 9600, 'model': 'atmega32u4', 'programmer': 'avr109', } AUTOTEST_AVAILABLE = [ 'echo', 'get_time', # mandatory 'get_uid', ] ALIM = '5V' def __init__(self): self.serial_redirection = SerialRedirection(self.TTY, self.BAUDRATE) self.avrdude = AvrDude(self.AVRDUDE_CONF) @logger_call("Node Leonardo : Setup of leonardo node") def setup(self, firmware_path): """ Flash open node, create serial redirection """ ret_val = 0 ret_val += self._wait_tty_ready() ret_val += self.flash(firmware_path) ret_val += self.serial_redirection.start() return ret_val @logger_call("Node Leonardo : Teardown of leonardo node") def teardown(self): """ Stop serial redirection and flash idle firmware """ ret_val = 0 ret_val += self._wait_tty_ready() ret_val += self.serial_redirection.stop() ret_val += self.flash(None) return ret_val @logger_call("Node Leonardo : Flash of leonardo node") def flash(self, firmware_path=None, binary=False, offset=0): """ Flash the given firmware on Leonardo node :param firmware_path: Path to the firmware to be flashed on `node`. If None, flash 'idle' firmware :param binary: whether to flash a binary file :param offset: at which offset to flash the binary file """ if AvrDude.trigger_bootloader(self.TTY, self.TTY_PROG, timeout=15): LOGGER.error("FLASH : Leonardo's jtag port not available") return 1 if binary: LOGGER.error('FLASH: binary mode not supported with Leonardo') return 1 if offset != 0: LOGGER.error('FLASH: flash offset is not supported with Leonardo') return 1 ret_val = 0 firmware_path = firmware_path or self.FW_IDLE LOGGER.info('Flash firmware on Leonardo: %s', firmware_path) ret_val += self.avrdude.flash(firmware_path) ret_val += common.wait_tty(self.TTY, LOGGER, self.TTY_RESTORE_TIME) return ret_val @logger_call("Node Leonardo : Reset of leonardo node") def reset(self): """ Reset the Leonardo node using jtag """ ret_val = 0 ret_val += AvrDude.trigger_bootloader(self.TTY, self.TTY_PROG) ret_val += common.wait_tty(self.TTY, LOGGER, self.TTY_RESTORE_TIME) return ret_val @staticmethod def status(): """ Check Leonardo node status """ # It's impossible for us to check the status of the leonardo node return 0 def _wait_tty_ready(self): """Wait that the tty is ready to use. Node may have been stopped at the end of the experiment. And then restarted again in cn teardown. This leads to problem where the TTY disappears and reappears during the first 2 seconds. So let some time if it wants to disappear first. Also, got some problems when using the tty directly after appearing, so git it some delay. """ common.wait_no_tty(self.TTY) ret = common.wait_tty(self.TTY, LOGGER) # wait tty ready to speak time.sleep(self.TTY_READY_DELAY) return ret
def reset(self): """ Reset the Leonardo node using jtag """ ret_val = 0 ret_val += AvrDude.trigger_bootloader(self.TTY, self.TTY_PROG) ret_val += common.wait_tty(self.TTY, LOGGER, self.TTY_RESTORE_TIME) return ret_val
class NodeLeonardo(object): """ Open node Leonardo implemention """ TYPE = 'leonardo' ELF_TARGET = ('ELFCLASS32', 'EM_AVR') TTY = '/dev/ttyON_LEONARDO' # The Leonardo node need a special open/close and then appear on a new TTY TTY_PROG = '/dev/ttyON_LEONARDO_PROG' # Regular TTY will be restored after 8 seconds TTY_RESTORE_TIME = 8 + common.TTY_DETECT_TIME TTY_READY_DELAY = 1 BAUDRATE = 9600 FW_IDLE = static_path('idle_leonardo.elf') FW_AUTOTEST = static_path('leonardo_autotest.elf') AVRDUDE_CONF = { 'tty': TTY_PROG, 'baudrate': 9600, 'model': 'atmega32u4', 'programmer': 'avr109', } AUTOTEST_AVAILABLE = [ 'echo', 'get_time', # mandatory 'get_uid', ] ALIM = '5V' def __init__(self): self.serial_redirection = SerialRedirection(self.TTY, self.BAUDRATE) self.avrdude = AvrDude(self.AVRDUDE_CONF) @logger_call("Node Leonardo : Setup of leonardo node") def setup(self, firmware_path): """ Flash open node, create serial redirection """ ret_val = 0 ret_val += self._wait_tty_ready() ret_val += self.flash(firmware_path) ret_val += self.serial_redirection.start() return ret_val @logger_call("Node Leonardo : Teardown of leonardo node") def teardown(self): """ Stop serial redirection and flash idle firmware """ ret_val = 0 ret_val += self._wait_tty_ready() ret_val += self.serial_redirection.stop() ret_val += self.flash(None) return ret_val @logger_call("Node Leonardo : Flash of leonardo node") def flash(self, firmware_path=None): """ Flash the given firmware on Leonardo node :param firmware_path: Path to the firmware to be flashed on `node`. If None, flash 'idle' firmware """ if AvrDude.trigger_bootloader(self.TTY, self.TTY_PROG, timeout=15): LOGGER.error("FLASH : Leonardo's jtag port not available") return 1 ret_val = 0 firmware_path = firmware_path or self.FW_IDLE LOGGER.info('Flash firmware on Leonardo: %s', firmware_path) ret_val += self.avrdude.flash(firmware_path) ret_val += common.wait_tty(self.TTY, LOGGER, self.TTY_RESTORE_TIME) return ret_val @logger_call("Node Leonardo : Reset of leonardo node") def reset(self): """ Reset the Leonardo node using jtag """ ret_val = 0 ret_val += AvrDude.trigger_bootloader(self.TTY, self.TTY_PROG) ret_val += common.wait_tty(self.TTY, LOGGER, self.TTY_RESTORE_TIME) return ret_val @staticmethod def status(): """ Check Leonardo node status """ # It's impossible for us to check the status of the leonardo node return 0 def _wait_tty_ready(self): """Wait that the tty is ready to use. Node may have been stopped at the end of the experiment. And then restarted again in cn teardown. This leads to problem where the TTY disappears and reappears during the first 2 seconds. So let some time if it wants to disappear first. Also, got some problems when using the tty directly after appearing, so git it some delay. """ common.wait_no_tty(self.TTY) ret = common.wait_tty(self.TTY, LOGGER) # wait tty ready to speak time.sleep(self.TTY_READY_DELAY) return ret