PCAN sandbox - error requestOutputChannels fix #3698
This commit is contained in:
parent
1973b33e13
commit
d7e25028a0
|
@ -14,6 +14,14 @@
|
|||
#include "os_access.h"
|
||||
#include "crc.h"
|
||||
|
||||
#if EFI_UNIT_TEST
|
||||
#define PRINT printf
|
||||
#define PRINT_EOL "\n"
|
||||
#else
|
||||
#define PRINT efiPrintf
|
||||
#define PRINT_EOL ""
|
||||
#endif
|
||||
|
||||
// todo: this file is asking to improve conditional compilation. unit_tests and cypress/kinetis are both special cases
|
||||
#if HAL_USE_CAN || EFI_UNIT_TEST
|
||||
#include "serial_can.h"
|
||||
|
@ -165,7 +173,7 @@ int CanStreamerState::sendDataTimeout(const uint8_t *txbuf, int numBytes, can_sy
|
|||
int offset = 0;
|
||||
|
||||
#ifdef SERIAL_CAN_DEBUG
|
||||
efiPrintf("*** INFO: sendDataTimeout %d", numBytes);
|
||||
PRINT("*** INFO: sendDataTimeout %d" PRINT_EOL, numBytes);
|
||||
#endif /* SERIAL_CAN_DEBUG */
|
||||
|
||||
if (numBytes < 1)
|
||||
|
@ -196,7 +204,7 @@ int CanStreamerState::sendDataTimeout(const uint8_t *txbuf, int numBytes, can_sy
|
|||
for (int numFcReceived = 0; ; numFcReceived++) {
|
||||
if (streamer->receive(CAN_ANY_MAILBOX, &rxmsg, timeout) != CAN_MSG_OK) {
|
||||
#ifdef SERIAL_CAN_DEBUG
|
||||
efiPrintf("*** ERROR: CAN Flow Control frame not received");
|
||||
PRINT("*** ERROR: CAN Flow Control frame not received" PRINT_EOL);
|
||||
#endif /* SERIAL_CAN_DEBUG */
|
||||
//warning(CUSTOM_ERR_CAN_COMMUNICATION, "CAN Flow Control frame not received");
|
||||
return 0;
|
||||
|
@ -265,7 +273,7 @@ can_msg_t CanStreamerState::streamAddToTxTimeout(size_t *np, const uint8_t *txbu
|
|||
int offset = 0;
|
||||
|
||||
#ifdef SERIAL_CAN_DEBUG
|
||||
efiPrintf("*** INFO: streamAddToTxTimeout adding %d", numBytes);
|
||||
PRINT("*** INFO: streamAddToTxTimeout adding %d, in buffer %d" PRINT_EOL, numBytes, txFifoBuf.getCount());
|
||||
#endif /* SERIAL_CAN_DEBUG */
|
||||
|
||||
// we send here only if the TX FIFO buffer is getting overflowed
|
||||
|
@ -275,23 +283,28 @@ can_msg_t CanStreamerState::streamAddToTxTimeout(size_t *np, const uint8_t *txbu
|
|||
int numSent = sendDataTimeout((const uint8_t *)txFifoBuf.getElements(), txFifoBuf.getCount(), timeout);
|
||||
|
||||
#ifdef SERIAL_CAN_DEBUG
|
||||
efiPrintf("*** INFO: streamAddToTxTimeout numSent %d / numBytes", numSent, numBytes);
|
||||
PRINT("*** INFO: streamAddToTxTimeout numBytesToAdd %d / numSent %d / numBytes %d" PRINT_EOL, numBytesToAdd, numSent, numBytes);
|
||||
#endif /* SERIAL_CAN_DEBUG */
|
||||
|
||||
if (numSent < 1)
|
||||
break;
|
||||
txFifoBuf.clear();
|
||||
offset += numSent;
|
||||
numBytes -= numSent;
|
||||
offset += numBytesToAdd;
|
||||
numBytes -= numBytesToAdd;
|
||||
}
|
||||
|
||||
#ifdef SERIAL_CAN_DEBUG
|
||||
efiPrintf("*** INFO: streamAddToTxTimeout remaining goes to buffer %d", numBytes);
|
||||
PRINT("*** INFO: streamAddToTxTimeout remaining goes to buffer %d" PRINT_EOL, numBytes);
|
||||
#endif /* SERIAL_CAN_DEBUG */
|
||||
|
||||
// now we put the rest on hold
|
||||
txFifoBuf.put(txbuf + offset, numBytes);
|
||||
|
||||
|
||||
#ifdef SERIAL_CAN_DEBUG
|
||||
PRINT("*** INFO: in buffer %d" PRINT_EOL, txFifoBuf.getCount());
|
||||
#endif /* SERIAL_CAN_DEBUG */
|
||||
|
||||
return CAN_MSG_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,10 +38,10 @@ public:
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void checkFrame(const T & frame, const std::string & bytes) {
|
||||
void checkFrame(const T & frame, const std::string & bytes, int frameIndex) {
|
||||
EXPECT_EQ(bytes.size(), frame.DLC);
|
||||
for (size_t i = 0; i < bytes.size(); i++) {
|
||||
EXPECT_EQ(bytes[i], frame.data8[i]) << "Frame byte #" << i << " differs!";
|
||||
EXPECT_EQ(bytes[i], frame.data8[i]) << "Frame byte #" << i << " differs! Frame " << frameIndex;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,9 +78,10 @@ public:
|
|||
EXPECT_EQ(frames.size(), streamer.ctfList.size());
|
||||
|
||||
auto it1 = streamer.ctfList.begin();
|
||||
int frameIndex = 0;
|
||||
auto it2 = frames.begin();
|
||||
for (; it1 != streamer.ctfList.end() && it2 != frames.end(); it1++, it2++) {
|
||||
streamer.checkFrame(*it1, *it2);
|
||||
streamer.checkFrame(*it1, *it2, frameIndex++);
|
||||
}
|
||||
|
||||
// copy transmitted data back into the receive buffer
|
||||
|
@ -98,7 +99,7 @@ public:
|
|||
std::string totalReceivedData;
|
||||
for (size_t chunkSize : receiveChunks) {
|
||||
size_t nr = chunkSize;
|
||||
uint8_t rxbuf[256];
|
||||
uint8_t rxbuf[1256];
|
||||
streamReceiveTimeout(&nr, rxbuf, 0);
|
||||
EXPECT_EQ(nr, chunkSize);
|
||||
totalReceivedSize += nr;
|
||||
|
@ -179,3 +180,64 @@ TEST(testCanSerial, testLongMessage) {
|
|||
"\x23"s "uvwxyz\0"s }, 26, { 26 }); // 26 bytes -> 4 8-byte frames, 5 bytes left in FIFO
|
||||
}
|
||||
}
|
||||
|
||||
TEST(testCanSerial, test64_7Message) {
|
||||
std::array<char, 64 + 7> buffer;
|
||||
|
||||
std::fill(std::begin(buffer), std::end(buffer), 0);
|
||||
|
||||
buffer[0] = 1;
|
||||
|
||||
buffer[64 + 7 - 1] = 4;
|
||||
std::string str(std::begin(buffer),std::end(buffer));
|
||||
|
||||
TestCanStreamerState state;
|
||||
state.test({ str }, {
|
||||
/* 0 */
|
||||
"\x10"s "\x40"s "\x01\0\0\0\0\0"s,
|
||||
"\x21"s "\0\0\0\0\0\0\0"s,
|
||||
"\x22"s "\0\0\0\0\0\0\0"s,
|
||||
"\x23"s "\0\0\0\0\0\0\0"s,
|
||||
"\x24"s "\0\0\0\0\0\0\0"s,
|
||||
"\x25"s "\0\0\0\0\0\0\0"s,
|
||||
"\x26"s "\0\0\0\0\0\0\0"s,
|
||||
"\x27"s "\0\0\0\0\0\0\0"s,
|
||||
"\x28"s "\0\0\0\0\0\0\0"s,
|
||||
"\x29"s "\0\0\0\0\0\0\0"s,
|
||||
|
||||
/* 10 */
|
||||
"\x07"s "\0\0\0\0\0\0\4"s,
|
||||
|
||||
}, 7, { 64 + 7 });
|
||||
}
|
||||
|
||||
TEST(testCanSerial, test3_64_4Message) {
|
||||
std::array<char, 64> buffer64;
|
||||
|
||||
std::fill(std::begin(buffer64), std::end(buffer64), 0);
|
||||
|
||||
buffer64[0] = 1;
|
||||
|
||||
buffer64[64 - 1] = 4;
|
||||
std::string str(std::begin(buffer64),std::end(buffer64));
|
||||
|
||||
TestCanStreamerState state;
|
||||
state.test({ "123"s, str, "abcd"s }, {
|
||||
/* 0 */
|
||||
"\x10"s "\x40"s "123\1\0\0"s,
|
||||
"\x21"s "\0\0\0\0\0\0\0"s,
|
||||
"\x22"s "\0\0\0\0\0\0\0"s,
|
||||
"\x23"s "\0\0\0\0\0\0\0"s,
|
||||
"\x24"s "\0\0\0\0\0\0\0"s,
|
||||
"\x25"s "\0\0\0\0\0\0\0"s,
|
||||
"\x26"s "\0\0\0\0\0\0\0"s,
|
||||
"\x27"s "\0\0\0\0\0\0\0"s,
|
||||
"\x28"s "\0\0\0\0\0\0\0"s,
|
||||
"\x29"s "\0\0\0\0\0\0\0"s,
|
||||
|
||||
/* 10 */
|
||||
"\x07"s "\0\0\4abcd"s,
|
||||
|
||||
}, 7, { 64 + 7 });
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue