PLOC SUPV Update to newer firmware #316

Merged
muellerr merged 99 commits from mueller/tas_ploc_supv_update into develop 2022-11-18 14:27:13 +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 PlocSupvHelper::performOperation(uint8_t operationCode) {
ReturnValue_t result; ReturnValue_t result;
lock->lockMutex(); lock->lockMutex();
internalState = InternalState::IDLE; state = InternalState::IDLE;
lock->unlockMutex(); lock->unlockMutex();
while (true) { while (true) {
semaphore->acquire(); semaphore->acquire();
@ -103,10 +103,10 @@ ReturnValue_t PlocSupvHelper::performOperation(uint8_t operationCode) {
if (bytesRead == 0) { if (bytesRead == 0) {
{ {
MutexGuard mg(lock); MutexGuard mg(lock);
if (internalState == InternalState::FINISH) { if (state == InternalState::FINISH) {
// Flush received and unread data // Flush received and unread data
tcflush(serialPort, TCIOFLUSH); tcflush(serialPort, TCIOFLUSH);
internalState = InternalState::IDLE; state = InternalState::IDLE;
break; break;
} }
} }
@ -128,7 +128,7 @@ ReturnValue_t PlocSupvHelper::performOperation(uint8_t operationCode) {
// TODO: Parse ring buffer here // TODO: Parse ring buffer here
} }
lock->lockMutex(); lock->lockMutex();
InternalState currentState = internalState; InternalState currentState = state;
lock->unlockMutex(); lock->unlockMutex();
switch (currentState) { switch (currentState) {
case InternalState::IDLE: { case InternalState::IDLE: {
@ -144,13 +144,13 @@ ReturnValue_t PlocSupvHelper::performOperation(uint8_t operationCode) {
triggerEvent(SUPV_UPDATE_FAILED, result); triggerEvent(SUPV_UPDATE_FAILED, result);
} }
MutexGuard mg(lock); MutexGuard mg(lock);
internalState = InternalState::IDLE; state = InternalState::IDLE;
break; break;
} }
case InternalState::CHECK_MEMORY: { case InternalState::CHECK_MEMORY: {
executeFullCheckMemoryCommand(); executeFullCheckMemoryCommand();
MutexGuard mg(lock); MutexGuard mg(lock);
internalState = InternalState::IDLE; state = InternalState::IDLE;
break; break;
} }
case InternalState::CONTINUE_UPDATE: { case InternalState::CONTINUE_UPDATE: {
@ -163,7 +163,7 @@ ReturnValue_t PlocSupvHelper::performOperation(uint8_t operationCode) {
triggerEvent(SUPV_CONTINUE_UPDATE_FAILED, result); triggerEvent(SUPV_CONTINUE_UPDATE_FAILED, result);
} }
MutexGuard mg(lock); MutexGuard mg(lock);
internalState = InternalState::IDLE; state = InternalState::IDLE;
break; break;
} }
case InternalState::REQUEST_EVENT_BUFFER: { case InternalState::REQUEST_EVENT_BUFFER: {
@ -177,7 +177,7 @@ ReturnValue_t PlocSupvHelper::performOperation(uint8_t operationCode) {
triggerEvent(SUPV_EVENT_BUFFER_REQUEST_FAILED, result); triggerEvent(SUPV_EVENT_BUFFER_REQUEST_FAILED, result);
} }
MutexGuard mg(lock); MutexGuard mg(lock);
internalState = InternalState::IDLE; state = InternalState::IDLE;
break; break;
} }
case InternalState::HANDLER_DRIVEN: { case InternalState::HANDLER_DRIVEN: {
@ -253,7 +253,7 @@ ReturnValue_t PlocSupvHelper::performUpdate(const supv::UpdateParams& params) {
update.packetNum = 1; update.packetNum = 1;
update.deleteMemory = params.deleteMemory; update.deleteMemory = params.deleteMemory;
update.sequenceCount = params.seqCount; update.sequenceCount = params.seqCount;
internalState = InternalState::UPDATE; state = InternalState::UPDATE;
uartComIF->flushUartTxAndRxBuf(comCookie); uartComIF->flushUartTxAndRxBuf(comCookie);
semaphore->release(); semaphore->release();
return result; return result;
@ -272,14 +272,14 @@ ReturnValue_t PlocSupvHelper::performMemCheck(uint8_t memoryId, uint32_t startAd
update.startAddress = startAddress; update.startAddress = startAddress;
update.length = sizeToCheck; update.length = sizeToCheck;
update.crcShouldBeChecked = checkCrc; update.crcShouldBeChecked = checkCrc;
internalState = InternalState::CHECK_MEMORY; state = InternalState::CHECK_MEMORY;
uartComIF->flushUartTxAndRxBuf(comCookie); uartComIF->flushUartTxAndRxBuf(comCookie);
semaphore->release(); semaphore->release();
return returnvalue::OK; return returnvalue::OK;
} }
void PlocSupvHelper::initiateUpdateContinuation() { void PlocSupvHelper::initiateUpdateContinuation() {
internalState = InternalState::CONTINUE_UPDATE; state = InternalState::CONTINUE_UPDATE;
semaphore->release(); semaphore->release();
} }
@ -294,7 +294,7 @@ ReturnValue_t PlocSupvHelper::startEventBufferRequest(std::string path) {
return PATH_NOT_EXISTS; return PATH_NOT_EXISTS;
} }
eventBufferReq.path = path; eventBufferReq.path = path;
internalState = InternalState::REQUEST_EVENT_BUFFER; state = InternalState::REQUEST_EVENT_BUFFER;
uartComIF->flushUartTxAndRxBuf(comCookie); uartComIF->flushUartTxAndRxBuf(comCookie);
semaphore->release(); semaphore->release();
return returnvalue::OK; return returnvalue::OK;
@ -584,7 +584,7 @@ ReturnValue_t PlocSupvHelper::sendCommand(ploc::SpTcBase& packet) {
result = uartComIF->sendMessage(comCookie, packet.getFullPacket(), packet.getFullPacketLen()); result = uartComIF->sendMessage(comCookie, packet.getFullPacket(), packet.getFullPacketLen());
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
sif::warning << "PlocSupvHelper::sendCommand: Failed to send command" << std::endl; 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;
} }
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) { if (result != returnvalue::OK) {
sif::warning << "PlocSupvHelper::receive: Failed to request reply" << std::endl; sif::warning << "PlocSupvHelper::receive: Failed to request reply" << std::endl;
triggerEvent(SUPV_HELPER_REQUESTING_REPLY_FAILED, result, 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; return returnvalue::FAILED;
} }
result = uartComIF->readReceivedMessage(comCookie, &buffer, readBytes); result = uartComIF->readReceivedMessage(comCookie, &buffer, readBytes);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
sif::warning << "PlocSupvHelper::receive: Failed to read received message" << std::endl; 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; return returnvalue::FAILED;
} }
if (*readBytes > 0) { if (*readBytes > 0) {
@ -900,6 +900,23 @@ void PlocSupvHelper::resetSpParams() { spParams.buf = commandBuffer; }
ReturnValue_t PlocSupvHelper::sendMessage(CookieIF* cookie, const uint8_t* sendData, ReturnValue_t PlocSupvHelper::sendMessage(CookieIF* cookie, const uint8_t* sendData,
size_t sendLen) { 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; 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, ReturnValue_t PlocSupvHelper::readReceivedMessage(CookieIF* cookie, uint8_t** buffer,
size_t* size) { 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) { ReturnValue_t PlocSupvHelper::parseRecRingBufForHdlc(size_t& readSize) {

View File

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