42 inline static FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_16> can2;
72 template <std::
size_t N>
73 static int send_message(
unsigned len,
const std::array<uint8_t, N> &buffer,
unsigned id);
131 can2.setBaudRate(500000);
135 can2.enableFIFOInterrupt();
138 can2.setFIFOFilter(REJECT_ALL);
139 for (
auto &fifoCode :
fifoCodes) can2.setFIFOFilter(fifoCode.key, fifoCode.code, STD);
143 can2.setFIFOFilter(fifoExtendedCode.key, fifoExtendedCode.code, EXT);
149 can2.mailboxStatus();
156 double right_wheel_rpm = (buf[4] << 24) | (buf[3] << 16) | (buf[2] << 8) | buf[1];
160 double left_wheel_rpm = (buf[4] << 24) | (buf[3] << 16) | (buf[2] << 8) | buf[1];
167 bool emg_stop1 = buf[0] & 0x01;
168 bool emg_stop2 = buf[3] >> 7 & 0x01;
169 bool go_switch = (buf[0] >> 1) & 0x01;
170 bool go_button = (buf[0] >> 2) & 0x01;
174 if (go_button || go_switch)
176 else if (!emg_stop1 && !emg_stop2) {
182 bool signal_loss = (buf[7] >> 6) & 0x01;
206 if (buf[1] ==
false) {
211 }
else if (buf[0] ==
VDC_BUS) {
212 unsigned dc_voltage = (buf[2] << 8) | buf[1];
218 DEBUG_PRINT(
"DC Voltage Drop under defined value for more than 150ms");
273 const std::array<uint8_t, 2>
msg = {
STATE_MSG,
static_cast<uint8_t
>(state_id)};
279 const std::array<uint8_t, 2>
msg = {
MISSION_MSG,
static_cast<uint8_t
>(mission_id)};
286 uint8_t state_checkup) {
302 const std::array<uint8_t, 8>
msg = {
304 (hydraulic_pressure >> 24) & 0xFF,
305 (hydraulic_pressure >> 16) & 0xFF,
306 (hydraulic_pressure >> 8) & 0xFF,
307 hydraulic_pressure & 0xFF,
308 (emergency_signal_bit & 0x01) << 7 | (pneumatic_line_pressure_bit & 0x01) << 6 |
309 (engage_ebs_check_bit & 0x01) << 5 | (release_ebs_check_bit & 0x01) << 4 |
310 (steer_dead_bit & 0x01) << 3 | (pc_dead_bit & 0x01) << 2 |
311 (inversor_dead_bit & 0x01) << 1 | (res_dead_bit & 0x01),
312 (asms_on_bit & 0x01) << 7 | (ts_on_bit & 0x01) << 6 | (sdc_state_open_bit & 0x01) << 5 |
313 (state_checkup & 0x0F),
314 (mission & 0x0F) | ((state & 0x0F) << 4)};
323 (dc_voltage >> 24) & 0xFF,
324 (dc_voltage >> 16) & 0xFF,
325 (dc_voltage >> 8) & 0xFF,
327 pneumatic_line_pressure_bit_1 & 0x01,
328 pneumatic_line_pressure_bit_2 & 0x01};
334 std::array<uint8_t, 5>
msg;
341template <std::
size_t N>
344 CAN_message_t can_message;
346 can_message.len = len;
347 for (
unsigned i = 0; i < len; i++) {
348 can_message.buf[i] = buffer[i];
350 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.
void init()
Initializes the CAN bus.
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 c1_callback(const uint8_t *buf)
Callback for data from C1 Teensy.
static void pc_callback(const uint8_t *buf)
Callback for message from AS CU.
static void bamocar_callback(const uint8_t *buf)
Callback from inversor, for alive signal and data.
static int publish_debug_log(SystemData system_data, uint8_t sate, uint8_t state_checkup)
Publish AS Mission to CAN.
static SystemData * _systemData
static void res_ready_callback()
Callback for RES activation.
static int publish_left_wheel_rpm(double value)
Publish rl wheel rpm to CAN.
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< 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...
constexpr auto RIGHT_WHEEL_CODE
constexpr auto AS_CU_EMERGENCY_SIGNAL
constexpr auto RES_ACTIVATE
constexpr auto STEERING_ID
constexpr auto MISSION_FINISHED
constexpr auto MISSION_MSG
constexpr auto HYDRAULIC_LINE
constexpr auto LEFT_WHEEL_CODE
constexpr auto DBG_LOG_MSG_2
constexpr auto DBG_LOG_MSG
constexpr auto WHEEL_PRECISION
#define DEBUG_PRINT_VAR(var)
constexpr auto to_underlying(Enum e) noexcept
bool pneumatic_line_pressure_1_
bool pneumatic_line_pressure_
bool pneumatic_line_pressure_2_
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_
bool process_go_signal()
Processes the go signal.
Metro releaseEbsTimestamp
int _hydraulic_line_pressure
The whole model of the system: holds all the data necessary.
DigitalData digital_data_
FailureDetection failure_detection_
void create_left_wheel_msg(std::array< uint8_t, 5 > &msg, double value)
Function to create left wheel msg.