Skip to content

Commit

Permalink
fix check: is a module enabled or not
Browse files Browse the repository at this point in the history
  • Loading branch information
PonomarevDA committed Sep 28, 2024
1 parent 44bae6d commit 075ce55
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
19 changes: 10 additions & 9 deletions Src/common/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/

#include "module.hpp"
#include "params.hpp"
#include <span>
#include "params.hpp"

Module::Module(float frequency, Protocol proto) : protocol(proto),
period_ms(period_ms_from_frequency(frequency)) {
Expand All @@ -28,6 +28,10 @@ Module::Mode Module::get_mode() const {
Module::Protocol Module::get_protocol() const {
return protocol;
}
bool Module::is_enabled() const {
auto active_protocol = ModuleManager::get_active_protocol();
return protocol == Protocol::CYPHAL_AND_DRONECAN || protocol == active_protocol;
}

void Module::process() {
uint32_t crnt_time_ms = HAL_GetTick();
Expand All @@ -53,19 +57,16 @@ void ModuleManager::register_module(Module* app_module) {
}

void ModuleManager::init() {
active_protocol = get_active_protocol();
for (auto app_module : active_modules) {
auto protocol = app_module->get_protocol();
if (protocol == Module::Protocol::CYPHAL_AND_DRONECAN || protocol == active_protocol) {
if (app_module->is_enabled()) {
app_module->init();
}
}
}

void ModuleManager::process() {
for (auto app_module : active_modules) {
auto protocol = app_module->get_protocol();
if (protocol == Module::Protocol::CYPHAL_AND_DRONECAN || protocol == active_protocol) {
if (app_module->is_enabled()) {
app_module->process();
}
}
Expand Down Expand Up @@ -94,7 +95,7 @@ Module::Status ModuleManager::get_global_status() {
auto global_status = Module::Status::OK;

for (auto app_module : active_modules) {
if (app_module->get_protocol() == active_protocol && app_module->get_health() > global_status) {
if (app_module->is_enabled() && app_module->get_health() > global_status) {
global_status = app_module->get_health();
}
}
Expand All @@ -106,7 +107,7 @@ Module::Mode ModuleManager::get_global_mode() {
auto global_mode = Module::Mode::STANDBY;

for (auto app_module : active_modules) {
if (app_module->get_protocol() == active_protocol && app_module->get_mode() > global_mode) {
if (app_module->is_enabled() && app_module->get_mode() > global_mode) {
global_mode = app_module->get_mode();
}
}
Expand All @@ -119,7 +120,7 @@ uint8_t ModuleManager::get_vssc() {

uint8_t module_idx = 0;
for (auto app_module : active_modules) {
if (app_module->get_protocol() != active_protocol) {
if (!app_module->is_enabled()) {
continue;
}

Expand Down
1 change: 1 addition & 0 deletions Src/common/module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Module {
Status get_health() const;
Mode get_mode() const;
Protocol get_protocol() const;
bool is_enabled() const;

protected:
/**
Expand Down

0 comments on commit 075ce55

Please sign in to comment.