Files
bobbycar-boardcomputer-firm…/main/can.cpp

548 lines
24 KiB
C++
Raw Normal View History

2021-11-01 20:44:57 +01:00
#include "can.h"
2021-11-24 16:43:17 +01:00
#ifdef FEATURE_CAN
2021-11-01 20:44:57 +01:00
// system includes
#include <cstring>
#include <optional>
2022-06-25 22:16:21 +02:00
#include <utility>
2021-11-01 20:44:57 +01:00
// esp-idf
#include <driver/twai.h>
2022-01-04 02:39:22 +01:00
#include <driver/gpio.h>
2021-11-01 20:44:57 +01:00
#include <esp_log.h>
// 3rdparty lib includes
#include <espchrono.h>
#include <tickchrono.h>
2021-12-30 00:00:31 +01:00
#include <screenmanager.h>
2021-11-01 20:44:57 +01:00
// local includes
#include "bobbycar-can.h"
#include "globals.h"
2021-12-29 03:11:31 +01:00
#include "newsettings.h"
2021-12-30 00:00:31 +01:00
#include "bobbybuttons.h"
2021-11-01 20:44:57 +01:00
2021-12-14 11:51:10 +01:00
using namespace std::chrono_literals;
2021-11-01 20:44:57 +01:00
namespace can {
2022-01-03 18:16:48 +01:00
uint32_t can_total_error_cnt;
2021-11-01 20:44:57 +01:00
namespace {
constexpr const char * const TAG = "BOBBYCAN";
2022-01-04 02:39:22 +01:00
bool tryParseCanInput();
2021-11-01 20:44:57 +01:00
} // namespace
std::optional<int16_t> can_gas, can_brems;
espchrono::millis_clock::time_point last_can_gas{}, last_can_brems{};
void initCan()
{
ESP_LOGI(TAG, "called");
twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(GPIO_NUM_21, GPIO_NUM_22, TWAI_MODE_NORMAL);
twai_timing_config_t t_config TWAI_TIMING_CONFIG_250KBITS();
twai_filter_config_t f_config TWAI_FILTER_CONFIG_ACCEPT_ALL();
// {
// //
// .acceptance_code = 0b00000000000,
// .acceptance_mask = 0b00001111111,
// .single_filter = true
// };
if (const auto result = twai_driver_install(&g_config, &t_config, &f_config); result == ESP_OK)
{
ESP_LOGI(TAG, "twai_driver_install() succeeded");
}
else
{
ESP_LOGE(TAG, "twai_driver_install() failed with %s", esp_err_to_name(result));
return;
}
if (const auto result = twai_start(); result == ESP_OK)
{
ESP_LOGI(TAG, "twai_start() succeeded");
}
else
{
ESP_LOGE(TAG, "twai_start() failed with %s", esp_err_to_name(result));
if (const auto result = twai_driver_uninstall(); result == ESP_OK)
{
ESP_LOGI(TAG, "twai_driver_uninstall() succeeded");
}
else
{
ESP_LOGE(TAG, "twai_driver_uninstall() failed with %s", esp_err_to_name(result));
}
return;
}
}
2022-01-04 02:39:22 +01:00
void updateCan()
{
2022-10-05 21:41:14 +02:00
if (configs.emulateFeedback.value())
{
return;
}
2022-01-04 02:39:22 +01:00
for (int i = 0; i < 4; i++)
if (!tryParseCanInput())
break;
}
2021-11-01 20:44:57 +01:00
namespace {
template<bool isBack>
bool parseMotorControllerCanMessage(const twai_message_t &message, Controller &controller)
{
switch (message.identifier)
{
using namespace bobbycar::protocol::can;
case MotorController<isBack, false>::Feedback::DcLink:
controller.feedback.left.dcLink = *((int16_t*)message.data);
return true;
case MotorController<isBack, true>::Feedback::DcLink:
controller.feedback.right.dcLink = *((int16_t*)message.data);
return true;
case MotorController<isBack, false>::Feedback::Speed:
controller.feedback.left.speed = *((int16_t*)message.data);
return true;
case MotorController<isBack, true>::Feedback::Speed:
controller.feedback.right.speed = *((int16_t*)message.data);
return true;
case MotorController<isBack, false>::Feedback::Error:
controller.feedback.left.error = *((int8_t*)message.data);
return true;
case MotorController<isBack, true>::Feedback::Error:
controller.feedback.right.error = *((int8_t*)message.data);
return true;
case MotorController<isBack, false>::Feedback::Angle:
controller.feedback.left.angle = *((int16_t*)message.data);
return true;
case MotorController<isBack, true>::Feedback::Angle:
controller.feedback.right.angle = *((int16_t*)message.data);
return true;
case MotorController<isBack, false>::Feedback::DcPhaA:
controller.feedback.left.dcPhaA = *((int16_t*)message.data);
return true;
case MotorController<isBack, true>::Feedback::DcPhaA:
controller.feedback.right.dcPhaA = *((int16_t*)message.data);
return true;
case MotorController<isBack, false>::Feedback::DcPhaB:
controller.feedback.left.dcPhaB = *((int16_t*)message.data);
return true;
case MotorController<isBack, true>::Feedback::DcPhaB:
controller.feedback.right.dcPhaB = *((int16_t*)message.data);
return true;
case MotorController<isBack, false>::Feedback::DcPhaC:
controller.feedback.left.dcPhaC = *((int16_t*)message.data);
return true;
case MotorController<isBack, true>::Feedback::DcPhaC:
controller.feedback.right.dcPhaC = *((int16_t*)message.data);
return true;
case MotorController<isBack, false>::Feedback::Chops:
controller.feedback.left.chops = *((uint16_t*)message.data);
return true;
case MotorController<isBack, true>::Feedback::Chops:
controller.feedback.right.chops = *((uint16_t*)message.data);
return true;
case MotorController<isBack, false>::Feedback::Hall:
controller.feedback.left.hallA = *((uint8_t*)message.data) & 1;
controller.feedback.left.hallB = *((uint8_t*)message.data) & 2;
controller.feedback.left.hallC = *((uint8_t*)message.data) & 4;
return true;
case MotorController<isBack, true>::Feedback::Hall:
controller.feedback.right.hallA = *((uint8_t*)message.data) & 1;
controller.feedback.right.hallB = *((uint8_t*)message.data) & 2;
controller.feedback.right.hallC = *((uint8_t*)message.data) & 4;
return true;
case MotorController<isBack, false>::Feedback::Voltage:
case MotorController<isBack, true>::Feedback::Voltage:
controller.feedback.batVoltage = *((int16_t*)message.data);
return true;
case MotorController<isBack, false>::Feedback::Temp:
case MotorController<isBack, true>::Feedback::Temp:
controller.feedback.boardTemp = *((int16_t*)message.data);
return true;
2022-09-17 17:38:53 +02:00
case MotorController<isBack, false>::Feedback::Id:
controller.feedback.left.id = *((int16_t*)message.data);
return true;
case MotorController<isBack, true>::Feedback::Id:
controller.feedback.right.id = *((int16_t*)message.data);
return true;
case MotorController<isBack, false>::Feedback::Iq:
controller.feedback.left.iq = *((int16_t*)message.data);
return true;
case MotorController<isBack, true>::Feedback::Iq:
controller.feedback.right.iq = *((int16_t*)message.data);
return true;
2021-11-01 20:44:57 +01:00
}
return false;
}
bool parseBoardcomputerCanMessage(const twai_message_t &message)
{
switch (message.identifier)
{
using namespace bobbycar::protocol::can;
2021-12-30 00:00:31 +01:00
case Boardcomputer::Command::RawButtonPressed:
if (espgui::currentDisplay)
espgui::currentDisplay->rawButtonPressed(*((const uint8_t*)message.data));
2022-04-25 20:25:31 +02:00
return true;
2021-12-30 00:00:31 +01:00
case Boardcomputer::Command::RawButtonReleased:
if (espgui::currentDisplay)
espgui::currentDisplay->rawButtonReleased(*((const uint8_t*)message.data));
2022-04-25 20:25:31 +02:00
return true;
2021-12-30 00:00:31 +01:00
case Boardcomputer::Command::ButtonPressed:
if (espgui::currentDisplay)
2022-04-25 20:47:07 +02:00
espgui::currentDisplay->buttonPressed(espgui::Button(*((const uint8_t*)message.data)));
2022-04-25 20:25:31 +02:00
return true;
2021-12-30 00:00:31 +01:00
case Boardcomputer::Command::ButtonReleased:
if (espgui::currentDisplay)
2022-04-25 20:47:07 +02:00
espgui::currentDisplay->buttonReleased(espgui::Button(*((const uint8_t*)message.data)));
2022-04-25 20:25:31 +02:00
return true;
2021-11-01 20:44:57 +01:00
case Boardcomputer::Command::RawGas:
can_gas = *((int16_t*)message.data);
last_can_gas = espchrono::millis_clock::now();
2022-04-25 20:25:31 +02:00
return true;
2021-11-01 20:44:57 +01:00
case Boardcomputer::Command::RawBrems:
can_brems = *((int16_t*)message.data);
last_can_brems = espchrono::millis_clock::now();
2022-04-25 20:25:31 +02:00
return true;
2021-11-01 20:44:57 +01:00
}
return false;
}
bool tryParseCanInput()
{
twai_message_t message;
2022-04-29 22:40:49 +02:00
const auto timeout = std::chrono::ceil<espcpputils::ticks>(espchrono::milliseconds32{configs.controllerHardware.canReceiveTimeout.value()}).count();
2021-11-01 20:44:57 +01:00
if (const auto result = twai_receive(&message, timeout); result != ESP_OK)
{
if (result != ESP_ERR_TIMEOUT)
{
ESP_LOGE(TAG, "twai_receive() failed with %s", esp_err_to_name(result));
}
if (espchrono::millis_clock::now() - controllers.front.lastCanFeedback > 100ms)
controllers.front.feedbackValid = false;
if (espchrono::millis_clock::now() - controllers.back.lastCanFeedback > 100ms)
controllers.back.feedbackValid = false;
return false;
}
2022-04-29 22:40:49 +02:00
Controller &front = configs.controllerHardware.swapFrontBack.value() ? controllers.back : controllers.front;
Controller &back = configs.controllerHardware.swapFrontBack.value() ? controllers.front : controllers.back;
2021-11-01 20:44:57 +01:00
if (parseMotorControllerCanMessage<false>(message, front))
{
if (espchrono::millis_clock::now() - back.lastCanFeedback > 100ms)
back.feedbackValid = false;
front.lastCanFeedback = espchrono::millis_clock::now();
front.feedbackValid = true;
return true;
}
else
{
if (espchrono::millis_clock::now() - front.lastCanFeedback > 100ms)
front.feedbackValid = false;
}
if (parseMotorControllerCanMessage<true>(message, back))
{
back.lastCanFeedback = espchrono::millis_clock::now();
back.feedbackValid = true;
return true;
}
else
{
if (espchrono::millis_clock::now() - back.lastCanFeedback > 100ms)
back.feedbackValid = false;
}
if (parseBoardcomputerCanMessage(message))
return true;
2022-09-17 22:43:52 +02:00
ESP_LOGW(TAG, "Unknown CAN info received .identifier = %lu", message.identifier);
2021-11-01 20:44:57 +01:00
return true;
}
2022-01-04 02:39:22 +01:00
} // namespace
2021-11-01 20:44:57 +01:00
void sendCanCommands()
{
2021-12-29 04:36:22 +01:00
static uint32_t can_sequential_error_cnt = 0;
2022-02-21 20:41:22 +01:00
static uint32_t can_sequential_bus_errors = 0;
2021-12-29 04:36:22 +01:00
if (!configs.controllerHardware.sendFrontCanCmd.value() && !configs.controllerHardware.sendBackCanCmd.value())
return;
2021-11-01 20:44:57 +01:00
constexpr auto send = [](uint32_t addr, auto value){
twai_message_t message;
2022-02-21 20:41:22 +01:00
twai_status_info_t status_info;
2021-11-01 20:44:57 +01:00
message.identifier = addr;
message.flags = TWAI_MSG_FLAG_SS;
message.data_length_code = sizeof(value);
std::fill(std::begin(message.data), std::end(message.data), 0);
std::memcpy(message.data, &value, sizeof(value));
2022-04-29 22:40:49 +02:00
const auto timeout = std::chrono::ceil<espcpputils::ticks>(espchrono::milliseconds32{configs.controllerHardware.canTransmitTimeout.value()}).count();
2021-12-29 03:11:31 +01:00
const auto timestamp_before = espchrono::millis_clock::now();
2021-11-01 20:44:57 +01:00
const auto result = twai_transmit(&message, timeout);
2022-02-21 20:41:22 +01:00
const auto status = twai_get_status_info(&status_info);
2022-01-04 00:54:40 +01:00
const auto timestamp_after = espchrono::millis_clock::now();
2022-01-01 19:58:19 +01:00
2022-08-05 21:00:58 +02:00
if ((result == ESP_ERR_TIMEOUT || status_info.state == TWAI_STATE_BUS_OFF) ||
(status == ESP_OK && status_info.bus_error_count > can_sequential_bus_errors))
2022-01-01 19:58:19 +01:00
{
2021-12-29 03:43:09 +01:00
++can_sequential_error_cnt;
++can_total_error_cnt;
2022-02-21 20:41:22 +01:00
can_sequential_bus_errors = status_info.bus_error_count;
2021-12-29 04:36:22 +01:00
2022-10-30 02:19:27 +02:00
if (can_total_error_cnt < 500 && (configs.canUninstallOnReset.value() && can_total_error_cnt < 100))
2022-10-01 02:48:24 +02:00
ESP_LOGW(TAG, "twai_transmit() failed after %lldms with %s, seq err: %lu, total err: %lu",
std::chrono::floor<std::chrono::milliseconds>(timestamp_after - timestamp_before).count(),
esp_err_to_name(result),
can_sequential_error_cnt,
can_total_error_cnt);
2022-01-01 19:58:19 +01:00
}
2022-01-04 00:54:40 +01:00
else if (result != ESP_OK)
{
2022-09-08 22:13:22 +02:00
ESP_LOGE(TAG, "twai_transmit() failed after %lldms with %s",
std::chrono::floor<std::chrono::milliseconds>(timestamp_after - timestamp_before).count(),
2022-01-04 00:54:40 +01:00
esp_err_to_name(result));
}
2022-01-01 19:58:19 +01:00
else
{
2021-12-29 03:11:31 +01:00
can_sequential_error_cnt = 0;
}
2022-01-01 19:58:19 +01:00
if (can_sequential_error_cnt > 3)
{
2021-12-29 03:11:31 +01:00
can_sequential_error_cnt = 0;
2022-04-29 22:40:49 +02:00
if (configs.canResetOnError.value())
2022-01-01 19:58:19 +01:00
{
2022-09-08 22:13:22 +02:00
ESP_LOGW(TAG, "Something isn't right, trying to restart can ic...");
2022-01-01 19:58:19 +01:00
if (const auto err = twai_stop(); err != ESP_OK)
{
2022-09-08 22:13:22 +02:00
ESP_LOGE(TAG, "twai_stop() failed with %s", esp_err_to_name(err));
2022-01-01 19:58:19 +01:00
}
2022-03-23 19:51:35 +01:00
2022-04-29 22:40:49 +02:00
if (configs.canUninstallOnReset.value())
2022-03-23 19:51:35 +01:00
{
if (const auto err = twai_driver_uninstall(); err != ESP_OK) {
2022-09-08 22:13:22 +02:00
ESP_LOGE(TAG, "twai_driver_uninstall() failed with %s", esp_err_to_name(err));
2022-03-23 19:51:35 +01:00
}
twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(GPIO_NUM_21, GPIO_NUM_22,
TWAI_MODE_NORMAL);
twai_timing_config_t t_config = TWAI_TIMING_CONFIG_250KBITS();
twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL();
if (const auto err = twai_driver_install(&g_config, &t_config, &f_config); err != ESP_OK) {
2022-09-08 22:13:22 +02:00
ESP_LOGE(TAG, "twai_driver_install() failed with %s", esp_err_to_name(err));
2022-03-23 19:51:35 +01:00
}
}
2022-01-01 19:58:19 +01:00
if (const auto err = twai_start(); err != ESP_OK)
{
2022-09-08 22:13:22 +02:00
ESP_LOGE(TAG, "twai_start() failed with %s", esp_err_to_name(err));
2022-01-01 19:58:19 +01:00
}
2021-12-29 03:11:31 +01:00
}
}
2021-11-01 20:44:57 +01:00
return result;
};
2022-04-29 22:40:49 +02:00
const bool swap = configs.controllerHardware.swapFrontBack.value();
2021-11-01 20:44:57 +01:00
const Controller *front =
2022-04-29 22:40:49 +02:00
(swap ? configs.controllerHardware.sendBackCanCmd.value() : configs.controllerHardware.sendFrontCanCmd.value() ) ?
2021-11-01 20:44:57 +01:00
(swap ? &controllers.back : &controllers.front) :
nullptr;
const Controller *back =
2022-04-29 22:40:49 +02:00
(swap ? configs.controllerHardware.sendFrontCanCmd.value() : configs.controllerHardware.sendBackCanCmd.value() ) ?
2021-11-01 20:44:57 +01:00
(swap ? &controllers.front : &controllers.back) :
nullptr;
using namespace bobbycar::protocol::can;
2022-02-12 19:07:34 +01:00
#ifdef HAS_SIMPLIFIED
SIMPLIFIED_PWM
#else
2021-11-01 20:44:57 +01:00
if (front) send(MotorController<false, false>::Command::InpTgt, front->command.left.pwm);
if (front) send(MotorController<false, true>::Command::InpTgt, front->command.right.pwm);
if (back) send(MotorController<true, false>::Command::InpTgt, back->command.left.pwm);
if (back) send(MotorController<true, true>::Command::InpTgt, back->command.right.pwm);
2022-02-12 19:07:34 +01:00
#endif
2021-11-01 20:44:57 +01:00
uint16_t buttonLeds{};
if (const auto index = settingsPersister.currentlyOpenProfileIndex())
switch (*index)
{
2022-04-25 20:25:31 +02:00
case 0: buttonLeds |= std::to_underlying(Boardcomputer::Button::Profile0); break;
case 1: buttonLeds |= std::to_underlying(Boardcomputer::Button::Profile1); break;
case 2: buttonLeds |= std::to_underlying(Boardcomputer::Button::Profile2); break;
case 3: buttonLeds |= std::to_underlying(Boardcomputer::Button::Profile3); break;
2021-11-01 20:44:57 +01:00
}
static struct {
struct {
struct {
int16_t nCruiseMotTgt{};
bool cruiseCtrlEna{};
} left, right;
uint8_t freq{};
uint8_t pattern{};
2021-11-01 20:44:57 +01:00
} front, back;
2022-04-25 20:25:31 +02:00
std::underlying_type_t<Boardcomputer::Button> buttonLeds{};
2021-11-01 20:44:57 +01:00
} lastValues;
static int i{};
// anti aufklatsch when tempomat
if ((front && front->command.left.nCruiseMotTgt != lastValues.front.left.nCruiseMotTgt) ||
(front && front->command.right.nCruiseMotTgt != lastValues.front.right.nCruiseMotTgt) ||
(back && back->command.left.nCruiseMotTgt != lastValues.back.left.nCruiseMotTgt) ||
(back && back->command.right.nCruiseMotTgt != lastValues.back.right.nCruiseMotTgt))
i = 8;
else if ((front && front->command.left.cruiseCtrlEna != lastValues.front.left.cruiseCtrlEna) ||
(front && front->command.right.cruiseCtrlEna != lastValues.front.right.cruiseCtrlEna) ||
(back && back->command.left.cruiseCtrlEna != lastValues.back.left.cruiseCtrlEna) ||
(back && back->command.right.cruiseCtrlEna != lastValues.back.right.cruiseCtrlEna))
i = 9;
else if ((front && front->command.buzzer.freq != lastValues.front.freq ) ||
(front && front->command.buzzer.pattern != lastValues.front.pattern ) ||
(back && back->command.buzzer.freq != lastValues.back.freq) ||
(back && back->command.buzzer.pattern != lastValues.back.pattern))
2021-11-01 20:44:57 +01:00
i = 10;
else if (buttonLeds != lastValues.buttonLeds)
i = 12;
switch (i++)
{
case 0:
if (front) send(MotorController<false, false>::Command::Enable, front->command.left.enable);
if (front) send(MotorController<false, true>::Command::Enable, front->command.right.enable);
if (back) send(MotorController<true, false>::Command::Enable, back->command.left.enable);
if (back) send(MotorController<true, true>::Command::Enable, back->command.right.enable);
break;
case 1:
2022-02-08 10:59:47 +01:00
#ifdef HAS_SIMPLIFIED
SIMPLIFIED_CONTROLTYPE
#endif
2021-11-01 20:44:57 +01:00
if (front) send(MotorController<false, false>::Command::CtrlTyp, front->command.left.ctrlTyp);
if (front) send(MotorController<false, true>::Command::CtrlTyp, front->command.right.ctrlTyp);
if (back) send(MotorController<true, false>::Command::CtrlTyp, back->command.left.ctrlTyp);
if (back) send(MotorController<true, true>::Command::CtrlTyp, back->command.right.ctrlTyp);
break;
case 2:
2022-02-08 10:59:47 +01:00
#ifdef HAS_SIMPLIFIED
SIMPLIFIED_CONTROLMODE
#endif
2021-11-01 20:44:57 +01:00
if (front) send(MotorController<false, false>::Command::CtrlMod, front->command.left.ctrlMod);
if (front) send(MotorController<false, true>::Command::CtrlMod, front->command.right.ctrlMod);
if (back) send(MotorController<true, false>::Command::CtrlMod, back->command.left.ctrlMod);
if (back) send(MotorController<true, true>::Command::CtrlMod, back->command.right.ctrlMod);
handbremse::finishedMotorUpdate = true;
2021-11-01 20:44:57 +01:00
break;
case 3:
2022-02-08 10:59:47 +01:00
#ifdef HAS_SIMPLIFIED
2021-11-01 20:44:57 +01:00
SIMPLIFIED_IMOTMAX
#endif
if (front) send(MotorController<false, false>::Command::IMotMax, front->command.left.iMotMax);
if (front) send(MotorController<false, true>::Command::IMotMax, front->command.right.iMotMax);
if (back) send(MotorController<true, false>::Command::IMotMax, back->command.left.iMotMax);
if (back) send(MotorController<true, true>::Command::IMotMax, back->command.right.iMotMax);
break;
case 4:
2022-02-08 10:59:47 +01:00
#ifdef HAS_SIMPLIFIED
2021-11-01 20:44:57 +01:00
SIMPLIFIED_IDCMAX
#endif
if (front) send(MotorController<false, false>::Command::IDcMax, front->command.left.iDcMax);
if (front) send(MotorController<false, true>::Command::IDcMax, front->command.right.iDcMax);
if (back) send(MotorController<true, false>::Command::IDcMax, back->command.left.iDcMax);
if (back) send(MotorController<true, true>::Command::IDcMax, back->command.right.iDcMax);
break;
case 5:
2022-02-08 10:59:47 +01:00
#ifdef HAS_SIMPLIFIED
2021-11-01 20:44:57 +01:00
SIMPLIFIED_NMOTMAX
#endif
if (front) send(MotorController<false, false>::Command::NMotMax, front->command.left.nMotMax);
if (front) send(MotorController<false, true>::Command::NMotMax, front->command.right.nMotMax);
if (back) send(MotorController<true, false>::Command::NMotMax, back->command.left.nMotMax);
if (back) send(MotorController<true, true>::Command::NMotMax, back->command.right.nMotMax);
break;
case 6:
2022-02-08 10:59:47 +01:00
#ifdef HAS_SIMPLIFIED
2021-11-01 20:44:57 +01:00
SIMPLIFIED_FIELDWEAKMAX
#endif
if (front) send(MotorController<false, false>::Command::FieldWeakMax, front->command.left.fieldWeakMax);
if (front) send(MotorController<false, true>::Command::FieldWeakMax, front->command.right.fieldWeakMax);
if (back) send(MotorController<true, false>::Command::FieldWeakMax, back->command.left.fieldWeakMax);
if (back) send(MotorController<true, true>::Command::FieldWeakMax, back->command.right.fieldWeakMax);
break;
case 7:
if (front) send(MotorController<false, false>::Command::PhaseAdvMax, front->command.left.phaseAdvMax);
if (front) send(MotorController<false, true>::Command::PhaseAdvMax, front->command.right.phaseAdvMax);
if (back) send(MotorController<true, false>::Command::PhaseAdvMax, back->command.left.phaseAdvMax);
if (back) send(MotorController<true, true>::Command::PhaseAdvMax, back->command.right.phaseAdvMax);
break;
case 8:
if (front) send(MotorController<false, false>::Command::CruiseMotTgt, front->command.left.nCruiseMotTgt);
if (front) send(MotorController<false, true>::Command::CruiseMotTgt, front->command.right.nCruiseMotTgt);
if (back) send(MotorController<true, false>::Command::CruiseMotTgt, back->command.left.nCruiseMotTgt);
if (back) send(MotorController<true, true>::Command::CruiseMotTgt, back->command.right.nCruiseMotTgt);
break;
case 9:
if (front) send(MotorController<false, false>::Command::CruiseCtrlEna, front->command.left.cruiseCtrlEna);
if (front) send(MotorController<false, true>::Command::CruiseCtrlEna, front->command.right.cruiseCtrlEna);
if (back) send(MotorController<true, false>::Command::CruiseCtrlEna, back->command.left.cruiseCtrlEna);
if (back) send(MotorController<true, true>::Command::CruiseCtrlEna, back->command.right.cruiseCtrlEna);
break;
2021-11-01 20:44:57 +01:00
case 10:
if (front && send(MotorController<false, false>::Command::BuzzerFreq, front->command.buzzer.freq) == ESP_OK)
lastValues.front.freq = front->command.buzzer.freq;
// if (front && send(MotorController<false, true>::Command::BuzzerFreq, front->command.buzzer.freq) == ESP_OK)
// lastValues.front.freq = front->command.buzzer.freq;
if (back && send(MotorController<true, false>::Command::BuzzerFreq, back->command.buzzer.freq) == ESP_OK)
lastValues.back.freq = back->command.buzzer.freq;
// if (back && send(MotorController<true, true>::Command::BuzzerFreq, back->command.buzzer.freq) == ESP_OK)
// lastValues.back.freq = back->command.buzzer.freq;
if (front && send(MotorController<false, false>::Command::BuzzerPattern, front->command.buzzer.pattern) == ESP_OK)
lastValues.front.pattern = front->command.buzzer.pattern;
// if (front && send(MotorController<false, true>::Command::BuzzerPattern, front->command.buzzer.pattern) == ESP_OK)
// lastValues.front.pattern = front->command.buzzer.pattern;
if (back && send(MotorController<true, false>::Command::BuzzerPattern, back->command.buzzer.pattern) == ESP_OK)
lastValues.back.pattern = back->command.buzzer.pattern;
// if (back && send(MotorController<true, true>::Command::BuzzerPattern, back->command.buzzer.pattern) == ESP_OK)
// lastValues.back.pattern = back->command.buzzer.pattern;
break;
case 11:
if (front) send(MotorController<false, false>::Command::Led, front->command.led);
//if (front) send(MotorController<false, true>::Command::Led, front->command.led);
if (back) send(MotorController<true, false>::Command::Led, back->command.led);
//if (back) send(MotorController<true, true>::Command::Led, back->command.led);
if (front) send(MotorController<false, false>::Command::Poweroff, front->command.poweroff);
//if (front) send(MotorController<false, true>::Command::Poweroff, front->command.poweroff);
if (back) send(MotorController<true, false>::Command::Poweroff, back->command.poweroff);
//if (back) send(MotorController<true, true>::Command::Poweroff, back->command.poweroff);
break;
case 12:
if (send(Boardcomputer::Feedback::ButtonLeds, buttonLeds) == ESP_OK)
lastValues.buttonLeds = buttonLeds;
[[fallthrough]];
default:
i=0;
break;
}
}
} // namespace can
2021-11-24 16:43:17 +01:00
#endif