23 BufferLogger::File ::File(BufferLogger& bufferLogger)
24 : m_bufferLogger(bufferLogger),
34 BufferLogger::File ::~File() {
43 const char*
const logFileSuffix,
45 const U8 sizeOfSize) {
49 this->m_prefix = logFilePrefix;
50 this->m_suffix = logFileSuffix;
51 this->m_maxSize = maxFileSize;
52 this->m_sizeOfSize = sizeOfSize;
55 FW_ASSERT(m_maxSize > sizeOfSize, static_cast<FwAssertArgType>(m_maxSize));
60 this->closeAndEmitEvent();
62 this->m_baseName = baseName;
63 this->m_fileCounter = 0;
67 void BufferLogger::File ::logBuffer(
const U8*
const data,
const FwSizeType size) {
71 const FwSizeType projectedByteCount = this->m_bytesWritten + this->m_sizeOfSize + size;
72 if (projectedByteCount > this->m_maxSize) {
73 this->closeAndEmitEvent();
82 (void)this->writeBuffer(data, size);
86 void BufferLogger::File ::closeAndEmitEvent() {
90 this->m_bufferLogger.log_DIAGNOSTIC_BL_LogFileClosed(logStringArg);
98 void BufferLogger::File ::open() {
102 if ((this->m_baseName.toChar()[0] ==
'\0') || (this->m_sizeOfSize >
sizeof(
FwSizeType)) ||
103 (this->m_maxSize <= this->m_sizeOfSize)) {
104 this->m_bufferLogger.log_WARNING_HI_BL_NoLogFileOpenInitError();
109 if (this->m_fileCounter == 0) {
111 this->m_name.format(
"%s%s%s", this->m_prefix.toChar(), this->m_baseName.toChar(), this->m_suffix.toChar());
113 formatStatus = this->m_name.format(
"%s%s%" PRI_FwSizeType "%s", this->m_prefix.toChar(),
114 this->m_baseName.toChar(), this->m_fileCounter, this->m_suffix.toChar());
117 this->m_bufferLogger.log_WARNING_HI_BL_LogFileNameError(static_cast<Fw::StringFormatStatus::T>(formatStatus));
123 this->m_fileCounter++;
125 this->m_bytesWritten = 0;
132 this->m_bufferLogger.log_WARNING_HI_BL_LogFileOpenError(status,
string);
136 bool BufferLogger::File ::writeBuffer(
const U8*
const data,
const FwSizeType size) {
137 bool status = this->writeSize(size);
139 status = this->writeBytes(data, size);
144 bool BufferLogger::File ::writeSize(
const FwSizeType size) {
147 if ((this->m_sizeOfSize <
sizeof(
FwSizeType)) && ((size >> (8 * this->m_sizeOfSize)) != 0)) {
155 for (
U8 i = 0; i < this->m_sizeOfSize; ++i) {
156 sizeBuffer[this->m_sizeOfSize - i - 1] = sizeRegister & 0xFF;
159 const bool status = this->writeBytes(sizeBuffer, this->m_sizeOfSize);
163 bool BufferLogger::File ::writeBytes(
const void*
const data,
const FwSizeType length) {
165 const Os::File::Status fileStatus = this->m_osFile.write(reinterpret_cast<const U8*>(data), size);
167 if (fileStatus ==
Os::File::OP_OK && static_cast<FwSizeType>(size) == length) {
168 this->m_bytesWritten += length;
169 this->m_hash.update(data, length);
174 this->m_bufferLogger.log_WARNING_HI_BL_LogFileWriteError(fileStatus, static_cast<U32>(size),
175 static_cast<U32>(length),
string);
181 void BufferLogger::File ::writeHashFile() {
184 this->m_hash.finalize(hashBuffer);
191 this->m_bufferLogger.log_WARNING_HI_BL_LogFileValidationError(logStringArg, status);
195 bool BufferLogger::File ::flush() {
200 void BufferLogger::File ::close() {
203 this->m_osFile.close();
205 this->writeHashFile();
PlatformSizeType FwSizeType
The validation of the file passed.
Os::ValidateFile::Status createHashFile()
Invalid argument passed in.
void init()
Initialize the OS Abstraction Layer (OSAL)
uint8_t U8
8-bit unsigned integer
Operation was successful.
A read-only abstract superclass for StringBase.
A container class for holding a hash buffer.
RateGroupDivider component implementation.
FormatStatus
status of string format calls