Skip to content

Commit 60daee2

Browse files
committed
Initial commit
0 parents  commit 60daee2

24 files changed

+1084
-0
lines changed

.clang-format

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
BasedOnStyle: Chromium
3+
AccessModifierOffset: -4
4+
AlignAfterOpenBracket: Align
5+
#AllowAllArgumentsOnNextLine: 'false'
6+
#AlignConsecutiveAssignments: None
7+
#AlignConsecutiveDeclarations: None
8+
AlignEscapedNewlines: Left
9+
AlignOperands: true
10+
AllowAllParametersOfDeclarationOnNextLine: true
11+
#AllowShortBlocksOnASingleLine: Never
12+
AllowShortCaseLabelsOnASingleLine: false
13+
AllowShortFunctionsOnASingleLine: None
14+
AllowShortIfStatementsOnASingleLine: false
15+
AllowShortLoopsOnASingleLine: false
16+
AlwaysBreakAfterReturnType: None
17+
AlwaysBreakBeforeMultilineStrings: false
18+
#AlwaysBreakTemplateDeclarations: Yes
19+
BinPackArguments: false
20+
BinPackParameters: false
21+
BreakBeforeBinaryOperators: None
22+
BreakBeforeBraces: Allman
23+
BreakBeforeTernaryOperators: true
24+
BreakConstructorInitializersBeforeComma: true
25+
ColumnLimit: 140
26+
CommentPragmas: '^ IWYU pragma:'
27+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
28+
ConstructorInitializerIndentWidth: 4
29+
ContinuationIndentWidth: 4
30+
IndentCaseLabels: true
31+
IndentWidth: 4
32+
KeepEmptyLinesAtTheStartOfBlocks: false
33+
Language: Cpp
34+
MaxEmptyLinesToKeep: 1
35+
NamespaceIndentation: All
36+
ObjCBlockIndentWidth: 4
37+
PenaltyBreakBeforeFirstCallParameter: 1
38+
PenaltyBreakComment: 300
39+
PenaltyBreakFirstLessLess: 120
40+
PenaltyBreakString: 1000
41+
PenaltyExcessCharacter: 1000000
42+
PenaltyReturnTypeOnItsOwnLine: 200
43+
PointerAlignment: Left
44+
#SortIncludes: Never
45+
SpaceAfterCStyleCast: true
46+
SpaceBeforeAssignmentOperators: true
47+
SpaceBeforeParens: ControlStatements
48+
SpacesBeforeTrailingComments: 2
49+
Standard: Auto
50+
TabWidth: 4
51+
UseTab: Never
52+
#NamespaceMacros:
53+
# - DECLARE_TEMPLATED_OPENDAQ_INTERFACE_T
54+
# - DECLARE_TEMPLATED_OPENDAQ_INTERFACE_T_U
55+
# - DECLARE_OPENDAQ_INTERFACE_EX
56+
# - DECLARE_OPENDAQ_INTERFACE
57+
FixNamespaceComments: false
58+
#MacroBlockBegin: "^BEGIN_NAMESPACE_OPENDAQ$"
59+
#MacroBlockEnd: "^END_NAMESPACE_OPENDAQ"
60+
#IndentPPDirectives: BeforeHash
61+
#SeparateDefinitionBlocks: Always
62+
...

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[{*.{cpp,h},CMakeLists.txt,*.rtclass,*.cmake,*.json}]
4+
indent_style = space
5+
indent_size = 4
6+
tab_size = 4
7+
insert_final_newline = true
8+
trim_trailing_whitespace = true
9+
10+
[*.yml]
11+
ident_style = space
12+
ident_size = 2
13+
tab_size = 2
14+
insert_final_newline = true
15+
trim_trailing_whitespace = true

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* text=auto
2+
*.[tT][xX][tT] text
3+
*.[sS][hH] text eol=lf

