restarting work on this since im using it in penguinator

master
Penguin 3 years ago
parent 519c761f7a
commit 125e6f2b5e

@ -0,0 +1,178 @@
---
Language: Cpp
# BasedOnStyle: Microsoft
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveMacros: None
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
AttributeMacros:
- __capability
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: true
AfterControlStatement: Always
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: false
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: true
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 1
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseLabels: false
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentExternBlock: AfterExternBlock
IndentRequires: false
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
LambdaBodyIndentation: Signature
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 1000
PenaltyIndentedWhitespace: 0
PointerAlignment: Right
PPIndentWidth: -1
ReferenceAlignment: Pointer
ReflowComments: true
ShortNamespaceLines: 1
SortIncludes: CaseSensitive
SortJavaStaticImport: Before
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceAroundPointerQualifiers: Default
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
BitFieldColonSpacing: Both
Standard: Latest
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 4
UseCRLF: false
UseTab: Always
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
- NS_SWIFT_NAME
- CF_SWIFT_NAME
...

@ -5,9 +5,9 @@
This is a ring buffer with limited capabilities. It is meant as a container for moving data.
Normally included features such as checks to see if the buffer is full or empty have been omitted
because this type of buffer is being implemented mainly for sensor data usage. Data is almost never read individually,
and even if it is, it isn't meant to be cleared on read. It is a simple moving buffer that automatically
writes over old data for the purpose of keeping track of the most up to date data.
because this type of buffer is being implemented mainly for sensor data usage. Data is almost never read
individually, and even if it is, it isn't meant to be cleared on read. It is a simple moving buffer that
automatically writes over old data for the purpose of keeping track of the most up to date data.
Notes:
- Initialization is mandatory using p_cb_<type>_init.
@ -29,8 +29,8 @@
#ifndef _PCIRCULARBUFFER_H_
#define _PCIRCULARBUFFER_H_
#include <stdint.h>
#include <stdbool.h>
#include <stdint.h>
// comment this out for release builds
//#define PB_CB_DEBUG
@ -40,11 +40,11 @@
// inversely active (enabled = 0, disable = 1)
// this way our en/dis definitions are explicit
#ifndef PB_ENABLE
#define PB_ENABLE (1)
#define PB_ENABLE (1)
#endif
#ifndef PB_DISABLE
#define PB_DISABLE (0)
#define PB_DISABLE (0)
#endif
// Max size is 65535 (2^16 - 1) so variables can be safely set 16 bits (unsigned)
@ -73,13 +73,12 @@ typedef enum PB_CB_STATUS
PB_CB_BAD_BUFFER_SIZE = 2,
PB_CB_NULL_BUFFER = 3,
PB_CB_NULL_CBUFFER = 4
}PB_CB_STATUS;
} PB_CB_STATUS;
#if PB_CB_U8
typedef struct p_cb_u8
{
uint8_t* buffer;
uint8_t *buffer;
uint16_t head;
uint16_t max_len;
// Signifies the buffer being filled at least once.
@ -89,17 +88,17 @@ typedef struct p_cb_u8
// Useful for knowing if data is being received
bool b_empty;
PB_CB_STATUS (*push)(struct p_cb_u8* cbuffer, uint8_t value);
PB_CB_STATUS (*empty)(struct p_cb_u8* cbuffer);
}p_cb_u8;
PB_CB_STATUS (*push)(struct p_cb_u8 *cbuffer, uint8_t value);
PB_CB_STATUS (*empty)(struct p_cb_u8 *cbuffer);
} p_cb_u8;
PB_CB_STATUS p_cb_u8_init(p_cb_u8* circ_buffer, uint8_t* buff, uint32_t max_length);
PB_CB_STATUS p_cb_u8_init(p_cb_u8 *circ_buffer, uint8_t *buff, uint32_t max_length);
#endif
#if PB_CB_U16
typedef struct p_cb_u16
{
uint16_t* buffer;
uint16_t *buffer;
uint16_t head;
uint16_t max_len;
// Signifies the buffer being filled at least once.
@ -109,17 +108,17 @@ typedef struct p_cb_u16
// Useful for knowing if data is being received
bool b_empty;
PB_CB_STATUS (*push)(struct p_cb_u16* cbuffer, uint16_t value);
PB_CB_STATUS (*empty)(struct p_cb_u16* cbuffer);
}p_cb_u16;
PB_CB_STATUS (*push)(struct p_cb_u16 *cbuffer, uint16_t value);
PB_CB_STATUS (*empty)(struct p_cb_u16 *cbuffer);
} p_cb_u16;
PB_CB_STATUS p_cb_u16_init(p_cb_u16* circ_buffer, uint16_t* buff, uint32_t max_length);
PB_CB_STATUS p_cb_u16_init(p_cb_u16 *circ_buffer, uint16_t *buff, uint32_t max_length);
#endif
#if PB_CB_U32
typedef struct p_cb_u32
{
uint32_t* buffer;
uint32_t *buffer;
uint16_t head;
uint16_t max_len;
// Signifies the buffer being filled at least once.
@ -129,18 +128,17 @@ typedef struct p_cb_u32
// Useful for knowing if data is being received
bool b_empty;
PB_CB_STATUS (*push)(struct p_cb_u32* cbuffer, uint32_t value);
PB_CB_STATUS (*empty)(struct p_cb_u32* cbuffer);
}p_cb_u32;
PB_CB_STATUS (*push)(struct p_cb_u32 *cbuffer, uint32_t value);
PB_CB_STATUS (*empty)(struct p_cb_u32 *cbuffer);
} p_cb_u32;
PB_CB_STATUS p_cb_u32_init(p_cb_u32* circ_buffer, uint32_t* buff, uint32_t max_length);
PB_CB_STATUS p_cb_u32_init(p_cb_u32 *circ_buffer, uint32_t *buff, uint32_t max_length);
#endif
#if PB_CB_U64
typedef struct p_cb_u64
{
uint64_t* buffer;
uint64_t *buffer;
uint16_t head;
uint16_t max_len;
// Signifies the buffer being filled at least once.
@ -150,17 +148,17 @@ typedef struct p_cb_u64
// Useful for knowing if data is being received
bool b_empty;
PB_CB_STATUS (*push)(struct p_cb_u64* cbuffer, uint64_t value);
PB_CB_STATUS (*empty)(struct p_cb_u64* cbuffer);
}p_cb_u64;
PB_CB_STATUS (*push)(struct p_cb_u64 *cbuffer, uint64_t value);
PB_CB_STATUS (*empty)(struct p_cb_u64 *cbuffer);
} p_cb_u64;
PB_CB_STATUS p_cb_u64_init(p_cb_u64* circ_buffer, uint64_t* buff, uint32_t max_length);
PB_CB_STATUS p_cb_u64_init(p_cb_u64 *circ_buffer, uint64_t *buff, uint32_t max_length);
#endif
#if PB_CB_FLOAT
typedef struct p_cb_float
{
float* buffer;
float *buffer;
uint16_t head;
uint16_t max_len;
// Signifies the buffer being filled at least once.
@ -170,17 +168,17 @@ typedef struct p_cb_float
// Useful for knowing if data is being received
bool b_empty;
PB_CB_STATUS (*push)(struct p_cb_float* cbuffer, float value);
PB_CB_STATUS (*empty)(struct p_cb_float* cbuffer);
}p_cb_float;
PB_CB_STATUS (*push)(struct p_cb_float *cbuffer, float value);
PB_CB_STATUS (*empty)(struct p_cb_float *cbuffer);
} p_cb_float;
PB_CB_STATUS p_cb_float_init(p_cb_float* circ_buffer, float* buff, uint32_t max_length);
PB_CB_STATUS p_cb_float_init(p_cb_float *circ_buffer, float *buff, uint32_t max_length);
#endif
#if PB_CB_DOUBLE
typedef struct p_cb_double
{
double* buffer;
double *buffer;
uint16_t head;
uint16_t max_len;
// Signifies the buffer being filled at least once.
@ -190,14 +188,11 @@ typedef struct p_cb_double
// Useful for knowing if data is being received
bool b_empty;
PB_CB_STATUS (*push)(struct p_cb_double* cbuffer, double value);
PB_CB_STATUS (*empty)(struct p_cb_double* cbuffer);
}p_cb_double;
PB_CB_STATUS (*push)(struct p_cb_double *cbuffer, double value);
PB_CB_STATUS (*empty)(struct p_cb_double *cbuffer);
} p_cb_double;
PB_CB_STATUS p_cb_double_init(p_cb_double* circ_buffer, double* buff, uint32_t max_length);
PB_CB_STATUS p_cb_double_init(p_cb_double *circ_buffer, double *buff, uint32_t max_length);
#endif
#endif

