rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Data Fields | Protected Attributes | Static Private Attributes
CanTxMessage Class Reference

#include <can_msg_tx.h>

Inheritance diagram for CanTxMessage:
Inheritance graph
[legend]
Collaboration diagram for CanTxMessage:
Collaboration graph
[legend]

Public Member Functions

 CanTxMessage (CanCategory category, uint32_t eid, uint8_t dlc=8, size_t bus=0, bool isExtended=false)
 
 ~CanTxMessage ()
 
uint8_t & operator[] (size_t)
 Read & write the raw underlying 8-byte buffer.
 
void setShortValue (uint16_t value, size_t offset)
 Write a 16-bit short value to the buffer. Note: this writes in Intel little endian byte order.
 
void setShortValueMsb (uint16_t value, size_t offset)
 
void setBit (size_t byteIdx, size_t bitIdx)
 Set a single bit in the transmit buffer. Useful for single-bit flags.
 
void setDlc (uint8_t dlc)
 
void setBus (size_t bus)
 
const CANTxFramegetFrame () const
 
void setArray (const uint8_t *data, size_t len)
 
template<size_t N>
void setArray (const uint8_t(&data)[N])
 

Static Public Member Functions

static void setDevice (CANDriver *device1, CANDriver *device2)
 

Data Fields

CanCategory category
 
size_t busIndex = 0
 

Protected Attributes

CANTxFrame m_frame
 

Static Private Attributes

static CANDriver * s_devices [2] = {nullptr, nullptr}
 

Detailed Description

Represent a message to be transmitted over CAN.

Usage:

Definition at line 31 of file can_msg_tx.h.

Constructor & Destructor Documentation

◆ CanTxMessage()

CanTxMessage::CanTxMessage ( CanCategory  category,
uint32_t  eid,
uint8_t  dlc = 8,
size_t  bus = 0,
bool  isExtended = false 
)
explicit

Create a new CAN message, with the specified extended ID.

Definition at line 31 of file can_msg_tx.cpp.

31 {
32 category = p_category;
33#if HAS_CAN_FRAME
34#ifndef STM32H7XX
35 // ST bxCAN device
36 m_frame.IDE = isExtended ? CAN_IDE_EXT : CAN_IDE_STD;
37 m_frame.RTR = CAN_RTR_DATA;
38#else /* if STM32H7XX */
39 // Bosch M_CAN FDCAN device
40 m_frame.common.XTD = isExtended;
41 m_frame.common.RTR = 0;
42#endif
43
44 if (isExtended) {
45 CAN_EID(m_frame) = eid;
46 } else {
47 if (eid >= 0x800) {
48 criticalError("Looks like extended CAN ID %x %s", eid, getCanCategory(category));
49 return;
50 }
51 CAN_SID(m_frame) = eid;
52 }
53
54 setDlc(dlc);
55
56 setBus(bus);
57
59#endif // HAS_CAN_FRAME
60}
const char * getCanCategory(CanCategory value)
void setBus(size_t bus)
void setDlc(uint8_t dlc)
CanCategory category
Definition can_msg_tx.h:44
CANTxFrame m_frame
Definition can_msg_tx.h:100
uint8_t data8[8]
Frame data.
Definition can_mocks.h:27
uint8_t RTR
Frame type.
Definition can_mocks.h:15
uint8_t IDE
Identifier type.
Definition can_mocks.h:16
void setArrayValues(TValue(&array)[TSize], float value)
Here is the call graph for this function:

◆ ~CanTxMessage()

CanTxMessage::~CanTxMessage ( )

Destruction of an instance of CanTxMessage will transmit the message over the wire.

Definition at line 62 of file can_msg_tx.cpp.

62 {
63#if EFI_SIMULATOR || EFI_UNIT_TEST
65
66#if EFI_UNIT_TEST
67 printf("%s Sending CAN%d message: ID=%x/l=%x %x %x %x %x %x %x %x %x \n",
69 busIndex + 1,
70 (unsigned int)CAN_ID(m_frame),
75 m_frame.data8[6], m_frame.data8[7]);
76#endif
77#endif // EFI_SIMULATOR
78
79#if EFI_CAN_SUPPORT
81
82 if (!engine->allowCanTx) {
83 return;
84 }
85
87 if (!device) {
88 criticalError("Send: CAN%d device not configured %s %x", busIndex + 1, getCanCategory(category),
89 (unsigned int)CAN_ID(m_frame));
90 return;
91 }
92
93 bool verboseCan0 = engineConfiguration->verboseCan && busIndex == 0;
94 bool verboseCan1 = engineConfiguration->verboseCan2 && busIndex == 1;
95
96 if (verboseCan0 || verboseCan1) {
97 efiPrintf("%s Sending CAN%d message: ID=%x/l=%x %x %x %x %x %x %x %x %x",
99 busIndex + 1,
100 (unsigned int)CAN_ID(m_frame),
101 m_frame.DLC,
102 m_frame.data8[0], m_frame.data8[1],
103 m_frame.data8[2], m_frame.data8[3],
104 m_frame.data8[4], m_frame.data8[5],
105 m_frame.data8[6], m_frame.data8[7]);
106 }
107
108 // 100 ms timeout
109 msg_t msg = canTransmit(device, CAN_ANY_MAILBOX, &m_frame, TIME_MS2I(100));
110#if EFI_TUNER_STUDIO
111 if (msg == MSG_OK) {
113 } else {
115 }
116#endif // EFI_TUNER_STUDIO
117#endif /* EFI_CAN_SUPPORT */
118}
fifo_buffer< CANTxFrame, 1024 > txCanBuffer
static CANDriver * s_devices[2]
Definition can_msg_tx.h:23
size_t busIndex
Definition can_msg_tx.h:53
bool allowCanTx
Definition engine.h:114
TunerStudioOutputChannels outputChannels
Definition engine.h:109
static EngineAccessor engine
Definition engine.h:413
static constexpr engine_configuration_s * engineConfiguration
static Lps25 device
Definition init_baro.cpp:4
@ CanDriverTx
uint8_t DLC
Data length.
Definition can_mocks.h:14
printf("\n")
Here is the call graph for this function:

Member Function Documentation

◆ getFrame()

const CANTxFrame * CanTxMessage::getFrame ( ) const
inline

Definition at line 81 of file can_msg_tx.h.

81 {
82 return &m_frame;
83 }

◆ operator[]()

uint8_t & CanTxMessage::operator[] ( size_t  index)

Read & write the raw underlying 8-byte buffer.

Definition at line 145 of file can_msg_tx.cpp.

145 {
146 return m_frame.data8[index];
147}

◆ setArray() [1/2]

void CanTxMessage::setArray ( const uint8_t *  data,
size_t  len 
)
inline

Definition at line 85 of file can_msg_tx.h.

85 {
86 for (size_t i = 0; i < std::min(len, size_t(8)); i++) {
87 m_frame.data8[i] = data[i];
88 }
89 }

Referenced by setArray().

Here is the caller graph for this function:

◆ setArray() [2/2]

template<size_t N>
void CanTxMessage::setArray ( const uint8_t(&)  data[N])
inline

Definition at line 92 of file can_msg_tx.h.

92 {
93 setArray(data, N);
94 }
void setArray(const uint8_t *data, size_t len)
Definition can_msg_tx.h:85
Here is the call graph for this function:

◆ setBit()

void CanTxMessage::setBit ( size_t  byteIdx,
size_t  bitIdx 
)

Set a single bit in the transmit buffer. Useful for single-bit flags.

Definition at line 141 of file can_msg_tx.cpp.

141 {
142 m_frame.data8[byteIdx] |= 1 << bitIdx;
143}

Referenced by canDashboardHaltech(), and canMazdaRX8().

Here is the caller graph for this function:

◆ setBus()

void CanTxMessage::setBus ( size_t  bus)

Definition at line 125 of file can_msg_tx.cpp.

125 {
126 busIndex = bus;
127}

Referenced by CanTxMessage().

Here is the caller graph for this function:

◆ setDevice()

void CanTxMessage::setDevice ( CANDriver *  device1,
CANDriver *  device2 
)
static

Configures the device for all messages to transmit from.

Definition at line 25 of file can_msg_tx.cpp.

25 {
26 s_devices[0] = device1;
27 s_devices[1] = device2;
28}

Referenced by initCan().

Here is the caller graph for this function:

◆ setDlc()

void CanTxMessage::setDlc ( uint8_t  dlc)

Definition at line 121 of file can_msg_tx.cpp.

121 {
122 m_frame.DLC = dlc;
123}

Referenced by CanTxMessage(), and lua_txCan().

Here is the caller graph for this function:

◆ setShortValue()

void CanTxMessage::setShortValue ( uint16_t  value,
size_t  offset 
)

Write a 16-bit short value to the buffer. Note: this writes in Intel little endian byte order.

Definition at line 130 of file can_msg_tx.cpp.

130 {
131 m_frame.data8[offset] = value & 0xFF;
132 m_frame.data8[offset + 1] = value >> 8;
133}
uint16_t offset
Definition tunerstudio.h:0

Referenced by canDashboardBmwE46(), canDashboardBmwE90(), canDashboardFiat(), canDashboardNissanVQ(), canDashboardVAG(), canDashboardVagMqb(), and canMazdaRX8().

Here is the caller graph for this function:

◆ setShortValueMsb()

void CanTxMessage::setShortValueMsb ( uint16_t  value,
size_t  offset 
)

Same as above but big endian Motorola for instance DBC 8|16@0

Definition at line 136 of file can_msg_tx.cpp.

136 {
137 m_frame.data8[offset] = value >> 8;
138 m_frame.data8[offset + 1] = value & 0xFF;
139}

Referenced by canDashboardGenesisCoupe(), canDashboardHaltech(), canDashboardHondaK(), canDashboardNissanVQ(), and canDashboardW202().

Here is the caller graph for this function:

Field Documentation

◆ busIndex

size_t CanTxMessage::busIndex = 0

Definition at line 53 of file can_msg_tx.h.

Referenced by obdSendPacket(), setBus(), and ~CanTxMessage().

◆ category

CanCategory CanTxMessage::category

Definition at line 44 of file can_msg_tx.h.

Referenced by CanTxMessage(), and ~CanTxMessage().

◆ m_frame

CANTxFrame CanTxMessage::m_frame
protected

◆ s_devices

CANDriver * CanTxMessage::s_devices = {nullptr, nullptr}
staticprivate

Definition at line 23 of file can_msg_tx.h.

Referenced by setDevice(), and ~CanTxMessage().


The documentation for this class was generated from the following files: