3rd Party Modules
Starting on Movesense device lib v1.7.0 the framework supports concept of 3rd party modules. The modules are (at the moment) source code only packages that can be easily incorporated into any application. This document describes the structure of the module folder as well as what must done in an app to use a 3rd party module.
Module structure
The structure of a 3rd party module is basically same as a movesense sensor application minus the CMakeLists.txt-file. It contains wbresources-subfolder with an empty .cpp file and any API definitions (.yaml -files) as well as C/C++ files (.c, .cpp, .h, .hpp) in the main module folder:
<module_dir> + wbresources
+-+- some_service.yaml
+- resources.cpp (empty)
+- ModuleFile1.h
+- ModuleFile1.cpp
+- ModuleFile2.h
+- ModuleFile2.cpp
The new build system finds all API definitions in wbresources and compiles them to resources, and all source files from the module folder and includes them into the build.
Using a Module
To add a 3rd party module in your sensor application you need to:
1. Include module folder into the cmake of your application:
You can do that either from command line when calling cmake:
cmake.exe ... -DMOVESENSE_MODULES=<path_to_module_folder> ...
or add them to the CMakeLists.txt file of your application:
# Create a list with all the modules
if(NOT DEFINED MOVESENSE_MODULES)
list(APPEND MOVESENSE_MODULES ${CMAKE_CURRENT_LIST_DIR}/<path_to_module1_folder>)
list(APPEND MOVESENSE_MODULES ${CMAKE_CURRENT_LIST_DIR}/<path_to_module2_folder>)
endif()
2. Include the needed .h-files in the .cpp-files of your application:
If the module contains a service (or other LaunchableModule) you need to include the .h-file of the LaunchableModule in the App.cpp file. If the module contains plain C/C++ code just include them in source files where you need.
3. Add the LaunchableModule(s) to the MOVESENSE_PROVIDERS_BEGIN/MOVESENSE_PROVIDERS_END block in App.cpp -file:
MOVESENSE_PROVIDERS_BEGIN(2)
MOVESENSE_PROVIDER_DEF(MyAppService)
MOVESENSE_PROVIDER_DEF(ExternalModuleClass)
MOVESENSE_PROVIDERS_END(2)
NOTE: Do not forget to increment the number in _BEGIN / _END macros to match the count of MOVESENSE_PROVIDER_DEF macros!
4. Add the modules API-definition in app_root.yaml -file
If the module contains a service which has an API-definition yaml-file in the wbresources folder of the module, you need to include the .yaml-file in the app_root.yaml file. This is done exactly like you would add the applications own yaml files:
apis:
AlgoECGRR.*:
apiId: 101
defaultExecutionContext: meas
Here the entry of the rr_from_ecg -module API (filename: AlgoECGRR.yaml) is included into the firmware by adding an entry in the "apis:" -section of the app_root.yaml.
- The entry is marked with a regexp that matches the yaml file name (here: "
AlgoECGRR.*
") - The apiId must be unique within the firmware (usually running number from 100 forward to not to confict with internal framework APIs)
- "defaultExecutionContext" tells which thread the service will run by default. Must be one of the contexts defined in the app_root.yaml. usually either "
meas
" or "application
".
5. Add resources.h in your .cpp -files
To access the precompiled API definitions in your own cpp-files, just include the compiled API in your cpp-file by adding the following line in the #includes -section:
#include "modules-resources/resources.h"
Then use them in your code just like you would use framework or your own APIs:
asyncSubscribe(WB_RES::LOCAL::ALGO_ECGRR());