@ -3,9 +3,9 @@
// Error handler used for debugging only
#ifdef PB_CB_DEBUG
#include <stdio.h>
static void handle_status(const char* func, PB_CB_STATUS status_code)
static void handle_status(const char *func, PB_CB_STATUS status_code)
{
if(status_code != PB_CB_GOOD)
if (status_code != PB_CB_GOOD)
{
printf("%s failed: error code: %d\r\n", func, status_code);
}
@ -14,150 +14,193 @@ static void handle_status(const char* func, PB_CB_STATUS status_code)
// Circular Buffer Prototypes -- uint8_t
#if PB_CB_U8
static PB_CB_STATUS p_cb_u8_push(p_cb_double* cbuffer, uint8_t value);
static PB_CB_STATUS p_cb_u8_empty(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_u8_push(p_cb_double *cbuffer, uint8_t value);
static PB_CB_STATUS p_cb_u8_empty(p_cb_double *cbuffer);
#endif
// Circular Buffer Prototypes -- uint16_t
#if PB_CB_U16
static PB_CB_STATUS p_cb_u16_push(p_cb_double* cbuffer, uint16_t value);
static PB_CB_STATUS p_cb_u16_empty(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_u16_push(p_cb_double *cbuffer, uint16_t value);
static PB_CB_STATUS p_cb_u16_empty(p_cb_double *cbuffer);
#endif
// Circular Buffer Prototypes -- uint32_t
#if PB_CB_U32
static PB_CB_STATUS p_cb_u32_push(p_cb_double* cbuffer, uint32_t value);
static PB_CB_STATUS p_cb_u32_empty(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_u32_push(p_cb_double *cbuffer, uint32_t value);
static PB_CB_STATUS p_cb_u32_empty(p_cb_double *cbuffer);
#endif
// Circular Buffer Prototypes -- uint64_t
#if PB_CB_U64
static PB_CB_STATUS p_cb_u64_push(p_cb_double* cbuffer, uint64_t value);
static PB_CB_STATUS p_cb_u64_empty(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_u64_push(p_cb_double *cbuffer, uint64_t value);
static PB_CB_STATUS p_cb_u64_empty(p_cb_double *cbuffer);
#endif
// Circular Buffer Prototypes -- int8_t
#if PB_CB_I8
static PB_CB_STATUS p_cb_i8_push(p_cb_double* cbuffer, int8_t value);
static PB_CB_STATUS p_cb_i8_empty(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_i8_push(p_cb_double *cbuffer, int8_t value);
static PB_CB_STATUS p_cb_i8_empty(p_cb_double *cbuffer);
#endif
// Circular Buffer Prototypes -- int16_t
#if PB_CB_I16
static PB_CB_STATUS p_cb_i16_push(p_cb_double* cbuffer, int16_t value);
static PB_CB_STATUS p_cb_i16_empty(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_i16_push(p_cb_double *cbuffer, int16_t value);
static PB_CB_STATUS p_cb_i16_empty(p_cb_double *cbuffer);
#endif
// Circular Buffer Prototypes -- int32_t
#if PB_CB_I32
static PB_CB_STATUS p_cb_i32_push(p_cb_double* cbuffer, int32_t value);
static PB_CB_STATUS p_cb_i32_empty(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_i32_push(p_cb_double *cbuffer, int32_t value);
static PB_CB_STATUS p_cb_i32_empty(p_cb_double *cbuffer);
#endif
// Circular Buffer Prototypes -- int64_t
#if PB_CB_I64
static PB_CB_STATUS p_cb_i64_push(p_cb_double* cbuffer, int64_t value);
static PB_CB_STATUS p_cb_i64_empty(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_i64_push(p_cb_double *cbuffer, int64_t value);
static PB_CB_STATUS p_cb_i64_empty(p_cb_double *cbuffer);
#endif
// Circular Buffer Prototypes -- Float
#if PB_CB_FLOAT
static PB_CB_STATUS p_cb_float_push(p_cb_double* cbuffer, float value);
static PB_CB_STATUS p_cb_float_empty(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_float_push(p_cb_double *cbuffer, float value);
static PB_CB_STATUS p_cb_float_empty(p_cb_double *cbuffer);
#endif
// Circular Buffer Prototypes -- Double
#if PB_CB_DOUBLE
static PB_CB_STATUS p_cb_double_push(p_cb_double* cbuffer, double value);
static PB_CB_STATUS p_cb_double_empty(p_cb_double* cbuffer);
static PB_CB_STATUS p_cb_double_push(p_cb_double *cbuffer, double value);
static PB_CB_STATUS p_cb_double_empty(p_cb_double *cbuffer);
#endif
// Circular Buffer Definitions -- uint8_t
#if PB_CB_U8
PB_CB_STATUS p_cb_u8_init(p_cb_u8* circ_buffer, uint8_t* buff, uint32_t max_length)
PB_CB_STATUS p_cb_u8_init(p_cb_u8 *circ_buffer, uint8_t *buff, uint32_t max_length)
{
PB_CB_STATUS ret = PB_CB_GOOD;
do
{
// Make sure the buffer isn't bad (null)
if(!buff)
if (!buff)
{
ret = PB_CB_NULL_BUFFER;
break;
}
// Make sure the max buffer is a useable size
if(max_length > PB_CB_MAX_BUFFER_SIZE || max_length <= 0)
if (max_length > PB_CB_MAX_BUFFER_SIZE || max_length <= 0)
{
ret = PB_CB_BAD_BUFFER_SIZE;
break;
}
} while (0);
// Debugging
#ifdef PB_CB_DEBUG
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
#endif
return ret;
}
PB_CB_STATUS p_cb_u8_push(p_cb_double* cbuffer, uint8_t value)
PB_CB_STATUS p_cb_u8_push(p_cb_double *cbuffer, uint8_t value)
{
PB_CB_STATUS ret = PB_CB_GOOD;
if (!cbuffer)
{
ret = PB_CB_NULL_CBUFFER;
}
else
{
cbuffer->buffer[cbuffer->head] = value;
cbuffer->head = (cbuffer->head + 1) % cbuffer->max_len;
}
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
return ret;
}
PB_CB_STATUS p_cb_u8_empty(p_cb_double* cbuffer)
PB_CB_STATUS p_cb_u8_empty(p_cb_double *cbuffer)
{
PB_CB_STATUS ret = PB_CB_GOOD;
do
{
if (!cbuffer)
{
ret = PB_CB_NULL_CBUFFER;
break;
}
if (!cbuffer->buffer)
{
ret = PB_CB_NULL_BUFFER;
break;
}
memset(cbuffer->buffer, 0, cbuffer->max_len);
cbuffer->head = 0;
cbuffer->b_empty = true;
cbuffer->b_filled = false;
} while (0);
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
return ret;
}
#endif
// Circular Buffer Definitions -- uint16_t
#if PB_CB_U16
PB_CB_STATUS p_cb_u16_init(p_cb_u16* circ_buffer, uint16_t* buff, uint32_t max_length)
PB_CB_STATUS p_cb_u16_init(p_cb_u16 *circ_buffer, uint16_t *buff, uint32_t max_length)
{
PB_CB_STATUS ret = PB_CB_GOOD;
do
{
// Make sure the buffer isn't bad (null)
if(!buff)
if (!buff)
{
ret = PB_CB_NULL_BUFFER;
break;
}
// Make sure the max buffer is a useable size
if(max_length > PB_CB_MAX_BUFFER_SIZE || max_length <= 0)
if (max_length > PB_CB_MAX_BUFFER_SIZE || max_length <= 0)
{
ret = PB_CB_BAD_BUFFER_SIZE;
break;
}
} while (0);
// Debugging
#ifdef PB_CB_DEBUG
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
#endif
return ret;
}
PB_CB_STATUS p_cb_u16_push(p_cb_double* cbuffer, uint16_t value)
PB_CB_STATUS p_cb_u16_push(p_cb_double *cbuffer, uint16_t value)
{
PB_CB_STATUS ret = PB_CB_GOOD;
// Debugging
#ifdef PB_CB_DEBUG
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
#endif
return ret;
}
PB_CB_STATUS p_cb_u16_empty(p_cb_double* cbuffer)
PB_CB_STATUS p_cb_u16_empty(p_cb_double *cbuffer)
{
PB_CB_STATUS ret = PB_CB_GOOD;
// Debugging
#ifdef PB_CB_DEBUG
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
#endif
return ret;
}
@ -165,50 +208,50 @@ PB_CB_STATUS p_cb_u16_empty(p_cb_double* cbuffer)
// Circular Buffer Definitions -- uint32_t
#if PB_CB_U32
PB_CB_STATUS p_cb_u32_init(p_cb_u32* circ_buffer, uint32_t* buff, uint32_t max_length)
PB_CB_STATUS p_cb_u32_init(p_cb_u32 *circ_buffer, uint32_t *buff, uint32_t max_length)
{
PB_CB_STATUS ret = PB_CB_GOOD;
do
{
// Make sure the buffer isn't bad (null)
if(!buff)
if (!buff)
{
ret = PB_CB_NULL_BUFFER;
break;
}
// Make sure the max buffer is a useable size
if(max_length > PB_CB_MAX_BUFFER_SIZE || max_length <= 0)
if (max_length > PB_CB_MAX_BUFFER_SIZE || max_length <= 0)
{
ret = PB_CB_BAD_BUFFER_SIZE;
break;
}
} while (0);
// Debugging
#ifdef PB_CB_DEBUG
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
#endif
return ret;
}
PB_CB_STATUS p_cb_u32_push(p_cb_double* cbuffer, uint32_t value)
PB_CB_STATUS p_cb_u32_push(p_cb_double *cbuffer, uint32_t value)
{
PB_CB_STATUS ret = PB_CB_GOOD;
// Debugging
#ifdef PB_CB_DEBUG
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
#endif
return ret;
}
PB_CB_STATUS p_cb_u32_empty(p_cb_double* cbuffer)
PB_CB_STATUS p_cb_u32_empty(p_cb_double *cbuffer)
{
PB_CB_STATUS ret = PB_CB_GOOD;
// Debugging
#ifdef PB_CB_DEBUG
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
#endif
return ret;
}
@ -216,100 +259,100 @@ PB_CB_STATUS p_cb_u32_empty(p_cb_double* cbuffer)
// Circular Buffer Definitions -- uint64_t
#if PB_CB_U64
PB_CB_STATUS p_cb_u64_init(p_cb_u64* circ_buffer, uint64_t* buff, uint32_t max_length)
PB_CB_STATUS p_cb_u64_init(p_cb_u64 *circ_buffer, uint64_t *buff, uint32_t max_length)
{
PB_CB_STATUS ret = PB_CB_GOOD;
do
{
// Make sure the buffer isn't bad (null)
if(!buff)
if (!buff)
{
ret = PB_CB_NULL_BUFFER;
break;
}
// Make sure the max buffer is a useable size
if(max_length > PB_CB_MAX_BUFFER_SIZE || max_length <= 0)
if (max_length > PB_CB_MAX_BUFFER_SIZE || max_length <= 0)
{
ret = PB_CB_BAD_BUFFER_SIZE;
break;
}
} while (0);
// Debugging
#ifdef PB_CB_DEBUG
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
#endif
return ret;
}
PB_CB_STATUS p_cb_u64_push(p_cb_double* cbuffer, uint64_t value)
PB_CB_STATUS p_cb_u64_push(p_cb_double *cbuffer, uint64_t value)
{
PB_CB_STATUS ret = PB_CB_GOOD;
// Debugging
#ifdef PB_CB_DEBUG
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
#endif
return ret;
}
PB_CB_STATUS p_cb_u64_empty(p_cb_double* cbuffer)
PB_CB_STATUS p_cb_u64_empty(p_cb_double *cbuffer)
{
PB_CB_STATUS ret = PB_CB_GOOD;
// Debugging
#ifdef PB_CB_DEBUG
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
#endif
return ret;
}
#endif
#if PB_CB_FLOAT
PB_CB_STATUS p_cb_float_init(p_cb_float* circ_buffer, float* buff, uint32_t max_length)
PB_CB_STATUS p_cb_float_init(p_cb_float *circ_buffer, float *buff, uint32_t max_length)
{
PB_CB_STATUS ret = PB_CB_GOOD;
do
{
// Make sure the buffer isn't bad (null)
if(!buff)
if (!buff)
{
ret = PB_CB_NULL_BUFFER;
break;
}
// Make sure the max buffer is a useable size
if(max_length > PB_CB_MAX_BUFFER_SIZE || max_length <= 0)
if (max_length > PB_CB_MAX_BUFFER_SIZE || max_length <= 0)
{
ret = PB_CB_BAD_BUFFER_SIZE;
break;
}
} while (0);
// Debugging
#ifdef PB_CB_DEBUG
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
#endif
return ret;
}
PB_CB_STATUS p_cb_float_push(p_cb_double* cbuffer, float value)
PB_CB_STATUS p_cb_float_push(p_cb_double *cbuffer, float value)
{
PB_CB_STATUS ret = PB_CB_GOOD;
// Debugging
#ifdef PB_CB_DEBUG
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
#endif
return ret;
}
PB_CB_STATUS p_cb_float_empty(p_cb_double* cbuffer)
PB_CB_STATUS p_cb_float_empty(p_cb_double *cbuffer)
{
PB_CB_STATUS ret = PB_CB_GOOD;
// Debugging
#ifdef PB_CB_DEBUG
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
#endif
return ret;
}
@ -317,20 +360,20 @@ PB_CB_STATUS p_cb_float_empty(p_cb_double* cbuffer)
// Circular Buffer Definitions -- double
#if PB_CB_DOUBLE
PB_CB_STATUS p_cb_double_init(p_cb_double* circ_buffer, double* buff, uint32_t max_length)
PB_CB_STATUS p_cb_double_init(p_cb_double *circ_buffer, double *buff, uint32_t max_length)
{
PB_CB_STATUS ret = PB_CB_GOOD;
do
{
// Make sure the buffer isn't bad (null)
if(!buff)
if (!buff)
{
ret = PB_CB_NULL_BUFFER;
break;
}
// Make sure the max buffer is a useable size
if(max_length > PB_CB_MAX_BUFFER_SIZE || max_length <= 0)
if (max_length > PB_CB_MAX_BUFFER_SIZE || max_length <= 0)
{
ret = PB_CB_BAD_BUFFER_SIZE;
break;
@ -343,20 +386,19 @@ PB_CB_STATUS p_cb_double_init(p_cb_double* circ_buffer, double* buff, uint32_t m
circ_buffer->empty(circ_buffer);
} while (0);
// Debugging
#ifdef PB_CB_DEBUG
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
#endif
return ret;
}
PB_CB_STATUS p_cb_double_push(p_cb_double* cbuffer, double value)
PB_CB_STATUS p_cb_double_push(p_cb_double *cbuffer, double value)
{
PB_CB_STATUS ret = PB_CB_GOOD;
if(!cbuffer)
if (!cbuffer)
{
ret = PB_CB_NULL_CBUFFER;
}
@ -366,43 +408,40 @@ PB_CB_STATUS p_cb_double_push(p_cb_double* cbuffer, double value)
cbuffer->head = (cbuffer->head + 1) % cbuffer->max_len;
}
// Debugging
#ifdef PB_CB_DEBUG
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
#endif
return ret;
}
PB_CB_STATUS p_cb_double_empty(p_cb_double* cbuffer)
PB_CB_STATUS p_cb_double_empty(p_cb_double *cbuffer)
{
PB_CB_STATUS ret = PB_CB_GOOD;
do
{
if(!cbuffer)
if (!cbuffer)
{
ret = PB_CB_NULL_CBUFFER;
break;
}
if(!cbuffer->buffer)
if (!cbuffer->buffer)
{
ret = PB_CB_NULL_BUFFER;
break;
}
for(int ind = 0; ind < cbuffer->max_len; ind++)
{
cbuffer->buffer[ind] = 0.0;
}
memset(cbuffer->buffer, 0, sizeof(double) * cbuffer->max_len);
cbuffer->head = 0;
cbuffer->b_empty = true;
cbuffer->b_filled = false;
} while (0);
// Debugging
#ifdef PB_CB_DEBUG
// Debugging
#ifdef PB_CB_DEBUG
handle_status(__func__, ret);
#endif
#endif
return ret;
}

Loading…
Cancel
Save