Skip to content

Commit d9804dd

Browse files
committed
Initial commit
0 parents  commit d9804dd

25 files changed

+1050
-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: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
cmake_minimum_required(VERSION 3.25)
2+
set(REPO_NAME example_device_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_DEVICE_EXAMPLE_ENABLE_SERVER_APP "Enable building example server application" OFF)
24+
25+
include(CommonUtils)
26+
setup_repo(${REPO_OPTION_PREFIX})
27+
28+
if(OPENDAQ_DEVICE_EXAMPLE_ENABLE_SERVER_APP)
29+
set(DAQMODULES_OPENDAQ_SERVER_MODULE ON CACHE BOOL "" FORCE)
30+
set(OPENDAQ_ENABLE_NATIVE_STREAMING ON CACHE BOOL "" FORCE)
31+
endif()
32+
33+
add_subdirectory(external)
34+
add_subdirectory(example_module)
35+
36+
if(OPENDAQ_DEVICE_EXAMPLE_ENABLE_SERVER_APP)
37+
message(STATUS "Enbled example server application")
38+
add_subdirectory(server_application)
39+
endif()
40+
41+
# Set CPack variables
42+
set(CPACK_COMPONENTS_ALL RUNTIME)
43+
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
44+
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
45+
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
46+
set(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_BINARY_DIR}/package")
47+
48+
# Set the CPack generator based on the platform
49+
if (WIN32)
50+
set(CPACK_GENERATOR "ZIP")
51+
elseif (UNIX AND NOT APPLE)
52+
cmake_host_system_information(RESULT DISTRO_ID QUERY DISTRIB_ID)
53+
cmake_host_system_information(RESULT DISTRO_VERSION_ID QUERY DISTRIB_VERSION_ID)
54+
set(CPACK_SYSTEM_NAME "${DISTRO_ID}${DISTRO_VERSION_ID}")
55+
set(CPACK_GENERATOR "TGZ")
56+
endif()
57+
58+
# Include CPack for packaging
59+
include(CPack)

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Example device module
2+
3+
Simple example that builds an openDAQ module giving access to an example device. Said device contains 2 channels, each with a value and time signal. The value signal outputs a counter signal, increasing at a rate of 1 per second.
4+
5+
## Testing the module
6+
7+
To test the module, enable the `OPENDAQ_DEVICE_EXAMPLE_ENABLE_SERVER_APP` cmake flag. Doing so will add an openDAQ native server module to your build targets, and add an additional "server_application" executable. Running the executable will create a device, add an openDAQ server, and enable discovery.
8+
9+
To connect to the device, the openDAQ Python GUI application can be used (Latest Python version is recommended):
10+
11+
```
12+
py -m pip install openDAQ
13+
py -m openDAQ
14+
```

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_module/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
get_current_folder_name(TARGET_FOLDER_NAME)
2+
project(ExampleModule VERSION 1.0.0 LANGUAGES CXX)
3+
4+
add_subdirectory(src)
5+
6+
if (OPENDAQ_ENABLE_TESTS)
7+
add_subdirectory(tests)
8+
endif()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2022-2024 openDAQ d.o.o.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#pragma once
18+
#include <coretypes/common.h>
19+
20+
#define BEGIN_NAMESPACE_EXAMPLE_MODULE BEGIN_NAMESPACE_OPENDAQ_MODULE(example_module)
21+
22+
static const std::string EXAMPLE_MODULE_NAME = "ExampleModule";
23+
24+
#define END_NAMESPACE_EXAMPLE_MODULE END_NAMESPACE_OPENDAQ_MODULE

0 commit comments

Comments
 (0)