-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
abcdb31
commit 673e3a9
Showing
8 changed files
with
167 additions
and
44 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
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,67 @@ | ||
import logging | ||
|
||
from middleware import is_device_available | ||
from dto import RetrievedInfoDto | ||
from client import Client | ||
from tools import print_output | ||
|
||
|
||
class SetSettingsCommand: | ||
"""Represents 'set_settings' command.""" | ||
|
||
# Represents 'reset' type of the setting(does not allow any value). | ||
RESET_TYPE: str = "reset" | ||
|
||
# Represents 'gain' type of the setting. | ||
SET_GAIN_TYPE: str = "gain" | ||
|
||
# Represents 'integral_time' type of the setting. | ||
SET_INTEGRAL_TIME_TYPE: str = "integral_time" | ||
|
||
@staticmethod | ||
def handle(device: str, baud_rate: int, type: str): | ||
"""Handles the execution of command wrapper.""" | ||
|
||
if not is_device_available(device): | ||
logging.error("Selected device is not available") | ||
return | ||
|
||
data: RetrievedInfoDto | ||
|
||
match type: | ||
case SetSettingsCommand.RESET_TYPE: | ||
data = SetSettingsCommand.process_reset_settings(device, baud_rate) | ||
|
||
case SetSettingsCommand.SET_GAIN_TYPE: | ||
data = SetSettingsCommand.process_set_gain_settings(device, baud_rate) | ||
|
||
case SetSettingsCommand.SET_INTEGRAL_TIME_TYPE: | ||
data = SetSettingsCommand.process_set_integral_time_settings(device, baud_rate) | ||
|
||
case _: | ||
logging.error("Given settings type is not valid.") | ||
return | ||
|
||
print_output(data) | ||
logging.info("Settings has been successfully set.") | ||
|
||
@staticmethod | ||
def process_reset_settings(device: str, baud_rate: int) -> RetrievedInfoDto: | ||
"""Processes request to retrieve 'reset' metadata info from the device""" | ||
|
||
with Client(device, baud_rate) as client: | ||
return client.send_info_bus_request_gain_info_type_content() | ||
|
||
@staticmethod | ||
def process_set_gain_settings(device: str, baud_rate: int) -> RetrievedInfoDto: | ||
"""Processes request to retrieve 'integral_time' metadata info from the device""" | ||
|
||
with Client(device, baud_rate) as client: | ||
return client.send_info_bus_request_integral_time_info_type_content() | ||
|
||
@staticmethod | ||
def process_set_integral_time_settings(device: str, baud_rate: int) -> RetrievedInfoDto: | ||
"""Processes request to retrieve 'processed_requests' metadata info from the device""" | ||
|
||
with Client(device, baud_rate) as client: | ||
return client.send_info_bus_request_processed_requests_info_type_content() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from enum import Enum | ||
|
||
|
||
# uint32 deviceId = 1; | ||
# SettingsType settingsType = 2; | ||
# bool result = 3; | ||
# uint32 nonce = 4; | ||
|
||
|
||
class SettingsTypeCompound(Enum): | ||
"""Represents settings compound used to represent result settings type.""" | ||
|
||
RESET = 'Reset' | ||
SET_GAIN = 'SetGain' | ||
SET_INTEGRAL_TIME = 'SetIntegralTime' | ||
|
||
|
||
class SetSettingsDto: | ||
"""Represents dto used to hold the result of a 'set_settings' command.""" | ||
|
||
# Represents remote device identification number. | ||
device_id: int | ||
|
||
# Represents settings type of the received result. | ||
settings_type: SettingsTypeCompound | ||
|
||
# Represents result of the received result. | ||
result: int | ||
|
||
# Represents nonce of the received result. | ||
nonce: int | ||
|
||
def __init__(self, device_id: int, settings_type: SettingsTypeCompound, result: bool, nonce: int): | ||
self.device_id = device_id | ||
self.settings_type = settings_type | ||
self.result = result | ||
self.nonce = nonce |
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