Skip to content

Commit

Permalink
feat(api): add module firmware update endpoint
Browse files Browse the repository at this point in the history
Closes #1654
  • Loading branch information
sanni-t committed Sep 7, 2018
1 parent 648118f commit 5f01e70
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
9 changes: 4 additions & 5 deletions api/opentrons/drivers/mag_deck/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,9 @@ def __init__(self, config={}):
self._plate_height = None
self._mag_position = None

def connect(self, port=None, baudrate=MAG_DECK_BAUDRATE) -> str:
def connect(self, port=None) -> str:
'''
:param port: '/dev/modules/ttyn_magdeck'
:param baudrate: MAG_DECK_BAUDRATE or 1200 for dfu
NOTE: Using the symlink above to connect makes sure that the robot
connects/reconnects to the module even after a device
reset/reconnection
Expand All @@ -168,7 +167,7 @@ def connect(self, port=None, baudrate=MAG_DECK_BAUDRATE) -> str:
return ''
try:
self.disconnect()
self._connect_to_port(port, baudrate)
self._connect_to_port(port)
self._wait_for_ack() # verify the device is there
except (SerialException, SerialNoResponse) as e:
return str(e)
Expand Down Expand Up @@ -327,13 +326,13 @@ def _send_command(self, command, timeout=DEFAULT_MAG_DECK_TIMEOUT):

return ret_code.strip()

def _connect_to_port(self, port=None, baudrate=MAG_DECK_BAUDRATE):
def _connect_to_port(self, port=None):
try:
mag_deck = environ.get('OT_MAG_DECK_ID')
self._connection = serial_communication.connect(
device_name=mag_deck,
port=port,
baudrate=baudrate
baudrate=MAG_DECK_BAUDRATE
)
except SerialException:
# if another process is using the port, pyserial raises an
Expand Down
26 changes: 14 additions & 12 deletions api/opentrons/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,13 @@ def discover_and_connect():

def enter_bootloader(module):
"""
Disconnect from current port, connect at 1200 baud and disconnect to
enter bootloader on a (possibly) different port. On disconnect, the
kernel could assign it a lower port number if available, or keep it on
the same port. So we check for changes in port assigned and use the
appropriate one
Using the driver method, enter bootloader mode of the atmega32u4. The bootloader mode opens a new port on the uC to
upload the hex file. After receiving a 'dfu' command, the firmware provides a 3-second window to close the
current port so as to do a clean switch to the bootloader port. The new port shows up as 'ttyn_bootloader' on the pi
Use this port to upload firmware
NOTE: Modules with old bootloader will have the bootloader port show up as a regular module port- 'ttyn_tempdeck'/
'ttyn_magdeck' with the port number being either different or same as the one that the module was originally on.
So we check for changes in ports and use the appropriate one
"""
ports_before_dfu_mode = discover_ports() # Required only for old bootloadr

Expand All @@ -107,10 +109,10 @@ def enter_bootloader(module):

async def update_firmware(module, firmware_file_path, config_file_path, loop):
"""
Enter bootloader then run avrdude firmware upload command. The kernel
could assign the module a new port after the update (since the board is
automatically reset). Scan for such a port change and use the
appropriate port
Run avrdude firmware upload command. Switch back to normal module port
Note: For modules with old bootloader, the kernel could assign the module a new port after the update
(since the board is automatically reset). Scan for such a port change and use the appropriate port
"""
# TODO: Make sure the module isn't in the middle of operation

Expand All @@ -124,7 +126,7 @@ async def update_firmware(module, firmware_file_path, config_file_path, loop):
'baudrate': '57600',
'firmware_file': firmware_file_path
}
proc = await asyncio.create_subprocess_shell(
proc = await asyncio.create_subprocess_exec(
'avrdude '
'-C{config_file} '
'-v -p{part_no} '
Expand Down Expand Up @@ -166,12 +168,12 @@ def port_on_mode_switch(ports_before_switch):
return new_port


def port_poll(has_old_bootloader, ports_before_switch=None):
def port_poll(old_bootloader, ports_before_switch=None):
"""
Checks for the bootloader port
"""
new_port = ''
if has_old_bootloader:
if old_bootloader:
new_port = port_on_mode_switch(ports_before_switch)
else:
discovered_ports = list(filter(
Expand Down
5 changes: 0 additions & 5 deletions api/opentrons/modules/magdeck.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import logging

from opentrons.drivers.mag_deck import MagDeck as MagDeckDriver
from opentrons import commands

LABWARE_ENGAGE_HEIGHT = {'biorad-hardshell-96-PCR': 18} # mm
MAX_ENGAGE_HEIGHT = 45 # mm from home position


log = logging.getLogger(__name__)


class MissingDevicePortError(Exception):
pass

Expand Down

0 comments on commit 5f01e70

Please sign in to comment.