9#if HAL_USE_CAN || EFI_UNIT_TEST
34 maxNumBytes = dlc -
offset;
48 int numBytes = minI(maxNumBytes, num);
50 if (data !=
nullptr) {
51 for (
int i = 0; i < numBytes; i++) {
52 txmsg[i +
offset] = data[i];
64 if (rxmsg ==
nullptr || rxmsg->
DLC < 1)
68 int numBytesAvailable, frameIdx;
69 uint8_t *srcBuf = rxmsg->
data8;
73 srcBuf = rxmsg->
data8 + 1;
125 int numBytesToCopy = minI(num, numBytesAvailable);
126 if (buf !=
nullptr) {
127 memcpy(buf, srcBuf, numBytesToCopy);
129 srcBuf += numBytesToCopy;
131 numBytesAvailable -= numBytesToCopy;
133 for (
int i = 0; i < numBytesAvailable; i++) {
147 return numBytesToCopy;
154 PRINT(
"*** INFO: sendDataTimeout %d" PRINT_EOL, numBytes);
165 return sendFrame(header, txbuf, numBytes, timeout);
177 int totalNumSent = numSent;
182 for (
size_t numFcReceived = 0; ; numFcReceived++) {
184#ifdef SERIAL_CAN_DEBUG
185 PRINT(
"*** ERROR: CAN Flow Control frame not received" PRINT_EOL);
199#ifdef SERIAL_CAN_DEBUG
200 efiPrintf(
"*** ERROR: CAN Flow Control mode not supported");
207 if (blockSize != 0 || minSeparationTime != 0) {
209#ifdef SERIAL_CAN_DEBUG
210 efiPrintf(
"*** ERROR: CAN Flow Control fields not supported");
220 while (numBytes > 0) {
221 int len = minI(numBytes, 7);
224 header.
index = ((idx++) & 0x0f);
229 totalNumSent += numSent;
239 int numReadFromFifo = minI(numBytes,
rxFifoBuf.getCount());
242 for (i = 0; !
rxFifoBuf.isEmpty() && i < numReadFromFifo; i++) {
254 PRINT(
"*** INFO: streamAddToTxTimeout adding %d, in buffer %d" PRINT_EOL, numBytes,
txFifoBuf.getCount());
264 PRINT(
"*** INFO: streamAddToTxTimeout numBytesToAdd %d / numSent %d / numBytes %d" PRINT_EOL, numBytesToAdd, numSent, numBytes);
271 numBytes -= numBytesToAdd;
275 PRINT(
"*** INFO: streamAddToTxTimeout remaining goes to buffer %d" PRINT_EOL, numBytes);
283 PRINT(
"*** INFO: in buffer %d" PRINT_EOL,
txFifoBuf.getCount());
300 size_t availableBufferSpace = *np;
306 while (availableBufferSpace > 0) {
309 int numReceived =
receiveFrame(&rxmsg, rxbuf + receivedSoFar, availableBufferSpace, timeout);
313 availableBufferSpace -= numReceived;
314 receivedSoFar += numReceived;
319 *np -= availableBufferSpace;
321#ifdef SERIAL_CAN_DEBUG
322 efiPrintf(
"* ret: %d %d (%d)", i, *np, availableBufferSpace);
323 for (
int j = 0; j < receivedSoFar; j++) {
324 efiPrintf(
"* [%d]: %02x", j, rxbuf[j]);
int32_t can_sysinterval_t
fifo_buffer< uint8_t, CAN_FIFO_BUF_SIZE > txFifoBuf
size_t isoHeaderByteIndex
fifo_buffer< uint8_t, CAN_FIFO_BUF_SIZE > rxFifoBuf
int receiveFrame(CANRxFrame *rxmsg, uint8_t *buf, int num, can_sysinterval_t timeout)
can_msg_t streamFlushTx(can_sysinterval_t timeout)
int sendDataTimeout(const uint8_t *txbuf, int numBytes, can_sysinterval_t timeout)
int sendFrame(const IsoTpFrameHeader &header, const uint8_t *data, int num, can_sysinterval_t timeout)
can_msg_t streamReceiveTimeout(size_t *np, uint8_t *rxbuf, can_sysinterval_t timeout)
ICanTransport * transport
int getDataFromFifo(uint8_t *rxbuf, size_t &numBytes)
can_msg_t streamAddToTxTimeout(size_t *np, const uint8_t *txbuf, can_sysinterval_t timeout)
virtual can_msg_t transmit(const CanTxMessage *ctfp, can_sysinterval_t timeout)=0
virtual can_msg_t receive(CANRxFrame *crfp, can_sysinterval_t timeout)=0
static EngineAccessor engine
static constexpr engine_configuration_s * engineConfiguration
@ ISO_TP_FRAME_CONSECUTIVE
@ ISO_TP_FRAME_FLOW_CONTROL
uint8_t data8[8]
Frame data.