some more bugfixes
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit

This commit is contained in:
Robin Müller 2023-02-15 19:27:19 +01:00
parent 8c001b6443
commit 655e01c2d1
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
2 changed files with 70 additions and 68 deletions

View File

@ -172,6 +172,7 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
gpioId_t gpioId = rwCookie.getChipSelectPin(); gpioId_t gpioId = rwCookie.getChipSelectPin();
GpioIF& gpioIF = spiIF->getGpioInterface(); GpioIF& gpioIF = spiIF->getGpioInterface();
pullCsLow(gpioId, spiLock, gpioIF); pullCsLow(gpioId, spiLock, gpioIF);
uint8_t byteRead = 0;
for (unsigned idx = 0; idx < MAX_RETRIES_REPLY; idx++) { for (unsigned idx = 0; idx < MAX_RETRIES_REPLY; idx++) {
result = openSpi(O_RDWR, fd); result = openSpi(O_RDWR, fd);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
@ -181,18 +182,17 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
* The reaction wheel responds with empty frames while preparing the reply data. * The reaction wheel responds with empty frames while preparing the reply data.
* However, receiving more than 5 empty frames will be interpreted as an error. * However, receiving more than 5 empty frames will be interpreted as an error.
*/ */
uint8_t byteRead = 0;
for (int idx = 0; idx < 5; idx++) { for (int idx = 0; idx < 5; idx++) {
if (read(fd, &byteRead, 1) != 1) { if (read(fd, &byteRead, 1) != 1) {
sif::error << "rwSpiCallback::spiCallback: Read failed" << std::endl; sif::error << "rwSpiCallback::spiCallback: Read failed" << std::endl;
pullCsHigh(gpioId, spiLock, gpioIF); pullCsHigh(gpioId, gpioIF);
closeSpi(fd); closeSpi(fd);
return rws::SPI_READ_FAILURE; return rws::SPI_READ_FAILURE;
} }
if (idx == 0) { if (idx == 0) {
if (byteRead != FLAG_BYTE) { if (byteRead != FLAG_BYTE) {
sif::error << "Invalid data, expected start marker" << std::endl; sif::error << "Invalid data, expected start marker" << std::endl;
pullCsHigh(gpioId, spiLock, gpioIF); pullCsHigh(gpioId, gpioIF);
closeSpi(fd); closeSpi(fd);
return rws::NO_START_MARKER; return rws::NO_START_MARKER;
} }
@ -202,7 +202,7 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
break; break;
} }
pullCsHigh(gpioId, spiLock, gpioIF); pullCsHigh(gpioId, gpioIF);
closeSpi(fd); closeSpi(fd);
if (idx == MAX_RETRIES_REPLY - 1) { if (idx == MAX_RETRIES_REPLY - 1) {
sif::error << "rwSpiCallback::spiCallback: Empty frame timeout" << std::endl; sif::error << "rwSpiCallback::spiCallback: Empty frame timeout" << std::endl;
@ -210,7 +210,7 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
} }
TaskFactory::delayTask(5); TaskFactory::delayTask(5);
} }
}
#if FSFW_HAL_SPI_WIRETAPPING == 1 #if FSFW_HAL_SPI_WIRETAPPING == 1
sif::info << "RW start marker detected" << std::endl; sif::info << "RW start marker detected" << std::endl;
#endif #endif
@ -218,7 +218,7 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
size_t decodedFrameLen = 0; size_t decodedFrameLen = 0;
while (decodedFrameLen < maxReplyLen) { while (decodedFrameLen < maxReplyLen) {
/** First byte already read in */ // First byte already read in
if (decodedFrameLen != 0) { if (decodedFrameLen != 0) {
byteRead = 0; byteRead = 0;
if (read(fd, &byteRead, 1) != 1) { if (read(fd, &byteRead, 1) != 1) {
@ -229,7 +229,7 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
} }
if (byteRead == FLAG_BYTE) { if (byteRead == FLAG_BYTE) {
/** Reached end of frame */ // Reached end of frame
break; break;
} else if (byteRead == 0x7D) { } else if (byteRead == 0x7D) {
if (read(fd, &byteRead, 1) != 1) { if (read(fd, &byteRead, 1) != 1) {
@ -247,7 +247,6 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
continue; continue;
} else { } else {
sif::error << "rwSpiCallback::spiCallback: Invalid substitute" << std::endl; sif::error << "rwSpiCallback::spiCallback: Invalid substitute" << std::endl;
closeSpi(fd);
result = rws::INVALID_SUBSTITUTE; result = rws::INVALID_SUBSTITUTE;
break; break;
} }
@ -257,9 +256,10 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
continue; continue;
} }
// Check end marker.
/** /**
* There might be the unlikely case that each byte in a get-telemetry reply has been * There might be the unlikely case that each byte in a get-telemetry reply has been
* replaced by its substitute. Than the next byte must correspond to the end sign 0x7E. * replaced by its substitute. Then the next byte must correspond to the end sign 0x7E.
* Otherwise there might be something wrong. * Otherwise there might be something wrong.
*/ */
if (decodedFrameLen == maxReplyLen) { if (decodedFrameLen == maxReplyLen) {
@ -269,8 +269,8 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
break; break;
} }
if (byteRead != FLAG_BYTE) { if (byteRead != FLAG_BYTE) {
sif::error << "rwSpiCallback::spiCallback: Missing end sign " sif::error << "rwSpiCallback::spiCallback: Missing end sign " << static_cast<int>(FLAG_BYTE)
<< static_cast<int>(FLAG_BYTE) << std::endl; << std::endl;
decodedFrameLen--; decodedFrameLen--;
result = rws::MISSING_END_SIGN; result = rws::MISSING_END_SIGN;
break; break;
@ -278,8 +278,10 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
} }
result = returnvalue::OK; result = returnvalue::OK;
} }
}
return returnvalue::OK; pullCsHigh(gpioId, gpioIF);
closeSpi(fd);
return result;
} }
ReturnValue_t RwPollingTask::writeOneRwCmd(uint8_t rwIdx, int fd) { ReturnValue_t RwPollingTask::writeOneRwCmd(uint8_t rwIdx, int fd) {
@ -410,10 +412,10 @@ ReturnValue_t RwPollingTask::sendOneMessage(int fd, RwCookie& rwCookie) {
encodeHdlc(writeBuffer.data(), writeLen, lenToSend); encodeHdlc(writeBuffer.data(), writeLen, lenToSend);
if (write(fd, encodedBuffer.data(), lenToSend) != static_cast<ssize_t>(lenToSend)) { if (write(fd, encodedBuffer.data(), lenToSend) != static_cast<ssize_t>(lenToSend)) {
sif::error << "rwSpiCallback::spiCallback: Write failed!" << std::endl; sif::error << "rwSpiCallback::spiCallback: Write failed!" << std::endl;
pullCsHigh(gpioId, spiLock, gpioIF); pullCsHigh(gpioId, gpioIF);
return rws::SPI_WRITE_FAILURE; return rws::SPI_WRITE_FAILURE;
} }
pullCsHigh(gpioId, spiLock, gpioIF); pullCsHigh(gpioId, gpioIF);
return returnvalue::OK; return returnvalue::OK;
} }
@ -434,7 +436,7 @@ ReturnValue_t RwPollingTask::pullCsLow(gpioId_t gpioId, MutexIF* spiLock, GpioIF
return returnvalue::OK; return returnvalue::OK;
} }
void RwPollingTask::pullCsHigh(gpioId_t gpioId, MutexIF* spiLock, GpioIF& gpioIF) { void RwPollingTask::pullCsHigh(gpioId_t gpioId, GpioIF& gpioIF) {
if (gpioId != gpio::NO_GPIO) { if (gpioId != gpio::NO_GPIO) {
if (gpioIF.pullHigh(gpioId) != returnvalue::OK) { if (gpioIF.pullHigh(gpioId) != returnvalue::OK) {
sif::error << "closeSpi: Failed to pull chip select high" << std::endl; sif::error << "closeSpi: Failed to pull chip select high" << std::endl;

View File

@ -77,7 +77,7 @@ class RwPollingTask : public SystemObject, public ExecutableObjectIF, public Dev
size_t idAndIdxToReadBuffer(DeviceCommandId_t id, uint8_t rwIdx, uint8_t** readPtr); 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 encodeHdlc(const uint8_t* sourceBuf, size_t sourceLen, size_t& encodedLen);
void pullCsHigh(gpioId_t gpioId, MutexIF* spiLock, GpioIF& gpioIF); void pullCsHigh(gpioId_t gpioId, GpioIF& gpioIF);
void closeSpi(int); void closeSpi(int);
}; };