diff --git a/Libs/Dronecan b/Libs/Dronecan index 8cf4a58..8b5fe10 160000 --- a/Libs/Dronecan +++ b/Libs/Dronecan @@ -1 +1 @@ -Subproject commit 8cf4a5807276951edf2a67e152c7360c2bdeb278 +Subproject commit 8b5fe10f300c6cf3714f4ca0379bd841ae2f0ee0 diff --git a/Src/common/application.cpp b/Src/common/application.cpp index e1f79da..bea7d6b 100644 --- a/Src/common/application.cpp +++ b/Src/common/application.cpp @@ -4,7 +4,6 @@ * Author: Dmitry Ponomarev */ -#include "application.hpp" #include #include #include "peripheral/adc/circuit_periphery.hpp" @@ -12,8 +11,9 @@ #include "params.hpp" #include "module.hpp" #include "main.h" +#include "can_driver.h" -#include "peripheral/led/led.hpp" +#include "application.hpp" #include "peripheral/gpio/gpio.hpp" #include "peripheral/iwdg/iwdg.hpp" @@ -41,6 +41,14 @@ static int8_t init_board_periphery() { return 0; } +static int8_t init_can_driver() { + int16_t res = canDriverInit(1000000, CAN_DRIVER_FIRST); + return res; +} +static int8_t get_can_driver_protocol() { + return canDriverGetProtocol(CAN_DRIVER_FIRST); +} + /** * @brief Since v2 hardware version all boards have an internal RGB LED and comply with the * RaccoonLab LED indication standard. @@ -82,10 +90,16 @@ static void blink_board_led() { __attribute__((noreturn)) void application_entry_point() { init_board_periphery(); + init_can_driver(); ModuleManager::init(); - + int8_t can_driver_protocol = CanProtocol::CAN_PROTOCOL_UNKNOWN; while (true) { - ModuleManager::process(); + if (can_driver_protocol == CanProtocol::CAN_PROTOCOL_UNKNOWN) { + can_driver_protocol = get_can_driver_protocol(); + ModuleManager::set_protocol(static_cast(can_driver_protocol)); + } else { + ModuleManager::process(); + } blink_board_led(); HAL::Watchdog::refresh(); } diff --git a/Src/common/module.cpp b/Src/common/module.cpp index b7d3df3..5883a54 100644 --- a/Src/common/module.cpp +++ b/Src/common/module.cpp @@ -72,6 +72,12 @@ void ModuleManager::process() { } } +void ModuleManager::set_protocol(Module::Protocol protocol) { + ModuleManager::active_protocol = protocol; + paramsSetIntegerValue(IntParamsIndexes::PARAM_SYSTEM_PROTOCOL, (int)(protocol)); + paramsSave(); +} + Module::Protocol ModuleManager::get_active_protocol() { #if defined(CONFIG_USE_CYPHAL) && !defined(CONFIG_USE_DRONECAN) return Module::Protocol::CYPHAL; diff --git a/Src/common/module.hpp b/Src/common/module.hpp index d5b1aae..7ec7aea 100644 --- a/Src/common/module.hpp +++ b/Src/common/module.hpp @@ -95,7 +95,7 @@ class ModuleManager { static void register_module(Module* app_module); static void init(); static void process(); - + static void set_protocol(Module::Protocol protocol); static Module::Protocol get_active_protocol(); static Module::Status get_global_status(); static Module::Mode get_global_mode();