From 4500e8b3a2a7b54eaa260a9a86940d34c385bdb8 Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Wed, 3 Apr 2024 16:43:54 +0200 Subject: [PATCH] feature: added cli script base --- .gitignore | 6 +- Core/External/Proto/Helper/proto_helper.cpp | 25 +++++++ Core/External/Proto/Helper/proto_helper.h | 52 +++++++++++++ .../Scheduler/Handler/scheduler_handler.cpp | 69 +++++++++++++++++- .../Scheduler/Handler/scheduler_handler.h | 45 ++++++++++++ Makefile | 2 +- README.md | 12 ++- Resources/Proto/Container/Content/info.proto | 1 + Scripts/{graph => }/__init__.py | 0 Scripts/cli/Makefile | 37 ++++++++++ Scripts/cli/README.md | 39 ++++++++++ Scripts/cli/__init__.py | 0 .../{graph => cli}/proto/Content/data_pb2.py | 0 .../{graph => cli}/proto/Content/info_pb2.py | 0 .../proto/Content/settings_pb2.py | 0 Scripts/{graph => cli}/proto/data_pb2.py | 0 Scripts/{graph => cli}/proto/info_pb2.py | 0 Scripts/{graph => cli}/proto/request_pb2.py | 0 Scripts/{graph => cli}/proto/response_pb2.py | 0 Scripts/{graph => cli}/proto/settings_pb2.py | 0 Scripts/cli/requirements.txt | 12 +++ Scripts/cli/setup.py | 48 ++++++++++++ Scripts/cli/src/__init__.py | 0 Scripts/cli/src/__main__.py | 6 ++ .../src/__pycache__/__init__.cpython-312.pyc | Bin 0 -> 201 bytes .../cli/src/__pycache__/cli.cpython-312.pyc | Bin 0 -> 473 bytes Scripts/cli/src/cli.py | 9 +++ Scripts/cli/src/command/__init__.py | 1 + .../__pycache__/__init__.cpython-312.pyc | Bin 0 -> 247 bytes .../command/__pycache__/base.cpython-312.pyc | Bin 0 -> 915 bytes .../list_available_devices.cpython-312.pyc | Bin 0 -> 799 bytes Scripts/cli/src/command/base.py | 33 +++++++++ Scripts/cli/src/command/get_data_once.py | 0 Scripts/cli/src/command/get_data_series.py | 0 Scripts/cli/src/command/get_info.py | 7 ++ .../cli/src/command/list_available_devices.py | 11 +++ Scripts/cli/src/command/set_settings.py | 0 Scripts/cli/src/compatibility/__init__.py | 2 + .../cli/src/compatibility/campatibility.py | 13 ++++ Scripts/cli/src/dto/__init__.py | 1 + .../dto/__pycache__/__init__.cpython-312.pyc | Bin 0 -> 268 bytes .../available_devices_dto.cpython-312.pyc | Bin 0 -> 640 bytes Scripts/cli/src/dto/available_devices_dto.py | 5 ++ Scripts/cli/src/graph/__init__.py | 0 .../{graph/main.py => cli/src/graph/graph.py} | 11 +-- Scripts/cli/src/tools/__init__.py | 1 + .../__pycache__/__init__.cpython-312.pyc | Bin 0 -> 252 bytes .../__pycache__/prettifier.cpython-312.pyc | Bin 0 -> 551 bytes Scripts/cli/src/tools/prettifier.py | 7 ++ light_detector.ioc | 13 ++-- 50 files changed, 451 insertions(+), 17 deletions(-) rename Scripts/{graph => }/__init__.py (100%) create mode 100644 Scripts/cli/Makefile create mode 100644 Scripts/cli/README.md create mode 100644 Scripts/cli/__init__.py rename Scripts/{graph => cli}/proto/Content/data_pb2.py (100%) rename Scripts/{graph => cli}/proto/Content/info_pb2.py (100%) rename Scripts/{graph => cli}/proto/Content/settings_pb2.py (100%) rename Scripts/{graph => cli}/proto/data_pb2.py (100%) rename Scripts/{graph => cli}/proto/info_pb2.py (100%) rename Scripts/{graph => cli}/proto/request_pb2.py (100%) rename Scripts/{graph => cli}/proto/response_pb2.py (100%) rename Scripts/{graph => cli}/proto/settings_pb2.py (100%) create mode 100644 Scripts/cli/requirements.txt create mode 100644 Scripts/cli/setup.py create mode 100644 Scripts/cli/src/__init__.py create mode 100644 Scripts/cli/src/__main__.py create mode 100644 Scripts/cli/src/__pycache__/__init__.cpython-312.pyc create mode 100644 Scripts/cli/src/__pycache__/cli.cpython-312.pyc create mode 100644 Scripts/cli/src/cli.py create mode 100644 Scripts/cli/src/command/__init__.py create mode 100644 Scripts/cli/src/command/__pycache__/__init__.cpython-312.pyc create mode 100644 Scripts/cli/src/command/__pycache__/base.cpython-312.pyc create mode 100644 Scripts/cli/src/command/__pycache__/list_available_devices.cpython-312.pyc create mode 100644 Scripts/cli/src/command/base.py create mode 100644 Scripts/cli/src/command/get_data_once.py create mode 100644 Scripts/cli/src/command/get_data_series.py create mode 100644 Scripts/cli/src/command/get_info.py create mode 100644 Scripts/cli/src/command/list_available_devices.py create mode 100644 Scripts/cli/src/command/set_settings.py create mode 100644 Scripts/cli/src/compatibility/__init__.py create mode 100644 Scripts/cli/src/compatibility/campatibility.py create mode 100644 Scripts/cli/src/dto/__init__.py create mode 100644 Scripts/cli/src/dto/__pycache__/__init__.cpython-312.pyc create mode 100644 Scripts/cli/src/dto/__pycache__/available_devices_dto.cpython-312.pyc create mode 100644 Scripts/cli/src/dto/available_devices_dto.py create mode 100644 Scripts/cli/src/graph/__init__.py rename Scripts/{graph/main.py => cli/src/graph/graph.py} (85%) create mode 100644 Scripts/cli/src/tools/__init__.py create mode 100644 Scripts/cli/src/tools/__pycache__/__init__.cpython-312.pyc create mode 100644 Scripts/cli/src/tools/__pycache__/prettifier.cpython-312.pyc create mode 100644 Scripts/cli/src/tools/prettifier.py diff --git a/.gitignore b/.gitignore index a049b91..5a2acee 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,8 @@ Debug/ # IDEA -.idea/ \ No newline at end of file +.idea/ + +# Scripts + +**/env/ \ No newline at end of file diff --git a/Core/External/Proto/Helper/proto_helper.cpp b/Core/External/Proto/Helper/proto_helper.cpp index 188743e..e3e9e83 100644 --- a/Core/External/Proto/Helper/proto_helper.cpp +++ b/Core/External/Proto/Helper/proto_helper.cpp @@ -51,4 +51,29 @@ bool ProtoHelper::is_info_bus_request_content_of_gain_info_type( bool ProtoHelper::is_info_bus_request_content_of_integral_time_info_type( const light_detector::InfoBusRequestContent& content) { return content.infoType() == light_detector::InfoType::IntegralTime; +} + +bool ProtoHelper::is_settings_bus_request_content_of_enable_settings_type( + const light_detector::SettingsBusRequestContent &content) { + return content.settingsType() == light_detector::SettingsType::Enable; +} + +bool ProtoHelper::is_settings_bus_request_content_of_disable_settings_type( + const light_detector::SettingsBusRequestContent &content) { + return content.settingsType() == light_detector::SettingsType::Disable; +} + +bool ProtoHelper::is_settings_bus_request_content_of_reset_settings_type( + const light_detector::SettingsBusRequestContent &content) { + return content.settingsType() == light_detector::SettingsType::Reset; +} + +bool ProtoHelper::is_settings_bus_request_content_of_set_gain_settings_type( + const light_detector::SettingsBusRequestContent &content) { + return content.settingsType() == light_detector::SettingsType::SetGain; +} + +bool ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type( + const light_detector::SettingsBusRequestContent &content) { + return content.settingsType() == light_detector::SettingsType::SetIntegralTime; }; diff --git a/Core/External/Proto/Helper/proto_helper.h b/Core/External/Proto/Helper/proto_helper.h index 01d97cb..f54f74a 100644 --- a/Core/External/Proto/Helper/proto_helper.h +++ b/Core/External/Proto/Helper/proto_helper.h @@ -110,6 +110,58 @@ class ProtoHelper { */ static bool is_info_bus_request_content_of_integral_time_info_type( const light_detector::InfoBusRequestContent& content); + + + + + + + + + /** + * Checks if the given settings bus request content of enable settings type. + * + * @param content - given settings bus request content. + * @return result of the check. + */ + static bool is_settings_bus_request_content_of_enable_settings_type( + const light_detector::SettingsBusRequestContent& content); + + /** + * Checks if the given settings bus request content of disable settings type. + * + * @param content - given settings bus request content. + * @return result of the check. + */ + static bool is_settings_bus_request_content_of_disable_settings_type( + const light_detector::SettingsBusRequestContent& content); + + /** + * Checks if the given settings bus request content of reset settings type. + * + * @param content - given settings bus request content. + * @return result of the check. + */ + static bool is_settings_bus_request_content_of_reset_settings_type( + const light_detector::SettingsBusRequestContent& content); + + /** + * Checks if the given settings bus request content of set gain settings type. + * + * @param content - given settings bus request content. + * @return result of the check. + */ + static bool is_settings_bus_request_content_of_set_gain_settings_type( + const light_detector::SettingsBusRequestContent& content); + + /** + * Checks if the given settings bus request content of set integral time settings type. + * + * @param content - given settings bus request content. + * @return result of the check. + */ + static bool is_settings_bus_request_content_of_set_integral_time_settings_type( + const light_detector::SettingsBusRequestContent& content); }; #endif //LIGHT_DETECTOR_PROTO_HELPER_H diff --git a/Core/External/Scheduler/Handler/scheduler_handler.cpp b/Core/External/Scheduler/Handler/scheduler_handler.cpp index 9aeb1e4..3ac1c23 100644 --- a/Core/External/Scheduler/Handler/scheduler_handler.cpp +++ b/Core/External/Scheduler/Handler/scheduler_handler.cpp @@ -227,5 +227,72 @@ int SchedulerHandler::process_info_bus_request_content_of_integral_time_info_typ int SchedulerHandler::process_settings_bus_request_content_response( const light_detector::RequestContainer &content) { + auto settings_bus_request_content = + ProtoHelper::extract_settings_bus_request_content(content); -} \ No newline at end of file + if (ProtoHelper::is_settings_bus_request_content_of_enable_settings_type( + settings_bus_request_content)) { + + + } else if (ProtoHelper::is_settings_bus_request_content_of_disable_settings_type( + settings_bus_request_content)) { + + + } else if (ProtoHelper::is_settings_bus_request_content_of_reset_settings_type( + settings_bus_request_content)) { + + + } else if (ProtoHelper::is_settings_bus_request_content_of_set_gain_settings_type( + settings_bus_request_content)) { + + + } else if (ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type( + settings_bus_request_content)) { + + + } + + return EXIT_SUCCESS; +} + +int SchedulerHandler::process_settings_bus_request_content_of_enable_settings_type_response( + const light_detector::RequestContainer &content) { + light_detector::ResponseContainer response_container; + + response_container.set_msgId(content.get_msgId()); + + light_detector::SettingsBusResponseContent settings_bus_response_content; + + settings_bus_response_content.set_deviceId(TSL2591X::get_device_id()); + settings_bus_response_content.set_settingsType(light_detector::SettingsType::Enable); + + TSL2591X::enable(); + uint8_t value = TSL2591X::get_integral_time(); + + settings_bus_response_content.set_result(true); + settings_bus_response_content.set_nonce(State::allocate_response_nonce()); + + response_container.set_settingsBus(settings_bus_response_content); + + return ProtoCodec::encode_response_container(response_container); +} + +int SchedulerHandler::process_settings_bus_request_content_of_disable_settings_type_response( + const light_detector::RequestContainer &content) { + return 0; +} + +int SchedulerHandler::process_settings_bus_request_content_of_reset_settings_type_response( + const light_detector::RequestContainer &content) { + return 0; +} + +int SchedulerHandler::process_settings_bus_request_content_of_set_gain_settings_type_response( + const light_detector::RequestContainer &content) { + return 0; +} + +int SchedulerHandler::process_settings_bus_request_content_of_set_integral_time_settings_type_response( + const light_detector::RequestContainer &content) { + return 0; +} diff --git a/Core/External/Scheduler/Handler/scheduler_handler.h b/Core/External/Scheduler/Handler/scheduler_handler.h index 0557632..b35618c 100644 --- a/Core/External/Scheduler/Handler/scheduler_handler.h +++ b/Core/External/Scheduler/Handler/scheduler_handler.h @@ -133,6 +133,51 @@ class SchedulerHandler { * @return status of the settings bus request content response processing. */ static int process_settings_bus_request_content_response(const light_detector::RequestContainer& content); + + /** + * Attempts to process settings bus request content of enable settings type response. + * + * @param content - given settings bus request content. + * @return status of the settings bus request content response processing. + */ + static int process_settings_bus_request_content_of_enable_settings_type_response( + const light_detector::RequestContainer& content); + + /** + * Attempts to process settings bus request content of disable settings type response. + * + * @param content - given settings bus request content. + * @return status of the settings bus request content response processing. + */ + static int process_settings_bus_request_content_of_disable_settings_type_response( + const light_detector::RequestContainer& content); + + /** + * Attempts to process settings bus request content of reset settings type response. + * + * @param content - given settings bus request content. + * @return status of the settings bus request content response processing. + */ + static int process_settings_bus_request_content_of_reset_settings_type_response( + const light_detector::RequestContainer& content); + + /** + * Attempts to process settings bus request content of set gain settings type response. + * + * @param content - given settings bus request content. + * @return status of the settings bus request content response processing. + */ + static int process_settings_bus_request_content_of_set_gain_settings_type_response( + const light_detector::RequestContainer& content); + + /** + * Attempts to process settings bus request content of set integral time settings type response. + * + * @param content - given settings bus request content. + * @return status of the settings bus request content response processing. + */ + static int process_settings_bus_request_content_of_set_integral_time_settings_type_response( + const light_detector::RequestContainer& content); }; #endif //LIGHT_DETECTOR_SCHEDULER_HANDLER_H diff --git a/Makefile b/Makefile index 83f35d1..522b603 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ else endif .PHONY: generate -generate: ## Generate prerequisites +generate: ## Generate ProtocolBuffers files(used mainly for development) @protoc -I./Resources/Proto/Container --python_out=./Scripts/graph/proto Content/data.proto Content/info.proto Content/settings.proto request.proto response.proto @protoc --plugin=/Volumes/Files/embedded/university/techno/project/deps/EmbeddedProto -I./Resources/Proto/Container --eams_out=./Core/External/Proto/Generated Content/data.proto Content/info.proto Content/settings.proto request.proto response.proto diff --git a/README.md b/README.md index 4008c81..ea6d6be 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ A driver-like application, which allows to communicate with TSL2591X light senso Includes following features: * Retrieve latest sensor data(**raw**, **full**, **infrared**, **visible**) * Retrieve meta information from the internal board state -* Modify settings for the light sensor. +* Modify settings for the light sensor. ## Setup @@ -27,4 +27,12 @@ Built **ELF** file is intended to be used for manual upload via **STM Programmer If **ProtocolBuffers** files need to be regenerated it's required to execute the following command: ```shell make generate -``` \ No newline at end of file +``` + +## Scripts + +### CLI + +Detailed documentation can be found [here](./Scripts/cli/README.md) + +# Use cases \ No newline at end of file diff --git a/Resources/Proto/Container/Content/info.proto b/Resources/Proto/Container/Content/info.proto index 466591f..e6e19a5 100644 --- a/Resources/Proto/Container/Content/info.proto +++ b/Resources/Proto/Container/Content/info.proto @@ -8,6 +8,7 @@ package light_detector; enum InfoType { Gain = 0; IntegralTime = 1; + ProcessedRequests = 2; } // Represents info bus request content send from the client to the board. diff --git a/Scripts/graph/__init__.py b/Scripts/__init__.py similarity index 100% rename from Scripts/graph/__init__.py rename to Scripts/__init__.py diff --git a/Scripts/cli/Makefile b/Scripts/cli/Makefile new file mode 100644 index 0000000..8a88950 --- /dev/null +++ b/Scripts/cli/Makefile @@ -0,0 +1,37 @@ +.ONESHELL: + +.PHONY: help +.DEFAULT_GOAL := help +help: + @grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +.PHONY: clean +clean: ## Cleans generated core files +ifneq (,$(wildcard ./Debug)) + @rm -r ./Debug + + @echo "Debug directory has been successfully deleted" +else + @echo "Debug directory does not exist" +endif + +ifneq (,$(wildcard ./Core/Src/main.c)) + @find ./Core/Src -name "*.cpp" | xargs -I {} rm {} + @cd ./Core/Src && \ + for file in *; do \ + mv "$$file" "`echo $$file | sed 's/\.c$$/.cpp/'`"; \ + done + + @echo "*.c files rename operation was performed successfully" +else + @echo "*.c files intented to be renamed don't exist" +endif + +prepare: ## Install prerequisites + pip3 install -r requirements.txt + +install: prepare ## Build and install the application + python3 setup.py install --user + +.PHONY: all +all: install \ No newline at end of file diff --git a/Scripts/cli/README.md b/Scripts/cli/README.md new file mode 100644 index 0000000..0330ccc --- /dev/null +++ b/Scripts/cli/README.md @@ -0,0 +1,39 @@ +# CLI + +[![Build](https://github.com/YarikRevich/ResourceTracker/actions/workflows/build.yml/badge.svg)](https://github.com/YarikRevich/ResourceTracker/actions/workflows/build.yml) +![Linux](https://img.shields.io/badge/Linux-FCC624?style=for-the-badge&logo=linux&logoColor=black) +![MacOS](https://img.shields.io/badge/MacOS-8773f5?style=for-the-badge&logo=macos&logoColor=black) +[![StandWithUkraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md) + +## General Information + +Allows to perform communication with serial connected devices. + +Includes following features: +* Retrieve latest sensor data(**raw**, **full**, **infrared**, **visible**) +* Retrieve meta information from the internal board state +* Modify settings for the light sensor. + +## Setup + +All setup related operations are processed via **Makefile** placed in the root directory. + +In order to build IOC project it's required to execute the following command. It uses **CubeMX CLI** to generate **ELF** upload file: +```shell +make build +``` + +Built **ELF** file is intended to be used for manual upload via **STM Programmer**. + +If **ProtocolBuffers** files need to be regenerated it's required to execute the following command: +```shell +make generate +``` + +## Scripts + +### CLI + +Detailed documentation can be found [here](./Scripts/cli/README.md) + +# Use cases \ No newline at end of file diff --git a/Scripts/cli/__init__.py b/Scripts/cli/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Scripts/graph/proto/Content/data_pb2.py b/Scripts/cli/proto/Content/data_pb2.py similarity index 100% rename from Scripts/graph/proto/Content/data_pb2.py rename to Scripts/cli/proto/Content/data_pb2.py diff --git a/Scripts/graph/proto/Content/info_pb2.py b/Scripts/cli/proto/Content/info_pb2.py similarity index 100% rename from Scripts/graph/proto/Content/info_pb2.py rename to Scripts/cli/proto/Content/info_pb2.py diff --git a/Scripts/graph/proto/Content/settings_pb2.py b/Scripts/cli/proto/Content/settings_pb2.py similarity index 100% rename from Scripts/graph/proto/Content/settings_pb2.py rename to Scripts/cli/proto/Content/settings_pb2.py diff --git a/Scripts/graph/proto/data_pb2.py b/Scripts/cli/proto/data_pb2.py similarity index 100% rename from Scripts/graph/proto/data_pb2.py rename to Scripts/cli/proto/data_pb2.py diff --git a/Scripts/graph/proto/info_pb2.py b/Scripts/cli/proto/info_pb2.py similarity index 100% rename from Scripts/graph/proto/info_pb2.py rename to Scripts/cli/proto/info_pb2.py diff --git a/Scripts/graph/proto/request_pb2.py b/Scripts/cli/proto/request_pb2.py similarity index 100% rename from Scripts/graph/proto/request_pb2.py rename to Scripts/cli/proto/request_pb2.py diff --git a/Scripts/graph/proto/response_pb2.py b/Scripts/cli/proto/response_pb2.py similarity index 100% rename from Scripts/graph/proto/response_pb2.py rename to Scripts/cli/proto/response_pb2.py diff --git a/Scripts/graph/proto/settings_pb2.py b/Scripts/cli/proto/settings_pb2.py similarity index 100% rename from Scripts/graph/proto/settings_pb2.py rename to Scripts/cli/proto/settings_pb2.py diff --git a/Scripts/cli/requirements.txt b/Scripts/cli/requirements.txt new file mode 100644 index 0000000..9ebdcb8 --- /dev/null +++ b/Scripts/cli/requirements.txt @@ -0,0 +1,12 @@ +contourpy==1.2.0 +cycler==0.12.1 +fonttools==4.50.0 +kiwisolver==1.4.5 +matplotlib==3.8.3 +numpy==1.26.4 +packaging==24.0 +pillow==10.3.0 +pyparsing==3.1.2 +pyserial==3.5 +python-dateutil==2.9.0.post0 +six==1.16.0 diff --git a/Scripts/cli/setup.py b/Scripts/cli/setup.py new file mode 100644 index 0000000..9f7b054 --- /dev/null +++ b/Scripts/cli/setup.py @@ -0,0 +1,48 @@ +import io +import os + +from setuptools import find_packages, setup + + +def read(*paths, **kwargs): + """Reads content at the given location.""" + + content = "" + with io.open( + os.path.join(os.path.dirname(__file__), *paths), + encoding=kwargs.get("encoding", "utf8"), + ) as open_file: + content = open_file.read().strip() + return content + + +def read_description() -> str: + """Reads description at the static location.""" + + return read("README.md") + + +def read_requirements() -> list[str]: + """Reads requirements file at the static location.""" + + return [ + line.strip() + for line in read("requirements.txt").split("\n") + if not line.startswith(('"', "#", "-", "git+")) + ] + + +setup( + name="light-sensor-cli", + version="0.0.1", + description="A tool used to allows to perform operations on STM32L476RG board with installed TSL2591X light sensor with the help of serial connection.", + url="https://github.com/YarikRevich/light-detector", + long_description=read_description(), + long_description_content_type="text/markdown", + author="YarikRevich", + packages=find_packages(exclude=["tests", ".github"]), + install_requires=read_requirements(), + entry_points={ + "console_scripts": ["light-sensor-cli = src.cli.__main__:main"] + }, +) diff --git a/Scripts/cli/src/__init__.py b/Scripts/cli/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Scripts/cli/src/__main__.py b/Scripts/cli/src/__main__.py new file mode 100644 index 0000000..ddb3d45 --- /dev/null +++ b/Scripts/cli/src/__main__.py @@ -0,0 +1,6 @@ +from cli import main + +if __name__ == "__main__": + """Represents external entrypoint.""" + + main() \ No newline at end of file diff --git a/Scripts/cli/src/__pycache__/__init__.cpython-312.pyc b/Scripts/cli/src/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d5e435dcf3bcc865a7e2726c73ed5b31a845023b GIT binary patch literal 201 zcmX@j%ge<81hMfvX(0MBh(HIQS%4zb87dhx8U0o=6fpsLpFwJVW$1?%rxq3KS0)za z7w06F6_;g}X+viWfvDDCa1<5>KU5o8R+L^re~DI zr=*soCYR(F=?5nlWfqha>nG=A>SyMaq!#5R=IF=AXXa&=#K-FuRQ}?y$<0qG%}KQ@ WVg*{v2*kx8#z$sGM#ds$APWFxaW&`w literal 0 HcmV?d00001 diff --git a/Scripts/cli/src/__pycache__/cli.cpython-312.pyc b/Scripts/cli/src/__pycache__/cli.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..aa913d4f069e2b496309f592049638772b53ad42 GIT binary patch literal 473 zcmXv~Jxc>Y5Z%4Id>Ia`wMg1)?u?3+Soj4gOkuPMVmR+My5_!^-9*kxK@h<{zd`&d z);4D;78Zh#RH>Xja|1hX-rL!E%e zqXccV+r}|VfC&~!(d3b25V=7U8Kg;!-0oOZEH zju&u8fTz$-(#!~59)VhE8IM@TbVp`oQmQ?+@7vGAcVh*rC|X)p1|~-kbu0r)sALuI ue`EQ7^AS)%J#U8^R`cq182h7u?SP3?EhRVj)hVSPr2a)3v$9TC^A~>^@@$C! literal 0 HcmV?d00001 diff --git a/Scripts/cli/src/cli.py b/Scripts/cli/src/cli.py new file mode 100644 index 0000000..c3be1a9 --- /dev/null +++ b/Scripts/cli/src/cli.py @@ -0,0 +1,9 @@ +import fire + +from command import BaseCommand + + +def main() -> None: + """Represents internal entrypoint.""" + + fire.Fire(BaseCommand) diff --git a/Scripts/cli/src/command/__init__.py b/Scripts/cli/src/command/__init__.py new file mode 100644 index 0000000..0089b43 --- /dev/null +++ b/Scripts/cli/src/command/__init__.py @@ -0,0 +1 @@ +from .base import BaseCommand \ No newline at end of file diff --git a/Scripts/cli/src/command/__pycache__/__init__.cpython-312.pyc b/Scripts/cli/src/command/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..003b223e14caa24632215966ac129c23d7e688d8 GIT binary patch literal 247 zcmX@j%ge<81fEH}X|h22F^B^LOi;#W0U%>KLkdF*V-7=$@<9HYo6u0wrq4X$A5tPLOmQ-y*fw2NXix2{Cps-}Ie6iaLbuNePJCvIk`ag8w zFM$3jObiGSsS{%8R&kY(I$=9$)qyuWKfjOP`?9}wyK_L(r+#<)iwnRnb2%fg6=v&N z*as9)$Uy;92#xG;r*KnO%P#e}SNN$9fdifa>hA#>95_vM8dRMqJTjLE)^j|U3Xe*m zq`n1POyqM zh5FRp^HZ;KqM*L~ghD@)IR(H^z5L7U7rY}q@5)sak8Zbo8nnGJ|UfsWE5|4<=b(e@XZEDqU$TGz!QYDgh zF38R)?nRCWG<+R2bw*C@NyfKpZ%7IzO)&_a?j&z@luRljO3BGYPIAR7C3mYlu}L?^ zefE6wY4V{IyK+P_hS%b?2l3s6=Q{(1DN{OqDUz*BCTUE`CGXBJzSY-oqirui@kb|z1m{yjswBe zSPXlSUxyf*#xbtvFfK|u=0={!`2Cph*3!Y4mKnz4iU$4+#DYFV*Rb%6b+jOjeh>Wg zmQOs_Up-!d{$k^6+K*ZC%@gE7gM_MGtFWY1%5DM3AkBpgp*H$z{l9MjLk0$<9nF*^`I< z5Bo1D{Zl-u2LlU&CvR#5VNcE^>0w2Dke6>>zW3gjFL~eVZGnyq_g=aP;Hx=o!f8M` z(%=LL5X2xs0YU~_%u4LQMqt4sAodD~v$pDvz{y>&_01eSR9t?r3}Y4^Fgm5nIHGc@ zxGr~75ib#E1GF-jI)>pY($xzy!I+UqaLD0IXZte(j z%d-n897Uy?d6qCP3e)ipO4D?f`!6IF($7P|B@35w87r16d6>uk{`04|CwtieeLQ{W zzvkjlreQ?!csRZ@9QiDMHCI}-qLJdl-;YF`D(Oco_N9pY<}EbsUvD`~^P)A^mN0sJ z<3ElKYff8BmD@VKfnOcC(Er%K_4dk#{^(O@EH3Ku%xe`Lj2B@-F)p?+PB_V!!Cj1x zvXC`T+87fanX*)&ilc<8IVYm0M+o!lRl`Krpw=cC%j8v^R`A)m`^CNV!?N8;X+vwf zLUoU!&pfxVi8jL+T)2vJCTqv5Vdoc|b?((7?~A^sn=dB~_--SFPT}S$T>tH~(c~xS HRPFc!OHIif literal 0 HcmV?d00001 diff --git a/Scripts/cli/src/command/base.py b/Scripts/cli/src/command/base.py new file mode 100644 index 0000000..4ea2bc1 --- /dev/null +++ b/Scripts/cli/src/command/base.py @@ -0,0 +1,33 @@ +from serial.tools import list_ports +from serial import Serial + +from .list_available_devices import ListAvailableDevicesCommand + + +class BaseCommand: + """Represents base command handler.""" + + def list_available_devices(self, name="list-available-devices") -> None: + """Lists all the available compatible devices connected to serial ports.""" + + ListAvailableDevicesCommand.handle() + + # """bit rate and bit amount per image""" + # + # + # ser = Serial("COM7", 9600) + # with open("/dev/COM7", "rb") as ser: + # while True: + # bs = ser.read(2048) + # print(repr(bs)) + # + # for entity in list_ports.comports(): + # print(entity.name, entity.device, entity.description, entity.manufacturer) + + # + # def is_connected(self, ): + # """""" + # return 2 * number + + """list available ports + is connected """ diff --git a/Scripts/cli/src/command/get_data_once.py b/Scripts/cli/src/command/get_data_once.py new file mode 100644 index 0000000..e69de29 diff --git a/Scripts/cli/src/command/get_data_series.py b/Scripts/cli/src/command/get_data_series.py new file mode 100644 index 0000000..e69de29 diff --git a/Scripts/cli/src/command/get_info.py b/Scripts/cli/src/command/get_info.py new file mode 100644 index 0000000..4bba785 --- /dev/null +++ b/Scripts/cli/src/command/get_info.py @@ -0,0 +1,7 @@ + +class GetInfoCommand: + """Represents 'list_available_devices' command.""" + + @staticmethod + def handle(): + """Handles the execution of command wrapper.""" \ No newline at end of file diff --git a/Scripts/cli/src/command/list_available_devices.py b/Scripts/cli/src/command/list_available_devices.py new file mode 100644 index 0000000..8bfc0f2 --- /dev/null +++ b/Scripts/cli/src/command/list_available_devices.py @@ -0,0 +1,11 @@ +from dto import AvailableDevicesDto +from tools import print_output + +class ListAvailableDevicesCommand: + """Represents 'list_available_devices' command.""" + + @staticmethod + def handle(): + """Handles the execution of command wrapper.""" + + print_output(AvailableDevicesDto("test")) diff --git a/Scripts/cli/src/command/set_settings.py b/Scripts/cli/src/command/set_settings.py new file mode 100644 index 0000000..e69de29 diff --git a/Scripts/cli/src/compatibility/__init__.py b/Scripts/cli/src/compatibility/__init__.py new file mode 100644 index 0000000..808c41f --- /dev/null +++ b/Scripts/cli/src/compatibility/__init__.py @@ -0,0 +1,2 @@ +from .campatibility import is_manufacturer_allowed +from .campatibility import is_device_allowed \ No newline at end of file diff --git a/Scripts/cli/src/compatibility/campatibility.py b/Scripts/cli/src/compatibility/campatibility.py new file mode 100644 index 0000000..c4d7ea7 --- /dev/null +++ b/Scripts/cli/src/compatibility/campatibility.py @@ -0,0 +1,13 @@ +STM_ELECTRONICS = "STM" + + +def is_manufacturer_allowed(src: str) -> bool: + """Checks if the given manufacturer is among of allowed ones.""" + + return True + + +def is_device_allowed(src: str) -> bool: + """Checks if the given device name is among of allowed ones.""" + + return True diff --git a/Scripts/cli/src/dto/__init__.py b/Scripts/cli/src/dto/__init__.py new file mode 100644 index 0000000..6807779 --- /dev/null +++ b/Scripts/cli/src/dto/__init__.py @@ -0,0 +1 @@ +from .available_devices_dto import AvailableDevicesDto diff --git a/Scripts/cli/src/dto/__pycache__/__init__.cpython-312.pyc b/Scripts/cli/src/dto/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..bb70e0391790f087f262eaf6d1c88c7a68f2d163 GIT binary patch literal 268 zcmX@j%ge<81g^2XY34xsF^B^LOi;#W0U%>KLkdF*V-7%$&reoK%<8vdrYvVwaM9KTW1vqKPo^_!Njld`d}v5i?NNN`}uMvwx-QhZd(6 z73)_f7UdV`B$gGIWtQYrmK0}KX6grr_!=8ImnNlpy143>=NDxc7bGU9#vAGxn&=tm z=VYd5lmN{wNlgZtsUMtNlvz+xte>2dsb5@_tPiwEKR!M)FS8^*Uaz3?7l%!5eoARh bs$CHW&|Z+ki$RPJ%#4hT_ZZBI*nk`WRmn@E literal 0 HcmV?d00001 diff --git a/Scripts/cli/src/dto/__pycache__/available_devices_dto.cpython-312.pyc b/Scripts/cli/src/dto/__pycache__/available_devices_dto.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f33b9293e43b6dfb35603fe4bccb87cb73077306 GIT binary patch literal 640 zcmZuv%We}f6uq9Aw4v$r7^Wz>9N_@8kH`^4B!o16-@O>G%`IA7Rt2WJ}g}kSrmB zXCPn!f_#bEN&$70$Gqzgaa)1)A#Ro+p&$Z^NRT2Hkxa&sh!;uGtCPIf96X+vN|$F^ z4&_{N>4x51J$)r-RysNLE)(8lm6IaFcy6@Fuuy5AnQ?ZcmGi9Z1ej^kH z4rX=JXG~3%XYA_mKMynLsvDy{H2ML)_4n6EV3hBK>1jEUj5T|VO^m2?;QNeSR;Aun zb{P|fV>));+8a1&cLIbjVEX~W18smHakmi`@I86CN=PsLc=8J{wB4a`l#_PgZ;|W% c!}k0~_7-++lx`wf#e|UGQ9{z6fUwc|1OB3=IRF3v literal 0 HcmV?d00001 diff --git a/Scripts/cli/src/dto/available_devices_dto.py b/Scripts/cli/src/dto/available_devices_dto.py new file mode 100644 index 0000000..8173ad2 --- /dev/null +++ b/Scripts/cli/src/dto/available_devices_dto.py @@ -0,0 +1,5 @@ +class AvailableDevicesDto: + """Represents dto used to hold result of 'list_available_devices' command""" + + def __init__(self, src: str): + pass \ No newline at end of file diff --git a/Scripts/cli/src/graph/__init__.py b/Scripts/cli/src/graph/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Scripts/graph/main.py b/Scripts/cli/src/graph/graph.py similarity index 85% rename from Scripts/graph/main.py rename to Scripts/cli/src/graph/graph.py index 1773193..969d6c2 100644 --- a/Scripts/graph/main.py +++ b/Scripts/cli/src/graph/graph.py @@ -1,3 +1,4 @@ + import tkinter from tkinter import Tk @@ -6,12 +7,14 @@ from serial.tools import list_ports + def retrieve_ports() -> list[str]: """Retrieves standardized""" for entity in list_ports.comports(): pass + def render_figure(data: list[str]) -> None: """Renderes figure with the given content""" @@ -31,10 +34,4 @@ def render_figure(data: list[str]) -> None: root.mainloop() -def main() -> None: - """Represents entrypoint""" - - render_figure(retrieve_ports()) - -if __name__ == "__main__": - main() \ No newline at end of file +render_figure(retrieve_ports()) \ No newline at end of file diff --git a/Scripts/cli/src/tools/__init__.py b/Scripts/cli/src/tools/__init__.py new file mode 100644 index 0000000..acac466 --- /dev/null +++ b/Scripts/cli/src/tools/__init__.py @@ -0,0 +1 @@ +from .prettifier import print_output \ No newline at end of file diff --git a/Scripts/cli/src/tools/__pycache__/__init__.cpython-312.pyc b/Scripts/cli/src/tools/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0da4406f9d83e3cf17f27ced53816ab008d43e9b GIT binary patch literal 252 zcmXwzu}T9$5QcZ}Ktk}qhe&hHjZsUnQ40%gqKyd4xwp|Fo9r?(7uhHA8GIJsAcc*U zg&?F$a1)tTLa8JzFRZ-HlFMr_P0Y>&Uq}nPh++4nZ~s72;+jw^0MiDg%o}Ho=MU zMdfi+8M*cG{ra=l&%3L#FuQxcue2wf7UWhA#(9)^VI;Lo zdTR@mjdU|KB*sRVyG~ha@wj)`J5i_W-^`!n@r?4U6GKW+ zr*|D`s(vt7q#QgXck|%IC#%Xrzl28=hF{?dxoONfzhLcY8uKTo!zm;9zI+{^DZT}b CJ&Jb# literal 0 HcmV?d00001 diff --git a/Scripts/cli/src/tools/prettifier.py b/Scripts/cli/src/tools/prettifier.py new file mode 100644 index 0000000..0c7bd95 --- /dev/null +++ b/Scripts/cli/src/tools/prettifier.py @@ -0,0 +1,7 @@ +import pprint + + +def print_output(src: object) -> None: + """Prints given object in a pretty way. Given object is supposed to be a data holder.""" + + pprint.pp(vars(src)) diff --git a/light_detector.ioc b/light_detector.ioc index 3badb6a..bcc6aae 100644 --- a/light_detector.ioc +++ b/light_detector.ioc @@ -43,11 +43,12 @@ Mcu.Pin1=PH0-OSC_IN (PH0) Mcu.Pin2=PH1-OSC_OUT (PH1) Mcu.Pin3=PA2 Mcu.Pin4=PA3 -Mcu.Pin5=PB8 -Mcu.Pin6=PB9 -Mcu.Pin7=VP_SYS_VS_Systick -Mcu.Pin8=VP_TIM16_VS_ClockSourceINT -Mcu.PinsNb=9 +Mcu.Pin5=PA5 +Mcu.Pin6=PB8 +Mcu.Pin7=PB9 +Mcu.Pin8=VP_SYS_VS_Systick +Mcu.Pin9=VP_TIM16_VS_ClockSourceINT +Mcu.PinsNb=10 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32L476RGTx @@ -77,6 +78,8 @@ PA2.Signal=USART2_TX PA3.Locked=true PA3.Mode=Asynchronous PA3.Signal=USART2_RX +PA5.Locked=true +PA5.Signal=GPIO_Output PB8.Locked=true PB8.Mode=I2C PB8.Signal=I2C1_SCL