Skip to content

Commit

Permalink
add auto protocol check support
Browse files Browse the repository at this point in the history
  • Loading branch information
AsiiaPine committed Oct 18, 2024
1 parent 8922ff0 commit 75662c2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Libs/Dronecan
22 changes: 18 additions & 4 deletions Src/common/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Author: Dmitry Ponomarev <[email protected]>
*/

#include "application.hpp"
#include <can_driver.h>
#include <array>
#include <bitset>
#include "peripheral/adc/circuit_periphery.hpp"
Expand All @@ -13,7 +13,7 @@
#include "module.hpp"
#include "main.h"

#include "peripheral/led/led.hpp"
#include "application.hpp"
#include "peripheral/gpio/gpio.hpp"
#include "peripheral/iwdg/iwdg.hpp"

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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<Module::Protocol>(can_driver_protocol));
} else {
ModuleManager::process();
}
blink_board_led();
HAL::Watchdog::refresh();
}
Expand Down
6 changes: 6 additions & 0 deletions Src/common/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Src/common/module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 75662c2

Please sign in to comment.