Skip to content

Commit

Permalink
Align model with template (#1)
Browse files Browse the repository at this point in the history
* Add template code and documentation

Signed-off-by: ClemensLinnhoff <[email protected]>

* Add CI Pipeline

Signed-off-by: ClemensLinnhoff <[email protected]>

* Adapt SETLevel camera model to fit into the template and conform to OpenMSL guidelines

Signed-off-by: Marzena Franek <[email protected]>

---------

Signed-off-by: ClemensLinnhoff <[email protected]>
Signed-off-by: Marzena Franek <[email protected]>
Co-authored-by: Marzena Franek <[email protected]>
  • Loading branch information
ClemensLinnhoff and MarzenaFranek authored Jul 11, 2023
1 parent 88c5f1d commit 59c8b08
Show file tree
Hide file tree
Showing 59 changed files with 3,807 additions and 4,599 deletions.
37 changes: 37 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
Language: Cpp
BasedOnStyle: Google
AccessModifierOffset: -2
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
BinPackArguments: false
BinPackParameters: false
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: true
AfterControlStatement: Always
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
ColumnLimit: 180
DerivePointerAlignment: false
IncludeCategories:
- Regex: '^(<|")(assert|complex|ctype|errno|fenv|float|inttypes|iso646|limits|locale|math|setjmp|signal|stdalign|stdargh|stdatomic|stdbool|stddef|stdint|stdio|stdlib|stdnoreturn|string|tgmath|threads|time|uchar|wchar|wctype)\.h'
Priority: 1
- Regex: '^(<|")(cstdlib|csignal|csetjmp|cstdarg|typeinfo|typeindex|type_traits|bitset|functional|utility|ctime|chrono|cstddef|initializer_list|tuple|any|optional|variant|new|memory|scoped_allocator|memory_resource|climits|cfloat|cstdint|cinttypes|limits|exception|stdexcept|cassert|system_error|cerrno|cctype|cwctype|cstring|cwchar|cuchar|string|string_view|array|vector|deque|list|forward_list|set|map|unordered_set|unordered_map|stack|queue|algorithm|execution|teratorslibrary|iterator|cmath|complex|valarray|random|numeric|ratio|cfenv|iosfwd|ios|istream|ostream|iostream|fstream|sstream|strstream|iomanip|streambuf|cstdio|locale|clocale|codecvt|regex|atomic|thread|mutex|shared_mutex|future|condition_variable|filesystem|ciso646|ccomplex|ctgmath|cstdalign|cstdbool)(>|")$'
Priority: 2
- Regex: '^<.*\.(h|hpp)>'
Priority: 3
- Regex: '^".*"'
Priority: 4
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: true
...
273 changes: 273 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
---
Checks: 'readability-*,cppcoreguidelines-*,-cppcoreguidelines-pro-type-vararg,-cppcoreguidelines-pro-type-cstyle-cast,-cppcoreguidelines-avoid-c-arrays,-cppcoreguidelines-non-private-member-variables-in-classes,-cppcoreguidelines-macro-usage,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-owning-memory,-readability-useless-return-value,-readability-const-return-type,-cppcoreguidelines-init-variables,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers'
HeaderFilterRegex: '.*/src/(?:adp|build_system|legacy)/.*'
AnalyzeTemporaryDtors: false
CheckOptions:
- key: readability-identifier-naming.AbstractClassCases
value: CamelCase
- key: readability-identifier-naming.AbstractClassPrefix
value: I
- key: readability-identifier-naming.AbstractClassSuffix
value: ''
- key: readability-identifier-naming.ClassCase
value: CamelCase
- key: readability-identifier-naming.ClassConstantCase
value: CamelCase
- key: readability-identifier-naming.ClassConstantPrefix
value: k
- key: readability-identifier-naming.ClassConstantSuffix
value: ''
- key: readability-identifier-naming.ClassMemberCase
value: lower_case
- key: readability-identifier-naming.ClassMemberPrefix
value: g_
- key: readability-identifier-naming.ClassMemberSuffix
value: ''
- key: readability-identifier-naming.ClassMethodCase
value: CamelCase
- key: readability-identifier-naming.ClassMethodPrefix
value: ''
- key: readability-identifier-naming.ClassMethodSuffix
value: ''
- key: readability-identifier-naming.ClassPrefix
value: ''
- key: readability-identifier-naming.ClassSuffix
value: ''
- key: readability-identifier-naming.ConstantCase
value: lower_case
- key: readability-identifier-naming.ConstantMemberCase
value: lower_case
- key: readability-identifier-naming.ConstantMemberPrefix
value: ''
- key: readability-identifier-naming.ConstantMemberSuffix
value: ''
- key: readability-identifier-naming.ConstantParameterCase
value: lower_case
- key: readability-identifier-naming.ConstantParameterPrefix
value: ''
- key: readability-identifier-naming.ConstantParameterSuffix
value: ''
- key: readability-identifier-naming.ConstantPrefix
value: ''
- key: readability-identifier-naming.ConstantSuffix
value: ''
- key: readability-identifier-naming.ConstexprFunctionCase
value: CamelCase
- key: readability-identifier-naming.ConstexprFunctionPrefix
value: ''
- key: readability-identifier-naming.ConstexprFunctionSuffix
value: ''
- key: readability-identifier-naming.ConstexprMethodCase
value: CamelCase
- key: readability-identifier-naming.ConstexprMethodPrefix
value: ''
- key: readability-identifier-naming.ConstexprMethodSuffix
value: ''
- key: readability-identifier-naming.ConstexprVariableCase
value: lower_case
- key: readability-identifier-naming.ConstexprVariablePrefix
value: ''
- key: readability-identifier-naming.ConstexprVariableSuffix
value: ''
- key: readability-identifier-naming.EnumCase
value: CamelCase
- key: readability-identifier-naming.EnumConstantCase
value: aNy_CasE
- key: readability-identifier-naming.EnumConstantPrefix
value: k
- key: readability-identifier-naming.EnumConstantSuffix
value: ''
- key: readability-identifier-naming.EnumPrefix
value: ''
- key: readability-identifier-naming.EnumSuffix
value: ''
- key: readability-identifier-naming.FunctionCase
value: CamelCase
- key: readability-identifier-naming.FunctionPrefix
value: ''
- key: readability-identifier-naming.FunctionSuffix
value: ''
- key: readability-identifier-naming.GlobalConstantCase
value: CamelCase
- key: readability-identifier-naming.GlobalConstantPrefix
value: k
- key: readability-identifier-naming.GlobalConstantSuffix
value: ''
- key: readability-identifier-naming.GlobalFunctionCase
value: CamelCase
- key: readability-identifier-naming.GlobalFunctionPrefix
value: ''
- key: readability-identifier-naming.GlobalFunctionSuffix
value: ''
- key: readability-identifier-naming.GlobalVariableCase
value: lower_case
- key: readability-identifier-naming.GlobalVariablePrefix
value: g_
- key: readability-identifier-naming.GlobalVariableSuffix
value: ''
- key: readability-identifier-naming.IgnoreFailedSplit
value: '0'
- key: readability-identifier-naming.InlineNamespaceCase
value: lower_case
- key: readability-identifier-naming.InlineNamespacePrefix
value: ''
- key: readability-identifier-naming.InlineNamespaceSuffix
value: ''
- key: readability-identifier-naming.LocalConstantCase
value: lower_case
- key: readability-identifier-naming.LocalConstantPrefix
value: ''
- key: readability-identifier-naming.LocalConstantSuffix
value: ''
- key: readability-identifier-naming.LocalVariableCase
value: lower_case
- key: readability-identifier-naming.LocalVariablePrefix
value: ''
- key: readability-identifier-naming.LocalVariableSuffix
value: ''
- key: readability-identifier-naming.MemberCase
value: lower_case
- key: readability-identifier-naming.MemberPrefix
value: ''
- key: readability-identifier-naming.MemberSuffix
value: _
- key: readability-identifier-naming.MethodCase
value: CamelCase
- key: readability-identifier-naming.MethodPrefix
value: ''
- key: readability-identifier-naming.MethodSuffix
value: ''
- key: readability-identifier-naming.NamespaceCase
value: lower_case
- key: readability-identifier-naming.NamespacePrefix
value: ''
- key: readability-identifier-naming.NamespaceSuffix
value: ''
- key: readability-identifier-naming.ParameterCase
value: lower_case
- key: readability-identifier-naming.ParameterPackCase
value: aNy_CasE
- key: readability-identifier-naming.ParameterPackPrefix
value: ''
- key: readability-identifier-naming.ParameterPackSuffix
value: ''
- key: readability-identifier-naming.ParameterPrefix
value: ''
- key: readability-identifier-naming.ParameterSuffix
value: ''
- key: readability-identifier-naming.PrivateMemberCase
value: lower_case
- key: readability-identifier-naming.PrivateMemberPrefix
value: ''
- key: readability-identifier-naming.PrivateMemberSuffix
value: _
- key: readability-identifier-naming.PrivateMethodCase
value: CamelCase
- key: readability-identifier-naming.PrivateMethodPrefix
value: ''
- key: readability-identifier-naming.PrivateMethodSuffix
value: ''
- key: readability-identifier-naming.ProtectedMemberCase
value: lower_case
- key: readability-identifier-naming.ProtectedMemberPrefix
value: ''
- key: readability-identifier-naming.ProtectedMemberSuffix
value: _
- key: readability-identifier-naming.ProtectedMethodCase
value: CamelCase
- key: readability-identifier-naming.ProtectedMethodPrefix
value: ''
- key: readability-identifier-naming.ProtectedMethodSuffix
value: ''
- key: readability-identifier-naming.PublicMemberCase
value: lower_case
- key: readability-identifier-naming.PublicMemberPrefix
value: ''
- key: readability-identifier-naming.PublicMemberSuffix
value: ''
- key: readability-identifier-naming.PublicMethodCase
value: CamelCase
- key: readability-identifier-naming.PublicMethodPrefix
value: ''
- key: readability-identifier-naming.PublicMethodSuffix
value: ''
- key: readability-identifier-naming.StaticConstantCase
value: aNy_CasE
- key: readability-identifier-naming.StaticConstantPrefix
value: ''
- key: readability-identifier-naming.StaticConstantSuffix
value: ''
- key: readability-identifier-naming.StaticVariableCase
value: aNy_CasE
- key: readability-identifier-naming.StaticVariablePrefix
value: ''
- key: readability-identifier-naming.StaticVariableSuffix
value: ''
- key: readability-identifier-naming.StructCase
value: CamelCase
- key: readability-identifier-naming.StructPrefix
value: ''
- key: readability-identifier-naming.StructSuffix
value: ''
- key: readability-identifier-naming.TemplateParameterCase
value: CamelCase
- key: readability-identifier-naming.TemplateParameterPrefix
value: ''
- key: readability-identifier-naming.TemplateParameterSuffix
value: ''
- key: readability-identifier-naming.TemplateTemplateParameterCase
value: CamelCase
- key: readability-identifier-naming.TemplateTemplateParameterPrefix
value: ''
- key: readability-identifier-naming.TemplateTemplateParameterSuffix
value: ''
- key: readability-identifier-naming.TypeTemplateParameterCase
value: CamelCase
- key: readability-identifier-naming.TypeTemplateParameterPrefix
value: ''
- key: readability-identifier-naming.TypeTemplateParameterSuffix
value: ''
- key: readability-identifier-naming.TypedefCase
value: CamelCase
- key: readability-identifier-naming.TypedefPrefix
value: ''
- key: readability-identifier-naming.TypedefSuffix
value: ''
- key: readability-identifier-naming.UnionCase
value: CamelCase
- key: readability-identifier-naming.UnionPrefix
value: ''
- key: readability-identifier-naming.UnionSuffix
value: ''
- key: readability-identifier-naming.ValueTemplateParameterCase
value: lower_case
- key: readability-identifier-naming.ValueTemplateParameterPrefix
value: ''
- key: readability-identifier-naming.ValueTemplateParameterSuffix
value: ''
- key: readability-identifier-naming.VariableCase
value: lower_case
- key: readability-identifier-naming.VariablePrefix
value: ''
- key: readability-identifier-naming.VariableSuffix
value: ''
- key: readability-identifier-naming.VirtualMethodCase
value: CamelCase
- key: readability-identifier-naming.VirtualMethodPrefix
value: ''
- key: readability-identifier-naming.VirtualMethodSuffix
value: ''
- key: readability-identifier-length.MinimumVariableNameLength
value: 0
- key: readability-identifier-length.MinimumParameterNameLength
value: 0
- key: readability-identifier-naming.VariableIgnoredRegexp
value: 'Alpha|Beta|Gamma|Delta|Theta'
- key: readability-identifier-length.IgnoredVariableNames
value: 'x|y|z|id|mu|a|b|c'
- key: readability-identifier-length.IgnoredParameterNames
value: 'x|y|z|id'
- key: readability-function-cognitive-complexity.Threshold
value: 100
...

64 changes: 64 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Build

on:
workflow_call:

env:
FMU_FILE_NAME: OSMPCameraSensor.fmu #TODO: Adjust to file name of your FMU

jobs:
build:
name: Build FMU
runs-on: ubuntu-latest

steps:
- name: Checkout Model
uses: actions/checkout@v3
with:
submodules: true

- name: Cache Protobuf
id: cache-protobuf
uses: actions/cache@v3
with:
path: protobuf-21.12
key: ${{ runner.os }}-protobuf

- name: Download ProtoBuf
if: steps.cache-protobuf.outputs.cache-hit != 'true'
run: curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v21.12/protobuf-all-21.12.tar.gz && tar xzvf protobuf-all-21.12.tar.gz

- name: Build ProtoBuf
if: steps.cache-protobuf.outputs.cache-hit != 'true'
working-directory: protobuf-21.12
run: ./configure DIST_LANG=cpp --disable-shared CXXFLAGS="-fPIC" && make

- name: Install ProtoBuf
working-directory: protobuf-21.12
run: sudo make install && sudo ldconfig

- name: Prepare C++ Build
run: mkdir build

- name: Configure CMake
working-directory: build
run: cmake -DCMAKE_PREFIX_PATH:PATH=${DEPS_DIR}/protobuf/install ..

- name: Build C++
working-directory: build
run: cmake --build .

- name: Create FMU Directory
working-directory: build
run: mkdir /tmp/model_fmu

- name: Copy Model FMU
working-directory: build
run: cp $FMU_FILE_NAME /tmp/model_fmu/SensorModel.fmu

- name: Cache Model FMU
id: cache-model-fmu
uses: actions/cache@v3
with:
path: /tmp/model_fmu
key: ${{ runner.os }}-model-fmu
Loading

1 comment on commit 59c8b08

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cpp-Linter Report ⚠️

Some files did not pass the configured checks!

clang-tidy reports: 22 concern(s)
  • src/OSMP.cpp

    /src/OSMP.cpp:60:5: warning: [cppcoreguidelines-pro-type-member-init]

    uninitialized record type: 'myaddr'

        union Addrconv
        ^

    /src/OSMP.cpp:69:12: warning: [cppcoreguidelines-pro-type-union-access]

    do not access members of unions; use (boost::)variant instead

        myaddr.base.lo = lo;
               ^

    /src/OSMP.cpp:70:12: warning: [cppcoreguidelines-pro-type-union-access]

    do not access members of unions; use (boost::)variant instead

        myaddr.base.hi = hi;
               ^

    /src/OSMP.cpp:71:12: warning: [cppcoreguidelines-pro-type-reinterpret-cast]

    do not use reinterpret_cast

        return reinterpret_cast<void*>(myaddr.address);
               ^

    /src/OSMP.cpp:71:43: warning: [cppcoreguidelines-pro-type-union-access]

    do not access members of unions; use (boost::)variant instead

        return reinterpret_cast<void*>(myaddr.address);
                                              ^

    /src/OSMP.cpp:82:5: warning: [cppcoreguidelines-pro-type-member-init]

    uninitialized record type: 'myaddr'

        union Addrconv
        ^

    /src/OSMP.cpp:91:12: warning: [cppcoreguidelines-pro-type-union-access]

    do not access members of unions; use (boost::)variant instead

        myaddr.address = reinterpret_cast<unsigned long long>(ptr);
               ^

    /src/OSMP.cpp:91:22: warning: [cppcoreguidelines-pro-type-reinterpret-cast]

    do not use reinterpret_cast

        myaddr.address = reinterpret_cast<unsigned long long>(ptr);
                         ^

    /src/OSMP.cpp:92:17: warning: [cppcoreguidelines-pro-type-union-access]

    do not access members of unions; use (boost::)variant instead

        hi = myaddr.base.hi;
                    ^

    /src/OSMP.cpp:93:17: warning: [cppcoreguidelines-pro-type-union-access]

    do not access members of unions; use (boost::)variant instead

        lo = myaddr.base.lo;
                    ^

    /src/OSMP.cpp:231:18: warning: [readability-convert-member-functions-to-static]

    method 'DoStart' can be made static

    fmi2Status OSMP::DoStart(fmi2Boolean tolerance_defined, fmi2Real tolerance, fmi2Real start_time, fmi2Boolean stop_time_defined, fmi2Real stop_time)
                     ^

    /src/OSMP.cpp:236:18: warning: [readability-convert-member-functions-to-static]

    method 'DoEnterInitializationMode' can be made static

    fmi2Status OSMP::DoEnterInitializationMode()
                     ^

    /src/OSMP.cpp:297:18: warning: [readability-convert-member-functions-to-static]

    method 'DoTerm' can be made static

    fmi2Status OSMP::DoTerm()
                     ^

    /src/OSMP.cpp:308:1: warning: [cppcoreguidelines-pro-type-member-init]

    constructor does not initialize these fields: boolean_vars_, integer_vars_, real_vars_

    OSMP::OSMP(fmi2String theinstance_name,
    ^

    /src/OSMP.cpp:468:24: warning: [cppcoreguidelines-pro-bounds-constant-array-index]

    do not use array subscript when the index is not an integer constant expression

                value[i] = real_vars_[vr[i]];
                           ^

    /src/OSMP.cpp:492:24: warning: [cppcoreguidelines-pro-bounds-constant-array-index]

    do not use array subscript when the index is not an integer constant expression

                value[i] = integer_vars_[vr[i]];
                           ^

    /src/OSMP.cpp:509:24: warning: [cppcoreguidelines-pro-bounds-constant-array-index]

    do not use array subscript when the index is not an integer constant expression

                value[i] = boolean_vars_[vr[i]];
                           ^

    /src/OSMP.cpp:526:24: warning: [cppcoreguidelines-pro-bounds-constant-array-index]

    do not use array subscript when the index is not an integer constant expression

                value[i] = string_vars_[vr[i]].c_str();
                           ^

    /src/OSMP.cpp:543:13: warning: [cppcoreguidelines-pro-bounds-constant-array-index]

    do not use array subscript when the index is not an integer constant expression

                real_vars_[vr[i]] = value[i];
                ^

    /src/OSMP.cpp:560:13: warning: [cppcoreguidelines-pro-bounds-constant-array-index]

    do not use array subscript when the index is not an integer constant expression

                integer_vars_[vr[i]] = value[i];
                ^

    /src/OSMP.cpp:577:13: warning: [cppcoreguidelines-pro-bounds-constant-array-index]

    do not use array subscript when the index is not an integer constant expression

                boolean_vars_[vr[i]] = value[i];
                ^

    /src/OSMP.cpp:594:13: warning: [cppcoreguidelines-pro-bounds-constant-array-index]

    do not use array subscript when the index is not an integer constant expression

                string_vars_[vr[i]] = value[i];
                ^

Have any feedback or feature suggestions? Share it here.

Please sign in to comment.