Skip to content

Commit

Permalink
feature: added cli script base
Browse files Browse the repository at this point in the history
  • Loading branch information
YarikRevich committed Apr 3, 2024
1 parent b5952bf commit 4500e8b
Show file tree
Hide file tree
Showing 50 changed files with 451 additions and 17 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ Debug/

# IDEA

.idea/
.idea/

# Scripts

**/env/
25 changes: 25 additions & 0 deletions Core/External/Proto/Helper/proto_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
52 changes: 52 additions & 0 deletions Core/External/Proto/Helper/proto_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
69 changes: 68 additions & 1 deletion Core/External/Scheduler/Handler/scheduler_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
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;
}
45 changes: 45 additions & 0 deletions Core/External/Scheduler/Handler/scheduler_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
```
```

## Scripts

### CLI

Detailed documentation can be found [here](./Scripts/cli/README.md)

# Use cases
1 change: 1 addition & 0 deletions Resources/Proto/Container/Content/info.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
File renamed without changes.
37 changes: 37 additions & 0 deletions Scripts/cli/Makefile
Original file line number Diff line number Diff line change
@@ -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
39 changes: 39 additions & 0 deletions Scripts/cli/README.md
Original file line number Diff line number Diff line change
@@ -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
Empty file added Scripts/cli/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions Scripts/cli/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 4500e8b

Please sign in to comment.