@@ -42,7 +42,9 @@ DpCatalog ::DpCatalog(const char* const compName)
4242 m_xmitCmdWait(false ),
4343 m_xmitBytes(0 ),
4444 m_xmitOpCode(0 ),
45- m_xmitCmdSeq(0 ) {}
45+ m_xmitCmdSeq(0 ),
46+ m_pendingFiles(0 ),
47+ m_pendingDpBytes(0 ) {}
4648
4749DpCatalog ::~DpCatalog () {}
4850
@@ -386,20 +388,13 @@ Fw::CmdResponse DpCatalog::fillBinaryTree() {
386388 // keep cumulative number of files
387389 FwSizeType totalFiles = 0 ;
388390
389- // file class instance for processing files
390- Os::File dpFile;
391- // Working buffer for DP headers
392- U8 dpBuff[Fw::DpContainer::MIN_PACKET_SIZE]; // Header buffer
393- Fw::Buffer hdrBuff (dpBuff, sizeof (dpBuff)); // buffer for container header decoding
394- Fw::DpContainer container; // container object for extracting header fields
395-
396391 // get file listings from file system
397392 for (FwSizeType dir = 0 ; dir < this ->m_numDirectories ; dir++) {
398393 // read in each directory and keep track of total
399394 this ->log_ACTIVITY_LO_ProcessingDirectory (this ->m_directories [dir]);
400395 FwSizeType filesRead = 0 ;
401- U32 pendingFiles = 0 ;
402- U64 pendingDpBytes = 0 ;
396+ m_pendingFiles = 0 ;
397+ m_pendingDpBytes = 0 ;
403398 U32 filesProcessed = 0 ;
404399
405400 Os::Directory dpDir;
@@ -434,93 +429,19 @@ Fw::CmdResponse DpCatalog::fillBinaryTree() {
434429 Fw::String fullFile;
435430 fullFile.format (" %s/%s" , this ->m_directories [dir].toChar (), this ->m_fileList [file].toChar ());
436431
437- this ->log_ACTIVITY_LO_ProcessingFile (fullFile);
438-
439- // get file size
440- FwSizeType fileSize = 0 ;
441- Os::FileSystem::Status sizeStat = Os::FileSystem::getFileSize (fullFile.toChar (), fileSize);
442- if (sizeStat != Os::FileSystem::OP_OK) {
443- this ->log_WARNING_HI_FileSizeError (fullFile, sizeStat);
444- continue ;
445- }
446-
447- Os::File::Status stat = dpFile.open (fullFile.toChar (), Os::File::OPEN_READ);
448- if (stat != Os::File::OP_OK) {
449- this ->log_WARNING_HI_FileOpenError (fullFile, stat);
450- continue ;
451- }
452-
453- // Read DP header
454- FwSizeType size = Fw::DpContainer::Header::SIZE;
455-
456- stat = dpFile.read (dpBuff, size);
457- if (stat != Os::File::OP_OK) {
458- this ->log_WARNING_HI_FileReadError (fullFile, stat);
459- dpFile.close ();
460- continue ; // maybe next file is fine
461- }
462-
463- // if full header isn't read, something's wrong with the file, so skip
464- if (size != Fw::DpContainer::Header::SIZE) {
465- this ->log_WARNING_HI_FileReadError (fullFile, Os::File::BAD_SIZE);
466- dpFile.close ();
467- continue ; // maybe next file is fine
468- }
469-
470- // if all is well, don't need the file any more
471- dpFile.close ();
472-
473- // give buffer to container instance
474- container.setBuffer (hdrBuff);
475-
476- // reset header deserialization in the container
477- Fw::SerializeStatus desStat = container.deserializeHeader ();
478- if (desStat != Fw::FW_SERIALIZE_OK) {
479- this ->log_WARNING_HI_FileHdrDesError (fullFile, desStat);
480- }
481-
482- // add entry to catalog.
483- DpStateEntry entry;
484- entry.dir = static_cast <FwIndexType>(dir);
485- entry.record .set_id (container.getId ());
486- entry.record .set_priority (container.getPriority ());
487- entry.record .set_state (container.getState ());
488- entry.record .set_tSec (container.getTimeTag ().getSeconds ());
489- entry.record .set_tSub (container.getTimeTag ().getUSeconds ());
490- entry.record .set_size (static_cast <U64>(fileSize));
491-
492- // check the state file to see if there is transmit state
493- this ->getFileState (entry);
494-
495- // insert entry into sorted list. if can't insert, quit
496- bool insertedOk = this ->insertEntry (entry);
497- if (not insertedOk) {
498- this ->log_WARNING_HI_DpInsertError (entry.record );
499- // clean up and return
500- this ->resetBinaryTree ();
501- this ->resetStateFileData ();
432+ int ret = processFile (fullFile, dir);
433+ if (ret < 0 ) {
502434 break ;
503435 }
504436
505- if (entry.record .get_state () == Fw::DpState::UNTRANSMITTED) {
506- pendingFiles++;
507- pendingDpBytes += entry.record .get_size ();
508- }
509-
510- // make sure we haven't exceeded the limit
511- if (this ->m_numDpRecords > this ->m_numDpSlots ) {
512- this ->log_WARNING_HI_DpCatalogFull (entry.record );
513- break ;
514- }
515-
516- filesProcessed++;
437+ filesProcessed += static_cast <U32>(ret);
517438
518439 } // end for each file in a directory
519440
520441 totalFiles += filesProcessed;
521442
522443 this ->log_ACTIVITY_HI_ProcessingDirectoryComplete (this ->m_directories [dir], static_cast <U32>(totalFiles),
523- pendingFiles, pendingDpBytes );
444+ m_pendingFiles, m_pendingDpBytes );
524445
525446 // check to see if catalog is full
526447 // that means generated products exceed the catalog size
@@ -534,6 +455,105 @@ Fw::CmdResponse DpCatalog::fillBinaryTree() {
534455
535456} // end fillBinaryTree()
536457
458+ int DpCatalog::processFile (Fw::String fullFile, FwSizeType dir = DP_MAX_DIRECTORIES) {
459+ // file class instance for processing files
460+ Os::File dpFile;
461+
462+ // Working buffer for DP headers
463+ U8 dpBuff[Fw::DpContainer::MIN_PACKET_SIZE]; // Header buffer
464+ Fw::Buffer hdrBuff (dpBuff, sizeof (dpBuff)); // buffer for container header decoding
465+ Fw::DpContainer container; // container object for extracting header fields
466+
467+ this ->log_ACTIVITY_LO_ProcessingFile (fullFile);
468+
469+ // Check if file is in one of our directories
470+ if (dir >= DP_MAX_DIRECTORIES) {
471+ // TODO: Figure out if this DIR is within m_directories
472+ // Currently Skips file
473+ this ->log_WARNING_HI_FileOpenError (fullFile, Os::FileSystem::Status::OTHER_ERROR);
474+ return 0 ;
475+ }
476+
477+ // get file size
478+ FwSizeType fileSize = 0 ;
479+ Os::FileSystem::Status sizeStat = Os::FileSystem::getFileSize (fullFile.toChar (), fileSize);
480+ if (sizeStat != Os::FileSystem::OP_OK) {
481+ this ->log_WARNING_HI_FileSizeError (fullFile, sizeStat);
482+ return 0 ;
483+ }
484+
485+ Os::File::Status stat = dpFile.open (fullFile.toChar (), Os::File::OPEN_READ);
486+ if (stat != Os::File::OP_OK) {
487+ this ->log_WARNING_HI_FileOpenError (fullFile, stat);
488+ return 0 ;
489+ }
490+
491+ // Read DP header
492+ FwSizeType size = Fw::DpContainer::Header::SIZE;
493+
494+ stat = dpFile.read (dpBuff, size);
495+ if (stat != Os::File::OP_OK) {
496+ this ->log_WARNING_HI_FileReadError (fullFile, stat);
497+ dpFile.close ();
498+ return 0 ;
499+ }
500+
501+ // if full header isn't read, something's wrong with the file, so skip
502+ if (size != Fw::DpContainer::Header::SIZE) {
503+ this ->log_WARNING_HI_FileReadError (fullFile, Os::File::BAD_SIZE);
504+ dpFile.close ();
505+ return 0 ;
506+ }
507+
508+ // if all is well, don't need the file any more
509+ dpFile.close ();
510+
511+ // give buffer to container instance
512+ container.setBuffer (hdrBuff);
513+
514+ // reset header deserialization in the container
515+ Fw::SerializeStatus desStat = container.deserializeHeader ();
516+ if (desStat != Fw::FW_SERIALIZE_OK) {
517+ this ->log_WARNING_HI_FileHdrDesError (fullFile, desStat);
518+ }
519+
520+ // add entry to catalog.
521+ DpStateEntry entry;
522+ entry.dir = static_cast <FwIndexType>(dir);
523+ entry.record .set_id (container.getId ());
524+ entry.record .set_priority (container.getPriority ());
525+ entry.record .set_state (container.getState ());
526+ entry.record .set_tSec (container.getTimeTag ().getSeconds ());
527+ entry.record .set_tSub (container.getTimeTag ().getUSeconds ());
528+ entry.record .set_size (static_cast <U64>(fileSize));
529+
530+ // check the state file to see if there is transmit state
531+ this ->getFileState (entry);
532+
533+ // insert entry into sorted list. if can't insert, quit
534+ bool insertedOk = this ->insertEntry (entry);
535+ if (not insertedOk) {
536+ this ->log_WARNING_HI_DpInsertError (entry.record );
537+ // clean up and return
538+ this ->resetBinaryTree ();
539+ this ->resetStateFileData ();
540+ return -1 ;
541+ }
542+
543+ if (entry.record .get_state () == Fw::DpState::UNTRANSMITTED) {
544+ m_pendingFiles++;
545+ m_pendingDpBytes += entry.record .get_size ();
546+ }
547+
548+ // make sure we haven't exceeded the limit
549+ if (this ->m_numDpRecords > this ->m_numDpSlots ) {
550+ this ->log_WARNING_HI_DpCatalogFull (entry.record );
551+ return -1 ;
552+ }
553+
554+ return 1 ;
555+ }
556+
537557bool DpCatalog::insertEntry (DpStateEntry& entry) {
538558 // the tree is filled in the following priority order:
539559 // 1. DP priority - lower number is higher priority
@@ -779,6 +799,13 @@ void DpCatalog ::pingIn_handler(FwIndexType portNum, U32 key) {
779799 this ->pingOut_out (0 , key);
780800}
781801
802+ void DpCatalog ::addToCat_handler (FwIndexType portNum,
803+ const Fw::StringBase& fileName,
804+ FwDpPriorityType priority,
805+ FwSizeType size) {
806+ // TODO
807+ }
808+
782809// ----------------------------------------------------------------------
783810// Handler implementations for commands
784811// ----------------------------------------------------------------------
0 commit comments