Skip to content

Commit

Permalink
fix: fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
YarikRevich committed Apr 8, 2024
1 parent bad3a4e commit 2c6b8ac
Show file tree
Hide file tree
Showing 9 changed files with 367 additions and 158 deletions.
9 changes: 9 additions & 0 deletions Core/External/Tools/Indicator/indicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ void Indicator::toggle_action_success() {
HAL_Delay(2000);
};

void Indicator::toggle_action_failure() {
for (int i = 0; i < 4; i++) {
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
HAL_Delay(200);
}

HAL_Delay(1000);
};

void Indicator::toggle_invalid_request() {
for (int i = 0; i < 2; i++) {
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
Expand Down
5 changes: 5 additions & 0 deletions Core/External/Tools/Indicator/indicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class Indicator {
*/
static void toggle_action_success();

/**
* Indicated operation action failure.
*/
static void toggle_action_failure();

/**
* Indicated invalid incoming request.
*/
Expand Down
318 changes: 192 additions & 126 deletions Scripts/cli/src/client/client.py

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions Scripts/cli/src/command/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from typing import Optional

from .get_available_devices import GetAvailableDevicesCommand
from .get_data import GetDataCommand
from .get_info import GetInfoCommand
from .set_settings import SetSettingsCommand
from visualizer import Visualizer


class BaseCommand:
Expand All @@ -14,7 +18,7 @@ def get_available_devices() -> None:

@staticmethod
def get_data(device: str, baud_rate: int, type: str, series: int = 1, export: str = None, generate: bool = False,
figure: str = "scatter") -> None:
figure: str = Visualizer.PLOT_FIGURE) -> None:
"""
Returns sensor data of selected type. The available data types are 'raw', 'full', 'infrared', 'visible'.
Allows to perform a series of measurements and export that data to a graph view. The available figure types are
Expand All @@ -33,10 +37,12 @@ def get_info(device: str, baud_rate: int, type: str) -> None:
GetInfoCommand.handle(device, baud_rate, type)

@staticmethod
def set_settings(device: str, baud_rate: int, type: str) -> None:
def set_settings(device: str, baud_rate: int, type: str, value: Optional[str]) -> None:
"""
Returns selected metadata info retrieved from the board.
The available info types are 'gain', 'integral_time', 'processed_requests'
Sets given settings to the board.
The available settings types are 'reset', 'set_gain'(with values 'low', 'medium', 'high', 'max'),
'set_integral_time'(with values 'first'(100ms), 'second'(200ms), 'third'(300ms), 'forth'(400ms), 'fifth'(500mx),
'sixth'(600ms)).
"""

GetInfoCommand.handle(device, baud_rate, type)
SetSettingsCommand.handle(device, baud_rate, type, value)
2 changes: 1 addition & 1 deletion Scripts/cli/src/command/get_available_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class GetAvailableDevicesCommand:
"""Represents 'get_available_devices' command."""

@staticmethod
def handle():
def handle() -> None:
"""Handles the execution of command wrapper."""

result = []
Expand Down
2 changes: 1 addition & 1 deletion Scripts/cli/src/command/get_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class GetDataCommand:
VISIBLE_TYPE: str = "visible"

@staticmethod
def handle(device: str, baud_rate: int, type: str, series: int, export: str, generate: bool, figure: str):
def handle(device: str, baud_rate: int, type: str, series: int, export: str, generate: bool, figure: str) -> None:
"""Handles the execution of command wrapper."""

if not is_device_available(device):
Expand Down
2 changes: 1 addition & 1 deletion Scripts/cli/src/command/get_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GetInfoCommand:
DEVICE_AVAILABLE_TYPE: str = "device_available"

@staticmethod
def handle(device: str, baud_rate: int, type: str):
def handle(device: str, baud_rate: int, type: str) -> None:
"""Handles the execution of command wrapper."""

if not is_device_available(device):
Expand Down
163 changes: 146 additions & 17 deletions Scripts/cli/src/command/set_settings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import logging
from typing import Optional

from middleware import is_device_available
from dto import RetrievedInfoDto
from dto import SetSettingsDto
from client import Client
from tools import print_output

Expand All @@ -12,31 +13,103 @@ class SetSettingsCommand:
# 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 'set_gain' type of the setting.
SET_GAIN_TYPE: str = "set_gain"

# Represents 'integral_time' type of the setting.
SET_INTEGRAL_TIME_TYPE: str = "integral_time"
# Represents 'low' type of value for 'set_gain' type of setting.
SET_GAIN_LOW_VALUE_TYPE: str = "low"

# Represents 'medium' type of value for 'set_gain' type of setting.
SET_GAIN_MEDIUM_VALUE_TYPE: str = "medium"

# Represents 'high' type of value for 'set_gain' type of setting.
SET_GAIN_HIGH_VALUE_TYPE: str = "high"

# Represents 'max' type of value for 'set_gain' type of setting.
SET_GAIN_MAX_VALUE_TYPE: str = "max"

# Represents 'set_integral_time' type of the setting.
SET_INTEGRAL_TIME_TYPE: str = "set_integral_time"

# Represents 'first' type of value for 'set_integral_time' type of setting.
SET_INTEGRAL_TIME_FIRST_VALUE_TYPE: str = "first"

# Represents 'second' type of value for 'set_integral_time' type of setting.
SET_INTEGRAL_TIME_SECOND_VALUE_TYPE: str = "second"

# Represents 'third' type of value for 'set_integral_time' type of setting.
SET_INTEGRAL_TIME_THIRD_VALUE_TYPE: str = "third"

# Represents 'forth' type of value for 'set_integral_time' type of setting.
SET_INTEGRAL_TIME_FORTH_VALUE_TYPE: str = "forth"

# Represents 'fifth' type of value for 'set_integral_time' type of setting.
SET_INTEGRAL_TIME_FIFTH_VALUE_TYPE: str = "fifth"

# Represents 'sixth' type of value for 'set_integral_time' type of setting.
SET_INTEGRAL_TIME_SIXTH_VALUE_TYPE: str = "sixth"

@staticmethod
def handle(device: str, baud_rate: int, type: str):
def handle(device: str, baud_rate: int, type: str, value: Optional[str]) -> None:
"""Handles the execution of command wrapper."""

if not is_device_available(device):
logging.error("Selected device is not available")
return

data: RetrievedInfoDto
data: SetSettingsDto

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)
match value:
case SetSettingsCommand.SET_GAIN_LOW_VALUE_TYPE:
data = SetSettingsCommand.process_set_gain_low_settings(device, baud_rate)

case SetSettingsCommand.SET_GAIN_MEDIUM_VALUE_TYPE:
data = SetSettingsCommand.process_set_gain_medium_settings(device, baud_rate)

case SetSettingsCommand.SET_GAIN_HIGH_VALUE_TYPE:
data = SetSettingsCommand.process_set_gain_high_settings(device, baud_rate)

case SetSettingsCommand.SET_GAIN_MAX_VALUE_TYPE:
data = SetSettingsCommand.process_set_gain_max_settings(device, baud_rate)

case _:
logging.error("Given settings value type is not valid.")
return

case SetSettingsCommand.SET_INTEGRAL_TIME_TYPE:
data = SetSettingsCommand.process_set_integral_time_settings(device, baud_rate)
match value:
case SetSettingsCommand.SET_INTEGRAL_TIME_FIRST_VALUE_TYPE:
data = SetSettingsCommand.process_set_integral_time_first_settings(
device, baud_rate)

case SetSettingsCommand.SET_INTEGRAL_TIME_SECOND_VALUE_TYPE:
data = SetSettingsCommand.process_set_integral_time_second_settings(
device, baud_rate)

case SetSettingsCommand.SET_INTEGRAL_TIME_THIRD_VALUE_TYPE:
data = SetSettingsCommand.process_set_integral_time_third_settings(
device, baud_rate)

case SetSettingsCommand.SET_INTEGRAL_TIME_FORTH_VALUE_TYPE:
data = SetSettingsCommand.process_set_integral_time_forth_settings(
device, baud_rate)

case SetSettingsCommand.SET_INTEGRAL_TIME_FIFTH_VALUE_TYPE:
data = SetSettingsCommand.process_set_integral_time_fifth_settings(
device, baud_rate)

case SetSettingsCommand.SET_INTEGRAL_TIME_SIXTH_VALUE_TYPE:
data = SetSettingsCommand.process_set_integral_time_sixth_settings(
device, baud_rate)

case _:
logging.error("Given settings value type is not valid.")
return

case _:
logging.error("Given settings type is not valid.")
Expand All @@ -46,22 +119,78 @@ def handle(device: str, baud_rate: int, type: str):
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"""
def process_reset_settings(device: str, baud_rate: int) -> SetSettingsDto:
"""Processes request to set 'reset' setting to 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"""
def process_set_gain_low_settings(device: str, baud_rate: int) -> SetSettingsDto:
"""Processes request to set 'set_gain' with 'low' value setting to the device."""

with Client(device, baud_rate) as client:
return client.send_settings_bus_request_set_gain_low_settings_type_content()

@staticmethod
def process_set_gain_medium_settings(device: str, baud_rate: int) -> SetSettingsDto:
"""Processes request to set 'set_gain' with 'medium' value setting to the device."""

with Client(device, baud_rate) as client:
return client.send_settings_bus_request_set_gain_medium_settings_type_content()

@staticmethod
def process_set_gain_high_settings(device: str, baud_rate: int) -> SetSettingsDto:
"""Processes request to set 'set_gain' with 'high' value setting to the device."""

with Client(device, baud_rate) as client:
return client.send_settings_bus_request_set_gain_high_settings_type_content()

@staticmethod
def process_set_gain_max_settings(device: str, baud_rate: int) -> SetSettingsDto:
"""Processes request to set 'set_gain' with 'max' value setting to the device."""

with Client(device, baud_rate) as client:
return client.send_settings_bus_request_set_gain_max_settings_type_content()

@staticmethod
def process_set_integral_time_first_settings(device: str, baud_rate: int) -> SetSettingsDto:
"""Processes request to set 'set_integral_time' with 'first' value setting to the device."""

with Client(device, baud_rate) as client:
return client.send_settings_bus_request_set_integral_time_first_settings_type_content()

@staticmethod
def process_set_integral_time_second_settings(device: str, baud_rate: int) -> SetSettingsDto:
"""Processes request to set 'set_integral_time' with 'second' value setting to the device."""

with Client(device, baud_rate) as client:
return client.send_settings_bus_request_set_integral_time_second_settings_type_content()

@staticmethod
def process_set_integral_time_third_settings(device: str, baud_rate: int) -> SetSettingsDto:
"""Processes request to set 'set_integral_time' with 'third' value setting to the device."""

with Client(device, baud_rate) as client:
return client.send_settings_bus_request_set_integral_time_third_settings_type_content()

@staticmethod
def process_set_integral_time_forth_settings(device: str, baud_rate: int) -> SetSettingsDto:
"""Processes request to set 'set_integral_time' with 'forth' value setting to the device."""

with Client(device, baud_rate) as client:
return client.send_settings_bus_request_set_integral_time_forth_settings_type_content()

@staticmethod
def process_set_integral_time_fifth_settings(device: str, baud_rate: int) -> SetSettingsDto:
"""Processes request to set 'set_integral_time' with 'fifth' value setting to the device."""

with Client(device, baud_rate) as client:
return client.send_info_bus_request_integral_time_info_type_content()
return client.send_settings_bus_request_set_integral_time_fifth_settings_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"""
def process_set_integral_time_sixth_settings(device: str, baud_rate: int) -> SetSettingsDto:
"""Processes request to set 'set_integral_time' with 'sixth' value setting to the device."""

with Client(device, baud_rate) as client:
return client.send_info_bus_request_processed_requests_info_type_content()
return client.send_settings_bus_request_set_integral_time_sixth_settings_type_content()
8 changes: 1 addition & 7 deletions Scripts/cli/src/dto/set_settings_dto.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
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."""

Expand All @@ -25,7 +19,7 @@ class SetSettingsDto:
settings_type: SettingsTypeCompound

# Represents result of the received result.
result: int
result: bool

# Represents nonce of the received result.
nonce: int
Expand Down

0 comments on commit 2c6b8ac

Please sign in to comment.