Red Bird Racing VCU v2
 
Loading...
Searching...
No Matches
Debug_can.cpp
Go to the documentation of this file.
1/**
2 * @file Debug_can.cpp
3 * @author Planeson, Chiho, Red Bird Racing
4 * @brief Implementation of the Debug_CAN namespace for CAN debugging functions
5 * @version 2.0
6 * @date 2026-02-25
7 * @see Debug_can.hpp
8 */
9
10#include "Debug_can.hpp"
11
12// ignore -Wpedantic warnings for mcp2515.h
13#pragma GCC diagnostic push
14#pragma GCC diagnostic ignored "-Wpedantic"
15#include <mcp2515.h>
16#pragma GCC diagnostic pop
17
18MCP2515 *Debug_CAN::can_interface = nullptr;
19
20/**
21 * @brief Initializes the Debug_CAN interface.
22 * It should be called before using any other Debug_CAN functions.
23 *
24 * @param can Pointer to the MCP2515 CAN controller instance.
25 */
26void Debug_CAN::initialize(MCP2515 *can)
27{
28 if (can == nullptr)
29 return;
30 can_interface = can;
31}
32
33/**
34 * @brief Sends arbitrary debug data via CAN with specified message ID and data bytes.
35 *
36 * @param id CAN message ID
37 * @param data0 Byte 0 of CAN data (default 0x00)
38 * @param data1 Byte 1 of CAN data (default 0x00)
39 * @param data2 Byte 2 of CAN data (default 0x00)
40 * @param data3 Byte 3 of CAN data (default 0x00)
41 * @param data4 Byte 4 of CAN data (default 0x00)
42 * @param data5 Byte 5 of CAN data (default 0x00)
43 * @param data6 Byte 6 of CAN data (default 0x00)
44 * @param data7 Byte 7 of CAN data (default 0x00)
45 */
47 canid_t id,
48 uint8_t data0,
49 uint8_t data1,
50 uint8_t data2,
51 uint8_t data3,
52 uint8_t data4,
53 uint8_t data5,
54 uint8_t data6,
55 uint8_t data7)
56{
57 if (!can_interface)
58 return;
59
60 can_frame tx_msg;
61 tx_msg.can_id = id;
62 tx_msg.can_dlc = 8;
63
64 tx_msg.data[0] = data0;
65 tx_msg.data[1] = data1;
66 tx_msg.data[2] = data2;
67 tx_msg.data[3] = data3;
68 tx_msg.data[4] = data4;
69 tx_msg.data[5] = data5;
70 tx_msg.data[6] = data6;
71 tx_msg.data[7] = data7;
72
73 can_interface->sendMessage(&tx_msg);
74}
Declaration of the Debug_CAN namespace for CAN debugging functions.
void initialize(MCP2515 *can_interface)
Initializes the Debug_CAN interface. It should be called before using any other Debug_CAN functions.
Definition: Debug_can.cpp:26
void send_message(canid_t id, uint8_t data0=0x00, uint8_t data1=0x00, uint8_t data2=0x00, uint8_t data3=0x00, uint8_t data4=0x00, uint8_t data5=0x00, uint8_t data6=0x00, uint8_t data7=0x00)
Sends arbitrary debug data via CAN with specified message ID and data bytes.
Definition: Debug_can.cpp:46
MCP2515 * can_interface
Definition: Debug_can.cpp:18