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)
 
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:116
uint32_t txFrameId
Definition isotp.h:118
uint32_t rxFrameId
Definition isotp.h:117
ICanTransmitter * txTransport
Definition isotp.h:114

Member Function Documentation

◆ sendFrame()

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

https://en.wikipedia.org/wiki/ISO_15765-2

Definition at line 12 of file isotp.cpp.

12 {
13 int dlc = 8; // standard 8 bytes
14 CanTxMessage txmsg(CanCategory::SERIAL, txFrameId, dlc, busIndex, IS_EXT_RANGE_ID(txFrameId));
15
16 // fill the frame data according to the CAN-TP protocol (ISO 15765-2)
17 txmsg[isoHeaderByteIndex] = (uint8_t)((header.frameType & 0xf) << 4);
18 int offset, maxNumBytes;
19 switch (header.frameType) {
22 maxNumBytes = minI(header.numBytes, dlc - offset);
23 txmsg[isoHeaderByteIndex] |= maxNumBytes;
24 break;
26 txmsg[isoHeaderByteIndex] |= (header.numBytes >> 8) & 0xf;
27 txmsg[isoHeaderByteIndex + 1] = (uint8_t)(header.numBytes & 0xff);
29 maxNumBytes = minI(header.numBytes, dlc - offset);
30 break;
32 txmsg[isoHeaderByteIndex] |= header.index & 0xf;
34 // todo: is it correct?
35 maxNumBytes = dlc - offset;
36 break;
38 txmsg[isoHeaderByteIndex] |= header.fcFlag & 0xf;
39 txmsg[isoHeaderByteIndex + 1] = (uint8_t)(header.blockSize);
40 txmsg[isoHeaderByteIndex + 2] = (uint8_t)(header.separationTime);
42 maxNumBytes = 0; // no data is sent with 'flow control' frame
43 break;
44 default:
45 // bad frame type
46 return 0;
47 }
48
49 int numBytes = minI(maxNumBytes, num);
50 // copy the contents
51 if (data != nullptr) {
52 for (int i = 0; i < numBytes; i++) {
53 txmsg[i + offset] = data[i];
54 }
55 }
56
57 // send the frame!
58 if (transmit(txmsg, timeout) == CAN_MSG_OK)
59 return numBytes;
60 return 0;
61}
can_msg_t transmit(CanTxMessage &ctfp, can_sysinterval_t timeout)
Definition isotp.h:99
size_t isoHeaderByteIndex
Definition isotp.h:112
IsoTpFrameType frameType
Definition isotp.h:38
int separationTime
Definition isotp.h:47
@ ISO_TP_FRAME_CONSECUTIVE
Definition isotp.h:32
@ ISO_TP_FRAME_FIRST
Definition isotp.h:31
@ ISO_TP_FRAME_FLOW_CONTROL
Definition isotp.h:33
@ ISO_TP_FRAME_SINGLE
Definition isotp.h:30
uint16_t offset
Definition tunerstudio.h:0

Referenced by IsoTpRx::readTimeout(), CanStreamerState::receiveFrame(), CanStreamerState::sendDataTimeout(), 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 99 of file isotp.h.

99 {
100 if (isoHeaderByteIndex) {
101 // yes that would be truncated to byte, that's expected
102 ctfp[0] = rxFrameId & 0xff;
103 }
104 if (txTransport) {
105 return txTransport->transmit(ctfp, timeout);
106 }
107 return CAN_MSG_OK;
108 }
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 116 of file isotp.h.

Referenced by sendFrame().

◆ isoHeaderByteIndex

size_t IsoTpBase::isoHeaderByteIndex = 0

◆ rxFrameId

uint32_t IsoTpBase::rxFrameId

Definition at line 117 of file isotp.h.

Referenced by transmit().

◆ txFrameId

uint32_t IsoTpBase::txFrameId

Definition at line 118 of file isotp.h.

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

◆ txTransport

ICanTransmitter* IsoTpBase::txTransport

Definition at line 114 of file isotp.h.

Referenced by transmit().


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