PLOC SUPV Update to newer firmware #316
@ -33,7 +33,7 @@ PlocSupvHelper::PlocSupvHelper(object_id_t objectId) : SystemObject(objectId), r
|
||||
lock = MutexFactory::instance()->createMutex();
|
||||
}
|
||||
|
||||
PlocSupvHelper::~PlocSupvHelper() {}
|
||||
PlocSupvHelper::~PlocSupvHelper() = default;
|
||||
|
||||
ReturnValue_t PlocSupvHelper::initialize() {
|
||||
#ifdef XIPHOS_Q7S
|
||||
@ -47,12 +47,47 @@ ReturnValue_t PlocSupvHelper::initialize() {
|
||||
}
|
||||
|
||||
ReturnValue_t PlocSupvHelper::performOperation(uint8_t operationCode) {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
semaphore->acquire();
|
||||
ReturnValue_t result;
|
||||
lock->lockMutex();
|
||||
internalState = InternalState::IDLE;
|
||||
lock->unlockMutex();
|
||||
while (true) {
|
||||
switch (internalState) {
|
||||
case InternalState::IDLE: {
|
||||
semaphore->acquire();
|
||||
int bytesRead = 0;
|
||||
while (true) {
|
||||
bytesRead = read(serialPort, reinterpret_cast<void*>(recBuf.data()),
|
||||
static_cast<unsigned int>(recBuf.size()));
|
||||
if (bytesRead == 0) {
|
||||
{
|
||||
MutexGuard mg(lock);
|
||||
if (internalState == InternalState::FINISH) {
|
||||
// Flush received and unread data
|
||||
tcflush(serialPort, TCIOFLUSH);
|
||||
internalState = InternalState::IDLE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (bytesRead < 0) {
|
||||
sif::warning << "ScexUartReader::performOperation: read call failed with error [" << errno
|
||||
<< ", " << strerror(errno) << "]" << std::endl;
|
||||
break;
|
||||
} else if (bytesRead >= static_cast<int>(recBuf.size())) {
|
||||
sif::error << "ScexUartReader::performOperation: Receive buffer too small for " << bytesRead
|
||||
<< " bytes" << std::endl;
|
||||
} else if (bytesRead > 0) {
|
||||
if (debugMode) {
|
||||
sif::info << "Received " << bytesRead
|
||||
<< " bytes from the Solar Cell Experiment:" << std::endl;
|
||||
}
|
||||
// insert buffer into ring buffer here
|
||||
// ReturnValue_t result = dleParser.passData(recBuf.data(), bytesRead);
|
||||
// TODO: Parse ring buffer here
|
||||
}
|
||||
lock->lockMutex();
|
||||
InternalState currentState = internalState;
|
||||
lock->unlockMutex();
|
||||
switch (currentState) {
|
||||
case InternalState::IDLE: {
|
||||
break;
|
||||
}
|
||||
case InternalState::UPDATE: {
|
||||
@ -64,11 +99,13 @@ ReturnValue_t PlocSupvHelper::performOperation(uint8_t operationCode) {
|
||||
} else {
|
||||
triggerEvent(SUPV_UPDATE_FAILED, result);
|
||||
}
|
||||
MutexGuard mg(lock);
|
||||
internalState = InternalState::IDLE;
|
||||
break;
|
||||
}
|
||||
case InternalState::CHECK_MEMORY: {
|
||||
executeFullCheckMemoryCommand();
|
||||
MutexGuard mg(lock);
|
||||
internalState = InternalState::IDLE;
|
||||
break;
|
||||
}
|
||||
@ -81,6 +118,7 @@ ReturnValue_t PlocSupvHelper::performOperation(uint8_t operationCode) {
|
||||
} else {
|
||||
triggerEvent(SUPV_CONTINUE_UPDATE_FAILED, result);
|
||||
}
|
||||
MutexGuard mg(lock);
|
||||
internalState = InternalState::IDLE;
|
||||
break;
|
||||
}
|
||||
@ -94,14 +132,19 @@ ReturnValue_t PlocSupvHelper::performOperation(uint8_t operationCode) {
|
||||
} else {
|
||||
triggerEvent(SUPV_EVENT_BUFFER_REQUEST_FAILED, result);
|
||||
}
|
||||
MutexGuard mg(lock);
|
||||
internalState = InternalState::IDLE;
|
||||
break;
|
||||
}
|
||||
case InternalState::HANDLER_DRIVEN: {
|
||||
continue;
|
||||
}
|
||||
default:
|
||||
sif::debug << "PlocSupvHelper::performOperation: Invalid state" << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t PlocSupvHelper::setComIF(UartComIF* uartComIF_) {
|
||||
|
@ -200,13 +200,22 @@ class PlocSupvHelper : public DeviceCommunicationIF,
|
||||
|
||||
EventBufferRequest eventBufferReq;
|
||||
|
||||
enum class InternalState { IDLE, UPDATE, CONTINUE_UPDATE, REQUEST_EVENT_BUFFER, CHECK_MEMORY };
|
||||
enum class InternalState {
|
||||
IDLE,
|
||||
HANDLER_DRIVEN,
|
||||
UPDATE,
|
||||
CONTINUE_UPDATE,
|
||||
REQUEST_EVENT_BUFFER,
|
||||
CHECK_MEMORY,
|
||||
FINISH
|
||||
};
|
||||
|
||||
InternalState internalState = InternalState::IDLE;
|
||||
|
||||
#ifdef XIPHOS_Q7S
|
||||
SdCardManager* sdcMan = nullptr;
|
||||
#endif
|
||||
std::array<uint8_t, 2048> recBuf = {};
|
||||
uint8_t commandBuffer[supv::MAX_COMMAND_SIZE]{};
|
||||
SpacePacketCreator creator;
|
||||
ploc::SpTcParams spParams = ploc::SpTcParams(creator);
|
||||
@ -214,6 +223,7 @@ class PlocSupvHelper : public DeviceCommunicationIF,
|
||||
std::array<uint8_t, supv::MAX_COMMAND_SIZE> tmBuf{};
|
||||
|
||||
bool terminate = false;
|
||||
bool debugMode = false;
|
||||
|
||||
SimpleRingBuffer ringBuf;
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user