19 m_chunkSize(BLOCK_SIZE_BYTES) {}
23 this->m_chunkSize = chunkSize;
32 void FileWorker ::cancelIn_handler(
FwIndexType portNum) {
33 this->m_abort.store(
true, std::memory_order_relaxed);
49 const char*
const fileName = path.
toChar();
59 this->m_abort.store(
false, std::memory_order_relaxed);
65 U32 crcCalculated = 0;
100 const char*
const fileName = path.
toChar();
105 U32 crcCalculated = 0;
113 if (crc != crcCalculated) {
128 void FileWorker ::writeIn_handler(
FwIndexType portNum,
144 if (offsetBytes > buffer.
getSize()) {
162 this->m_abort.store(
false, std::memory_order_relaxed);
177 fileName[
sizeof(fileName) - 1] = 0;
180 const bool isWrite = this->writeBufferToFile(buffer, fileName, offsetBytes, append);
182 this->writeBufferHashToFile(buffer, fileName, offsetBytes, append);
266 numChunks = (size / this->m_chunkSize);
267 if (size % this->m_chunkSize > 0) {
270 timeout = numChunks * TIMEOUT_MS;
281 FW_ASSERT(
false, static_cast<FwAssertArgType>(readStat));
297 FwSizeType numChunks = (size / this->m_chunkSize);
298 if (size % this->m_chunkSize > 0) {
301 U64 timeout = numChunks * TIMEOUT_MS;
317 bytesRead += readAmtActual;
321 bool currAbort = this->m_abort.load(std::memory_order_relaxed);
332 if (elapsed >= timeout) {
337 bytesRead += readAmt;
338 if (bytesRead >= size) {
347 bool FileWorker ::getHash(
const char*
const hashFileName,
350 const U8*
const data,
364 U8* hashValuePtr =
reinterpret_cast<U8*
>(&hashValue);
379 hash.
hash(data, size, hashBuffer);
390 bool FileWorker ::writeBufferToFile(
Fw::Buffer& buffer,
const char* fileName,
FwSizeType offset,
bool append) {
398 U8*
const data =
reinterpret_cast<U8*
>(buffer.
getData());
414 U8*
const dataFromOffset =
reinterpret_cast<U8*
>(data + offset);
422 stat = file.
open(fileName, Os::File::Mode::OPEN_WRITE);
424 stat = file.
open(fileName, Os::File::Mode::OPEN_APPEND);
434 FwSizeType writtenSize = this->writeToFile(dataFromOffset, size, file, fileName);
437 if (writtenSize != size) {
445 void FileWorker ::writeBufferHashToFile(
Fw::Buffer& buffer,
const char* fileName,
FwSizeType offset,
bool append) {
459 U8*
const data =
reinterpret_cast<U8*
>(buffer.
getData());
474 U8*
const dataFromOffset =
reinterpret_cast<U8*
>(data + offset);
479 hash.
hash(dataFromOffset, size, hashBuffer);
482 bool isHash = this->getHash(hashFileName, hash, hashBuffer, dataFromOffset, size);
502 if (writtenSize != hashSize) {
519 FwSizeType numChunks = (size / this->m_chunkSize);
520 if (size % this->m_chunkSize > 0) {
523 U64 timeout = numChunks * TIMEOUT_MS;
527 const FwSizeType maxIterations = numChunks + MAX_LOOP_ITERATIONS;
530 for (
FwSizeType i = 0; (i < maxIterations) && (bytesWritten < size); i++) {
540 bool currAbort = this->m_abort.load(std::memory_order_relaxed);
554 if (elapsed >= timeout) {
561 bytesWritten += writeAmt;
void update(const void *const data, const FwSizeType len)
void log_WARNING_HI_ReadFailedFileSize(U32 fsStat)
PlatformSizeType FwSizeType
Serializable::SizeType getSize() const override
Get current buffer size.
void log_WARNING_HI_WriteValidationOpenError(const Fw::StringBase &hashFileName, I32 status)
void log_WARNING_HI_WriteTimeout(FwSizeType bytesWritten, FwSizeType writeSize, const Fw::StringBase &fileName, U64 timeout) const
virtual const CHAR * toChar() const =0
Convert to a C-style char*.
void log_WARNING_LO_ReadAborted(FwSizeType bytesRead, FwSizeType readSize, const Fw::StringBase &fileName) const
void log_ACTIVITY_LO_WriteBegin(FwSizeType writeSize, const Fw::StringBase &fileName) const
static Time sub(const Time &minuend, const Time &subtrahend)
void log_WARNING_HI_InvalidInput(const Fw::StringBase &handler, const Fw::StringBase &issue) const
void log_ACTIVITY_LO_ReadCompleted(FwSizeType fileSize, const Fw::StringBase &fileName) const
Os::FileInterface::Status open(const char *path, Mode mode)
open file with supplied path and mode
void writeDoneOut_out(FwIndexType portNum, U32 status, FwSizeType sizeBytes) const
Invoke output port writeDoneOut.
U8 * getBuffAddr()
Get buffer address for data filling (non-const version)
#define FW_MIN(a, b)
MIN macro (deprecated in C++, use std::min)
void log_WARNING_HI_OpenFileError(const Fw::StringBase &fileName, U32 fsStat)
File doesn't exist (for read)
void log_ACTIVITY_LO_WriteCompleted(FwSizeType writeSize, const Fw::StringBase &fileName) const
char * string_copy(char *destination, const char *source, FwSizeType num)
copy string with null-termination guaranteed
void setHashValue(HashBuffer &value)
void verifyDoneOut_out(FwIndexType portNum, U32 status, FwSizeType sizeBytes) const
Invoke output port verifyDoneOut.
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
A generic interface for creating and comparing hash values.
static const char * getFileExtensionString()
~FileWorker()
Destroy FileWorker object.
crc_stat_t verify_checksum(const char *const fname, U32 &expected, U32 &actual)
void readDoneOut_out(FwIndexType portNum, U32 status, FwSizeType sizeBytes) const
Invoke output port readDoneOut.
void log_WARNING_HI_WriteFileError(FwSizeType bytesWritten, FwSizeType writeSize, const Fw::StringBase &fileName, I32 status)
uint8_t U8
8-bit unsigned integer
void log_WARNING_HI_NotInIdle(U32 currState)
void log_WARNING_LO_WriteAborted(FwSizeType bytesWritten, FwSizeType writeSize, const Fw::StringBase &fileName) const
void log_ACTIVITY_LO_ReadBegin(FwSizeType fileSize, const Fw::StringBase &fileName) const
static Status getFileSize(const char *path, FwSizeType &size)
Get the size of the file (in bytes) at the specified path.
Status read(U8 *buffer, FwSizeType &size)
read data from this file into supplied buffer bounded by size
FwSizeType getSize() const
static void hash(const void *data, const FwSizeType len, HashBuffer &buffer)
void log_WARNING_HI_WriteValidationReadError(const Fw::StringBase &hashFileName, I32 status)
Operation was successful.
void log_WARNING_HI_CrcFailed(U32 crcStat)
PlatformIndexType FwIndexType
void log_WARNING_LO_CrcVerificationError(U32 crcExp, U32 crcCalculated) const
void configure(U64 chunkSize)
A container class for holding a hash buffer.
FormatStatus stringFormat(char *destination, const FwSizeType maximumSize, const char *formatString,...)
format a c-string
FileWorker(const char *const compName)
Construct FileWorker object.
RateGroupDivider component implementation.
virtual SizeType length() const
Get the length of the string.
void log_WARNING_LO_WriteValidationError(const Fw::StringBase &hashFileName, FwSizeType bytesWritten, FwSizeType hashSize) const
Operation was successful.
void start(FwTaskPriorityType priority=Os::Task::TASK_PRIORITY_DEFAULT, FwSizeType stackSize=Os::Task::TASK_DEFAULT, FwSizeType cpuAffinity=Os::Task::TASK_DEFAULT, FwTaskIdType identifier=static_cast< FwTaskIdType >(Os::Task::TASK_DEFAULT))
called by instantiator when task is to be started
void finalize(HashBuffer &buffer) const
void log_WARNING_HI_ReadError(FwSizeType bytesRead, FwSizeType readSize, const Fw::StringBase &fileName) const
bool isOpen() const
determine if the file is open
void log_WARNING_HI_ReadTimeout(FwSizeType bytesRead, FwSizeType readSize, const Fw::StringBase &fileName, U64 timeout) const
Auto-generated base for FileWorker component.
FwSizeType string_length(const CHAR *source, FwSizeType buffer_size)
get the length of the source string
FormatStatus
status of string format calls