Skip to content

Commit

Permalink
Remove custom serial monitors - bad design
Browse files Browse the repository at this point in the history
  • Loading branch information
Krisjanis Veinbahs committed Mar 12, 2022
1 parent 197f6f0 commit 76ab43b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 30 deletions.
16 changes: 1 addition & 15 deletions client/src/monitor/monitor_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class MonitorType(Enum):
"""Choices of available monitor implementations"""
hexbytes = 0
buttonleds = 1
script = 2

@staticmethod
def build(value: str) -> Result['MonitorType', MonitorTypeBuildError]:
Expand All @@ -53,25 +52,12 @@ def build(value: str) -> Result['MonitorType', MonitorTypeBuildError]:

def resolve(
self,
socket: SocketInterface,
monitor_script_path: Optional[ExistingFilePath]
socket: SocketInterface
) -> Result[MonitorSerial, MonitorResolutionError]:
# Monitor implementation resolution
monitor: Optional[MonitorSerial] = None
if self is MonitorType.hexbytes:
monitor = MonitorSerialHexbytes(MonitorSerialHelper(), socket)
elif self is MonitorType.buttonleds:
monitor = MonitorSerialButtonLedBytes(MonitorSerialHelper(), socket)
elif self is MonitorType.script:
# Script file path
if monitor_script_path is None:
return Err(MonitorResolutionError(f"Monitor script path is required"))
# Script file import
script_result = pymodules.import_path_module(monitor_script_path.value)
if isinstance(script_result, Err):
return Err(MonitorResolutionError(f"Monitor script could not be imported", reason=script_result.value))
# Script method import
if not hasattr(script_result.value, 'monitor'):
return Err(MonitorResolutionError(f"Monitor script does not contain attribute 'monitor'"))
monitor = script_result.value.monitor
return Ok(monitor)
8 changes: 3 additions & 5 deletions client/src/service/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ def hardware_serial_monitor(
config_path_str: Optional[str],
control_server_str: Optional[str],
hardware_id_str: str,
monitor_type_str: str,
monitor_script_path_str: Optional[str]
monitor_type_str: str
):
pass

Expand Down Expand Up @@ -746,8 +745,7 @@ def hardware_serial_monitor(
config_path_str: Optional[str],
control_server_str: Optional[str],
hardware_id_str: str,
monitor_type_str: str,
monitor_script_path_str: Optional[str]
monitor_type_str: str
) -> Result[MonitorSerial, DIPClientError]:
# Build backend
backend_result = CLI.parsed_backend(config_path_str, control_server_str, None, None, None)
Expand All @@ -770,7 +768,7 @@ def hardware_serial_monitor(
decoder = s11n_hybrid.MONITOR_LISTENER_INCOMING_MESSAGE_DECODER
encoder = s11n_hybrid.MONITOR_LISTENER_OUTGOING_MESSAGE_ENCODER
websocket = WebSocket(url_result.value, decoder, encoder)
return monitor_serial.resolve(websocket, monitor_script_path_str)
return monitor_serial.resolve(websocket)

@staticmethod
async def quick_run(
Expand Down
12 changes: 2 additions & 10 deletions client/src/service/click.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@
"--monitor-type", "-t", "monitor_type_str", type=click.Choice([t.name for t in MonitorType]),
show_envvar=True, envvar=f"{ENV_PREFIX}_MONITOR_TYPE", required=False, default=MonitorType.buttonleds.name,
help="Sets the type of monitor implementation to be used")
MONITOR_SCRIPT_PATH_OPTION = click.option(
"--monitor-script-path", "-s", "monitor_script_path_str", type=str, default=None,
show_envvar=True, envvar=f"{ENV_PREFIX}_MONITOR_SCRIPT_PATH", required=False,
help="File path to the monitor implementation script e.g. './monitor-script.py'")


# Formatting
JSON_OUTPUT_OPTION = click.option(
Expand Down Expand Up @@ -562,22 +557,19 @@ def hardware_software_upload(
@CONTROL_SERVER_OPTION
@HARDWARE_ID_OPTION
@MONITOR_TYPE_OPTION
@MONITOR_SCRIPT_PATH_OPTION
def hardware_serial_monitor(
config_path_str: Optional[str],
control_server_str: Optional[str],
hardware_id_str: str,
monitor_type_str: str,
monitor_script_path_str: str
monitor_type_str: str
):
"""Monitor hardware's serial port"""
async def exec():
await CLI.execute_runnable_result(CLI.hardware_serial_monitor(
config_path_str,
control_server_str,
hardware_id_str,
monitor_type_str,
monitor_script_path_str), "Finished monitoring")
monitor_type_str), "Finished monitoring")
asyncio.run(exec())


Expand Down

0 comments on commit 76ab43b

Please sign in to comment.