percent progress event

And some changes to allow restarting from the middle
This commit is contained in:
Robin Müller 2022-08-20 20:26:25 +02:00
parent f2190f8aa1
commit c094b45fb4
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
3 changed files with 38 additions and 28 deletions

View File

@ -1,5 +1,6 @@
#include "PlocSupvHelper.h" #include "PlocSupvHelper.h"
#include <cmath>
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
@ -98,8 +99,8 @@ ReturnValue_t PlocSupvHelper::setComIF(UartComIF* uartComIF_) {
void PlocSupvHelper::setComCookie(CookieIF* comCookie_) { comCookie = comCookie_; } void PlocSupvHelper::setComCookie(CookieIF* comCookie_) { comCookie = comCookie_; }
ReturnValue_t PlocSupvHelper::startUpdate(std::string file, uint8_t memoryId, ReturnValue_t PlocSupvHelper::startUpdate(std::string file, uint8_t memoryId, uint32_t startAddress,
uint32_t startAddress) { size_t startBytesWritten, uint16_t initSeqCount) {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
#ifdef XIPHOS_Q7S #ifdef XIPHOS_Q7S
result = FilesystemHelper::checkPath(file); result = FilesystemHelper::checkPath(file);
@ -125,10 +126,11 @@ ReturnValue_t PlocSupvHelper::startUpdate(std::string file, uint8_t memoryId,
update.length = getFileSize(update.file); update.length = getFileSize(update.file);
update.memoryId = memoryId; update.memoryId = memoryId;
update.startAddress = startAddress; update.startAddress = startAddress;
update.progressPercent = 0;
update.remainingSize = update.length; update.remainingSize = update.length;
update.bytesWritten = 0; update.bytesWritten = startBytesWritten;
update.packetNum = 1; update.packetNum = 1;
update.sequenceCount = 1; update.sequenceCount = initSeqCount;
internalState = InternalState::UPDATE; internalState = InternalState::UPDATE;
uartComIF->flushUartTxAndRxBuf(comCookie); uartComIF->flushUartTxAndRxBuf(comCookie);
semaphore.release(); semaphore.release();
@ -181,17 +183,7 @@ ReturnValue_t PlocSupvHelper::performUpdate() {
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
sif::info << "PlocSupvHelper::performUpdate: Writing Update Packets" << std::endl; return updateOperation();
result = writeUpdatePackets();
if (result != RETURN_OK) {
return result;
}
sif::info << "PlocSupvHelper::performUpdate: Memory Check" << std::endl;
result = handleCheckMemoryCommand();
if (result != RETURN_OK) {
return result;
}
return result;
} }
ReturnValue_t PlocSupvHelper::continueUpdate() { ReturnValue_t PlocSupvHelper::continueUpdate() {
@ -199,15 +191,17 @@ ReturnValue_t PlocSupvHelper::continueUpdate() {
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
result = writeUpdatePackets(); return updateOperation();
}
ReturnValue_t PlocSupvHelper::updateOperation() {
sif::info << "PlocSupvHelper::performUpdate: Writing Update Packets" << std::endl;
auto result = writeUpdatePackets();
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
result = handleCheckMemoryCommand(); sif::info << "PlocSupvHelper::performUpdate: Memory Check" << std::endl;
if (result != RETURN_OK) { return handleCheckMemoryCommand();
return result;
}
return result;
} }
ReturnValue_t PlocSupvHelper::writeUpdatePackets() { ReturnValue_t PlocSupvHelper::writeUpdatePackets() {
@ -216,7 +210,7 @@ ReturnValue_t PlocSupvHelper::writeUpdatePackets() {
ProgressPrinter progressPrinter("Supervisor update", update.length, ProgressPrinter progressPrinter("Supervisor update", update.length,
ProgressPrinter::HALF_PERCENT); ProgressPrinter::HALF_PERCENT);
#endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */ #endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */
uint8_t tempData[supv::WriteMemory::CHUNK_MAX]; uint8_t tempData[supv::WriteMemory::CHUNK_MAX + 1]{};
std::ifstream file(update.file, std::ifstream::binary); std::ifstream file(update.file, std::ifstream::binary);
uint16_t dataLength = 0; uint16_t dataLength = 0;
ccsds::SequenceFlags seqFlags; ccsds::SequenceFlags seqFlags;
@ -232,7 +226,7 @@ ReturnValue_t PlocSupvHelper::writeUpdatePackets() {
dataLength = static_cast<uint16_t>(update.remainingSize); dataLength = static_cast<uint16_t>(update.remainingSize);
} }
if (file.is_open()) { if (file.is_open()) {
file.seekg(update.bytesWritten, file.beg); file.seekg(update.bytesWritten, std::ios::beg);
file.read(reinterpret_cast<char*>(tempData), dataLength); file.read(reinterpret_cast<char*>(tempData), dataLength);
if (!file) { if (!file) {
sif::warning << "PlocSupvHelper::performUpdate: Read only " << file.gcount() << " of " sif::warning << "PlocSupvHelper::performUpdate: Read only " << file.gcount() << " of "
@ -252,22 +246,31 @@ ReturnValue_t PlocSupvHelper::writeUpdatePackets() {
} }
resetSpParams(); resetSpParams();
supv::WriteMemory packet(spParams); supv::WriteMemory packet(spParams);
result = packet.buildPacket(seqFlags, update.sequenceCount++, update.memoryId, result = packet.buildPacket(seqFlags, update.sequenceCount, update.memoryId,
update.startAddress + update.bytesWritten, dataLength, tempData); update.startAddress + update.bytesWritten, dataLength, tempData);
if (result != RETURN_OK) { if (result != RETURN_OK) {
update.sequenceCount--;
triggerEvent(WRITE_MEMORY_FAILED, update.packetNum); triggerEvent(WRITE_MEMORY_FAILED, update.packetNum);
return result; return result;
} }
result = handlePacketTransmission(packet); result = handlePacketTransmission(packet);
if (result != RETURN_OK) { if (result != RETURN_OK) {
update.sequenceCount--;
triggerEvent(WRITE_MEMORY_FAILED, update.packetNum); triggerEvent(WRITE_MEMORY_FAILED, update.packetNum);
return result; return result;
} }
uint8_t progPercent =
static_cast<uint8_t>(std::floor(static_cast<float>(update.bytesWritten) / update.length));
if (progPercent > update.progressPercent) {
update.progressPercent = progPercent;
if (progPercent % 5 == 0) {
// Useful to allow restarting the update
triggerEvent(SUPV_UPDATE_PROGRESS, update.bytesWritten, update.sequenceCount);
}
}
update.sequenceCount++;
update.remainingSize -= dataLength; update.remainingSize -= dataLength;
update.packetNum += 1; update.packetNum += 1;
update.bytesWritten += dataLength; update.bytesWritten += dataLength;
#if OBSW_DEBUG_PLOC_SUPERVISOR == 1 #if OBSW_DEBUG_PLOC_SUPERVISOR == 1
progressPrinter.print(update.bytesWritten); progressPrinter.print(update.bytesWritten);
#endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */ #endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */

View File

@ -89,6 +89,10 @@ class PlocSupvHelper : public SystemObject, public ExecutableObjectIF, public Ha
static const Event SUPV_REPLY_SIZE_MISSMATCH = MAKE_EVENT(20, severity::LOW); static const Event SUPV_REPLY_SIZE_MISSMATCH = MAKE_EVENT(20, severity::LOW);
static const Event SUPV_REPLY_CRC_MISSMATCH = MAKE_EVENT(21, severity::LOW); static const Event SUPV_REPLY_CRC_MISSMATCH = MAKE_EVENT(21, severity::LOW);
//! [EXPORT] : [COMMENT] Will be triggered every 5 percent of the update progress.
//! P1: Bytes written, P2: Sequence Count
static constexpr Event SUPV_UPDATE_PROGRESS = MAKE_EVENT(22, severity::INFO);
PlocSupvHelper(object_id_t objectId); PlocSupvHelper(object_id_t objectId);
virtual ~PlocSupvHelper(); virtual ~PlocSupvHelper();
@ -107,7 +111,8 @@ class PlocSupvHelper : public SystemObject, public ExecutableObjectIF, public Ha
* *
* @return RETURN_OK if successful, otherwise error return value * @return RETURN_OK if successful, otherwise error return value
*/ */
ReturnValue_t startUpdate(std::string file, uint8_t memoryId, uint32_t startAddress); ReturnValue_t startUpdate(std::string file, uint8_t memoryId, uint32_t startAddress,
size_t startBytesWritten = 0, uint16_t initSeqCount = 1);
/** /**
* @brief This initiate the continuation of a failed update. * @brief This initiate the continuation of a failed update.
@ -157,6 +162,7 @@ class PlocSupvHelper : public SystemObject, public ExecutableObjectIF, public Ha
size_t bytesWritten; size_t bytesWritten;
uint32_t packetNum; uint32_t packetNum;
uint16_t sequenceCount; uint16_t sequenceCount;
uint8_t progressPercent;
}; };
struct Update update; struct Update update;
@ -200,6 +206,7 @@ class PlocSupvHelper : public SystemObject, public ExecutableObjectIF, public Ha
ReturnValue_t performUpdate(); ReturnValue_t performUpdate();
ReturnValue_t continueUpdate(); ReturnValue_t continueUpdate();
ReturnValue_t updateOperation();
ReturnValue_t writeUpdatePackets(); ReturnValue_t writeUpdatePackets();
ReturnValue_t performEventBufferRequest(); ReturnValue_t performEventBufferRequest();
ReturnValue_t handlePacketTransmission(ploc::SpTcBase& packet, ReturnValue_t handlePacketTransmission(ploc::SpTcBase& packet,

2
tmtc

@ -1 +1 @@
Subproject commit 1b39bb2ad2421db89487b4ea352edbd4d420b9b1 Subproject commit 00e99292cc158a347f485507537fa5b63262243b