some more bugfixes
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit
This commit is contained in:
parent
8c001b6443
commit
655e01c2d1
@ -172,6 +172,7 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
|
||||
gpioId_t gpioId = rwCookie.getChipSelectPin();
|
||||
GpioIF& gpioIF = spiIF->getGpioInterface();
|
||||
pullCsLow(gpioId, spiLock, gpioIF);
|
||||
uint8_t byteRead = 0;
|
||||
for (unsigned idx = 0; idx < MAX_RETRIES_REPLY; idx++) {
|
||||
result = openSpi(O_RDWR, fd);
|
||||
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.
|
||||
* However, receiving more than 5 empty frames will be interpreted as an error.
|
||||
*/
|
||||
uint8_t byteRead = 0;
|
||||
for (int idx = 0; idx < 5; idx++) {
|
||||
if (read(fd, &byteRead, 1) != 1) {
|
||||
sif::error << "rwSpiCallback::spiCallback: Read failed" << std::endl;
|
||||
pullCsHigh(gpioId, spiLock, gpioIF);
|
||||
pullCsHigh(gpioId, gpioIF);
|
||||
closeSpi(fd);
|
||||
return rws::SPI_READ_FAILURE;
|
||||
}
|
||||
if (idx == 0) {
|
||||
if (byteRead != FLAG_BYTE) {
|
||||
sif::error << "Invalid data, expected start marker" << std::endl;
|
||||
pullCsHigh(gpioId, spiLock, gpioIF);
|
||||
pullCsHigh(gpioId, gpioIF);
|
||||
closeSpi(fd);
|
||||
return rws::NO_START_MARKER;
|
||||
}
|
||||
@ -202,7 +202,7 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
|
||||
break;
|
||||
}
|
||||
|
||||
pullCsHigh(gpioId, spiLock, gpioIF);
|
||||
pullCsHigh(gpioId, gpioIF);
|
||||
closeSpi(fd);
|
||||
if (idx == MAX_RETRIES_REPLY - 1) {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
#if FSFW_HAL_SPI_WIRETAPPING == 1
|
||||
sif::info << "RW start marker detected" << std::endl;
|
||||
#endif
|
||||
@ -218,7 +218,7 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
|
||||
size_t decodedFrameLen = 0;
|
||||
|
||||
while (decodedFrameLen < maxReplyLen) {
|
||||
/** First byte already read in */
|
||||
// First byte already read in
|
||||
if (decodedFrameLen != 0) {
|
||||
byteRead = 0;
|
||||
if (read(fd, &byteRead, 1) != 1) {
|
||||
@ -229,7 +229,7 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
|
||||
}
|
||||
|
||||
if (byteRead == FLAG_BYTE) {
|
||||
/** Reached end of frame */
|
||||
// Reached end of frame
|
||||
break;
|
||||
} else if (byteRead == 0x7D) {
|
||||
if (read(fd, &byteRead, 1) != 1) {
|
||||
@ -247,7 +247,6 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
|
||||
continue;
|
||||
} else {
|
||||
sif::error << "rwSpiCallback::spiCallback: Invalid substitute" << std::endl;
|
||||
closeSpi(fd);
|
||||
result = rws::INVALID_SUBSTITUTE;
|
||||
break;
|
||||
}
|
||||
@ -257,9 +256,10 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check end marker.
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
if (decodedFrameLen == maxReplyLen) {
|
||||
@ -269,8 +269,8 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
|
||||
break;
|
||||
}
|
||||
if (byteRead != FLAG_BYTE) {
|
||||
sif::error << "rwSpiCallback::spiCallback: Missing end sign "
|
||||
<< static_cast<int>(FLAG_BYTE) << std::endl;
|
||||
sif::error << "rwSpiCallback::spiCallback: Missing end sign " << static_cast<int>(FLAG_BYTE)
|
||||
<< std::endl;
|
||||
decodedFrameLen--;
|
||||
result = rws::MISSING_END_SIGN;
|
||||
break;
|
||||
@ -278,8 +278,10 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
|
||||
}
|
||||
result = returnvalue::OK;
|
||||
}
|
||||
}
|
||||
return returnvalue::OK;
|
||||
|
||||
pullCsHigh(gpioId, gpioIF);
|
||||
closeSpi(fd);
|
||||
return result;
|
||||
}
|
||||
|
||||
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);
|
||||
if (write(fd, encodedBuffer.data(), lenToSend) != static_cast<ssize_t>(lenToSend)) {
|
||||
sif::error << "rwSpiCallback::spiCallback: Write failed!" << std::endl;
|
||||
pullCsHigh(gpioId, spiLock, gpioIF);
|
||||
pullCsHigh(gpioId, gpioIF);
|
||||
return rws::SPI_WRITE_FAILURE;
|
||||
}
|
||||
pullCsHigh(gpioId, spiLock, gpioIF);
|
||||
pullCsHigh(gpioId, gpioIF);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
@ -434,7 +436,7 @@ ReturnValue_t RwPollingTask::pullCsLow(gpioId_t gpioId, MutexIF* spiLock, GpioIF
|
||||
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 (gpioIF.pullHigh(gpioId) != returnvalue::OK) {
|
||||
sif::error << "closeSpi: Failed to pull chip select high" << std::endl;
|
||||
|
@ -77,7 +77,7 @@ class RwPollingTask : public SystemObject, public ExecutableObjectIF, public Dev
|
||||
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, MutexIF* spiLock, GpioIF& gpioIF);
|
||||
void pullCsHigh(gpioId_t gpioId, GpioIF& gpioIF);
|
||||
void closeSpi(int);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user