.gitignore

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# file types
2+
*.bin
3+
*.bak
4+
*.cache
5+
*.check_cache
6+
*.db
7+
*.dcu
8+
*.depend
9+
*.exp
10+
*.filters
11+
*.idb
12+
*.ilk
13+
*.list
14+
*.log
15+
*.obj
16+
*.orig
17+
*.pdb
18+
*.pyc
19+
*.rule
20+
*.rsm
21+
*.stamp
22+
*.stat
23+
*.suo
24+
*.tlog
25+
*.user
26+
27+
# IDE files
28+
.idea/
29+
.idea_/
30+
.vs/
31+
.vscode/
32+
__history/
33+
__recovery/
34+
__pycache__/
35+
36+
# build and backup folders
37+
/_build*
38+
/build*
39+
/build_win
40+
/cmake-build*
41+
/out*
42+
bckp
43+
44+
# cmake
45+
CMakeUserPresets.json
46+
CMakeSettings.json

CMakeLists.txt

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
cmake_minimum_required(VERSION 3.25)
2+
set(REPO_NAME example_fb_module)
3+
set(REPO_OPTION_PREFIX EXAMPLE_MODULE)
4+
5+
project(${REPO_NAME} VERSION 1.0.0)
6+
7+
if (POLICY CMP0135)
8+
cmake_policy(SET CMP0135 NEW)
9+
endif()
10+
11+
if (POLICY CMP0077)
12+
cmake_policy(SET CMP0077 NEW)
13+
endif()
14+
15+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
16+
list(APPEND CMAKE_MESSAGE_CONTEXT ${REPO_NAME})
17+
set(CMAKE_MESSAGE_CONTEXT_SHOW ON CACHE BOOL "Show CMake message context")
18+
19+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
20+
21+
add_definitions(-DFMT_HEADER_ONLY)
22+
23+
option(OPENDAQ_FB_EXAMPLE_ENABLE_APP "Enable building example function block application" OFF)
24+
option(EXAMPLE_MODULE_ENABLE_TESTS "Enable building of test suite for the example function block module" OFF)
25+
26+
include(CommonUtils)
27+
setup_repo(${REPO_OPTION_PREFIX})
28+
29+
if(OPENDAQ_FB_EXAMPLE_ENABLE_APP)
30+
set(DAQMODULES_REF_FB_MODULE ON CACHE BOOL "" FORCE)
31+
set(DAQMODULES_REF_DEVICE_MODULE ON CACHE BOOL "" FORCE)
32+
endif()
33+
34+
add_subdirectory(external)
35+
add_subdirectory(example_module)
36+
37+
if(OPENDAQ_FB_EXAMPLE_ENABLE_APP)
38+
message(STATUS "Enabled example function block application")
39+
add_subdirectory(example_application)
40+
endif()
41+
42+
# Set CPack variables
43+
set(CPACK_COMPONENTS_ALL RUNTIME)
44+
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
45+
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
46+
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
47+
set(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_BINARY_DIR}/package")
48+
49+
# Set the CPack generator based on the platform
50+
if (WIN32)
51+
set(CPACK_GENERATOR "ZIP")
52+
elseif (UNIX AND NOT APPLE)
53+
cmake_host_system_information(RESULT DISTRO_ID QUERY DISTRIB_ID)
54+
cmake_host_system_information(RESULT DISTRO_VERSION_ID QUERY DISTRIB_VERSION_ID)
55+
set(CPACK_SYSTEM_NAME "${DISTRO_ID}${DISTRO_VERSION_ID}")
56+
set(CPACK_GENERATOR "TGZ")
57+
endif()
58+
59+
# Include CPack for packaging
60+
include(CPack)

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Example function block module
2+
3+
Simple example that builds an openDAQ module giving access to an example function block. Said function block scales an input signal with a provided scale, and offsets it by a provided offset.
4+
5+
## Testing the module
6+
7+
To test the module, enable the `OPENDAQ_FB_EXAMPLE_ENABLE_APP` cmake flag. Doing so will add an the openDAQ reference device and function block modules to your project. Those are used to create a simulator device via the "daqref://device0" connection string, as well as a renderer via the "RefFBModuleRenderer" function block ID. The main application connects a reference device signal into both the example scaler and renderer. Additionally, it connects the scaler output into the renderer.
8+
9+
To add additional tests, enable the `EXAMPLE_MODULE_ENABLE_TESTS` cmake flag. Doing so will create a new test target configured for use with the GTest framework.

