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
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 int separationTimeUs = 0;
488 while (numFcReceived < 3) {
489 // TODO: adjust timeout!
490 if (!rxFifoBuf.get(rxmsg, timeout)) {
491 efiPrintf("IsoTp: Flow Control frame not received");
492 //warning(ObdCode::CUSTOM_ERR_CAN_COMMUNICATION, "CAN Flow Control frame not received");
493 return 0;
494 }
495 uint8_t frameType = (rxmsg.data8[isoHeaderByteIndex] >> 4) & 0xf;
496
497 // if something is not ok
498 if (frameType != ISO_TP_FRAME_FLOW_CONTROL) {
499 // should we expect only FC here?
500 continue;
501 }
502
503 // Ok, frame is FC
504 numFcReceived++;
505 uint8_t flowStatus = rxmsg.data8[isoHeaderByteIndex] & 0xf;
506
507 if (flowStatus == CAN_FLOW_STATUS_ABORT) {
508 efiPrintf("IsoTp: Flow Control ABORT");
509 // TODO: error codes
510 return -4;
511 }
512
513 if (flowStatus == CAN_FLOW_STATUS_WAIT_MORE) {
514 // if the receiver is not ready yet and asks to wait for the next FC frame (give it 3 attempts)
515 if (numFcReceived < 3) {
516 continue;
517 }
518 // TODO: error codes
519 return -5;
520 }
521
522 if (flowStatus != CAN_FLOW_STATUS_OK) {
523 efiPrintf("IsoTp: Flow Control unknown Status %d", flowStatus);
524 // TODO: error codes
525 return -6;
526 }
527
528 uint8_t blockSize = rxmsg.data8[isoHeaderByteIndex + 1];
529 uint8_t minSeparationTime = rxmsg.data8[isoHeaderByteIndex + 2];
530 if (blockSize != 0) {
531 // todo: process other Flow Control fields (see ISO 15765-2)
532 efiPrintf("IsoTp: Flow Control blockSize is not supported %d", blockSize);
533 // TODO: error codes
534 return -7;
535 }
536
537 if (minSeparationTime <= 0x7f) {
538 // mS units
539 separationTimeUs = minSeparationTime * 1000;
540 } else if ((minSeparationTime >= 0xf1) && (minSeparationTime <= 0xf9)) {
541 // 100 uS units
542 separationTimeUs = (minSeparationTime - 0xf0) * 100;
543 }
544
545 break;
546 }
547#endif /* EFI_UNIT_TEST */
548
549 // send the rest of the data
550 uint8_t idx = 1;
551 while (size > 0) {
552 int len = minI(size, 7 - isoHeaderByteIndex);
553 // send the consecutive frames
555 header.index = ((idx++) & 0x0f);
556 header.numBytes = len;
557 numSent = IsoTpBase::sendFrame(header, txbuf + offset, len, timeout);
558 if (numSent < 1)
559 break;
560 offset += numSent;
561 size -= numSent;
562
563#if ! EFI_UNIT_TEST
564 if (separationTimeUs) {
565 chThdSleepMicroseconds(separationTimeUs);
566 }
567#endif // EFI_UNIT_TEST
568 }
569 return offset;
570}
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: