20 this->m_chunkSize = chunkSize;
29 void FileWorker ::cancelIn_handler(
FwIndexType portNum) {
30 this->m_abort.store(
true, std::memory_order_relaxed);
38 const char*
const fileName = path.
toChar();
48 this->m_abort.store(
false, std::memory_order_relaxed);
54 U32 crcCalculated = 0;
79 const char*
const fileName = path.
toChar();
84 U32 crcCalculated = 0;
92 if (crc != crcFromFile) {
107 void FileWorker ::writeIn_handler(
FwIndexType portNum,
129 this->m_abort.store(
false, std::memory_order_relaxed);
138 fileName[
sizeof(fileName) - 1] = 0;
141 bool isWrite = this->writeBufferToFile(buffer, fileName, offsetBytes, append);
143 this->writeBufferHashToFile(buffer, fileName, offsetBytes, append);
174 this->readFile(buffer, readSize, file, fileNameStr);
213 static_assert(BLOCK_SIZE_BYTES > 0,
"Divide by 0 error");
214 numChunks = (size / BLOCK_SIZE_BYTES);
215 if (size % BLOCK_SIZE_BYTES > 0) {
218 timeout = numChunks * TIMEOUT_MS;
238 static_assert(BLOCK_SIZE_BYTES > 0,
"Divide by 0 error");
239 FwSizeType numChunks = (size / BLOCK_SIZE_BYTES);
240 if (size % BLOCK_SIZE_BYTES > 0) {
243 U64 timeout = numChunks * TIMEOUT_MS;
249 for (U32 i = 0; i < MAX_LOOP_ITERATIONS; i++) {
258 bool currAbort = this->m_abort.load(std::memory_order_relaxed);
269 if (elapsed >= timeout) {
274 bytesRead += readAmt;
275 if (bytesRead >= size) {
284 bool FileWorker ::getHash(
const char*
const hashFileName,
287 const U8*
const data,
301 U8* hashValuePtr =
reinterpret_cast<U8*
>(&hashValue);
316 hash.
hash(data, size, hashBuffer);
327 bool FileWorker ::writeBufferToFile(
Fw::Buffer& buffer,
const char* fileName,
FwSizeType offset,
bool append) {
337 stat = file.
open(fileName, Os::File::Mode::OPEN_WRITE);
339 stat = file.
open(fileName, Os::File::Mode::OPEN_APPEND);
349 U8*
const data =
reinterpret_cast<U8*
>(buffer.
getData());
355 U8*
const dataFromOffset =
reinterpret_cast<U8*
>(data + offset);
360 FwSizeType writtenSize = this->writeToFile(dataFromOffset, size, file, fileName);
363 if (writtenSize != size) {
371 void FileWorker ::writeBufferHashToFile(
Fw::Buffer& buffer,
const char* fileName,
FwSizeType offset,
bool append) {
385 U8*
const data =
reinterpret_cast<U8*
>(buffer.
getData());
391 U8*
const dataFromOffset =
reinterpret_cast<U8*
>(data + offset);
396 hash.
hash(dataFromOffset, size, hashBuffer);
399 bool isHash = this->getHash(hashFileName, hash, hashBuffer, dataFromOffset, size);
419 if (writtenSize != hashSize) {
435 static_assert(BLOCK_SIZE_BYTES > 0,
"Divide by 0 error");
436 FwSizeType numChunks = (size / BLOCK_SIZE_BYTES);
437 if (size % BLOCK_SIZE_BYTES > 0) {
440 U64 timeout = numChunks * TIMEOUT_MS;
445 for (U32 i = 0; i < MAX_LOOP_ITERATIONS; i++) {
455 bool currAbort = this->m_abort.load(std::memory_order_relaxed);
469 if (elapsed >= timeout) {
476 bytesWritten += writeAmt;
477 if (bytesWritten >= size) {
void verifyDoneOut_out(FwIndexType portNum, U32 status, FwSizeType sizeBytes)
Invoke output port verifyDoneOut.
void update(const void *const data, const FwSizeType len)
void log_WARNING_HI_ReadFailedFileSize(U32 fsStat)
U8 * getBuffAddr() override
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
Os::FileInterface::Status open(const char *path, Mode mode)
open file with supplied path and mode
void log_ACTIVITY_LO_WriteBegin(FwSizeType writeSize, const Fw::StringBase &fileName) const
static Time sub(const Time &minuend, const Time &subtrahend)
void log_ACTIVITY_LO_ReadCompleted(FwSizeType fileSize, const Fw::StringBase &fileName) const
void finalize(HashBuffer &buffer)
#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 readDoneOut_out(FwIndexType portNum, U32 status, FwSizeType sizeBytes)
Invoke output port readDoneOut.
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 writeDoneOut_out(FwIndexType portNum, U32 status, FwSizeType sizeBytes)
Invoke output port writeDoneOut.
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 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 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