diff --git a/linux/devices/SusPolling.cpp b/linux/devices/SusPolling.cpp index 1b7d3605..e5d330a3 100644 --- a/linux/devices/SusPolling.cpp +++ b/linux/devices/SusPolling.cpp @@ -18,7 +18,21 @@ ReturnValue_t SusPolling::performOperation(uint8_t operationCode) { state = InternalState::IDLE; ipcLock->unlockMutex(); semaphore->acquire(); - // TODO: Perform SUS polling here. + for(auto& susDev: susDevs) { + acs::SimpleSensorMode mode; + bool doPerformStartup = false; + { + MutexGuard mg(ipcLock); + mode = susDev.mode; + doPerformStartup = susDev.performStartup; + } + if (mode == acs::SimpleSensorMode::NORMAL) { + if(doPerformStartup) { + // Startup handling. + } + // Regular sensor polling. + } + } } return OK; } @@ -51,7 +65,14 @@ ReturnValue_t SusPolling::sendMessage(CookieIF* cookie, const uint8_t* sendData, return FAILED; } const auto* susReq = reinterpret_cast(sendData); + MutexGuard mg(ipcLock); if (susDevs[susIdx].mode != susReq->mode) { + if(susReq->mode == acs::SimpleSensorMode::NORMAL) { + susDevs[susIdx].performStartup = true; + } else { + susDevs[susIdx].ownReply.dataWasSet = false; + } + susDevs[susIdx].mode = susReq->mode; } return OK; } @@ -61,6 +82,18 @@ ReturnValue_t SusPolling::getSendSuccess(CookieIF* cookie) { return OK; } ReturnValue_t SusPolling::requestReceiveMessage(CookieIF* cookie, size_t requestLen) { return OK; } ReturnValue_t SusPolling::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) { + auto* spiCookie = dynamic_cast(cookie); + if (spiCookie == nullptr) { + return FAILED; + } + int susIdx = addressToIndex(spiCookie->getSpiAddress()); + if (susIdx < 0) { + return FAILED; + } + MutexGuard mg(ipcLock); + std::memcpy(&susDevs[susIdx].readerReply, &susDevs[susIdx].ownReply, sizeof(acs::SusReply)); + *buffer = reinterpret_cast(&susDevs[susIdx].readerReply); + *size = sizeof(acs::SusReply); return OK; }