8#include "../../CAN_IDs.h"
20inline std::array<Code, 8>
fifoCodes = {{{0, DASH_ID},
21 {1, BAMO_RESPONSE_ID},
22 {2, AS_CU_EMERGENCY_SIGNAL},
23 {3, MISSION_FINISHED},
45 inline static FlexCAN_T4<CAN3, RX_SIZE_256, TX_SIZE_16> can3;
75 template <std::
size_t N>
76 static int send_message(
unsigned len,
const std::array<uint8_t, N> &buffer,
unsigned id);
138 uint8_t state_checkup);
150 can3.setBaudRate(1'000'000);
151 can3.setRFFN(RFFN_32);
153 can3.enableFIFOInterrupt();
155 can3.setFIFOFilter(REJECT_ALL);
156 for (
auto &fifoCode :
fifoCodes) can3.setFIFOFilter(fifoCode.key, fifoCode.code, STD);
159 can3.setFIFOFilter(fifoExtendedCode.key, fifoExtendedCode.code, EXT);
163 can3.mailboxStatus();
166 bool emg_stop1 = buf[0] & 0x01;
167 bool emg_stop2 = buf[3] >> 7 & 0x01;
168 bool go_switch = (buf[0] >> 1) & 0x01;
169 bool go_button = (buf[0] >> 2) & 0x01;
173 if (go_button || go_switch)
175 else if (!(emg_stop1 || emg_stop2)) {
181 bool signal_loss = (buf[7] >> 6) & 0x01;
194 std::array<uint8_t, 2>
msg = {0x01, NODE_ID};
202 if (buf[0] == BTB_READY) {
203 if (buf[1] ==
false) {
206 }
else if (buf[0] == BAMOCAR_BATTERY_VOLTAGE_CODE) {
207 unsigned dc_voltage = (buf[2] << 8) | buf[1];
211 if (dc_voltage < DC_THRESHOLD) {
231 if (buf[0] == PC_ALIVE) {
233 }
else if (buf[0] == MISSION_FINISHED) {
235 }
else if (buf[0] == AS_CU_EMERGENCY_SIGNAL) {
246 if (buf[0] == HYDRAULIC_LINE) {
264 case BAMO_RESPONSE_ID:
281 const std::array<uint8_t, 2>
msg = {STATE_MSG,
static_cast<uint8_t
>(state_id)};
287 const std::array<uint8_t, 2>
msg = {MISSION_MSG,
static_cast<uint8_t
>(mission_id)};
293 uint8_t state_checkup) {
302 const std::array<uint8_t, 2>
msg = {SOC_MSG, soc};
308 const std::array<uint8_t, 2>
msg = {ASMS, asms_on};
314 std::array<uint8_t, 5> rl_rpm_msg = {0};
315 std::array<uint8_t, 5> rr_rpm_msg = {0};
322 rl_rpm_msg[0] = LEFT_WHEEL_CODE;
323 for (
int i = 0; i < 4; i++) {
324 rl_rpm_msg[i + 1] = rl_rpm_byte[i];
327 rr_rpm_msg[0] = RIGHT_WHEEL_CODE;
328 for (
int i = 0; i < 4; i++) {
329 rr_rpm_msg[i + 1] = rr_rpm_byte[i];
344 std::array<uint8_t, 2>
msg = {EBS_REDUNDANCY_MSG, ebs_state & 0x0F};
347 std::array<uint8_t, 2>
msg = {EBS_STATE_MSG, ebs_state & 0x0F};
354template <std::
size_t N>
357 CAN_message_t can_message;
359 can_message.len = len;
360 for (
unsigned i = 0; i < len; i++) {
361 can_message.buf[i] = buffer[i];
363 can3.write(can_message);
Class that contains definitions of typical messages to send via CAN It serves only as an example of t...
static void steering_callback()
Callback for steering actuator information.
static int publish_mission(int mission_id)
Publish AS Mission to CAN.
static int publish_rpm()
Publish rl wheel rpm to CAN.
void init()
Initializes the CAN bus.
static int publish_debug_morning_log(const SystemData &system_data, uint8_t sate, uint8_t state_checkup)
Publish AS Mission to CAN.
Communicator(SystemData *systemdata)
Constructor for the Communicator class Initializes the Communicator with the given system data instan...
static void parse_message(const CAN_message_t &msg)
Parses the message received from the CAN bus.
static void res_state_callback(const uint8_t *buf)
Callback RES default callback.
static void dash_callback(const uint8_t *buf)
Callback for dashboard.
static void bms_callback(const uint8_t *buf)
Callback for BMS messages.
static int send_message(unsigned len, const std::array< uint8_t, N > &buffer, unsigned id)
Sends a message to the CAN bus.
static void pc_callback(const uint8_t *buf)
Callback for message from AS CU.
static int publish_soc(uint8_t soc)
Publish SOC to CAN.
static int publish_asms_on(bool asms_on)
Publish ASMS state to CAN.
static void bamocar_callback(const uint8_t *buf)
Callback from inversor, for alive signal and data.
static SystemData * _systemData
static int publish_ebs_states(uint8_t ebs_state, bool is_redundancy=false)
Publish EBS States to CAN.
static void res_ready_callback()
Callback for RES activation.
static int publish_state(int state_id)
Publish AS State to CAN.
void reset() volatile
Resets the timer to the current time.
bool checkWithoutReset() const volatile
Checks if the interval has passed without resetting the timer.
std::array< uint8_t, 8 > create_signals_msg_1(const SystemData &system_data, const uint8_t state, const uint8_t state_checkup)
std::array< uint8_t, 8 > create_hydraulic_presures_msg(const SystemData &system_data)
std::array< Code, 1 > fifoExtendedCodes
Array of extended CAN message codes to be used for FIFO filtering Contains the key and corresponding ...
std::array< Code, 8 > fifoCodes
Array of standard CAN message codes to be used for FIFO filtering Each Code struct contains a key and...
volatile bool emergency_signal_
volatile unsigned dc_voltage_
volatile double radio_quality_
int hydraulic_line_front_pressure
VolatileMetro steer_alive_timestamp_
VolatileMetro pc_alive_timestamp_
VolatileMetro inversor_alive_timestamp_
VolatileMetro res_signal_loss_timestamp_
VolatileMetro dc_voltage_drop_timestamp_
VolatileMetro dc_voltage_hold_timestamp_
VolatileMetro bms_alive_timestamp_
void process_go_signal()
Processes the go signal.
The whole model of the system: holds all the data necessary.
FailureDetection failure_detection_
HardwareData hardware_data_
NonUnitaryFailureDetection updatable_timestamps_
void rpm_2_byte(const float rr_rpm, char *rr_rpm_byte)