Fix shadow variables (#2482)

* Fixed shadow warnings from Fprime

* Fix unit tests

* Fix missing shadow warnings

* Fix condition in cmake

* Fix cmake

* Fixes from review

* Fixed mistake in PathName

* Fixing comment

---------

Co-authored-by: M Starch <LeStarch@googlemail.com>
This commit is contained in:
Johan Bertrand 2024-02-01 19:18:10 +01:00 committed by GitHub
parent a3578a03fe
commit f0f19baafb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
45 changed files with 820 additions and 806 deletions

View File

@ -20,13 +20,13 @@ static U32 min(const U32 a, const U32 b) {
namespace CFDP {
Checksum ::
Checksum() : value(0)
Checksum() : m_value(0)
{
}
Checksum ::
Checksum(const U32 value) : value(value)
Checksum(const U32 value) : m_value(value)
{
}
@ -34,7 +34,7 @@ namespace CFDP {
Checksum ::
Checksum(const Checksum &original)
{
this->value = original.getValue();
this->m_value = original.getValue();
}
Checksum ::
@ -46,14 +46,14 @@ namespace CFDP {
Checksum& Checksum ::
operator=(const Checksum& checksum)
{
this->value = checksum.value;
this->m_value = checksum.m_value;
return *this;
}
bool Checksum ::
operator==(const Checksum& checksum) const
{
return this->value == checksum.value;
return this->m_value == checksum.m_value;
}
bool Checksum ::
@ -65,7 +65,7 @@ namespace CFDP {
U32 Checksum ::
getValue() const
{
return this->value;
return this->m_value;
}
void Checksum ::
@ -137,7 +137,7 @@ namespace CFDP {
{
FW_ASSERT(offset < 4);
const U32 addend = byte << (8*(3-offset));
this->value += addend;
this->m_value += addend;
}
}

View File

@ -102,7 +102,7 @@ namespace CFDP {
// ----------------------------------------------------------------------
//! The accumulated checksum value
U32 value;
U32 m_value;
};

View File

@ -25,6 +25,14 @@ add_compile_options(
-Wno-unused-parameter
)
# Add -Wshadow only for framework code, not the unit tests
# TODO: Next lines to be uncommented once FPP is not generating files with shadow variables
# if (NOT BUILD_TESTING)
# add_compile_options(
# -Wshadow
# )
# endif()
# Turn on pedantic checks for clang, but disable specific checks that F' doesn't comply with.
# GCC doesn't support disabling specific pedantic checks, so skip pedantic on GCC for now.
#

View File

@ -122,7 +122,7 @@ bool LinuxUartDriver::open(const char* const device,
if (fc == HW_FLOW) {
struct termios t;
int stat = tcgetattr(fd, &t);
stat = tcgetattr(fd, &t);
if (-1 == stat) {
DEBUG_PRINT("tcgetattr UART fd %d failed\n", fd);
close(fd);

View File

@ -18,15 +18,15 @@ namespace Fw {
void FilePacket::DataPacket ::
initialize(
const U32 sequenceIndex,
const U32 byteOffset,
const U16 dataSize,
const U8 *const data
const U32 a_byteOffset,
const U16 a_dataSize,
const U8 *const a_data
)
{
this->header.initialize(FilePacket::T_DATA, sequenceIndex);
this->byteOffset = byteOffset;
this->dataSize = dataSize;
this->data = data;
this->byteOffset = a_byteOffset;
this->dataSize = a_dataSize;
this->data = a_data;
}
U32 FilePacket::DataPacket ::

View File

@ -30,7 +30,7 @@ namespace Fw {
U32 FilePacket::EndPacket ::
bufferSize() const
{
return this->header.bufferSize() + sizeof(this->checksumValue);
return this->header.bufferSize() + sizeof(this->m_checksumValue);
}
SerializeStatus FilePacket::EndPacket ::
@ -46,14 +46,14 @@ namespace Fw {
void FilePacket::EndPacket ::
setChecksum(const CFDP::Checksum& checksum)
{
this->checksumValue = checksum.getValue();
this->m_checksumValue = checksum.getValue();
}
void FilePacket::EndPacket ::
getChecksum(CFDP::Checksum& checksum) const
{
CFDP::Checksum c(this->checksumValue);
CFDP::Checksum c(this->m_checksumValue);
checksum = c;
}
@ -64,7 +64,7 @@ namespace Fw {
FW_ASSERT(this->header.type == T_END);
const SerializeStatus status =
serialBuffer.deserialize(this->checksumValue);
serialBuffer.deserialize(this->m_checksumValue);
return status;
@ -82,7 +82,7 @@ namespace Fw {
if (status != FW_SERIALIZE_OK)
return status;
status = serialBuffer.serialize(this->checksumValue);
status = serialBuffer.serialize(this->m_checksumValue);
if (status != FW_SERIALIZE_OK)
return status;

View File

@ -34,77 +34,77 @@ namespace Fw {
const FilePacket::Header& FilePacket ::
asHeader() const
{
return this->header;
return this->m_header;
}
const FilePacket::StartPacket& FilePacket ::
asStartPacket() const
{
FW_ASSERT(this->header.type == T_START);
return this->startPacket;
FW_ASSERT(this->m_header.type == T_START);
return this->m_startPacket;
}
const FilePacket::DataPacket& FilePacket ::
asDataPacket() const
{
FW_ASSERT(this->header.type == T_DATA);
return this->dataPacket;
FW_ASSERT(this->m_header.type == T_DATA);
return this->m_dataPacket;
}
const FilePacket::EndPacket& FilePacket ::
asEndPacket() const
{
FW_ASSERT(this->header.type == T_END);
return this->endPacket;
FW_ASSERT(this->m_header.type == T_END);
return this->m_endPacket;
}
const FilePacket::CancelPacket& FilePacket ::
asCancelPacket() const
{
FW_ASSERT(this->header.type == T_CANCEL);
return this->cancelPacket;
FW_ASSERT(this->m_header.type == T_CANCEL);
return this->m_cancelPacket;
}
void FilePacket ::
fromStartPacket(const StartPacket& startPacket)
{
this->startPacket = startPacket;
this->header.type = T_START;
this->m_startPacket = startPacket;
this->m_header.type = T_START;
}
void FilePacket ::
fromDataPacket(const DataPacket& dataPacket)
{
this->dataPacket = dataPacket;
this->header.type = T_DATA;
this->m_dataPacket = dataPacket;
this->m_header.type = T_DATA;
}
void FilePacket ::
fromEndPacket(const EndPacket& endPacket)
{
this->endPacket = endPacket;
this->header.type = T_END;
this->m_endPacket = endPacket;
this->m_header.type = T_END;
}
void FilePacket ::
fromCancelPacket(const CancelPacket& cancelPacket)
{
this->cancelPacket = cancelPacket;
this->header.type = T_CANCEL;
this->m_cancelPacket = cancelPacket;
this->m_header.type = T_CANCEL;
}
U32 FilePacket ::
bufferSize() const
{
switch (this->header.type) {
switch (this->m_header.type) {
case T_START:
return this->startPacket.bufferSize();
return this->m_startPacket.bufferSize();
case T_DATA:
return this->dataPacket.bufferSize();
return this->m_dataPacket.bufferSize();
case T_END:
return this->endPacket.bufferSize();
return this->m_endPacket.bufferSize();
case T_CANCEL:
return this->cancelPacket.bufferSize();
return this->m_cancelPacket.bufferSize();
case T_NONE:
return 0;
default:
@ -116,15 +116,15 @@ namespace Fw {
SerializeStatus FilePacket ::
toBuffer(Buffer& buffer) const
{
switch (this->header.type) {
switch (this->m_header.type) {
case T_START:
return this->startPacket.toBuffer(buffer);
return this->m_startPacket.toBuffer(buffer);
case T_DATA:
return this->dataPacket.toBuffer(buffer);
return this->m_dataPacket.toBuffer(buffer);
case T_END:
return this->endPacket.toBuffer(buffer);
return this->m_endPacket.toBuffer(buffer);
case T_CANCEL:
return this->cancelPacket.toBuffer(buffer);
return this->m_cancelPacket.toBuffer(buffer);
default:
FW_ASSERT(0);
return static_cast<SerializeStatus>(0);
@ -139,21 +139,21 @@ namespace Fw {
fromSerialBuffer(SerialBuffer& serialBuffer)
{
SerializeStatus status;
status = this->header.fromSerialBuffer(serialBuffer);
status = this->m_header.fromSerialBuffer(serialBuffer);
if (status != FW_SERIALIZE_OK)
return status;
switch (this->header.type) {
switch (this->m_header.type) {
case T_START:
status = this->startPacket.fromSerialBuffer(serialBuffer);
status = this->m_startPacket.fromSerialBuffer(serialBuffer);
break;
case T_DATA:
status = this->dataPacket.fromSerialBuffer(serialBuffer);
status = this->m_dataPacket.fromSerialBuffer(serialBuffer);
break;
case T_END:
status = this->endPacket.fromSerialBuffer(serialBuffer);
status = this->m_endPacket.fromSerialBuffer(serialBuffer);
break;
case T_CANCEL:
status = this->cancelPacket.fromSerialBuffer(serialBuffer);
status = this->m_cancelPacket.fromSerialBuffer(serialBuffer);
break;
case T_NONE:
status = FW_DESERIALIZE_TYPE_MISMATCH;

View File

@ -63,7 +63,7 @@ namespace Fw {
//! Initialize a PathName
void initialize(
const char *const value //! The path value
const char *const a_value //! The path value
);
//! Compute the buffer size needed to hold this PathName
@ -99,8 +99,8 @@ namespace Fw {
//! Initialize a file packet header
void initialize(
const Type type, //!< The packet type
const U32 sequenceIndex //!< The sequence index
const Type a_type, //!< The packet type
const U32 a_sequenceIndex //!< The sequence index
);
//! Compute the buffer size needed to hold this Header
@ -137,9 +137,9 @@ namespace Fw {
//! Initialize a StartPacket with sequence number 0
void initialize(
const U32 fileSize, //!< The file size
const char *const sourcePath, //!< The source path
const char *const destinationPath //!< The destination path
const U32 a_fileSize, //!< The file size
const char *const a_sourcePath, //!< The source path
const char *const a_destinationPath //!< The destination path
);
//! Compute the buffer size needed to hold this StartPacket
@ -188,9 +188,9 @@ namespace Fw {
//! Initialize a data packet
void initialize(
const U32 sequenceIndex, //!< The sequence index
const U32 byteOffset, //!< The byte offset
const U16 dataSize, //!< The data size
const U8 *const data //!< The file data
const U32 a_byteOffset, //!< The byte offset
const U16 a_dataSize, //!< The data size
const U8 *const a_data //!< The file data
);
//! Compute the buffer size needed to hold this DataPacket
@ -245,7 +245,7 @@ namespace Fw {
PRIVATE:
//! The checksum
U32 checksumValue;
U32 m_checksumValue;
//! Initialize this EndPacket from a SerialBuffer
SerializeStatus fromSerialBuffer(SerialBuffer& serialBuffer);
@ -291,7 +291,7 @@ namespace Fw {
// Constructor
// ----------------------------------------------------------------------
FilePacket() { this->header.type = T_NONE; }
FilePacket() { this->m_header.type = T_NONE; }
public:
@ -365,23 +365,23 @@ namespace Fw {
//! this, seen as a header
//!
Header header;
Header m_header;
//! this, seen as a Start packet
//!
StartPacket startPacket;
StartPacket m_startPacket;
//! this, seen as a Data packet
//!
DataPacket dataPacket;
DataPacket m_dataPacket;
//! this, seen as an End packet
//!
EndPacket endPacket;
EndPacket m_endPacket;
//! this, seen as a Cancel packet
//!
CancelPacket cancelPacket;
CancelPacket m_cancelPacket;
};

View File

@ -17,12 +17,12 @@ namespace Fw {
void FilePacket::Header ::
initialize(
const Type type,
const U32 sequenceIndex
const Type a_type,
const U32 a_sequenceIndex
)
{
this->type = type;
this->sequenceIndex = sequenceIndex;
this->type = a_type;
this->sequenceIndex = a_sequenceIndex;
}
U32 FilePacket::Header ::
@ -35,14 +35,14 @@ namespace Fw {
fromSerialBuffer(SerialBuffer& serialBuffer)
{
U8 type;
U8 new_type;
SerializeStatus status;
status = serialBuffer.deserialize(type);
status = serialBuffer.deserialize(new_type);
if (status != FW_SERIALIZE_OK) {
return status;
}
this->type = static_cast<Type>(type);
this->type = static_cast<Type>(new_type);
status = serialBuffer.deserialize(this->sequenceIndex);
@ -54,10 +54,10 @@ namespace Fw {
toSerialBuffer(SerialBuffer& serialBuffer) const
{
const U8 type = static_cast<U8>(this->type);
const U8 type_casted = static_cast<U8>(this->type);
SerializeStatus status;
status = serialBuffer.serialize(type);
status = serialBuffer.serialize(type_casted);
if (status != FW_SERIALIZE_OK)
return status;

View File

@ -19,11 +19,11 @@
namespace Fw {
void FilePacket::PathName ::
initialize(const char *const value)
initialize(const char *const a_value)
{
const U8 length = static_cast<U8>(StringUtils::string_length(value, MAX_LENGTH));
this->length = length;
this->value = value;
const U8 new_length = static_cast<U8>(StringUtils::string_length(a_value, MAX_LENGTH));
this->length = new_length;
this->value = a_value;
}
U32 FilePacket::PathName ::

View File

@ -17,16 +17,16 @@ namespace Fw {
void FilePacket::StartPacket ::
initialize(
const U32 fileSize,
const char *const sourcePath,
const char *const destinationPath
const U32 a_fileSize,
const char *const a_sourcePath,
const char *const a_destinationPath
)
{
const FilePacket::Header header = { FilePacket::T_START, 0 };
this->header = header;
this->fileSize = fileSize;
this->sourcePath.initialize(sourcePath);
this->destinationPath.initialize(destinationPath);
const FilePacket::Header new_header = { FilePacket::T_START, 0 };
this->header = new_header;
this->fileSize = a_fileSize;
this->sourcePath.initialize(a_sourcePath);
this->destinationPath.initialize(a_destinationPath);
}
U32 FilePacket::StartPacket ::

View File

@ -17,18 +17,18 @@
namespace Fw {
SerializableFile::SerializableFile(MemAllocator* allocator, NATIVE_UINT_TYPE maxSerializedSize) :
allocator(allocator),
recoverable(false), // for compiler; not used
actualSize(maxSerializedSize),
buffer(static_cast<U8*>(this->allocator->allocate(0, actualSize, recoverable)), actualSize)
m_allocator(allocator),
m_recoverable(false), // for compiler; not used
m_actualSize(maxSerializedSize),
m_buffer(static_cast<U8*>(this->m_allocator->allocate(0, m_actualSize, m_recoverable)), m_actualSize)
{
// assert if allocator returns smaller size
FW_ASSERT(maxSerializedSize == actualSize,maxSerializedSize,actualSize);
FW_ASSERT(nullptr != buffer.getBuffAddr());
FW_ASSERT(maxSerializedSize == m_actualSize,maxSerializedSize,m_actualSize);
FW_ASSERT(nullptr != m_buffer.getBuffAddr());
}
SerializableFile::~SerializableFile() {
this->allocator->deallocate(0, this->buffer.getBuffAddr());
this->m_allocator->deallocate(0, this->m_buffer.getBuffAddr());
}
SerializableFile::Status SerializableFile::load(const char* fileName, Serializable& serializable) {
@ -39,9 +39,9 @@ namespace Fw {
return FILE_OPEN_ERROR;
}
NATIVE_INT_TYPE capacity = this->buffer.getBuffCapacity();
NATIVE_INT_TYPE capacity = this->m_buffer.getBuffCapacity();
NATIVE_INT_TYPE length = capacity;
status = file.read(this->buffer.getBuffAddr(), length, false);
status = file.read(this->m_buffer.getBuffAddr(), length, false);
if( Os::File::OP_OK != status ) {
file.close();
return FILE_READ_ERROR;
@ -50,9 +50,9 @@ namespace Fw {
this->reset();
SerializeStatus serStatus;
serStatus = this->buffer.setBuffLen(static_cast<NATIVE_UINT_TYPE>(length));
serStatus = this->m_buffer.setBuffLen(static_cast<NATIVE_UINT_TYPE>(length));
FW_ASSERT(FW_SERIALIZE_OK == serStatus, serStatus);
serStatus = serializable.deserialize(this->buffer);
serStatus = serializable.deserialize(this->m_buffer);
if(FW_SERIALIZE_OK != serStatus) {
return DESERIALIZATION_ERROR;
}
@ -62,7 +62,7 @@ namespace Fw {
SerializableFile::Status SerializableFile::save(const char* fileName, Serializable& serializable) {
this->reset();
SerializeStatus serStatus = serializable.serialize(this->buffer);
SerializeStatus serStatus = serializable.serialize(this->m_buffer);
FW_ASSERT(FW_SERIALIZE_OK == serStatus, serStatus);
Os::File file;
@ -72,9 +72,9 @@ namespace Fw {
return FILE_OPEN_ERROR;
}
NATIVE_INT_TYPE length = this->buffer.getBuffLength();
NATIVE_INT_TYPE length = this->m_buffer.getBuffLength();
NATIVE_INT_TYPE size = length;
status = file.write(this->buffer.getBuffAddr(), length);
status = file.write(this->m_buffer.getBuffAddr(), length);
if( (Os::File::OP_OK != status) ||
(length != size) )
{
@ -88,7 +88,7 @@ namespace Fw {
}
void SerializableFile::reset() {
this->buffer.resetSer(); //!< reset to beginning of buffer to reuse for serialization
this->buffer.resetDeser(); //!< reset deserialization to beginning
this->m_buffer.resetSer(); //!< reset to beginning of buffer to reuse for serialization
this->m_buffer.resetDeser(); //!< reset deserialization to beginning
}
}

View File

@ -1,4 +1,4 @@
// ======================================================================
// ======================================================================
// \title SerializableFile.hpp
// \author dinkel
// \brief hpp file for SerializableFile
@ -7,8 +7,8 @@
// Copyright 2009-2016, by the California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
//
// ======================================================================
#ifndef Fw_SerializableFile_HPP
#define Fw_SerializableFile_HPP
@ -34,16 +34,16 @@ namespace Fw {
// NOTE!: This should not be used with an allocator that can return a smaller buffer than requested
SerializableFile(MemAllocator* allocator, NATIVE_UINT_TYPE maxSerializedSize);
~SerializableFile();
Status load(const char* fileName, Serializable& serializable);
Status save(const char* fileName, Serializable& serializable);
PRIVATE:
void reset();
MemAllocator* allocator;
bool recoverable; // don't care; for allocator
NATIVE_UINT_TYPE actualSize; // for checking
SerialBuffer buffer;
MemAllocator* m_allocator;
bool m_recoverable; // don't care; for allocator
NATIVE_UINT_TYPE m_actualSize; // for checking
SerialBuffer m_buffer;
};
}

View File

@ -20,8 +20,8 @@ namespace Fw {
U8 *const data,
const U32 capacity
) :
data(data),
capacity(capacity)
m_data(data),
m_capacity(capacity)
{
}
@ -29,25 +29,25 @@ namespace Fw {
NATIVE_UINT_TYPE SerialBuffer ::
getBuffCapacity() const
{
return capacity;
return m_capacity;
}
U8* SerialBuffer ::
getBuffAddr()
{
return data;
return m_data;
}
const U8* SerialBuffer ::
getBuffAddr() const
{
return data;
return m_data;
}
void SerialBuffer ::
fill()
{
const SerializeStatus status = this->setBuffLen(this->capacity);
const SerializeStatus status = this->setBuffLen(this->m_capacity);
FW_ASSERT(status == FW_SERIALIZE_OK);
}

View File

@ -78,10 +78,10 @@ namespace Fw {
// ----------------------------------------------------------------------
//! The data
U8 *const data;
U8 *const m_data;
//! The capacity
const U32 capacity;
const U32 m_capacity;
};

View File

@ -121,11 +121,11 @@ namespace Os {
NATIVE_UINT_TYPE getBufferIndex(NATIVE_INT_TYPE index);
// Member variables:
void* queue; // The queue can be implemented in various ways
NATIVE_UINT_TYPE msgSize; // Max size of message on the queue
NATIVE_UINT_TYPE depth; // Max number of messages on the queue
NATIVE_UINT_TYPE count; // Current number of messages on the queue
NATIVE_UINT_TYPE maxCount; // Maximum number of messages ever seen on the queue
void* m_queue; // The queue can be implemented in various ways
NATIVE_UINT_TYPE m_msgSize; // Max size of message on the queue
NATIVE_UINT_TYPE m_depth; // Max number of messages on the queue
NATIVE_UINT_TYPE m_count; // Current number of messages on the queue
NATIVE_UINT_TYPE m_maxCount; // Maximum number of messages ever seen on the queue
};
}

View File

@ -24,11 +24,11 @@ namespace Os {
BufferQueue::BufferQueue() {
// Set member variables:
this->queue = nullptr;
this->msgSize = 0;
this->depth = 0;
this->count = 0;
this->maxCount = 0;
this->m_queue = nullptr;
this->m_msgSize = 0;
this->m_depth = 0;
this->m_count = 0;
this->m_maxCount = 0;
}
BufferQueue::~BufferQueue() {
@ -37,20 +37,20 @@ namespace Os {
bool BufferQueue::create(NATIVE_UINT_TYPE depth, NATIVE_UINT_TYPE msgSize) {
// Queue is already set up. destroy it and try again:
if (nullptr != this->queue) {
if (nullptr != this->m_queue) {
this->finalize();
}
FW_ASSERT(nullptr == this->queue, reinterpret_cast<POINTER_CAST>(this->queue));
FW_ASSERT(nullptr == this->m_queue, reinterpret_cast<POINTER_CAST>(this->m_queue));
// Set member variables:
this->msgSize = msgSize;
this->depth = depth;
this->m_msgSize = msgSize;
this->m_depth = depth;
return this->initialize(depth, msgSize);
}
bool BufferQueue::push(const U8* buffer, NATIVE_UINT_TYPE size, NATIVE_INT_TYPE priority) {
FW_ASSERT(size <= this->msgSize);
FW_ASSERT(size <= this->m_msgSize);
if( this->isFull() ) {
return false;
}
@ -62,9 +62,9 @@ namespace Os {
}
// Increment count:
++this->count;
if( this->count > this->maxCount ) {
this->maxCount = this->count;
++this->m_count;
if( this->m_count > this->m_maxCount ) {
this->m_maxCount = this->m_count;
}
return true;
}
@ -83,38 +83,38 @@ namespace Os {
}
// Decrement count:
--this->count;
--this->m_count;
return true;
}
bool BufferQueue::isFull() {
return (this->count == this->depth);
return (this->m_count == this->m_depth);
}
bool BufferQueue::isEmpty() {
return (this->count == 0);
return (this->m_count == 0);
}
NATIVE_UINT_TYPE BufferQueue::getCount() {
return this->count;
return this->m_count;
}
NATIVE_UINT_TYPE BufferQueue::getMaxCount() {
return this->maxCount;
return this->m_maxCount;
}
NATIVE_UINT_TYPE BufferQueue::getMsgSize() {
return this->msgSize;
return this->m_msgSize;
}
NATIVE_UINT_TYPE BufferQueue::getDepth() {
return this->depth;
return this->m_depth;
}
NATIVE_UINT_TYPE BufferQueue::getBufferIndex(NATIVE_INT_TYPE index) {
return (index % this->depth) * (sizeof(NATIVE_INT_TYPE) + this->msgSize);
return (index % this->m_depth) * (sizeof(NATIVE_INT_TYPE) + this->m_msgSize);
}
void BufferQueue::enqueueBuffer(const U8* buffer, NATIVE_UINT_TYPE size, U8* data, NATIVE_UINT_TYPE index) {

View File

@ -31,31 +31,31 @@ namespace Os {
MaxHeap::MaxHeap() {
// Initialize the heap:
this->capacity = 0;
this->heap = nullptr;
this->size = 0;
this->order = 0;
this->m_capacity = 0;
this->m_heap = nullptr;
this->m_size = 0;
this->m_order = 0;
}
MaxHeap::~MaxHeap() {
delete [] this->heap;
this->heap = nullptr;
delete [] this->m_heap;
this->m_heap = nullptr;
}
bool MaxHeap::create(NATIVE_UINT_TYPE capacity)
{
// The heap has already been created.. so delete
// it and try again.
if( nullptr != this->heap ) {
delete [] this->heap;
this->heap = nullptr;
if( nullptr != this->m_heap ) {
delete [] this->m_heap;
this->m_heap = nullptr;
}
this->heap = new(std::nothrow) Node[capacity];
if( nullptr == this->heap ) {
this->m_heap = new(std::nothrow) Node[capacity];
if( nullptr == this->m_heap ) {
return false;
}
this->capacity = capacity;
this->m_capacity = capacity;
return true;
}
@ -67,10 +67,10 @@ namespace Os {
// Heap indexes:
NATIVE_UINT_TYPE parent;
NATIVE_UINT_TYPE index = this->size;
NATIVE_UINT_TYPE index = this->m_size;
// Max loop bounds for bit flip protection:
NATIVE_UINT_TYPE maxIter = this->size+1;
NATIVE_UINT_TYPE maxIter = this->m_size+1;
NATIVE_UINT_TYPE maxCount = 0;
// Start at the bottom of the heap and work our ways
@ -85,26 +85,26 @@ namespace Os {
// If the current value is less than the parent,
// then the current index is in the correct place,
// so break out of the loop:
if(value <= this->heap[parent].value) {
if(value <= this->m_heap[parent].value) {
break;
}
// Swap the parent and child:
this->heap[index] = this->heap[parent];
this->m_heap[index] = this->m_heap[parent];
index = parent;
++maxCount;
}
// Check for programming errors or bit flips:
FW_ASSERT(maxCount < maxIter, maxCount, maxIter);
FW_ASSERT(index <= this->size, index);
FW_ASSERT(index <= this->m_size, index);
// Set the values of the new element:
this->heap[index].value = value;
this->heap[index].order = order;
this->heap[index].id = id;
this->m_heap[index].value = value;
this->m_heap[index].order = m_order;
this->m_heap[index].id = id;
++this->size;
++this->order;
++this->m_size;
++this->m_order;
return true;
}
@ -117,17 +117,17 @@ namespace Os {
// Set the return values to the top (max) of
// the heap:
value = this->heap[0].value;
id = this->heap[0].id;
value = this->m_heap[0].value;
id = this->m_heap[0].id;
// Now place the last element on the heap in
// the root position, and resize the heap.
// This will put the smallest value in the
// heap on the top, violating the heap property.
NATIVE_UINT_TYPE index = this->size-1;
// Fw::Logger::logMsg("Putting on top: i: %u v: %d\n", index, this->heap[index].value);
this->heap[0]= this->heap[index];
--this->size;
NATIVE_UINT_TYPE index = this->m_size-1;
// Fw::Logger::logMsg("Putting on top: i: %u v: %d\n", index, this->m_heap[index].value);
this->m_heap[0]= this->m_heap[index];
--this->m_size;
// Now that the heap property is violated, we
// need to reorganize the heap to restore it's
@ -138,17 +138,17 @@ namespace Os {
// Is the heap full:
bool MaxHeap::isFull() {
return (this->size == this->capacity);
return (this->m_size == this->m_capacity);
}
// Is the heap empty:
bool MaxHeap::isEmpty() {
return (this->size == 0);
return (this->m_size == 0);
}
// Get the current size of the heap:
NATIVE_UINT_TYPE MaxHeap::getSize() {
return this->size;
return this->m_size;
}
// A non-recursive heapify method.
@ -162,10 +162,10 @@ namespace Os {
NATIVE_UINT_TYPE largest;
// Max loop bounds for bit flip protection:
NATIVE_UINT_TYPE maxIter = this->size+1;
NATIVE_UINT_TYPE maxIter = this->m_size+1;
NATIVE_UINT_TYPE maxCount = 0;
while(index <= this->size && maxCount < maxIter) {
while(index <= this->m_size && maxCount < maxIter) {
// Get the children indexes for this node:
left = LCHILD(index);
right = RCHILD(index);
@ -175,7 +175,7 @@ namespace Os {
// If the left node is bigger than the heap
// size, we have reached the end of the heap
// so we can stop:
if (left >= this->size) {
if (left >= this->m_size) {
break;
}
@ -188,7 +188,7 @@ namespace Os {
largest = this->max(left, largest);
// Make sure the right node exists before checking it:
if (right < this->size) {
if (right < this->m_size) {
// Which one is larger, the current largest
// node or the right node?
largest = this->max(right, largest);
@ -203,8 +203,8 @@ namespace Os {
// Swap the largest node with the current node:
// Fw::Logger::logMsg("Swapping: i: %u v: %d with i: %u v: %d\n",
// index, this->heap[index].value,
// largest, this->heap[largest].value);
// index, this->m_heap[index].value,
// largest, this->m_heap[largest].value);
this->swap(index, largest);
// Set the new index to whichever child was larger:
@ -213,18 +213,18 @@ namespace Os {
// Check for programming errors or bit flips:
FW_ASSERT(maxCount < maxIter, maxCount, maxIter);
FW_ASSERT(index <= this->size, index);
FW_ASSERT(index <= this->m_size, index);
}
// Return the maximum priority index between two nodes. If their
// priorities are equal, return the oldest to keep the heap stable
NATIVE_UINT_TYPE MaxHeap::max(NATIVE_UINT_TYPE a, NATIVE_UINT_TYPE b) {
FW_ASSERT(a < this->size, a, this->size);
FW_ASSERT(b < this->size, b, this->size);
FW_ASSERT(a < this->m_size, a, this->m_size);
FW_ASSERT(b < this->m_size, b, this->m_size);
// Extract the priorities:
NATIVE_INT_TYPE aValue = this->heap[a].value;
NATIVE_INT_TYPE bValue = this->heap[b].value;
NATIVE_INT_TYPE aValue = this->m_heap[a].value;
NATIVE_INT_TYPE bValue = this->m_heap[b].value;
// If the priorities are equal, the "larger" one will be
// the "older" one as determined by order pushed on to the
@ -233,8 +233,8 @@ namespace Os {
// Note: We check this first, because it is the most common
// case. Let's save as many ticks as we can...
if(aValue == bValue) {
NATIVE_UINT_TYPE aAge = this->order - this->heap[a].order;
NATIVE_UINT_TYPE bAge = this->order - this->heap[b].order;
NATIVE_UINT_TYPE aAge = this->m_order - this->m_heap[a].order;
NATIVE_UINT_TYPE bAge = this->m_order - this->m_heap[b].order;
if(aAge > bAge) {
return a;
}
@ -251,11 +251,11 @@ namespace Os {
// Swap two nodes in the heap:
void MaxHeap::swap(NATIVE_UINT_TYPE a, NATIVE_UINT_TYPE b) {
FW_ASSERT(a < this->size, a, this->size);
FW_ASSERT(b < this->size, b, this->size);
Node temp = this->heap[a];
this->heap[a] = this->heap[b];
this->heap[b] = temp;
FW_ASSERT(a < this->m_size, a, this->m_size);
FW_ASSERT(b < this->m_size, b, this->m_size);
Node temp = this->m_heap[a];
this->m_heap[a] = this->m_heap[b];
this->m_heap[b] = temp;
}
// Print heap, for debugging purposes only:
@ -263,25 +263,25 @@ namespace Os {
NATIVE_UINT_TYPE index = 0;
NATIVE_UINT_TYPE left;
NATIVE_UINT_TYPE right;
Fw::Logger::logMsg("Printing Heap of Size: %d\n", this->size);
while(index < this->size) {
Fw::Logger::logMsg("Printing Heap of Size: %d\n", this->m_size);
while(index < this->m_size) {
left = LCHILD(index);
right = RCHILD(index);
if( left >= size && index == 0) {
if( left >= m_size && index == 0) {
Fw::Logger::logMsg("i: %u v: %d d: %u -> (NULL, NULL)\n",
index, this->heap[index].value, this->heap[index].id);
index, this->m_heap[index].value, this->m_heap[index].id);
}
else if( right >= size && left < size ) {
else if( right >= m_size && left < m_size ) {
Fw::Logger::logMsg("i: %u v: %d d: %u -> (i: %u v: %d d: %u, NULL)\n",
index, this->heap[index].value, this->heap[index].id,
left, this->heap[left].value, this->heap[left].id);
index, this->m_heap[index].value, this->m_heap[index].id,
left, this->m_heap[left].value, this->m_heap[left].id);
}
else if( right < size && left < size ) {
else if( right < m_size && left < m_size ) {
Fw::Logger::logMsg("i: %u v: %d d: %u -> (i: %u v: %d d: %u, i: %u v: %d d: %u)\n",
index, this->heap[index].value, this->heap[index].id,
left, this->heap[left].value,this->heap[left].id,
right, this->heap[right].value, this->heap[right].id);
index, this->m_heap[index].value, this->m_heap[index].id,
left, this->m_heap[left].value,this->m_heap[left].id,
right, this->m_heap[right].value, this->m_heap[right].id);
}
++index;

View File

@ -25,7 +25,7 @@ namespace Os {
//! off in FIFO order. Insertion and deletion from the heap are both
//! O(log(n)) time.
class MaxHeap {
public:
//! \brief MaxHeap constructor
//!
@ -47,7 +47,7 @@ namespace Os {
//! \brief Push an item onto the heap.
//!
//! The item will be put into the heap according to its value. The
//! id field is a data field set by the user which can be used to
//! id field is a data field set by the user which can be used to
//! identify the element when it is popped off the heap.
//!
//! \param value the value of the element to push onto the heap
@ -87,7 +87,7 @@ namespace Os {
//! This function here is for debugging purposes.
//!
void print();
private:
// Private functions:
// Ensure the heap meets the heap property:
@ -101,14 +101,14 @@ namespace Os {
struct Node {
NATIVE_INT_TYPE value; // the priority of the node
NATIVE_UINT_TYPE order; // order in which node was pushed
NATIVE_UINT_TYPE id; // unique id for this node
NATIVE_UINT_TYPE id; // unique id for this node
};
// Private members:
Node* heap; // the heap itself
NATIVE_UINT_TYPE size; // the current size of the heap
NATIVE_UINT_TYPE order; // the current count of heap pushes
NATIVE_UINT_TYPE capacity; // the maximum capacity of the heap
Node* m_heap; // the heap itself
NATIVE_UINT_TYPE m_size; // the current size of the heap
NATIVE_UINT_TYPE m_order; // the current count of heap pushes
NATIVE_UINT_TYPE m_capacity; // the maximum capacity of the heap
};
}

View File

@ -102,12 +102,12 @@ namespace Os {
priorityQueue->indexes = indexes;
priorityQueue->startIndex = 0;
priorityQueue->stopIndex = depth;
this->queue = priorityQueue;
this->m_queue = priorityQueue;
return true;
}
void BufferQueue::finalize() {
PriorityQueue* pQueue = static_cast<PriorityQueue*>(this->queue);
PriorityQueue* pQueue = static_cast<PriorityQueue*>(this->m_queue);
if (nullptr != pQueue)
{
MaxHeap* heap = pQueue->heap;
@ -125,18 +125,18 @@ namespace Os {
}
delete pQueue;
}
this->queue = nullptr;
this->m_queue = nullptr;
}
bool BufferQueue::enqueue(const U8* buffer, NATIVE_UINT_TYPE size, NATIVE_INT_TYPE priority) {
// Extract queue handle variables:
PriorityQueue* pQueue = static_cast<PriorityQueue*>(this->queue);
PriorityQueue* pQueue = static_cast<PriorityQueue*>(this->m_queue);
MaxHeap* heap = pQueue->heap;
U8* data = pQueue->data;
// Get an available data index:
NATIVE_UINT_TYPE index = checkoutIndex(pQueue, this->depth);
NATIVE_UINT_TYPE index = checkoutIndex(pQueue, this->m_depth);
// Insert the data into the heap:
bool ret = heap->push(priority, index);
@ -151,7 +151,7 @@ namespace Os {
bool BufferQueue::dequeue(U8* buffer, NATIVE_UINT_TYPE& size, NATIVE_INT_TYPE &priority) {
// Extract queue handle variables:
PriorityQueue* pQueue = static_cast<PriorityQueue*>(this->queue);
PriorityQueue* pQueue = static_cast<PriorityQueue*>(this->m_queue);
MaxHeap* heap = pQueue->heap;
U8* data = pQueue->data;
@ -170,7 +170,7 @@ namespace Os {
}
// Return the index to the available indexes:
returnIndex(pQueue, this->depth, index);
returnIndex(pQueue, this->m_depth, index);
return true;
}

View File

@ -113,7 +113,7 @@ namespace Os {
if(pushSucceeded) {
// Push worked - wake up a thread that might be waiting on
// the other end of the queue:
NATIVE_INT_TYPE ret = pthread_cond_signal(queueNotEmpty);
ret = pthread_cond_signal(queueNotEmpty);
FW_ASSERT(ret == 0, errno); // If this fails, something horrible happened.
}
else {
@ -147,7 +147,7 @@ namespace Os {
// If the queue is full, wait until a message is taken off the queue:
while( queue->isFull() ) {
NATIVE_INT_TYPE ret = pthread_cond_wait(queueNotFull, queueLock);
ret = pthread_cond_wait(queueNotFull, queueLock);
FW_ASSERT(ret == 0, errno);
}
@ -227,7 +227,7 @@ namespace Os {
// Pop worked - wake up a thread that might be waiting on
// the send end of the queue:
NATIVE_INT_TYPE ret = pthread_cond_signal(queueNotFull);
ret = pthread_cond_signal(queueNotFull);
FW_ASSERT(ret == 0, errno); // If this fails, something horrible happened.
}
else {
@ -276,7 +276,7 @@ namespace Os {
// If the queue is empty, wait until a message is put on the queue:
while( queue->isEmpty() ) {
NATIVE_INT_TYPE ret = pthread_cond_wait(queueNotEmpty, queueLock);
ret = pthread_cond_wait(queueNotEmpty, queueLock);
FW_ASSERT(ret == 0, errno);
}
@ -290,7 +290,7 @@ namespace Os {
// Pop worked - wake up a thread that might be waiting on
// the send end of the queue:
NATIVE_INT_TYPE ret = pthread_cond_signal(queueNotFull);
ret = pthread_cond_signal(queueNotFull);
FW_ASSERT(ret == 0, errno); // If this fails, something horrible happened.
}
else {

View File

@ -17,11 +17,11 @@ namespace Os {
ValidatedFile ::
ValidatedFile(const char *const fileName) :
fileName(fileName),
hashFileName(""),
hashBuffer()
m_fileName(fileName),
m_hashFileName(""),
m_hashBuffer()
{
Utils::Hash::addFileExtension(this->fileName, this->hashFileName);
Utils::Hash::addFileExtension(this->m_fileName, this->m_hashFileName);
}
Os::ValidateFile::Status ValidatedFile ::
@ -29,9 +29,9 @@ namespace Os {
{
const Os::ValidateFile::Status status =
Os::ValidateFile::validate(
this->fileName.toChar(),
this->hashFileName.toChar(),
this->hashBuffer
this->m_fileName.toChar(),
this->m_hashFileName.toChar(),
this->m_hashBuffer
);
return status;
}
@ -41,9 +41,9 @@ namespace Os {
{
const Os::ValidateFile::Status status =
Os::ValidateFile::createValidation(
this->fileName.toChar(),
this->hashFileName.toChar(),
this->hashBuffer
this->m_fileName.toChar(),
this->m_hashFileName.toChar(),
this->m_hashBuffer
);
return status;
}
@ -51,19 +51,19 @@ namespace Os {
const Fw::StringBase& ValidatedFile ::
getFileName() const
{
return this->fileName;
return this->m_fileName;
}
const Fw::StringBase& ValidatedFile ::
getHashFileName() const
{
return this->hashFileName;
return this->m_hashFileName;
}
const Utils::HashBuffer& ValidatedFile ::
getHashBuffer() const
{
return this->hashBuffer;
return this->m_hashBuffer;
}
}

View File

@ -56,13 +56,13 @@ namespace Os {
PRIVATE:
//! The file name
Fw::String fileName;
Fw::String m_fileName;
//! The hash file name
Fw::String hashFileName;
Fw::String m_hashFileName;
//! The hash value after creating or loading a validation file
Utils::HashBuffer hashBuffer;
Utils::HashBuffer m_hashBuffer;
};
}

View File

@ -57,7 +57,7 @@ target_compile_options("${PROJECT_NAME}" PUBLIC -Wall)
target_compile_options("${PROJECT_NAME}" PUBLIC -Wextra)
target_compile_options("${PROJECT_NAME}" PUBLIC -Werror)
target_compile_options("${PROJECT_NAME}" PUBLIC -pedantic)
#target_compile_options("${PROJECT_NAME}" PUBLIC -Wshadow)
target_compile_options("${PROJECT_NAME}" PUBLIC -Wshadow)
target_compile_options("${PROJECT_NAME}" PUBLIC -Wconversion)
target_compile_options("${PROJECT_NAME}" PUBLIC -Wsign-conversion)
target_compile_options("${PROJECT_NAME}" PUBLIC -Wformat-security)

View File

@ -27,9 +27,9 @@ namespace STest {
//! Construct object Rule
Rule(
const char *const name //!< The name of the rule
const char *const a_name //!< The name of the rule
) :
name(name)
name(a_name)
{
}

View File

@ -22,11 +22,11 @@ namespace Svc {
// ----------------------------------------------------------------------
BufferAccumulator::ArrayFIFOBuffer ::ArrayFIFOBuffer()
: elements(nullptr),
capacity(0),
enqueueIndex(0),
dequeueIndex(0),
size(0)
: m_elements(nullptr),
m_capacity(0),
m_enqueueIndex(0),
m_dequeueIndex(0),
m_size(0)
{
}
@ -38,29 +38,29 @@ BufferAccumulator::ArrayFIFOBuffer ::~ArrayFIFOBuffer() {}
void BufferAccumulator::ArrayFIFOBuffer ::init(Fw::Buffer* const elements,
NATIVE_UINT_TYPE capacity) {
this->elements = elements;
this->capacity = capacity;
this->m_elements = elements;
this->m_capacity = capacity;
// Construct all elements
for (NATIVE_UINT_TYPE idx = 0; idx < capacity; idx++) {
new (&this->elements[idx]) Fw::Buffer;
new (&this->m_elements[idx]) Fw::Buffer;
}
}
bool BufferAccumulator::ArrayFIFOBuffer ::enqueue(const Fw::Buffer& e) {
if (this->elements == nullptr) {
if (this->m_elements == nullptr) {
return false;
}
bool status;
if (this->size < this->capacity) {
if (this->m_size < this->m_capacity) {
// enqueueIndex is unsigned, no need to compare with 0
FW_ASSERT(enqueueIndex < this->capacity, enqueueIndex);
this->elements[this->enqueueIndex] = e;
this->enqueueIndex = (this->enqueueIndex + 1) % this->capacity;
FW_ASSERT(m_enqueueIndex < this->m_capacity, m_enqueueIndex);
this->m_elements[this->m_enqueueIndex] = e;
this->m_enqueueIndex = (this->m_enqueueIndex + 1) % this->m_capacity;
status = true;
this->size++;
this->m_size++;
} else {
status = false;
}
@ -70,19 +70,19 @@ bool BufferAccumulator::ArrayFIFOBuffer ::enqueue(const Fw::Buffer& e) {
bool BufferAccumulator::ArrayFIFOBuffer ::dequeue(Fw::Buffer& e) {
if (this->elements == nullptr) {
if (this->m_elements == nullptr) {
return false;
}
FW_ASSERT(this->elements);
FW_ASSERT(this->m_elements);
bool status;
if (this->size > 0) {
if (this->m_size > 0) {
// dequeueIndex is unsigned, no need to compare with 0
FW_ASSERT(dequeueIndex < this->capacity, dequeueIndex);
e = this->elements[this->dequeueIndex];
this->dequeueIndex = (this->dequeueIndex + 1) % this->capacity;
this->size--;
FW_ASSERT(m_dequeueIndex < this->m_capacity, m_dequeueIndex);
e = this->m_elements[this->m_dequeueIndex];
this->m_dequeueIndex = (this->m_dequeueIndex + 1) % this->m_capacity;
this->m_size--;
status = true;
} else {
status = false;
@ -92,11 +92,11 @@ bool BufferAccumulator::ArrayFIFOBuffer ::dequeue(Fw::Buffer& e) {
}
U32 BufferAccumulator::ArrayFIFOBuffer ::getSize() const {
return this->size;
return this->m_size;
}
U32 BufferAccumulator::ArrayFIFOBuffer ::getCapacity() const {
return this->capacity;
return this->m_capacity;
}
} // namespace Svc

View File

@ -26,17 +26,17 @@ namespace Svc {
BufferAccumulator ::
BufferAccumulator(const char* const compName)
: BufferAccumulatorComponentBase(compName), //!< The component name
mode(BufferAccumulator_OpState::ACCUMULATE),
bufferMemory(nullptr),
bufferQueue(),
send(false),
waitForBuffer(false),
numWarnings(0u),
numDrained(0u),
numToDrain(0u),
opCode(),
cmdSeq(0u),
allocatorId(0) {
m_mode(BufferAccumulator_OpState::ACCUMULATE),
m_bufferMemory(nullptr),
m_bufferQueue(),
m_send(false),
m_waitForBuffer(false),
m_numWarnings(0u),
m_numDrained(0u),
m_numToDrain(0u),
m_opCode(),
m_cmdSeq(0u),
m_allocatorId(0) {
}
void BufferAccumulator ::init(const NATIVE_INT_TYPE queueDepth,
@ -55,17 +55,17 @@ void BufferAccumulator ::allocateQueue(
NATIVE_UINT_TYPE maxNumBuffers //!< The maximum number of buffers
) {
this->allocatorId = identifier;
this->m_allocatorId = identifier;
NATIVE_UINT_TYPE memSize = sizeof(Fw::Buffer) * maxNumBuffers;
bool recoverable = false;
this->bufferMemory = static_cast<Fw::Buffer*>(
this->m_bufferMemory = static_cast<Fw::Buffer*>(
allocator.allocate(identifier, memSize, recoverable));
//TODO: Fail gracefully here
bufferQueue.init(this->bufferMemory, maxNumBuffers);
m_bufferQueue.init(this->m_bufferMemory, maxNumBuffers);
}
void BufferAccumulator ::deallocateQueue(Fw::MemAllocator& allocator) {
allocator.deallocate(this->allocatorId, this->bufferMemory);
allocator.deallocate(this->m_allocatorId, this->m_bufferMemory);
}
// ----------------------------------------------------------------------
@ -75,34 +75,34 @@ void BufferAccumulator ::deallocateQueue(Fw::MemAllocator& allocator) {
void BufferAccumulator ::bufferSendInFill_handler(const NATIVE_INT_TYPE portNum,
Fw::Buffer& buffer) {
const bool status = this->bufferQueue.enqueue(buffer);
const bool status = this->m_bufferQueue.enqueue(buffer);
if (status) {
if (this->numWarnings > 0) {
if (this->m_numWarnings > 0) {
this->log_ACTIVITY_HI_BA_BufferAccepted();
}
this->numWarnings = 0;
this->m_numWarnings = 0;
} else {
if (this->numWarnings == 0) {
if (this->m_numWarnings == 0) {
this->log_WARNING_HI_BA_QueueFull();
}
numWarnings++;
m_numWarnings++;
}
if (this->send) {
if (this->m_send) {
this->sendStoredBuffer();
}
this->tlmWrite_BA_NumQueuedBuffers(this->bufferQueue.getSize());
this->tlmWrite_BA_NumQueuedBuffers(this->m_bufferQueue.getSize());
}
void BufferAccumulator ::bufferSendInReturn_handler(
const NATIVE_INT_TYPE portNum, Fw::Buffer& buffer) {
this->bufferSendOutReturn_out(0, buffer);
this->waitForBuffer = false;
if ((this->mode == BufferAccumulator_OpState::DRAIN) || // we are draining ALL buffers
(this->numDrained < this->numToDrain)) { // OR we aren't done draining some buffers
this->m_waitForBuffer = false;
if ((this->m_mode == BufferAccumulator_OpState::DRAIN) || // we are draining ALL buffers
(this->m_numDrained < this->m_numToDrain)) { // OR we aren't done draining some buffers
// in a partial drain
this->send = true;
this->m_send = true;
this->sendStoredBuffer();
}
}
@ -121,22 +121,22 @@ void BufferAccumulator ::BA_SetMode_cmdHandler(const FwOpcodeType opCode,
BufferAccumulator_OpState mode) {
// cancel an in-progress partial drain
if (this->numToDrain > 0) {
if (this->m_numToDrain > 0) {
// reset counters for partial buffer drain
this->numToDrain = 0;
this->numDrained = 0;
this->m_numToDrain = 0;
this->m_numDrained = 0;
// respond to the original command
this->cmdResponse_out(this->opCode, this->cmdSeq, Fw::CmdResponse::OK);
this->cmdResponse_out(this->m_opCode, this->m_cmdSeq, Fw::CmdResponse::OK);
}
this->mode = mode;
this->m_mode = mode;
if (mode == BufferAccumulator_OpState::DRAIN) {
if (!this->waitForBuffer) {
this->send = true;
if (!this->m_waitForBuffer) {
this->m_send = true;
this->sendStoredBuffer();
}
} else {
this->send = false;
this->m_send = false;
}
this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
}
@ -145,13 +145,13 @@ void BufferAccumulator ::BA_DrainBuffers_cmdHandler(
const FwOpcodeType opCode, const U32 cmdSeq, U32 numToDrain,
BufferAccumulator_BlockMode blockMode) {
if (this->numDrained < this->numToDrain) {
this->log_WARNING_HI_BA_StillDraining(this->numDrained, this->numToDrain);
if (this->m_numDrained < this->m_numToDrain) {
this->log_WARNING_HI_BA_StillDraining(this->m_numDrained, this->m_numToDrain);
this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::BUSY);
return;
}
if (this->mode == BufferAccumulator_OpState::DRAIN) {
if (this->m_mode == BufferAccumulator_OpState::DRAIN) {
this->log_WARNING_HI_BA_AlreadyDraining();
this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::VALIDATION_ERROR);
return;
@ -163,23 +163,23 @@ void BufferAccumulator ::BA_DrainBuffers_cmdHandler(
return;
}
this->opCode = opCode;
this->cmdSeq = cmdSeq;
this->numDrained = 0;
this->numToDrain = numToDrain;
this->m_opCode = opCode;
this->m_cmdSeq = cmdSeq;
this->m_numDrained = 0;
this->m_numToDrain = numToDrain;
if (blockMode == BufferAccumulator_BlockMode::NOBLOCK) {
U32 numBuffers = this->bufferQueue.getSize();
U32 numBuffers = this->m_bufferQueue.getSize();
if (numBuffers < numToDrain) {
this->numToDrain = numBuffers;
this->log_WARNING_LO_BA_NonBlockDrain(this->numToDrain, numToDrain);
this->m_numToDrain = numBuffers;
this->log_WARNING_LO_BA_NonBlockDrain(this->m_numToDrain, numToDrain);
}
/* OK if there were 0 buffers queued, and we
* end up setting numToDrain to 0
*/
if (0 == this->numToDrain) {
if (0 == this->m_numToDrain) {
this->log_ACTIVITY_HI_BA_PartialDrainDone(0);
this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
return;
@ -187,8 +187,8 @@ void BufferAccumulator ::BA_DrainBuffers_cmdHandler(
}
// We are still waiting for a buffer from last time
if (!this->waitForBuffer) {
this->send = true;
if (!this->m_waitForBuffer) {
this->m_send = true;
this->sendStoredBuffer(); // kick off the draining;
}
}
@ -199,19 +199,19 @@ void BufferAccumulator ::BA_DrainBuffers_cmdHandler(
void BufferAccumulator ::sendStoredBuffer() {
FW_ASSERT(this->send);
FW_ASSERT(this->m_send);
Fw::Buffer buffer;
if ((this->numToDrain == 0) || // we are draining ALL buffers
(this->numDrained < this->numToDrain)) { // OR we aren't done draining some buffers in a
if ((this->m_numToDrain == 0) || // we are draining ALL buffers
(this->m_numDrained < this->m_numToDrain)) { // OR we aren't done draining some buffers in a
// partial drain
const bool status = this->bufferQueue.dequeue(buffer);
const bool status = this->m_bufferQueue.dequeue(buffer);
if (status) { // a buffer was dequeued
this->numDrained++;
this->m_numDrained++;
this->bufferSendOutDrain_out(0, buffer);
this->waitForBuffer = true;
this->send = false;
} else if (this->numToDrain > 0) {
this->log_WARNING_HI_BA_DrainStalled(this->numDrained, this->numToDrain);
this->m_waitForBuffer = true;
this->m_send = false;
} else if (this->m_numToDrain > 0) {
this->log_WARNING_HI_BA_DrainStalled(this->m_numDrained, this->m_numToDrain);
}
}
@ -219,18 +219,18 @@ void BufferAccumulator ::sendStoredBuffer() {
* drained buffers in a partial drain to be RETURNED before returning OK.
* Correct thing is to return OK once they are SENT
*/
if ((this->numToDrain > 0) && // we are doing a partial drain
(this->numDrained == this->numToDrain)) { // AND we just finished draining
if ((this->m_numToDrain > 0) && // we are doing a partial drain
(this->m_numDrained == this->m_numToDrain)) { // AND we just finished draining
//
this->log_ACTIVITY_HI_BA_PartialDrainDone(this->numDrained);
this->log_ACTIVITY_HI_BA_PartialDrainDone(this->m_numDrained);
// reset counters for partial buffer drain
this->numToDrain = 0;
this->numDrained = 0;
this->send = false;
this->cmdResponse_out(this->opCode, this->cmdSeq, Fw::CmdResponse::OK);
this->m_numToDrain = 0;
this->m_numDrained = 0;
this->m_send = false;
this->cmdResponse_out(this->m_opCode, this->m_cmdSeq, Fw::CmdResponse::OK);
}
this->tlmWrite_BA_NumQueuedBuffers(this->bufferQueue.getSize());
this->tlmWrite_BA_NumQueuedBuffers(this->m_bufferQueue.getSize());
}
} // namespace Svc

View File

@ -66,19 +66,19 @@ namespace Svc {
// ----------------------------------------------------------------------
//! The memory for the elements
Fw::Buffer* elements;
Fw::Buffer* m_elements;
//! The capacity of the queue
NATIVE_UINT_TYPE capacity;
NATIVE_UINT_TYPE m_capacity;
//! The enqueue index
NATIVE_UINT_TYPE enqueueIndex;
NATIVE_UINT_TYPE m_enqueueIndex;
//! The dequeue index
NATIVE_UINT_TYPE dequeueIndex;
NATIVE_UINT_TYPE m_dequeueIndex;
//! The size of the queue
NATIVE_UINT_TYPE size;
NATIVE_UINT_TYPE m_size;
}; // class ArrayFIFOBuffer
public:
@ -178,39 +178,39 @@ namespace Svc {
// ----------------------------------------------------------------------
//! The mode
BufferAccumulator_OpState mode;
BufferAccumulator_OpState m_mode;
//! Memory for the buffer array
Fw::Buffer* bufferMemory;
Fw::Buffer* m_bufferMemory;
//! The FIFO queue of buffers
ArrayFIFOBuffer bufferQueue;
ArrayFIFOBuffer m_bufferQueue;
//! Whether to send a buffer to the downstream client
bool send;
bool m_send;
//! If we are switched to ACCUMULATE then back to DRAIN, whether we were
//! waiting on a buffer
bool waitForBuffer;
bool m_waitForBuffer;
//! The number of QueueFull warnings sent since the last successful enqueue
//! operation
U32 numWarnings;
U32 m_numWarnings;
//! The number of buffers drained in a partial drain command
U32 numDrained;
U32 m_numDrained;
//! The number of buffers TO drain in a partial drain command
U32 numToDrain;
U32 m_numToDrain;
//! The DrainBuffers opcode to respond to
FwOpcodeType opCode;
FwOpcodeType m_opCode;
//! The DrainBuffers cmdSeq to respond to
U32 cmdSeq;
U32 m_cmdSeq;
//! The allocator ID
NATIVE_INT_TYPE allocatorId;
NATIVE_INT_TYPE m_allocatorId;
};
} // namespace Svc

View File

@ -116,37 +116,37 @@ namespace Svc {
PRIVATE:
//! The enclosing BufferLogger instance
BufferLogger& bufferLogger;
BufferLogger& m_bufferLogger;
//! The prefix to use for file names
Fw::String prefix;
Fw::String m_prefix;
//! The suffix to use for file names
Fw::String suffix;
Fw::String m_suffix;
//! The file name base
Fw::String baseName;
Fw::String m_baseName;
//! The counter to use for the same file name
NATIVE_UINT_TYPE fileCounter;
NATIVE_UINT_TYPE m_fileCounter;
//! The maximum file size
U32 maxSize;
U32 m_maxSize;
//! The number of bytes to use when storing the size field at the start of each buffer
U8 sizeOfSize;
U8 m_sizeOfSize;
//! The name of the currently open file
Fw::String name;
Fw::String m_name;
// The current mode
Mode::t mode;
Mode::t m_mode;
//! The underlying Os::File representation
Os::File osFile;
Os::File m_osFile;
//! The number of bytes written to the current file
U32 bytesWritten;
U32 m_bytesWritten;
}; // class File

View File

@ -24,15 +24,15 @@ namespace Svc {
File(
BufferLogger& bufferLogger
) :
bufferLogger(bufferLogger),
prefix(""),
suffix(""),
baseName(""),
fileCounter(0),
maxSize(0),
sizeOfSize(0),
mode(Mode::CLOSED),
bytesWritten(0)
m_bufferLogger(bufferLogger),
m_prefix(""),
m_suffix(""),
m_baseName(""),
m_fileCounter(0),
m_maxSize(0),
m_sizeOfSize(0),
m_mode(Mode::CLOSED),
m_bytesWritten(0)
{
}
@ -55,15 +55,15 @@ namespace Svc {
)
{
//NOTE(mereweth) - only call this before opening the file
FW_ASSERT(this->mode == File::Mode::CLOSED);
FW_ASSERT(this->m_mode == File::Mode::CLOSED);
this->prefix = logFilePrefix;
this->suffix = logFileSuffix;
this->maxSize = maxFileSize;
this->sizeOfSize = sizeOfSize;
this->m_prefix = logFilePrefix;
this->m_suffix = logFileSuffix;
this->m_maxSize = maxFileSize;
this->m_sizeOfSize = sizeOfSize;
FW_ASSERT(sizeOfSize <= sizeof(U32), sizeOfSize);
FW_ASSERT(maxSize > sizeOfSize, maxSize);
FW_ASSERT(m_maxSize > sizeOfSize, m_maxSize);
}
void BufferLogger::File ::
@ -71,11 +71,11 @@ namespace Svc {
const Fw::StringBase& baseName
)
{
if (this->mode == File::Mode::OPEN) {
if (this->m_mode == File::Mode::OPEN) {
this->closeAndEmitEvent();
}
this->baseName = baseName;
this->fileCounter = 0;
this->m_baseName = baseName;
this->m_fileCounter = 0;
this->open();
}
@ -86,19 +86,19 @@ namespace Svc {
)
{
// Close the file if it will be too big
if (this->mode == File::Mode::OPEN) {
if (this->m_mode == File::Mode::OPEN) {
const U32 projectedByteCount =
this->bytesWritten + this->sizeOfSize + size;
if (projectedByteCount > this->maxSize) {
this->m_bytesWritten + this->m_sizeOfSize + size;
if (projectedByteCount > this->m_maxSize) {
this->closeAndEmitEvent();
}
}
// Open a file if necessary
if (this->mode == File::Mode::CLOSED) {
if (this->m_mode == File::Mode::CLOSED) {
this->open();
}
// Write to the file if it is open
if (this->mode == File::Mode::OPEN) {
if (this->m_mode == File::Mode::OPEN) {
(void) this->writeBuffer(data, size);
}
}
@ -106,10 +106,10 @@ namespace Svc {
void BufferLogger::File ::
closeAndEmitEvent()
{
if (this->mode == File::Mode::OPEN) {
if (this->m_mode == File::Mode::OPEN) {
this->close();
Fw::LogStringArg logStringArg(this->name.toChar());
this->bufferLogger.log_DIAGNOSTIC_BL_LogFileClosed(logStringArg);
Fw::LogStringArg logStringArg(this->m_name.toChar());
this->m_bufferLogger.log_DIAGNOSTIC_BL_LogFileClosed(logStringArg);
}
}
@ -120,48 +120,48 @@ namespace Svc {
void BufferLogger::File ::
open()
{
FW_ASSERT(this->mode == File::Mode::CLOSED);
FW_ASSERT(this->m_mode == File::Mode::CLOSED);
// NOTE(mereweth) - check that file path has been set and that initLog has been called
if ((this->baseName.toChar()[0] == '\0') ||
(this->sizeOfSize > sizeof(U32)) ||
(this->maxSize <= this->sizeOfSize)) {
this->bufferLogger.log_WARNING_HI_BL_NoLogFileOpenInitError();
if ((this->m_baseName.toChar()[0] == '\0') ||
(this->m_sizeOfSize > sizeof(U32)) ||
(this->m_maxSize <= this->m_sizeOfSize)) {
this->m_bufferLogger.log_WARNING_HI_BL_NoLogFileOpenInitError();
return;
}
if (this->fileCounter == 0) {
this->name.format(
if (this->m_fileCounter == 0) {
this->m_name.format(
"%s%s%s",
this->prefix.toChar(),
this->baseName.toChar(),
this->suffix.toChar()
this->m_prefix.toChar(),
this->m_baseName.toChar(),
this->m_suffix.toChar()
);
}
else {
this->name.format(
this->m_name.format(
"%s%s%d%s",
this->prefix.toChar(),
this->baseName.toChar(),
this->fileCounter,
this->suffix.toChar()
this->m_prefix.toChar(),
this->m_baseName.toChar(),
this->m_fileCounter,
this->m_suffix.toChar()
);
}
const Os::File::Status status = this->osFile.open(
this->name.toChar(),
const Os::File::Status status = this->m_osFile.open(
this->m_name.toChar(),
Os::File::OPEN_WRITE
);
if (status == Os::File::OP_OK) {
this->fileCounter++;
this->m_fileCounter++;
// Reset bytes written
this->bytesWritten = 0;
this->m_bytesWritten = 0;
// Set mode
this->mode = File::Mode::OPEN;
this->m_mode = File::Mode::OPEN;
}
else {
Fw::LogStringArg string(this->name.toChar());
this->bufferLogger.log_WARNING_HI_BL_LogFileOpenError(status, string);
Fw::LogStringArg string(this->m_name.toChar());
this->m_bufferLogger.log_WARNING_HI_BL_LogFileOpenError(status, string);
}
}
@ -181,16 +181,16 @@ namespace Svc {
bool BufferLogger::File ::
writeSize(const U32 size)
{
FW_ASSERT(this->sizeOfSize <= sizeof(U32));
FW_ASSERT(this->m_sizeOfSize <= sizeof(U32));
U8 sizeBuffer[sizeof(U32)];
U32 sizeRegister = size;
for (U8 i = 0; i < this->sizeOfSize; ++i) {
sizeBuffer[this->sizeOfSize - i - 1] = sizeRegister & 0xFF;
for (U8 i = 0; i < this->m_sizeOfSize; ++i) {
sizeBuffer[this->m_sizeOfSize - i - 1] = sizeRegister & 0xFF;
sizeRegister >>= 8;
}
const bool status = this->writeBytes(
sizeBuffer,
this->sizeOfSize
this->m_sizeOfSize
);
return status;
}
@ -203,16 +203,16 @@ namespace Svc {
{
FW_ASSERT(length > 0, length);
NATIVE_INT_TYPE size = length;
const Os::File::Status fileStatus = this->osFile.write(data, size);
const Os::File::Status fileStatus = this->m_osFile.write(data, size);
bool status;
if (fileStatus == Os::File::OP_OK && size == static_cast<NATIVE_INT_TYPE>(length)) {
this->bytesWritten += length;
this->m_bytesWritten += length;
status = true;
}
else {
Fw::LogStringArg string(this->name.toChar());
Fw::LogStringArg string(this->m_name.toChar());
this->bufferLogger.log_WARNING_HI_BL_LogFileWriteError(fileStatus, size, length, string);
this->m_bufferLogger.log_WARNING_HI_BL_LogFileWriteError(fileStatus, size, length, string);
status = false;
}
return status;
@ -221,13 +221,13 @@ namespace Svc {
void BufferLogger::File ::
writeHashFile()
{
Os::ValidatedFile validatedFile(this->name.toChar());
Os::ValidatedFile validatedFile(this->m_name.toChar());
const Os::ValidateFile::Status status =
validatedFile.createHashFile();
if (status != Os::ValidateFile::VALIDATION_OK) {
const Fw::String &hashFileName = validatedFile.getHashFileName();
Fw::LogStringArg logStringArg(hashFileName.toChar());
this->bufferLogger.log_WARNING_HI_BL_LogFileValidationError(
this->m_bufferLogger.log_WARNING_HI_BL_LogFileValidationError(
logStringArg,
status
);
@ -258,13 +258,13 @@ namespace Svc {
void BufferLogger::File ::
close()
{
if (this->mode == File::Mode::OPEN) {
if (this->m_mode == File::Mode::OPEN) {
// Close file
this->osFile.close();
this->m_osFile.close();
// Write out the hash file to disk
this->writeHashFile();
// Update mode
this->mode = File::Mode::CLOSED;
this->m_mode = File::Mode::CLOSED;
}
}

View File

@ -64,7 +64,7 @@ namespace Svc {
void BufferLoggerTester ::
LogNoInit()
{
this->component.m_file.baseName = Fw::String("LogNoInit");
this->component.m_file.m_baseName = Fw::String("LogNoInit");
// NOTE (mereweth) - make something sensible happen when no-one calls initLog()
// Send data
this->sendComBuffers(3);

View File

@ -25,10 +25,10 @@ namespace Svc {
// Remove buf directory
(void) system("rm -rf buf");
this->component.m_file.baseName = Fw::String("LogFileOpen");
this->component.m_file.m_baseName = Fw::String("LogFileOpen");
// Check initial state
ASSERT_EQ(BufferLogger::File::Mode::CLOSED, this->component.m_file.mode);
ASSERT_EQ(BufferLogger::File::Mode::CLOSED, this->component.m_file.m_mode);
ASSERT_EVENTS_SIZE(0);
// Send data
@ -42,13 +42,13 @@ namespace Svc {
ASSERT_EVENTS_BL_LogFileOpenError(
i,
Os::File::DOESNT_EXIST,
this->component.m_file.name.toChar()
this->component.m_file.m_name.toChar()
);
}
// Create buf directory and try again
(void) system("mkdir buf");
ASSERT_EQ(BufferLogger::File::Mode::CLOSED, this->component.m_file.mode);
ASSERT_EQ(BufferLogger::File::Mode::CLOSED, this->component.m_file.m_mode);
// Send data
this->sendComBuffers(3);
@ -61,7 +61,7 @@ namespace Svc {
// Remove buf directory and try again
(void) system("rm -rf buf");
ASSERT_EQ(BufferLogger::File::Mode::CLOSED, this->component.m_file.mode);
ASSERT_EQ(BufferLogger::File::Mode::CLOSED, this->component.m_file.m_mode);
// Send data
this->sendComBuffers(3);
@ -74,7 +74,7 @@ namespace Svc {
ASSERT_EVENTS_BL_LogFileOpenError(
i,
Os::File::DOESNT_EXIST,
this->component.m_file.name.toChar()
this->component.m_file.m_name.toChar()
);
}
@ -83,16 +83,16 @@ namespace Svc {
void BufferLoggerTester ::
LogFileWrite()
{
ASSERT_EQ(BufferLogger::File::Mode::CLOSED, this->component.m_file.mode);
ASSERT_EQ(BufferLogger::File::Mode::CLOSED, this->component.m_file.m_mode);
ASSERT_EVENTS_SIZE(0);
this->component.m_file.baseName = Fw::String("LogFileWrite");
this->component.m_file.m_baseName = Fw::String("LogFileWrite");
// Send data
this->sendComBuffers(1);
// Force close the file
this->component.m_file.osFile.close();
this->component.m_file.m_osFile.close();
// Send data
this->sendComBuffers(1);
@ -101,9 +101,9 @@ namespace Svc {
Fw::String fileName;
fileName.format(
"%s%s%s",
this->component.m_file.prefix.toChar(),
this->component.m_file.baseName.toChar(),
this->component.m_file.suffix.toChar()
this->component.m_file.m_prefix.toChar(),
this->component.m_file.m_baseName.toChar(),
this->component.m_file.m_suffix.toChar()
);
// Check events
@ -119,16 +119,16 @@ namespace Svc {
);
// Make comlogger open a new file:
this->component.m_file.mode = BufferLogger::File::Mode::CLOSED;
this->component.m_file.m_mode = BufferLogger::File::Mode::CLOSED;
this->component.m_file.open();
// NOTE(mereweth) - new file; counter has incremented
fileName.format(
"%s%s%d%s",
this->component.m_file.prefix.toChar(),
this->component.m_file.baseName.toChar(),
this->component.m_file.m_prefix.toChar(),
this->component.m_file.m_baseName.toChar(),
1,
this->component.m_file.suffix.toChar()
this->component.m_file.m_suffix.toChar()
);
// Try to write and make sure it succeeds
@ -140,7 +140,7 @@ namespace Svc {
ASSERT_EVENTS_BL_LogFileWriteError_SIZE(1);
// Force close the file from underneath the component
component.m_file.osFile.close();
component.m_file.m_osFile.close();
// Send data
this->sendComBuffers(3);
@ -164,7 +164,7 @@ namespace Svc {
void BufferLoggerTester ::
LogFileValidation()
{
this->component.m_file.baseName = Fw::String("LogFileValidation");
this->component.m_file.m_baseName = Fw::String("LogFileValidation");
// Send data
this->sendComBuffers(1);
@ -178,9 +178,9 @@ namespace Svc {
Fw::String fileName;
fileName.format(
"%s%s%s",
this->component.m_file.prefix.toChar(),
this->component.m_file.baseName.toChar(),
this->component.m_file.suffix.toChar()
this->component.m_file.m_prefix.toChar(),
this->component.m_file.m_baseName.toChar(),
this->component.m_file.m_suffix.toChar()
);
ASSERT_EVENTS_BL_LogFileClosed(
0,

View File

@ -52,7 +52,7 @@ namespace Svc {
//! Check that files exist
void checkFilesExist() {
const Fw::String& fileName = this->component.m_file.name;
const Fw::String& fileName = this->component.m_file.m_name;
this->checkFileExists(fileName);
this->checkHashFileExists(fileName);
}
@ -60,14 +60,14 @@ namespace Svc {
public:
void test() {
this->component.m_file.baseName = Fw::String("CloseFileTester");
this->component.m_file.m_baseName = Fw::String("CloseFileTester");
ASSERT_EVENTS_SIZE(0);
this->sendCloseFileCommands(3);
this->sendComBuffers(3);
this->sendCloseFileCommands(3);
ASSERT_EVENTS_SIZE(1);
ASSERT_EVENTS_BL_LogFileClosed_SIZE(1);
ASSERT_EVENTS_BL_LogFileClosed(0, component.m_file.name.toChar());
ASSERT_EVENTS_BL_LogFileClosed(0, component.m_file.m_name.toChar());
this->checkFilesExist();
}
@ -104,32 +104,32 @@ namespace Svc {
Fw::String currentFileName;
currentFileName.format(
"%s%s%s",
this->component.m_file.prefix.toChar(),
this->component.m_file.m_prefix.toChar(),
baseName,
this->component.m_file.suffix.toChar()
this->component.m_file.m_suffix.toChar()
);
this->sendBuffers(1);
// 0th event has already happened (file open)
for (U32 i = 1; i < numFiles+1; ++i) {
// File was just created and name set
ASSERT_EQ(currentFileName, this->component.m_file.name);
ASSERT_EQ(currentFileName, this->component.m_file.m_name);
// Write data to the file
this->sendBuffers(MAX_ENTRIES_PER_FILE-1);
// File still should have same name
ASSERT_EQ(currentFileName, this->component.m_file.name);
ASSERT_EQ(currentFileName, this->component.m_file.m_name);
// Send more data
// This should open a new file with the updated counter
this->sendBuffers(1);
currentFileName.format(
"%s%s%d%s",
this->component.m_file.prefix.toChar(),
this->component.m_file.m_prefix.toChar(),
baseName,
i,
this->component.m_file.suffix.toChar()
this->component.m_file.m_suffix.toChar()
);
// Assert file state
ASSERT_EQ(BufferLogger::File::Mode::OPEN, component.m_file.mode);
ASSERT_EQ(currentFileName, this->component.m_file.name);
ASSERT_EQ(BufferLogger::File::Mode::OPEN, component.m_file.m_mode);
ASSERT_EQ(currentFileName, this->component.m_file.m_name);
// Assert events
ASSERT_EVENTS_SIZE(i);
ASSERT_EVENTS_BL_LogFileClosed_SIZE(i);
@ -146,18 +146,18 @@ namespace Svc {
if (i == 0) {
fileName.format(
"%s%s%s",
this->component.m_file.prefix.toChar(),
this->component.m_file.m_prefix.toChar(),
baseName,
this->component.m_file.suffix.toChar()
this->component.m_file.m_suffix.toChar()
);
}
else {
fileName.format(
"%s%s%d%s",
this->component.m_file.prefix.toChar(),
this->component.m_file.m_prefix.toChar(),
baseName,
i,
this->component.m_file.suffix.toChar()
this->component.m_file.m_suffix.toChar()
);
}
// Check events
@ -240,11 +240,11 @@ namespace Svc {
//! Test logging on
void testLoggingOn() {
this->component.m_file.baseName = Fw::String("OnOffTester");
this->component.m_file.m_baseName = Fw::String("OnOffTester");
this->sendData();
this->setState(BufferLogger_LogState::LOGGING_OFF);
this->checkLogFileIntegrity(
this->component.m_file.name.toChar(),
this->component.m_file.m_name.toChar(),
MAX_BYTES_PER_FILE,
MAX_ENTRIES_PER_FILE
);

View File

@ -20,13 +20,13 @@ namespace Svc {
ComLogger ::
ComLogger(const char* compName, const char* incomingFilePrefix, U32 maxFileSize, bool storeBufferLength) :
ComLoggerComponentBase(compName),
maxFileSize(maxFileSize),
fileMode(CLOSED),
byteCount(0),
writeErrorOccurred(false),
openErrorOccurred(false),
storeBufferLength(storeBufferLength),
initialized(true)
m_maxFileSize(maxFileSize),
m_fileMode(CLOSED),
m_byteCount(0),
m_writeErrorOccurred(false),
m_openErrorOccurred(false),
m_storeBufferLength(storeBufferLength),
m_initialized(true)
{
this->init_log_file(incomingFilePrefix, maxFileSize, storeBufferLength);
}
@ -34,16 +34,16 @@ namespace Svc {
ComLogger ::
ComLogger(const char* compName) :
ComLoggerComponentBase(compName),
filePrefix(),
maxFileSize(0),
fileMode(CLOSED),
fileName(),
hashFileName(),
byteCount(0),
writeErrorOccurred(false),
openErrorOccurred(false),
storeBufferLength(),
initialized(false)
m_filePrefix(),
m_maxFileSize(0),
m_fileMode(CLOSED),
m_fileName(),
m_hashFileName(),
m_byteCount(0),
m_writeErrorOccurred(false),
m_openErrorOccurred(false),
m_storeBufferLength(),
m_initialized(false)
{
}
@ -61,18 +61,18 @@ namespace Svc {
init_log_file(const char* incomingFilePrefix, U32 maxFileSize, bool storeBufferLength)
{
FW_ASSERT(incomingFilePrefix != nullptr);
this->maxFileSize = maxFileSize;
this->storeBufferLength = storeBufferLength;
if( this->storeBufferLength ) {
this->m_maxFileSize = maxFileSize;
this->m_storeBufferLength = storeBufferLength;
if( this->m_storeBufferLength ) {
FW_ASSERT(maxFileSize > sizeof(U16), maxFileSize);
}
FW_ASSERT(Fw::StringUtils::string_length(incomingFilePrefix, sizeof(this->filePrefix)) < sizeof(this->filePrefix),
Fw::StringUtils::string_length(incomingFilePrefix, sizeof(this->filePrefix)), sizeof(this->filePrefix)); // ensure that file prefix is not too big
FW_ASSERT(Fw::StringUtils::string_length(incomingFilePrefix, sizeof(this->m_filePrefix)) < sizeof(this->m_filePrefix),
Fw::StringUtils::string_length(incomingFilePrefix, sizeof(this->m_filePrefix)), sizeof(this->m_filePrefix)); // ensure that file prefix is not too big
(void)Fw::StringUtils::string_copy(this->filePrefix, incomingFilePrefix, sizeof(this->filePrefix));
(void)Fw::StringUtils::string_copy(this->m_filePrefix, incomingFilePrefix, sizeof(this->m_filePrefix));
this->initialized = true;
this->m_initialized = true;
}
@ -85,15 +85,15 @@ namespace Svc {
// in the destructor. This can cause "virtual method called" segmentation
// faults.
// So I am copying part of that function here.
if( OPEN == this->fileMode ) {
if( OPEN == this->m_fileMode ) {
// Close file:
this->file.close();
this->m_file.close();
// Write out the hash file to disk:
this->writeHashFile();
// Update mode:
this->fileMode = CLOSED;
this->m_fileMode = CLOSED;
// Send event:
//Fw::LogStringArg logStringArg((char*) fileName);
@ -122,23 +122,23 @@ namespace Svc {
U16 size = size32 & 0xFFFF;
// Close the file if it will be too big:
if( OPEN == this->fileMode ) {
U32 projectedByteCount = this->byteCount + size;
if( this->storeBufferLength ) {
if( OPEN == this->m_fileMode ) {
U32 projectedByteCount = this->m_byteCount + size;
if( this->m_storeBufferLength ) {
projectedByteCount += sizeof(size);
}
if( projectedByteCount > this->maxFileSize ) {
if( projectedByteCount > this->m_maxFileSize ) {
this->closeFile();
}
}
// Open the file if it there is not one open:
if( CLOSED == this->fileMode ){
if( CLOSED == this->m_fileMode ){
this->openFile();
}
// Write to the file if it is open:
if( OPEN == this->fileMode ) {
if( OPEN == this->m_fileMode ) {
this->writeComBufferToFile(data, size);
}
}
@ -167,9 +167,9 @@ namespace Svc {
openFile(
)
{
FW_ASSERT( CLOSED == this->fileMode );
FW_ASSERT( CLOSED == this->m_fileMode );
if( !this->initialized ){
if( !this->m_initialized ){
this->log_WARNING_LO_FileNotInitialized();
return;
}
@ -178,36 +178,36 @@ namespace Svc {
// Create filename:
Fw::Time timestamp = getTime();
memset(this->fileName, 0, sizeof(this->fileName));
bytesCopied = snprintf(this->fileName, sizeof(this->fileName), "%s_%" PRI_FwTimeBaseStoreType "_%" PRIu32 "_%06" PRIu32 ".com",
this->filePrefix, static_cast<FwTimeBaseStoreType>(timestamp.getTimeBase()), timestamp.getSeconds(), timestamp.getUSeconds());
memset(this->m_fileName, 0, sizeof(this->m_fileName));
bytesCopied = snprintf(this->m_fileName, sizeof(this->m_fileName), "%s_%" PRI_FwTimeBaseStoreType "_%" PRIu32 "_%06" PRIu32 ".com",
this->m_filePrefix, static_cast<FwTimeBaseStoreType>(timestamp.getTimeBase()), timestamp.getSeconds(), timestamp.getUSeconds());
// "A return value of size or more means that the output was truncated"
// See here: http://linux.die.net/man/3/snprintf
FW_ASSERT( bytesCopied < sizeof(this->fileName) );
FW_ASSERT( bytesCopied < sizeof(this->m_fileName) );
// Create sha filename:
bytesCopied = snprintf(this->hashFileName, sizeof(this->hashFileName), "%s_%" PRI_FwTimeBaseStoreType "_%" PRIu32 "_%06" PRIu32 ".com%s",
this->filePrefix, static_cast<FwTimeBaseStoreType>(timestamp.getTimeBase()), timestamp.getSeconds(), timestamp.getUSeconds(), Utils::Hash::getFileExtensionString());
FW_ASSERT( bytesCopied < sizeof(this->hashFileName) );
bytesCopied = snprintf(this->m_hashFileName, sizeof(this->m_hashFileName), "%s_%" PRI_FwTimeBaseStoreType "_%" PRIu32 "_%06" PRIu32 ".com%s",
this->m_filePrefix, static_cast<FwTimeBaseStoreType>(timestamp.getTimeBase()), timestamp.getSeconds(), timestamp.getUSeconds(), Utils::Hash::getFileExtensionString());
FW_ASSERT( bytesCopied < sizeof(this->m_hashFileName) );
Os::File::Status ret = file.open(this->fileName, Os::File::OPEN_WRITE);
Os::File::Status ret = m_file.open(this->m_fileName, Os::File::OPEN_WRITE);
if( Os::File::OP_OK != ret ) {
if( !this->openErrorOccurred ) { // throttle this event, otherwise a positive
if( !this->m_openErrorOccurred ) { // throttle this event, otherwise a positive
// feedback event loop can occur!
Fw::LogStringArg logStringArg(this->fileName);
Fw::LogStringArg logStringArg(this->m_fileName);
this->log_WARNING_HI_FileOpenError(ret, logStringArg);
}
this->openErrorOccurred = true;
this->m_openErrorOccurred = true;
} else {
// Reset event throttle:
this->openErrorOccurred = false;
this->m_openErrorOccurred = false;
// Reset byte count:
this->byteCount = 0;
this->m_byteCount = 0;
// Set mode:
this->fileMode = OPEN;
this->m_fileMode = OPEN;
}
}
@ -215,18 +215,18 @@ namespace Svc {
closeFile(
)
{
if( OPEN == this->fileMode ) {
if( OPEN == this->m_fileMode ) {
// Close file:
this->file.close();
this->m_file.close();
// Write out the hash file to disk:
this->writeHashFile();
// Update mode:
this->fileMode = CLOSED;
this->m_fileMode = CLOSED;
// Send event:
Fw::LogStringArg logStringArg(this->fileName);
Fw::LogStringArg logStringArg(this->m_fileName);
this->log_DIAGNOSTIC_FileClosed(logStringArg);
}
}
@ -237,13 +237,13 @@ namespace Svc {
U16 size
)
{
if( this->storeBufferLength ) {
if( this->m_storeBufferLength ) {
U8 buffer[sizeof(size)];
Fw::SerialBuffer serialLength(&buffer[0], sizeof(size));
serialLength.serialize(size);
if(this->writeToFile(serialLength.getBuffAddr(),
static_cast<U16>(serialLength.getBuffLength()))) {
this->byteCount += serialLength.getBuffLength();
this->m_byteCount += serialLength.getBuffLength();
}
else {
return;
@ -252,7 +252,7 @@ namespace Svc {
// Write buffer to file:
if(this->writeToFile(data.getBuffAddr(), size)) {
this->byteCount += size;
this->m_byteCount += size;
}
}
@ -263,18 +263,18 @@ namespace Svc {
)
{
NATIVE_INT_TYPE size = length;
Os::File::Status ret = file.write(data, size);
Os::File::Status ret = m_file.write(data, size);
if( Os::File::OP_OK != ret || size != static_cast<NATIVE_INT_TYPE>(length) ) {
if( !this->writeErrorOccurred ) { // throttle this event, otherwise a positive
if( !this->m_writeErrorOccurred ) { // throttle this event, otherwise a positive
// feedback event loop can occur!
Fw::LogStringArg logStringArg(this->fileName);
Fw::LogStringArg logStringArg(this->m_fileName);
this->log_WARNING_HI_FileWriteError(ret, size, length, logStringArg);
}
this->writeErrorOccurred = true;
this->m_writeErrorOccurred = true;
return false;
}
this->writeErrorOccurred = false;
this->m_writeErrorOccurred = false;
return true;
}
@ -283,10 +283,10 @@ namespace Svc {
)
{
Os::ValidateFile::Status validateStatus;
validateStatus = Os::ValidateFile::createValidation(this->fileName, this->hashFileName);
validateStatus = Os::ValidateFile::createValidation(this->m_fileName, this->m_hashFileName);
if( Os::ValidateFile::VALIDATION_OK != validateStatus ) {
Fw::LogStringArg logStringArg1(this->fileName);
Fw::LogStringArg logStringArg2(this->hashFileName);
Fw::LogStringArg logStringArg1(this->m_fileName);
Fw::LogStringArg logStringArg2(this->m_hashFileName);
this->log_WARNING_LO_FileValidationError(logStringArg1, logStringArg2, validateStatus);
}
}

View File

@ -105,8 +105,8 @@ namespace Svc {
};
// The filename data:
CHAR filePrefix[MAX_FILENAME_SIZE + MAX_PATH_SIZE];
U32 maxFileSize;
CHAR m_filePrefix[MAX_FILENAME_SIZE + MAX_PATH_SIZE];
U32 m_maxFileSize;
// ----------------------------------------------------------------------
// Internal state:
@ -116,15 +116,15 @@ namespace Svc {
OPEN = 1
};
FileMode fileMode;
Os::File file;
CHAR fileName[MAX_FILENAME_SIZE + MAX_PATH_SIZE];
CHAR hashFileName[MAX_FILENAME_SIZE + MAX_PATH_SIZE];
U32 byteCount;
bool writeErrorOccurred;
bool openErrorOccurred;
bool storeBufferLength;
bool initialized;
FileMode m_fileMode;
Os::File m_file;
CHAR m_fileName[MAX_FILENAME_SIZE + MAX_PATH_SIZE];
CHAR m_hashFileName[MAX_FILENAME_SIZE + MAX_PATH_SIZE];
U32 m_byteCount;
bool m_writeErrorOccurred;
bool m_openErrorOccurred;
bool m_storeBufferLength;
bool m_initialized;
// ----------------------------------------------------------------------
// File functions:

View File

@ -92,7 +92,7 @@ namespace Svc {
Os::File::Status ret;
Os::File file;
ASSERT_TRUE(comLogger.fileMode == ComLogger::CLOSED);
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::CLOSED);
ASSERT_EVENTS_SIZE(0);
U8 data[COM_BUFFER_LENGTH] = {0xde,0xad,0xbe,0xef};
@ -125,7 +125,7 @@ namespace Svc {
{
invoke_to_comIn(0, buffer, 0);
dispatchAll();
ASSERT_TRUE(comLogger.fileMode == ComLogger::OPEN);
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::OPEN);
}
// OK a new file should be opened after this final invoke, set a new test time so that a file
@ -133,12 +133,12 @@ namespace Svc {
setTestTime(testTimeNext);
invoke_to_comIn(0, buffer, 0);
dispatchAll();
ASSERT_TRUE(comLogger.fileMode == ComLogger::OPEN);
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::OPEN);
// A new file should have been opened from the previous loop iteration:
if( j > 0 ) {
ASSERT_TRUE(comLogger.fileMode == ComLogger::OPEN);
ASSERT_TRUE(strcmp(static_cast<char*>(comLogger.fileName), fileName) == 0 );
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::OPEN);
ASSERT_TRUE(strcmp(static_cast<char*>(comLogger.m_fileName), fileName) == 0 );
}
// Make sure we got a closed file event:
@ -213,15 +213,15 @@ namespace Svc {
Os::File::Status ret;
Os::File file;
ASSERT_TRUE(comLogger.fileMode == ComLogger::CLOSED);
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::CLOSED);
ASSERT_EVENTS_SIZE(0);
U8 data[COM_BUFFER_LENGTH] = {0xde,0xad,0xbe,0xef};
Fw::ComBuffer buffer(&data[0], sizeof(data));
// Make sure that noLengthMode is enabled:
comLogger.storeBufferLength = false;
comLogger.maxFileSize = MAX_BYTES_PER_FILE_NO_LENGTH;
comLogger.m_storeBufferLength = false;
comLogger.m_maxFileSize = MAX_BYTES_PER_FILE_NO_LENGTH;
for(int j = 0; j < 3; j++)
{
@ -248,7 +248,7 @@ namespace Svc {
{
invoke_to_comIn(0, buffer, 0);
dispatchAll();
ASSERT_TRUE(comLogger.fileMode == ComLogger::OPEN);
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::OPEN);
}
// OK a new file should be opened after this final invoke, set a new test time so that a file
@ -256,12 +256,12 @@ namespace Svc {
setTestTime(testTimeNext);
invoke_to_comIn(0, buffer, 0);
dispatchAll();
ASSERT_TRUE(comLogger.fileMode == ComLogger::OPEN);
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::OPEN);
// A new file should have been opened from the previous loop iteration:
if( j > 0 ) {
ASSERT_TRUE(comLogger.fileMode == ComLogger::OPEN);
ASSERT_TRUE(strcmp(static_cast<char*>(comLogger.fileName), fileName) == 0 );
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::OPEN);
ASSERT_TRUE(strcmp(static_cast<char*>(comLogger.m_fileName), fileName) == 0 );
}
// Make sure we got a closed file event:
@ -323,9 +323,9 @@ namespace Svc {
memset(filePrefix, 0, sizeof(filePrefix));
snprintf(filePrefix, sizeof(filePrefix), "illegal/fname?;\\*");
strncpy(static_cast<char*>(comLogger.filePrefix), filePrefix, sizeof(comLogger.filePrefix));
strncpy(static_cast<char*>(comLogger.m_filePrefix), filePrefix, sizeof(comLogger.m_filePrefix));
ASSERT_TRUE(comLogger.fileMode == ComLogger::CLOSED);
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::CLOSED);
ASSERT_EVENTS_SIZE(0);
const U8 data[COM_BUFFER_LENGTH] = {0xde,0xad,0xbe,0xef};
@ -340,7 +340,7 @@ namespace Svc {
{
invoke_to_comIn(0, buffer, 0);
dispatchAll();
ASSERT_TRUE(comLogger.fileMode == ComLogger::CLOSED);
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::CLOSED);
}
// Check generated events:
@ -358,9 +358,9 @@ namespace Svc {
memset(filePrefix, 0, sizeof(filePrefix));
snprintf(filePrefix, sizeof(filePrefix), "good_");
strncpy(comLogger.filePrefix, filePrefix, sizeof(comLogger.filePrefix));
strncpy(comLogger.m_filePrefix, filePrefix, sizeof(comLogger.m_filePrefix));
ASSERT_TRUE(comLogger.fileMode == ComLogger::CLOSED);
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::CLOSED);
snprintf(fileName, sizeof(fileName), "%s_%d_%d_%06d.com", filePrefix, static_cast<U32>(testTime.getTimeBase()), testTime.getSeconds(), testTime.getUSeconds());
@ -368,7 +368,7 @@ namespace Svc {
{
invoke_to_comIn(0, buffer, 0);
dispatchAll();
ASSERT_TRUE(comLogger.fileMode == ComLogger::OPEN);
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::OPEN);
}
// Check generated events:
@ -382,9 +382,9 @@ namespace Svc {
memset(filePrefix, 0, sizeof(filePrefix));
snprintf(filePrefix, sizeof(filePrefix), "illegal/fname?;\\*");
strncpy(static_cast<char*>(comLogger.filePrefix), filePrefix, sizeof(comLogger.filePrefix));
strncpy(static_cast<char*>(comLogger.m_filePrefix), filePrefix, sizeof(comLogger.m_filePrefix));
ASSERT_TRUE(comLogger.fileMode == ComLogger::CLOSED);
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::CLOSED);
snprintf(fileName, sizeof(fileName), "%s_%d_%d_%06d.com", filePrefix, static_cast<U32>(testTime.getTimeBase()), testTime.getSeconds(), testTime.getUSeconds());
@ -392,7 +392,7 @@ namespace Svc {
{
invoke_to_comIn(0, buffer, 0);
dispatchAll();
ASSERT_TRUE(comLogger.fileMode == ComLogger::CLOSED);
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::CLOSED);
}
// Check generated events:
@ -404,7 +404,7 @@ namespace Svc {
void ComLoggerTester ::
writeError()
{
ASSERT_TRUE(comLogger.fileMode == ComLogger::CLOSED);
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::CLOSED);
ASSERT_EVENTS_SIZE(0);
const U8 data[4] = {0xde,0xad,0xbe,0xef};
@ -417,17 +417,17 @@ namespace Svc {
{
invoke_to_comIn(0, buffer, 0);
dispatchAll();
ASSERT_TRUE(comLogger.fileMode == ComLogger::OPEN);
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::OPEN);
}
// Force close the file from underneath the component:
comLogger.file.close();
comLogger.m_file.close();
// Send 2 packets:
for(int i = 0; i < 3; i++) {
invoke_to_comIn(0, buffer, 0);
dispatchAll();
ASSERT_TRUE(comLogger.fileMode == ComLogger::OPEN);
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::OPEN);
}
// Construct filename:
@ -449,7 +449,7 @@ namespace Svc {
);
// Make comlogger open a new file:
comLogger.fileMode = ComLogger::CLOSED;
comLogger.m_fileMode = ComLogger::CLOSED;
comLogger.openFile();
// Try to write and make sure it succeeds:
@ -457,7 +457,7 @@ namespace Svc {
for(int i = 0; i < 3; i++) {
invoke_to_comIn(0, buffer, 0);
dispatchAll();
ASSERT_TRUE(comLogger.fileMode == ComLogger::OPEN);
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::OPEN);
}
// Expect no new errors:
@ -465,13 +465,13 @@ namespace Svc {
ASSERT_EVENTS_FileWriteError_SIZE(1);
// Force close the file from underneath the component:
comLogger.file.close();
comLogger.m_file.close();
// Send 2 packets:
for(int i = 0; i < 3; i++) {
invoke_to_comIn(0, buffer, 0);
dispatchAll();
ASSERT_TRUE(comLogger.fileMode == ComLogger::OPEN);
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::OPEN);
}
// Check generated events:
@ -504,14 +504,14 @@ namespace Svc {
memset(hashFileName, 0, sizeof(hashFileName));
snprintf(hashFileName, sizeof(hashFileName), "%s_%d_%d_%06d.com%s", FILE_STR, testTime.getTimeBase(), testTime.getSeconds(), testTime.getUSeconds(), Utils::Hash::getFileExtensionString());
ASSERT_TRUE(comLogger.fileMode == ComLogger::CLOSED);
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::CLOSED);
ASSERT_EVENTS_SIZE(0);
// Send close file commands:
for(int i = 0; i < 3; i++) {
sendCmd_CloseFile(0, i+1);
dispatchAll();
ASSERT_TRUE(comLogger.fileMode == ComLogger::CLOSED);
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::CLOSED);
}
ASSERT_CMD_RESPONSE_SIZE(3);
@ -532,14 +532,14 @@ namespace Svc {
{
invoke_to_comIn(0, buffer, 0);
dispatchAll();
ASSERT_TRUE(comLogger.fileMode == ComLogger::OPEN);
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::OPEN);
}
// Send close file commands:
for(int i = 0; i < 3; i++) {
sendCmd_CloseFile(0, i+1);
dispatchAll();
ASSERT_TRUE(comLogger.fileMode == ComLogger::CLOSED);
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::CLOSED);
}
ASSERT_CMD_RESPONSE_SIZE(6);
@ -582,7 +582,7 @@ namespace Svc {
this->comLogger.init_log_file(FILE_STR, MAX_BYTES_PER_FILE);
ASSERT_TRUE(comLogger.fileMode == ComLogger::CLOSED);
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::CLOSED);
ASSERT_EVENTS_SIZE(0);
U8 data[COM_BUFFER_LENGTH] = {0xde,0xad,0xbe,0xef};
@ -615,7 +615,7 @@ namespace Svc {
{
invoke_to_comIn(0, buffer, 0);
dispatchAll();
ASSERT_TRUE(comLogger.fileMode == ComLogger::OPEN);
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::OPEN);
}
// OK a new file should be opened after this final invoke, set a new test time so that a file
@ -623,12 +623,12 @@ namespace Svc {
setTestTime(testTimeNext);
invoke_to_comIn(0, buffer, 0);
dispatchAll();
ASSERT_TRUE(comLogger.fileMode == ComLogger::OPEN);
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::OPEN);
// A new file should have been opened from the previous loop iteration:
if( j > 0 ) {
ASSERT_TRUE(comLogger.fileMode == ComLogger::OPEN);
ASSERT_TRUE(strcmp(static_cast<char*>(comLogger.fileName), fileName) == 0 );
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::OPEN);
ASSERT_TRUE(strcmp(static_cast<char*>(comLogger.m_fileName), fileName) == 0 );
}
// Make sure we got a closed file event:
@ -695,7 +695,7 @@ namespace Svc {
this->invoke_to_comIn(0, buffer, 0);
dispatchAll();
ASSERT_TRUE(comLogger.fileMode == ComLogger::CLOSED);
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::CLOSED);
ASSERT_EVENTS_FileNotInitialized_SIZE(1);
this->comLogger.init_log_file(FILE_STR, MAX_BYTES_PER_FILE);
@ -703,7 +703,7 @@ namespace Svc {
this->clearHistory();
this->invoke_to_comIn(0, buffer, 0);
dispatchAll();
ASSERT_TRUE(comLogger.fileMode == ComLogger::OPEN);
ASSERT_TRUE(comLogger.m_fileMode == ComLogger::OPEN);
ASSERT_EVENTS_FileNotInitialized_SIZE(0);
}

View File

@ -1,4 +1,4 @@
// ======================================================================
// ======================================================================
// \title File.cpp
// \author bocchino
// \brief cpp file for FileDownlink::File
@ -7,8 +7,8 @@
// Copyright 2009-2015, by the California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
//
// ======================================================================
#include <Svc/FileDownlink/FileDownlink.hpp>
#include <Fw/Types/Assert.hpp>
@ -33,20 +33,20 @@ namespace Svc {
this->destName = destLogStringArg;
// Set size
FwSizeType size;
const Os::FileSystem::Status status =
Os::FileSystem::getFileSize(sourceFileName, size);
FwSizeType file_size;
const Os::FileSystem::Status status =
Os::FileSystem::getFileSize(sourceFileName, file_size);
if (status != Os::FileSystem::OP_OK)
return Os::File::BAD_SIZE;
// If the size does not cast cleanly to the desired U32 type, return size error
if (static_cast<FwSizeType>(static_cast<U32>(size)) != size) {
if (static_cast<FwSizeType>(static_cast<U32>(file_size)) != file_size) {
return Os::File::BAD_SIZE;
}
this->size = static_cast<U32>(size);
this->size = static_cast<U32>(file_size);
// Initialize checksum
CFDP::Checksum checksum;
this->checksum = checksum;
this->m_checksum = checksum;
// Open osFile for reading
return this->osFile.open(sourceFileName, Os::File::OPEN_READ);
@ -57,7 +57,7 @@ namespace Svc {
read(
U8 *const data,
const U32 byteOffset,
const U32 size
const U32 a_size
)
{
@ -66,15 +66,15 @@ namespace Svc {
if (status != Os::File::OP_OK)
return status;
NATIVE_INT_TYPE intSize = size;
NATIVE_INT_TYPE intSize = a_size;
status = this->osFile.read(data, intSize);
if (status != Os::File::OP_OK)
return status;
// Force a bad size error when the U32 carrying size is bad
if (static_cast<U32>(intSize) != size) {
if (static_cast<U32>(intSize) != a_size) {
return Os::File::BAD_SIZE;
}
this->checksum.update(data, byteOffset, size);
this->m_checksum.update(data, byteOffset, a_size);
return Os::File::OP_OK;

View File

@ -27,19 +27,19 @@ namespace Svc {
const char *const name
) :
FileDownlinkComponentBase(name),
configured(false),
filesSent(this),
packetsSent(this),
warnings(this),
sequenceIndex(0),
curTimer(0),
bufferSize(0),
byteOffset(0),
endOffset(0),
lastCompletedType(Fw::FilePacket::T_NONE),
lastBufferId(0),
curEntry(),
cntxId(0)
m_configured(false),
m_filesSent(this),
m_packetsSent(this),
m_warnings(this),
m_sequenceIndex(0),
m_curTimer(0),
m_bufferSize(0),
m_byteOffset(0),
m_endOffset(0),
m_lastCompletedType(Fw::FilePacket::T_NONE),
m_lastBufferId(0),
m_curEntry(),
m_cntxId(0)
{
}
@ -60,12 +60,12 @@ namespace Svc {
U32 fileQueueDepth
)
{
this->timeout = timeout;
this->cooldown = cooldown;
this->cycleTime = cycleTime;
this->configured = true;
this->m_timeout = timeout;
this->m_cooldown = cooldown;
this->m_cycleTime = cycleTime;
this->m_configured = true;
Os::Queue::QueueStatus stat = fileQueue.create(
Os::Queue::QueueStatus stat = m_fileQueue.create(
Os::QueueString("fileDownlinkQueue"),
fileQueueDepth,
sizeof(struct FileEntry)
@ -76,7 +76,7 @@ namespace Svc {
void FileDownlink ::
preamble()
{
FW_ASSERT(this->configured == true);
FW_ASSERT(this->m_configured == true);
}
FileDownlink ::
@ -95,49 +95,49 @@ namespace Svc {
NATIVE_UINT_TYPE context
)
{
switch(this->mode.get())
switch(this->m_mode.get())
{
case Mode::IDLE: {
NATIVE_INT_TYPE real_size = 0;
NATIVE_INT_TYPE prio = 0;
Os::Queue::QueueStatus stat = fileQueue.receive(
reinterpret_cast<U8*>(&this->curEntry),
sizeof(this->curEntry),
Os::Queue::QueueStatus stat = m_fileQueue.receive(
reinterpret_cast<U8*>(&this->m_curEntry),
sizeof(this->m_curEntry),
real_size,
prio,
Os::Queue::QUEUE_NONBLOCKING
);
if(stat != Os::Queue::QUEUE_OK || sizeof(this->curEntry) != real_size) {
if(stat != Os::Queue::QUEUE_OK || sizeof(this->m_curEntry) != real_size) {
return;
}
sendFile(
this->curEntry.srcFilename,
this->curEntry.destFilename,
this->curEntry.offset,
this->curEntry.length
this->m_curEntry.srcFilename,
this->m_curEntry.destFilename,
this->m_curEntry.offset,
this->m_curEntry.length
);
break;
}
case Mode::COOLDOWN: {
if (this->curTimer >= this->cooldown) {
this->curTimer = 0;
this->mode.set(Mode::IDLE);
if (this->m_curTimer >= this->m_cooldown) {
this->m_curTimer = 0;
this->m_mode.set(Mode::IDLE);
} else {
this->curTimer += cycleTime;
this->m_curTimer += m_cycleTime;
}
break;
}
case Mode::WAIT: {
//If current timeout is too-high and we are waiting for a packet, issue a timeout
if (this->curTimer >= this->timeout) {
this->curTimer = 0;
this->log_WARNING_HI_DownlinkTimeout(this->file.sourceName, this->file.destName);
if (this->m_curTimer >= this->m_timeout) {
this->m_curTimer = 0;
this->log_WARNING_HI_DownlinkTimeout(this->m_file.sourceName, this->m_file.destName);
this->enterCooldown();
this->sendResponse(FILEDOWNLINK_COMMAND_FAILURES_DISABLED ? SendFileStatus::STATUS_OK : SendFileStatus::STATUS_ERROR);
} else { //Otherwise update the current counter
this->curTimer += cycleTime;
this->m_curTimer += m_cycleTime;
}
break;
}
@ -163,14 +163,14 @@ namespace Svc {
entry.source = FileDownlink::PORT;
entry.opCode = 0;
entry.cmdSeq = 0;
entry.context = cntxId++;
entry.context = m_cntxId++;
FW_ASSERT(sourceFilename.length() < sizeof(entry.srcFilename));
FW_ASSERT(destFilename.length() < sizeof(entry.destFilename));
Fw::StringUtils::string_copy(entry.srcFilename, sourceFilename.toChar(), sizeof(entry.srcFilename));
Fw::StringUtils::string_copy(entry.destFilename, destFilename.toChar(), sizeof(entry.destFilename));
Os::Queue::QueueStatus status = fileQueue.send(reinterpret_cast<U8*>(&entry), sizeof(entry), 0, Os::Queue::QUEUE_NONBLOCKING);
Os::Queue::QueueStatus status = m_fileQueue.send(reinterpret_cast<U8*>(&entry), sizeof(entry), 0, Os::Queue::QUEUE_NONBLOCKING);
if(status != Os::Queue::QUEUE_OK) {
return SendFileResponse(SendFileStatus::STATUS_ERROR, std::numeric_limits<U32>::max());
@ -195,21 +195,21 @@ namespace Svc {
{
//If this is a stale buffer (old, timed-out, or both), then ignore its return.
//File downlink actions only respond to the return of the most-recently-sent buffer.
if (this->lastBufferId != fwBuffer.getContext() + 1 ||
this->mode.get() == Mode::IDLE) {
if (this->m_lastBufferId != fwBuffer.getContext() + 1 ||
this->m_mode.get() == Mode::IDLE) {
return;
}
//Non-ignored buffers cannot be returned in "DOWNLINK" and "IDLE" state. Only in "WAIT", "CANCEL" state.
FW_ASSERT(this->mode.get() == Mode::WAIT || this->mode.get() == Mode::CANCEL, this->mode.get());
FW_ASSERT(this->m_mode.get() == Mode::WAIT || this->m_mode.get() == Mode::CANCEL, this->m_mode.get());
//If the last packet has been sent (and is returning now) then finish the file
if (this->lastCompletedType == Fw::FilePacket::T_END ||
this->lastCompletedType == Fw::FilePacket::T_CANCEL) {
finishHelper(this->lastCompletedType == Fw::FilePacket::T_CANCEL);
if (this->m_lastCompletedType == Fw::FilePacket::T_END ||
this->m_lastCompletedType == Fw::FilePacket::T_CANCEL) {
finishHelper(this->m_lastCompletedType == Fw::FilePacket::T_CANCEL);
return;
}
//If waiting and a buffer is in-bound, then switch to downlink mode
else if (this->mode.get() == Mode::WAIT) {
this->mode.set(Mode::DOWNLINK);
else if (this->m_mode.get() == Mode::WAIT) {
this->m_mode.set(Mode::DOWNLINK);
}
this->downlinkPacket();
@ -243,7 +243,7 @@ namespace Svc {
Fw::StringUtils::string_copy(entry.srcFilename, sourceFilename.toChar(), sizeof(entry.srcFilename));
Fw::StringUtils::string_copy(entry.destFilename, destFilename.toChar(), sizeof(entry.destFilename));
Os::Queue::QueueStatus status = fileQueue.send(reinterpret_cast<U8*>(&entry), sizeof(entry), 0, Os::Queue::QUEUE_NONBLOCKING);
Os::Queue::QueueStatus status = m_fileQueue.send(reinterpret_cast<U8*>(&entry), sizeof(entry), 0, Os::Queue::QUEUE_NONBLOCKING);
if(status != Os::Queue::QUEUE_OK) {
this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR);
@ -276,7 +276,7 @@ namespace Svc {
Fw::StringUtils::string_copy(entry.srcFilename, sourceFilename.toChar(), sizeof(entry.srcFilename));
Fw::StringUtils::string_copy(entry.destFilename, destFilename.toChar(), sizeof(entry.destFilename));
Os::Queue::QueueStatus status = fileQueue.send(reinterpret_cast<U8*>(&entry), sizeof(entry), 0, Os::Queue::QUEUE_NONBLOCKING);
Os::Queue::QueueStatus status = m_fileQueue.send(reinterpret_cast<U8*>(&entry), sizeof(entry), 0, Os::Queue::QUEUE_NONBLOCKING);
if(status != Os::Queue::QUEUE_OK) {
this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR);
@ -290,8 +290,8 @@ namespace Svc {
)
{
//Must be able to cancel in both downlink and waiting states
if (this->mode.get() == Mode::DOWNLINK || this->mode.get() == Mode::WAIT) {
this->mode.set(Mode::CANCEL);
if (this->m_mode.get() == Mode::DOWNLINK || this->m_mode.get() == Mode::WAIT) {
this->m_mode.set(Mode::CANCEL);
}
this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
}
@ -324,12 +324,12 @@ namespace Svc {
void FileDownlink ::
sendResponse(SendFileStatus resp)
{
if(this->curEntry.source == FileDownlink::COMMAND) {
this->cmdResponse_out(this->curEntry.opCode, this->curEntry.cmdSeq, statusToCmdResp(resp));
if(this->m_curEntry.source == FileDownlink::COMMAND) {
this->cmdResponse_out(this->m_curEntry.opCode, this->m_curEntry.cmdSeq, statusToCmdResp(resp));
} else {
for(NATIVE_INT_TYPE i = 0; i < this->getNum_FileComplete_OutputPorts(); i++) {
if(this->isConnected_FileComplete_OutputPort(i)) {
this->FileComplete_out(i, Svc::SendFileResponse(resp, this->curEntry.context));
this->FileComplete_out(i, Svc::SendFileResponse(resp, this->m_curEntry.context));
}
}
}
@ -344,78 +344,78 @@ namespace Svc {
)
{
// Open file for downlink
Os::File::Status status = this->file.open(
Os::File::Status status = this->m_file.open(
sourceFilename,
destFilename
);
// Reject command if error when opening file
if (status != Os::File::OP_OK) {
this->mode.set(Mode::IDLE);
this->warnings.fileOpenError();
this->m_mode.set(Mode::IDLE);
this->m_warnings.fileOpenError();
sendResponse(FILEDOWNLINK_COMMAND_FAILURES_DISABLED ? SendFileStatus::STATUS_OK : SendFileStatus::STATUS_ERROR);
return;
}
if (startOffset >= this->file.size) {
if (startOffset >= this->m_file.size) {
this->enterCooldown();
this->log_WARNING_HI_DownlinkPartialFail(this->file.sourceName, this->file.destName, startOffset, this->file.size);
this->log_WARNING_HI_DownlinkPartialFail(this->m_file.sourceName, this->m_file.destName, startOffset, this->m_file.size);
sendResponse(FILEDOWNLINK_COMMAND_FAILURES_DISABLED ? SendFileStatus::STATUS_OK : SendFileStatus::STATUS_INVALID);
return;
} else if (startOffset + length > this->file.size) {
} else if (startOffset + length > this->m_file.size) {
// If the amount to downlink is greater than the file size, emit a Warning and then allow
// the file to be downlinked anyway
this->log_WARNING_LO_DownlinkPartialWarning(startOffset, length, this->file.size, this->file.sourceName, this->file.destName);
length = this->file.size - startOffset;
this->log_WARNING_LO_DownlinkPartialWarning(startOffset, length, this->m_file.size, this->m_file.sourceName, this->m_file.destName);
length = this->m_file.size - startOffset;
}
// Send file and switch to WAIT mode
this->getBuffer(this->buffer, FILE_PACKET);
this->getBuffer(this->m_buffer, FILE_PACKET);
this->sendStartPacket();
this->mode.set(Mode::WAIT);
this->sequenceIndex = 1;
this->curTimer = 0;
this->byteOffset = startOffset;
this->lastCompletedType = Fw::FilePacket::T_START;
this->m_mode.set(Mode::WAIT);
this->m_sequenceIndex = 1;
this->m_curTimer = 0;
this->m_byteOffset = startOffset;
this->m_lastCompletedType = Fw::FilePacket::T_START;
// zero length means read until end of file
if (length > 0) {
this->log_ACTIVITY_HI_SendStarted(length, this->file.sourceName, this->file.destName);
this->endOffset = startOffset + length;
this->log_ACTIVITY_HI_SendStarted(length, this->m_file.sourceName, this->m_file.destName);
this->m_endOffset = startOffset + length;
}
else {
this->log_ACTIVITY_HI_SendStarted(this->file.size - startOffset, this->file.sourceName, this->file.destName);
this->endOffset = this->file.size;
this->log_ACTIVITY_HI_SendStarted(this->m_file.size - startOffset, this->m_file.sourceName, this->m_file.destName);
this->m_endOffset = this->m_file.size;
}
}
Os::File::Status FileDownlink ::
sendDataPacket(U32 &byteOffset)
{
FW_ASSERT(byteOffset < this->endOffset);
FW_ASSERT(byteOffset < this->m_endOffset);
const U32 maxDataSize = FILEDOWNLINK_INTERNAL_BUFFER_SIZE - Fw::FilePacket::DataPacket::HEADERSIZE;
const U32 dataSize = (byteOffset + maxDataSize > this->endOffset) ? (this->endOffset - byteOffset) : maxDataSize;
const U32 dataSize = (byteOffset + maxDataSize > this->m_endOffset) ? (this->m_endOffset - byteOffset) : maxDataSize;
U8 buffer[FILEDOWNLINK_INTERNAL_BUFFER_SIZE - Fw::FilePacket::DataPacket::HEADERSIZE];
//This will be last data packet sent
if (dataSize + byteOffset == this->endOffset) {
this->lastCompletedType = Fw::FilePacket::T_DATA;
if (dataSize + byteOffset == this->m_endOffset) {
this->m_lastCompletedType = Fw::FilePacket::T_DATA;
}
const Os::File::Status status =
this->file.read(buffer, byteOffset, dataSize);
this->m_file.read(buffer, byteOffset, dataSize);
if (status != Os::File::OP_OK) {
this->warnings.fileRead(status);
this->m_warnings.fileRead(status);
return status;
}
const Fw::FilePacket::DataPacket dataPacket = {
{ Fw::FilePacket::T_DATA, this->sequenceIndex },
{ Fw::FilePacket::T_DATA, this->m_sequenceIndex },
byteOffset,
static_cast<U16>(dataSize),
buffer
};
++this->sequenceIndex;
++this->m_sequenceIndex;
Fw::FilePacket filePacket;
filePacket.fromDataPacket(dataPacket);
this->sendFilePacket(filePacket);
@ -431,7 +431,7 @@ namespace Svc {
{
Fw::Buffer buffer;
const Fw::FilePacket::CancelPacket cancelPacket = {
{ Fw::FilePacket::T_CANCEL, this->sequenceIndex }
{ Fw::FilePacket::T_CANCEL, this->m_sequenceIndex }
};
Fw::FilePacket filePacket;
@ -441,7 +441,7 @@ namespace Svc {
const Fw::SerializeStatus status = filePacket.toBuffer(buffer);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK);
this->bufferSendOut_out(0, buffer);
this->packetsSent.packetSent();
this->m_packetsSent.packetSent();
}
void FileDownlink ::
@ -449,13 +449,13 @@ namespace Svc {
{
const Fw::FilePacket::Header header = {
Fw::FilePacket::T_END,
this->sequenceIndex
this->m_sequenceIndex
};
Fw::FilePacket::EndPacket endPacket;
endPacket.header = header;
CFDP::Checksum checksum;
this->file.getChecksum(checksum);
this->m_file.getChecksum(checksum);
endPacket.setChecksum(checksum);
Fw::FilePacket filePacket;
@ -469,9 +469,9 @@ namespace Svc {
{
Fw::FilePacket::StartPacket startPacket;
startPacket.initialize(
this->file.size,
this->file.sourceName.toChar(),
this->file.destName.toChar()
this->m_file.size,
this->m_file.sourceName.toChar(),
this->m_file.destName.toChar()
);
Fw::FilePacket filePacket;
filePacket.fromStartPacket(startPacket);
@ -482,43 +482,43 @@ namespace Svc {
sendFilePacket(const Fw::FilePacket& filePacket)
{
const U32 bufferSize = filePacket.bufferSize();
FW_ASSERT(this->buffer.getData() != nullptr);
FW_ASSERT(this->buffer.getSize() >= bufferSize, bufferSize, this->buffer.getSize());
const Fw::SerializeStatus status = filePacket.toBuffer(this->buffer);
FW_ASSERT(this->m_buffer.getData() != nullptr);
FW_ASSERT(this->m_buffer.getSize() >= bufferSize, bufferSize, this->m_buffer.getSize());
const Fw::SerializeStatus status = filePacket.toBuffer(this->m_buffer);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK);
// set the buffer size to the packet size
this->buffer.setSize(bufferSize);
this->bufferSendOut_out(0, this->buffer);
this->m_buffer.setSize(bufferSize);
this->bufferSendOut_out(0, this->m_buffer);
// restore buffer size to max
this->buffer.setSize(FILEDOWNLINK_INTERNAL_BUFFER_SIZE);
this->packetsSent.packetSent();
this->m_buffer.setSize(FILEDOWNLINK_INTERNAL_BUFFER_SIZE);
this->m_packetsSent.packetSent();
}
void FileDownlink ::
enterCooldown()
{
this->file.osFile.close();
this->mode.set(Mode::COOLDOWN);
this->lastCompletedType = Fw::FilePacket::T_NONE;
this->curTimer = 0;
this->m_file.osFile.close();
this->m_mode.set(Mode::COOLDOWN);
this->m_lastCompletedType = Fw::FilePacket::T_NONE;
this->m_curTimer = 0;
}
void FileDownlink ::
downlinkPacket()
{
FW_ASSERT(this->lastCompletedType != Fw::FilePacket::T_NONE, this->lastCompletedType);
FW_ASSERT(this->mode.get() == Mode::CANCEL || this->mode.get() == Mode::DOWNLINK, this->mode.get());
FW_ASSERT(this->m_lastCompletedType != Fw::FilePacket::T_NONE, this->m_lastCompletedType);
FW_ASSERT(this->m_mode.get() == Mode::CANCEL || this->m_mode.get() == Mode::DOWNLINK, this->m_mode.get());
//If canceled mode and currently downlinking data then send a cancel packet
if (this->mode.get() == Mode::CANCEL && this->lastCompletedType == Fw::FilePacket::T_START) {
if (this->m_mode.get() == Mode::CANCEL && this->m_lastCompletedType == Fw::FilePacket::T_START) {
this->sendCancelPacket();
this->lastCompletedType = Fw::FilePacket::T_CANCEL;
this->m_lastCompletedType = Fw::FilePacket::T_CANCEL;
}
//If in downlink mode and currently downlinking data then continue with the next packer
else if (this->mode.get() == Mode::DOWNLINK && this->lastCompletedType == Fw::FilePacket::T_START) {
else if (this->m_mode.get() == Mode::DOWNLINK && this->m_lastCompletedType == Fw::FilePacket::T_START) {
//Send the next packet, or fail doing so
const Os::File::Status status = this->sendDataPacket(this->byteOffset);
const Os::File::Status status = this->sendDataPacket(this->m_byteOffset);
if (status != Os::File::OP_OK) {
this->log_WARNING_HI_SendDataFail(this->file.sourceName, this->byteOffset);
this->log_WARNING_HI_SendDataFail(this->m_file.sourceName, this->m_byteOffset);
this->enterCooldown();
this->sendResponse(FILEDOWNLINK_COMMAND_FAILURES_DISABLED ? SendFileStatus::STATUS_OK : SendFileStatus::STATUS_ERROR);
//Don't go to wait state
@ -526,12 +526,12 @@ namespace Svc {
}
}
//If in downlink mode or cancel and finished downlinking data then send the last packet
else if (this->lastCompletedType == Fw::FilePacket::T_DATA) {
else if (this->m_lastCompletedType == Fw::FilePacket::T_DATA) {
this->sendEndPacket();
this->lastCompletedType = Fw::FilePacket::T_END;
this->m_lastCompletedType = Fw::FilePacket::T_END;
}
this->mode.set(Mode::WAIT);
this->curTimer = 0;
this->m_mode.set(Mode::WAIT);
this->m_curTimer = 0;
}
void FileDownlink ::
@ -539,10 +539,10 @@ namespace Svc {
{
//Complete command and switch to IDLE
if (not cancel) {
this->filesSent.fileSent();
this->log_ACTIVITY_HI_FileSent(this->file.sourceName, this->file.destName);
this->m_filesSent.fileSent();
this->log_ACTIVITY_HI_FileSent(this->m_file.sourceName, this->m_file.destName);
} else {
this->log_ACTIVITY_HI_DownlinkCanceled(this->file.sourceName, this->file.destName);
this->log_ACTIVITY_HI_DownlinkCanceled(this->m_file.sourceName, this->m_file.destName);
}
this->enterCooldown();
sendResponse(SendFileStatus::STATUS_OK);
@ -554,10 +554,10 @@ namespace Svc {
//Check type is correct
FW_ASSERT(type < COUNT_PACKET_TYPE && type >= 0, type);
// Wrap the buffer around our indexed memory.
buffer.setData(this->memoryStore[type]);
buffer.setData(this->m_memoryStore[type]);
buffer.setSize(FILEDOWNLINK_INTERNAL_BUFFER_SIZE);
//Set a known ID to look for later
buffer.setContext(lastBufferId);
lastBufferId++;
buffer.setContext(m_lastBufferId);
m_lastBufferId++;
}
} // end namespace Svc

View File

@ -43,32 +43,32 @@ namespace Svc {
public:
//! Constructor
Mode() : value(IDLE) { }
Mode() : m_value(IDLE) { }
public:
//! Set the Mode value
void set(const Type value) {
this->mutex.lock();
this->value = value;
this->mutex.unLock();
this->m_mutex.lock();
this->m_value = value;
this->m_mutex.unLock();
}
//! Get the Mode value
Type get() {
this->mutex.lock();
const Type value = this->value;
this->mutex.unLock();
this->m_mutex.lock();
const Type value = this->m_value;
this->m_mutex.unLock();
return value;
}
private:
//! The Mode value
Type value;
Type m_value;
//! The Mode mutex
Os::Mutex mutex;
Os::Mutex m_mutex;
};
//! Class representing an outgoing file
@ -96,7 +96,7 @@ namespace Svc {
PRIVATE:
//! The checksum for the file
CFDP::Checksum checksum;
CFDP::Checksum m_checksum;
public:
@ -110,12 +110,12 @@ namespace Svc {
Os::File::Status read(
U8 *const data,
const U32 byteOffset,
const U32 size
const U32 a_size
);
//! Get the checksum
void getChecksum(CFDP::Checksum& checksum) {
checksum = this->checksum;
checksum = this->m_checksum;
}
};
@ -126,24 +126,25 @@ namespace Svc {
//! Construct a FilesSent object
FilesSent(FileDownlink *const fileDownlink) :
n(0), fileDownlink(fileDownlink)
m_sent_file_count(0),
m_fileDownlink(fileDownlink)
{ }
public:
//! Record a file sent
void fileSent() {
++this->n;
this->fileDownlink->tlmWrite_FilesSent(n);
++this->m_sent_file_count;
this->m_fileDownlink->tlmWrite_FilesSent(m_sent_file_count);
}
PRIVATE:
//! The total number of downlinks canceled
U32 n;
//! The total number of file sent
U32 m_sent_file_count;
//! The enclosing FileDownlink object
FileDownlink *const fileDownlink;
FileDownlink *const m_fileDownlink;
};
@ -154,24 +155,25 @@ namespace Svc {
//! Construct a PacketsSent object
PacketsSent(FileDownlink *const fileDownlink) :
n(0), fileDownlink(fileDownlink)
m_sent_packet_count(0),
m_fileDownlink(fileDownlink)
{ }
public:
//! Record a packet sent
void packetSent() {
++this->n;
this->fileDownlink->tlmWrite_PacketsSent(n);
++this->m_sent_packet_count;
this->m_fileDownlink->tlmWrite_PacketsSent(m_sent_packet_count);
}
PRIVATE:
//! The total number of downlinks canceled
U32 n;
//! The total number of downlinked packets
U32 m_sent_packet_count;
//! The enclosing FileDownlink object
FileDownlink *const fileDownlink;
FileDownlink *const m_fileDownlink;
};
@ -182,7 +184,8 @@ namespace Svc {
//! Construct a Warnings object
Warnings(FileDownlink *const fileDownlink) :
n(0), fileDownlink(fileDownlink)
m_warning_count(0),
m_fileDownlink(fileDownlink)
{ }
public:
@ -197,17 +200,17 @@ namespace Svc {
//! Record a warning
void warning() {
++this->n;
this->fileDownlink->tlmWrite_Warnings(n);
++this->m_warning_count;
this->m_fileDownlink->tlmWrite_Warnings(m_warning_count);
}
PRIVATE:
//! The total number of warnings
U32 n;
U32 m_warning_count;
//! The enclosing FileDownlink object
FileDownlink *const fileDownlink;
FileDownlink *const m_fileDownlink;
};
@ -390,67 +393,67 @@ namespace Svc {
// ----------------------------------------------------------------------
//! Whether the configuration function has been called.
bool configured;
bool m_configured;
//! File downlink queue
Os::Queue fileQueue;
Os::Queue m_fileQueue;
//!Buffer's memory backing
U8 memoryStore[COUNT_PACKET_TYPE][FILEDOWNLINK_INTERNAL_BUFFER_SIZE];
U8 m_memoryStore[COUNT_PACKET_TYPE][FILEDOWNLINK_INTERNAL_BUFFER_SIZE];
//! The mode
Mode mode;
Mode m_mode;
//! The file
File file;
File m_file;
//! Files sent
FilesSent filesSent;
FilesSent m_filesSent;
//! Packets sent
PacketsSent packetsSent;
PacketsSent m_packetsSent;
//! Warnings
Warnings warnings;
Warnings m_warnings;
//! The current sequence index
U32 sequenceIndex;
U32 m_sequenceIndex;
//! Timeout threshold (milliseconds) while in WAIT state
U32 timeout;
U32 m_timeout;
//! Cooldown (in ms) between finishing a downlink and starting the next file.
U32 cooldown;
U32 m_cooldown;
//! current time residing in WAIT state
U32 curTimer;
U32 m_curTimer;
//! rate (milliseconds) at which we are running
U32 cycleTime;
U32 m_cycleTime;
////! Buffer for sending file data
Fw::Buffer buffer;
Fw::Buffer m_buffer;
//! Buffer size for file data
U32 bufferSize;
U32 m_bufferSize;
//! Current byte offset in file
U32 byteOffset;
U32 m_byteOffset;
//! Amount of bytes left to read
U32 endOffset;
U32 m_endOffset;
//! Set to true when all data packets have been sent
Fw::FilePacket::Type lastCompletedType;
Fw::FilePacket::Type m_lastCompletedType;
//! Last buffer used
U32 lastBufferId;
U32 m_lastBufferId;
//! Current in progress file entry from queue
struct FileEntry curEntry;
struct FileEntry m_curEntry;
//! Incrementing context id used to unique identify a specific downlink request
U32 cntxId;
U32 m_cntxId;
};
} // end namespace Svc

View File

@ -15,8 +15,8 @@ namespace Svc {
void FileDownlink::Warnings ::
fileOpenError()
{
this->fileDownlink->log_WARNING_HI_FileOpenError(
this->fileDownlink->file.sourceName
this->m_fileDownlink->log_WARNING_HI_FileOpenError(
this->m_fileDownlink->m_file.sourceName
);
this->warning();
}
@ -24,8 +24,8 @@ namespace Svc {
void FileDownlink::Warnings ::
fileRead(const Os::File::Status status)
{
this->fileDownlink->log_WARNING_HI_FileReadError(
this->fileDownlink->file.sourceName,
this->m_fileDownlink->log_WARNING_HI_FileReadError(
this->m_fileDownlink->m_file.sourceName,
status
);
this->warning();

View File

@ -55,7 +55,7 @@ namespace Svc {
downlink()
{
// Assert idle mode
ASSERT_EQ(FileDownlink::Mode::IDLE, this->component.mode.get());
ASSERT_EQ(FileDownlink::Mode::IDLE, this->component.m_mode.get());
// Create a file
const char *const sourceFileName = "source.bin";
@ -102,7 +102,7 @@ namespace Svc {
ASSERT_EQ(true, FileBuffer::compare(fileBufferIn, fileBufferOut));
// Assert idle mode
ASSERT_EQ(FileDownlink::Mode::IDLE, this->component.mode.get());
ASSERT_EQ(FileDownlink::Mode::IDLE, this->component.m_mode.get());
// Remove the outgoing file
this->removeFile(sourceFileName);
@ -160,7 +160,7 @@ namespace Svc {
ASSERT_CMD_RESPONSE_SIZE(1);
ASSERT_CMD_RESPONSE(0, FileDownlink::OPCODE_CANCEL, CMD_SEQ, Fw::CmdResponse::OK);
this->cmdResponseHistory->clear();
ASSERT_EQ(FileDownlink::Mode::CANCEL, this->component.mode.get());
ASSERT_EQ(FileDownlink::Mode::CANCEL, this->component.m_mode.get());
this->component.doDispatch(); // Process return of original buffer and send cancel packet
this->component.doDispatch(); // Process return of cancel packet
@ -177,7 +177,7 @@ namespace Svc {
ASSERT_EVENTS_SIZE(2); // Started and cancel
ASSERT_EVENTS_DownlinkCanceled_SIZE(1);
ASSERT_EQ(FileDownlink::Mode::COOLDOWN, this->component.mode.get());
ASSERT_EQ(FileDownlink::Mode::COOLDOWN, this->component.m_mode.get());
this->removeFile(sourceFileName);
}
@ -186,14 +186,14 @@ namespace Svc {
cancelInIdleMode()
{
// Assert idle mode
ASSERT_EQ(FileDownlink::Mode::IDLE, this->component.mode.get());
ASSERT_EQ(FileDownlink::Mode::IDLE, this->component.m_mode.get());
// Send a cancel command
this->cancel(Fw::CmdResponse::OK);
this->component.Run_handler(0,0);
// Assert idle mode
ASSERT_EQ(FileDownlink::Mode::IDLE, this->component.mode.get());
ASSERT_EQ(FileDownlink::Mode::IDLE, this->component.m_mode.get());
}
@ -201,7 +201,7 @@ namespace Svc {
downlinkPartial()
{
// Assert idle mode
ASSERT_EQ(FileDownlink::Mode::IDLE, this->component.mode.get());
ASSERT_EQ(FileDownlink::Mode::IDLE, this->component.m_mode.get());
// Create a file
const char *const sourceFileName = "source.bin";
@ -263,7 +263,7 @@ namespace Svc {
ASSERT_EQ(true, FileBuffer::compare(fileBufferIn, fileBufferOutSubset));
// Assert idle mode
ASSERT_EQ(FileDownlink::Mode::IDLE, this->component.mode.get());
ASSERT_EQ(FileDownlink::Mode::IDLE, this->component.m_mode.get());
// Remove the outgoing file
this->removeFile(sourceFileName);
@ -274,7 +274,7 @@ namespace Svc {
timeout()
{
// Assert idle mode
ASSERT_EQ(FileDownlink::Mode::IDLE, this->component.mode.get());
ASSERT_EQ(FileDownlink::Mode::IDLE, this->component.m_mode.get());
// Create a file
const char *const sourceFileName = "source.bin";
@ -318,7 +318,7 @@ namespace Svc {
ASSERT_EVENTS_DownlinkTimeout(0, sourceFileName, destFileName);
// Assert idle mode
ASSERT_EQ(FileDownlink::Mode::COOLDOWN, this->component.mode.get());
ASSERT_EQ(FileDownlink::Mode::COOLDOWN, this->component.m_mode.get());
// Remove the outgoing file
this->removeFile(sourceFileName);
@ -342,8 +342,8 @@ namespace Svc {
ASSERT_EQ(resp.getcontext(), 0);
this->component.Run_handler(0,0); // Dequeue file downlink request
while (this->component.mode.get() != FileDownlink::Mode::IDLE) {
if(this->component.mode.get() != FileDownlink::Mode::COOLDOWN) {
while (this->component.m_mode.get() != FileDownlink::Mode::IDLE) {
if(this->component.m_mode.get() != FileDownlink::Mode::COOLDOWN) {
this->component.doDispatch();
}
this->component.Run_handler(0,0);
@ -538,8 +538,8 @@ namespace Svc {
this->component.doDispatch();
this->component.Run_handler(0,0);
while (this->component.mode.get() != FileDownlink::Mode::IDLE) {
if(this->component.mode.get() != FileDownlink::Mode::COOLDOWN) {
while (this->component.m_mode.get() != FileDownlink::Mode::IDLE) {
if(this->component.m_mode.get() != FileDownlink::Mode::COOLDOWN) {
this->component.doDispatch();
}
this->component.Run_handler(0,0);
@ -572,8 +572,8 @@ namespace Svc {
this->component.doDispatch();
this->component.Run_handler(0,0);
while (this->component.mode.get() != FileDownlink::Mode::IDLE) {
if(this->component.mode.get() != FileDownlink::Mode::COOLDOWN) {
while (this->component.m_mode.get() != FileDownlink::Mode::IDLE) {
if(this->component.m_mode.get() != FileDownlink::Mode::COOLDOWN) {
this->component.doDispatch();
}
this->component.Run_handler(0,0);

View File

@ -27,7 +27,7 @@ namespace Svc {
this->name = logStringArg;
this->size = startPacket.fileSize;
CFDP::Checksum checksum;
this->checksum = checksum;
this->m_checksum = checksum;
return this->osFile.open(path, Os::File::OPEN_WRITE);
}
@ -53,7 +53,7 @@ namespace Svc {
}
FW_ASSERT(static_cast<U32>(intLength) == length, intLength);
this->checksum.update(data, byteOffset, length);
this->m_checksum.update(data, byteOffset, length);
return Os::File::OP_OK;
}

View File

@ -49,7 +49,7 @@ namespace Svc {
PRIVATE:
//! The checksum for the file
::CFDP::Checksum checksum;
::CFDP::Checksum m_checksum;
public:
@ -67,7 +67,7 @@ namespace Svc {
//! Get the checksum
void getChecksum(::CFDP::Checksum& checksum) {
checksum = this->checksum;
checksum = this->m_checksum;
}
};
@ -79,24 +79,25 @@ namespace Svc {
//! Construct a FilesReceived object
FilesReceived(FileUplink *const fileUplink) :
n(0), fileUplink(fileUplink)
m_received_files_counter(0),
m_fileUplink(fileUplink)
{ }
public:
//! Record a received file
void fileReceived() {
++this->n;
this->fileUplink->tlmWrite_FilesReceived(n);
++this->m_received_files_counter;
this->m_fileUplink->tlmWrite_FilesReceived(m_received_files_counter);
}
PRIVATE:
//! The total number of files received
U32 n;
U32 m_received_files_counter;
//! The enclosing FileUplink object
FileUplink *const fileUplink;
FileUplink *const m_fileUplink;
};
@ -107,24 +108,25 @@ namespace Svc {
//! Construct a PacketsReceived object
PacketsReceived(FileUplink *const fileUplink) :
n(0), fileUplink(fileUplink)
m_received_packet_count(0),
m_fileUplink(fileUplink)
{ }
public:
//! Record a packet received
void packetReceived() {
++this->n;
this->fileUplink->tlmWrite_PacketsReceived(n);
++this->m_received_packet_count;
this->m_fileUplink->tlmWrite_PacketsReceived(m_received_packet_count);
}
PRIVATE:
//! The total number of cancel packets
U32 n;
//! The total number of received packets
U32 m_received_packet_count;
//! The enclosing FileUplink object
FileUplink *const fileUplink;
FileUplink *const m_fileUplink;
};
@ -135,7 +137,8 @@ namespace Svc {
//! Construct a Warnings object
Warnings(FileUplink *const fileUplink) :
n(0), fileUplink(fileUplink)
m_warning_count(0),
m_fileUplink(fileUplink)
{ }
public:
@ -171,17 +174,17 @@ namespace Svc {
//! Record a warning
void warning() {
++this->n;
this->fileUplink->tlmWrite_Warnings(n);
++this->m_warning_count;
this->m_fileUplink->tlmWrite_Warnings(m_warning_count);
}
PRIVATE:
//! The total number of warnings
U32 n;
U32 m_warning_count;
//! The enclosing FileUplink object
FileUplink *const fileUplink;
FileUplink *const m_fileUplink;
};

View File

@ -1,4 +1,4 @@
// ======================================================================
// ======================================================================
// \title Warnings.cpp
// \author bocchino
// \brief cpp file for FileUplink::Warnings
@ -7,8 +7,8 @@
// Copyright 2009-2016, by the California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
//
// ======================================================================
#include <Svc/FileUplink/FileUplink.hpp>
@ -17,9 +17,9 @@ namespace Svc {
void FileUplink::Warnings ::
invalidReceiveMode(const Fw::FilePacket::Type packetType)
{
this->fileUplink->log_WARNING_HI_InvalidReceiveMode(
this->m_fileUplink->log_WARNING_HI_InvalidReceiveMode(
static_cast<U32>(packetType),
static_cast<U32>(fileUplink->receiveMode)
static_cast<U32>(m_fileUplink->receiveMode)
);
this->warning();
}
@ -27,7 +27,7 @@ namespace Svc {
void FileUplink::Warnings ::
fileOpen(Fw::LogStringArg& fileName)
{
this->fileUplink->log_WARNING_HI_FileOpenError(fileName);
this->m_fileUplink->log_WARNING_HI_FileOpenError(fileName);
this->warning();
}
@ -37,7 +37,7 @@ namespace Svc {
Fw::LogStringArg& fileName
)
{
this->fileUplink->log_WARNING_HI_PacketOutOfBounds(
this->m_fileUplink->log_WARNING_HI_PacketOutOfBounds(
sequenceIndex,
fileName
);
@ -50,7 +50,7 @@ namespace Svc {
const U32 lastSequenceIndex
)
{
this->fileUplink->log_WARNING_HI_PacketOutOfOrder(
this->m_fileUplink->log_WARNING_HI_PacketOutOfOrder(
sequenceIndex,
lastSequenceIndex
);
@ -60,7 +60,7 @@ namespace Svc {
void FileUplink::Warnings ::
fileWrite(Fw::LogStringArg& fileName)
{
this->fileUplink->log_WARNING_HI_FileWriteError(fileName);
this->m_fileUplink->log_WARNING_HI_FileWriteError(fileName);
this->warning();
}
@ -70,8 +70,8 @@ namespace Svc {
const U32 read
)
{
this->fileUplink->log_WARNING_HI_BadChecksum(
this->fileUplink->file.name,
this->m_fileUplink->log_WARNING_HI_BadChecksum(
this->m_fileUplink->file.name,
computed,
read
);

View File

@ -165,7 +165,7 @@ void TlmChan::Run_handler(NATIVE_INT_TYPE portNum, NATIVE_UINT_TYPE context) {
// reset packet for more entries
pkt.resetPktSer();
// add entry to new packet
Fw::SerializeStatus stat = pkt.addValue(p_entry->id, p_entry->lastUpdate, p_entry->buffer);
stat = pkt.addValue(p_entry->id, p_entry->lastUpdate, p_entry->buffer);
// if this doesn't work, that means packet isn't big enough for
// even one channel, so assert
FW_ASSERT(Fw::FW_SERIALIZE_OK == stat, static_cast<NATIVE_INT_TYPE>(stat));