v1.14.0 #304

Merged
muellerr merged 366 commits from develop into main 2022-10-10 17:46:38 +02:00
3 changed files with 38 additions and 28 deletions
Showing only changes of commit c094b45fb4 - Show all commits

View File

@ -1,5 +1,6 @@
#include "PlocSupvHelper.h"
#include <cmath>
#include <filesystem>
#include <fstream>
@ -98,8 +99,8 @@ ReturnValue_t PlocSupvHelper::setComIF(UartComIF* uartComIF_) {
void PlocSupvHelper::setComCookie(CookieIF* comCookie_) { comCookie = comCookie_; }
ReturnValue_t PlocSupvHelper::startUpdate(std::string file, uint8_t memoryId,
uint32_t startAddress) {
ReturnValue_t PlocSupvHelper::startUpdate(std::string file, uint8_t memoryId, uint32_t startAddress,
size_t startBytesWritten, uint16_t initSeqCount) {
ReturnValue_t result = RETURN_OK;
#ifdef XIPHOS_Q7S
result = FilesystemHelper::checkPath(file);
@ -125,10 +126,11 @@ ReturnValue_t PlocSupvHelper::startUpdate(std::string file, uint8_t memoryId,
update.length = getFileSize(update.file);
update.memoryId = memoryId;
update.startAddress = startAddress;
update.progressPercent = 0;
update.remainingSize = update.length;
update.bytesWritten = 0;
update.bytesWritten = startBytesWritten;
update.packetNum = 1;
update.sequenceCount = 1;
update.sequenceCount = initSeqCount;
internalState = InternalState::UPDATE;
uartComIF->flushUartTxAndRxBuf(comCookie);
semaphore.release();
@ -181,17 +183,7 @@ ReturnValue_t PlocSupvHelper::performUpdate() {
if (result != RETURN_OK) {
return result;
}
sif::info << "PlocSupvHelper::performUpdate: Writing Update Packets" << std::endl;
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;
return updateOperation();
}
ReturnValue_t PlocSupvHelper::continueUpdate() {
@ -199,15 +191,17 @@ ReturnValue_t PlocSupvHelper::continueUpdate() {
if (result != RETURN_OK) {
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) {
return result;
}
result = handleCheckMemoryCommand();
if (result != RETURN_OK) {
return result;
}
return result;
sif::info << "PlocSupvHelper::performUpdate: Memory Check" << std::endl;
return handleCheckMemoryCommand();
}
ReturnValue_t PlocSupvHelper::writeUpdatePackets() {
@ -216,7 +210,7 @@ ReturnValue_t PlocSupvHelper::writeUpdatePackets() {
ProgressPrinter progressPrinter("Supervisor update", update.length,
ProgressPrinter::HALF_PERCENT);
#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);
uint16_t dataLength = 0;
ccsds::SequenceFlags seqFlags;
@ -232,7 +226,7 @@ ReturnValue_t PlocSupvHelper::writeUpdatePackets() {
dataLength = static_cast<uint16_t>(update.remainingSize);
}
if (file.is_open()) {
file.seekg(update.bytesWritten, file.beg);
file.seekg(update.bytesWritten, std::ios::beg);
file.read(reinterpret_cast<char*>(tempData), dataLength);
if (!file) {
sif::warning << "PlocSupvHelper::performUpdate: Read only " << file.gcount() << " of "
@ -252,22 +246,31 @@ ReturnValue_t PlocSupvHelper::writeUpdatePackets() {
}
resetSpParams();
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);
if (result != RETURN_OK) {
update.sequenceCount--;
triggerEvent(WRITE_MEMORY_FAILED, update.packetNum);
return result;
}
result = handlePacketTransmission(packet);
if (result != RETURN_OK) {
update.sequenceCount--;
triggerEvent(WRITE_MEMORY_FAILED, update.packetNum);
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.packetNum += 1;
update.bytesWritten += dataLength;
#if OBSW_DEBUG_PLOC_SUPERVISOR == 1
progressPrinter.print(update.bytesWritten);
#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_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);
virtual ~PlocSupvHelper();
@ -107,7 +111,8 @@ class PlocSupvHelper : public SystemObject, public ExecutableObjectIF, public Ha
*
* @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.
@ -157,6 +162,7 @@ class PlocSupvHelper : public SystemObject, public ExecutableObjectIF, public Ha
size_t bytesWritten;
uint32_t packetNum;
uint16_t sequenceCount;
uint8_t progressPercent;
};
struct Update update;
@ -200,6 +206,7 @@ class PlocSupvHelper : public SystemObject, public ExecutableObjectIF, public Ha
ReturnValue_t performUpdate();
ReturnValue_t continueUpdate();
ReturnValue_t updateOperation();
ReturnValue_t writeUpdatePackets();
ReturnValue_t performEventBufferRequest();
ReturnValue_t handlePacketTransmission(ploc::SpTcBase& packet,

2
tmtc

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