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 (
int numFcReceived = 0; ; numFcReceived++) {
184#ifdef SERIAL_CAN_DEBUG
185 PRINT(
"*** ERROR: CAN Flow Control frame not received" PRINT_EOL);
191 int flowStatus = rxmsg.
data8[0] & 0xf;
193 if (flowStatus != CAN_FLOW_STATUS_OK) {
195 if (flowStatus == CAN_FLOW_STATUS_WAIT_MORE && numFcReceived < 3) {
198#ifdef SERIAL_CAN_DEBUG
199 efiPrintf(
"*** ERROR: CAN Flow Control mode not supported");
204 int blockSize = rxmsg.
data8[1];
205 int minSeparationTime = rxmsg.
data8[2];
206 if (blockSize != 0 || minSeparationTime != 0) {
208#ifdef SERIAL_CAN_DEBUG
209 efiPrintf(
"*** ERROR: CAN Flow Control fields not supported");
219 while (numBytes > 0) {
220 int len = minI(numBytes, 7);
223 header.
index = ((idx++) & 0x0f);
228 totalNumSent += numSent;
238 int numReadFromFifo = minI(numBytes,
rxFifoBuf.getCount());
241 for (i = 0; !
rxFifoBuf.isEmpty() && i < numReadFromFifo; i++) {
253 PRINT(
"*** INFO: streamAddToTxTimeout adding %d, in buffer %d" PRINT_EOL, numBytes,
txFifoBuf.getCount());
263 PRINT(
"*** INFO: streamAddToTxTimeout numBytesToAdd %d / numSent %d / numBytes %d" PRINT_EOL, numBytesToAdd, numSent, numBytes);
270 numBytes -= numBytesToAdd;
274 PRINT(
"*** INFO: streamAddToTxTimeout remaining goes to buffer %d" PRINT_EOL, numBytes);
282 PRINT(
"*** INFO: in buffer %d" PRINT_EOL,
txFifoBuf.getCount());
299 size_t availableBufferSpace = *np;
305 while (availableBufferSpace > 0) {
308 int numReceived =
receiveFrame(&rxmsg, rxbuf + receivedSoFar, availableBufferSpace, timeout);
312 availableBufferSpace -= numReceived;
313 receivedSoFar += numReceived;
318 *np -= availableBufferSpace;
320#ifdef SERIAL_CAN_DEBUG
321 efiPrintf(
"* ret: %d %d (%d)", i, *np, availableBufferSpace);
322 for (
int j = 0; j < receivedSoFar; j++) {
323 efiPrintf(
"* [%d]: %02x", j, rxbuf[j]);
int32_t can_sysinterval_t
fifo_buffer< uint8_t, CAN_FIFO_BUF_SIZE > txFifoBuf
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.