v1.17.0 #327

Merged
muellerr merged 131 commits from develop into main 2022-11-28 18:29:31 +01:00
2 changed files with 49 additions and 21 deletions
Showing only changes of commit 5df45f9fa7 - Show all commits

View File

@ -92,7 +92,7 @@ ReturnValue_t PlocSupvHelper::initialize() {
ReturnValue_t PlocSupvHelper::performOperation(uint8_t operationCode) {
ReturnValue_t result;
lock->lockMutex();
internalState = InternalState::IDLE;
state = InternalState::IDLE;
lock->unlockMutex();
while (true) {
semaphore->acquire();
@ -103,10 +103,10 @@ ReturnValue_t PlocSupvHelper::performOperation(uint8_t operationCode) {
if (bytesRead == 0) {
{
MutexGuard mg(lock);
if (internalState == InternalState::FINISH) {
if (state == InternalState::FINISH) {
// Flush received and unread data
tcflush(serialPort, TCIOFLUSH);
internalState = InternalState::IDLE;
state = InternalState::IDLE;
break;
}
}
@ -128,7 +128,7 @@ ReturnValue_t PlocSupvHelper::performOperation(uint8_t operationCode) {
// TODO: Parse ring buffer here
}
lock->lockMutex();
InternalState currentState = internalState;
InternalState currentState = state;
lock->unlockMutex();
switch (currentState) {
case InternalState::IDLE: {
@ -144,13 +144,13 @@ ReturnValue_t PlocSupvHelper::performOperation(uint8_t operationCode) {
triggerEvent(SUPV_UPDATE_FAILED, result);
}
MutexGuard mg(lock);
internalState = InternalState::IDLE;
state = InternalState::IDLE;
break;
}
case InternalState::CHECK_MEMORY: {
executeFullCheckMemoryCommand();
MutexGuard mg(lock);
internalState = InternalState::IDLE;
state = InternalState::IDLE;
break;
}
case InternalState::CONTINUE_UPDATE: {
@ -163,7 +163,7 @@ ReturnValue_t PlocSupvHelper::performOperation(uint8_t operationCode) {
triggerEvent(SUPV_CONTINUE_UPDATE_FAILED, result);
}
MutexGuard mg(lock);
internalState = InternalState::IDLE;
state = InternalState::IDLE;
break;
}
case InternalState::REQUEST_EVENT_BUFFER: {
@ -177,7 +177,7 @@ ReturnValue_t PlocSupvHelper::performOperation(uint8_t operationCode) {
triggerEvent(SUPV_EVENT_BUFFER_REQUEST_FAILED, result);
}
MutexGuard mg(lock);
internalState = InternalState::IDLE;
state = InternalState::IDLE;
break;
}
case InternalState::HANDLER_DRIVEN: {
@ -253,7 +253,7 @@ ReturnValue_t PlocSupvHelper::performUpdate(const supv::UpdateParams& params) {
update.packetNum = 1;
update.deleteMemory = params.deleteMemory;
update.sequenceCount = params.seqCount;
internalState = InternalState::UPDATE;
state = InternalState::UPDATE;
uartComIF->flushUartTxAndRxBuf(comCookie);
semaphore->release();
return result;
@ -272,14 +272,14 @@ ReturnValue_t PlocSupvHelper::performMemCheck(uint8_t memoryId, uint32_t startAd
update.startAddress = startAddress;
update.length = sizeToCheck;
update.crcShouldBeChecked = checkCrc;
internalState = InternalState::CHECK_MEMORY;
state = InternalState::CHECK_MEMORY;
uartComIF->flushUartTxAndRxBuf(comCookie);
semaphore->release();
return returnvalue::OK;
}
void PlocSupvHelper::initiateUpdateContinuation() {
internalState = InternalState::CONTINUE_UPDATE;
state = InternalState::CONTINUE_UPDATE;
semaphore->release();
}
@ -294,7 +294,7 @@ ReturnValue_t PlocSupvHelper::startEventBufferRequest(std::string path) {
return PATH_NOT_EXISTS;
}
eventBufferReq.path = path;
internalState = InternalState::REQUEST_EVENT_BUFFER;
state = InternalState::REQUEST_EVENT_BUFFER;
uartComIF->flushUartTxAndRxBuf(comCookie);
semaphore->release();
return returnvalue::OK;
@ -584,7 +584,7 @@ ReturnValue_t PlocSupvHelper::sendCommand(ploc::SpTcBase& packet) {
result = uartComIF->sendMessage(comCookie, packet.getFullPacket(), packet.getFullPacketLen());
if (result != returnvalue::OK) {
sif::warning << "PlocSupvHelper::sendCommand: Failed to send command" << std::endl;
triggerEvent(SUPV_SENDING_COMMAND_FAILED, result, static_cast<uint32_t>(internalState));
triggerEvent(SUPV_SENDING_COMMAND_FAILED, result, static_cast<uint32_t>(state));
return result;
}
return result;
@ -699,13 +699,13 @@ ReturnValue_t PlocSupvHelper::receive(uint8_t* data, size_t* readBytes, size_t r
if (result != returnvalue::OK) {
sif::warning << "PlocSupvHelper::receive: Failed to request reply" << std::endl;
triggerEvent(SUPV_HELPER_REQUESTING_REPLY_FAILED, result,
static_cast<uint32_t>(static_cast<uint32_t>(internalState)));
static_cast<uint32_t>(static_cast<uint32_t>(state)));
return returnvalue::FAILED;
}
result = uartComIF->readReceivedMessage(comCookie, &buffer, readBytes);
if (result != returnvalue::OK) {
sif::warning << "PlocSupvHelper::receive: Failed to read received message" << std::endl;
triggerEvent(SUPV_HELPER_READING_REPLY_FAILED, result, static_cast<uint32_t>(internalState));
triggerEvent(SUPV_HELPER_READING_REPLY_FAILED, result, static_cast<uint32_t>(state));
return returnvalue::FAILED;
}
if (*readBytes > 0) {
@ -900,6 +900,23 @@ void PlocSupvHelper::resetSpParams() { spParams.buf = commandBuffer; }
ReturnValue_t PlocSupvHelper::sendMessage(CookieIF* cookie, const uint8_t* sendData,
size_t sendLen) {
ReturnValue_t result;
if (sendData == nullptr or sendLen == 0) {
return FAILED;
}
lock->lockMutex();
if (state != InternalState::IDLE) {
lock->unlockMutex();
return FAILED;
}
tcflush(serialPort, TCIFLUSH);
state = InternalState::RUNNING;
lock->unlockMutex();
result = semaphore->release();
if (result != OK) {
std::cout << "PlocSupvHelper::sendMessage: Releasing semaphore failed" << std::endl;
}
return returnvalue::OK;
}
@ -911,7 +928,18 @@ ReturnValue_t PlocSupvHelper::requestReceiveMessage(CookieIF* cookie, size_t req
ReturnValue_t PlocSupvHelper::readReceivedMessage(CookieIF* cookie, uint8_t** buffer,
size_t* size) {
return returnvalue::OK;
MutexGuard mg(lock);
if (ipcQueue.empty()) {
*size = 0;
return OK;
}
ipcQueue.retrieve(size);
*buffer = ipcBuffer.data();
ReturnValue_t result = ipcRingBuf.readData(ipcBuffer.data(), *size, true);
if (result != OK) {
sif::warning << "ScexUartReader::readReceivedMessage: Reading RingBuffer failed" << std::endl;
}
return OK;
}
ReturnValue_t PlocSupvHelper::parseRecRingBufForHdlc(size_t& readSize) {

View File

@ -211,17 +211,17 @@ class PlocSupvHelper : public DeviceCommunicationIF,
EventBufferRequest eventBufferReq;
enum class InternalState {
IDLE,
enum class InternalState { IDLE, RUNNING, FINISH };
enum class Request {
HANDLER_DRIVEN,
UPDATE,
CONTINUE_UPDATE,
REQUEST_EVENT_BUFFER,
CHECK_MEMORY,
FINISH
};
InternalState internalState = InternalState::IDLE;
InternalState state = InternalState::IDLE;
Request request = Request::HANDLER_DRIVEN;
#ifdef XIPHOS_Q7S
SdCardManager* sdcMan = nullptr;