eive-obsw/linux/devices/ploc/PlocSupvHelper.cpp

563 lines
18 KiB
C++
Raw Normal View History

2022-04-06 08:36:34 +02:00
#include "PlocSupvHelper.h"
#include <filesystem>
#include <fstream>
#include "OBSWConfig.h"
#ifdef XIPHOS_Q7S
#include "bsp_q7s/memory/FilesystemHelper.h"
2022-04-22 14:16:40 +02:00
#include "bsp_q7s/memory/SdCardManager.h"
2022-04-06 08:36:34 +02:00
#endif
2022-04-10 18:46:39 +02:00
#include "fsfw/globalfunctions/CRC.h"
#include "fsfw/tasks/TaskFactory.h"
2022-05-13 18:37:16 +02:00
#include "fsfw/timemanager/Countdown.h"
2022-04-14 07:52:21 +02:00
#include "mission/utility/Filenaming.h"
#include "mission/utility/ProgressPrinter.h"
#include "mission/utility/Timestamp.h"
2022-04-06 08:36:34 +02:00
PlocSupvHelper::PlocSupvHelper(object_id_t objectId) : SystemObject(objectId) {}
PlocSupvHelper::~PlocSupvHelper() {}
ReturnValue_t PlocSupvHelper::initialize() {
#ifdef XIPHOS_Q7S
sdcMan = SdCardManager::instance();
if (sdcMan == nullptr) {
sif::warning << "PlocSupvHelper::initialize: Invalid SD Card Manager" << std::endl;
return RETURN_FAILED;
}
#endif
return RETURN_OK;
}
ReturnValue_t PlocSupvHelper::performOperation(uint8_t operationCode) {
ReturnValue_t result = RETURN_OK;
semaphore.acquire();
while (true) {
switch (internalState) {
case InternalState::IDLE: {
semaphore.acquire();
break;
}
2022-04-07 11:00:07 +02:00
case InternalState::UPDATE: {
2022-04-06 08:36:34 +02:00
result = performUpdate();
if (result == RETURN_OK) {
2022-04-13 11:56:37 +02:00
triggerEvent(SUPV_UPDATE_SUCCESSFUL, result);
} else if (result == PROCESS_TERMINATED) {
// Event already triggered
2022-04-06 08:36:34 +02:00
} else {
2022-04-13 11:56:37 +02:00
triggerEvent(SUPV_UPDATE_FAILED, result);
}
internalState = InternalState::IDLE;
break;
}
2022-05-23 12:05:42 +02:00
case InternalState::CONTINUE_UPDATE: {
result = continueUpdate();
if (result == RETURN_OK) {
triggerEvent(SUPV_CONTINUE_UPDATE_SUCCESSFUL, result);
} else if (result == PROCESS_TERMINATED) {
// Event already triggered
} else {
triggerEvent(SUPV_CONTINUE_UPDATE_FAILED, result);
}
internalState = InternalState::IDLE;
break;
}
2022-04-13 11:56:37 +02:00
case InternalState::REQUEST_EVENT_BUFFER: {
result = performEventBufferRequest();
if (result == RETURN_OK) {
triggerEvent(SUPV_EVENT_BUFFER_REQUEST_SUCCESSFUL, result);
} else if (result == PROCESS_TERMINATED) {
// Event already triggered
break;
} else {
2022-04-13 11:56:37 +02:00
triggerEvent(SUPV_EVENT_BUFFER_REQUEST_FAILED, result);
2022-04-06 08:36:34 +02:00
}
internalState = InternalState::IDLE;
break;
}
default:
sif::debug << "PlocSupvHelper::performOperation: Invalid state" << std::endl;
break;
}
}
}
2022-04-10 18:46:39 +02:00
ReturnValue_t PlocSupvHelper::setComIF(UartComIF* uartComIF_) {
if (uartComIF_ == nullptr) {
sif::warning << "PlocSupvHelper::initialize: Provided invalid uart com if" << std::endl;
2022-04-06 08:36:34 +02:00
return RETURN_FAILED;
}
2022-04-10 18:46:39 +02:00
uartComIF = uartComIF_;
2022-04-06 08:36:34 +02:00
return RETURN_OK;
}
void PlocSupvHelper::setComCookie(CookieIF* comCookie_) { comCookie = comCookie_; }
2022-04-07 11:00:07 +02:00
ReturnValue_t PlocSupvHelper::startUpdate(std::string file, uint8_t memoryId,
uint32_t startAddress) {
2022-04-06 08:36:34 +02:00
ReturnValue_t result = RETURN_OK;
#ifdef XIPHOS_Q7S
2022-04-07 11:00:07 +02:00
result = FilesystemHelper::checkPath(file);
2022-04-06 08:36:34 +02:00
if (result != RETURN_OK) {
2022-04-10 18:46:39 +02:00
sif::warning << "PlocSupvHelper::startUpdate: File " << file << " does not exist" << std::endl;
2022-04-06 08:36:34 +02:00
return result;
}
result = FilesystemHelper::fileExists(file);
2022-04-10 18:46:39 +02:00
if (result != RETURN_OK) {
sif::warning << "PlocSupvHelper::startUpdate: The file " << file << " does not exist"
<< std::endl;
return result;
2022-04-10 18:46:39 +02:00
}
#endif
#ifdef TE0720_1CFA
if (not std::filesystem::exists(file)) {
sif::warning << "PlocSupvHelper::startUpdate: The file " << file << " does not exist"
<< std::endl;
return RETURN_FAILED;
}
2022-04-06 08:36:34 +02:00
#endif
2022-04-07 11:00:07 +02:00
update.file = file;
2022-04-10 18:46:39 +02:00
update.length = getFileSize(update.file);
2022-04-07 11:00:07 +02:00
update.memoryId = memoryId;
update.startAddress = startAddress;
2022-05-23 12:05:42 +02:00
update.remainingSize = update.length;
update.bytesWritten = 0;
update.packetNum = 1;
update.sequenceCount = 1;
2022-04-07 11:00:07 +02:00
internalState = InternalState::UPDATE;
2022-04-10 18:46:39 +02:00
uartComIF->flushUartTxAndRxBuf(comCookie);
semaphore.release();
2022-04-06 08:36:34 +02:00
return result;
}
2022-05-23 12:05:42 +02:00
void PlocSupvHelper::initiateUpdateContinuation() {
internalState = InternalState::CONTINUE_UPDATE;
semaphore.release();
}
2022-04-13 11:56:37 +02:00
ReturnValue_t PlocSupvHelper::startEventbBufferRequest(std::string path) {
#ifdef XIPHOS_Q7S
ReturnValue_t result = FilesystemHelper::checkPath(path);
if (result != RETURN_OK) {
return result;
}
#endif
if (not std::filesystem::exists(path)) {
return PATH_NOT_EXISTS;
}
eventBufferReq.path = path;
internalState = InternalState::REQUEST_EVENT_BUFFER;
uartComIF->flushUartTxAndRxBuf(comCookie);
semaphore.release();
return RETURN_OK;
}
2022-04-06 08:36:34 +02:00
void PlocSupvHelper::stopProcess() { terminate = true; }
ReturnValue_t PlocSupvHelper::performUpdate() {
ReturnValue_t result = RETURN_OK;
2022-04-19 13:33:37 +02:00
result = calcImageCrc();
if (result != RETURN_OK) {
return result;
}
2022-05-23 12:05:42 +02:00
result = selectMemory();
if (result != RETURN_OK) {
return result;
}
2022-04-10 18:46:39 +02:00
result = prepareUpdate();
if (result != RETURN_OK) {
return result;
}
2022-04-06 08:36:34 +02:00
result = eraseMemory();
if (result != RETURN_OK) {
return result;
}
2022-05-23 12:05:42 +02:00
result = writeUpdatePackets();
if (result != RETURN_OK) {
return result;
}
result = handleCheckMemoryCommand();
if (result != RETURN_OK) {
return result;
}
return result;
}
ReturnValue_t PlocSupvHelper::continueUpdate() {
ReturnValue_t result = prepareUpdate();
if (result != RETURN_OK) {
return result;
}
result = writeUpdatePackets();
if (result != RETURN_OK) {
return result;
}
result = handleCheckMemoryCommand();
if (result != RETURN_OK) {
return result;
}
return result;
}
ReturnValue_t PlocSupvHelper::writeUpdatePackets() {
ReturnValue_t result = RETURN_OK;
#if OBSW_DEBUG_PLOC_SUPERVISOR == 1
ProgressPrinter progressPrinter("Supervisor update", update.length,
ProgressPrinter::HALF_PERCENT);
#endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */
2022-04-10 18:46:39 +02:00
uint8_t tempData[supv::WriteMemory::CHUNK_MAX];
2022-04-06 08:36:34 +02:00
std::ifstream file(update.file, std::ifstream::binary);
2022-04-10 18:46:39 +02:00
uint16_t dataLength = 0;
2022-05-23 12:05:42 +02:00
supv::SequenceFlags seqFlags;
while (update.remainingSize > 0) {
2022-04-06 08:36:34 +02:00
if (terminate) {
terminate = false;
2022-05-13 18:37:16 +02:00
triggerEvent(TERMINATED_UPDATE_PROCEDURE);
2022-04-10 18:46:39 +02:00
return PROCESS_TERMINATED;
2022-04-06 08:36:34 +02:00
}
2022-05-23 12:05:42 +02:00
if (update.remainingSize > supv::WriteMemory::CHUNK_MAX) {
2022-04-10 18:46:39 +02:00
dataLength = supv::WriteMemory::CHUNK_MAX;
2022-04-06 08:36:34 +02:00
} else {
2022-05-23 12:05:42 +02:00
dataLength = static_cast<uint16_t>(update.remainingSize);
2022-04-06 08:36:34 +02:00
}
if (file.is_open()) {
2022-05-23 12:05:42 +02:00
file.seekg(update.bytesWritten, file.beg);
2022-04-06 08:36:34 +02:00
file.read(reinterpret_cast<char*>(tempData), dataLength);
2022-04-19 13:33:37 +02:00
if (!file) {
sif::warning << "PlocSupvHelper::performUpdate: Read only " << file.gcount() << " of "
<< dataLength << " bytes" << std::endl;
2022-04-19 13:33:37 +02:00
sif::info << "PlocSupvHelper::performUpdate: Failed when trying to read byte "
2022-05-23 12:05:42 +02:00
<< update.bytesWritten << std::endl;
2022-04-19 13:33:37 +02:00
}
2022-04-06 08:36:34 +02:00
} else {
return FILE_CLOSED_ACCIDENTALLY;
}
2022-05-23 12:05:42 +02:00
if (update.bytesWritten == 0) {
2022-04-10 18:46:39 +02:00
seqFlags = supv::SequenceFlags::FIRST_PKT;
2022-05-23 12:05:42 +02:00
} else if (update.remainingSize == 0) {
2022-04-10 18:46:39 +02:00
seqFlags = supv::SequenceFlags::LAST_PKT;
} else {
seqFlags = supv::SequenceFlags::CONTINUED_PKT;
}
2022-05-23 12:05:42 +02:00
supv::WriteMemory packet(seqFlags, update.sequenceCount++, update.memoryId,
update.startAddress + update.bytesWritten, dataLength, tempData);
2022-04-10 18:46:39 +02:00
result = handlePacketTransmission(packet);
2022-04-06 08:36:34 +02:00
if (result != RETURN_OK) {
2022-05-23 12:05:42 +02:00
update.sequenceCount--;
triggerEvent(WRITE_MEMORY_FAILED, update.packetNum);
2022-04-06 08:36:34 +02:00
return result;
}
2022-05-23 12:05:42 +02:00
update.remainingSize -= dataLength;
update.packetNum += 1;
update.bytesWritten += dataLength;
#if OBSW_DEBUG_PLOC_SUPERVISOR == 1
2022-05-23 12:05:42 +02:00
progressPrinter.print(update.bytesWritten);
#endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */
2022-04-17 14:52:43 +02:00
}
2022-04-06 08:36:34 +02:00
return result;
}
2022-04-13 11:56:37 +02:00
ReturnValue_t PlocSupvHelper::performEventBufferRequest() {
using namespace supv;
2022-04-14 07:52:21 +02:00
ReturnValue_t result = RETURN_OK;
2022-04-13 11:56:37 +02:00
RequestLoggingData packet(RequestLoggingData::Sa::REQUEST_EVENT_BUFFERS);
result = sendCommand(packet);
if (result != RETURN_OK) {
return result;
}
result = handleAck();
if (result != RETURN_OK) {
return result;
}
result = handleEventBufferReception();
if (result != RETURN_OK) {
return result;
}
result = handleExe();
if (result != RETURN_OK) {
return result;
}
2022-04-14 07:52:21 +02:00
return result;
2022-04-13 11:56:37 +02:00
}
2022-05-23 12:05:42 +02:00
ReturnValue_t PlocSupvHelper::selectMemory() {
ReturnValue_t result = RETURN_OK;
supv::MPSoCBootSelect packet(update.memoryId);
result = handlePacketTransmission(packet);
if (result != RETURN_OK) {
return result;
}
return RETURN_OK;
}
2022-04-10 18:46:39 +02:00
ReturnValue_t PlocSupvHelper::prepareUpdate() {
2022-04-06 08:36:34 +02:00
ReturnValue_t result = RETURN_OK;
2022-04-10 18:46:39 +02:00
supv::ApidOnlyPacket packet(supv::APID_PREPARE_UPDATE);
result = handlePacketTransmission(packet, PREPARE_UPDATE_EXECUTION_REPORT);
2022-04-06 08:36:34 +02:00
if (result != RETURN_OK) {
return result;
}
return RETURN_OK;
}
2022-04-10 18:46:39 +02:00
ReturnValue_t PlocSupvHelper::eraseMemory() {
2022-04-06 08:36:34 +02:00
ReturnValue_t result = RETURN_OK;
2022-04-10 18:46:39 +02:00
supv::EraseMemory eraseMemory(update.memoryId, update.startAddress, update.length);
2022-04-19 13:33:37 +02:00
result = handlePacketTransmission(eraseMemory, supv::recv_timeout::ERASE_MEMORY);
2022-04-06 08:36:34 +02:00
if (result != RETURN_OK) {
return result;
}
return RETURN_OK;
}
2022-04-19 13:33:37 +02:00
ReturnValue_t PlocSupvHelper::handlePacketTransmission(SpacePacket& packet,
uint32_t timeoutExecutionReport) {
2022-04-06 08:36:34 +02:00
ReturnValue_t result = RETURN_OK;
2022-04-10 18:46:39 +02:00
result = sendCommand(packet);
2022-04-06 08:36:34 +02:00
if (result != RETURN_OK) {
return result;
}
result = handleAck();
if (result != RETURN_OK) {
return result;
}
2022-04-19 13:33:37 +02:00
result = handleExe(timeoutExecutionReport);
2022-04-06 08:36:34 +02:00
if (result != RETURN_OK) {
return result;
}
return RETURN_OK;
}
2022-04-10 18:46:39 +02:00
ReturnValue_t PlocSupvHelper::sendCommand(SpacePacket& packet) {
2022-04-06 08:36:34 +02:00
ReturnValue_t result = RETURN_OK;
2022-04-17 14:52:43 +02:00
rememberApid = packet.getAPID();
2022-04-10 18:46:39 +02:00
result = uartComIF->sendMessage(comCookie, packet.getWholeData(), packet.getFullSize());
2022-04-06 08:36:34 +02:00
if (result != RETURN_OK) {
sif::warning << "PlocSupvHelper::sendCommand: Failed to send command" << std::endl;
2022-04-10 18:46:39 +02:00
triggerEvent(SUPV_SENDING_COMMAND_FAILED, result, static_cast<uint32_t>(internalState));
2022-04-06 08:36:34 +02:00
return result;
}
return result;
}
ReturnValue_t PlocSupvHelper::handleAck() {
ReturnValue_t result = RETURN_OK;
supv::AcknowledgmentReport ackReport;
result = handleTmReception(&ackReport, supv::SIZE_ACK_REPORT);
2022-04-06 08:36:34 +02:00
if (result != RETURN_OK) {
2022-04-17 14:52:43 +02:00
triggerEvent(ACK_RECEPTION_FAILURE, result, static_cast<uint32_t>(rememberApid));
2022-04-10 18:46:39 +02:00
sif::warning << "PlocSupvHelper::handleAck: Error in reception of acknowledgment report"
<< std::endl;
2022-04-06 08:36:34 +02:00
return result;
}
result = ackReport.checkApid();
if (result != RETURN_OK) {
if (result == SupvReturnValuesIF::RECEIVED_ACK_FAILURE) {
triggerEvent(SUPV_ACK_FAILURE_REPORT, static_cast<uint32_t>(ackReport.getRefApid()));
} else if (result == SupvReturnValuesIF::INVALID_APID) {
triggerEvent(SUPV_ACK_INVALID_APID, static_cast<uint32_t>(rememberApid));
}
return result;
2022-04-06 08:36:34 +02:00
}
return RETURN_OK;
}
2022-04-19 13:33:37 +02:00
ReturnValue_t PlocSupvHelper::handleExe(uint32_t timeout) {
2022-04-06 08:36:34 +02:00
ReturnValue_t result = RETURN_OK;
supv::ExecutionReport exeReport;
result = handleTmReception(&exeReport, supv::SIZE_EXE_REPORT, timeout);
2022-04-06 08:36:34 +02:00
if (result != RETURN_OK) {
2022-04-17 14:52:43 +02:00
triggerEvent(EXE_RECEPTION_FAILURE, result, static_cast<uint32_t>(rememberApid));
2022-04-10 18:46:39 +02:00
sif::warning << "PlocSupvHelper::handleExe: Error in reception of execution report"
<< std::endl;
2022-04-06 08:36:34 +02:00
return result;
}
result = exeReport.checkApid();
if (result != RETURN_OK) {
if (result == SupvReturnValuesIF::RECEIVED_EXE_FAILURE) {
triggerEvent(SUPV_EXE_FAILURE_REPORT, static_cast<uint32_t>(exeReport.getRefApid()));
} else if (result == SupvReturnValuesIF::INVALID_APID) {
triggerEvent(SUPV_EXE_INVALID_APID, static_cast<uint32_t>(rememberApid));
}
return result;
2022-04-06 08:36:34 +02:00
}
return RETURN_OK;
}
2022-04-19 13:33:37 +02:00
ReturnValue_t PlocSupvHelper::handleTmReception(supv::TmPacket* tmPacket, size_t remainingBytes,
uint32_t timeout) {
2022-04-06 08:36:34 +02:00
ReturnValue_t result = RETURN_OK;
size_t readBytes = 0;
size_t currentBytes = 0;
2022-04-19 13:33:37 +02:00
Countdown countdown(timeout);
while (!countdown.hasTimedOut()) {
2022-04-06 08:36:34 +02:00
result = receive(tmPacket->getWholeData() + readBytes, &currentBytes, remainingBytes);
if (result != RETURN_OK) {
return result;
}
readBytes += currentBytes;
remainingBytes = remainingBytes - currentBytes;
if (remainingBytes == 0) {
break;
}
}
if (remainingBytes != 0) {
sif::warning << "PlocSupvHelper::handleTmReception: Failed to read " << std::dec
<< remainingBytes << " bytes" << std::endl;
2022-04-06 08:36:34 +02:00
return RETURN_FAILED;
}
result = tmPacket->checkCrc();
if (result != RETURN_OK) {
sif::warning << "PlocSupvHelper::handleTmReception: CRC check failed" << std::endl;
return result;
}
return result;
}
ReturnValue_t PlocSupvHelper::receive(uint8_t* data, size_t* readBytes, size_t requestBytes) {
ReturnValue_t result = RETURN_OK;
uint8_t* buffer = nullptr;
result = uartComIF->requestReceiveMessage(comCookie, requestBytes);
if (result != RETURN_OK) {
sif::warning << "PlocSupvHelper::receive: Failed to request reply" << std::endl;
2022-04-10 18:46:39 +02:00
triggerEvent(SUPV_HELPER_REQUESTING_REPLY_FAILED, result,
2022-04-06 08:36:34 +02:00
static_cast<uint32_t>(static_cast<uint32_t>(internalState)));
return RETURN_FAILED;
}
result = uartComIF->readReceivedMessage(comCookie, &buffer, readBytes);
if (result != RETURN_OK) {
sif::warning << "PlocSupvHelper::receive: Failed to read received message" << std::endl;
2022-04-10 18:46:39 +02:00
triggerEvent(SUPV_HELPER_READING_REPLY_FAILED, result, static_cast<uint32_t>(internalState));
2022-04-06 08:36:34 +02:00
return RETURN_FAILED;
}
if (*readBytes > 0) {
std::memcpy(data, buffer, *readBytes);
2022-05-13 18:37:16 +02:00
} else {
TaskFactory::delayTask(40);
}
2022-04-06 08:36:34 +02:00
return result;
}
2022-04-10 18:46:39 +02:00
ReturnValue_t PlocSupvHelper::calcImageCrc() {
ReturnValue_t result = RETURN_OK;
#ifdef XIPHOS_Q7S
result = FilesystemHelper::checkPath(update.file);
#endif
if (result != RETURN_OK) {
sif::warning << "PlocSupvHelper::calcImageCrc: File " << update.file << " does not exist"
<< std::endl;
return result;
}
std::ifstream file(update.file, std::ifstream::binary);
uint16_t remainder = CRC16_INIT;
uint8_t input;
2022-04-19 13:33:37 +02:00
#if OBSW_DEBUG_PLOC_SUPERVISOR == 1
ProgressPrinter progress("Supervisor update crc calculation", update.length,
ProgressPrinter::ONE_PERCENT);
2022-04-19 13:33:37 +02:00
#endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */
uint32_t byteCount = 0;
for (byteCount = 0; byteCount < update.length; byteCount++) {
2022-04-10 18:46:39 +02:00
file.seekg(byteCount, file.beg);
file.read(reinterpret_cast<char*>(&input), 1);
remainder = CRC::crc16ccitt(&input, sizeof(input), remainder);
2022-04-19 13:33:37 +02:00
#if OBSW_DEBUG_PLOC_SUPERVISOR == 1
progress.print(byteCount);
#endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */
2022-04-10 18:46:39 +02:00
}
2022-04-19 13:33:37 +02:00
#if OBSW_DEBUG_PLOC_SUPERVISOR == 1
progress.print(byteCount);
#endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */
2022-04-10 18:46:39 +02:00
file.close();
update.crc = remainder;
return result;
}
ReturnValue_t PlocSupvHelper::handleCheckMemoryCommand() {
ReturnValue_t result = RETURN_OK;
// Verification of update write procedure
supv::CheckMemory packet(update.memoryId, update.startAddress, update.length);
result = sendCommand(packet);
if (result != RETURN_OK) {
return result;
}
result = handleAck();
if (result != RETURN_OK) {
return result;
}
supv::UpdateStatusReport updateStatusReport;
result = handleTmReception(&updateStatusReport,
2022-04-19 13:33:37 +02:00
static_cast<size_t>(updateStatusReport.getNominalSize()),
supv::recv_timeout::UPDATE_STATUS_REPORT);
2022-04-10 18:46:39 +02:00
if (result != RETURN_OK) {
sif::warning
<< "PlocSupvHelper::handleCheckMemoryCommand: Failed to receive update status report"
<< std::endl;
2022-04-10 18:46:39 +02:00
return result;
}
result = handleExe(CRC_EXECUTION_TIMEOUT);
2022-04-10 18:46:39 +02:00
if (result != RETURN_OK) {
return result;
}
result = updateStatusReport.parseDataField();
if (result != RETURN_OK) {
return result;
}
result = updateStatusReport.verifycrc(update.crc);
if (result != RETURN_OK) {
2022-04-24 12:34:08 +02:00
sif::warning << "PlocSupvHelper::handleCheckMemoryCommand: CRC failure. Expected CRC 0x"
<< std::hex << update.crc << " but received CRC 0x" << updateStatusReport.getCrc()
2022-04-10 18:46:39 +02:00
<< std::endl;
return result;
}
return result;
}
uint32_t PlocSupvHelper::getFileSize(std::string filename) {
std::ifstream file(filename, std::ifstream::binary);
file.seekg(0, file.end);
uint32_t size = file.tellg();
file.close();
return size;
2022-04-10 18:46:39 +02:00
}
2022-04-13 11:56:37 +02:00
ReturnValue_t PlocSupvHelper::handleEventBufferReception() {
2022-04-14 07:52:21 +02:00
ReturnValue_t result = RETURN_OK;
std::string filename = Filenaming::generateAbsoluteFilename(
eventBufferReq.path, eventBufferReq.filename, timestamping);
2022-04-13 11:56:37 +02:00
std::ofstream file(filename, std::ios_base::app | std::ios_base::out);
uint32_t packetsRead = 0;
2022-04-14 07:52:21 +02:00
size_t requestLen = 0;
2022-04-13 11:56:37 +02:00
supv::TmPacket tmPacket;
2022-04-14 07:52:21 +02:00
for (packetsRead = 0; packetsRead < NUM_EVENT_BUFFER_PACKETS; packetsRead++) {
2022-04-13 11:56:37 +02:00
if (terminate) {
triggerEvent(SUPV_EVENT_BUFFER_REQUEST_TERMINATED, packetsRead - 1);
file.close();
return PROCESS_TERMINATED;
}
2022-04-14 07:52:21 +02:00
if (packetsRead == NUM_EVENT_BUFFER_PACKETS - 1) {
requestLen = SIZE_EVENT_BUFFER_LAST_PACKET;
} else {
requestLen = SIZE_EVENT_BUFFER_FULL_PACKET;
}
result = handleTmReception(&tmPacket, requestLen);
2022-04-13 11:56:37 +02:00
if (result != RETURN_OK) {
2022-04-14 07:52:21 +02:00
sif::debug << "PlocSupvHelper::handleEventBufferReception: Failed while trying to read packet"
<< " " << packetsRead + 1 << std::endl;
2022-04-14 07:52:21 +02:00
file.close();
2022-04-13 11:56:37 +02:00
return result;
}
uint16_t apid = tmPacket.getAPID();
if (apid != supv::APID_MRAM_DUMP_TM) {
sif::warning << "PlocSupvHelper::handleEventBufferReception: Did not expect space packet "
2022-04-14 07:52:21 +02:00
<< "with APID 0x" << std::hex << apid << std::endl;
file.close();
return EVENT_BUFFER_REPLY_INVALID_APID;
2022-04-13 11:56:37 +02:00
}
2022-04-14 07:52:21 +02:00
file.write(reinterpret_cast<const char*>(tmPacket.getPacketData()),
tmPacket.getPayloadDataLength());
2022-04-13 11:56:37 +02:00
}
2022-04-14 07:52:21 +02:00
return result;
2022-04-13 11:56:37 +02:00
}