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 (size_t idx, CANDriver *device)
 

Data Fields

CanCategory category
 
size_t busIndex = 0
 

Protected Attributes

CANTxFrame m_frame
 

Static Private Attributes

static CANDriver * s_devices [EFI_CAN_BUS_COUNT]
 

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 40 of file can_msg_tx.cpp.

40 {
41 category = p_category;
42#if HAS_CAN_FRAME
43#ifndef STM32H7XX
44 // ST bxCAN device
45 m_frame.IDE = isExtended ? CAN_IDE_EXT : CAN_IDE_STD;
46 m_frame.RTR = CAN_RTR_DATA;
47#else /* if STM32H7XX */
48 // Bosch M_CAN FDCAN device
49 m_frame.common.XTD = isExtended;
50 m_frame.common.RTR = 0;
51#endif
52
53 if (isExtended) {
54 CAN_EID(m_frame) = eid;
55 } else {
56 if (eid >= 0x800) {
57 criticalError("Looks like extended CAN ID %x %s", eid, getCanCategory(category));
58 return;
59 }
60 CAN_SID(m_frame) = eid;
61 }
62
63 setDlc(dlc);
64
65 setBus(bus);
66
68#endif // HAS_CAN_FRAME
69}
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 71 of file can_msg_tx.cpp.

71 {
72#if EFI_SIMULATOR || EFI_UNIT_TEST
74
75#if EFI_UNIT_TEST
76 printf("%s Sending CAN%d message: ID=%x/l=%x %x %x %x %x %x %x %x %x \n",
78 busIndex + 1,
79 (unsigned int)CAN_ID(m_frame),
84 m_frame.data8[6], m_frame.data8[7]);
85#endif
86#endif // EFI_SIMULATOR
87
88#if EFI_CAN_SUPPORT
90
91 if (!engine->allowCanTx) {
92 return;
93 }
94
96 if (!device) {
97 criticalError("Send: CAN%d device not configured %s %x", busIndex + 1, getCanCategory(category),
98 (unsigned int)CAN_ID(m_frame));
99 return;
100 }
101
102 bool verboseCan = engineConfiguration->verboseCan && busIndex == 0;
103 verboseCan |= engineConfiguration->verboseCan2 && busIndex == 1;
104#if (EFI_CAN_BUS_COUNT >= 3)
105 verboseCan |= engineConfiguration->verboseCan3 && busIndex == 2;
106#endif
107
108 if (verboseCan) {
109 efiPrintf("%s Sending CAN%d message: ID=%x/l=%x %x %x %x %x %x %x %x %x",
111 busIndex + 1,
112 (unsigned int)CAN_ID(m_frame),
113 m_frame.DLC,
114 m_frame.data8[0], m_frame.data8[1],
115 m_frame.data8[2], m_frame.data8[3],
116 m_frame.data8[4], m_frame.data8[5],
117 m_frame.data8[6], m_frame.data8[7]);
118 }
119
120 // 100 ms timeout
121 msg_t msg = canTransmit(device, CAN_ANY_MAILBOX, &m_frame, TIME_MS2I(100));
122#if EFI_TUNER_STUDIO
123 if (msg == MSG_OK) {
125 } else {
127 }
128#endif // EFI_TUNER_STUDIO
129#endif /* EFI_CAN_SUPPORT */
130}
fifo_buffer< CANTxFrame, 1024 > txCanBuffer
static CANDriver * s_devices[EFI_CAN_BUS_COUNT]
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 157 of file can_msg_tx.cpp.

157 {
158 return m_frame.data8[index];
159}

◆ 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 153 of file can_msg_tx.cpp.

153 {
154 m_frame.data8[byteIdx] |= 1 << bitIdx;
155}

Referenced by canDashboardHaltech(), and canMazdaRX8().

Here is the caller graph for this function:

◆ setBus()

void CanTxMessage::setBus ( size_t  bus)

Definition at line 137 of file can_msg_tx.cpp.

137 {
138 busIndex = bus;
139}

Referenced by CanTxMessage().

Here is the caller graph for this function:

◆ setDevice()

void CanTxMessage::setDevice ( size_t  idx,
CANDriver *  device 
)
static

Configures the device for all messages to transmit from.

Definition at line 31 of file can_msg_tx.cpp.

31 {
32 if (idx > efi::size(s_devices)) {
33 criticalError("Attemp to install CAN%d bus!", idx + 1);
34 return;
35 }
36 s_devices[idx] = device;
37}

Referenced by initCan().

Here is the caller graph for this function:

◆ setDlc()

void CanTxMessage::setDlc ( uint8_t  dlc)

Definition at line 133 of file can_msg_tx.cpp.

133 {
134 m_frame.DLC = dlc;
135}

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 142 of file can_msg_tx.cpp.

142 {
143 m_frame.data8[offset] = value & 0xFF;
144 m_frame.data8[offset + 1] = value >> 8;
145}
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 148 of file can_msg_tx.cpp.

148 {
149 m_frame.data8[offset] = value >> 8;
150 m_frame.data8[offset + 1] = value & 0xFF;
151}

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
staticprivate
Initial value:
= {
nullptr,
nullptr,
#if (EFI_CAN_BUS_COUNT >= 3)
nullptr
#endif
}

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: