15 static_assert(std::numeric_limits<U16>::max() <= std::numeric_limits<FwSizeType>::max(),
16 "U16 must fit in the positive range of FwSizeType");
21 ComLogger ::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),
30 this->
init_log_file(incomingFilePrefix, maxFileSize, storeBufferLength);
41 m_writeErrorOccurred(false),
42 m_openErrorOccurred(false),
43 m_storeBufferLength(),
44 m_initialized(false) {}
48 this->m_maxFileSize = maxFileSize;
49 this->m_storeBufferLength = storeBufferLength;
50 if (this->m_storeBufferLength) {
51 FW_ASSERT(maxFileSize >
sizeof(U16), static_cast<FwAssertArgType>(maxFileSize));
56 this->m_initialized =
true;
66 if (OPEN == this->m_fileMode) {
71 this->writeHashFile();
74 this->m_fileMode = CLOSED;
93 FW_ASSERT(sizeNative < 65536, static_cast<FwAssertArgType>(sizeNative));
94 U16 size = sizeNative & 0xFFFF;
97 if (OPEN == this->m_fileMode) {
98 U32 projectedByteCount = this->m_byteCount + size;
99 if (this->m_storeBufferLength) {
100 projectedByteCount +=
static_cast<U32
>(
sizeof(size));
102 if (projectedByteCount > this->m_maxFileSize) {
108 if (CLOSED == this->m_fileMode) {
113 if (OPEN == this->m_fileMode) {
114 this->writeComBufferToFile(data, size);
118 void ComLogger ::CloseFile_cmdHandler(
FwOpcodeType opCode, U32 cmdSeq) {
123 void ComLogger ::pingIn_handler(
const FwIndexType portNum, U32 key) {
128 void ComLogger ::openFile() {
131 if (!this->m_initialized) {
147 if (!this->m_openErrorOccurred) {
151 this->m_openErrorOccurred =
true;
154 this->m_openErrorOccurred =
false;
157 this->m_byteCount = 0;
160 this->m_fileMode = OPEN;
164 void ComLogger ::closeFile() {
165 if (OPEN == this->m_fileMode) {
167 this->m_file.
close();
170 this->writeHashFile();
173 this->m_fileMode = CLOSED;
180 void ComLogger ::writeComBufferToFile(
Fw::ComBuffer& data, U16 size) {
181 if (this->m_storeBufferLength) {
182 U8 buffer[
sizeof(size)];
184 serialLength.serialize(size);
185 if (this->writeToFile(serialLength.getBuffAddr(),
static_cast<U16
>(serialLength.getBuffLength()))) {
186 this->m_byteCount +=
static_cast<U32
>(serialLength.getBuffLength());
194 this->m_byteCount += size;
198 bool ComLogger ::writeToFile(
void* data, U16 length) {
202 if (!this->m_writeErrorOccurred) {
206 this->m_writeErrorOccurred =
true;
210 this->m_writeErrorOccurred =
false;
214 void ComLogger ::writeHashFile() {
A variable-length serializable buffer.
FwIdType FwOpcodeType
The type of a command opcode.
PlatformSizeType FwSizeType
void log_WARNING_LO_FileNotInitialized()
Log event FileNotInitialized.
void log_DIAGNOSTIC_FileClosed(const Fw::StringBase &file) const
TimeBase getTimeBase() const
Os::FileInterface::Status open(const char *path, Mode mode)
open file with supplied path and mode
void init_log_file(const char *filePrefix, U32 maxFileSize, bool storeBufferLength=true)
void pingOut_out(FwIndexType portNum, U32 key)
Invoke output port pingOut.
The validation of the file passed.
Serializable::SizeType getBuffLength() const
returns current buffer size
const char * toChar() const
void log_WARNING_HI_FileOpenError(U32 errornum, const Fw::StringBase &file) const
void cmdResponse_out(FwOpcodeType opCode, U32 cmdSeq, Fw::CmdResponse response)
Emit command response.
U8 * getBuffAddr()
gets buffer address for data filling
void log_WARNING_HI_FileWriteError(U32 errornum, U32 bytesWritten, U32 bytesToWrite, const Fw::StringBase &file) const
void close() override
close the file, if not opened then do nothing
Status write(const U8 *buffer, FwSizeType &size)
write data to this file from the supplied buffer bounded by size
static const char * getFileExtensionString()
#define PRI_FwTimeBaseStoreType
FormatStatus format(const CHAR *formatString,...)
write formatted string to buffer
Command successfully executed.
uint8_t U8
8-bit unsigned integer
Status createValidation(const char *fileName, const char *hash, Utils::HashBuffer &hashBuffer)
void log_WARNING_LO_FileValidationError(const Fw::StringBase &validationFile, const Fw::StringBase &file, U32 status) const
Operation was successful.
Defines a file class to validate files or generate a file validator file.
PlatformIndexType FwIndexType
RateGroupDivider component implementation.
U16 FwTimeBaseStoreType
The type used to serialize a time base value.
ComLogger(const char *compName, const char *filePrefix, U32 maxFileSize, bool storeBufferLength=true)
Auto-generated base for ComLogger component.
FormatStatus
status of string format calls