26 m_sortedDpList(nullptr),
34 m_xmitInProgress(false),
35 m_currXmitRecord(nullptr),
59 this->m_memSize =
DP_MAX_FILES * (
sizeof(DpStateEntry) +
sizeof(DpSortedList));
62 this->m_memPtr = allocator.
allocate(memId, this->m_memSize, notUsed);
67 (this->m_memSize >= (
sizeof(DpSortedList) +
sizeof(DpStateEntry))) and
68 (this->m_memPtr !=
nullptr)
71 this->m_numDpSlots = this->m_memSize / (
sizeof(DpSortedList) +
sizeof(DpStateEntry));
74 this->m_dpList =
static_cast<DpStateEntry*
>(this->m_memPtr);
76 this->m_sortedDpList =
reinterpret_cast<DpSortedList*
>(&this->m_dpList[this->m_numDpSlots]);
77 for (
FwSizeType slot = 0; slot < this->m_numDpSlots; slot++) {
79 (void)
new(&this->m_dpList[slot]) DpStateEntry();
80 this->m_dpList[slot].entry =
false;
81 this->m_dpList[slot].dir = -1;
83 this->m_sortedDpList[slot].recPtr =
nullptr;
84 this->m_sortedDpList[slot].sent =
false;
90 this->m_numDpSlots = 0;
94 for (
FwSizeType dir = 0; dir < numDirs; dir++) {
95 this->m_directories[dir] = directories[dir];
97 this->m_numDirectories = numDirs;
100 this->m_allocator = &allocator;
101 this->m_allocatorId = memId;
102 this->m_initialized =
true;
108 if (not this->checkInit()) {
113 if (this->m_xmitInProgress) {
129 for (
FwSizeType dir = 0; dir < this->m_numDirectories; dir++) {
133 U32 pendingFiles = 0;
134 U64 pendingDpBytes = 0;
138 this->m_directories[dir].toChar(),
139 static_cast<U32
>(this->m_numDpSlots - totalFiles),
145 this->m_directories[dir],
153 filesRead <= this->m_numDpSlots - totalFiles,
161 this->m_directories[dir].toChar(),
162 this->m_fileList[file].toChar()
184 stat = dpFile.
read(dpBuff, size);
213 entry.record.setid(container.
getId());
215 entry.record.setstate(container.
getState());
218 entry.record.setsize(
static_cast<U64>(fileSize));
222 this->m_dpList[this->m_numDpRecords] = entry;
225 if (not this->insertEntry(this->m_dpList[this->m_numDpRecords])) {
232 pendingDpBytes += entry.record.getsize();
236 if (this->m_numDpRecords > this->m_numDpSlots) {
243 totalFiles += filesRead;
246 this->m_directories[dir],
247 static_cast<U32
>(totalFiles),
254 if (totalFiles == this->m_numDpSlots) {
265 bool DpCatalog::insertEntry(DpStateEntry& entry) {
268 this->m_sortedDpList[this->m_numDpRecords].recPtr = &entry;
269 this->m_sortedDpList[this->m_numDpRecords].sent =
false;
270 this->m_numDpRecords++;
276 void DpCatalog::deleteEntry(DpStateEntry& entry) {
280 void DpCatalog::sendNextEntry() {
286 for (
FwSizeType record = 0; record < this->m_numDpRecords; record++) {
287 if (not this->m_sortedDpList[record].sent) {
289 if (this->m_sortedDpList[record].recPtr !=
nullptr) {
291 this->m_currXmitRecord = &this->m_sortedDpList[record];
294 this->m_directories[this->m_sortedDpList[record].recPtr->dir].toChar(),
295 this->m_sortedDpList[record].recPtr->record.getid(),
296 this->m_sortedDpList[record].recPtr->record.gettSec(),
297 this->m_sortedDpList[record].recPtr->record.gettSub()
300 this->m_currXmitFileName,
301 static_cast<U32
>(this->m_sortedDpList[record].recPtr->record.getsize()),
302 this->m_sortedDpList[record].recPtr->record.getpriority()
304 this->
fileOut_out(0, this->m_currXmitFileName, this->m_currXmitFileName, 0, 0);
305 this->m_xmitBytes += this->m_sortedDpList[record].recPtr->record.getsize();
310 this->m_sortedDpList[record].sent =
true;
316 this->m_xmitInProgress =
false;
317 this->m_xmitBytes = 0;
318 this->m_currXmitRecord =
nullptr;
320 if (this->m_xmitCmdWait) {
321 this->m_xmitCmdWait =
false;
327 bool DpCatalog::checkInit() {
328 if (not this->m_initialized) {
332 else if (0 == this->m_numDpSlots) {
344 if ((this->m_allocator !=
nullptr) and (this->m_memPtr !=
nullptr)) {
345 this->m_allocator->
deallocate(this->m_allocatorId, this->m_memPtr);
361 if (this->m_currXmitRecord) {
362 this->m_currXmitRecord->sent =
true;
366 this->sendNextEntry();
384 BUILD_CATALOG_cmdHandler(
394 START_XMIT_CATALOG_cmdHandler(
405 this->m_xmitCmdWait =
false;
406 this->m_xmitOpCode = 0;
407 this->m_xmitCmdSeq = 0;
410 this->m_xmitCmdWait =
true;
411 this->m_xmitOpCode = opCode;
412 this->m_xmitCmdSeq = cmdSeq;
419 this->m_xmitBytes = 0;
420 this->sendNextEntry();
427 STOP_XMIT_CATALOG_cmdHandler(
437 CLEAR_CATALOG_cmdHandler(
PlatformIntType NATIVE_INT_TYPE
uint8_t U8
8-bit unsigned integer
PlatformUIntType NATIVE_UINT_TYPE
constexpr const char * DP_FILENAME_FORMAT
PlatformAssertArgType FwAssertArgType
PlatformUIntType FwNativeUIntType
PlatformSignedSizeType FwSignedSizeType
PlatformSizeType FwSizeType
PlatformIndexType FwIndexType
C++-compatible configuration header for fprime configuration.
Enum representing a command response.
@ EXECUTION_ERROR
Command had execution error.
@ OK
Command successfully executed.
A data product Container.
Fw::Time getTimeTag() const
static constexpr FwSizeType MIN_PACKET_SIZE
FwDpPriorityType getPriority() const
Fw::DpState getState() const
Get the product state.
Fw::SerializeStatus deserializeHeader()
void setBuffer(const Buffer &buffer)
Set the packet buffer.
@ UNTRANSMITTED
The untransmitted state.
virtual void deallocate(const NATIVE_UINT_TYPE identifier, void *ptr)=0
Deallocate memory.
virtual void * allocate(const NATIVE_UINT_TYPE identifier, NATIVE_UINT_TYPE &size, bool &recoverable)=0
Allocate memory.
void format(const CHAR *formatString,...)
write formatted string to buffer
const char * toChar() const
Wait or don't wait for something.
Status read(U8 *buffer, FwSignedSizeType &size)
read data from this file into supplied buffer bounded by size
void close() override
close the file, if not opened then do nothing
Os::FileInterface::Status open(const char *path, Mode mode)
open file with supplied path and mode
@ BAD_SIZE
Invalid size parameter.
@ OP_OK
Operation was successful.
@ OPEN_READ
Open file for reading.
Auto-generated base for DpCatalog component.
Svc::SendFileResponse fileOut_out(FwIndexType portNum, const Fw::StringBase &sourceFileName, const Fw::StringBase &destFileName, U32 offset, U32 length)
Invoke output port fileOut.
void log_WARNING_LO_DpXmitInProgress()
void cmdResponse_out(FwOpcodeType opCode, U32 cmdSeq, Fw::CmdResponse response)
Emit command response.
void log_WARNING_HI_FileOpenError(const Fw::StringBase &loc, I32 stat)
void log_ACTIVITY_HI_ProcessingDirectoryComplete(const Fw::StringBase &loc, U32 total, U32 pending, U64 pending_bytes)
void log_ACTIVITY_LO_SendingProduct(const Fw::StringBase &file, U32 bytes, U32 prio)
void log_WARNING_HI_DirectoryOpenError(const Fw::StringBase &loc, I32 stat)
void log_ACTIVITY_LO_ProcessingFile(const Fw::StringBase &file)
void log_ACTIVITY_LO_ProcessingDirectory(const Fw::StringBase &directory)
void log_ACTIVITY_HI_CatalogBuildComplete()
void log_WARNING_HI_DpInsertError(Svc::DpRecord dp)
void log_WARNING_HI_ComponentNotInitialized()
void log_WARNING_HI_FileReadError(const Fw::StringBase &file, I32 stat)
void log_WARNING_HI_ComponentNoMemory()
void pingOut_out(FwIndexType portNum, U32 key)
Invoke output port pingOut.
void log_WARNING_HI_FileSizeError(const Fw::StringBase &file, I32 stat)
void log_WARNING_HI_CatalogFull(const Fw::StringBase &dir)
void log_WARNING_HI_DpCatalogFull(Svc::DpRecord dp)
void log_WARNING_HI_FileHdrDesError(const Fw::StringBase &file, I32 stat)
void log_ACTIVITY_HI_CatalogXmitCompleted(U64 bytes)
void log_ACTIVITY_LO_ProductComplete(const Fw::StringBase &file)
void configure(Fw::FileNameString directories[DP_MAX_DIRECTORIES], FwSizeType numDirs, NATIVE_UINT_TYPE memId, Fw::MemAllocator &allocator)
Configure the DpCatalog.
DpCatalog(const char *const compName)
DpCatalog constructor.
~DpCatalog()
DpCatalog destructor.
Send file response struct.
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.
Status getFileSize(const char *path, FwSizeType &size)
@ OP_OK
Operation was successful.
Status readDirectory(const char *path, const U32 maxNum, Fw::String fileArray[], U32 &numFiles)
read the contents of a directory. Size of fileArray should be maxNum. Cleaner implementation found in...
static const FwSizeType DP_MAX_FILES
static const FwSizeType DP_MAX_DIRECTORIES