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 ()
 
bool isRxEmpty ()
 
virtual void decodeFrame (const CANRxFrame &frame, efitick_t nowNt)
 
int readTimeout (uint8_t *rxbuf, size_t *size, sysinterval_t timeout)
 
void resetRxVerbose ()
 
- 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)
 
void sendFlowControl (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 238 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 240 of file isotp.h.

241 :
242 IsoTpRx(p_busIndex, p_rxFrameId, p_txFrameId)
243 {}

Member Function Documentation

◆ writeTimeout()

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

Definition at line 492 of file isotp.cpp.

492 {
493 int offset = 0;
494
496 PRINT("*** INFO: sendDataTimeout %d" PRINT_EOL, size);
497 }
498
499 if (size < 1)
500 return 0;
501
502 // 1 frame
503 if (size <= 7 - isoHeaderByteIndex) {
504 IsoTpFrameHeader header;
506 header.numBytes = size;
507 return IsoTpBase::sendFrame(header, txbuf, size, timeout);
508 }
509
510 // multiple frames
511
512 // send the first header frame (FF)
513 IsoTpFrameHeader header;
515 header.numBytes = size;
516 int numSent = IsoTpBase::sendFrame(header, txbuf + offset, size, timeout);
517 offset += numSent;
518 size -= numSent;
519
520 // get a flow control (FC) frame
521#if !EFI_UNIT_TEST // todo: add FC to unit-tests?
522 CANRxFrame rxmsg;
523 size_t numFcReceived = 0;
524 int separationTimeUs = 0;
525 while (numFcReceived < 3) {
526 // TODO: adjust timeout!
527 if (!rxFifoBuf.get(rxmsg, timeout)) {
528 efiPrintf("IsoTp: Flow Control frame not received");
529 //warning(ObdCode::CUSTOM_ERR_CAN_COMMUNICATION, "CAN Flow Control frame not received");
530 return 0;
531 }
532 uint8_t frameType = (rxmsg.data8[isoHeaderByteIndex] >> 4) & 0xf;
533
534 // if something is not ok
535 if (frameType != ISO_TP_FRAME_FLOW_CONTROL) {
536 // should we expect only FC here?
537 continue;
538 }
539
540 // Ok, frame is FC
541 numFcReceived++;
542 uint8_t flowStatus = rxmsg.data8[isoHeaderByteIndex] & 0xf;
543
544 if (flowStatus == CAN_FLOW_STATUS_ABORT) {
545 efiPrintf("IsoTp: Flow Control ABORT");
546 // TODO: error codes
547 return -4;
548 }
549
550 if (flowStatus == CAN_FLOW_STATUS_WAIT_MORE) {
551 // if the receiver is not ready yet and asks to wait for the next FC frame (give it 3 attempts)
552 if (numFcReceived < 3) {
553 continue;
554 }
555 // TODO: error codes
556 return -5;
557 }
558
559 if (flowStatus != CAN_FLOW_STATUS_OK) {
560 efiPrintf("IsoTp: Flow Control unknown Status %d", flowStatus);
561 // TODO: error codes
562 return -6;
563 }
564
565 uint8_t blockSize = rxmsg.data8[isoHeaderByteIndex + 1];
566 uint8_t minSeparationTime = rxmsg.data8[isoHeaderByteIndex + 2];
567 if (blockSize != 0) {
568 // todo: process other Flow Control fields (see ISO 15765-2)
569 efiPrintf("IsoTp: Flow Control blockSize is not supported %d", blockSize);
570 // TODO: error codes
571 return -7;
572 }
573
574 if (minSeparationTime <= 0x7f) {
575 // mS units
576 separationTimeUs = minSeparationTime * 1000;
577 } else if ((minSeparationTime >= 0xf1) && (minSeparationTime <= 0xf9)) {
578 // 100 uS units
579 separationTimeUs = (minSeparationTime - 0xf0) * 100;
580 }
581
582 break;
583 }
584#endif /* EFI_UNIT_TEST */
585
586 // send the rest of the data
587 uint8_t idx = 1;
588 while (size > 0) {
589 int len = minI(size, 7 - isoHeaderByteIndex);
590 // send the consecutive frames
592 header.index = ((idx++) & 0x0f);
593 header.numBytes = len;
594 numSent = IsoTpBase::sendFrame(header, txbuf + offset, len, timeout);
595 if (numSent < 1)
596 break;
597 offset += numSent;
598 size -= numSent;
599
600#if ! EFI_UNIT_TEST
601 if (separationTimeUs) {
602 chThdSleepMicroseconds(separationTimeUs);
603 }
604#endif // EFI_UNIT_TEST
605 }
606 return offset;
607}
int sendFrame(const IsoTpFrameHeader &header, const uint8_t *data, int num, can_sysinterval_t timeout)
Definition isotp.cpp:14
size_t isoHeaderByteIndex
Definition isotp.h:114
IsoTpFrameType frameType
Definition isotp.h:38
fifo_buffer_sync< CANRxFrame, ISOTP_RX_QUEUE_LEN > rxFifoBuf
Definition isotp.h:235
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: