21 ComLogger(
const char* compName,
const char* incomingFilePrefix, U32 maxFileSize,
bool storeBufferLength) :
23 m_maxFileSize(maxFileSize),
26 m_writeErrorOccurred(false),
27 m_openErrorOccurred(false),
28 m_storeBufferLength(storeBufferLength),
31 this->
init_log_file(incomingFilePrefix, maxFileSize, storeBufferLength);
43 m_writeErrorOccurred(false),
44 m_openErrorOccurred(false),
45 m_storeBufferLength(),
61 init_log_file(
const char* incomingFilePrefix, U32 maxFileSize,
bool storeBufferLength)
64 this->m_maxFileSize = maxFileSize;
65 this->m_storeBufferLength = storeBufferLength;
66 if( this->m_storeBufferLength ) {
67 FW_ASSERT(maxFileSize >
sizeof(U16), maxFileSize);
75 this->m_initialized =
true;
88 if( OPEN == this->m_fileMode ) {
93 this->writeHashFile();
96 this->m_fileMode = CLOSED;
122 U16 size = size32 & 0xFFFF;
125 if( OPEN == this->m_fileMode ) {
126 U32 projectedByteCount = this->m_byteCount + size;
127 if( this->m_storeBufferLength ) {
128 projectedByteCount +=
sizeof(size);
130 if( projectedByteCount > this->m_maxFileSize ) {
136 if( CLOSED == this->m_fileMode ){
141 if( OPEN == this->m_fileMode ) {
142 this->writeComBufferToFile(data, size);
147 CloseFile_cmdHandler(
172 if( !this->m_initialized ){
181 memset(this->m_fileName, 0,
sizeof(this->m_fileName));
182 bytesCopied = snprintf(this->m_fileName,
sizeof(this->m_fileName),
"%s_%" PRI_FwTimeBaseStoreType "_%" PRIu32
"_%06" PRIu32
".com",
187 FW_ASSERT( bytesCopied <
sizeof(this->m_fileName) );
190 bytesCopied = snprintf(this->m_hashFileName,
sizeof(this->m_hashFileName),
"%s_%" PRI_FwTimeBaseStoreType "_%" PRIu32
"_%06" PRIu32
".com%s",
192 FW_ASSERT( bytesCopied <
sizeof(this->m_hashFileName) );
196 if( !this->m_openErrorOccurred ) {
201 this->m_openErrorOccurred =
true;
204 this->m_openErrorOccurred =
false;
207 this->m_byteCount = 0;
210 this->m_fileMode = OPEN;
218 if( OPEN == this->m_fileMode ) {
220 this->m_file.
close();
223 this->writeHashFile();
226 this->m_fileMode = CLOSED;
235 writeComBufferToFile(
240 if( this->m_storeBufferLength ) {
241 U8 buffer[
sizeof(size)];
243 serialLength.serialize(size);
244 if(this->writeToFile(serialLength.getBuffAddr(),
245 static_cast<U16
>(serialLength.getBuffLength()))) {
246 this->m_byteCount += serialLength.getBuffLength();
255 this->m_byteCount += size;
268 if( !this->m_writeErrorOccurred ) {
273 this->m_writeErrorOccurred =
true;
277 this->m_writeErrorOccurred =
false;
PlatformIntType NATIVE_INT_TYPE
uint8_t U8
8-bit unsigned integer
#define PRI_FwTimeBaseStoreType
C++-compatible configuration header for fprime configuration.
Defines a file class to validate files or generate a file validator file.
@ OK
Command successfully executed.
U8 * getBuffAddr()
gets buffer address for data filling
void init()
Object initializer.
A variable-length serializable buffer.
NATIVE_UINT_TYPE getBuffLength() const
returns current buffer size
TimeBase getTimeBase() const
@ OP_OK
Operation was successful.
Status write(const void *buffer, NATIVE_INT_TYPE &size, bool waitForDone=true)
write size; will return amount written or errno
@ OPEN_WRITE
Open file for writing.
Status open(const char *fileName, Mode mode)
open file. Writing creates file if it doesn't exist
Auto-generated base for ComLogger component.
void log_WARNING_HI_FileOpenError(U32 errornum, const Fw::LogStringArg &file)
void log_DIAGNOSTIC_FileClosed(const Fw::LogStringArg &file)
void log_WARNING_LO_FileValidationError(const Fw::LogStringArg &validationFile, const Fw::LogStringArg &file, U32 status)
void log_WARNING_LO_FileNotInitialized()
Log event FileNotInitialized.
void cmdResponse_out(FwOpcodeType opCode, U32 cmdSeq, Fw::CmdResponse response)
Emit command response.
void pingOut_out(NATIVE_INT_TYPE portNum, U32 key)
Invoke output port pingOut.
void log_WARNING_HI_FileWriteError(U32 errornum, U32 bytesWritten, U32 bytesToWrite, const Fw::LogStringArg &file)
void init_log_file(const char *filePrefix, U32 maxFileSize, bool storeBufferLength=true)
ComLogger(const char *compName, const char *filePrefix, U32 maxFileSize, bool storeBufferLength=true)
static const char * getFileExtensionString()
char * string_copy(char *destination, const char *source, U32 num)
copy string with null-termination guaranteed
U32 string_length(const CHAR *source, U32 max_len)
get the length of the source string or max_len if the string is longer than max_len.
@ VALIDATION_OK
The validation of the file passed.
Status createValidation(const char *fileName, const char *hash, Utils::HashBuffer &hashBuffer)