fixed some bugs
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good

This commit is contained in:
2023-02-16 17:57:21 +01:00
parent c29d7e6f3e
commit cfad85c6c5
7 changed files with 31 additions and 26 deletions

View File

@ -32,6 +32,7 @@ ReturnValue_t RwPollingTask::performOperation(uint8_t operationCode) {
state = InternalState::IDLE;
ipcLock->unlockMutex();
semaphore->acquire();
TaskFactory::delayTask(5);
int fd = 0;
for (auto& skip : skipCommandingForRw) {
skip = false;
@ -55,7 +56,7 @@ ReturnValue_t RwPollingTask::performOperation(uint8_t operationCode) {
}
closeSpi(fd);
usleep(rws::SPI_REPLY_DELAY);
if (readAllRws(fd, rws::SET_SPEED) != returnvalue::OK) {
if (readAllRws(rws::SET_SPEED) != returnvalue::OK) {
continue;
}
prepareSimpleCommand(rws::GET_LAST_RESET_STATUS);
@ -117,7 +118,7 @@ ReturnValue_t RwPollingTask::initializeInterface(CookieIF* cookie) {
ReturnValue_t RwPollingTask::sendMessage(CookieIF* cookie, const uint8_t* sendData,
size_t sendLen) {
if (sendLen < 6) {
if (sendData == nullptr or sendLen < 8) {
return DeviceHandlerIF::INVALID_DATA;
}
int32_t speed = 0;
@ -142,7 +143,7 @@ ReturnValue_t RwPollingTask::sendMessage(CookieIF* cookie, const uint8_t* sendDa
rwCookie->currentRwSpeed = speed;
rwCookie->currentRampTime = rampTime;
rwCookie->specialRequest = specialRequest;
if (state == InternalState::IDLE and rwCookie->rwIdx == 3) {
if (state == InternalState::IDLE) {
state = InternalState::BUSY;
semaphore->release();
}
@ -188,13 +189,13 @@ ReturnValue_t RwPollingTask::writeAndReadAllRws(DeviceCommandId_t id) {
closeSpi(fd);
usleep(rws::SPI_REPLY_DELAY);
return readAllRws(fd, id);
return readAllRws(id);
}
ReturnValue_t RwPollingTask::openSpi(int flags, int& fd) {
fd = open(spiDev, flags);
if (fd < 0) {
sif::error << "rwSpiCallback::spiCallback: Failed to open device file" << std::endl;
sif::error << "RwPollingTask::openSpi: Failed to open device file" << std::endl;
return SpiComIF::OPENING_FILE_FAILED;
}
@ -206,27 +207,27 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
ReturnValue_t result = returnvalue::OK;
int fd = 0;
gpioId_t gpioId = rwCookie.getChipSelectPin();
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) {
return result;
}
pullCsLow(gpioId, spiLock, gpioIF);
/**
* 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.
*/
for (int idx = 0; idx < 5; idx++) {
if (read(fd, &byteRead, 1) != 1) {
sif::error << "rwSpiCallback::spiCallback: Read failed" << std::endl;
sif::error << "RwPollingTask: Read failed" << std::endl;
pullCsHigh(gpioId, gpioIF);
closeSpi(fd);
return rws::SPI_READ_FAILURE;
}
if (idx == 0) {
if (byteRead != rws::FRAME_DELIMITER) {
sif::error << "Invalid data, expected start marker" << std::endl;
sif::error << "Invalid data, expected start marker, got " << (int)byteRead << std::endl;
pullCsHigh(gpioId, gpioIF);
closeSpi(fd);
return rws::NO_START_MARKER;
@ -257,7 +258,7 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
if (decodedFrameLen != 0) {
byteRead = 0;
if (read(fd, &byteRead, 1) != 1) {
sif::error << "rwSpiCallback::spiCallback: Read failed" << std::endl;
sif::error << "RwPollingTask: Read failed" << std::endl;
result = rws::SPI_READ_FAILURE;
break;
}
@ -268,7 +269,7 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
break;
} else if (byteRead == 0x7D) {
if (read(fd, &byteRead, 1) != 1) {
sif::error << "rwSpiCallback::spiCallback: Read failed" << std::endl;
sif::error << "RwPollingTask: Read failed" << std::endl;
result = rws::SPI_READ_FAILURE;
break;
}
@ -281,7 +282,7 @@ ReturnValue_t RwPollingTask::readNextReply(RwCookie& rwCookie, uint8_t* replyBuf
decodedFrameLen++;
continue;
} else {
sif::error << "rwSpiCallback::spiCallback: Invalid substitute" << std::endl;
sif::error << "RwPollingTask: Invalid substitute" << std::endl;
result = rws::INVALID_SUBSTITUTE;
break;
}
@ -327,7 +328,7 @@ ReturnValue_t RwPollingTask::writeOneRwCmd(uint8_t rwIdx, int fd) {
return returnvalue::OK;
}
ReturnValue_t RwPollingTask::readAllRws(int fd, DeviceCommandId_t id) {
ReturnValue_t RwPollingTask::readAllRws(DeviceCommandId_t id) {
// SPI dev will be opened in readNextReply on demand.
for (unsigned idx = 0; idx < rwCookies.size(); idx++) {
if (((id == rws::SET_SPEED) and !rwCookies[idx]->setSpeed) or skipCommandingForRw[idx]) {
@ -463,14 +464,14 @@ ReturnValue_t RwPollingTask::sendOneMessage(int fd, RwCookie& rwCookie) {
ReturnValue_t RwPollingTask::pullCsLow(gpioId_t gpioId, MutexIF* spiLock, GpioIF& gpioIF) {
ReturnValue_t result = spiLock->lockMutex(TIMEOUT_TYPE, TIMEOUT_MS);
if (result != returnvalue::OK) {
sif::debug << "rwSpiCallback::spiCallback: Failed to lock mutex" << std::endl;
sif::debug << "RwPollingTask::pullCsLow: Failed to lock mutex" << std::endl;
return result;
}
// Pull SPI CS low. For now, no support for active high given
if (gpioId != gpio::NO_GPIO) {
ReturnValue_t result = gpioIF.pullLow(gpioId);
if (result != returnvalue::OK) {
sif::error << "rwSpiCallback::spiCallback: Failed to pull chip select low" << std::endl;
sif::error << "RwPollingTask::pullCsLow: Failed to pull chip select low" << std::endl;
return result;
}
}
@ -484,7 +485,7 @@ void RwPollingTask::pullCsHigh(gpioId_t gpioId, GpioIF& gpioIF) {
}
}
if (spiLock->unlockMutex() != returnvalue::OK) {
sif::error << "rwSpiCallback::closeSpi: Failed to unlock mutex" << std::endl;
sif::error << "RwPollingTask::pullCsHigh: Failed to unlock mutex" << std::endl;
;
}
}

View File

@ -58,7 +58,7 @@ class RwPollingTask : public SystemObject, public ExecutableObjectIF, public Dev
ReturnValue_t writeAndReadAllRws(DeviceCommandId_t id);
ReturnValue_t writeOneRwCmd(uint8_t rwIdx, int fd);
ReturnValue_t readAllRws(int fd, DeviceCommandId_t id);
ReturnValue_t readAllRws(DeviceCommandId_t id);
ReturnValue_t sendOneMessage(int fd, RwCookie& rwCookie);
ReturnValue_t readNextReply(RwCookie& rwCookie, uint8_t* replyBuf, size_t maxReplyLen);

View File

@ -47,7 +47,7 @@ enum sourceObjects : uint32_t {
GPIO_IF = 0x49010005,
/* Custom device handler */
SPI_RW_COM_IF = 0x49020005,
RW_POLLING_TASK = 0x49020005,
/* 0x54 ('T') for test handlers */
TEST_TASK = 0x54694269,