Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update BufferAccumulator to FPv3 #1944

Merged
merged 23 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bb087ec
Adding updated BufferAccumulator files to public repo
kubiak-jpl Mar 21, 2023
ea35446
Ported BufferAccumulator to FPv3
kubiak-jpl Mar 22, 2023
60d247e
Cleanup notes and todos
kubiak-jpl Mar 22, 2023
ccc57d7
Cleanup old build system files
kubiak-jpl Mar 22, 2023
f6022a3
Updated format of code after a clang-format pass
kubiak-jpl Mar 22, 2023
4106dba
Style changes in BufferAccumulator
kubiak-jpl Mar 22, 2023
8f2c7bf
Replace NULL with nullptr in BufferAccumulator
kubiak-jpl Mar 23, 2023
81ba17b
Merge branch 'devel' into dev/BufferAccumulatorPort
kubiak-jpl Mar 23, 2023
340b963
Removed unnecessary cast and void arguments
kubiak-jpl Mar 27, 2023
e6f9440
Construct initial version of the Fw::Buffer objects to prevent UBSAN …
kubiak-jpl Mar 27, 2023
3c34b76
Fixing incorrect variable in asser message
LeStarch Mar 31, 2023
a80a303
Removing superfluous parenthesis on the placement new
LeStarch Mar 31, 2023
167fbf3
Adding header for placement new
LeStarch Mar 31, 2023
8c147a5
Adding explicit operator to appease CPPlint
LeStarch Mar 31, 2023
7127190
Added DRAINBUFFERS and NOBLOCK
timcanham Mar 31, 2023
9171a1c
Fixed Tester.cpp void arguments
timcanham Mar 31, 2023
eb792a1
Remove void
timcanham Mar 31, 2023
c100d6d
Remove void
timcanham Mar 31, 2023
b1beace
remove void
timcanham Mar 31, 2023
a832a65
Remove void
timcanham Mar 31, 2023
2d0017a
string header fix
timcanham Mar 31, 2023
0779ba4
Update comments in BufferAccumulator fdd
kubiak-jpl Apr 17, 2023
b8af314
Update BufferAccumulator.fpp
timcanham Apr 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 65 additions & 70 deletions Svc/BufferAccumulator/ArrayFIFOBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,98 +10,93 @@
//
// ======================================================================

#include "Svc/BufferAccumulator/BufferAccumulator.hpp"
#include <FpConfig.hpp>

#include "Fw/Types/Assert.hpp"
#include "Fw/Types/BasicTypes.hpp"
#include "Svc/BufferAccumulator/BufferAccumulator.hpp"
#include <new> // For placement new

namespace Svc {

// ----------------------------------------------------------------------
// Constructors
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
// Constructors
// ----------------------------------------------------------------------

BufferAccumulator::ArrayFIFOBuffer ::
ArrayFIFOBuffer() :
elements(nullptr),
BufferAccumulator::ArrayFIFOBuffer ::ArrayFIFOBuffer()
: elements(nullptr),
capacity(0),
enqueueIndex(0),
dequeueIndex(0),
size(0)
{
{
}

}
BufferAccumulator::ArrayFIFOBuffer ::~ArrayFIFOBuffer() {}

Check notice

Code scanning / CodeQL

More than one statement per line

This line contains 2 statements; only one is allowed.

// ----------------------------------------------------------------------
// Public functions
// ----------------------------------------------------------------------

BufferAccumulator::ArrayFIFOBuffer ::
~ArrayFIFOBuffer()
{
void BufferAccumulator::ArrayFIFOBuffer ::init(Fw::Buffer* const elements,
NATIVE_UINT_TYPE capacity) {
this->elements = elements;
this->capacity = capacity;

// Construct all elements
for (NATIVE_UINT_TYPE idx = 0; idx < capacity; idx++) {
new (&this->elements[idx]) Fw::Buffer;
}
}

// ----------------------------------------------------------------------
// Public functions
// ----------------------------------------------------------------------
bool BufferAccumulator::ArrayFIFOBuffer ::enqueue(const Fw::Buffer& e) {

Check notice

Code scanning / CodeQL

Long function without assertion

All functions of more than 10 lines should have at least one assertion.

void BufferAccumulator::ArrayFIFOBuffer ::
init(Fw::Buffer *const elements, NATIVE_UINT_TYPE capacity)
{
this->elements = elements;
this->capacity = capacity;
if (this->elements == nullptr) {
return false;
}

bool BufferAccumulator::ArrayFIFOBuffer ::
enqueue(const Fw::Buffer& e)
{
if (this->elements == nullptr) {
return false;
}
bool status;
if (this->size < this->capacity) {
// NOTE(mereweth) 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;
status = true;
++this->size;
}
else {
status = false;
}
return status;
bool status;
if (this->size < this->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;
status = true;
this->size++;
} else {
status = false;
}

bool BufferAccumulator::ArrayFIFOBuffer ::
dequeue(Fw::Buffer& e)
{
if (this->elements == nullptr) {
return false;
}
FW_ASSERT(this->elements);
bool status;
if (this->size > 0) {
// NOTE(mereweth) dequeueIndex is unsigned, no need to compare with 0
FW_ASSERT(dequeueIndex < this->capacity, enqueueIndex);
e = this->elements[this->dequeueIndex];
this->dequeueIndex = (this->dequeueIndex + 1) % this->capacity;
--this->size;
status = true;
}
else {
status = false;
}
return status;
}
return status;
}

bool BufferAccumulator::ArrayFIFOBuffer ::dequeue(Fw::Buffer& e) {

Check notice

Code scanning / CodeQL

Long function without assertion

All functions of more than 10 lines should have at least one assertion.

U32 BufferAccumulator::ArrayFIFOBuffer ::
getSize() const
{
return this->size;
if (this->elements == nullptr) {
return false;
}

U32 BufferAccumulator::ArrayFIFOBuffer ::
getCapacity() const
{
return this->capacity;
FW_ASSERT(this->elements);
bool status;

if (this->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--;
status = true;
} else {
status = false;
}

return status;
}

U32 BufferAccumulator::ArrayFIFOBuffer ::getSize() const {
return this->size;
}

U32 BufferAccumulator::ArrayFIFOBuffer ::getCapacity() const {
return this->capacity;
}

} // namespace Svc
Loading