8#include "../../CAN_IDs.h"
14#include "../utils.hpp"
20inline std::array<Code, 7>
fifoCodes = {{{0, DASH_ID},
21 {1, BAMO_RESPONSE_ID},
22 {2, AS_CU_EMERGENCY_SIGNAL},
23 {3, MISSION_FINISHED},
44 inline static FlexCAN_T4<CAN3, RX_SIZE_256, TX_SIZE_16> can2;
74 template <std::
size_t N>
75 static int send_message(
unsigned len,
const std::array<uint8_t, N> &buffer,
unsigned id);
123 uint8_t state_checkup);
135 can2.setBaudRate(500000);
138 can2.enableFIFOInterrupt();
140 can2.setFIFOFilter(REJECT_ALL);
141 for (
auto &fifoCode :
fifoCodes) can2.setFIFOFilter(fifoCode.key, fifoCode.code, STD);
144 can2.setFIFOFilter(fifoExtendedCode.key, fifoExtendedCode.code, EXT);
148 can2.mailboxStatus();
152 bool emg_stop1 = buf[0] & 0x01;
153 bool emg_stop2 = buf[3] >> 7 & 0x01;
154 bool go_switch = (buf[0] >> 1) & 0x01;
155 bool go_button = (buf[0] >> 2) & 0x01;
157 if (go_button || go_switch)
159 else if (!(emg_stop1 || emg_stop2)) {
164 bool signal_loss = (buf[7] >> 6) & 0x01;
177 std::array<uint8_t, 2>
msg = {0x01, NODE_ID};
185 if (buf[0] == BTB_READY) {
186 if (buf[1] ==
false) {
189 }
else if (buf[0] == BAMOCAR_BATTERY_VOLTAGE_CODE) {
190 unsigned dc_voltage = (buf[2] << 8) | buf[1];
194 if (dc_voltage < DC_THRESHOLD) {
213 if (buf[0] == PC_ALIVE) {
215 }
else if (buf[0] == MISSION_FINISHED) {
217 }
else if (buf[0] == AS_CU_EMERGENCY_SIGNAL) {
236 case BAMO_RESPONSE_ID:
248 const std::array<uint8_t, 2>
msg = {STATE_MSG,
static_cast<uint8_t
>(state_id)};
254 const std::array<uint8_t, 2>
msg = {MISSION_MSG,
static_cast<uint8_t
>(mission_id)};
260 uint8_t state_checkup) {
267 const std::array<uint8_t, 2>
msg = {SOC_MSG, soc};
273 const std::array<uint8_t, 2>
msg = {ASMS_ON, asms_on};
279 std::array<uint8_t, 5> rl_rpm_msg = {0};
280 std::array<uint8_t, 5> rr_rpm_msg = {0};
287 rl_rpm_msg[0] = LEFT_WHEEL_CODE;
288 for (
int i = 0; i < 4; i++) {
289 rl_rpm_msg[i + 1] = rl_rpm_byte[i];
292 rr_rpm_msg[0] = RIGHT_WHEEL_CODE;
293 for (
int i = 0; i < 4; i++) {
294 rr_rpm_msg[i + 1] = rr_rpm_byte[i];
302template <std::
size_t N>
305 CAN_message_t can_message;
307 can_message.len = len;
308 for (
unsigned i = 0; i < len; i++) {
309 can_message.buf[i] = buffer[i];
311 can2.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 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 void res_ready_callback()
Callback for RES activation.
static int publish_state(int state_id)
Publish AS State to CAN.
void reset()
Resets the timer to the current time.
bool checkWithoutReset() const
Checks if the interval has passed without resetting the timer.
std::array< uint8_t, 8 > create_debug_message_1(const SystemData &system_data, uint8_t state, uint8_t state_checkup)
std::array< uint8_t, 7 > create_debug_message_2(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, 7 > fifoCodes
Array of standard CAN message codes to be used for FIFO filtering Each Code struct contains a key and...
Metro pc_alive_timestamp_
Metro dc_voltage_hold_timestamp_
Metro steer_alive_timestamp_
Metro res_signal_loss_timestamp_
Metro dc_voltage_drop_timestamp_
Metro inversor_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_
void rpm_2_byte(const float rr_rpm, char *rr_rpm_byte)