v1.14.0 #304
@ -114,14 +114,13 @@ ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId,
|
|||||||
if (size > config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE) {
|
if (size > config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE) {
|
||||||
return SupvReturnValuesIF::FILENAME_TOO_LONG;
|
return SupvReturnValuesIF::FILENAME_TOO_LONG;
|
||||||
}
|
}
|
||||||
std::string file = "";
|
UpdateParams params;
|
||||||
uint8_t memoryId = 0;
|
result = extractUpdateCommand(data, size, params);
|
||||||
uint32_t startAddress = 0;
|
|
||||||
result = extractUpdateCommand(data, size, &file, &memoryId, &startAddress);
|
|
||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
result = supvHelper->startUpdate(file, memoryId, startAddress);
|
result = supvHelper->performUpdate(params.file, params.memId, params.startAddr,
|
||||||
|
params.bytesWritten, params.seqCount);
|
||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -1974,24 +1973,23 @@ ReturnValue_t PlocSupervisorHandler::getTimeStampString(std::string& timeStamp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t PlocSupervisorHandler::extractUpdateCommand(const uint8_t* commandData, size_t size,
|
ReturnValue_t PlocSupervisorHandler::extractUpdateCommand(const uint8_t* commandData, size_t size,
|
||||||
std::string* file, uint8_t* memoryId,
|
UpdateParams& params) {
|
||||||
uint32_t* startAddress) {
|
|
||||||
ReturnValue_t result = RETURN_OK;
|
ReturnValue_t result = RETURN_OK;
|
||||||
if (size > (config::MAX_FILENAME_SIZE + config::MAX_PATH_SIZE + sizeof(*memoryId)) +
|
if (size > (config::MAX_FILENAME_SIZE + config::MAX_PATH_SIZE + sizeof(params.memId)) +
|
||||||
sizeof(*startAddress)) {
|
sizeof(params.startAddr)) {
|
||||||
sif::warning << "PlocSupervisorHandler::extractUpdateCommand: Data size too big" << std::endl;
|
sif::warning << "PlocSupervisorHandler::extractUpdateCommand: Data size too big" << std::endl;
|
||||||
return SupvReturnValuesIF::INVALID_LENGTH;
|
return SupvReturnValuesIF::INVALID_LENGTH;
|
||||||
}
|
}
|
||||||
*file = std::string(reinterpret_cast<const char*>(commandData));
|
params.file = std::string(reinterpret_cast<const char*>(commandData));
|
||||||
if (file->size() > (config::MAX_FILENAME_SIZE + config::MAX_PATH_SIZE)) {
|
if (params.file.size() > (config::MAX_FILENAME_SIZE + config::MAX_PATH_SIZE)) {
|
||||||
sif::warning << "PlocSupervisorHandler::extractUpdateCommand: Filename too long" << std::endl;
|
sif::warning << "PlocSupervisorHandler::extractUpdateCommand: Filename too long" << std::endl;
|
||||||
return SupvReturnValuesIF::FILENAME_TOO_LONG;
|
return SupvReturnValuesIF::FILENAME_TOO_LONG;
|
||||||
}
|
}
|
||||||
*memoryId = *(commandData + file->size() + SIZE_NULL_TERMINATOR);
|
params.memId = *(commandData + params.file.size() + SIZE_NULL_TERMINATOR);
|
||||||
const uint8_t* startAddressPtr =
|
const uint8_t* startAddressPtr =
|
||||||
commandData + file->size() + SIZE_NULL_TERMINATOR + sizeof(*memoryId);
|
commandData + params.file.size() + SIZE_NULL_TERMINATOR + sizeof(params.memId);
|
||||||
size_t remainingSize = 4;
|
size_t remainingSize = 10;
|
||||||
result = SerializeAdapter::deSerialize(startAddress, startAddressPtr, &remainingSize,
|
result = SerializeAdapter::deSerialize(¶ms.startAddr, &startAddressPtr, &remainingSize,
|
||||||
SerializeIF::Endianness::BIG);
|
SerializeIF::Endianness::BIG);
|
||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
sif::warning
|
sif::warning
|
||||||
@ -1999,6 +1997,22 @@ ReturnValue_t PlocSupervisorHandler::extractUpdateCommand(const uint8_t* command
|
|||||||
<< std::endl;
|
<< std::endl;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
result = SerializeAdapter::deSerialize(¶ms.bytesWritten, &startAddressPtr, &remainingSize,
|
||||||
|
SerializeIF::Endianness::BIG);
|
||||||
|
if (result != RETURN_OK) {
|
||||||
|
sif::warning << "PlocSupervisorHandler::extractUpdateCommand: Failed to deserialize bytes "
|
||||||
|
"already written"
|
||||||
|
<< std::endl;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
result = SerializeAdapter::deSerialize(¶ms.seqCount, &startAddressPtr, &remainingSize,
|
||||||
|
SerializeIF::Endianness::BIG);
|
||||||
|
if (result != RETURN_OK) {
|
||||||
|
sif::warning
|
||||||
|
<< "PlocSupervisorHandler::extractUpdateCommand: Failed to deserialize start sequence count"
|
||||||
|
<< std::endl;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,8 +367,15 @@ class PlocSupervisorHandler : public DeviceHandlerBase {
|
|||||||
|
|
||||||
ReturnValue_t prepareSetShutdownTimeoutCmd(const uint8_t* commandData);
|
ReturnValue_t prepareSetShutdownTimeoutCmd(const uint8_t* commandData);
|
||||||
|
|
||||||
ReturnValue_t extractUpdateCommand(const uint8_t* commandData, size_t size, std::string* file,
|
struct UpdateParams {
|
||||||
uint8_t* memoryId, uint32_t* startAddress);
|
std::string file;
|
||||||
|
uint8_t memId;
|
||||||
|
uint32_t startAddr;
|
||||||
|
uint32_t bytesWritten;
|
||||||
|
uint16_t seqCount;
|
||||||
|
};
|
||||||
|
|
||||||
|
ReturnValue_t extractUpdateCommand(const uint8_t* commandData, size_t size, UpdateParams& params);
|
||||||
ReturnValue_t eventSubscription();
|
ReturnValue_t eventSubscription();
|
||||||
|
|
||||||
ReturnValue_t handleExecutionSuccessReport(const uint8_t* data);
|
ReturnValue_t handleExecutionSuccessReport(const uint8_t* data);
|
||||||
|
@ -99,8 +99,14 @@ 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, uint32_t startAddress,
|
ReturnValue_t PlocSupvHelper::startUpdate(std::string file, uint8_t memoryId,
|
||||||
size_t startBytesWritten, uint16_t initSeqCount) {
|
uint32_t startAddress) {
|
||||||
|
return performUpdate(file, memoryId, startAddress, 0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t PlocSupvHelper::performUpdate(std::string file, uint8_t memoryId,
|
||||||
|
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);
|
||||||
@ -127,7 +133,6 @@ ReturnValue_t PlocSupvHelper::startUpdate(std::string file, uint8_t memoryId, ui
|
|||||||
update.memoryId = memoryId;
|
update.memoryId = memoryId;
|
||||||
update.startAddress = startAddress;
|
update.startAddress = startAddress;
|
||||||
update.progressPercent = 0;
|
update.progressPercent = 0;
|
||||||
update.remainingSize = update.length;
|
|
||||||
update.bytesWritten = startBytesWritten;
|
update.bytesWritten = startBytesWritten;
|
||||||
update.packetNum = 1;
|
update.packetNum = 1;
|
||||||
update.sequenceCount = initSeqCount;
|
update.sequenceCount = initSeqCount;
|
||||||
@ -214,16 +219,19 @@ ReturnValue_t PlocSupvHelper::writeUpdatePackets() {
|
|||||||
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;
|
||||||
while (update.remainingSize > 0) {
|
while (update.bytesWritten < update.length) {
|
||||||
if (terminate) {
|
if (terminate) {
|
||||||
terminate = false;
|
terminate = false;
|
||||||
triggerEvent(TERMINATED_UPDATE_PROCEDURE);
|
triggerEvent(TERMINATED_UPDATE_PROCEDURE);
|
||||||
return PROCESS_TERMINATED;
|
return PROCESS_TERMINATED;
|
||||||
}
|
}
|
||||||
if (update.remainingSize > supv::WriteMemory::CHUNK_MAX) {
|
size_t remainingSize = update.length - update.bytesWritten;
|
||||||
|
bool lastSegment = false;
|
||||||
|
if (remainingSize > supv::WriteMemory::CHUNK_MAX) {
|
||||||
dataLength = supv::WriteMemory::CHUNK_MAX;
|
dataLength = supv::WriteMemory::CHUNK_MAX;
|
||||||
} else {
|
} else {
|
||||||
dataLength = static_cast<uint16_t>(update.remainingSize);
|
lastSegment = true;
|
||||||
|
dataLength = static_cast<uint16_t>(remainingSize);
|
||||||
}
|
}
|
||||||
if (file.is_open()) {
|
if (file.is_open()) {
|
||||||
file.seekg(update.bytesWritten, std::ios::beg);
|
file.seekg(update.bytesWritten, std::ios::beg);
|
||||||
@ -239,26 +247,14 @@ ReturnValue_t PlocSupvHelper::writeUpdatePackets() {
|
|||||||
}
|
}
|
||||||
if (update.bytesWritten == 0) {
|
if (update.bytesWritten == 0) {
|
||||||
seqFlags = ccsds::SequenceFlags::FIRST_SEGMENT;
|
seqFlags = ccsds::SequenceFlags::FIRST_SEGMENT;
|
||||||
} else if (update.remainingSize == 0) {
|
} else if (lastSegment) {
|
||||||
seqFlags = ccsds::SequenceFlags::LAST_SEGMENT;
|
seqFlags = ccsds::SequenceFlags::LAST_SEGMENT;
|
||||||
} else {
|
} else {
|
||||||
seqFlags = ccsds::SequenceFlags::CONTINUATION;
|
seqFlags = ccsds::SequenceFlags::CONTINUATION;
|
||||||
}
|
}
|
||||||
resetSpParams();
|
resetSpParams();
|
||||||
supv::WriteMemory packet(spParams);
|
float progress = static_cast<float>(update.bytesWritten) / update.length;
|
||||||
result = packet.buildPacket(seqFlags, update.sequenceCount, update.memoryId,
|
uint8_t progPercent = std::floor(progress * 100);
|
||||||
update.startAddress + update.bytesWritten, dataLength, tempData);
|
|
||||||
if (result != RETURN_OK) {
|
|
||||||
triggerEvent(WRITE_MEMORY_FAILED, update.packetNum);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
result = handlePacketTransmission(packet);
|
|
||||||
if (result != RETURN_OK) {
|
|
||||||
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) {
|
if (progPercent > update.progressPercent) {
|
||||||
update.progressPercent = progPercent;
|
update.progressPercent = progPercent;
|
||||||
if (progPercent % 5 == 0) {
|
if (progPercent % 5 == 0) {
|
||||||
@ -266,8 +262,19 @@ ReturnValue_t PlocSupvHelper::writeUpdatePackets() {
|
|||||||
triggerEvent(SUPV_UPDATE_PROGRESS, update.bytesWritten, update.sequenceCount);
|
triggerEvent(SUPV_UPDATE_PROGRESS, update.bytesWritten, update.sequenceCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
supv::WriteMemory packet(spParams);
|
||||||
|
result = packet.buildPacket(seqFlags, update.sequenceCount, update.memoryId,
|
||||||
|
update.startAddress + update.bytesWritten, dataLength, tempData);
|
||||||
|
if (result != RETURN_OK) {
|
||||||
|
triggerEvent(WRITE_MEMORY_FAILED, update.bytesWritten, update.sequenceCount);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
result = handlePacketTransmission(packet);
|
||||||
|
if (result != RETURN_OK) {
|
||||||
|
triggerEvent(WRITE_MEMORY_FAILED, update.bytesWritten, update.sequenceCount);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
update.sequenceCount++;
|
update.sequenceCount++;
|
||||||
update.remainingSize -= dataLength;
|
|
||||||
update.packetNum += 1;
|
update.packetNum += 1;
|
||||||
update.bytesWritten += dataLength;
|
update.bytesWritten += dataLength;
|
||||||
|
|
||||||
|
@ -83,8 +83,8 @@ class PlocSupvHelper : public SystemObject, public ExecutableObjectIF, public Ha
|
|||||||
//! P1: Return value
|
//! P1: Return value
|
||||||
//! P2: Apid of command for which the reception of the execution report failed
|
//! P2: Apid of command for which the reception of the execution report failed
|
||||||
static const Event EXE_RECEPTION_FAILURE = MAKE_EVENT(18, severity::LOW);
|
static const Event EXE_RECEPTION_FAILURE = MAKE_EVENT(18, severity::LOW);
|
||||||
//! [EXPORT] : [COMMENT] Update procedure failed when sending packet with number P1
|
//! [EXPORT] : [COMMENT] Update procedure failed when sending packet.
|
||||||
//! P1: Packet number for which the memory write command fails
|
//! P1: Bytes written, P2: Sequence Count
|
||||||
static const Event WRITE_MEMORY_FAILED = MAKE_EVENT(19, severity::LOW);
|
static const Event WRITE_MEMORY_FAILED = MAKE_EVENT(19, severity::LOW);
|
||||||
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);
|
||||||
@ -111,8 +111,9 @@ 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 performUpdate(std::string file, uint8_t memoryId, uint32_t startAddress,
|
||||||
size_t startBytesWritten = 0, uint16_t initSeqCount = 1);
|
size_t startBytesWritten, uint16_t initSeqCount);
|
||||||
|
ReturnValue_t startUpdate(std::string file, uint8_t memoryId, uint32_t startAddress);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This initiate the continuation of a failed update.
|
* @brief This initiate the continuation of a failed update.
|
||||||
@ -158,7 +159,7 @@ class PlocSupvHelper : public SystemObject, public ExecutableObjectIF, public Ha
|
|||||||
// Size of update
|
// Size of update
|
||||||
uint32_t length;
|
uint32_t length;
|
||||||
uint32_t crc;
|
uint32_t crc;
|
||||||
size_t remainingSize;
|
// size_t remainingSize;
|
||||||
size_t bytesWritten;
|
size_t bytesWritten;
|
||||||
uint32_t packetNum;
|
uint32_t packetNum;
|
||||||
uint16_t sequenceCount;
|
uint16_t sequenceCount;
|
||||||
|
Loading…
Reference in New Issue
Block a user