diff --git a/linux/devices/RwPollingTask.cpp b/linux/devices/RwPollingTask.cpp index b300136a..c8744301 100644 --- a/linux/devices/RwPollingTask.cpp +++ b/linux/devices/RwPollingTask.cpp @@ -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(FLAG_BYTE) - << std::endl; + if (byteRead != rws::FRAME_DELIMITER) { + sif::error << "rwSpiCallback::spiCallback: Missing end sign " + << static_cast(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(lenToSend)) { sif::error << "rwSpiCallback::spiCallback: Write failed!" << std::endl; pullCsHigh(gpioId, gpioIF); diff --git a/linux/devices/RwPollingTask.h b/linux/devices/RwPollingTask.h index 701771f1..b9895865 100644 --- a/linux/devices/RwPollingTask.h +++ b/linux/devices/RwPollingTask.h @@ -48,8 +48,6 @@ class RwPollingTask : public SystemObject, public ExecutableObjectIF, public Dev std::array 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); diff --git a/misc/eclipse/.cproject b/misc/eclipse/.cproject index 0dfd812a..0f3348a8 100644 --- a/misc/eclipse/.cproject +++ b/misc/eclipse/.cproject @@ -57,7 +57,8 @@ - + + @@ -119,7 +120,8 @@ - + + @@ -187,7 +189,8 @@ - + + @@ -255,7 +258,8 @@ - + + @@ -418,7 +422,8 @@ - + + @@ -580,7 +585,8 @@ - + + @@ -680,7 +686,7 @@