cmake/CommonUtils.cmake

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
macro(setup_repo REPO_OPTION_PREFIX)
2+
if (NOT DEFINED PROJECT_SOURCE_DIR)
3+
message(FATAL_ERROR "Must be run inside a project()")
4+
endif()
5+
6+
# Additional build options
7+
option(${REPO_OPTION_PREFIX}_DISABLE_DEBUG_POSTFIX "Disable debug ('-debug') postfix" OFF)
8+
option(${REPO_OPTION_PREFIX}_DEBUG_WARNINGS_AS_ERRORS "Treat debug warnings as errors" OFF)
9+
option(${REPO_OPTION_PREFIX}_ENABLE_TESTS "Enable unit-tests for ${REPO_OPTION_PREFIX}" ON)
10+
11+
get_filename_component(ROOT_DIR ${CMAKE_SOURCE_DIR} REALPATH)
12+
13+
if (NOT ${PROJECT_SOURCE_DIR} STREQUAL ${ROOT_DIR})
14+
set(BUILDING_AS_SUBMODULE ON PARENT_SCOPE)
15+
message(STATUS "Building as submodule")
16+
else()
17+
message(STATUS "Building standalone")
18+
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER ".CMakePredefinedTargets")
19+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
20+
21+
get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
22+
23+
message(STATUS "Platform: ${CMAKE_SYSTEM_PROCESSOR} | ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_VERSION}")
24+
message(STATUS "Generator: ${CMAKE_GENERATOR} | ${CMAKE_GENERATOR_PLATFORM}")
25+
26+
if (IS_MULTICONFIG)
27+
message(STATUS "Configuration types:")
28+
29+
block()
30+
list(APPEND CMAKE_MESSAGE_INDENT "\t")
31+
32+
foreach(CONFIG_TYPE ${CMAKE_CONFIGURATION_TYPES})
33+
message(STATUS ${CONFIG_TYPE})
34+
endforeach()
35+
endblock()
36+
else()
37+
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
38+
endif()
39+
40+
string(TIMESTAMP CONFIGURE_DATE)
41+
string(TIMESTAMP CURRENT_YEAR "%Y")
42+
endif()
43+
44+
set(CMAKE_CXX_STANDARD 17)
45+
if (WIN32)
46+
add_compile_definitions(NOMINMAX
47+
_WIN32_WINNT=0x0601 # Windows 7 Compat
48+
)
49+
50+
add_compile_definitions(UNICODE _UNICODE)
51+
endif()
52+
53+
if(NOT CMAKE_DEBUG_POSTFIX AND NOT ${REPO_OPTION_PREFIX}_DISABLE_DEBUG_POSTFIX)
54+
set(CMAKE_DEBUG_POSTFIX -debug)
55+
endif()
56+
57+
if (MSVC)
58+
# As above CMAKE_CXX_STANDARD but for VS
59+
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/std:c++17>)
60+
61+
foreach (flag IN ITEMS
62+
# Set source and execution character sets to UTF-8
63+
# https://learn.microsoft.com/en-us/cpp/build/reference/utf-8-set-source-and-executable-character-sets-to-utf-8
64+
/utf-8
65+
# Display level 1, level 2, and level 3 warnings, and all level 4 (informational) warnings that aren't off by default.
66+
# https://learn.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level
67+
/W4
68+
# data member 'member1' will be initialized after data member 'member2'
69+
# https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/c5038
70+
#/w15038
71+
# Supress warnings
72+
# https://learn.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level
73+
#
74+
# 'class1' : inherits 'class2::member' via dominance
75+
# https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4250
76+
#/wd4250
77+
# Your code uses a function, class member, variable, or typedef that's marked deprecated.
78+
# https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4996
79+
/wd4996
80+
# declaration of 'identifier' hides class member
81+
# https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4458
82+
/wd4458
83+
# nonstandard extension used : nameless struct/union
84+
# https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4201
85+
#/wd4201
86+
# unreachable code
87+
# https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4702
88+
#/wd4702
89+
# declaration of 'identifier' hides global declaration
90+
# https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4459
91+
#/wd4459
92+
# 'function' : unreferenced local function has been removed
93+
# https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4505
94+
#/wd4505
95+
# conditional expression is constant
96+
# https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4127
97+
#/wd4127
98+
# assignment within conditional expression
99+
# https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4706
100+
#/wd4706
101+
# loss of data / precision, unsigned <--> signed
102+
#
103+
# 'argument' : conversion from 'type1' to 'type2', possible loss of data
104+
# https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4244
105+
/wd4244
106+
# 'var' : conversion from 'size_t' to 'type', possible loss of data
107+
# https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4267
108+
#/wd4267
109+
# 'identifier' : unreferenced formal parameter
110+
# https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4100
111+
/wd4100
112+
)
113+
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:${flag}>)
114+
endforeach()
115+
116+
if (NOT OPENDAQ_MSVC_SINGLE_PROCESS_BUILD)
117+
# Build with multiple processes
118+
# https://learn.microsoft.com/en-us/cpp/build/reference/mp-build-with-multiple-processes
119+
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/MP>)
120+
endif()
121+
122+
# Treat warnings as errors if not Debug or OPENDAQ_DEBUG_WARNINGS_AS_ERRORS is ON
123+
add_compile_options($<$<OR:$<NOT:$<CONFIG:Debug>>,$<BOOL:${${REPO_OPTION_PREFIX}_DEBUG_WARNINGS_AS_ERRORS}>>:/WX>)
124+
125+
add_compile_definitions($<$<CONFIG:Debug>:_DEBUG>)
126+
127+
if (MSVC_VERSION GREATER_EQUAL 1910)
128+
# /Zc:__cplusplus forces MSVC to use the correct value of __cplusplus macro (otherwise always C++98)
129+
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/Zc:__cplusplus>)
130+
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
131+
# /Zf (Faster PDB generation) is not supported by ClangCL
132+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Zf")
133+
endif()
134+
135+
# Produce diagnostic messages with exact location
136+
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/diagnostics:caret>)
137+
endif()
138+
139+
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /ignore:4221")
140+
# set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /ignore:4221")
141+
# set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /ignore:4221")
142+
endif()
143+
144+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
145+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
146+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
147+
148+
if (${REPO_OPTION_PREFIX}_ENABLE_TESTS)
149+
set(OPENDAQ_ENABLE_TEST_UTILS ON CACHE BOOL "Enable testing utils library")
150+
endif()
151+
endmacro()

