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. 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 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, because this type of buffer is being implemented mainly for sensor data usage. Data is almost never read
and even if it is, it isn't meant to be cleared on read. It is a simple moving buffer that automatically individually, and even if it is, it isn't meant to be cleared on read. It is a simple moving buffer that
writes over old data for the purpose of keeping track of the most up to date data. automatically writes over old data for the purpose of keeping track of the most up to date data.
Notes: Notes:
- Initialization is mandatory using p_cb_<type>_init. - Initialization is mandatory using p_cb_<type>_init.
@ -29,8 +29,8 @@
#ifndef _PCIRCULARBUFFER_H_ #ifndef _PCIRCULARBUFFER_H_
#define _PCIRCULARBUFFER_H_ #define _PCIRCULARBUFFER_H_
#include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h>
// comment this out for release builds // comment this out for release builds
//#define PB_CB_DEBUG //#define PB_CB_DEBUG
@ -75,7 +75,6 @@ typedef enum PB_CB_STATUS
PB_CB_NULL_CBUFFER = 4 PB_CB_NULL_CBUFFER = 4
} PB_CB_STATUS; } PB_CB_STATUS;
#if PB_CB_U8 #if PB_CB_U8
typedef struct p_cb_u8 typedef struct p_cb_u8
{ {
@ -136,7 +135,6 @@ typedef struct 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 #endif
#if PB_CB_U64 #if PB_CB_U64
typedef struct p_cb_u64 typedef struct p_cb_u64
{ {
@ -197,7 +195,4 @@ typedef struct 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
#endif #endif

@ -104,11 +104,54 @@ PB_CB_STATUS p_cb_u8_init(p_cb_u8* circ_buffer, uint8_t* buff, uint32_t max_leng
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 #endif
// Circular Buffer Definitions -- uint16_t // Circular Buffer Definitions -- uint16_t
@ -348,7 +391,6 @@ PB_CB_STATUS p_cb_double_init(p_cb_double* circ_buffer, double* buff, uint32_t m
handle_status(__func__, ret); handle_status(__func__, ret);
#endif #endif
return ret; return ret;
} }
@ -390,10 +432,7 @@ PB_CB_STATUS p_cb_double_empty(p_cb_double* cbuffer)
ret = PB_CB_NULL_BUFFER; ret = PB_CB_NULL_BUFFER;
break; break;
} }
for(int ind = 0; ind < cbuffer->max_len; ind++) memset(cbuffer->buffer, 0, sizeof(double) * cbuffer->max_len);
{
cbuffer->buffer[ind] = 0.0;
}
cbuffer->head = 0; cbuffer->head = 0;
cbuffer->b_empty = true; cbuffer->b_empty = true;
cbuffer->b_filled = false; cbuffer->b_filled = false;

Loading…
Cancel
Save