From 4d3500050fdf0af285eda4e743b27d8a72ffa8f5 Mon Sep 17 00:00:00 2001 From: Windel Bouwman Date: Thu, 23 Apr 2026 13:29:56 +0200 Subject: [PATCH 1/3] Add clang format file. --- .clang-format | 321 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 321 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..f814a339 --- /dev/null +++ b/.clang-format @@ -0,0 +1,321 @@ +--- +Language: Cpp +AlignAfterOpenBracket: true +AccessModifierOffset: -2 +AlignArrayOfStructures: None +AlignConsecutiveAssignments: + Enabled: true + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: false + AlignFunctionPointers: false + PadOperators: true +AlignConsecutiveBitFields: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: true + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveMacros: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveShortCaseStatements: + Enabled: true + AcrossEmptyLines: true + AcrossComments: false + AlignCaseArrows: false + AlignCaseColons: true +AlignConsecutiveTableGenBreakingDAGArgColons: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveTableGenCondOperatorColons: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveTableGenDefinitionColons: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: false + AlignFunctionPointers: false + PadOperators: false +AlignEscapedNewlines: Right +AlignOperands: Align +AlignTrailingComments: + AlignPPAndNotPP: true + Kind: Always + OverEmptyLines: 0 +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowBreakBeforeNoexceptSpecifier: Never +AllowBreakBeforeQtProperty: false +AllowShortBlocksOnASingleLine: Never +AllowShortCaseExpressionOnASingleLine: true +AllowShortCaseLabelsOnASingleLine: true +AllowShortCompoundRequirementOnASingleLine: true +AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: Inline +AllowShortLoopsOnASingleLine: false +AllowShortNamespacesOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AttributeMacros: + - __capability +BinPackArguments: true +BinPackLongBracedList: true +BinPackParameters: BinPack +BitFieldColonSpacing: Both +BracedInitializerIndentWidth: -1 +BraceWrapping: + AfterCaseLabel: true + AfterClass: false + AfterControlStatement: Always + AfterEnum: false + AfterExternBlock: false + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: true + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: false +BreakAdjacentStringLiterals: true +BreakAfterAttributes: Leave +BreakAfterJavaFieldAnnotations: false +BreakAfterOpenBracketBracedList: false +BreakAfterOpenBracketFunction: false +BreakAfterOpenBracketIf: false +BreakAfterOpenBracketLoop: false +BreakAfterOpenBracketSwitch: true +BreakAfterReturnType: Automatic +BreakArrays: true +BreakBeforeBinaryOperators: None +BreakBeforeCloseBracketBracedList: false +BreakBeforeCloseBracketFunction: false +BreakBeforeCloseBracketIf: false +BreakBeforeCloseBracketLoop: false +BreakBeforeCloseBracketSwitch: false +BreakBeforeConceptDeclarations: Always +BreakBeforeBraces: Custom +BreakBeforeInlineASMColon: OnlyMultiline +BreakBeforeTemplateCloser: false +BreakBeforeTernaryOperators: true +BreakBinaryOperations: Never +BreakConstructorInitializers: BeforeComma +BreakFunctionDefinitionParameters: false +BreakInheritanceList: BeforeColon +BreakStringLiterals: true +BreakTemplateDeclarations: MultiLine +ColumnLimit: 200 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: AlignFirstComment +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +EnumTrailingComma: Leave +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +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 +IndentCaseBlocks: false +IndentCaseLabels: true +IndentExportBlock: true +IndentExternBlock: AfterExternBlock +IndentGotoLabels: true +IndentPPDirectives: None +IndentRequiresClause: true +IndentWidth: 4 +IndentWrappedFunctionNames: false +InsertBraces: false +InsertNewlineAtEOF: false +InsertTrailingCommas: None +IntegerLiteralSeparator: + Binary: 0 + BinaryMinDigitsInsert: 0 + BinaryMaxDigitsRemove: 0 + Decimal: 0 + DecimalMinDigitsInsert: 0 + DecimalMaxDigitsRemove: 0 + Hex: 0 + HexMinDigitsInsert: 0 + HexMaxDigitsRemove: 0 + BinaryMinDigits: 0 + DecimalMinDigits: 0 + HexMinDigits: 0 +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLines: + AtEndOfFile: false + AtStartOfBlock: true + AtStartOfFile: true +KeepFormFeed: false +LambdaBodyIndentation: Signature +LineEnding: DeriveLF +MacroBlockBegin: '' +MacroBlockEnd: '' +MainIncludeChar: Quote +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: All +NumericLiteralCase: + ExponentLetter: Leave + HexDigit: Leave + Prefix: Leave + Suffix: Leave +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +OneLineFormatOffRegex: '' +PackConstructorInitializers: Never +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakBeforeMemberAccess: 150 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakScopeResolution: 500 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyIndentedWhitespace: 0 +PenaltyReturnTypeOnItsOwnLine: 160 +PointerAlignment: Left +PPIndentWidth: -1 +QualifierAlignment: Leave +ReferenceAlignment: Pointer +ReflowComments: Always +RemoveBracesLLVM: false +RemoveEmptyLinesInUnwrappedLines: false +RemoveParentheses: Leave +RemoveSemicolon: false +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SkipMacroDefinitionBody: false +SortIncludes: + Enabled: false + IgnoreCase: false + IgnoreExtension: false +SortJavaStaticImport: Before +SortUsingDeclarations: LexicographicNumeric +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: true +SpaceAfterOperatorKeyword: true +SpaceAfterTemplateKeyword: false +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeJsonColon: false +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterNot: true + AfterOverloadedOperator: false + AfterPlacementOperator: true + AfterRequiresInClause: false + AfterRequiresInExpression: false + BeforeNonEmptyParentheses: false +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBraces: Never +SpacesBeforeTrailingComments: 2 +SpacesInAngles: Never +SpacesInContainerLiterals: true +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParens: Never +SpacesInParensOptions: + ExceptDoubleParentheses: false + InCStyleCasts: false + InConditionalStatements: false + InEmptyParentheses: false + Other: false +SpacesInSquareBrackets: false +Standard: Latest +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TableGenBreakInsideDAGArg: DontBreak +TabWidth: 8 +UseTab: Never +VerilogBreakBetweenInstancePorts: true +WhitespaceSensitiveMacros: + - BOOST_PP_STRINGIZE + - CF_SWIFT_NAME + - NS_SWIFT_NAME + - PP_STRINGIZE + - STRINGIZE +WrapNamespaceBodyWithEmptyLines: Leave +... + From 44f3201ebd3bf4077be3f6fcf2705872001162b3 Mon Sep 17 00:00:00 2001 From: Windel Bouwman Date: Wed, 24 Jun 2026 09:43:06 +0200 Subject: [PATCH 2/3] Add script to run uncrustify --- .clang-format | 321 ------------------------------------------ scripts/format_cpp.sh | 105 ++++++++++++++ 2 files changed, 105 insertions(+), 321 deletions(-) delete mode 100644 .clang-format create mode 100755 scripts/format_cpp.sh diff --git a/.clang-format b/.clang-format deleted file mode 100644 index f814a339..00000000 --- a/.clang-format +++ /dev/null @@ -1,321 +0,0 @@ ---- -Language: Cpp -AlignAfterOpenBracket: true -AccessModifierOffset: -2 -AlignArrayOfStructures: None -AlignConsecutiveAssignments: - Enabled: true - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionDeclarations: false - AlignFunctionPointers: false - PadOperators: true -AlignConsecutiveBitFields: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionDeclarations: false - AlignFunctionPointers: false - PadOperators: false -AlignConsecutiveDeclarations: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionDeclarations: true - AlignFunctionPointers: false - PadOperators: false -AlignConsecutiveMacros: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionDeclarations: false - AlignFunctionPointers: false - PadOperators: false -AlignConsecutiveShortCaseStatements: - Enabled: true - AcrossEmptyLines: true - AcrossComments: false - AlignCaseArrows: false - AlignCaseColons: true -AlignConsecutiveTableGenBreakingDAGArgColons: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionDeclarations: false - AlignFunctionPointers: false - PadOperators: false -AlignConsecutiveTableGenCondOperatorColons: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionDeclarations: false - AlignFunctionPointers: false - PadOperators: false -AlignConsecutiveTableGenDefinitionColons: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionDeclarations: false - AlignFunctionPointers: false - PadOperators: false -AlignEscapedNewlines: Right -AlignOperands: Align -AlignTrailingComments: - AlignPPAndNotPP: true - Kind: Always - OverEmptyLines: 0 -AllowAllArgumentsOnNextLine: true -AllowAllParametersOfDeclarationOnNextLine: true -AllowBreakBeforeNoexceptSpecifier: Never -AllowBreakBeforeQtProperty: false -AllowShortBlocksOnASingleLine: Never -AllowShortCaseExpressionOnASingleLine: true -AllowShortCaseLabelsOnASingleLine: true -AllowShortCompoundRequirementOnASingleLine: true -AllowShortEnumsOnASingleLine: true -AllowShortFunctionsOnASingleLine: None -AllowShortIfStatementsOnASingleLine: Never -AllowShortLambdasOnASingleLine: Inline -AllowShortLoopsOnASingleLine: false -AllowShortNamespacesOnASingleLine: false -AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakBeforeMultilineStrings: false -AttributeMacros: - - __capability -BinPackArguments: true -BinPackLongBracedList: true -BinPackParameters: BinPack -BitFieldColonSpacing: Both -BracedInitializerIndentWidth: -1 -BraceWrapping: - AfterCaseLabel: true - AfterClass: false - AfterControlStatement: Always - AfterEnum: false - AfterExternBlock: false - AfterFunction: true - AfterNamespace: true - AfterObjCDeclaration: false - AfterStruct: false - AfterUnion: false - BeforeCatch: true - BeforeElse: false - BeforeLambdaBody: false - BeforeWhile: false - IndentBraces: false - SplitEmptyFunction: true - SplitEmptyRecord: true - SplitEmptyNamespace: false -BreakAdjacentStringLiterals: true -BreakAfterAttributes: Leave -BreakAfterJavaFieldAnnotations: false -BreakAfterOpenBracketBracedList: false -BreakAfterOpenBracketFunction: false -BreakAfterOpenBracketIf: false -BreakAfterOpenBracketLoop: false -BreakAfterOpenBracketSwitch: true -BreakAfterReturnType: Automatic -BreakArrays: true -BreakBeforeBinaryOperators: None -BreakBeforeCloseBracketBracedList: false -BreakBeforeCloseBracketFunction: false -BreakBeforeCloseBracketIf: false -BreakBeforeCloseBracketLoop: false -BreakBeforeCloseBracketSwitch: false -BreakBeforeConceptDeclarations: Always -BreakBeforeBraces: Custom -BreakBeforeInlineASMColon: OnlyMultiline -BreakBeforeTemplateCloser: false -BreakBeforeTernaryOperators: true -BreakBinaryOperations: Never -BreakConstructorInitializers: BeforeComma -BreakFunctionDefinitionParameters: false -BreakInheritanceList: BeforeColon -BreakStringLiterals: true -BreakTemplateDeclarations: MultiLine -ColumnLimit: 200 -CommentPragmas: '^ IWYU pragma:' -CompactNamespaces: false -ConstructorInitializerIndentWidth: 4 -ContinuationIndentWidth: 4 -Cpp11BracedListStyle: AlignFirstComment -DerivePointerAlignment: false -DisableFormat: false -EmptyLineAfterAccessModifier: Never -EmptyLineBeforeAccessModifier: LogicalBlock -EnumTrailingComma: Leave -ExperimentalAutoDetectBinPacking: false -FixNamespaceComments: false -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 -IndentCaseBlocks: false -IndentCaseLabels: true -IndentExportBlock: true -IndentExternBlock: AfterExternBlock -IndentGotoLabels: true -IndentPPDirectives: None -IndentRequiresClause: true -IndentWidth: 4 -IndentWrappedFunctionNames: false -InsertBraces: false -InsertNewlineAtEOF: false -InsertTrailingCommas: None -IntegerLiteralSeparator: - Binary: 0 - BinaryMinDigitsInsert: 0 - BinaryMaxDigitsRemove: 0 - Decimal: 0 - DecimalMinDigitsInsert: 0 - DecimalMaxDigitsRemove: 0 - Hex: 0 - HexMinDigitsInsert: 0 - HexMaxDigitsRemove: 0 - BinaryMinDigits: 0 - DecimalMinDigits: 0 - HexMinDigits: 0 -JavaScriptQuotes: Leave -JavaScriptWrapImports: true -KeepEmptyLines: - AtEndOfFile: false - AtStartOfBlock: true - AtStartOfFile: true -KeepFormFeed: false -LambdaBodyIndentation: Signature -LineEnding: DeriveLF -MacroBlockBegin: '' -MacroBlockEnd: '' -MainIncludeChar: Quote -MaxEmptyLinesToKeep: 1 -NamespaceIndentation: All -NumericLiteralCase: - ExponentLetter: Leave - HexDigit: Leave - Prefix: Leave - Suffix: Leave -ObjCBinPackProtocolList: Auto -ObjCBlockIndentWidth: 2 -ObjCBreakBeforeNestedBlockParam: true -ObjCSpaceAfterProperty: false -ObjCSpaceBeforeProtocolList: true -OneLineFormatOffRegex: '' -PackConstructorInitializers: Never -PenaltyBreakAssignment: 2 -PenaltyBreakBeforeFirstCallParameter: 19 -PenaltyBreakBeforeMemberAccess: 150 -PenaltyBreakComment: 300 -PenaltyBreakFirstLessLess: 120 -PenaltyBreakOpenParenthesis: 0 -PenaltyBreakScopeResolution: 500 -PenaltyBreakString: 1000 -PenaltyBreakTemplateDeclaration: 10 -PenaltyExcessCharacter: 1000000 -PenaltyIndentedWhitespace: 0 -PenaltyReturnTypeOnItsOwnLine: 160 -PointerAlignment: Left -PPIndentWidth: -1 -QualifierAlignment: Leave -ReferenceAlignment: Pointer -ReflowComments: Always -RemoveBracesLLVM: false -RemoveEmptyLinesInUnwrappedLines: false -RemoveParentheses: Leave -RemoveSemicolon: false -RequiresClausePosition: OwnLine -RequiresExpressionIndentation: OuterScope -SeparateDefinitionBlocks: Leave -ShortNamespaceLines: 1 -SkipMacroDefinitionBody: false -SortIncludes: - Enabled: false - IgnoreCase: false - IgnoreExtension: false -SortJavaStaticImport: Before -SortUsingDeclarations: LexicographicNumeric -SpaceAfterCStyleCast: false -SpaceAfterLogicalNot: true -SpaceAfterOperatorKeyword: true -SpaceAfterTemplateKeyword: false -SpaceAroundPointerQualifiers: Default -SpaceBeforeAssignmentOperators: true -SpaceBeforeCaseColon: false -SpaceBeforeCpp11BracedList: false -SpaceBeforeCtorInitializerColon: true -SpaceBeforeInheritanceColon: true -SpaceBeforeJsonColon: false -SpaceBeforeParens: ControlStatements -SpaceBeforeParensOptions: - AfterControlStatements: true - AfterForeachMacros: true - AfterFunctionDefinitionName: false - AfterFunctionDeclarationName: false - AfterIfMacros: true - AfterNot: true - AfterOverloadedOperator: false - AfterPlacementOperator: true - AfterRequiresInClause: false - AfterRequiresInExpression: false - BeforeNonEmptyParentheses: false -SpaceBeforeRangeBasedForLoopColon: true -SpaceBeforeSquareBrackets: false -SpaceInEmptyBraces: Never -SpacesBeforeTrailingComments: 2 -SpacesInAngles: Never -SpacesInContainerLiterals: true -SpacesInLineCommentPrefix: - Minimum: 1 - Maximum: -1 -SpacesInParens: Never -SpacesInParensOptions: - ExceptDoubleParentheses: false - InCStyleCasts: false - InConditionalStatements: false - InEmptyParentheses: false - Other: false -SpacesInSquareBrackets: false -Standard: Latest -StatementAttributeLikeMacros: - - Q_EMIT -StatementMacros: - - Q_UNUSED - - QT_REQUIRE_VERSION -TableGenBreakInsideDAGArg: DontBreak -TabWidth: 8 -UseTab: Never -VerilogBreakBetweenInstancePorts: true -WhitespaceSensitiveMacros: - - BOOST_PP_STRINGIZE - - CF_SWIFT_NAME - - NS_SWIFT_NAME - - PP_STRINGIZE - - STRINGIZE -WrapNamespaceBodyWithEmptyLines: Leave -... - diff --git a/scripts/format_cpp.sh b/scripts/format_cpp.sh new file mode 100755 index 00000000..10d4dec1 --- /dev/null +++ b/scripts/format_cpp.sh @@ -0,0 +1,105 @@ +#!/bin/bash + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" + +source "$SCRIPT_DIR/lib/log.sh" + +DEFAULT_DIRS=("lib" "examples") + +if ! command -v uncrustify &> /dev/null; then + error "uncrustify is not installed or not in PATH." + exit 1 +fi + +print_usage() { + echo "Usage: $0 [check|apply] [paths...]" + echo "" + echo "Commands:" + echo " check Verify that files are correctly formatted (used in CI)." + echo " apply Apply formatting to files in place." + echo "" + echo "If no paths are provided, it defaults to: ${DEFAULT_DIRS[*]}" +} + +get_filenames() { + local search_paths=("$@") + if [ ${#search_paths[@]} -eq 0 ]; then + search_paths=("${DEFAULT_DIRS[@]}") + fi + + local final_paths=() + for path in "${search_paths[@]}"; do + if [[ ! -e "$path" && -e "$PROJECT_ROOT/$path" ]]; then + final_paths+=("$PROJECT_ROOT/$path") + elif [[ -e "$path" ]]; then + final_paths+=("$path") + else + warn "Skipping non-existing path $path" + fi + done + + local filenames=() + for path in "${final_paths[@]}"; do + while IFS= read -r -d '' filename; do + filenames+=("$filename") + done < <(find "$path" -name '*.cc' -print0) + done + echo "${filenames[@]}" +} + +check_format() { + local filenames + filenames=$(get_filenames "$@") + + step "Checking C++ formatting" + local total_files=0 + local bad_files=0 + for filename in $filenames; do + info "Checking $filename ..." + total_files=$((total_files + 1)) + if uncrustify -c "$PROJECT_ROOT/uncrustify.cfg" --check "$filename"; then + info "OK" + else + bad_files=$((bad_files + 1)) + warn "format not ok" + diff -u "$filename" <(uncrustify -c "$PROJECT_ROOT/uncrustify.cfg" -f "$filename") + fi + done + + if [ $bad_files -gt 0 ]; then + error "${bad_files} out of ${total_files} C++ files are not correctly formatted. Run '$0 apply' to fix." + return 1 + else + success "All ${total_files} C++ files are correctly formatted." + return 0 + fi +} + +apply_format() { + local filenames + filenames=$(get_filenames "$@") + + step "Applying C++ formatting" + for filename in $filenames; do + info "Formatting $filename" + uncrustify -c "$PROJECT_ROOT/uncrustify.cfg" --replace --no-backup "$filename" + done + success "Formatting applied." +} + +# Main execution logic +case "$1" in + check) + shift + check_format "$@" + ;; + apply) + shift + apply_format "$@" + ;; + *) + print_usage + exit 1 + ;; +esac From aac149869857051b7ce5b2728f78b49976b09e5a Mon Sep 17 00:00:00 2001 From: Windel Bouwman Date: Sat, 18 Jul 2026 14:21:09 +0200 Subject: [PATCH 3/3] Format slave examples and add CI step. --- .github/workflows/ci.yml | 19 +++- examples/slave/common/xpg_strerror_r.cc | 2 +- .../slave/nuttx/lan9252/arduino-due/main.cc | 16 +-- .../slave/nuttx/lan9252/freedom-k64f/main.cc | 21 ++-- .../lan9252/freedom-k64f/od_populator.cc | 72 ++++++------- examples/slave/nuttx/xmc4800/main_foot.cc | 4 +- examples/slave/nuttx/xmc4800/main_relax.cc | 32 +++--- examples/slave/nuttx/xmc4800/od_populator.cc | 100 +++++++++--------- examples/slave/rpi/lan9252/main.cc | 2 +- examples/slave/rpi/lan9252/od_populator.cc | 44 ++++---- 10 files changed, 160 insertions(+), 152 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ac34fe89..d00a6ca4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,9 +22,18 @@ jobs: - name: Check Python formatting and linting run: scripts/format_py.sh check + cpp_lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - name: Install uncrustify + run: sudo apt-get update && sudo apt-get install -y uncrustify + - name: Check C++ formatting + run: scripts/format_cpp.sh check examples/slave + # Build C++ and Build Wheels build_x86: - needs: py_lint + needs: [py_lint, cpp_lint] name: Build C++ (${{ matrix.os }}${{ matrix.preset && format(' - {0}', matrix.preset) || '' }}) runs-on: ${{ matrix.os }} strategy: @@ -107,7 +116,7 @@ jobs: # Sanitizer build + unit tests: ASan + LSan + UBSan (catches overflows, use-after-free, leaks, # and undefined behaviour; alignment is excluded for the packed EtherCAT frame layer). build_sanitizers: - needs: py_lint + needs: [py_lint, cpp_lint] name: Build C++ (ASan + UBSan) runs-on: ubuntu-latest env: @@ -134,7 +143,7 @@ jobs: shell: bash build_arm64: - needs: py_lint + needs: [py_lint, cpp_lint] name: Build C++ (ARM64 - ${{ matrix.preset }}) runs-on: ubuntu-24.04-arm strategy: @@ -170,7 +179,7 @@ jobs: retention-days: 1 build-wheels: - needs: py_lint + needs: [py_lint, cpp_lint] name: Build Python Wheels (${{ matrix.os }}) runs-on: ${{ matrix.os }} strategy: @@ -332,7 +341,7 @@ jobs: # NuttX Builds build_NuttX: - needs: py_lint + needs: [py_lint, cpp_lint] runs-on: ubuntu-latest continue-on-error: ${{ matrix.nuttx.label == 'master' }} strategy: diff --git a/examples/slave/common/xpg_strerror_r.cc b/examples/slave/common/xpg_strerror_r.cc index 09b9b1ef..9223dd04 100644 --- a/examples/slave/common/xpg_strerror_r.cc +++ b/examples/slave/common/xpg_strerror_r.cc @@ -7,7 +7,7 @@ // Uses GNU strerror internally, but provides thread-safe semantics // by copying into a thread-local buffer. // To use if the symbol is not defined (i.e. NuttX + GCC 14 ARM toolchain) -extern "C" int __xpg_strerror_r(int errnum, char *buf, size_t buflen) +extern "C" int __xpg_strerror_r(int errnum, char* buf, size_t buflen) { if (buf == nullptr or buflen == 0) { diff --git a/examples/slave/nuttx/lan9252/arduino-due/main.cc b/examples/slave/nuttx/lan9252/arduino-due/main.cc index 303232a8..75a1d4bd 100644 --- a/examples/slave/nuttx/lan9252/arduino-due/main.cc +++ b/examples/slave/nuttx/lan9252/arduino-due/main.cc @@ -13,10 +13,10 @@ using namespace kickcat; -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { - (void) argc; - (void) argv; + (void)argc; + (void)argv; std::shared_ptr spi_driver = std::make_shared(); spi_driver->open("/dev/spi0", 0, 0, 10000000); @@ -59,11 +59,11 @@ int main(int argc, char *argv[]) { slave.routine(); // Print received data - // for (uint8_t i = 0; i < PDO_MAX_SIZE; ++i) - // { - // printf("%x", buffer_out[i]); - // } - // printf("\n"); + // for (uint8_t i = 0; i < PDO_MAX_SIZE; ++i) + // { + // printf("%x", buffer_out[i]); + // } + // printf("\n"); if (slave.state() == State::SAFE_OP) { diff --git a/examples/slave/nuttx/lan9252/freedom-k64f/main.cc b/examples/slave/nuttx/lan9252/freedom-k64f/main.cc index 98322893..78e47ff9 100644 --- a/examples/slave/nuttx/lan9252/freedom-k64f/main.cc +++ b/examples/slave/nuttx/lan9252/freedom-k64f/main.cc @@ -17,7 +17,7 @@ using namespace kickcat; -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { (void)argc; (void)argv; @@ -94,16 +94,16 @@ int main(int argc, char *argv[]) bool pdo_configured = false; - int16_t *ax = nullptr; - int16_t *ay = nullptr; - int16_t *az = nullptr; - int16_t *mx = nullptr; - int16_t *my = nullptr; - int16_t *mz = nullptr; + int16_t* ax = nullptr; + int16_t* ay = nullptr; + int16_t* az = nullptr; + int16_t* mx = nullptr; + int16_t* my = nullptr; + int16_t* mz = nullptr; - uint8_t *led_r = nullptr; - uint8_t *led_g = nullptr; - uint8_t *led_b = nullptr; + uint8_t* led_r = nullptr; + uint8_t* led_g = nullptr; + uint8_t* led_b = nullptr; while (true) { @@ -132,7 +132,6 @@ int main(int argc, char *argv[]) } else if (state == State::OPERATIONAL) { - if (read(sensor_fd, &sensor_data, sizeof(sensor_data)) == sizeof(sensor_data)) { *ax = sensor_data.accel.x; diff --git a/examples/slave/nuttx/lan9252/freedom-k64f/od_populator.cc b/examples/slave/nuttx/lan9252/freedom-k64f/od_populator.cc index 4e12af08..4dbe8271 100644 --- a/examples/slave/nuttx/lan9252/freedom-k64f/od_populator.cc +++ b/examples/slave/nuttx/lan9252/freedom-k64f/od_populator.cc @@ -16,7 +16,7 @@ namespace kickcat::CoE "Device Type", {} }; - CoE::addEntry(object,0,32,0,CoE::Access::READ,CoE::DataType::UNSIGNED32,"",0x0); + CoE::addEntry(object, 0, 32, 0, CoE::Access::READ, CoE::DataType::UNSIGNED32, "", 0x0); dictionary.push_back(std::move(object)); } @@ -28,11 +28,11 @@ namespace kickcat::CoE "Identity Object", {} }; - CoE::addEntry(object,0,8,0,CoE::Access::READ,CoE::DataType::UNSIGNED8,"Subindex 000",0x4); - CoE::addEntry(object,1,32,8,CoE::Access::READ,CoE::DataType::UNSIGNED32,"Vendor ID",0x6a5); - CoE::addEntry(object,2,32,40,CoE::Access::READ,CoE::DataType::UNSIGNED32,"Product code",0xb0cad0); - CoE::addEntry(object,3,32,72,CoE::Access::READ,CoE::DataType::UNSIGNED32,"Revision number",0x0); - CoE::addEntry(object,4,32,104,CoE::Access::READ,CoE::DataType::UNSIGNED32,"Serial number",0xcafedeca); + CoE::addEntry(object, 0, 8, 0, CoE::Access::READ, CoE::DataType::UNSIGNED8, "Subindex 000", 0x4); + CoE::addEntry(object, 1, 32, 8, CoE::Access::READ, CoE::DataType::UNSIGNED32, "Vendor ID", 0x6a5); + CoE::addEntry(object, 2, 32, 40, CoE::Access::READ, CoE::DataType::UNSIGNED32, "Product code", 0xb0cad0); + CoE::addEntry(object, 3, 32, 72, CoE::Access::READ, CoE::DataType::UNSIGNED32, "Revision number", 0x0); + CoE::addEntry(object, 4, 32, 104, CoE::Access::READ, CoE::DataType::UNSIGNED32, "Serial number", 0xcafedeca); dictionary.push_back(std::move(object)); } @@ -44,10 +44,10 @@ namespace kickcat::CoE "RxPDO Map 1", {} }; - CoE::addEntry(object,0,8,0,CoE::Access::READ | CoE::Access::WRITE,CoE::DataType::UNSIGNED8,"Subindex 000",0x3); - CoE::addEntry(object,1,32,8,CoE::Access::READ | CoE::Access::WRITE,CoE::DataType::UNSIGNED32,"RxPDO Map 1 Element 1",0x70000008); - CoE::addEntry(object,2,32,40,CoE::Access::READ | CoE::Access::WRITE,CoE::DataType::UNSIGNED32,"RxPDO Map 1 Element 2",0x70010008); - CoE::addEntry(object,3,32,72,CoE::Access::READ | CoE::Access::WRITE,CoE::DataType::UNSIGNED32,"RxPDO Map 1 Element 3",0x70020008); + CoE::addEntry(object, 0, 8, 0, CoE::Access::READ | CoE::Access::WRITE, CoE::DataType::UNSIGNED8, "Subindex 000", 0x3); + CoE::addEntry(object, 1, 32, 8, CoE::Access::READ | CoE::Access::WRITE, CoE::DataType::UNSIGNED32, "RxPDO Map 1 Element 1", 0x70000008); + CoE::addEntry(object, 2, 32, 40, CoE::Access::READ | CoE::Access::WRITE, CoE::DataType::UNSIGNED32, "RxPDO Map 1 Element 2", 0x70010008); + CoE::addEntry(object, 3, 32, 72, CoE::Access::READ | CoE::Access::WRITE, CoE::DataType::UNSIGNED32, "RxPDO Map 1 Element 3", 0x70020008); dictionary.push_back(std::move(object)); } @@ -59,13 +59,13 @@ namespace kickcat::CoE "TxPDO Map 1", {} }; - CoE::addEntry(object,0,8,0,CoE::Access::READ | CoE::Access::WRITE,CoE::DataType::UNSIGNED8,"Subindex 000",0x6); - CoE::addEntry(object,1,32,8,CoE::Access::READ | CoE::Access::WRITE,CoE::DataType::UNSIGNED32,"TxPDO Map 1 Element 1",0x60000010); - CoE::addEntry(object,2,32,40,CoE::Access::READ | CoE::Access::WRITE,CoE::DataType::UNSIGNED32,"TxPDO Map 1 Element 2",0x60010010); - CoE::addEntry(object,3,32,72,CoE::Access::READ | CoE::Access::WRITE,CoE::DataType::UNSIGNED32,"TxPDO Map 1 Element 3",0x60020010); - CoE::addEntry(object,4,32,104,CoE::Access::READ | CoE::Access::WRITE,CoE::DataType::UNSIGNED32,"TxPDO Map 1 Element 4",0x60030010); - CoE::addEntry(object,5,32,136,CoE::Access::READ | CoE::Access::WRITE,CoE::DataType::UNSIGNED32,"TxPDO Map 1 Element 5",0x60040010); - CoE::addEntry(object,6,32,168,CoE::Access::READ | CoE::Access::WRITE,CoE::DataType::UNSIGNED32,"TxPDO Map 1 Element 6",0x60050010); + CoE::addEntry(object, 0, 8, 0, CoE::Access::READ | CoE::Access::WRITE, CoE::DataType::UNSIGNED8, "Subindex 000", 0x6); + CoE::addEntry(object, 1, 32, 8, CoE::Access::READ | CoE::Access::WRITE, CoE::DataType::UNSIGNED32, "TxPDO Map 1 Element 1", 0x60000010); + CoE::addEntry(object, 2, 32, 40, CoE::Access::READ | CoE::Access::WRITE, CoE::DataType::UNSIGNED32, "TxPDO Map 1 Element 2", 0x60010010); + CoE::addEntry(object, 3, 32, 72, CoE::Access::READ | CoE::Access::WRITE, CoE::DataType::UNSIGNED32, "TxPDO Map 1 Element 3", 0x60020010); + CoE::addEntry(object, 4, 32, 104, CoE::Access::READ | CoE::Access::WRITE, CoE::DataType::UNSIGNED32, "TxPDO Map 1 Element 4", 0x60030010); + CoE::addEntry(object, 5, 32, 136, CoE::Access::READ | CoE::Access::WRITE, CoE::DataType::UNSIGNED32, "TxPDO Map 1 Element 5", 0x60040010); + CoE::addEntry(object, 6, 32, 168, CoE::Access::READ | CoE::Access::WRITE, CoE::DataType::UNSIGNED32, "TxPDO Map 1 Element 6", 0x60050010); dictionary.push_back(std::move(object)); } @@ -77,11 +77,11 @@ namespace kickcat::CoE "Sync manager type", {} }; - CoE::addEntry(object,0,8,0,CoE::Access::READ,CoE::DataType::UNSIGNED8,"Subindex 0",0x4); - CoE::addEntry(object,1,8,8,CoE::Access::READ,CoE::DataType::UNSIGNED8,"Subindex 1",0x1); - CoE::addEntry(object,2,8,16,CoE::Access::READ,CoE::DataType::UNSIGNED8,"Subindex 2",0x2); - CoE::addEntry(object,3,8,24,CoE::Access::READ,CoE::DataType::UNSIGNED8,"Subindex 3",0x3); - CoE::addEntry(object,4,8,32,CoE::Access::READ,CoE::DataType::UNSIGNED8,"Subindex 4",0x4); + CoE::addEntry(object, 0, 8, 0, CoE::Access::READ, CoE::DataType::UNSIGNED8, "Subindex 0", 0x4); + CoE::addEntry(object, 1, 8, 8, CoE::Access::READ, CoE::DataType::UNSIGNED8, "Subindex 1", 0x1); + CoE::addEntry(object, 2, 8, 16, CoE::Access::READ, CoE::DataType::UNSIGNED8, "Subindex 2", 0x2); + CoE::addEntry(object, 3, 8, 24, CoE::Access::READ, CoE::DataType::UNSIGNED8, "Subindex 3", 0x3); + CoE::addEntry(object, 4, 8, 32, CoE::Access::READ, CoE::DataType::UNSIGNED8, "Subindex 4", 0x4); dictionary.push_back(std::move(object)); } @@ -93,8 +93,8 @@ namespace kickcat::CoE "RxPDO assign", {} }; - CoE::addEntry(object,0,8,0,CoE::Access::READ | CoE::Access::WRITE_PREOP,CoE::DataType::UNSIGNED8,"Subindex 000",0x1); - CoE::addEntry(object,1,16,8,CoE::Access::READ | CoE::Access::WRITE_PREOP,CoE::DataType::UNSIGNED16,"RxPDO assign Element 1",0x1600); + CoE::addEntry(object, 0, 8, 0, CoE::Access::READ | CoE::Access::WRITE_PREOP, CoE::DataType::UNSIGNED8, "Subindex 000", 0x1); + CoE::addEntry(object, 1, 16, 8, CoE::Access::READ | CoE::Access::WRITE_PREOP, CoE::DataType::UNSIGNED16, "RxPDO assign Element 1", 0x1600); dictionary.push_back(std::move(object)); } @@ -106,8 +106,8 @@ namespace kickcat::CoE "TxPDO assign", {} }; - CoE::addEntry(object,0,8,0,CoE::Access::READ | CoE::Access::WRITE_PREOP,CoE::DataType::UNSIGNED8,"Subindex 000",0x1); - CoE::addEntry(object,1,16,8,CoE::Access::READ | CoE::Access::WRITE_PREOP,CoE::DataType::UNSIGNED16,"TxPDO assign Element 1",0x1a00); + CoE::addEntry(object, 0, 8, 0, CoE::Access::READ | CoE::Access::WRITE_PREOP, CoE::DataType::UNSIGNED8, "Subindex 000", 0x1); + CoE::addEntry(object, 1, 16, 8, CoE::Access::READ | CoE::Access::WRITE_PREOP, CoE::DataType::UNSIGNED16, "TxPDO assign Element 1", 0x1a00); dictionary.push_back(std::move(object)); } @@ -119,7 +119,7 @@ namespace kickcat::CoE "accel_x", {} }; - CoE::addEntry(object,0,16,0,CoE::Access::READ | CoE::Access::TxPDO,CoE::DataType::INTEGER16,"accel_x",0); + CoE::addEntry(object, 0, 16, 0, CoE::Access::READ | CoE::Access::TxPDO, CoE::DataType::INTEGER16, "accel_x", 0); dictionary.push_back(std::move(object)); } @@ -131,7 +131,7 @@ namespace kickcat::CoE "accel_y", {} }; - CoE::addEntry(object,0,16,0,CoE::Access::READ | CoE::Access::TxPDO,CoE::DataType::INTEGER16,"accel_y",0); + CoE::addEntry(object, 0, 16, 0, CoE::Access::READ | CoE::Access::TxPDO, CoE::DataType::INTEGER16, "accel_y", 0); dictionary.push_back(std::move(object)); } @@ -143,7 +143,7 @@ namespace kickcat::CoE "accel_z", {} }; - CoE::addEntry(object,0,16,0,CoE::Access::READ | CoE::Access::TxPDO,CoE::DataType::INTEGER16,"accel_z",0); + CoE::addEntry(object, 0, 16, 0, CoE::Access::READ | CoE::Access::TxPDO, CoE::DataType::INTEGER16, "accel_z", 0); dictionary.push_back(std::move(object)); } @@ -155,7 +155,7 @@ namespace kickcat::CoE "mag_x", {} }; - CoE::addEntry(object,0,16,0,CoE::Access::READ | CoE::Access::TxPDO,CoE::DataType::INTEGER16,"mag_x",0); + CoE::addEntry(object, 0, 16, 0, CoE::Access::READ | CoE::Access::TxPDO, CoE::DataType::INTEGER16, "mag_x", 0); dictionary.push_back(std::move(object)); } @@ -167,7 +167,7 @@ namespace kickcat::CoE "mag_y", {} }; - CoE::addEntry(object,0,16,0,CoE::Access::READ | CoE::Access::TxPDO,CoE::DataType::INTEGER16,"mag_y",0); + CoE::addEntry(object, 0, 16, 0, CoE::Access::READ | CoE::Access::TxPDO, CoE::DataType::INTEGER16, "mag_y", 0); dictionary.push_back(std::move(object)); } @@ -179,7 +179,7 @@ namespace kickcat::CoE "mag_z", {} }; - CoE::addEntry(object,0,16,0,CoE::Access::READ | CoE::Access::TxPDO,CoE::DataType::INTEGER16,"mag_z",0); + CoE::addEntry(object, 0, 16, 0, CoE::Access::READ | CoE::Access::TxPDO, CoE::DataType::INTEGER16, "mag_z", 0); dictionary.push_back(std::move(object)); } @@ -191,7 +191,7 @@ namespace kickcat::CoE "LED_R", {} }; - CoE::addEntry(object,0,8,0,CoE::Access::WRITE | CoE::Access::RxPDO,CoE::DataType::UNSIGNED8,"LED_R",0); + CoE::addEntry(object, 0, 8, 0, CoE::Access::WRITE | CoE::Access::RxPDO, CoE::DataType::UNSIGNED8, "LED_R", 0); dictionary.push_back(std::move(object)); } @@ -203,7 +203,7 @@ namespace kickcat::CoE "LED_G", {} }; - CoE::addEntry(object,0,8,0,CoE::Access::WRITE | CoE::Access::RxPDO,CoE::DataType::UNSIGNED8,"LED_G",0); + CoE::addEntry(object, 0, 8, 0, CoE::Access::WRITE | CoE::Access::RxPDO, CoE::DataType::UNSIGNED8, "LED_G", 0); dictionary.push_back(std::move(object)); } @@ -215,10 +215,10 @@ namespace kickcat::CoE "LED_B", {} }; - CoE::addEntry(object,0,8,0,CoE::Access::WRITE | CoE::Access::RxPDO,CoE::DataType::UNSIGNED8,"LED_B",0); + CoE::addEntry(object, 0, 8, 0, CoE::Access::WRITE | CoE::Access::RxPDO, CoE::DataType::UNSIGNED8, "LED_B", 0); dictionary.push_back(std::move(object)); } - return dictionary; + return dictionary; } } diff --git a/examples/slave/nuttx/xmc4800/main_foot.cc b/examples/slave/nuttx/xmc4800/main_foot.cc index 78ca4777..1197d503 100644 --- a/examples/slave/nuttx/xmc4800/main_foot.cc +++ b/examples/slave/nuttx/xmc4800/main_foot.cc @@ -20,7 +20,7 @@ namespace foot int16_t gyroscopeZ; int16_t temperature; // Celsius degrees - }__attribute__((packed)); + } __attribute__((packed)); struct Input { @@ -43,7 +43,7 @@ namespace foot } __attribute__((packed)); } -int main(int, char *[]) +int main(int, char*[]) { using namespace kickcat; diff --git a/examples/slave/nuttx/xmc4800/main_relax.cc b/examples/slave/nuttx/xmc4800/main_relax.cc index da2236b6..f0043245 100644 --- a/examples/slave/nuttx/xmc4800/main_relax.cc +++ b/examples/slave/nuttx/xmc4800/main_relax.cc @@ -12,26 +12,26 @@ using namespace kickcat; int main(int, char*[]) { printf("XMC hello relax\n"); - + XMC4800 esc; XMC4800EEPROM eeprom; PDO pdo(&esc); slave::Slave slave(&esc, &pdo); - + eeprom.init(); - + uint16_t al_status; uint16_t al_control; esc.read(reg::AL_STATUS, &al_status, sizeof(al_status)); esc.read(reg::AL_CONTROL, &al_control, sizeof(al_control)); printf("al_status %x al_control %x \n", al_status, al_control); - + // The master can request less inputs/ouputs and these buffers are the space // that the slave app allocated to let the master play with the mapping. constexpr uint32_t PDO_MAX_SIZE = 32; uint8_t buffer_in[PDO_MAX_SIZE]; uint8_t buffer_out[PDO_MAX_SIZE]; - + // Init values for (uint32_t i = 0; i < PDO_MAX_SIZE; ++i) { @@ -47,29 +47,29 @@ int main(int, char*[]) slave.setDictionary(&dictionary); // and the slave uses it for bind / PDO mapping pdo.setInput(buffer_in, PDO_MAX_SIZE); pdo.setOutput(buffer_out, PDO_MAX_SIZE); - + uint8_t esc_config; esc.read(reg::ESC_CONFIG, &esc_config, sizeof(esc_config)); bool is_emulated = esc_config & PDI_EMULATION; printf("esc config 0x%x, is emulated %i \n", esc_config, is_emulated); - + uint8_t pdi_config; esc.read(reg::PDI_CONFIGURATION, &pdi_config, sizeof(pdi_config)); printf("pdi config 0x%x \n", pdi_config); - + slave.start(); - + // Variables for toggling pattern uint32_t iteration_counter = 0; uint8_t current_value = 0x11; // Start with 0x11 constexpr uint32_t ITER = 10000; // Number of iterations before updating input buffer - + while (true) { eeprom.process(); slave.routine(); - + if (slave.state() == State::SAFE_OP) { if (buffer_out[1] != 0xFF) @@ -77,19 +77,19 @@ int main(int, char*[]) slave.validateOutputData(); } } - + // Update input buffer every ITER iterations iteration_counter++; if (iteration_counter >= ITER) { iteration_counter = 0; - + // Fill buffer with current value for (uint32_t i = 0; i < PDO_MAX_SIZE; ++i) { buffer_in[i] = current_value; } - + // Move to next value: 0x11 -> 0x22 -> 0x33 -> ... -> 0xFF -> 0x00 -> 0x11 if (current_value == 0xFF) { @@ -98,9 +98,9 @@ int main(int, char*[]) else { current_value += 0x11; - } + } } } - + return 0; } diff --git a/examples/slave/nuttx/xmc4800/od_populator.cc b/examples/slave/nuttx/xmc4800/od_populator.cc index 56eeacd0..54871cc3 100644 --- a/examples/slave/nuttx/xmc4800/od_populator.cc +++ b/examples/slave/nuttx/xmc4800/od_populator.cc @@ -16,7 +16,7 @@ namespace kickcat::CoE "Device Type", {} }; - CoE::addEntry(object,0,32,0,7,static_cast(7),"",0x0); + CoE::addEntry(object, 0, 32, 0, 7, static_cast(7), "", 0x0); dictionary.push_back(std::move(object)); } @@ -28,11 +28,11 @@ namespace kickcat::CoE "Identity Object", {} }; - CoE::addEntry(object,0,8,0,7,static_cast(5),"Subindex 000",0x4); - CoE::addEntry(object,1,32,16,7,static_cast(7),"Vendor ID",0x6a5); - CoE::addEntry(object,2,32,48,7,static_cast(7),"Product code",0xb0cad0); - CoE::addEntry(object,3,32,80,7,static_cast(7),"Revision number",0x0); - CoE::addEntry(object,4,32,112,7,static_cast(7),"Serial number",0xcafedeca); + CoE::addEntry(object, 0, 8, 0, 7, static_cast(5), "Subindex 000", 0x4); + CoE::addEntry(object, 1, 32, 16, 7, static_cast(7), "Vendor ID", 0x6a5); + CoE::addEntry(object, 2, 32, 48, 7, static_cast(7), "Product code", 0xb0cad0); + CoE::addEntry(object, 3, 32, 80, 7, static_cast(7), "Revision number", 0x0); + CoE::addEntry(object, 4, 32, 112, 7, static_cast(7), "Serial number", 0xcafedeca); dictionary.push_back(std::move(object)); } @@ -44,8 +44,8 @@ namespace kickcat::CoE "RxPDO Map 1", {} }; - CoE::addEntry(object,0,8,0,7,static_cast(5),"Subindex 000",0x1); - CoE::addEntry(object,1,32,16,7,static_cast(7),"RxPDO Map 1 Element 1",0x60000010); + CoE::addEntry(object, 0, 8, 0, 7, static_cast(5), "Subindex 000", 0x1); + CoE::addEntry(object, 1, 32, 16, 7, static_cast(7), "RxPDO Map 1 Element 1", 0x60000010); dictionary.push_back(std::move(object)); } @@ -57,21 +57,21 @@ namespace kickcat::CoE "TxPDO Map 1", {} }; - CoE::addEntry(object,0,8,0,7,static_cast(5),"Subindex 000",0xd); - CoE::addEntry(object,1,32,16,7,static_cast(7),"TxPDO Map 1 Element 1",0x60000010); - CoE::addEntry(object,2,32,48,7,static_cast(7),"TxPDO Map 1 Element 2",0x60010010); - CoE::addEntry(object,3,32,80,7,static_cast(7),"TxPDO Map 1 Element 3",0x60020010); - CoE::addEntry(object,4,32,112,7,static_cast(7),"TxPDO Map 1 Element 4",0x60030010); - CoE::addEntry(object,5,32,144,7,static_cast(7),"TxPDO Map 1 Element 5",0x60040010); - CoE::addEntry(object,6,32,176,7,static_cast(7),"TxPDO Map 1 Element 6",0x60050010); - CoE::addEntry(object,7,32,208,7,static_cast(7),"TxPDO Map 1 Element 7",0x60060010); - CoE::addEntry(object,8,32,240,7,static_cast(7),"TxPDO Map 1 Element 8",0x60070010); - CoE::addEntry(object,9,32,272,7,static_cast(7),"TxPDO Map 1 Element 9",0x60080010); - CoE::addEntry(object,10,32,304,7,static_cast(7),"TxPDO Map 1 Element 10",0x60090010); - CoE::addEntry(object,11,32,336,7,static_cast(7),"TxPDO Map 1 Element 11",0x600a0010); - CoE::addEntry(object,12,32,368,7,static_cast(7),"TxPDO Map 1 Element 12",0x600b0010); - CoE::addEntry(object,13,32,400,7,static_cast(7),"TxPDO Map 1 Element 13",0x600c0010); - CoE::addEntry(object,14,32,432,7,static_cast(7),"TxPDO Map 1 Element 14",0x600d0010); + CoE::addEntry(object, 0, 8, 0, 7, static_cast(5), "Subindex 000", 0xd); + CoE::addEntry(object, 1, 32, 16, 7, static_cast(7), "TxPDO Map 1 Element 1", 0x60000010); + CoE::addEntry(object, 2, 32, 48, 7, static_cast(7), "TxPDO Map 1 Element 2", 0x60010010); + CoE::addEntry(object, 3, 32, 80, 7, static_cast(7), "TxPDO Map 1 Element 3", 0x60020010); + CoE::addEntry(object, 4, 32, 112, 7, static_cast(7), "TxPDO Map 1 Element 4", 0x60030010); + CoE::addEntry(object, 5, 32, 144, 7, static_cast(7), "TxPDO Map 1 Element 5", 0x60040010); + CoE::addEntry(object, 6, 32, 176, 7, static_cast(7), "TxPDO Map 1 Element 6", 0x60050010); + CoE::addEntry(object, 7, 32, 208, 7, static_cast(7), "TxPDO Map 1 Element 7", 0x60060010); + CoE::addEntry(object, 8, 32, 240, 7, static_cast(7), "TxPDO Map 1 Element 8", 0x60070010); + CoE::addEntry(object, 9, 32, 272, 7, static_cast(7), "TxPDO Map 1 Element 9", 0x60080010); + CoE::addEntry(object, 10, 32, 304, 7, static_cast(7), "TxPDO Map 1 Element 10", 0x60090010); + CoE::addEntry(object, 11, 32, 336, 7, static_cast(7), "TxPDO Map 1 Element 11", 0x600a0010); + CoE::addEntry(object, 12, 32, 368, 7, static_cast(7), "TxPDO Map 1 Element 12", 0x600b0010); + CoE::addEntry(object, 13, 32, 400, 7, static_cast(7), "TxPDO Map 1 Element 13", 0x600c0010); + CoE::addEntry(object, 14, 32, 432, 7, static_cast(7), "TxPDO Map 1 Element 14", 0x600d0010); dictionary.push_back(std::move(object)); } @@ -83,11 +83,11 @@ namespace kickcat::CoE "Sync manager type", {} }; - CoE::addEntry(object,0,8,0,7,static_cast(5),"Subindex 0",0x4); - CoE::addEntry(object,1,8,16,7,static_cast(5),"Subindex 1",0x1); - CoE::addEntry(object,2,8,24,7,static_cast(5),"Subindex 2",0x2); - CoE::addEntry(object,3,8,32,7,static_cast(5),"Subindex 3",0x3); - CoE::addEntry(object,4,8,40,7,static_cast(5),"Subindex 4",0x4); + CoE::addEntry(object, 0, 8, 0, 7, static_cast(5), "Subindex 0", 0x4); + CoE::addEntry(object, 1, 8, 16, 7, static_cast(5), "Subindex 1", 0x1); + CoE::addEntry(object, 2, 8, 24, 7, static_cast(5), "Subindex 2", 0x2); + CoE::addEntry(object, 3, 8, 32, 7, static_cast(5), "Subindex 3", 0x3); + CoE::addEntry(object, 4, 8, 40, 7, static_cast(5), "Subindex 4", 0x4); dictionary.push_back(std::move(object)); } @@ -99,8 +99,8 @@ namespace kickcat::CoE "RxPDO assign", {} }; - CoE::addEntry(object,0,8,0,15,static_cast(5),"Subindex 000",0x1); - CoE::addEntry(object,1,16,16,15,static_cast(6),"RxPDO assign Element 1",0x1600); + CoE::addEntry(object, 0, 8, 0, 15, static_cast(5), "Subindex 000", 0x1); + CoE::addEntry(object, 1, 16, 16, 15, static_cast(6), "RxPDO assign Element 1", 0x1600); dictionary.push_back(std::move(object)); } @@ -112,8 +112,8 @@ namespace kickcat::CoE "TxPDO assign", {} }; - CoE::addEntry(object,0,8,0,15,static_cast(5),"Subindex 000",0x1); - CoE::addEntry(object,1,16,16,15,static_cast(6),"TxPDO assign Element 1",0x1a00); + CoE::addEntry(object, 0, 8, 0, 15, static_cast(5), "Subindex 000", 0x1); + CoE::addEntry(object, 1, 16, 16, 15, static_cast(6), "TxPDO assign Element 1", 0x1a00); dictionary.push_back(std::move(object)); } @@ -125,9 +125,9 @@ namespace kickcat::CoE "FreezeValue", {} }; - CoE::addEntry(object,0,8,0,7,static_cast(5),"Subindex 000",0x2); - CoE::addEntry(object,1,32,16,63,static_cast(7),"ForceSensor0",0x2); - CoE::addEntry(object,2,32,48,63,static_cast(7),"IMU",0x2); + CoE::addEntry(object, 0, 8, 0, 7, static_cast(5), "Subindex 000", 0x2); + CoE::addEntry(object, 1, 32, 16, 63, static_cast(7), "ForceSensor0", 0x2); + CoE::addEntry(object, 2, 32, 48, 63, static_cast(7), "IMU", 0x2); dictionary.push_back(std::move(object)); } @@ -139,7 +139,7 @@ namespace kickcat::CoE "wdg_counter", {} }; - CoE::addEntry(object,0,16,0,199,static_cast(6),"",0x0); + CoE::addEntry(object, 0, 16, 0, 199, static_cast(6), "", 0x0); dictionary.push_back(std::move(object)); } @@ -151,7 +151,7 @@ namespace kickcat::CoE "acc_x", {} }; - CoE::addEntry(object,0,16,0,135,static_cast(6),"",0x0); + CoE::addEntry(object, 0, 16, 0, 135, static_cast(6), "", 0x0); dictionary.push_back(std::move(object)); } @@ -163,7 +163,7 @@ namespace kickcat::CoE "acc_y", {} }; - CoE::addEntry(object,0,16,0,135,static_cast(6),"",0x0); + CoE::addEntry(object, 0, 16, 0, 135, static_cast(6), "", 0x0); dictionary.push_back(std::move(object)); } @@ -175,7 +175,7 @@ namespace kickcat::CoE "acc_z", {} }; - CoE::addEntry(object,0,16,0,135,static_cast(6),"",0x0); + CoE::addEntry(object, 0, 16, 0, 135, static_cast(6), "", 0x0); dictionary.push_back(std::move(object)); } @@ -187,7 +187,7 @@ namespace kickcat::CoE "gyro_x", {} }; - CoE::addEntry(object,0,16,0,135,static_cast(6),"",0x0); + CoE::addEntry(object, 0, 16, 0, 135, static_cast(6), "", 0x0); dictionary.push_back(std::move(object)); } @@ -199,7 +199,7 @@ namespace kickcat::CoE "gyro_y", {} }; - CoE::addEntry(object,0,16,0,135,static_cast(6),"",0x0); + CoE::addEntry(object, 0, 16, 0, 135, static_cast(6), "", 0x0); dictionary.push_back(std::move(object)); } @@ -211,7 +211,7 @@ namespace kickcat::CoE "gyro_z", {} }; - CoE::addEntry(object,0,16,0,135,static_cast(6),"",0x0); + CoE::addEntry(object, 0, 16, 0, 135, static_cast(6), "", 0x0); dictionary.push_back(std::move(object)); } @@ -223,7 +223,7 @@ namespace kickcat::CoE "imu_temperature", {} }; - CoE::addEntry(object,0,16,0,135,static_cast(6),"",0x0); + CoE::addEntry(object, 0, 16, 0, 135, static_cast(6), "", 0x0); dictionary.push_back(std::move(object)); } @@ -235,7 +235,7 @@ namespace kickcat::CoE "force_sensor_0", {} }; - CoE::addEntry(object,0,16,0,135,static_cast(6),"",0x0); + CoE::addEntry(object, 0, 16, 0, 135, static_cast(6), "", 0x0); dictionary.push_back(std::move(object)); } @@ -247,7 +247,7 @@ namespace kickcat::CoE "force_sensor_1", {} }; - CoE::addEntry(object,0,16,0,135,static_cast(6),"",0x0); + CoE::addEntry(object, 0, 16, 0, 135, static_cast(6), "", 0x0); dictionary.push_back(std::move(object)); } @@ -259,7 +259,7 @@ namespace kickcat::CoE "force_sensor_2", {} }; - CoE::addEntry(object,0,16,0,135,static_cast(6),"",0x0); + CoE::addEntry(object, 0, 16, 0, 135, static_cast(6), "", 0x0); dictionary.push_back(std::move(object)); } @@ -271,7 +271,7 @@ namespace kickcat::CoE "force_sensor_3", {} }; - CoE::addEntry(object,0,16,0,135,static_cast(6),"",0x0); + CoE::addEntry(object, 0, 16, 0, 135, static_cast(6), "", 0x0); dictionary.push_back(std::move(object)); } @@ -283,7 +283,7 @@ namespace kickcat::CoE "adc_vref", {} }; - CoE::addEntry(object,0,16,0,135,static_cast(6),"",0x0); + CoE::addEntry(object, 0, 16, 0, 135, static_cast(6), "", 0x0); dictionary.push_back(std::move(object)); } @@ -295,10 +295,10 @@ namespace kickcat::CoE "board_status", {} }; - CoE::addEntry(object,0,16,0,135,static_cast(6),"",0x0); + CoE::addEntry(object, 0, 16, 0, 135, static_cast(6), "", 0x0); dictionary.push_back(std::move(object)); } - return dictionary; + return dictionary; } } diff --git a/examples/slave/rpi/lan9252/main.cc b/examples/slave/rpi/lan9252/main.cc index c62740fe..a5f47304 100644 --- a/examples/slave/rpi/lan9252/main.cc +++ b/examples/slave/rpi/lan9252/main.cc @@ -12,7 +12,7 @@ using namespace kickcat; -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { (void)argc; (void)argv; diff --git a/examples/slave/rpi/lan9252/od_populator.cc b/examples/slave/rpi/lan9252/od_populator.cc index c1180ebc..14fe5799 100644 --- a/examples/slave/rpi/lan9252/od_populator.cc +++ b/examples/slave/rpi/lan9252/od_populator.cc @@ -16,7 +16,7 @@ namespace kickcat::CoE "Device Type", {} }; - CoE::addEntry(object,0,32,0,CoE::Access::READ,CoE::DataType::UNSIGNED32,"",0x0); + CoE::addEntry(object, 0, 32, 0, CoE::Access::READ, CoE::DataType::UNSIGNED32, "", 0x0); dictionary.push_back(std::move(object)); } @@ -28,11 +28,11 @@ namespace kickcat::CoE "Identity Object", {} }; - CoE::addEntry(object,0,8,0,CoE::Access::READ,CoE::DataType::UNSIGNED8,"Subindex 000",0x4); - CoE::addEntry(object,1,32,8,CoE::Access::READ,CoE::DataType::UNSIGNED32,"Vendor ID",0x6a5); - CoE::addEntry(object,2,32,40,CoE::Access::READ,CoE::DataType::UNSIGNED32,"Product code",0xb0cad0); - CoE::addEntry(object,3,32,72,CoE::Access::READ,CoE::DataType::UNSIGNED32,"Revision number",0x0); - CoE::addEntry(object,4,32,104,CoE::Access::READ,CoE::DataType::UNSIGNED32,"Serial number",0xcafedeca); + CoE::addEntry(object, 0, 8, 0, CoE::Access::READ, CoE::DataType::UNSIGNED8, "Subindex 000", 0x4); + CoE::addEntry(object, 1, 32, 8, CoE::Access::READ, CoE::DataType::UNSIGNED32, "Vendor ID", 0x6a5); + CoE::addEntry(object, 2, 32, 40, CoE::Access::READ, CoE::DataType::UNSIGNED32, "Product code", 0xb0cad0); + CoE::addEntry(object, 3, 32, 72, CoE::Access::READ, CoE::DataType::UNSIGNED32, "Revision number", 0x0); + CoE::addEntry(object, 4, 32, 104, CoE::Access::READ, CoE::DataType::UNSIGNED32, "Serial number", 0xcafedeca); dictionary.push_back(std::move(object)); } @@ -44,8 +44,8 @@ namespace kickcat::CoE "RxPDO Map 1", {} }; - CoE::addEntry(object,0,8,0,CoE::Access::READ | CoE::Access::WRITE,CoE::DataType::UNSIGNED8,"Subindex 000",0x1); - CoE::addEntry(object,1,32,8,CoE::Access::READ | CoE::Access::WRITE,CoE::DataType::UNSIGNED32,"RxPDO Map 1 Element 1",0x70000008); + CoE::addEntry(object, 0, 8, 0, CoE::Access::READ | CoE::Access::WRITE, CoE::DataType::UNSIGNED8, "Subindex 000", 0x1); + CoE::addEntry(object, 1, 32, 8, CoE::Access::READ | CoE::Access::WRITE, CoE::DataType::UNSIGNED32, "RxPDO Map 1 Element 1", 0x70000008); dictionary.push_back(std::move(object)); } @@ -57,8 +57,8 @@ namespace kickcat::CoE "TxPDO Map 1", {} }; - CoE::addEntry(object,0,8,0,CoE::Access::READ | CoE::Access::WRITE,CoE::DataType::UNSIGNED8,"Subindex 000",0x1); - CoE::addEntry(object,1,32,8,CoE::Access::READ | CoE::Access::WRITE,CoE::DataType::UNSIGNED32,"TxPDO Map 1 Element 1",0x60000010); + CoE::addEntry(object, 0, 8, 0, CoE::Access::READ | CoE::Access::WRITE, CoE::DataType::UNSIGNED8, "Subindex 000", 0x1); + CoE::addEntry(object, 1, 32, 8, CoE::Access::READ | CoE::Access::WRITE, CoE::DataType::UNSIGNED32, "TxPDO Map 1 Element 1", 0x60000010); dictionary.push_back(std::move(object)); } @@ -70,11 +70,11 @@ namespace kickcat::CoE "Sync manager type", {} }; - CoE::addEntry(object,0,8,0,CoE::Access::READ,CoE::DataType::UNSIGNED8,"Subindex 0",0x4); - CoE::addEntry(object,1,8,8,CoE::Access::READ,CoE::DataType::UNSIGNED8,"Subindex 1",0x1); - CoE::addEntry(object,2,8,16,CoE::Access::READ,CoE::DataType::UNSIGNED8,"Subindex 2",0x2); - CoE::addEntry(object,3,8,24,CoE::Access::READ,CoE::DataType::UNSIGNED8,"Subindex 3",0x3); - CoE::addEntry(object,4,8,32,CoE::Access::READ,CoE::DataType::UNSIGNED8,"Subindex 4",0x4); + CoE::addEntry(object, 0, 8, 0, CoE::Access::READ, CoE::DataType::UNSIGNED8, "Subindex 0", 0x4); + CoE::addEntry(object, 1, 8, 8, CoE::Access::READ, CoE::DataType::UNSIGNED8, "Subindex 1", 0x1); + CoE::addEntry(object, 2, 8, 16, CoE::Access::READ, CoE::DataType::UNSIGNED8, "Subindex 2", 0x2); + CoE::addEntry(object, 3, 8, 24, CoE::Access::READ, CoE::DataType::UNSIGNED8, "Subindex 3", 0x3); + CoE::addEntry(object, 4, 8, 32, CoE::Access::READ, CoE::DataType::UNSIGNED8, "Subindex 4", 0x4); dictionary.push_back(std::move(object)); } @@ -86,8 +86,8 @@ namespace kickcat::CoE "RxPDO assign", {} }; - CoE::addEntry(object,0,8,0,CoE::Access::READ | CoE::Access::WRITE_PREOP,CoE::DataType::UNSIGNED8,"Subindex 000",0x1); - CoE::addEntry(object,1,16,8,CoE::Access::READ | CoE::Access::WRITE_PREOP,CoE::DataType::UNSIGNED16,"RxPDO assign Element 1",0x1600); + CoE::addEntry(object, 0, 8, 0, CoE::Access::READ | CoE::Access::WRITE_PREOP, CoE::DataType::UNSIGNED8, "Subindex 000", 0x1); + CoE::addEntry(object, 1, 16, 8, CoE::Access::READ | CoE::Access::WRITE_PREOP, CoE::DataType::UNSIGNED16, "RxPDO assign Element 1", 0x1600); dictionary.push_back(std::move(object)); } @@ -99,8 +99,8 @@ namespace kickcat::CoE "TxPDO assign", {} }; - CoE::addEntry(object,0,8,0,CoE::Access::READ | CoE::Access::WRITE_PREOP,CoE::DataType::UNSIGNED8,"Subindex 000",0x1); - CoE::addEntry(object,1,16,8,CoE::Access::READ | CoE::Access::WRITE_PREOP,CoE::DataType::UNSIGNED16,"TxPDO assign Element 1",0x1a00); + CoE::addEntry(object, 0, 8, 0, CoE::Access::READ | CoE::Access::WRITE_PREOP, CoE::DataType::UNSIGNED8, "Subindex 000", 0x1); + CoE::addEntry(object, 1, 16, 8, CoE::Access::READ | CoE::Access::WRITE_PREOP, CoE::DataType::UNSIGNED16, "TxPDO assign Element 1", 0x1a00); dictionary.push_back(std::move(object)); } @@ -112,7 +112,7 @@ namespace kickcat::CoE "input", {} }; - CoE::addEntry(object,0,16,0,CoE::Access::READ | CoE::Access::TxPDO,CoE::DataType::INTEGER16,"input",0); + CoE::addEntry(object, 0, 16, 0, CoE::Access::READ | CoE::Access::TxPDO, CoE::DataType::INTEGER16, "input", 0); dictionary.push_back(std::move(object)); } @@ -124,10 +124,10 @@ namespace kickcat::CoE "output", {} }; - CoE::addEntry(object,0,8,0,CoE::Access::WRITE | CoE::Access::RxPDO,CoE::DataType::UNSIGNED8,"output",0); + CoE::addEntry(object, 0, 8, 0, CoE::Access::WRITE | CoE::Access::RxPDO, CoE::DataType::UNSIGNED8, "output", 0); dictionary.push_back(std::move(object)); } - return dictionary; + return dictionary; } }