rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Data Fields
IsoTpBase Class Reference

#include <isotp.h>

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

Public Member Functions

 IsoTpBase (ICanTransmitter *p_txTransport, size_t p_busIndex, uint32_t p_rxFrameId, uint32_t p_txFrameId)
 
int sendFrame (const IsoTpFrameHeader &header, const uint8_t *data, int num, can_sysinterval_t timeout)
 
void sendFlowControl (can_sysinterval_t timeout)
 
can_msg_t transmit (CanTxMessage &ctfp, can_sysinterval_t timeout)
 

Data Fields

size_t isoHeaderByteIndex = 0
 
ICanTransmittertxTransport
 
size_t busIndex
 
uint32_t rxFrameId
 
uint32_t txFrameId
 

Detailed Description

Definition at line 87 of file isotp.h.

Constructor & Destructor Documentation

◆ IsoTpBase()

IsoTpBase::IsoTpBase ( ICanTransmitter p_txTransport,
size_t  p_busIndex,
uint32_t  p_rxFrameId,
uint32_t  p_txFrameId 
)
inline

Definition at line 89 of file isotp.h.

90 :
91 txTransport(p_txTransport),
92 busIndex(p_busIndex),
93 rxFrameId(p_rxFrameId),
94 txFrameId(p_txFrameId)
95 {}
size_t busIndex
Definition isotp.h:118
uint32_t txFrameId
Definition isotp.h:120
uint32_t rxFrameId
Definition isotp.h:119
ICanTransmitter * txTransport
Definition isotp.h:116

Member Function Documentation

◆ sendFlowControl()

void IsoTpBase::sendFlowControl ( can_sysinterval_t  timeout)

Definition at line 80 of file isotp.cpp.

80 {
81 IsoTpFrameHeader header;
83 header.fcFlag = 0; // = "continue to send"
84 header.blockSize = 0; // = the remaining "frames" to be sent without flow control or delay
85 header.separationTime = 0; // = wait 0 milliseconds, send immediately
86 sendFrame(header, nullptr, 0, timeout);
87}
int sendFrame(const IsoTpFrameHeader &header, const uint8_t *data, int num, can_sysinterval_t timeout)
Definition isotp.cpp:14
IsoTpFrameType frameType
Definition isotp.h:38
int separationTime
Definition isotp.h:47
@ ISO_TP_FRAME_FLOW_CONTROL
Definition isotp.h:33

Referenced by IsoTpRx::readTimeout(), and CanStreamerState::receiveFrame().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendFrame()

int IsoTpBase::sendFrame ( const IsoTpFrameHeader header,
const uint8_t *  data,
int  num,
can_sysinterval_t  timeout 
)

Definition at line 14 of file isotp.cpp.

14 {
15 // Calculate needed DLC and maximum payload
16 int offset, numBytes;
17 switch (header.frameType) {
20 numBytes = minI(num, maxDlc - offset);
21 break;
24 numBytes = minI(num, maxDlc - offset);
25 break;
28 numBytes = minI(num, maxDlc - offset);
29 break;
32 numBytes = 0; // no data is sent with 'flow control' frame
33 break;
34 default:
35 // bad frame type
36 return 0;
37 }
38
39 int dlc = offset + numBytes;
40 CanTxMessage txmsg(CanCategory::SERIAL, txFrameId, dlc, busIndex, IS_EXT_RANGE_ID(txFrameId));
41
42 // fill the frame data according to the CAN-TP protocol (ISO 15765-2)
43 txmsg[isoHeaderByteIndex] = (uint8_t)((header.frameType & 0xf) << 4);
44 switch (header.frameType) {
46 txmsg[isoHeaderByteIndex] |= numBytes;
47 break;
49 txmsg[isoHeaderByteIndex] |= (header.numBytes >> 8) & 0xf;
50 txmsg[isoHeaderByteIndex + 1] = (uint8_t)(header.numBytes & 0xff);
51 break;
53 txmsg[isoHeaderByteIndex] |= header.index & 0xf;
54 break;
56 txmsg[isoHeaderByteIndex] |= header.fcFlag & 0xf;
57 txmsg[isoHeaderByteIndex + 1] = (uint8_t)(header.blockSize);
58 txmsg[isoHeaderByteIndex + 2] = (uint8_t)(header.separationTime);
59 break;
60 default:
61 // bad frame type
62 return 0;
63 }
64
65 // copy the contents
66 if (data != nullptr) {
67 for (int i = 0; i < numBytes; i++) {
68 txmsg[i + offset] = data[i];
69 }
70 }
71
72 // send the frame!
73 if (transmit(txmsg, timeout) == CAN_MSG_OK) {
74 return numBytes;
75 }
76
77 return 0;
78}
can_msg_t transmit(CanTxMessage &ctfp, can_sysinterval_t timeout)
Definition isotp.h:101
size_t isoHeaderByteIndex
Definition isotp.h:114
static const size_t maxDlc
Definition isotp.cpp:12
@ ISO_TP_FRAME_CONSECUTIVE
Definition isotp.h:32
@ ISO_TP_FRAME_FIRST
Definition isotp.h:31
@ ISO_TP_FRAME_SINGLE
Definition isotp.h:30
uint16_t offset
Definition tunerstudio.h:0

Referenced by CanStreamerState::sendDataTimeout(), sendFlowControl(), and IsoTpRxTx::writeTimeout().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ transmit()

can_msg_t IsoTpBase::transmit ( CanTxMessage ctfp,
can_sysinterval_t  timeout 
)
inline

Definition at line 101 of file isotp.h.

101 {
102 if (isoHeaderByteIndex) {
103 // yes that would be truncated to byte, that's expected
104 ctfp[0] = rxFrameId & 0xff;
105 }
106 if (txTransport) {
107 return txTransport->transmit(ctfp, timeout);
108 }
109 return CAN_MSG_OK;
110 }
virtual can_msg_t transmit(CanTxMessage &ctfp, can_sysinterval_t timeout)=0

Referenced by sendFrame().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ busIndex

size_t IsoTpBase::busIndex

Definition at line 118 of file isotp.h.

Referenced by IsoTpRx::resetRxVerbose(), and sendFrame().

◆ isoHeaderByteIndex

size_t IsoTpBase::isoHeaderByteIndex = 0

◆ rxFrameId

uint32_t IsoTpBase::rxFrameId

Definition at line 119 of file isotp.h.

Referenced by transmit().

◆ txFrameId

uint32_t IsoTpBase::txFrameId

Definition at line 120 of file isotp.h.

Referenced by IsoTpRx::decodeFrame(), and sendFrame().

◆ txTransport

ICanTransmitter* IsoTpBase::txTransport

Definition at line 116 of file isotp.h.

Referenced by transmit().


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