Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

add auto protocol check support #79

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,16 +4,16 @@
* Author: Dmitry Ponomarev <ponomarevda96@gmail.com>
*/

#include "application.hpp"
#include <array>
#include <bitset>
#include "peripheral/adc/circuit_periphery.hpp"
#include "peripheral/led/led.hpp"
#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"

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
Loading