-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
amit lissack
committed
Oct 23, 2021
1 parent
185be8d
commit c25c1e7
Showing
9 changed files
with
147 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 0 additions & 52 deletions
52
api/src/opentrons/hardware_control/emulation/run_module_emulator.py
This file was deleted.
Oops, something went wrong.
Empty file.
54 changes: 54 additions & 0 deletions
54
api/src/opentrons/hardware_control/emulation/scripts/run_app.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"""Script for starting up emulation up with module emulators.""" | ||
import logging | ||
import asyncio | ||
from argparse import ArgumentParser | ||
from typing import List | ||
|
||
from opentrons.hardware_control.emulation.app import Application | ||
from opentrons.hardware_control.emulation.scripts.run_module_emulator import ( | ||
emulator_builder, | ||
) | ||
from opentrons.hardware_control.emulation.settings import Settings | ||
from .run_module_emulator import run as run_module_by_name | ||
|
||
|
||
async def run(settings: Settings, modules: List[str]) -> None: | ||
"""Run the emulator app with connected module emulators. | ||
Args: | ||
settings: App settings. | ||
modules: The module emulators to start. | ||
Returns: | ||
None | ||
""" | ||
loop = asyncio.get_event_loop() | ||
|
||
app_task = loop.create_task(Application(settings=settings).run()) | ||
module_tasks = [ | ||
loop.create_task( | ||
run_module_by_name(settings=settings, emulator_name=n, host="localhost") | ||
) | ||
for n in modules | ||
] | ||
await asyncio.gather(app_task, *module_tasks) | ||
|
||
|
||
def main() -> None: | ||
"""Entry point.""" | ||
a = ArgumentParser() | ||
a.add_argument( | ||
"--m", | ||
action="append", | ||
choices=emulator_builder.keys(), | ||
help="which module(s) to emulate.", | ||
) | ||
args = a.parse_args() | ||
|
||
logging.basicConfig(format="%(asctime)s:%(message)s", level=logging.DEBUG) | ||
asyncio.run(run(Settings(), args.m)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
65 changes: 65 additions & 0 deletions
65
api/src/opentrons/hardware_control/emulation/scripts/run_module_emulator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
"""Script for starting up a python module emulator.""" | ||
import logging | ||
import asyncio | ||
from argparse import ArgumentParser | ||
from typing import Dict, Callable | ||
from typing_extensions import Final | ||
|
||
from opentrons.hardware_control.emulation.abstract_emulator import AbstractEmulator | ||
from opentrons.hardware_control.emulation.types import ModuleType | ||
from opentrons.hardware_control.emulation.magdeck import MagDeckEmulator | ||
from opentrons.hardware_control.emulation.parser import Parser | ||
from opentrons.hardware_control.emulation.tempdeck import TempDeckEmulator | ||
from opentrons.hardware_control.emulation.thermocycler import ThermocyclerEmulator | ||
|
||
|
||
from opentrons.hardware_control.emulation.run_emulator import run_emulator_client | ||
from opentrons.hardware_control.emulation.settings import Settings, ProxySettings | ||
|
||
emulator_builder: Final[Dict[str, Callable[[Settings], AbstractEmulator]]] = { | ||
ModuleType.Magnetic.value: lambda s: MagDeckEmulator(Parser()), | ||
ModuleType.Temperature.value: lambda s: TempDeckEmulator(Parser()), | ||
ModuleType.Thermocycler.value: lambda s: ThermocyclerEmulator(Parser()), | ||
} | ||
|
||
emulator_port: Final[Dict[str, Callable[[Settings], ProxySettings]]] = { | ||
ModuleType.Magnetic.value: lambda s: s.magdeck_proxy, | ||
ModuleType.Temperature.value: lambda s: s.temperature_proxy, | ||
ModuleType.Thermocycler.value: lambda s: s.thermocycler_proxy, | ||
} | ||
|
||
|
||
async def run(settings: Settings, emulator_name: str, host: str) -> None: | ||
"""Run an emulator. | ||
Args: | ||
settings: emulator settings | ||
emulator_name: Name of emulator. This must be a key in emulator_builder | ||
host: host to connect to. | ||
Returns: | ||
None | ||
""" | ||
e = emulator_builder[emulator_name](settings) | ||
proxy_settings = emulator_port[emulator_name](settings) | ||
await run_emulator_client(host, proxy_settings.emulator_port, e) | ||
|
||
|
||
def main() -> None: | ||
"""Entry point.""" | ||
a = ArgumentParser() | ||
a.add_argument( | ||
"emulator", | ||
type=str, | ||
choices=emulator_builder.keys(), | ||
help="which module to emulate.", | ||
) | ||
a.add_argument("host", type=str, help="the emulator host") | ||
args = a.parse_args() | ||
|
||
logging.basicConfig(format="%(asctime)s:%(message)s", level=logging.DEBUG) | ||
asyncio.run(run(Settings(), args.emulator, args.host)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from enum import Enum | ||
|
||
|
||
class ModuleType(str, Enum): | ||
"""Module type enumeration.""" | ||
|
||
Magnetic = "magnetic" | ||
Temperature = "temperature" | ||
Thermocycler = "thermocycler" | ||
Heatershaker = "heatershaker" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters