added basic unittests for hdlc encoder
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good
This commit is contained in:
@ -190,7 +190,7 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
|
||||
return rws::SPI_READ_FAILURE;
|
||||
}
|
||||
if (idx == 0) {
|
||||
if (byteRead != FLAG_BYTE) {
|
||||
if (byteRead != rws::FRAME_DELIMITER) {
|
||||
sif::error << "Invalid data, expected start marker" << std::endl;
|
||||
pullCsHigh(gpioId, gpioIF);
|
||||
closeSpi(fd);
|
||||
@ -198,7 +198,7 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
|
||||
}
|
||||
}
|
||||
|
||||
if (byteRead != FLAG_BYTE) {
|
||||
if (byteRead != rws::FRAME_DELIMITER) {
|
||||
break;
|
||||
}
|
||||
|
||||
@ -228,7 +228,7 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
|
||||
}
|
||||
}
|
||||
|
||||
if (byteRead == FLAG_BYTE) {
|
||||
if (byteRead == rws::FRAME_DELIMITER) {
|
||||
// Reached end of frame
|
||||
break;
|
||||
} else if (byteRead == 0x7D) {
|
||||
@ -268,9 +268,9 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
|
||||
result = rws::SPI_READ_FAILURE;
|
||||
break;
|
||||
}
|
||||
if (byteRead != FLAG_BYTE) {
|
||||
sif::error << "rwSpiCallback::spiCallback: Missing end sign " << static_cast<int>(FLAG_BYTE)
|
||||
<< std::endl;
|
||||
if (byteRead != rws::FRAME_DELIMITER) {
|
||||
sif::error << "rwSpiCallback::spiCallback: Missing end sign "
|
||||
<< static_cast<int>(rws::FRAME_DELIMITER) << std::endl;
|
||||
decodedFrameLen--;
|
||||
result = rws::MISSING_END_SIGN;
|
||||
break;
|
||||
@ -353,23 +353,6 @@ size_t RwPollingTask::idAndIdxToReadBuffer(DeviceCommandId_t id, uint8_t rwIdx,
|
||||
}
|
||||
}
|
||||
|
||||
void RwPollingTask::encodeHdlc(const uint8_t* sourceBuf, size_t sourceLen, size_t& encodedLen) {
|
||||
encodedBuffer[0] = FLAG_BYTE;
|
||||
encodedLen = 1;
|
||||
for (size_t sourceIdx = 0; sourceIdx < sourceLen; sourceIdx++) {
|
||||
if (sourceBuf[sourceIdx] == 0x7E) {
|
||||
encodedBuffer[encodedLen++] = 0x7D;
|
||||
encodedBuffer[encodedLen++] = 0x5E;
|
||||
} else if (sourceBuf[sourceIdx] == 0x7D) {
|
||||
encodedBuffer[encodedLen++] = 0x7D;
|
||||
encodedBuffer[encodedLen++] = 0x5D;
|
||||
} else {
|
||||
encodedBuffer[encodedLen++] = sourceBuf[sourceIdx];
|
||||
}
|
||||
}
|
||||
encodedBuffer[encodedLen++] = FLAG_BYTE;
|
||||
}
|
||||
|
||||
// This closes the SPI
|
||||
void RwPollingTask::closeSpi(int fd) {
|
||||
// This will perform the function to close the SPI
|
||||
@ -385,31 +368,9 @@ ReturnValue_t RwPollingTask::sendOneMessage(int fd, RwCookie& rwCookie) {
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
pullCsLow(gpioId, spiLock, gpioIF);
|
||||
/*
|
||||
//Encoding and sending command
|
||||
size_t idx = 0;
|
||||
while (idx < dataLen) {
|
||||
switch (*(data + idx)) {
|
||||
case 0x7E:
|
||||
writeBuffer[0] = 0x7D;
|
||||
writeBuffer[1] = 0x5E;
|
||||
writeSize = 2;
|
||||
break;
|
||||
case 0x7D:
|
||||
writeBuffer[0] = 0x7D;
|
||||
writeBuffer[1] = 0x5D;
|
||||
writeSize = 2;
|
||||
break;
|
||||
default:
|
||||
writeBuffer[0] = *(data + idx);
|
||||
writeSize = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
*/
|
||||
// Add datalinklayer like specified in the datasheet.
|
||||
size_t lenToSend = 0;
|
||||
encodeHdlc(writeBuffer.data(), writeLen, lenToSend);
|
||||
rws::encodeHdlc(writeBuffer.data(), writeLen, encodedBuffer.data(), lenToSend);
|
||||
if (write(fd, encodedBuffer.data(), lenToSend) != static_cast<ssize_t>(lenToSend)) {
|
||||
sif::error << "rwSpiCallback::spiCallback: Write failed!" << std::endl;
|
||||
pullCsHigh(gpioId, gpioIF);
|
||||
|
@ -48,8 +48,6 @@ class RwPollingTask : public SystemObject, public ExecutableObjectIF, public Dev
|
||||
std::array<uint8_t, rws::MAX_CMD_SIZE * 2> encodedBuffer;
|
||||
|
||||
size_t writeLen = 0;
|
||||
//! This is the end and start marker of the frame datalinklayer
|
||||
static constexpr uint8_t FLAG_BYTE = 0x7E;
|
||||
static constexpr MutexIF::TimeoutType TIMEOUT_TYPE = MutexIF::TimeoutType::WAITING;
|
||||
static constexpr uint32_t TIMEOUT_MS = 20;
|
||||
static constexpr uint8_t MAX_RETRIES_REPLY = 5;
|
||||
@ -75,7 +73,6 @@ class RwPollingTask : public SystemObject, public ExecutableObjectIF, public Dev
|
||||
ReturnValue_t prepareSetSpeedCmd(uint8_t rwIdx);
|
||||
|
||||
size_t idAndIdxToReadBuffer(DeviceCommandId_t id, uint8_t rwIdx, uint8_t** readPtr);
|
||||
void encodeHdlc(const uint8_t* sourceBuf, size_t sourceLen, size_t& encodedLen);
|
||||
|
||||
void pullCsHigh(gpioId_t gpioId, GpioIF& gpioIF);
|
||||
void closeSpi(int);
|
||||
|
Reference in New Issue
Block a user