From 075ce555e96e871aaf5f47d230c53d0510a9acd9 Mon Sep 17 00:00:00 2001 From: PonomarevDA Date: Fri, 27 Sep 2024 00:57:50 +0300 Subject: [PATCH] fix check: is a module enabled or not --- Src/common/module.cpp | 19 ++++++++++--------- Src/common/module.hpp | 1 + 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Src/common/module.cpp b/Src/common/module.cpp index 2291242..b7d3df3 100644 --- a/Src/common/module.cpp +++ b/Src/common/module.cpp @@ -5,8 +5,8 @@ */ #include "module.hpp" -#include "params.hpp" #include +#include "params.hpp" Module::Module(float frequency, Protocol proto) : protocol(proto), period_ms(period_ms_from_frequency(frequency)) { @@ -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(); @@ -53,10 +57,8 @@ 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(); } } @@ -64,8 +66,7 @@ void ModuleManager::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(); } } @@ -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(); } } @@ -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(); } } @@ -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; } diff --git a/Src/common/module.hpp b/Src/common/module.hpp index 5ad6ea3..d5b1aae 100644 --- a/Src/common/module.hpp +++ b/Src/common/module.hpp @@ -65,6 +65,7 @@ class Module { Status get_health() const; Mode get_mode() const; Protocol get_protocol() const; + bool is_enabled() const; protected: /**