rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions
IsoTpRxTx Class Reference

#include <isotp.h>

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

Public Member Functions

 IsoTpRxTx (size_t p_busIndex, uint32_t p_rxFrameId, uint32_t p_txFrameId)
 
int writeTimeout (const uint8_t *txbuf, size_t size, sysinterval_t timeout)
 
- Public Member Functions inherited from IsoTpRx
 IsoTpRx (size_t p_busIndex, uint32_t p_rxFrameId, uint32_t p_txFrameId)
 
 ~IsoTpRx ()
 
void reset ()
 
virtual void decodeFrame (const CANRxFrame &frame, efitick_t nowNt)
 
int readTimeout (uint8_t *rxbuf, size_t *size, sysinterval_t timeout)
 
- Public Member Functions inherited from CanListener
 CanListener (uint32_t id)
 
CanListenerprocessFrame (const size_t busIndex, const CANRxFrame &frame, efitick_t nowNt)
 
uint32_t getId ()
 
void setNext (CanListener *next)
 
virtual CanListenerrequest ()
 
CanListenergetNext () const
 
virtual bool acceptFrame (const size_t busIndex, const CANRxFrame &frame) const
 
- Public Member Functions inherited from IsoTpBase
 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)
 

Additional Inherited Members

- Data Fields inherited from IsoTpBase
size_t isoHeaderByteIndex = 0
 
ICanTransmittertxTransport
 
size_t busIndex
 
uint32_t rxFrameId
 
uint32_t txFrameId
 
- Protected Attributes inherited from IsoTpRx
fifo_buffer_sync< CANRxFrame, ISOTP_RX_QUEUE_LEN > rxFifoBuf
 

Detailed Description

Definition at line 228 of file isotp.h.

Constructor & Destructor Documentation

◆ IsoTpRxTx()

IsoTpRxTx::IsoTpRxTx ( size_t  p_busIndex,
uint32_t  p_rxFrameId,
uint32_t  p_txFrameId 
)
inline

Definition at line 230 of file isotp.h.

231 :
232 IsoTpRx(p_busIndex, p_rxFrameId, p_txFrameId)
233 {}

Member Function Documentation

◆ writeTimeout()

int IsoTpRxTx::writeTimeout ( const uint8_t *  txbuf,
size_t  size,
sysinterval_t  timeout 
)

Definition at line 455 of file isotp.cpp.

455 {
456 int offset = 0;
457
458 if (engineConfiguration->verboseIsoTp) {
459 PRINT("*** INFO: sendDataTimeout %d" PRINT_EOL, size);
460 }
461
462 if (size < 1)
463 return 0;
464
465 // 1 frame
466 if (size <= 7 - isoHeaderByteIndex) {
467 IsoTpFrameHeader header;
469 header.numBytes = size;
470 return IsoTpBase::sendFrame(header, txbuf, size, timeout);
471 }
472
473 // multiple frames
474
475 // send the first header frame (FF)
476 IsoTpFrameHeader header;
478 header.numBytes = size;
479 int numSent = IsoTpBase::sendFrame(header, txbuf + offset, size, timeout);
480 offset += numSent;
481 size -= numSent;
482
483 // get a flow control (FC) frame
484#if !EFI_UNIT_TEST // todo: add FC to unit-tests?
485 CANRxFrame rxmsg;
486 size_t numFcReceived = 0;
487 while (numFcReceived < 3) {
488 // TODO: adjust timeout!
489 if (!rxFifoBuf.get(rxmsg, timeout)) {
490 efiPrintf("IsoTp: Flow Control frame not received");
491 //warning(ObdCode::CUSTOM_ERR_CAN_COMMUNICATION, "CAN Flow Control frame not received");
492 return 0;
493 }
494 uint8_t frameType = (rxmsg.data8[isoHeaderByteIndex] >> 4) & 0xf;
495
496 // if something is not ok
497 if (frameType != ISO_TP_FRAME_FLOW_CONTROL) {
498 // should we expect only FC here?
499 continue;
500 }
501
502 // Ok, frame is FC
503 numFcReceived++;
504 uint8_t flowStatus = rxmsg.data8[isoHeaderByteIndex] & 0xf;
505
506 if (flowStatus == CAN_FLOW_STATUS_ABORT) {
507 efiPrintf("IsoTp: Flow Control ABORT");
508 // TODO: error codes
509 return -4;
510 }
511
512 if (flowStatus == CAN_FLOW_STATUS_WAIT_MORE) {
513 // if the receiver is not ready yet and asks to wait for the next FC frame (give it 3 attempts)
514 if (numFcReceived < 3) {
515 continue;
516 }
517 // TODO: error codes
518 return -5;
519 }
520
521 if (flowStatus != CAN_FLOW_STATUS_OK) {
522 efiPrintf("IsoTp: Flow Control unknown Status %d", flowStatus);
523 // TODO: error codes
524 return -6;
525 }
526
527 uint8_t blockSize = rxmsg.data8[isoHeaderByteIndex + 1];
528 uint8_t minSeparationTime = rxmsg.data8[isoHeaderByteIndex + 2];
529 if (blockSize != 0 || minSeparationTime != 0) {
530 // todo: process other Flow Control fields (see ISO 15765-2)
531 efiPrintf("IsoTp: Flow Control fields not supported");
532 // TODO: error codes
533 return -7;
534 }
535
536 break;
537 }
538#endif /* EFI_UNIT_TEST */
539
540 // send the rest of the data
541 uint8_t idx = 1;
542 while (size > 0) {
543 int len = minI(size, 7 - isoHeaderByteIndex);
544 // send the consecutive frames
546 header.index = ((idx++) & 0x0f);
547 header.numBytes = len;
548 numSent = IsoTpBase::sendFrame(header, txbuf + offset, len, timeout);
549 if (numSent < 1)
550 break;
551 offset += numSent;
552 size -= numSent;
553 }
554 return offset;
555}
int sendFrame(const IsoTpFrameHeader &header, const uint8_t *data, int num, can_sysinterval_t timeout)
Definition isotp.cpp:12
size_t isoHeaderByteIndex
Definition isotp.h:112
IsoTpFrameType frameType
Definition isotp.h:38
fifo_buffer_sync< CANRxFrame, ISOTP_RX_QUEUE_LEN > rxFifoBuf
Definition isotp.h:225
static constexpr engine_configuration_s * engineConfiguration
@ 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
uint8_t data8[8]
Frame data.
Definition can_mocks.h:55
composite packet size
uint16_t offset
Definition tunerstudio.h:0
Here is the call graph for this function:

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