example_application/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
add_executable(fb_application_example main.cpp)
2+
3+
target_link_libraries(fb_application_example PRIVATE daq::opendaq)
4+
5+
add_dependencies(
6+
fb_application_example
7+
example_module
8+
daq::ref_device_module
9+
daq::ref_fb_module
10+
)

example_application/main.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Server application
3+
*/
4+
5+
#include <iostream>
6+
#include <opendaq/opendaq.h>
7+
8+
using namespace daq;
9+
10+
int main(int /*argc*/, const char* /*argv*/[])
11+
{
12+
const auto instance = Instance();
13+
auto referenceDevice = instance.addDevice("daqref://device0");
14+
auto renderer = instance.addFunctionBlock("RefFBModuleRenderer");
15+
auto exampleModule = instance.addFunctionBlock("ExampleScalingModule");
16+
exampleModule.setPropertyValue("Scale", 3);
17+
exampleModule.setPropertyValue("Offset", -2);
18+
19+
exampleModule.getInputPorts()[0].connect(referenceDevice.getSignalsRecursive()[0]);
20+
renderer.getInputPorts()[0].connect(referenceDevice.getSignalsRecursive()[0]);
21+
renderer.getInputPorts()[1].connect(exampleModule.getSignals()[0]);
22+
23+
std::cout << "Press \"enter\" to exit the application..." << std::endl;
24+
std::cin.get();
25+
return 0;
26+
}

0 commit comments

Comments
 (0)