Compare commits
70 Commits
e29606a2d0
...
v3.0.1
Author | SHA1 | Date | |
---|---|---|---|
620841a9e5 | |||
bd29688307 | |||
43b7a314b6 | |||
2a268e14d1 | |||
bd64a43819 | |||
d0c7878da4 | |||
2bd1e6acbd | |||
9697575f50 | |||
cec44ad44c | |||
![]() |
661b7b44e0 | ||
e952a82b65 | |||
cbcfa8fe56 | |||
32ba4301e4 | |||
4a5204d6f6 | |||
df45f02c39 | |||
15dddd7fc4 | |||
fd7581f8ba | |||
c2bf09d506 | |||
bf31248a50 | |||
9fadc9b830 | |||
8c17c7e1a7 | |||
9c5e3565c6 | |||
ecc7f1d691 | |||
00dced31ee | |||
ab7117d81e | |||
05c4f4fadc | |||
186b3565e0 | |||
e688105073 | |||
f7c6ec329b | |||
30217aa42b | |||
0176c07886 | |||
6d5eb5b387 | |||
9a38106b57 | |||
75e16e0b7b | |||
87a15910fe | |||
9ad215c9a3 | |||
2ca7a84e86 | |||
fbeb578d1c | |||
58d4525e8a | |||
8d004e9621 | |||
a53992fdc9 | |||
c6bbc19b85 | |||
36aaf3d758 | |||
7c855592d0 | |||
cb7399b999 | |||
d675621b73 | |||
3448a8c01b | |||
42458725e8 | |||
cc7250fcf5 | |||
da42edcc0c | |||
b02f737418 | |||
1923b339e9 | |||
3c41472649 | |||
da19764232 | |||
2126e6e375 | |||
5f8adc63b7 | |||
81bae85825 | |||
e263f2fbdc | |||
8d34561137 | |||
19f9b0280c | |||
e86319707f | |||
0e653378c3 | |||
a506b94d7e | |||
7bff632042 | |||
07a0dd5331 | |||
f16dcebf6b | |||
dc6ed40bfb | |||
a5a306ff66 | |||
7122c37511 | |||
6e97bd4db4 |
7
.clang-format
Normal file
7
.clang-format
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
BasedOnStyle: Google
|
||||
IndentWidth: 2
|
||||
---
|
||||
Language: Cpp
|
||||
ColumnLimit: 100
|
||||
---
|
@@ -1,8 +1,11 @@
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
set(FSFW_VERSION 2)
|
||||
set(FSFW_VERSION 3)
|
||||
set(FSFW_SUBVERSION 0)
|
||||
set(FSFW_REVISION 0)
|
||||
set(FSFW_REVISION 1)
|
||||
|
||||
# Add the cmake folder so the FindSphinx module is found
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
|
||||
|
||||
option(FSFW_GENERATE_SECTIONS
|
||||
"Generate function and data sections. Required to remove unused code" ON
|
||||
@@ -12,6 +15,7 @@ if(FSFW_GENERATE_SECTIONS)
|
||||
endif()
|
||||
|
||||
option(FSFW_BUILD_UNITTESTS "Build unittest binary in addition to static library" OFF)
|
||||
option(FSFW_BUILD_DOCS "Build documentation with Sphinx and Doxygen" OFF)
|
||||
if(FSFW_BUILD_UNITTESTS)
|
||||
option(FSFW_TESTS_GEN_COV "Generate coverage data for unittests" ON)
|
||||
endif()
|
||||
@@ -36,7 +40,9 @@ option(FSFW_ADD_SGP4_PROPAGATOR "Add SGP4 propagator code" OFF)
|
||||
|
||||
set(LIB_FSFW_NAME fsfw)
|
||||
set(FSFW_TEST_TGT fsfw-tests)
|
||||
set(FSFW_DUMMY_TGT fsfw-dummy)
|
||||
|
||||
project(${LIB_FSFW_NAME})
|
||||
add_library(${LIB_FSFW_NAME})
|
||||
|
||||
if(FSFW_BUILD_UNITTESTS)
|
||||
@@ -59,7 +65,6 @@ if(FSFW_BUILD_UNITTESTS)
|
||||
set(FSFW_CONFIG_PATH tests/src/fsfw_tests/unit/testcfg)
|
||||
configure_file(tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in FSFWConfig.h)
|
||||
configure_file(tests/src/fsfw_tests/unit/testcfg/TestsConfig.h.in tests/TestsConfig.h)
|
||||
configure_file(tests/src/fsfw_tests/unit/testcfg/OBSWConfig.h.in OBSWConfig.h)
|
||||
|
||||
project(${FSFW_TEST_TGT} CXX C)
|
||||
add_executable(${FSFW_TEST_TGT})
|
||||
@@ -93,14 +98,6 @@ target_include_directories(${LIB_FSFW_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
if(FSFW_BUILD_UNITTESTS)
|
||||
configure_file(src/fsfw/FSFW.h.in fsfw/FSFW.h)
|
||||
configure_file(src/fsfw/FSFWVersion.h.in fsfw/FSFWVersion.h)
|
||||
else()
|
||||
configure_file(src/fsfw/FSFW.h.in FSFW.h)
|
||||
configure_file(src/fsfw/FSFWVersion.h.in FSFWVersion.h)
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_CXX_STANDARD)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||
@@ -155,6 +152,14 @@ else()
|
||||
set(OS_FSFW "host")
|
||||
endif()
|
||||
|
||||
if(FSFW_BUILD_UNITTESTS OR FSFW_BUILD_DOCS)
|
||||
configure_file(src/fsfw/FSFW.h.in fsfw/FSFW.h)
|
||||
configure_file(src/fsfw/FSFWVersion.h.in fsfw/FSFWVersion.h)
|
||||
else()
|
||||
configure_file(src/fsfw/FSFW.h.in FSFW.h)
|
||||
configure_file(src/fsfw/FSFWVersion.h.in FSFWVersion.h)
|
||||
endif()
|
||||
|
||||
message(STATUS "Compiling FSFW for the ${FSFW_OS_NAME} operating system.")
|
||||
|
||||
add_subdirectory(src)
|
||||
@@ -163,6 +168,9 @@ if(FSFW_ADD_HAL)
|
||||
add_subdirectory(hal)
|
||||
endif()
|
||||
add_subdirectory(contrib)
|
||||
if(FSFW_BUILD_DOCS)
|
||||
add_subdirectory(docs)
|
||||
endif()
|
||||
|
||||
if(FSFW_BUILD_UNITTESTS)
|
||||
if(FSFW_TESTS_GEN_COV)
|
||||
@@ -234,9 +242,11 @@ endif()
|
||||
# The project CMakeLists file has to set the FSFW_CONFIG_PATH and add it.
|
||||
# If this is not given, we include the default configuration and emit a warning.
|
||||
if(NOT FSFW_CONFIG_PATH)
|
||||
message(WARNING "Flight Software Framework configuration path not set!")
|
||||
set(DEF_CONF_PATH misc/defaultcfg/fsfwconfig)
|
||||
message(WARNING "Setting default configuration from ${DEF_CONF_PATH} ..")
|
||||
if(NOT FSFW_BUILD_DOCS)
|
||||
message(WARNING "Flight Software Framework configuration path not set!")
|
||||
message(WARNING "Setting default configuration from ${DEF_CONF_PATH} ..")
|
||||
endif()
|
||||
add_subdirectory(${DEF_CONF_PATH})
|
||||
set(FSFW_CONFIG_PATH ${DEF_CONF_PATH})
|
||||
endif()
|
||||
|
24
README.md
24
README.md
@@ -42,7 +42,7 @@ There are some functions like `printChar` which are different depending on the t
|
||||
and need to be implemented by the mission developer.
|
||||
|
||||
A template configuration folder was provided and can be copied into the project root to have
|
||||
a starting point. The [configuration section](doc/README-config.md#top) provides more specific
|
||||
a starting point. The [configuration section](docs/README-config.md#top) provides more specific
|
||||
information about the possible options.
|
||||
|
||||
## Adding the library
|
||||
@@ -107,16 +107,22 @@ cmake --build . -- fsfw-tests_coverage -j
|
||||
|
||||
The `coverage.py` script located in the `script` folder can also be used to do this conveniently.
|
||||
|
||||
## Formatting the sources
|
||||
|
||||
The formatting is done by the `clang-format` tool. The configuration is contained within the
|
||||
`.clang-format` file in the repository root. As long as `clang-format` is installed, you
|
||||
can run the `apply-clang-format.sh` helper script to format all source files consistently.
|
||||
|
||||
## Index
|
||||
|
||||
[1. High-level overview](doc/README-highlevel.md#top) <br>
|
||||
[2. Core components](doc/README-core.md#top) <br>
|
||||
[3. Configuration](doc/README-config.md#top) <br>
|
||||
[4. OSAL overview](doc/README-osal.md#top) <br>
|
||||
[5. PUS services](doc/README-pus.md#top) <br>
|
||||
[6. Device Handler overview](doc/README-devicehandlers.md#top) <br>
|
||||
[7. Controller overview](doc/README-controllers.md#top) <br>
|
||||
[8. Local Data Pools](doc/README-localpools.md#top) <br>
|
||||
[1. High-level overview](docs/README-highlevel.md#top) <br>
|
||||
[2. Core components](docs/README-core.md#top) <br>
|
||||
[3. Configuration](docs/README-config.md#top) <br>
|
||||
[4. OSAL overview](docs/README-osal.md#top) <br>
|
||||
[5. PUS services](docs/README-pus.md#top) <br>
|
||||
[6. Device Handler overview](docs/README-devicehandlers.md#top) <br>
|
||||
[7. Controller overview](docs/README-controllers.md#top) <br>
|
||||
[8. Local Data Pools](docs/README-localpools.md#top) <br>
|
||||
|
||||
|
||||
|
||||
|
8
automation/Dockerfile
Normal file
8
automation/Dockerfile
Normal file
@@ -0,0 +1,8 @@
|
||||
FROM ubuntu:focal
|
||||
|
||||
RUN apt-get update
|
||||
RUN apt-get --yes upgrade
|
||||
|
||||
#tzdata is a dependency, won't install otherwise
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
RUN apt-get --yes install gcc g++ cmake make lcov git valgrind nano
|
72
automation/Jenkinsfile
vendored
Normal file
72
automation/Jenkinsfile
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
pipeline {
|
||||
agent any
|
||||
environment {
|
||||
BUILDDIR = 'build-unittests'
|
||||
}
|
||||
stages {
|
||||
stage('Create Docker') {
|
||||
agent {
|
||||
dockerfile {
|
||||
dir 'automation'
|
||||
additionalBuildArgs '--no-cache'
|
||||
reuseNode true
|
||||
}
|
||||
}
|
||||
steps {
|
||||
sh 'rm -rf $BUILDDIR'
|
||||
}
|
||||
}
|
||||
stage('Configure') {
|
||||
agent {
|
||||
dockerfile {
|
||||
dir 'automation'
|
||||
reuseNode true
|
||||
}
|
||||
}
|
||||
steps {
|
||||
dir(BUILDDIR) {
|
||||
sh 'cmake -DFSFW_OSAL=host -DFSFW_BUILD_UNITTESTS=ON ..'
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Build') {
|
||||
agent {
|
||||
dockerfile {
|
||||
dir 'automation'
|
||||
reuseNode true
|
||||
}
|
||||
}
|
||||
steps {
|
||||
dir(BUILDDIR) {
|
||||
sh 'cmake --build . -j'
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Unittests') {
|
||||
agent {
|
||||
dockerfile {
|
||||
dir 'automation'
|
||||
reuseNode true
|
||||
}
|
||||
}
|
||||
steps {
|
||||
dir(BUILDDIR) {
|
||||
sh 'cmake --build . -- fsfw-tests_coverage -j'
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Valgrind') {
|
||||
agent {
|
||||
dockerfile {
|
||||
dir 'automation'
|
||||
reuseNode true
|
||||
}
|
||||
}
|
||||
steps {
|
||||
dir(BUILDDIR) {
|
||||
sh 'valgrind --leak-check=full --error-exitcode=1 ./fsfw-tests'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
13
cmake/FindSphinx.cmake
Normal file
13
cmake/FindSphinx.cmake
Normal file
@@ -0,0 +1,13 @@
|
||||
# Look for an executable called sphinx-build
|
||||
find_program(SPHINX_EXECUTABLE
|
||||
NAMES sphinx-build
|
||||
DOC "Path to sphinx-build executable")
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
# Handle standard arguments to find_package like REQUIRED and QUIET
|
||||
find_package_handle_standard_args(
|
||||
Sphinx
|
||||
"Failed to find sphinx-build executable"
|
||||
SPHINX_EXECUTABLE
|
||||
)
|
1
docs/.gitignore
vendored
Normal file
1
docs/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/_build
|
66
docs/CMakeLists.txt
Normal file
66
docs/CMakeLists.txt
Normal file
@@ -0,0 +1,66 @@
|
||||
# This is based on this excellent posting provided by Sy:
|
||||
# https://devblogs.microsoft.com/cppblog/clear-functional-c-documentation-with-sphinx-breathe-doxygen-cmake/
|
||||
find_package(Doxygen REQUIRED)
|
||||
find_package(Sphinx REQUIRED)
|
||||
|
||||
get_target_property(LIB_FSFW_PUBLIC_HEADER_DIRS ${LIB_FSFW_NAME} INTERFACE_INCLUDE_DIRECTORIES)
|
||||
# TODO: Add HAL as well
|
||||
file(GLOB_RECURSE LIB_FSFW_PUBLIC_HEADERS ${PROJECT_SOURCE_DIR}/src/*.h)
|
||||
file(GLOB_RECURSE RST_DOC_FILES ${PROJECT_SOURCE_DIR}/docs/*.rst)
|
||||
|
||||
set(DOXYGEN_INPUT_DIR ${PROJECT_SOURCE_DIR}/src)
|
||||
set(DOXYGEN_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/doxygen)
|
||||
set(DOXYGEN_INDEX_FILE ${DOXYGEN_OUTPUT_DIR}/xml/index.xml)
|
||||
set(DOXYFILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
|
||||
set(DOXYFILE_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
|
||||
|
||||
# Replace variables inside @@ with the current values
|
||||
configure_file(${DOXYFILE_IN} ${DOXYFILE_OUT} @ONLY)
|
||||
|
||||
# Doxygen won't create this for us
|
||||
file(MAKE_DIRECTORY ${DOXYGEN_OUTPUT_DIR})
|
||||
|
||||
# Only regenerate Doxygen when the Doxyfile or public headers change
|
||||
add_custom_command(
|
||||
OUTPUT ${DOXYGEN_INDEX_FILE}
|
||||
DEPENDS ${LIB_FSFW_PUBLIC_HEADERS}
|
||||
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE_OUT}
|
||||
MAIN_DEPENDENCY ${DOXYFILE_OUT} ${DOXYFILE_IN}
|
||||
COMMENT "Generating docs"
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
# Nice named target so we can run the job easily
|
||||
add_custom_target(Doxygen ALL DEPENDS ${DOXYGEN_INDEX_FILE})
|
||||
|
||||
set(SPHINX_SOURCE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
set(SPHINX_BUILD ${CMAKE_CURRENT_BINARY_DIR}/sphinx)
|
||||
set(SPHINX_INDEX_FILE ${SPHINX_BUILD}/index.html)
|
||||
|
||||
# Only regenerate Sphinx when:
|
||||
# - Doxygen has rerun
|
||||
# - Our doc files have been updated
|
||||
# - The Sphinx config has been updated
|
||||
add_custom_command(
|
||||
OUTPUT ${SPHINX_INDEX_FILE}
|
||||
COMMAND
|
||||
${SPHINX_EXECUTABLE} -b html
|
||||
# Tell Breathe where to find the Doxygen output
|
||||
-Dbreathe_projects.fsfw=${DOXYGEN_OUTPUT_DIR}/xml
|
||||
${SPHINX_SOURCE} ${SPHINX_BUILD}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
DEPENDS
|
||||
# Other docs files you want to track should go here (or in some variable)
|
||||
${RST_DOC_FILES}
|
||||
${DOXYGEN_INDEX_FILE}
|
||||
MAIN_DEPENDENCY ${SPHINX_SOURCE}/conf.py
|
||||
COMMENT "Generating documentation with Sphinx"
|
||||
)
|
||||
|
||||
# Nice named target so we can run the job easily
|
||||
add_custom_target(Sphinx ALL DEPENDS ${SPHINX_INDEX_FILE})
|
||||
|
||||
# Add an install target to install the docs
|
||||
include(GNUInstallDirs)
|
||||
install(DIRECTORY ${SPHINX_BUILD}
|
||||
DESTINATION ${CMAKE_INSTALL_DOCDIR})
|
7
docs/Doxyfile.in
Normal file
7
docs/Doxyfile.in
Normal file
@@ -0,0 +1,7 @@
|
||||
INPUT = "@DOXYGEN_INPUT_DIR@"
|
||||
|
||||
RECURSIVE = YES
|
||||
|
||||
OUTPUT_DIRECTORY = "@DOXYGEN_OUTPUT_DIR@"
|
||||
|
||||
GENERATE_XML = YES
|
20
docs/Makefile
Normal file
20
docs/Makefile
Normal file
@@ -0,0 +1,20 @@
|
||||
# Minimal makefile for Sphinx documentation
|
||||
#
|
||||
|
||||
# You can set these variables from the command line, and also
|
||||
# from the environment for the first two.
|
||||
SPHINXOPTS ?=
|
||||
SPHINXBUILD ?= sphinx-build
|
||||
SOURCEDIR = .
|
||||
BUILDDIR = _build
|
||||
|
||||
# Put it first so that "make" without argument is like "make help".
|
||||
help:
|
||||
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||
|
||||
.PHONY: help Makefile
|
||||
|
||||
# Catch-all target: route all unknown targets to Sphinx using the new
|
||||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
||||
%: Makefile
|
||||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
@@ -31,7 +31,9 @@ cohesive pool variables. These sets simply iterator over the list of variables a
|
||||
`read` and `commit` functions of each variable. The following diagram shows the
|
||||
high-level architecture of the local data pools.
|
||||
|
||||
<img align="center" src="./images/PoolArchitecture.png" width="50%"> <br>
|
||||
.. image:: ../misc/logo/FSFW_Logo_V3_bw.png
|
||||
:alt: FSFW Logo
|
||||
|
||||
|
||||
An example is shown for using the local data pools with a Gyroscope.
|
||||
For example, the following code shows an implementation to access data from a Gyroscope taken
|
16
docs/api.rst
Normal file
16
docs/api.rst
Normal file
@@ -0,0 +1,16 @@
|
||||
API
|
||||
====
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 4
|
||||
|
||||
api/objectmanager
|
||||
api/task
|
||||
api/ipc
|
||||
api/returnvalue
|
||||
api/event
|
||||
api/modes
|
||||
api/health
|
||||
api/action
|
||||
api/devicehandler
|
||||
api/controller
|
15
docs/api/action.rst
Normal file
15
docs/api/action.rst
Normal file
@@ -0,0 +1,15 @@
|
||||
Action Module API
|
||||
=================
|
||||
|
||||
``ActionHelper``
|
||||
-----------------
|
||||
|
||||
.. doxygenclass:: ActionHelper
|
||||
:members:
|
||||
|
||||
``HasActionsIF``
|
||||
-----------------
|
||||
|
||||
.. doxygenclass:: HasActionsIF
|
||||
:members:
|
||||
:protected-members:
|
16
docs/api/controller.rst
Normal file
16
docs/api/controller.rst
Normal file
@@ -0,0 +1,16 @@
|
||||
Controller API
|
||||
=================
|
||||
|
||||
``ControllerBase``
|
||||
-------------------------
|
||||
|
||||
.. doxygenclass:: ControllerBase
|
||||
:members:
|
||||
:protected-members:
|
||||
|
||||
``ExtendedControllerBase``
|
||||
-----------------------------
|
||||
|
||||
.. doxygenclass:: ExtendedControllerBase
|
||||
:members:
|
||||
:protected-members:
|
16
docs/api/devicehandler.rst
Normal file
16
docs/api/devicehandler.rst
Normal file
@@ -0,0 +1,16 @@
|
||||
Device Handler Base API
|
||||
=========================
|
||||
|
||||
``DeviceHandlerBase``
|
||||
-----------------------
|
||||
|
||||
.. doxygenclass:: DeviceHandlerBase
|
||||
:members:
|
||||
:protected-members:
|
||||
|
||||
``DeviceHandlerIF``
|
||||
-----------------------
|
||||
|
||||
.. doxygenclass:: DeviceHandlerIF
|
||||
:members:
|
||||
:protected-members:
|
6
docs/api/event.rst
Normal file
6
docs/api/event.rst
Normal file
@@ -0,0 +1,6 @@
|
||||
.. _eventapi:
|
||||
|
||||
Event API
|
||||
============
|
||||
|
||||
.. doxygenfile:: Event.h
|
9
docs/api/health.rst
Normal file
9
docs/api/health.rst
Normal file
@@ -0,0 +1,9 @@
|
||||
Health API
|
||||
===========
|
||||
|
||||
``HasHealthIF``
|
||||
------------------
|
||||
|
||||
.. doxygenclass:: HasHealthIF
|
||||
:members:
|
||||
:protected-members:
|
9
docs/api/ipc.rst
Normal file
9
docs/api/ipc.rst
Normal file
@@ -0,0 +1,9 @@
|
||||
IPC Module API
|
||||
=================
|
||||
|
||||
``MessageQueueIF``
|
||||
-------------------
|
||||
|
||||
.. doxygenclass:: MessageQueueIF
|
||||
:members:
|
||||
:protected-members:
|
10
docs/api/modes.rst
Normal file
10
docs/api/modes.rst
Normal file
@@ -0,0 +1,10 @@
|
||||
Modes API
|
||||
=========
|
||||
|
||||
|
||||
``HasModesIF``
|
||||
---------------
|
||||
|
||||
.. doxygenclass:: HasModesIF
|
||||
:members:
|
||||
:protected-members:
|
30
docs/api/objectmanager.rst
Normal file
30
docs/api/objectmanager.rst
Normal file
@@ -0,0 +1,30 @@
|
||||
Object Manager API
|
||||
=========================
|
||||
|
||||
``SystemObject``
|
||||
--------------------
|
||||
|
||||
.. doxygenclass:: SystemObject
|
||||
:members:
|
||||
:protected-members:
|
||||
|
||||
``ObjectManager``
|
||||
-----------------------
|
||||
|
||||
.. doxygenclass:: ObjectManager
|
||||
:members:
|
||||
:protected-members:
|
||||
|
||||
``SystemObjectIF``
|
||||
--------------------
|
||||
|
||||
.. doxygenclass:: SystemObjectIF
|
||||
:members:
|
||||
:protected-members:
|
||||
|
||||
``ObjectManagerIF``
|
||||
-----------------------
|
||||
|
||||
.. doxygenclass:: ObjectManagerIF
|
||||
:members:
|
||||
:protected-members:
|
10
docs/api/returnvalue.rst
Normal file
10
docs/api/returnvalue.rst
Normal file
@@ -0,0 +1,10 @@
|
||||
.. _retvalapi:
|
||||
|
||||
Returnvalue API
|
||||
==================
|
||||
|
||||
.. doxygenfile:: HasReturnvaluesIF.h
|
||||
|
||||
.. _fwclassids:
|
||||
|
||||
.. doxygenfile:: FwClassIds.h
|
8
docs/api/task.rst
Normal file
8
docs/api/task.rst
Normal file
@@ -0,0 +1,8 @@
|
||||
Task API
|
||||
=========
|
||||
|
||||
``ExecutableObjectIF``
|
||||
-----------------------
|
||||
|
||||
.. doxygenclass:: ExecutableObjectIF
|
||||
:members:
|
56
docs/conf.py
Normal file
56
docs/conf.py
Normal file
@@ -0,0 +1,56 @@
|
||||
# Configuration file for the Sphinx documentation builder.
|
||||
#
|
||||
# This file only contains a selection of the most common options. For a full
|
||||
# list see the documentation:
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
||||
|
||||
# -- Path setup --------------------------------------------------------------
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||
#
|
||||
# import os
|
||||
# import sys
|
||||
# sys.path.insert(0, os.path.abspath('.'))
|
||||
|
||||
|
||||
# -- Project information -----------------------------------------------------
|
||||
|
||||
project = 'Flight Software Framework'
|
||||
copyright = '2021, Institute of Space Systems (IRS)'
|
||||
author = 'Institute of Space Systems (IRS)'
|
||||
|
||||
# The full version, including alpha/beta/rc tags
|
||||
release = '2.0.1'
|
||||
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
|
||||
# Add any Sphinx extension module names here, as strings. They can be
|
||||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
||||
# ones.
|
||||
extensions = [ "breathe" ]
|
||||
|
||||
breathe_default_project = "fsfw"
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ['_templates']
|
||||
|
||||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
# This pattern also affects html_static_path and html_extra_path.
|
||||
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
|
||||
|
||||
|
||||
# -- Options for HTML output -------------------------------------------------
|
||||
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
#
|
||||
html_theme = 'alabaster'
|
||||
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
html_static_path = []
|
41
docs/config.rst
Normal file
41
docs/config.rst
Normal file
@@ -0,0 +1,41 @@
|
||||
Configuring the FSFW
|
||||
=====================
|
||||
|
||||
The FSFW can be configured via the ``fsfwconfig`` folder. A template folder has been provided in
|
||||
``misc/defaultcfg`` to have a starting point for this. The folder should be added
|
||||
to the include path. The primary configuration file is the ``FSFWConfig.h`` folder. Some
|
||||
of the available options will be explained in more detail here.
|
||||
|
||||
Auto-Translation of Events
|
||||
----------------------------
|
||||
|
||||
The FSFW allows the automatic translation of events, which allows developers to track triggered
|
||||
events directly via console output. Using this feature requires:
|
||||
|
||||
1. ``FSFW_OBJ_EVENT_TRANSLATION`` set to 1 in the configuration file.
|
||||
2. Special auto-generated translation files which translate event IDs and object IDs into
|
||||
human readable strings. These files can be generated using the
|
||||
`fsfwgen Python scripts <https://egit.irs.uni-stuttgart.de/fsfw/fsfw-gen>`_.
|
||||
3. The generated translation files for the object IDs should be named ``translatesObjects.cpp``
|
||||
and ``translateObjects.h`` and should be copied to the ``fsfwconfig/objects`` folder
|
||||
4. The generated translation files for the event IDs should be named ``translateEvents.cpp`` and
|
||||
``translateEvents.h`` and should be copied to the ``fsfwconfig/events`` folder
|
||||
|
||||
An example implementations of these translation file generators can be found as part
|
||||
of the `SOURCE project here <https://git.ksat-stuttgart.de/source/sourceobsw/-/tree/develop/generators>`_
|
||||
or the `FSFW example <https://egit.irs.uni-stuttgart.de/fsfw/fsfw-example-hosted/src/branch/master/generators>`_
|
||||
|
||||
Configuring the Event Manager
|
||||
----------------------------------
|
||||
|
||||
The number of allowed subscriptions can be modified with the following
|
||||
parameters:
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
namespace fsfwconfig {
|
||||
//! Configure the allocated pool sizes for the event manager.
|
||||
static constexpr size_t FSFW_EVENTMGMR_MATCHTREE_NODES = 240;
|
||||
static constexpr size_t FSFW_EVENTMGMT_EVENTIDMATCHERS = 120;
|
||||
static constexpr size_t FSFW_EVENTMGMR_RANGEMATCHERS = 120;
|
||||
}
|
2
docs/controllers.rst
Normal file
2
docs/controllers.rst
Normal file
@@ -0,0 +1,2 @@
|
||||
Controllers
|
||||
=============
|
70
docs/core.rst
Normal file
70
docs/core.rst
Normal file
@@ -0,0 +1,70 @@
|
||||
.. _core:
|
||||
|
||||
Core Modules
|
||||
=============
|
||||
|
||||
The core modules provide the most important functionalities of the Flight Software Framework.
|
||||
|
||||
Clock
|
||||
------
|
||||
|
||||
- This is a class of static functions that can be used at anytime
|
||||
- Leap Seconds must be set if any time conversions from UTC to other times is used
|
||||
|
||||
Object Manager
|
||||
---------------
|
||||
|
||||
- Must be created during program startup
|
||||
- The component which handles all references. All :cpp:class:`SystemObject`\s register at this
|
||||
component.
|
||||
- All :cpp:class:`SystemObject`\s needs to have a unique Object ID. Those can be managed like
|
||||
framework objects.
|
||||
- A reference to an object can be retrieved by calling the ``get`` function of
|
||||
:cpp:class:`ObjectManagerIF`. The target type must be specified as a template argument.
|
||||
A ``nullptr`` check of the returning pointer must be done. This function is based on
|
||||
run-time type information.
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
template <typename T> T* ObjectManagerIF::get(object_id_t id);
|
||||
|
||||
- A typical way to create all objects on startup is a handing a static produce function to the
|
||||
ObjectManager on creation. By calling ``ObjectManager::instance()->initialize(produceFunc)`` the
|
||||
produce function will be called and all :cpp:class:`SystemObject`\s will be initialized
|
||||
afterwards.
|
||||
|
||||
Event Manager
|
||||
---------------
|
||||
|
||||
- Component which allows routing of events
|
||||
- Other objects can subscribe to specific events, ranges of events or all events of an object.
|
||||
- Subscriptions can be done during runtime but should be done during initialization
|
||||
- Amounts of allowed subscriptions can be configured in ``FSFWConfig.h``
|
||||
|
||||
Health Table
|
||||
---------------
|
||||
|
||||
- A component which holds every health state
|
||||
- Provides a thread safe way to access all health states without the need of message exchanges
|
||||
|
||||
Stores
|
||||
--------------
|
||||
|
||||
- The message based communication can only exchange a few bytes of information inside the message
|
||||
itself. Therefore, additional information can be exchanged with Stores. With this, only the
|
||||
store address must be exchanged in the message.
|
||||
- Internally, the FSFW uses an IPC Store to exchange data between processes. For incoming TCs a TC
|
||||
Store is used. For outgoing TM a TM store is used.
|
||||
- All of them should use the Thread Safe Class storagemanager/PoolManager
|
||||
|
||||
Tasks
|
||||
---------
|
||||
|
||||
There are two different types of tasks:
|
||||
|
||||
- The PeriodicTask just executes objects that are of type ExecutableObjectIF in the order of the
|
||||
insertion to the Tasks.
|
||||
- FixedTimeslotTask executes a list of calls in the order of the given list. This is intended for
|
||||
DeviceHandlers, where polling should be in a defined order. An example can be found in
|
||||
``defaultcfg/fsfwconfig/pollingSequence`` folder
|
||||
|
3
docs/devicehandlers.rst
Normal file
3
docs/devicehandlers.rst
Normal file
@@ -0,0 +1,3 @@
|
||||
Device Handlers
|
||||
==================
|
||||
|
115
docs/getting_started.rst
Normal file
115
docs/getting_started.rst
Normal file
@@ -0,0 +1,115 @@
|
||||
Getting Started
|
||||
================
|
||||
|
||||
|
||||
Getting started
|
||||
----------------
|
||||
|
||||
The `Hosted FSFW example`_ provides a good starting point and a demo to see the FSFW capabilities.
|
||||
It is recommended to get started by building and playing around with the demo application.
|
||||
There are also other examples provided for all OSALs using the popular embedded platforms
|
||||
Raspberry Pi, Beagle Bone Black and STM32H7.
|
||||
|
||||
Generally, the FSFW is included in a project by providing
|
||||
a configuration folder, building the static library and linking against it.
|
||||
There are some functions like ``printChar`` which are different depending on the target architecture
|
||||
and need to be implemented by the mission developer.
|
||||
|
||||
A template configuration folder was provided and can be copied into the project root to have
|
||||
a starting point. The [configuration section](docs/README-config.md#top) provides more specific
|
||||
information about the possible options.
|
||||
|
||||
Adding the library
|
||||
-------------------
|
||||
|
||||
The following steps show how to add and use FSFW components. It is still recommended to
|
||||
try out the example mentioned above to get started, but the following steps show how to
|
||||
add and link against the FSFW library in general.
|
||||
|
||||
1. Add this repository as a submodule
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
git submodule add https://egit.irs.uni-stuttgart.de/fsfw/fsfw.git fsfw
|
||||
|
||||
2. Add the following directive inside the uppermost ``CMakeLists.txt`` file of your project
|
||||
|
||||
.. code-block:: cmake
|
||||
|
||||
add_subdirectory(fsfw)
|
||||
|
||||
3. Make sure to provide a configuration folder and supply the path to that folder with
|
||||
the `FSFW_CONFIG_PATH` CMake variable from the uppermost `CMakeLists.txt` file.
|
||||
It is also necessary to provide the `printChar` function. You can find an example
|
||||
implementation for a hosted build
|
||||
`here <https://egit.irs.uni-stuttgart.de/fsfw/fsfw-example-hosted/src/branch/master/bsp_hosted/utility/printChar.c>`_.
|
||||
|
||||
4. Link against the FSFW library
|
||||
|
||||
.. code-block:: cmake
|
||||
|
||||
target_link_libraries(<YourProjectName> PRIVATE fsfw)
|
||||
|
||||
|
||||
5. It should now be possible use the FSFW as a static library from the user code.
|
||||
|
||||
Building the unittests
|
||||
-------------------------
|
||||
|
||||
The FSFW also has unittests which use the `Catch2 library`_.
|
||||
These are built by setting the CMake option ``FSFW_BUILD_UNITTESTS`` to ``ON`` or `TRUE`
|
||||
from your project `CMakeLists.txt` file or from the command line.
|
||||
|
||||
The fsfw-tests binary will be built as part of the static library and dropped alongside it.
|
||||
If the unittests are built, the library and the tests will be built with coverage information by
|
||||
default. This can be disabled by setting the `FSFW_TESTS_COV_GEN` option to `OFF` or `FALSE`.
|
||||
|
||||
You can use the following commands inside the ``fsfw`` folder to set up the build system
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
mkdir build-tests && cd build-tests
|
||||
cmake -DFSFW_BUILD_UNITTESTS=ON -DFSFW_OSAL=host ..
|
||||
|
||||
|
||||
You can also use ``-DFSFW_OSAL=linux`` on Linux systems.
|
||||
|
||||
Coverage data in HTML format can be generated using the `Code coverage`_ CMake module.
|
||||
To build the unittests, run them and then generare the coverage data in this format,
|
||||
the following command can be used inside the build directory after the build system was set up
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
cmake --build . -- fsfw-tests_coverage -j
|
||||
|
||||
|
||||
The ``helper.py`` script located in the ``script`` folder can also be used to create, build
|
||||
and open the unittests conveniently. Try ``helper.py -h`` for more information.
|
||||
|
||||
Building the documentation
|
||||
----------------------------
|
||||
|
||||
The FSFW documentation is built using the tools Sphinx, doxygen and breathe based on the
|
||||
instructions provided in `this blogpost <https://devblogs.microsoft.com/cppblog/clear-functional-c-documentation-with-sphinx-breathe-doxygen-cmake/>`_. You can set up a
|
||||
documentation build system using the following commands
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
mkdir build-docs && cd build-docs
|
||||
cmake -DFSFW_BUILD_DOCS=ON -DFSFW_OSAL=host ..
|
||||
|
||||
Then you can generate the documentation using
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
cmake --build . -j
|
||||
|
||||
You can find the generated documentation inside the ``docs/sphinx`` folder inside the build
|
||||
folder. Simply open the ``index.html`` in the webbrowser of your choice.
|
||||
|
||||
The ``helper.py`` script located in the ``script`` folder can also be used to create, build
|
||||
and open the documentation conveniently. Try ``helper.py -h`` for more information.
|
||||
|
||||
.. _`Hosted FSFW example`: https://egit.irs.uni-stuttgart.de/fsfw/fsfw-example-hosted
|
||||
.. _`Catch2 library`: https://github.com/catchorg/Catch2
|
||||
.. _`Code coverage`: https://github.com/bilke/cmake-modules/tree/master
|
149
docs/highlevel.rst
Normal file
149
docs/highlevel.rst
Normal file
@@ -0,0 +1,149 @@
|
||||
.. _highlevel:
|
||||
|
||||
High-level overview
|
||||
===================
|
||||
|
||||
Structure
|
||||
----------
|
||||
|
||||
The general structure is driven by the usage of interfaces provided by objects.
|
||||
The FSFW uses C++11 as baseline. The intention behind this is that this C++ Standard should be
|
||||
widely available, even with older compilers.
|
||||
The FSFW uses dynamic allocation during the initialization but provides static containers during runtime.
|
||||
This simplifies the instantiation of objects and allows the usage of some standard containers.
|
||||
Dynamic Allocation after initialization is discouraged and different solutions are provided in the
|
||||
FSFW to achieve that. The fsfw uses run-time type information but exceptions are not allowed.
|
||||
|
||||
Failure Handling
|
||||
-----------------
|
||||
|
||||
Functions should return a defined :cpp:type:`ReturnValue_t` to signal to the caller that something has
|
||||
gone wrong. Returnvalues must be unique. For this the function :cpp:func:`HasReturnvaluesIF::makeReturnCode`
|
||||
or the :ref:`macro MAKE_RETURN_CODE <retvalapi>` can be used. The ``CLASS_ID`` is a unique ID for that type of object.
|
||||
See the :ref:`FSFW Class IDs file <fwclassids>`. The user can add custom ``CLASS_ID``\s via the
|
||||
``fsfwconfig`` folder.
|
||||
|
||||
OSAL
|
||||
------------
|
||||
|
||||
The FSFW provides operation system abstraction layers for Linux, FreeRTOS and RTEMS.
|
||||
The OSAL provides periodic tasks, message queues, clocks and semaphores as well as mutexes.
|
||||
The :ref:`OSAL README <osal>` provides more detailed information on provided components
|
||||
and how to use them.
|
||||
|
||||
Core Components
|
||||
----------------
|
||||
|
||||
The FSFW has following core components. More detailed informations can be found in the
|
||||
:ref:`core component section <core>`:
|
||||
|
||||
1. Tasks: Abstraction for different (periodic) task types like periodic tasks or tasks
|
||||
with fixed timeslots
|
||||
2. ObjectManager: This module stores all `SystemObjects` by mapping a provided unique object ID
|
||||
to the object handles.
|
||||
3. Static Stores: Different stores are provided to store data of variable size (like telecommands
|
||||
or small telemetry) in a pool structure without using dynamic memory allocation.
|
||||
These pools are allocated up front.
|
||||
4. Clock: This module provided common time related functions
|
||||
5. EventManager: This module allows routing of events generated by `SystemObjects`
|
||||
6. HealthTable: A component which stores the health states of objects
|
||||
|
||||
Static IDs in the framework
|
||||
--------------------------------
|
||||
|
||||
Some parts of the framework use a static routing address for communication.
|
||||
An example setup of IDs can be found in the example config in ``misc/defaultcfg/fsfwconfig/objects``
|
||||
inside the function ``Factory::setStaticFrameworkObjectIds``.
|
||||
|
||||
Events
|
||||
----------------
|
||||
|
||||
Events are tied to objects. EventIds can be generated by calling the
|
||||
:ref:`macro MAKE_EVENT <eventapi>` or the function :cpp:func:`event::makeEvent`.
|
||||
This works analog to the returnvalues. Every object that needs own Event IDs has to get a
|
||||
unique ``SUBSYSTEM_ID``. Every :cpp:class:`SystemObject` can call
|
||||
:cpp:func:`SystemObject::triggerEvent` from the parent class.
|
||||
Therefore, event messages contain the specific EventId and the objectId of the object that
|
||||
has triggered.
|
||||
|
||||
Internal Communication
|
||||
-------------------------
|
||||
|
||||
Components communicate mostly via Messages through Queues.
|
||||
Those queues are created by calling the singleton ``QueueFactory::instance()->create`` which
|
||||
will create `MessageQueue` instances for the used OSAL.
|
||||
|
||||
External Communication
|
||||
--------------------------
|
||||
|
||||
The external communication with the mission control system is mostly up to the user implementation.
|
||||
The FSFW provides PUS Services which can be used to but don't need to be used.
|
||||
The services can be seen as a conversion from a TC to a message based communication and back.
|
||||
|
||||
TMTC Communication
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The FSFW provides some components to facilitate TMTC handling via the PUS commands.
|
||||
For example, a UDP or TCP PUS server socket can be opened on a specific port using the
|
||||
files located in ``osal/common``. The FSFW example uses this functionality to allow sending
|
||||
telecommands and receiving telemetry using the
|
||||
`TMTC commander application <https://github.com/robamu-org/tmtccmd>`_.
|
||||
|
||||
Simple commands like the PUS Service 17 ping service can be tested by simply running the
|
||||
``tmtc_client_cli.py`` or ``tmtc_client_gui.py`` utility in
|
||||
the `example tmtc folder <https://egit.irs.uni-stuttgart.de/fsfw/fsfw_example_public/src/branch/master/tmtc>`_
|
||||
while the `fsfw_example` application is running.
|
||||
|
||||
More generally, any class responsible for handling incoming telecommands and sending telemetry
|
||||
can implement the generic ``TmTcBridge`` class located in ``tmtcservices``. Many applications
|
||||
also use a dedicated polling task for reading telecommands which passes telecommands
|
||||
to the ``TmTcBridge`` implementation.
|
||||
|
||||
CCSDS Frames, CCSDS Space Packets and PUS
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
If the communication is based on CCSDS Frames and Space Packets, several classes can be used to
|
||||
distributed the packets to the corresponding services. Those can be found in ``tcdistribution``.
|
||||
If Space Packets are used, a timestamper has to be provided by the user.
|
||||
An example can be found in the ``timemanager`` folder, which uses ``CCSDSTime::CDS_short``.
|
||||
|
||||
Device Handlers
|
||||
--------------------------
|
||||
|
||||
DeviceHandlers are another important component of the FSFW. The idea is, to have a software
|
||||
counterpart of every physical device to provide a simple mode, health and commanding interface.
|
||||
By separating the underlying Communication Interface with
|
||||
``DeviceCommunicationIF``, a device handler (DH) can be tested on different hardware.
|
||||
The DH has mechanisms to monitor the communication with the physical device which allow
|
||||
for FDIR reaction. Device Handlers can be created by implementing ``DeviceHandlerBase``.
|
||||
A standard FDIR component for the DH will be created automatically but can
|
||||
be overwritten by the user. More information on DeviceHandlers can be found in the
|
||||
related [documentation section](doc/README-devicehandlers.md#top).
|
||||
|
||||
Modes and Health
|
||||
--------------------
|
||||
|
||||
The two interfaces ``HasModesIF`` and ``HasHealthIF`` provide access for commanding and monitoring
|
||||
of components. On-board mode management is implement in hierarchy system.
|
||||
|
||||
- Device handlers and controllers are the lowest part of the hierarchy.
|
||||
- The next layer are assemblies. Those assemblies act as a component which handle
|
||||
redundancies of handlers. Assemblies share a common core with the top level subsystem components
|
||||
- The top level subsystem components are used to group assemblies, controllers and device handlers.
|
||||
For example, a spacecraft can have a atttitude control subsystem and a power subsystem.
|
||||
|
||||
Those assemblies are intended to act as auto-generated components from a database which describes
|
||||
the subsystem modes. The definitions contain transition and target tables which contain the DH,
|
||||
Assembly and Controller Modes to be commanded.
|
||||
Transition tables contain as many steps as needed to reach the mode from any other mode, e.g. a
|
||||
switch into any higher AOCS mode might first turn on the sensors, than the actuators and the
|
||||
controller as last component.
|
||||
The target table is used to describe the state that is checked continuously by the subsystem.
|
||||
All of this allows System Modes to be generated as Subsystem object as well from the same database.
|
||||
This System contains list of subsystem modes in the transition and target tables.
|
||||
Therefore, it allows a modular system to create system modes and easy commanding of those, because
|
||||
only the highest components must be commanded.
|
||||
|
||||
The health state represents if the component is able to perform its tasks.
|
||||
This can be used to signal the system to avoid using this component instead of a redundant one.
|
||||
The on-board FDIR uses the health state for isolation and recovery.
|
Before Width: | Height: | Size: 52 KiB After Width: | Height: | Size: 52 KiB |
69
docs/index.rst
Normal file
69
docs/index.rst
Normal file
@@ -0,0 +1,69 @@
|
||||
.. Flight Software Framework documentation master file, created by
|
||||
sphinx-quickstart on Tue Nov 30 10:56:03 2021.
|
||||
You can adapt this file completely to your liking, but it should at least
|
||||
contain the root `toctree` directive.
|
||||
|
||||
Flight Software Framework (FSFW) documentation
|
||||
================================================
|
||||
|
||||
.. image:: ../misc/logo/FSFW_Logo_V3_bw.png
|
||||
:alt: FSFW Logo
|
||||
|
||||
The Flight Software Framework is a C++ Object Oriented Framework for unmanned,
|
||||
automated systems like Satellites.
|
||||
|
||||
The initial version of the Flight Software Framework was developed during
|
||||
the Flying Laptop Project by the University of Stuttgart in cooperation
|
||||
with Airbus Defence and Space GmbH.
|
||||
|
||||
Quick facts
|
||||
---------------
|
||||
|
||||
The framework is designed for systems, which communicate with external devices, perform control
|
||||
loops, receive telecommands and send telemetry, and need to maintain a high level of availability.
|
||||
Therefore, a mode and health system provides control over the states of the software and the
|
||||
controlled devices. In addition, a simple mechanism of event based fault detection, isolation and
|
||||
recovery is implemented as well.
|
||||
|
||||
The FSFW provides abstraction layers for operating systems to provide a uniform operating system
|
||||
abstraction layer (OSAL). Some components of this OSAL are required internally by the FSFW but is
|
||||
also very useful for developers to implement the same application logic on different operating
|
||||
systems with a uniform interface.
|
||||
|
||||
Currently, the FSFW provides the following OSALs:
|
||||
|
||||
- Linux
|
||||
- Host
|
||||
- FreeRTOS
|
||||
- RTEMS
|
||||
|
||||
The recommended hardware is a microprocessor with more than 1 MB of RAM and 1 MB of non-volatile
|
||||
memory. For reference, current applications use a Cobham Gaisler UT699 (LEON3FT), a
|
||||
ISISPACE IOBC or a Zynq-7020 SoC. The ``fsfw`` was also successfully run on the
|
||||
STM32H743ZI-Nucleo board and on a Raspberry Pi and is currently running on the active
|
||||
satellite mission Flying Laptop.
|
||||
|
||||
Index
|
||||
-------
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
:caption: Contents:
|
||||
|
||||
getting_started
|
||||
highlevel
|
||||
core
|
||||
config
|
||||
osal
|
||||
pus
|
||||
devicehandlers
|
||||
controllers
|
||||
localpools
|
||||
api
|
||||
|
||||
Indices and tables
|
||||
==================
|
||||
|
||||
* :ref:`genindex`
|
||||
* :ref:`modindex`
|
||||
* :ref:`search`
|
181
docs/localpools.rst
Normal file
181
docs/localpools.rst
Normal file
@@ -0,0 +1,181 @@
|
||||
Local Data Pools
|
||||
=========================================
|
||||
|
||||
The following text is targeted towards mission software developers which would like
|
||||
to use the local data pools provided by the FSFW to store data like sensor values so they can be
|
||||
used by other software objects like controllers as well. If a custom class should have a local
|
||||
pool which can be used by other software objects as well, following steps have to be performed:
|
||||
|
||||
1. Create a ``LocalDataPoolManager`` member object in the custom class
|
||||
2. Implement the ``HasLocalDataPoolIF`` with specifies the interface between the local pool
|
||||
manager and the class owning the local pool.
|
||||
|
||||
The local data pool manager is also able to process housekeeping service requests in form
|
||||
of messages, generate periodic housekeeping packet, generate notification and snapshots of changed
|
||||
variables and datasets and process notifications and snapshots coming from other objects.
|
||||
The two former tasks are related to the external interface using telemetry and telecommands (TMTC)
|
||||
while the later two are related to data consumers like controllers only acting on data change
|
||||
detected by the data creator instead of checking the data manually each cycle. Two important
|
||||
framework classes ``DeviceHandlerBase`` and ``ExtendedControllerBase`` already perform the two steps
|
||||
shown above so the steps required are altered slightly.
|
||||
|
||||
Storing and Accessing pool data
|
||||
-------------------------------------
|
||||
|
||||
The pool manager is responsible for thread-safe access of the pool data, but the actual
|
||||
access to the pool data from the point of view of a mission software developer happens via proxy
|
||||
classes like pool variable classes. These classes store a copy
|
||||
of the pool variable with the matching datatype and copy the actual data from the local pool
|
||||
on a ``read`` call. Changed variables can then be written to the local pool with a ``commit`` call.
|
||||
The ``read`` and ``commit`` calls are thread-safe and can be called concurrently from data creators
|
||||
and data consumers. Generally, a user will create a dataset class which in turn groups all
|
||||
cohesive pool variables. These sets simply iterator over the list of variables and call the
|
||||
``read`` and ``commit`` functions of each variable. The following diagram shows the
|
||||
high-level architecture of the local data pools.
|
||||
|
||||
.. image:: ../docs/images/PoolArchitecture.png
|
||||
:alt: Pool Architecture
|
||||
|
||||
An example is shown for using the local data pools with a Gyroscope.
|
||||
For example, the following code shows an implementation to access data from a Gyroscope taken
|
||||
from the SOURCE CubeSat project:
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
class GyroPrimaryDataset: public StaticLocalDataSet<3 * sizeof(float)> {
|
||||
public:
|
||||
/**
|
||||
* Constructor for data users
|
||||
* @param gyroId
|
||||
*/
|
||||
GyroPrimaryDataset(object_id_t gyroId):
|
||||
StaticLocalDataSet(sid_t(gyroId, gyrodefs::GYRO_DATA_SET_ID)) {
|
||||
setAllVariablesReadOnly();
|
||||
}
|
||||
|
||||
lp_var_t<float> angVelocityX = lp_var_t<float>(sid.objectId,
|
||||
gyrodefs::ANGULAR_VELOCITY_X, this);
|
||||
lp_var_t<float> angVelocityY = lp_var_t<float>(sid.objectId,
|
||||
gyrodefs::ANGULAR_VELOCITY_Y, this);
|
||||
lp_var_t<float> angVelocityZ = lp_var_t<float>(sid.objectId,
|
||||
gyrodefs::ANGULAR_VELOCITY_Z, this);
|
||||
private:
|
||||
|
||||
friend class GyroHandler;
|
||||
/**
|
||||
* Constructor for data creator
|
||||
* @param hkOwner
|
||||
*/
|
||||
GyroPrimaryDataset(HasLocalDataPoolIF* hkOwner):
|
||||
StaticLocalDataSet(hkOwner, gyrodefs::GYRO_DATA_SET_ID) {}
|
||||
};
|
||||
|
||||
There is a public constructor for users which sets all variables to read-only and there is a
|
||||
constructor for the GyroHandler data creator by marking it private and declaring the ``GyroHandler``
|
||||
as a friend class. Both the atittude controller and the ``GyroHandler`` can now
|
||||
use the same class definition to access the pool variables with ``read`` and ``commit`` semantics
|
||||
in a thread-safe way. Generally, each class requiring access will have the set class as a member
|
||||
class. The data creator will also be generally a ``DeviceHandlerBase`` subclass and some additional
|
||||
steps are necessary to expose the set for housekeeping purposes.
|
||||
|
||||
Using the local data pools in a ``DeviceHandlerBase`` subclass
|
||||
--------------------------------------------------------------
|
||||
|
||||
It is very common to store data generated by devices like a sensor into a pool which can
|
||||
then be used by other objects. Therefore, the ``DeviceHandlerBase`` already has a
|
||||
local pool. Using the aforementioned example, the ``GyroHandler`` will now have the set class
|
||||
as a member:
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
class GyroHandler: ... {
|
||||
|
||||
public:
|
||||
...
|
||||
private:
|
||||
...
|
||||
GyroPrimaryDataset gyroData;
|
||||
...
|
||||
};
|
||||
|
||||
|
||||
The constructor used for the creators expects the owner class as a parameter, so we initialize
|
||||
the object in the `GyroHandler` constructor like this:
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
GyroHandler::GyroHandler(object_id_t objectId, object_id_t comIF,
|
||||
CookieIF *comCookie, uint8_t switchId):
|
||||
DeviceHandlerBase(objectId, comIF, comCookie), switchId(switchId),
|
||||
gyroData(this) {}
|
||||
|
||||
|
||||
We need to assign the set to a reply ID used in the ``DeviceHandlerBase``.
|
||||
The combination of the ``GyroHandler`` object ID and the reply ID will be the 64-bit structure ID
|
||||
``sid_t`` and is used to globally identify the set, for example when requesting housekeeping data or
|
||||
generating update messages. We need to assign our custom set class in some way so that the local
|
||||
pool manager can access the custom data sets as well.
|
||||
By default, the ``getDataSetHandle`` will take care of this tasks. The default implementation for a
|
||||
``DeviceHandlerBase`` subclass will use the internal command map to retrieve
|
||||
a handle to a dataset from a given reply ID. Therefore,
|
||||
we assign the set in the ``fillCommandAndReplyMap`` function:
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
void GyroHandler::fillCommandAndReplyMap() {
|
||||
...
|
||||
this->insertInCommandAndReplyMap(gyrodefs::GYRO_DATA, 3, &gyroData);
|
||||
...
|
||||
}
|
||||
|
||||
|
||||
Now, we need to create the actual pool entries as well, using the ``initializeLocalDataPool``
|
||||
function. Here, we also immediately subscribe for periodic housekeeping packets
|
||||
with an interval of 4 seconds. They are still disabled in this example and can be enabled
|
||||
with a housekeeping service command.
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
ReturnValue_t GyroHandler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||
LocalDataPoolManager &poolManager) {
|
||||
localDataPoolMap.emplace(gyrodefs::ANGULAR_VELOCITY_X,
|
||||
new PoolEntry<float>({0.0}));
|
||||
localDataPoolMap.emplace(gyrodefs::ANGULAR_VELOCITY_Y,
|
||||
new PoolEntry<float>({0.0}));
|
||||
localDataPoolMap.emplace(gyrodefs::ANGULAR_VELOCITY_Z,
|
||||
new PoolEntry<float>({0.0}));
|
||||
localDataPoolMap.emplace(gyrodefs::GENERAL_CONFIG_REG42,
|
||||
new PoolEntry<uint8_t>({0}));
|
||||
localDataPoolMap.emplace(gyrodefs::RANGE_CONFIG_REG43,
|
||||
new PoolEntry<uint8_t>({0}));
|
||||
|
||||
poolManager.subscribeForPeriodicPacket(gyroData.getSid(), false, 4.0, false);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
Now, if we receive some sensor data and converted them into the right format,
|
||||
we can write it into the pool like this, using a guard class to ensure the set is commited back
|
||||
in any case:
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
PoolReadGuard readHelper(&gyroData);
|
||||
if(readHelper.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
|
||||
if(not gyroData.isValid()) {
|
||||
gyroData.setValidity(true, true);
|
||||
}
|
||||
|
||||
gyroData.angVelocityX = angularVelocityX;
|
||||
gyroData.angVelocityY = angularVelocityY;
|
||||
gyroData.angVelocityZ = angularVelocityZ;
|
||||
}
|
||||
|
||||
|
||||
The guard class will commit the changed data on destruction automatically.
|
||||
|
||||
Using the local data pools in a ``ExtendedControllerBase`` subclass
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Coming soon
|
||||
|
||||
|
35
docs/make.bat
Normal file
35
docs/make.bat
Normal file
@@ -0,0 +1,35 @@
|
||||
@ECHO OFF
|
||||
|
||||
pushd %~dp0
|
||||
|
||||
REM Command file for Sphinx documentation
|
||||
|
||||
if "%SPHINXBUILD%" == "" (
|
||||
set SPHINXBUILD=sphinx-build
|
||||
)
|
||||
set SOURCEDIR=.
|
||||
set BUILDDIR=_build
|
||||
|
||||
if "%1" == "" goto help
|
||||
|
||||
%SPHINXBUILD% >NUL 2>NUL
|
||||
if errorlevel 9009 (
|
||||
echo.
|
||||
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
|
||||
echo.installed, then set the SPHINXBUILD environment variable to point
|
||||
echo.to the full path of the 'sphinx-build' executable. Alternatively you
|
||||
echo.may add the Sphinx directory to PATH.
|
||||
echo.
|
||||
echo.If you don't have Sphinx installed, grab it from
|
||||
echo.http://sphinx-doc.org/
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
|
||||
goto end
|
||||
|
||||
:help
|
||||
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
|
||||
|
||||
:end
|
||||
popd
|
63
docs/osal.rst
Normal file
63
docs/osal.rst
Normal file
@@ -0,0 +1,63 @@
|
||||
.. _osal:
|
||||
|
||||
Operating System Abstraction Layer (OSAL)
|
||||
============================================
|
||||
|
||||
Some specific information on the provided OSALs are provided.
|
||||
|
||||
Linux
|
||||
-------
|
||||
|
||||
This OSAL can be used to compile for Linux host systems like Ubuntu 20.04 or for
|
||||
embedded Linux targets like the Raspberry Pi. This OSAL generally requires threading support
|
||||
and real-time functionalities. For most UNIX systems, this is done by adding ``-lrt`` and
|
||||
``-lpthread`` to the linked libraries in the compilation process. The CMake build support provided
|
||||
will do this automatically for the ``fsfw`` target. It should be noted that most UNIX systems need
|
||||
to be configured specifically to allow the real-time functionalities required by the FSFW.
|
||||
|
||||
Hosted OSAL
|
||||
-------------------
|
||||
|
||||
This is the newest OSAL. Support for Semaphores has not been implemented yet and will propably be
|
||||
implemented as soon as C++20 with Semaphore support has matured. This OSAL can be used to run the
|
||||
FSFW on any host system, but currently has only been tested on Windows 10 and Ubuntu 20.04. Unlike
|
||||
the other OSALs, it uses dynamic memory allocation (e.g. for the message queue implementation).
|
||||
Cross-platform serial port (USB) support might be added soon.
|
||||
|
||||
FreeRTOS OSAL
|
||||
------------------
|
||||
|
||||
FreeRTOS is not included and the developer needs to take care of compiling the FreeRTOS sources and
|
||||
adding the ``FreeRTOSConfig.h`` file location to the include path. This OSAL has only been tested
|
||||
extensively with the pre-emptive scheduler configuration so far but it should in principle also be
|
||||
possible to use a cooperative scheduler. It is recommended to use the `heap_4` allocation scheme.
|
||||
When using newlib (nano), it is also recommended to add ``#define configUSE_NEWLIB_REENTRANT`` to
|
||||
the FreeRTOS configuration file to ensure thread-safety.
|
||||
|
||||
When using this OSAL, developers also need to provide an implementation for the
|
||||
``vRequestContextSwitchFromISR`` function. This has been done because the call to request a context
|
||||
switch from an ISR is generally located in the ``portmacro.h`` header and is different depending on
|
||||
the target architecture or device.
|
||||
|
||||
RTEMS OSAL
|
||||
---------------
|
||||
|
||||
The RTEMS OSAL was the first implemented OSAL which is also used on the active satellite Flying Laptop.
|
||||
|
||||
TCP/IP socket abstraction
|
||||
------------------------------
|
||||
|
||||
The Linux and Host OSAL provide abstraction layers for the socket API. Currently, only UDP sockets
|
||||
have been imlemented. This is very useful to test TMTC handling either on the host computer
|
||||
directly (targeting localhost with a TMTC application) or on embedded Linux devices, sending
|
||||
TMTC packets via Ethernet.
|
||||
|
||||
Example Applications
|
||||
----------------------
|
||||
|
||||
There are example applications available for each OSAL
|
||||
|
||||
- `Hosted OSAL <https://egit.irs.uni-stuttgart.de/fsfw/fsfw-example-hosted>`_
|
||||
- `Linux OSAL for MCUs <https://egit.irs.uni-stuttgart.de/fsfw/fsfw-example-linux-mcu>`_
|
||||
- `FreeRTOS OSAL on the STM32H743ZIT <https://egit.irs.uni-stuttgart.de/fsfw/fsfw-example-stm32h7-freertos>`_
|
||||
- `RTEMS OSAL on the STM32H743ZIT <https://egit.irs.uni-stuttgart.de/fsfw/fsfw-example-stm32h7-rtems>`_
|
2
docs/pus.rst
Normal file
2
docs/pus.rst
Normal file
@@ -0,0 +1,2 @@
|
||||
PUS Services
|
||||
==============
|
@@ -186,7 +186,7 @@ ReturnValue_t MgmRM3100Handler::interpretDeviceReply(DeviceCommandId_t id, const
|
||||
uint8_t cmmValue = packet[1];
|
||||
// We clear the seventh bit in any case
|
||||
// because this one is zero sometimes for some reason
|
||||
bitutil::bitClear(&cmmValue, 6);
|
||||
bitutil::clear(&cmmValue, 6);
|
||||
if(cmmValue == cmmRegValue and internalState == InternalState::READ_CMM) {
|
||||
commandExecuted = true;
|
||||
}
|
||||
|
@@ -4,7 +4,6 @@ endif()
|
||||
|
||||
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||
UnixFileGuard.cpp
|
||||
CommandExecutor.cpp
|
||||
utility.cpp
|
||||
)
|
||||
|
||||
|
@@ -1,210 +0,0 @@
|
||||
#include "CommandExecutor.h"
|
||||
|
||||
#include "fsfw/serviceinterface.h"
|
||||
#include "fsfw/container/SimpleRingBuffer.h"
|
||||
#include "fsfw/container/DynamicFIFO.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
CommandExecutor::CommandExecutor(const size_t maxSize):
|
||||
readVec(maxSize) {
|
||||
waiter.events = POLLIN;
|
||||
}
|
||||
|
||||
ReturnValue_t CommandExecutor::load(std::string command, bool blocking, bool printOutput) {
|
||||
if(state == States::PENDING) {
|
||||
return COMMAND_PENDING;
|
||||
}
|
||||
|
||||
currentCmd = command;
|
||||
this->blocking = blocking;
|
||||
this->printOutput = printOutput;
|
||||
if(state == States::IDLE) {
|
||||
state = States::COMMAND_LOADED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t CommandExecutor::execute() {
|
||||
if(state == States::IDLE) {
|
||||
return NO_COMMAND_LOADED_OR_PENDING;
|
||||
}
|
||||
else if(state == States::PENDING) {
|
||||
return COMMAND_PENDING;
|
||||
}
|
||||
currentCmdFile = popen(currentCmd.c_str(), "r");
|
||||
if(currentCmdFile == nullptr) {
|
||||
lastError = errno;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
if(blocking) {
|
||||
return executeBlocking();
|
||||
}
|
||||
else {
|
||||
currentFd = fileno(currentCmdFile);
|
||||
waiter.fd = currentFd;
|
||||
}
|
||||
state = States::PENDING;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t CommandExecutor::close() {
|
||||
if(state == States::PENDING) {
|
||||
// Attempt to close process, irrespective of if it is running or not
|
||||
if(currentCmdFile != nullptr) {
|
||||
pclose(currentCmdFile);
|
||||
}
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void CommandExecutor::printLastError(std::string funcName) const {
|
||||
if(lastError != 0) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << funcName << " pclose failed with code " << lastError << ": " <<
|
||||
strerror(lastError) << std::endl;
|
||||
#else
|
||||
sif::printError("%s pclose failed with code %d: %s\n",
|
||||
funcName, lastError, strerror(lastError));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void CommandExecutor::setRingBuffer(SimpleRingBuffer *ringBuffer,
|
||||
DynamicFIFO<uint16_t>* sizesFifo) {
|
||||
this->ringBuffer = ringBuffer;
|
||||
this->sizesFifo = sizesFifo;
|
||||
}
|
||||
|
||||
ReturnValue_t CommandExecutor::check(bool& bytesRead) {
|
||||
if(blocking) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
switch(state) {
|
||||
case(States::IDLE):
|
||||
case(States::COMMAND_LOADED): {
|
||||
return NO_COMMAND_LOADED_OR_PENDING;
|
||||
}
|
||||
case(States::PENDING): {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int result = poll(&waiter, 1, 0);
|
||||
switch(result) {
|
||||
case(0): {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
break;
|
||||
}
|
||||
case(1): {
|
||||
if (waiter.revents & POLLIN) {
|
||||
ssize_t readBytes = read(currentFd, readVec.data(), readVec.size());
|
||||
if(readBytes == 0) {
|
||||
// Should not happen
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "CommandExecutor::check: No bytes read "
|
||||
"after poll event.." << std::endl;
|
||||
#else
|
||||
sif::printWarning("CommandExecutor::check: No bytes read after poll event..\n");
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
else if(readBytes > 0) {
|
||||
bytesRead = true;
|
||||
if(printOutput) {
|
||||
// It is assumed the command output is line terminated
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << currentCmd << " | " << readVec.data();
|
||||
#else
|
||||
sif::printInfo("%s | %s", currentCmd, readVec.data());
|
||||
#endif
|
||||
}
|
||||
if(ringBuffer != nullptr) {
|
||||
ringBuffer->writeData(reinterpret_cast<const uint8_t*>(
|
||||
readVec.data()), readBytes);
|
||||
}
|
||||
if(sizesFifo != nullptr) {
|
||||
if(not sizesFifo->full()) {
|
||||
sizesFifo->insert(readBytes);
|
||||
}
|
||||
}
|
||||
return BYTES_READ;
|
||||
}
|
||||
else {
|
||||
// Should also not happen
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "CommandExecutor::check: Error " << errno << ": " <<
|
||||
strerror(errno) << std::endl;
|
||||
#else
|
||||
sif::printWarning("CommandExecutor::check: Error %d: %s\n", errno, strerror(errno));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if(waiter.revents & POLLERR) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "CommandExecuter::check: Poll error" << std::endl;
|
||||
#else
|
||||
sif::printWarning("CommandExecuter::check: Poll error\n");
|
||||
#endif
|
||||
return COMMAND_ERROR;
|
||||
}
|
||||
else if(waiter.revents & POLLHUP) {
|
||||
int result = pclose(currentCmdFile);
|
||||
if(result != 0) {
|
||||
lastError = result;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
state = States::IDLE;
|
||||
currentCmdFile = nullptr;
|
||||
currentFd = 0;
|
||||
return EXECUTION_FINISHED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void CommandExecutor::reset() {
|
||||
CommandExecutor::close();
|
||||
currentCmdFile = nullptr;
|
||||
currentFd = 0;
|
||||
state = States::IDLE;
|
||||
}
|
||||
|
||||
int CommandExecutor::getLastError() const {
|
||||
return this->lastError;
|
||||
}
|
||||
|
||||
CommandExecutor::States CommandExecutor::getCurrentState() const {
|
||||
return state;
|
||||
}
|
||||
|
||||
ReturnValue_t CommandExecutor::executeBlocking() {
|
||||
while(fgets(readVec.data(), readVec.size(), currentCmdFile) != nullptr) {
|
||||
std::string output(readVec.data());
|
||||
if(printOutput) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << currentCmd << " | " << output;
|
||||
#else
|
||||
sif::printInfo("%s | %s", currentCmd, output);
|
||||
#endif
|
||||
}
|
||||
if(ringBuffer != nullptr) {
|
||||
ringBuffer->writeData(reinterpret_cast<const uint8_t*>(output.data()), output.size());
|
||||
}
|
||||
if(sizesFifo != nullptr) {
|
||||
if(not sizesFifo->full()) {
|
||||
sizesFifo->insert(output.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
int result = pclose(currentCmdFile);
|
||||
if(result != 0) {
|
||||
lastError = result;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
@@ -1,134 +0,0 @@
|
||||
#ifndef FSFW_SRC_FSFW_OSAL_LINUX_COMMANDEXECUTOR_H_
|
||||
#define FSFW_SRC_FSFW_OSAL_LINUX_COMMANDEXECUTOR_H_
|
||||
|
||||
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||
#include "fsfw/returnvalues/FwClassIds.h"
|
||||
|
||||
#include <poll.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class SimpleRingBuffer;
|
||||
template <typename T> class DynamicFIFO;
|
||||
|
||||
/**
|
||||
* @brief Helper class to execute shell commands in blocking and non-blocking mode
|
||||
* @details
|
||||
* This class is able to execute processes by using the Linux popen call. It also has the
|
||||
* capability of writing the read output of a process into a provided ring buffer.
|
||||
*
|
||||
* The executor works by first loading the command which should be executed and specifying
|
||||
* whether it should be executed blocking or non-blocking. After that, execution can be started
|
||||
* with the execute command. In blocking mode, the execute command will block until the command
|
||||
* has finished
|
||||
*/
|
||||
class CommandExecutor {
|
||||
public:
|
||||
enum class States {
|
||||
IDLE,
|
||||
COMMAND_LOADED,
|
||||
PENDING
|
||||
};
|
||||
|
||||
static constexpr uint8_t CLASS_ID = CLASS_ID::LINUX_OSAL;
|
||||
|
||||
//! [EXPORT] : [COMMENT] Execution of the current command has finished
|
||||
static constexpr ReturnValue_t EXECUTION_FINISHED =
|
||||
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 0);
|
||||
|
||||
//! [EXPORT] : [COMMENT] Command is pending. This will also be returned if the user tries
|
||||
//! to load another command but a command is still pending
|
||||
static constexpr ReturnValue_t COMMAND_PENDING =
|
||||
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 1);
|
||||
//! [EXPORT] : [COMMENT] Some bytes have been read from the executing process
|
||||
static constexpr ReturnValue_t BYTES_READ =
|
||||
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 2);
|
||||
//! [EXPORT] : [COMMENT] Command execution failed
|
||||
static constexpr ReturnValue_t COMMAND_ERROR =
|
||||
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 3);
|
||||
//! [EXPORT] : [COMMENT]
|
||||
static constexpr ReturnValue_t NO_COMMAND_LOADED_OR_PENDING =
|
||||
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 4);
|
||||
static constexpr ReturnValue_t PCLOSE_CALL_ERROR =
|
||||
HasReturnvaluesIF::makeReturnCode(CLASS_ID, 6);
|
||||
|
||||
/**
|
||||
* Constructor. Is initialized with maximum size of internal buffer to read data from the
|
||||
* executed process.
|
||||
* @param maxSize
|
||||
*/
|
||||
CommandExecutor(const size_t maxSize);
|
||||
|
||||
/**
|
||||
* Load a new command which should be executed
|
||||
* @param command
|
||||
* @param blocking
|
||||
* @param printOutput
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t load(std::string command, bool blocking, bool printOutput = true);
|
||||
/**
|
||||
* Execute the loaded command.
|
||||
* @return
|
||||
* - In blocking mode, it will return RETURN_FAILED if
|
||||
* the result of the system call was not 0. The error value can be accessed using
|
||||
* getLastError
|
||||
* - In non-blocking mode, this call will start
|
||||
* the execution and then return RETURN_OK
|
||||
*/
|
||||
ReturnValue_t execute();
|
||||
/**
|
||||
* Only used in non-blocking mode. Checks the currently running command.
|
||||
* @param bytesRead Will be set to the number of bytes read, if bytes have been read
|
||||
* @return
|
||||
* - BYTES_READ if bytes have been read from the executing process. It is recommended to call
|
||||
* check again after this
|
||||
* - RETURN_OK execution is pending, but no bytes have been read from the executing process
|
||||
* - RETURN_FAILED if execution has failed, error value can be accessed using getLastError
|
||||
* - EXECUTION_FINISHED if the process was executed successfully
|
||||
* - COMMAND_ERROR internal poll error
|
||||
*/
|
||||
ReturnValue_t check(bool& bytesRead);
|
||||
/**
|
||||
* Abort the current command. Should normally not be necessary, check can be used to find
|
||||
* out whether command execution was successful
|
||||
* @return RETURN_OK
|
||||
*/
|
||||
ReturnValue_t close();
|
||||
|
||||
States getCurrentState() const;
|
||||
int getLastError() const;
|
||||
void printLastError(std::string funcName) const;
|
||||
|
||||
/**
|
||||
* Assign a ring buffer and a FIFO which will be filled by the executor with the output
|
||||
* read from the started process
|
||||
* @param ringBuffer
|
||||
* @param sizesFifo
|
||||
*/
|
||||
void setRingBuffer(SimpleRingBuffer* ringBuffer, DynamicFIFO<uint16_t>* sizesFifo);
|
||||
|
||||
/**
|
||||
* Reset the executor. This calls close internally and then reset the state machine so new
|
||||
* commands can be loaded and executed
|
||||
*/
|
||||
void reset();
|
||||
private:
|
||||
std::string currentCmd;
|
||||
bool blocking = true;
|
||||
FILE* currentCmdFile = nullptr;
|
||||
int currentFd = 0;
|
||||
bool printOutput = true;
|
||||
std::vector<char> readVec;
|
||||
struct pollfd waiter {};
|
||||
SimpleRingBuffer* ringBuffer = nullptr;
|
||||
DynamicFIFO<uint16_t>* sizesFifo = nullptr;
|
||||
|
||||
States state = States::IDLE;
|
||||
int lastError = 0;
|
||||
|
||||
ReturnValue_t executeBlocking();
|
||||
};
|
||||
|
||||
#endif /* FSFW_SRC_FSFW_OSAL_LINUX_COMMANDEXECUTOR_H_ */
|
25
hal/src/fsfw_hal/stm32h7/definitions.h
Normal file
25
hal/src/fsfw_hal/stm32h7/definitions.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef FSFW_HAL_STM32H7_DEFINITIONS_H_
|
||||
#define FSFW_HAL_STM32H7_DEFINITIONS_H_
|
||||
|
||||
#include <utility>
|
||||
#include "stm32h7xx.h"
|
||||
|
||||
namespace stm32h7 {
|
||||
|
||||
/**
|
||||
* Typedef for STM32 GPIO pair where the first entry is the port used (e.g. GPIOA)
|
||||
* and the second entry is the pin number
|
||||
*/
|
||||
struct GpioCfg {
|
||||
GpioCfg(): port(nullptr), pin(0), altFnc(0) {};
|
||||
|
||||
GpioCfg(GPIO_TypeDef* port, uint16_t pin, uint8_t altFnc = 0):
|
||||
port(port), pin(pin), altFnc(altFnc) {};
|
||||
GPIO_TypeDef* port;
|
||||
uint16_t pin;
|
||||
uint8_t altFnc;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* #ifndef FSFW_HAL_STM32H7_DEFINITIONS_H_ */
|
@@ -4,7 +4,7 @@
|
||||
#include "fsfw_hal/stm32h7/spi/spiDefinitions.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
|
||||
#include "fsfw_hal/stm32h7/spi/stm32h743ziSpi.h"
|
||||
#include "fsfw_hal/stm32h7/spi/stm32h743zi.h"
|
||||
|
||||
#include "fsfw/tasks/TaskFactory.h"
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
@@ -33,20 +33,20 @@ GyroL3GD20H::GyroL3GD20H(SPI_HandleTypeDef *spiHandle, spi::TransferModes transf
|
||||
mspCfg = new spi::MspDmaConfigStruct();
|
||||
auto typedCfg = dynamic_cast<spi::MspDmaConfigStruct*>(mspCfg);
|
||||
spi::setDmaHandles(txDmaHandle, rxDmaHandle);
|
||||
spi::h743zi::standardDmaCfg(*typedCfg, IrqPriorities::HIGHEST_FREERTOS,
|
||||
stm32h7::h743zi::standardDmaCfg(*typedCfg, IrqPriorities::HIGHEST_FREERTOS,
|
||||
IrqPriorities::HIGHEST_FREERTOS, IrqPriorities::HIGHEST_FREERTOS);
|
||||
spi::setSpiDmaMspFunctions(typedCfg);
|
||||
}
|
||||
else if(transferMode == spi::TransferModes::INTERRUPT) {
|
||||
mspCfg = new spi::MspIrqConfigStruct();
|
||||
auto typedCfg = dynamic_cast<spi::MspIrqConfigStruct*>(mspCfg);
|
||||
spi::h743zi::standardInterruptCfg(*typedCfg, IrqPriorities::HIGHEST_FREERTOS);
|
||||
stm32h7::h743zi::standardInterruptCfg(*typedCfg, IrqPriorities::HIGHEST_FREERTOS);
|
||||
spi::setSpiIrqMspFunctions(typedCfg);
|
||||
}
|
||||
else if(transferMode == spi::TransferModes::POLLING) {
|
||||
mspCfg = new spi::MspPollingConfigStruct();
|
||||
auto typedCfg = dynamic_cast<spi::MspPollingConfigStruct*>(mspCfg);
|
||||
spi::h743zi::standardPollingCfg(*typedCfg);
|
||||
stm32h7::h743zi::standardPollingCfg(*typedCfg);
|
||||
spi::setSpiPollingMspFunctions(typedCfg);
|
||||
}
|
||||
|
||||
|
@@ -5,5 +5,5 @@ target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||
mspInit.cpp
|
||||
SpiCookie.cpp
|
||||
SpiComIF.cpp
|
||||
stm32h743ziSpi.cpp
|
||||
stm32h743zi.cpp
|
||||
)
|
||||
|
@@ -138,12 +138,14 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) {
|
||||
spi::setSpiDmaMspFunctions(typedCfg);
|
||||
}
|
||||
|
||||
gpio::initializeGpioClock(gpioPort);
|
||||
GPIO_InitTypeDef chipSelect = {};
|
||||
chipSelect.Pin = gpioPin;
|
||||
chipSelect.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
HAL_GPIO_Init(gpioPort, &chipSelect);
|
||||
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_SET);
|
||||
if(gpioPort != nullptr) {
|
||||
gpio::initializeGpioClock(gpioPort);
|
||||
GPIO_InitTypeDef chipSelect = {};
|
||||
chipSelect.Pin = gpioPin;
|
||||
chipSelect.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
HAL_GPIO_Init(gpioPort, &chipSelect);
|
||||
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
if(HAL_SPI_Init(&spiHandle) != HAL_OK) {
|
||||
sif::printWarning("SpiComIF::initialize: Error initializing SPI\n");
|
||||
@@ -259,10 +261,15 @@ ReturnValue_t SpiComIF::handlePollingSendOperation(uint8_t* recvPtr, SPI_HandleT
|
||||
return returnval;
|
||||
}
|
||||
spiCookie.setTransferState(spi::TransferStates::WAIT);
|
||||
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_RESET);
|
||||
if(gpioPort != nullptr) {
|
||||
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
auto result = HAL_SPI_TransmitReceive(&spiHandle, const_cast<uint8_t*>(sendData),
|
||||
recvPtr, sendLen, defaultPollingTimeout);
|
||||
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_SET);
|
||||
if(gpioPort != nullptr) {
|
||||
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_SET);
|
||||
}
|
||||
spiSemaphore->release();
|
||||
switch(result) {
|
||||
case(HAL_OK): {
|
||||
@@ -392,8 +399,10 @@ ReturnValue_t SpiComIF::genericIrqSendSetup(uint8_t *recvPtr, SPI_HandleTypeDef&
|
||||
// The SPI handle is passed to the default SPI callback as a void argument. This callback
|
||||
// is different from the user callbacks specified above!
|
||||
spi::assignSpiUserArgs(spiCookie.getSpiIdx(), reinterpret_cast<void*>(&spiHandle));
|
||||
HAL_GPIO_WritePin(spiCookie.getChipSelectGpioPort(), spiCookie.getChipSelectGpioPin(),
|
||||
GPIO_PIN_RESET);
|
||||
if(spiCookie.getChipSelectGpioPort() != nullptr) {
|
||||
HAL_GPIO_WritePin(spiCookie.getChipSelectGpioPort(), spiCookie.getChipSelectGpioPin(),
|
||||
GPIO_PIN_RESET);
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
@@ -426,9 +435,12 @@ void SpiComIF::genericIrqHandler(void *irqArgsVoid, spi::TransferStates targetSt
|
||||
|
||||
spiCookie->setTransferState(targetState);
|
||||
|
||||
// Pull CS pin high again
|
||||
HAL_GPIO_WritePin(spiCookie->getChipSelectGpioPort(), spiCookie->getChipSelectGpioPin(),
|
||||
GPIO_PIN_SET);
|
||||
if(spiCookie->getChipSelectGpioPort() != nullptr) {
|
||||
// Pull CS pin high again
|
||||
HAL_GPIO_WritePin(spiCookie->getChipSelectGpioPort(), spiCookie->getChipSelectGpioPin(),
|
||||
GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
|
||||
#if defined FSFW_OSAL_FREERTOS
|
||||
// Release the task semaphore
|
||||
|
@@ -60,7 +60,6 @@ public:
|
||||
void addDmaHandles(DMA_HandleTypeDef* txHandle, DMA_HandleTypeDef* rxHandle);
|
||||
|
||||
ReturnValue_t initialize() override;
|
||||
protected:
|
||||
|
||||
// DeviceCommunicationIF overrides
|
||||
virtual ReturnValue_t initializeInterface(CookieIF * cookie) override;
|
||||
@@ -72,7 +71,7 @@ protected:
|
||||
virtual ReturnValue_t readReceivedMessage(CookieIF *cookie,
|
||||
uint8_t **buffer, size_t *size) override;
|
||||
|
||||
private:
|
||||
protected:
|
||||
|
||||
struct SpiInstance {
|
||||
SpiInstance(size_t maxRecvSize): replyBuffer(std::vector<uint8_t>(maxRecvSize)) {}
|
||||
|
@@ -3,10 +3,10 @@
|
||||
|
||||
SpiCookie::SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferModes transferMode,
|
||||
spi::MspCfgBase* mspCfg, uint32_t spiSpeed, spi::SpiModes spiMode,
|
||||
uint16_t chipSelectGpioPin, GPIO_TypeDef* chipSelectGpioPort, size_t maxRecvSize):
|
||||
size_t maxRecvSize, stm32h7::GpioCfg csGpio):
|
||||
deviceAddress(deviceAddress), spiIdx(spiIdx), spiSpeed(spiSpeed), spiMode(spiMode),
|
||||
transferMode(transferMode), chipSelectGpioPin(chipSelectGpioPin),
|
||||
chipSelectGpioPort(chipSelectGpioPort), mspCfg(mspCfg), maxRecvSize(maxRecvSize) {
|
||||
transferMode(transferMode), csGpio(csGpio),
|
||||
mspCfg(mspCfg), maxRecvSize(maxRecvSize) {
|
||||
spiHandle.Init.DataSize = SPI_DATASIZE_8BIT;
|
||||
spiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||
spiHandle.Init.TIMode = SPI_TIMODE_DISABLE;
|
||||
@@ -24,11 +24,11 @@ SpiCookie::SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferM
|
||||
}
|
||||
|
||||
uint16_t SpiCookie::getChipSelectGpioPin() const {
|
||||
return chipSelectGpioPin;
|
||||
return csGpio.pin;
|
||||
}
|
||||
|
||||
GPIO_TypeDef* SpiCookie::getChipSelectGpioPort() {
|
||||
return chipSelectGpioPort;
|
||||
return csGpio.port;
|
||||
}
|
||||
|
||||
address_t SpiCookie::getDeviceAddress() const {
|
||||
|
@@ -3,11 +3,14 @@
|
||||
|
||||
#include "spiDefinitions.h"
|
||||
#include "mspInit.h"
|
||||
#include "../definitions.h"
|
||||
|
||||
#include "fsfw/devicehandlers/CookieIF.h"
|
||||
|
||||
#include "stm32h743xx.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
/**
|
||||
* @brief SPI cookie implementation for the STM32H7 device family
|
||||
* @details
|
||||
@@ -18,6 +21,7 @@
|
||||
class SpiCookie: public CookieIF {
|
||||
friend class SpiComIF;
|
||||
public:
|
||||
|
||||
/**
|
||||
* Allows construction of a SPI cookie for a connected SPI device
|
||||
* @param deviceAddress
|
||||
@@ -32,10 +36,11 @@ public:
|
||||
* definitions supplied in the MCU header file! (e.g. GPIO_PIN_X)
|
||||
* @param chipSelectGpioPort GPIO port (e.g. GPIOA)
|
||||
* @param maxRecvSize Maximum expected receive size. Chose as small as possible.
|
||||
* @param csGpio Optional CS GPIO definition.
|
||||
*/
|
||||
SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, spi::TransferModes transferMode,
|
||||
spi::MspCfgBase* mspCfg, uint32_t spiSpeed, spi::SpiModes spiMode,
|
||||
uint16_t chipSelectGpioPin, GPIO_TypeDef* chipSelectGpioPort, size_t maxRecvSize);
|
||||
size_t maxRecvSize, stm32h7::GpioCfg csGpio = stm32h7::GpioCfg(nullptr, 0, 0));
|
||||
|
||||
uint16_t getChipSelectGpioPin() const;
|
||||
GPIO_TypeDef* getChipSelectGpioPort();
|
||||
@@ -55,8 +60,8 @@ private:
|
||||
spi::SpiModes spiMode;
|
||||
spi::TransferModes transferMode;
|
||||
volatile spi::TransferStates transferState = spi::TransferStates::IDLE;
|
||||
uint16_t chipSelectGpioPin;
|
||||
GPIO_TypeDef* chipSelectGpioPort;
|
||||
stm32h7::GpioCfg csGpio;
|
||||
|
||||
// The MSP configuration is cached here. Be careful when using this, it is automatically
|
||||
// deleted by the SPI communication interface if it is not required anymore!
|
||||
spi::MspCfgBase* mspCfg = nullptr;
|
||||
|
@@ -118,40 +118,40 @@ void spi::halMspInitPolling(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {};
|
||||
/*##-1- Enable peripherals and GPIO Clocks #################################*/
|
||||
/* Enable GPIO TX/RX clock */
|
||||
cfg->setupMacroWrapper();
|
||||
cfg->setupCb();
|
||||
|
||||
/*##-2- Configure peripheral GPIO ##########################################*/
|
||||
/* SPI SCK GPIO pin configuration */
|
||||
GPIO_InitStruct.Pin = cfg->sckPin;
|
||||
GPIO_InitStruct.Pin = cfg->sck.pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
GPIO_InitStruct.Alternate = cfg->sckAlternateFunction;
|
||||
HAL_GPIO_Init(cfg->sckPort, &GPIO_InitStruct);
|
||||
GPIO_InitStruct.Alternate = cfg->sck.altFnc;
|
||||
HAL_GPIO_Init(cfg->sck.port, &GPIO_InitStruct);
|
||||
|
||||
/* SPI MISO GPIO pin configuration */
|
||||
GPIO_InitStruct.Pin = cfg->misoPin;
|
||||
GPIO_InitStruct.Alternate = cfg->misoAlternateFunction;
|
||||
HAL_GPIO_Init(cfg->misoPort, &GPIO_InitStruct);
|
||||
GPIO_InitStruct.Pin = cfg->miso.pin;
|
||||
GPIO_InitStruct.Alternate = cfg->miso.altFnc;
|
||||
HAL_GPIO_Init(cfg->miso.port, &GPIO_InitStruct);
|
||||
|
||||
/* SPI MOSI GPIO pin configuration */
|
||||
GPIO_InitStruct.Pin = cfg->mosiPin;
|
||||
GPIO_InitStruct.Alternate = cfg->mosiAlternateFunction;
|
||||
HAL_GPIO_Init(cfg->mosiPort, &GPIO_InitStruct);
|
||||
GPIO_InitStruct.Pin = cfg->mosi.pin;
|
||||
GPIO_InitStruct.Alternate = cfg->mosi.altFnc;
|
||||
HAL_GPIO_Init(cfg->mosi.port, &GPIO_InitStruct);
|
||||
}
|
||||
|
||||
void spi::halMspDeinitPolling(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
|
||||
auto cfg = reinterpret_cast<MspPollingConfigStruct*>(cfgBase);
|
||||
// Reset peripherals
|
||||
cfg->cleanUpMacroWrapper();
|
||||
cfg->cleanupCb();
|
||||
|
||||
// Disable peripherals and GPIO Clocks
|
||||
/* Configure SPI SCK as alternate function */
|
||||
HAL_GPIO_DeInit(cfg->sckPort, cfg->sckPin);
|
||||
HAL_GPIO_DeInit(cfg->sck.port, cfg->sck.pin);
|
||||
/* Configure SPI MISO as alternate function */
|
||||
HAL_GPIO_DeInit(cfg->misoPort, cfg->misoPin);
|
||||
HAL_GPIO_DeInit(cfg->miso.port, cfg->miso.pin);
|
||||
/* Configure SPI MOSI as alternate function */
|
||||
HAL_GPIO_DeInit(cfg->mosiPort, cfg->mosiPin);
|
||||
HAL_GPIO_DeInit(cfg->mosi.port, cfg->mosi.pin);
|
||||
}
|
||||
|
||||
void spi::halMspInitInterrupt(SPI_HandleTypeDef* hspi, MspCfgBase* cfgBase) {
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#define FSFW_HAL_STM32H7_SPI_MSPINIT_H_
|
||||
|
||||
#include "spiDefinitions.h"
|
||||
#include "../definitions.h"
|
||||
#include "../dma.h"
|
||||
|
||||
#include "stm32h7xx_hal_spi.h"
|
||||
@@ -12,6 +13,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
using mspCb = void (*) (void);
|
||||
|
||||
/**
|
||||
* @brief This file provides MSP implementation for DMA, IRQ and Polling mode for the
|
||||
* SPI peripheral. This configuration is required for the SPI communication to work.
|
||||
@@ -19,27 +22,37 @@ extern "C" {
|
||||
namespace spi {
|
||||
|
||||
struct MspCfgBase {
|
||||
MspCfgBase();
|
||||
MspCfgBase(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso,
|
||||
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr):
|
||||
sck(sck), mosi(mosi), miso(miso), cleanupCb(cleanupCb),
|
||||
setupCb(setupCb) {}
|
||||
|
||||
virtual ~MspCfgBase() = default;
|
||||
|
||||
void (* cleanUpMacroWrapper) (void) = nullptr;
|
||||
void (* setupMacroWrapper) (void) = nullptr;
|
||||
stm32h7::GpioCfg sck;
|
||||
stm32h7::GpioCfg mosi;
|
||||
stm32h7::GpioCfg miso;
|
||||
|
||||
GPIO_TypeDef* sckPort = nullptr;
|
||||
uint32_t sckPin = 0;
|
||||
uint8_t sckAlternateFunction = 0;
|
||||
GPIO_TypeDef* mosiPort = nullptr;
|
||||
uint32_t mosiPin = 0;
|
||||
uint8_t mosiAlternateFunction = 0;
|
||||
GPIO_TypeDef* misoPort = nullptr;
|
||||
uint32_t misoPin = 0;
|
||||
uint8_t misoAlternateFunction = 0;
|
||||
mspCb cleanupCb = nullptr;
|
||||
mspCb setupCb = nullptr;
|
||||
};
|
||||
|
||||
struct MspPollingConfigStruct: public MspCfgBase {};
|
||||
struct MspPollingConfigStruct: public MspCfgBase {
|
||||
MspPollingConfigStruct(): MspCfgBase() {};
|
||||
MspPollingConfigStruct(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso,
|
||||
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr):
|
||||
MspCfgBase(sck, mosi, miso, cleanupCb, setupCb) {}
|
||||
};
|
||||
|
||||
/* A valid instance of this struct must be passed to the MSP initialization function as a void*
|
||||
argument */
|
||||
struct MspIrqConfigStruct: public MspPollingConfigStruct {
|
||||
MspIrqConfigStruct(): MspPollingConfigStruct() {};
|
||||
MspIrqConfigStruct(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso,
|
||||
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr):
|
||||
MspPollingConfigStruct(sck, mosi, miso, cleanupCb, setupCb) {}
|
||||
|
||||
SpiBus spiBus = SpiBus::SPI_1;
|
||||
user_handler_t spiIrqHandler = nullptr;
|
||||
user_args_t spiUserArgs = nullptr;
|
||||
@@ -53,11 +66,16 @@ struct MspIrqConfigStruct: public MspPollingConfigStruct {
|
||||
/* A valid instance of this struct must be passed to the MSP initialization function as a void*
|
||||
argument */
|
||||
struct MspDmaConfigStruct: public MspIrqConfigStruct {
|
||||
MspDmaConfigStruct(): MspIrqConfigStruct() {};
|
||||
MspDmaConfigStruct(stm32h7::GpioCfg sck, stm32h7::GpioCfg mosi, stm32h7::GpioCfg miso,
|
||||
mspCb cleanupCb = nullptr, mspCb setupCb = nullptr):
|
||||
MspIrqConfigStruct(sck, mosi, miso, cleanupCb, setupCb) {}
|
||||
void (* dmaClkEnableWrapper) (void) = nullptr;
|
||||
dma::DMAIndexes txDmaIndex;
|
||||
dma::DMAIndexes rxDmaIndex;
|
||||
dma::DMAStreams txDmaStream;
|
||||
dma::DMAStreams rxDmaStream;
|
||||
|
||||
dma::DMAIndexes txDmaIndex = dma::DMAIndexes::DMA_1;
|
||||
dma::DMAIndexes rxDmaIndex = dma::DMAIndexes::DMA_1;
|
||||
dma::DMAStreams txDmaStream = dma::DMAStreams::STREAM_0;
|
||||
dma::DMAStreams rxDmaStream = dma::DMAStreams::STREAM_0;
|
||||
IRQn_Type txDmaIrqNumber = DMA1_Stream0_IRQn;
|
||||
IRQn_Type rxDmaIrqNumber = DMA1_Stream1_IRQn;
|
||||
// Priorities for NVIC
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#include "fsfw_hal/stm32h7/spi/stm32h743ziSpi.h"
|
||||
#include "fsfw_hal/stm32h7/spi/stm32h743zi.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiCore.h"
|
||||
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
|
||||
|
||||
@@ -22,27 +22,27 @@ void spiDmaClockEnableWrapper() {
|
||||
__HAL_RCC_DMA2_CLK_ENABLE();
|
||||
}
|
||||
|
||||
void spi::h743zi::standardPollingCfg(MspPollingConfigStruct& cfg) {
|
||||
cfg.setupMacroWrapper = &spiSetupWrapper;
|
||||
cfg.cleanUpMacroWrapper = &spiCleanUpWrapper;
|
||||
cfg.sckPort = GPIOA;
|
||||
cfg.sckPin = GPIO_PIN_5;
|
||||
cfg.misoPort = GPIOA;
|
||||
cfg.misoPin = GPIO_PIN_6;
|
||||
cfg.mosiPort = GPIOA;
|
||||
cfg.mosiPin = GPIO_PIN_7;
|
||||
cfg.sckAlternateFunction = GPIO_AF5_SPI1;
|
||||
cfg.mosiAlternateFunction = GPIO_AF5_SPI1;
|
||||
cfg.misoAlternateFunction = GPIO_AF5_SPI1;
|
||||
void stm32h7::h743zi::standardPollingCfg(spi::MspPollingConfigStruct& cfg) {
|
||||
cfg.setupCb = &spiSetupWrapper;
|
||||
cfg.cleanupCb = &spiCleanUpWrapper;
|
||||
cfg.sck.port = GPIOA;
|
||||
cfg.sck.pin = GPIO_PIN_5;
|
||||
cfg.miso.port = GPIOA;
|
||||
cfg.miso.pin = GPIO_PIN_6;
|
||||
cfg.mosi.port = GPIOA;
|
||||
cfg.mosi.pin = GPIO_PIN_7;
|
||||
cfg.sck.altFnc = GPIO_AF5_SPI1;
|
||||
cfg.mosi.altFnc = GPIO_AF5_SPI1;
|
||||
cfg.miso.altFnc = GPIO_AF5_SPI1;
|
||||
}
|
||||
|
||||
void spi::h743zi::standardInterruptCfg(MspIrqConfigStruct& cfg, IrqPriorities spiIrqPrio,
|
||||
void stm32h7::h743zi::standardInterruptCfg(spi::MspIrqConfigStruct& cfg, IrqPriorities spiIrqPrio,
|
||||
IrqPriorities spiSubprio) {
|
||||
// High, but works on FreeRTOS as well (priorities range from 0 to 15)
|
||||
cfg.preEmptPriority = spiIrqPrio;
|
||||
cfg.subpriority = spiSubprio;
|
||||
cfg.spiIrqNumber = SPI1_IRQn;
|
||||
cfg.spiBus = SpiBus::SPI_1;
|
||||
cfg.spiBus = spi::SpiBus::SPI_1;
|
||||
user_handler_t spiUserHandler = nullptr;
|
||||
user_args_t spiUserArgs = nullptr;
|
||||
getSpiUserHandler(spi::SpiBus::SPI_1, &spiUserHandler, &spiUserArgs);
|
||||
@@ -55,7 +55,7 @@ void spi::h743zi::standardInterruptCfg(MspIrqConfigStruct& cfg, IrqPriorities sp
|
||||
standardPollingCfg(cfg);
|
||||
}
|
||||
|
||||
void spi::h743zi::standardDmaCfg(MspDmaConfigStruct& cfg, IrqPriorities spiIrqPrio,
|
||||
void stm32h7::h743zi::standardDmaCfg(spi::MspDmaConfigStruct& cfg, IrqPriorities spiIrqPrio,
|
||||
IrqPriorities txIrqPrio, IrqPriorities rxIrqPrio, IrqPriorities spiSubprio,
|
||||
IrqPriorities txSubprio, IrqPriorities rxSubprio) {
|
||||
cfg.dmaClkEnableWrapper = &spiDmaClockEnableWrapper;
|
@@ -3,21 +3,20 @@
|
||||
|
||||
#include "mspInit.h"
|
||||
|
||||
namespace spi {
|
||||
namespace stm32h7 {
|
||||
|
||||
namespace h743zi {
|
||||
|
||||
void standardPollingCfg(MspPollingConfigStruct& cfg);
|
||||
void standardInterruptCfg(MspIrqConfigStruct& cfg, IrqPriorities spiIrqPrio,
|
||||
void standardPollingCfg(spi::MspPollingConfigStruct& cfg);
|
||||
void standardInterruptCfg(spi::MspIrqConfigStruct& cfg, IrqPriorities spiIrqPrio,
|
||||
IrqPriorities spiSubprio = HIGHEST);
|
||||
void standardDmaCfg(MspDmaConfigStruct& cfg, IrqPriorities spiIrqPrio,
|
||||
void standardDmaCfg(spi::MspDmaConfigStruct& cfg, IrqPriorities spiIrqPrio,
|
||||
IrqPriorities txIrqPrio, IrqPriorities rxIrqPrio,
|
||||
IrqPriorities spiSubprio = HIGHEST, IrqPriorities txSubPrio = HIGHEST,
|
||||
IrqPriorities rxSubprio = HIGHEST);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* FSFW_HAL_STM32H7_SPI_STM32H743ZISPI_H_ */
|
@@ -1,23 +1,49 @@
|
||||
target_include_directories(${TARGET_NAME} PRIVATE
|
||||
if(DEFINED TARGET_NAME)
|
||||
target_include_directories(${TARGET_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
ipc/missionMessageTypes.cpp
|
||||
pollingsequence/PollingSequenceFactory.cpp
|
||||
objects/FsfwFactory.cpp
|
||||
)
|
||||
|
||||
# If a special translation file for object IDs exists, compile it.
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/objects/translateObjects.cpp")
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
objects/translateObjects.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
# If a special translation file for events exists, compile it.
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/objects/translateObjects.cpp")
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
events/translateEvents.cpp
|
||||
ipc/missionMessageTypes.cpp
|
||||
pollingsequence/PollingSequenceFactory.cpp
|
||||
objects/FsfwFactory.cpp
|
||||
)
|
||||
|
||||
# If a special translation file for object IDs exists, compile it.
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/objects/translateObjects.cpp")
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
objects/translateObjects.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
# If a special translation file for events exists, compile it.
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/objects/translateObjects.cpp")
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
events/translateEvents.cpp
|
||||
)
|
||||
endif()
|
||||
else()
|
||||
target_include_directories(${LIB_FSFW_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||
ipc/missionMessageTypes.cpp
|
||||
pollingsequence/PollingSequenceFactory.cpp
|
||||
objects/FsfwFactory.cpp
|
||||
)
|
||||
|
||||
# If a special translation file for object IDs exists, compile it.
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/objects/translateObjects.cpp")
|
||||
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||
objects/translateObjects.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
# If a special translation file for events exists, compile it.
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/objects/translateObjects.cpp")
|
||||
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||
events/translateEvents.cpp
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
@@ -7,7 +7,7 @@
|
||||
#include <fsfw/tmtcpacket/pus/tm/TmPacketStored.h>
|
||||
#include <fsfw/tmtcservices/CommandingServiceBase.h>
|
||||
#include <fsfw/tmtcservices/PusServiceBase.h>
|
||||
#include <fsfw/internalError/InternalErrorReporter.h>
|
||||
#include <fsfw/internalerror/InternalErrorReporter.h>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -48,6 +48,6 @@ void Factory::setStaticFrameworkObjectIds() {
|
||||
|
||||
DeviceHandlerFailureIsolation::powerConfirmationId = objects::NO_OBJECT;
|
||||
|
||||
TmPacketStored::timeStamperId = objects::NO_OBJECT;
|
||||
TmPacketBase::timeStamperId = objects::NO_OBJECT;
|
||||
}
|
||||
|
||||
|
8
scripts/apply-clang-format.sh
Executable file
8
scripts/apply-clang-format.sh
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
if [[ ! -f README.md ]]; then
|
||||
cd ..
|
||||
fi
|
||||
|
||||
find ./src -iname *.h -o -iname *.cpp -o -iname *.c | xargs clang-format --style=file -i
|
||||
find ./hal -iname *.h -o -iname *.cpp -o -iname *.c | xargs clang-format --style=file -i
|
||||
find ./tests -iname *.h -o -iname *.cpp -o -iname *.c | xargs clang-format --style=file -i
|
@@ -1,76 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*
|
||||
"""Small portable helper script to generate LCOV HTML coverage data"""
|
||||
import os
|
||||
import platform
|
||||
import sys
|
||||
import time
|
||||
import argparse
|
||||
from typing import List
|
||||
|
||||
|
||||
"""Copy this helper script into your project folder. It will try to determine a CMake build folder
|
||||
and then attempt to build your project with coverage information.
|
||||
|
||||
See Unittest documentation at https://egit.irs.uni-stuttgart.de/fsfw/fsfw for more
|
||||
information how to set up the build folder.
|
||||
"""
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(description="Processing arguments for LCOV helper script.")
|
||||
|
||||
build_dir_list = []
|
||||
if not os.path.isfile('README.md'):
|
||||
os.chdir('..')
|
||||
for directory in os.listdir("."):
|
||||
if os.path.isdir(directory):
|
||||
os.chdir(directory)
|
||||
check_for_cmake_build_dir(build_dir_list)
|
||||
os.chdir("..")
|
||||
|
||||
if len(build_dir_list) == 0:
|
||||
print("No valid CMake build directory found. Trying to set up hosted build")
|
||||
build_directory = 'build-Debug-Host'
|
||||
os.mkdir(build_directory)
|
||||
os.chdir(build_directory)
|
||||
os.system('cmake -DFSFW_OSAL=host -DFSFW_BUILD_UNITTESTS=ON ..')
|
||||
os.chdir('..')
|
||||
elif len(build_dir_list) == 1:
|
||||
build_directory = build_dir_list[0]
|
||||
else:
|
||||
print("Multiple build directories found!")
|
||||
build_directory = determine_build_dir(build_dir_list)
|
||||
perform_lcov_operation(build_directory)
|
||||
|
||||
|
||||
def check_for_cmake_build_dir(build_dir_dict: list):
|
||||
if os.path.isfile("CMakeCache.txt"):
|
||||
build_dir_dict.append(os.getcwd())
|
||||
|
||||
|
||||
def perform_lcov_operation(directory):
|
||||
os.chdir(directory)
|
||||
os.system("cmake --build . -- fsfw-tests_coverage -j")
|
||||
|
||||
|
||||
def determine_build_dir(build_dir_list: List[str]):
|
||||
build_directory = ""
|
||||
for idx, directory in enumerate(build_dir_list):
|
||||
print(f"{idx + 1}: {directory}")
|
||||
while True:
|
||||
idx = input("Pick the directory to perform LCOV HTML generation by index: ")
|
||||
if not idx.isdigit():
|
||||
print("Invalid input!")
|
||||
continue
|
||||
|
||||
idx = int(idx)
|
||||
if idx > len(build_dir_list) or idx < 1:
|
||||
print("Invalid input!")
|
||||
continue
|
||||
build_directory = build_dir_list[idx - 1]
|
||||
break
|
||||
return build_directory
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
188
scripts/helper.py
Executable file
188
scripts/helper.py
Executable file
@@ -0,0 +1,188 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*
|
||||
"""Small portable helper script to generate test or doc configuration for the
|
||||
flight software framework
|
||||
"""
|
||||
import os
|
||||
import argparse
|
||||
import webbrowser
|
||||
import shutil
|
||||
import sys
|
||||
import time
|
||||
from typing import List
|
||||
|
||||
|
||||
UNITTEST_FOLDER_NAME = 'build-tests'
|
||||
DOCS_FOLDER_NAME = 'build-docs'
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(description="FSFW helper script")
|
||||
choices = ('docs', 'tests')
|
||||
parser.add_argument(
|
||||
'type', metavar='type', choices=choices,
|
||||
help=f'Target type. Choices: {choices}'
|
||||
)
|
||||
parser.add_argument(
|
||||
'-a', '--all', action='store_true',
|
||||
help='Create, build and open specified type'
|
||||
)
|
||||
parser.add_argument(
|
||||
'-c', '--create', action='store_true',
|
||||
help='Create docs or test build configuration'
|
||||
)
|
||||
parser.add_argument(
|
||||
'-b', '--build', action='store_true',
|
||||
help='Build the specified type'
|
||||
)
|
||||
parser.add_argument(
|
||||
'-o', '--open', action='store_true',
|
||||
help='Open test or documentation data in webbrowser'
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
if args.all:
|
||||
args.build = True
|
||||
args.create = True
|
||||
args.open = True
|
||||
elif not args.build and not args.create and not args.open:
|
||||
print(
|
||||
'Please select at least one operation to perform. '
|
||||
'Use helper.py -h for more information'
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
# This script can be called from root and from script folder
|
||||
if not os.path.isfile('README.md'):
|
||||
os.chdir('..')
|
||||
build_dir_list = []
|
||||
if not args.create:
|
||||
build_dir_list = build_build_dir_list()
|
||||
|
||||
if args.type == 'tests':
|
||||
handle_tests_type(args, build_dir_list)
|
||||
elif args.type == 'docs':
|
||||
handle_docs_type(args, build_dir_list)
|
||||
else:
|
||||
print('Invalid or unknown type')
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def handle_docs_type(args, build_dir_list: list):
|
||||
if args.create:
|
||||
if os.path.exists(DOCS_FOLDER_NAME):
|
||||
shutil.rmtree(DOCS_FOLDER_NAME)
|
||||
create_docs_build_cfg()
|
||||
build_directory = DOCS_FOLDER_NAME
|
||||
elif len(build_dir_list) == 0:
|
||||
print('No valid CMake docs build directory found. Trying to set up docs build system')
|
||||
shutil.rmtree(DOCS_FOLDER_NAME)
|
||||
create_docs_build_cfg()
|
||||
build_directory = DOCS_FOLDER_NAME
|
||||
elif len(build_dir_list) == 1:
|
||||
build_directory = build_dir_list[0]
|
||||
else:
|
||||
print("Multiple build directories found!")
|
||||
build_directory = determine_build_dir(build_dir_list)
|
||||
os.chdir(build_directory)
|
||||
if args.build:
|
||||
os.system('cmake --build . -j')
|
||||
if args.open:
|
||||
if not os.path.isfile('docs/sphinx/index.html'):
|
||||
# try again..
|
||||
os.system('cmake --build . -j')
|
||||
if not os.path.isfile('docs/sphinx/index.html'):
|
||||
print(
|
||||
"No Sphinx documentation file detected. "
|
||||
"Try to build it first with the -b argument"
|
||||
)
|
||||
sys.exit(1)
|
||||
webbrowser.open('docs/sphinx/index.html')
|
||||
|
||||
|
||||
def handle_tests_type(args, build_dir_list: list):
|
||||
if args.create:
|
||||
if os.path.exists(UNITTEST_FOLDER_NAME):
|
||||
shutil.rmtree(UNITTEST_FOLDER_NAME)
|
||||
create_tests_build_cfg()
|
||||
build_directory = UNITTEST_FOLDER_NAME
|
||||
elif len(build_dir_list) == 0:
|
||||
print(
|
||||
'No valid CMake tests build directory found. '
|
||||
'Trying to set up test build system'
|
||||
)
|
||||
create_tests_build_cfg()
|
||||
build_directory = UNITTEST_FOLDER_NAME
|
||||
elif len(build_dir_list) == 1:
|
||||
build_directory = build_dir_list[0]
|
||||
else:
|
||||
print("Multiple build directories found!")
|
||||
build_directory = determine_build_dir(build_dir_list)
|
||||
os.chdir(build_directory)
|
||||
if args.build:
|
||||
perform_lcov_operation(build_directory, False)
|
||||
if args.open:
|
||||
if not os.path.isdir('fsfw-tests_coverage'):
|
||||
print("No Unittest folder detected. Try to build them first with the -b argument")
|
||||
sys.exit(1)
|
||||
webbrowser.open('fsfw-tests_coverage/index.html')
|
||||
|
||||
|
||||
def create_tests_build_cfg():
|
||||
os.mkdir(UNITTEST_FOLDER_NAME)
|
||||
os.chdir(UNITTEST_FOLDER_NAME)
|
||||
os.system('cmake -DFSFW_OSAL=host -DFSFW_BUILD_UNITTESTS=ON ..')
|
||||
os.chdir('..')
|
||||
|
||||
|
||||
def create_docs_build_cfg():
|
||||
os.mkdir(DOCS_FOLDER_NAME)
|
||||
os.chdir(DOCS_FOLDER_NAME)
|
||||
os.system('cmake -DFSFW_OSAL=host -DFSFW_BUILD_DOCS=ON ..')
|
||||
os.chdir('..')
|
||||
|
||||
|
||||
def build_build_dir_list() -> list:
|
||||
build_dir_list = []
|
||||
for directory in os.listdir("."):
|
||||
if os.path.isdir(directory):
|
||||
os.chdir(directory)
|
||||
build_dir_list = check_for_cmake_build_dir(build_dir_list)
|
||||
os.chdir("..")
|
||||
return build_dir_list
|
||||
|
||||
|
||||
def check_for_cmake_build_dir(build_dir_list: list) -> list:
|
||||
if os.path.isfile("CMakeCache.txt"):
|
||||
build_dir_list.append(os.getcwd())
|
||||
return build_dir_list
|
||||
|
||||
|
||||
def perform_lcov_operation(directory: str, chdir: bool):
|
||||
if chdir:
|
||||
os.chdir(directory)
|
||||
os.system("cmake --build . -- fsfw-tests_coverage -j")
|
||||
|
||||
|
||||
def determine_build_dir(build_dir_list: List[str]):
|
||||
build_directory = ""
|
||||
for idx, directory in enumerate(build_dir_list):
|
||||
print(f"{idx + 1}: {directory}")
|
||||
while True:
|
||||
idx = input("Pick the directory: ")
|
||||
if not idx.isdigit():
|
||||
print("Invalid input!")
|
||||
continue
|
||||
|
||||
idx = int(idx)
|
||||
if idx > len(build_dir_list) or idx < 1:
|
||||
print("Invalid input!")
|
||||
continue
|
||||
build_directory = build_dir_list[idx - 1]
|
||||
break
|
||||
return build_directory
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@@ -16,5 +16,3 @@ target_include_directories(${LIB_FSFW_NAME} PRIVATE
|
||||
target_include_directories(${LIB_FSFW_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
configure_file(fsfw/FSFW.h.in fsfw/FSFW.h)
|
||||
|
@@ -18,10 +18,6 @@
|
||||
|
||||
// FSFW core defines
|
||||
|
||||
#ifndef FSFW_TCP_RECV_WIRETAPPING_ENABLED
|
||||
#define FSFW_TCP_RECV_WIRETAPPING_ENABLED 0
|
||||
#endif
|
||||
|
||||
#ifndef FSFW_CPP_OSTREAM_ENABLED
|
||||
#define FSFW_CPP_OSTREAM_ENABLED 1
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED */
|
||||
|
@@ -5,7 +5,8 @@
|
||||
#include <cstddef>
|
||||
|
||||
/**
|
||||
* @brief Circular buffer implementation, useful for buffering into data streams.
|
||||
* @brief Circular buffer implementation, useful for buffering
|
||||
* into data streams.
|
||||
* @details
|
||||
* Note that the deleteData() has to be called to increment the read pointer.
|
||||
* This class allocated dynamically, so
|
||||
@@ -19,8 +20,8 @@ public:
|
||||
* @param size
|
||||
* @param overwriteOld If the ring buffer is overflowing at a write
|
||||
* operation, the oldest data will be overwritten.
|
||||
* @param maxExcessBytes These additional bytes will be allocated in addition
|
||||
* to the specified size to accommodate continuous write operations
|
||||
* @param maxExcessBytes These additional bytes will be allocated in addtion
|
||||
* to the specified size to accomodate contiguous write operations
|
||||
* with getFreeElement.
|
||||
*
|
||||
*/
|
||||
@@ -31,10 +32,10 @@ public:
|
||||
* @param buffer
|
||||
* @param size
|
||||
* @param overwriteOld
|
||||
* If the ring buffer is overflowing at a write operation, the oldest data
|
||||
* If the ring buffer is overflowing at a write operartion, the oldest data
|
||||
* will be overwritten.
|
||||
* @param maxExcessBytes
|
||||
* If the buffer can accommodate additional bytes for contiguous write
|
||||
* If the buffer can accomodate additional bytes for contigous write
|
||||
* operations with getFreeElement, this is the maximum allowed additional
|
||||
* size
|
||||
*/
|
||||
@@ -47,7 +48,7 @@ public:
|
||||
* Write to circular buffer and increment write pointer by amount.
|
||||
* @param data
|
||||
* @param amount
|
||||
* @return -@c RETURN_OK if write operation was successful
|
||||
* @return -@c RETURN_OK if write operation was successfull
|
||||
* -@c RETURN_FAILED if
|
||||
*/
|
||||
ReturnValue_t writeData(const uint8_t* data, size_t amount);
|
||||
@@ -107,7 +108,7 @@ public:
|
||||
* Delete data by incrementing read pointer.
|
||||
* @param amount
|
||||
* @param deleteRemaining
|
||||
* If the amount specified is larger than the remaining size to read and this
|
||||
* If the amount specified is larger than the remaing size to read and this
|
||||
* is set to true, the remaining amount will be deleted as well
|
||||
* @param trueAmount [out]
|
||||
* If deleteRemaining was set to true, the amount deleted will be assigned
|
||||
|
@@ -110,7 +110,7 @@ ReturnValue_t LocalPoolDataSetBase::serializeWithValidityBuffer(uint8_t **buffer
|
||||
for (uint16_t count = 0; count < fillCount; count++) {
|
||||
if(registeredVariables[count]->isValid()) {
|
||||
/* Set bit at correct position */
|
||||
bitutil::bitSet(validityPtr + validBufferIndex, validBufferIndexBit);
|
||||
bitutil::set(validityPtr + validBufferIndex, validBufferIndexBit);
|
||||
}
|
||||
if(validBufferIndexBit == 7) {
|
||||
validBufferIndex ++;
|
||||
@@ -156,8 +156,8 @@ ReturnValue_t LocalPoolDataSetBase::deSerializeWithValidityBuffer(
|
||||
uint8_t validBufferIndexBit = 0;
|
||||
for (uint16_t count = 0; count < fillCount; count++) {
|
||||
// set validity buffer here.
|
||||
bool nextVarValid = bitutil::bitGet(*buffer +
|
||||
validBufferIndex, validBufferIndexBit);
|
||||
bool nextVarValid = false;
|
||||
bitutil::get(*buffer + validBufferIndex, validBufferIndexBit, nextVarValid);
|
||||
registeredVariables[count]->setValid(nextVarValid);
|
||||
|
||||
if(validBufferIndexBit == 7) {
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
/**
|
||||
* @brief Base class to implement reconfiguration and failure handling for
|
||||
* redundant devices by monitoring their modes and health states.
|
||||
* redundant devices by monitoring their modes health states.
|
||||
* @details
|
||||
* Documentation: Dissertation Baetz p.156, 157.
|
||||
*
|
||||
|
@@ -85,10 +85,9 @@ public:
|
||||
* Called by DHB in the GET_WRITE doGetWrite().
|
||||
* Get send confirmation that the data in sendMessage() was sent successfully.
|
||||
* @param cookie
|
||||
* @return
|
||||
* - @c RETURN_OK if data was sent successfully but a reply is expected
|
||||
* - NO_REPLY_EXPECTED if data was sent successfully and no reply is expected
|
||||
* - Everything else to indicate failure
|
||||
* @return - @c RETURN_OK if data was sent successfull
|
||||
* - Everything else triggers falure event with
|
||||
* returnvalue as parameter 1
|
||||
*/
|
||||
virtual ReturnValue_t getSendSuccess(CookieIF *cookie) = 0;
|
||||
|
||||
|
@@ -334,7 +334,8 @@ protected:
|
||||
* - @c RETURN_OK to send command after #rawPacket and #rawPacketLen
|
||||
* have been set.
|
||||
* - @c HasActionsIF::EXECUTION_COMPLETE to generate a finish reply immediately. This can
|
||||
* be used if no reply is expected
|
||||
* be used if no reply is expected. Otherwise, the developer can call #actionHelper.finish
|
||||
* to finish the command handling.
|
||||
* - Anything else triggers an event with the return code as a parameter as well as a
|
||||
* step reply failed with the return code
|
||||
*/
|
||||
|
@@ -120,8 +120,7 @@ public:
|
||||
static const ReturnValue_t WRONG_MODE_FOR_COMMAND = MAKE_RETURN_CODE(0xA5);
|
||||
static const ReturnValue_t TIMEOUT = MAKE_RETURN_CODE(0xA6);
|
||||
static const ReturnValue_t BUSY = MAKE_RETURN_CODE(0xA7);
|
||||
//!< Used to indicate that this is a command-only command.
|
||||
static const ReturnValue_t NO_REPLY_EXPECTED = MAKE_RETURN_CODE(0xA8);
|
||||
static const ReturnValue_t NO_REPLY_EXPECTED = MAKE_RETURN_CODE(0xA8); //!< Used to indicate that this is a command-only command.
|
||||
static const ReturnValue_t NON_OP_TEMPERATURE = MAKE_RETURN_CODE(0xA9);
|
||||
static const ReturnValue_t COMMAND_NOT_IMPLEMENTED = MAKE_RETURN_CODE(0xAA);
|
||||
|
||||
|
@@ -3,16 +3,16 @@
|
||||
|
||||
PeriodicOperationDivider::PeriodicOperationDivider(uint32_t divider,
|
||||
bool resetAutomatically): resetAutomatically(resetAutomatically),
|
||||
counter(divider), divider(divider) {
|
||||
divider(divider) {
|
||||
}
|
||||
|
||||
bool PeriodicOperationDivider::checkAndIncrement() {
|
||||
counter++;
|
||||
bool opNecessary = check();
|
||||
if(opNecessary) {
|
||||
if(resetAutomatically) {
|
||||
resetCounter();
|
||||
}
|
||||
if(opNecessary and resetAutomatically) {
|
||||
resetCounter();
|
||||
}
|
||||
else {
|
||||
counter++;
|
||||
}
|
||||
return opNecessary;
|
||||
}
|
||||
@@ -24,10 +24,8 @@ bool PeriodicOperationDivider::check() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PeriodicOperationDivider::resetCounter() {
|
||||
counter = 0;
|
||||
counter = 1;
|
||||
}
|
||||
|
||||
void PeriodicOperationDivider::setDivider(uint32_t newDivider) {
|
||||
|
@@ -16,16 +16,15 @@ public:
|
||||
/**
|
||||
* Initialize with the desired divider and specify whether the internal
|
||||
* counter will be reset automatically.
|
||||
* @param divider
|
||||
* @param divider Value of 0 or 1 will cause #check and #checkAndIncrement to always return
|
||||
* true
|
||||
* @param resetAutomatically
|
||||
*/
|
||||
PeriodicOperationDivider(uint32_t divider, bool resetAutomatically = true);
|
||||
|
||||
|
||||
/**
|
||||
* Check whether operation is necessary.
|
||||
* If an operation is necessary and the class has been
|
||||
* configured to be reset automatically, the counter will be reset.
|
||||
* Check whether operation is necessary. If an operation is necessary and the class has been
|
||||
* configured to be reset automatically, the counter will be reset to 1 automatically
|
||||
*
|
||||
* @return
|
||||
* -@c true if the counter is larger or equal to the divider
|
||||
@@ -34,8 +33,7 @@ public:
|
||||
bool checkAndIncrement();
|
||||
|
||||
/**
|
||||
* Checks whether an operation is necessary.
|
||||
* This function will not increment the counter!
|
||||
* Checks whether an operation is necessary. This function will not increment the counter.
|
||||
* @return
|
||||
* -@c true if the counter is larger or equal to the divider
|
||||
* -@c false otherwise
|
||||
@@ -43,7 +41,7 @@ public:
|
||||
bool check();
|
||||
|
||||
/**
|
||||
* Can be used to reset the counter to 0 manually.
|
||||
* Can be used to reset the counter to 1 manually
|
||||
*/
|
||||
void resetCounter();
|
||||
uint32_t getCounter() const;
|
||||
@@ -54,9 +52,10 @@ public:
|
||||
*/
|
||||
void setDivider(uint32_t newDivider);
|
||||
uint32_t getDivider() const;
|
||||
|
||||
private:
|
||||
bool resetAutomatically = true;
|
||||
uint32_t counter = 0;
|
||||
uint32_t counter = 1;
|
||||
uint32_t divider = 0;
|
||||
};
|
||||
|
||||
|
@@ -45,18 +45,18 @@ void arrayprinter::printHex(const uint8_t *data, size_t size,
|
||||
std::cout << "\r" << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "[" << std::hex;
|
||||
std::cout << "hex [" << std::setfill('0') << std::hex;
|
||||
for(size_t i = 0; i < size; i++) {
|
||||
std::cout << "0x" << static_cast<int>(data[i]);
|
||||
std::cout << std::setw(2) << static_cast<int>(data[i]);
|
||||
if(i < size - 1) {
|
||||
std::cout << " , ";
|
||||
std::cout << ",";
|
||||
if(i > 0 and (i + 1) % maxCharPerLine == 0) {
|
||||
std::cout << std::endl;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
std::cout << std::dec;
|
||||
std::cout << std::dec << std::setfill(' ');
|
||||
std::cout << "]" << std::endl;
|
||||
#else
|
||||
// General format: 0x01, 0x02, 0x03 so it is number of chars times 6
|
||||
@@ -69,16 +69,16 @@ void arrayprinter::printHex(const uint8_t *data, size_t size,
|
||||
break;
|
||||
}
|
||||
|
||||
currentPos += snprintf(printBuffer + currentPos, 6, "0x%02x", data[i]);
|
||||
currentPos += snprintf(printBuffer + currentPos, 6, "%02x", data[i]);
|
||||
if(i < size - 1) {
|
||||
currentPos += sprintf(printBuffer + currentPos, ", ");
|
||||
currentPos += sprintf(printBuffer + currentPos, ",");
|
||||
if(i > 0 and (i + 1) % maxCharPerLine == 0) {
|
||||
currentPos += sprintf(printBuffer + currentPos, "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
#if FSFW_DISABLE_PRINTOUT == 0
|
||||
printf("[%s]\n", printBuffer);
|
||||
printf("hex [%s]\n", printBuffer);
|
||||
#endif /* FSFW_DISABLE_PRINTOUT == 0 */
|
||||
#endif
|
||||
}
|
||||
@@ -90,11 +90,11 @@ void arrayprinter::printDec(const uint8_t *data, size_t size,
|
||||
std::cout << "\r" << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "[" << std::dec;
|
||||
std::cout << "dec [" << std::dec;
|
||||
for(size_t i = 0; i < size; i++) {
|
||||
std::cout << static_cast<int>(data[i]);
|
||||
if(i < size - 1){
|
||||
std::cout << " , ";
|
||||
std::cout << ",";
|
||||
if(i > 0 and (i + 1) % maxCharPerLine == 0) {
|
||||
std::cout << std::endl;
|
||||
}
|
||||
@@ -114,14 +114,14 @@ void arrayprinter::printDec(const uint8_t *data, size_t size,
|
||||
|
||||
currentPos += snprintf(printBuffer + currentPos, 3, "%d", data[i]);
|
||||
if(i < size - 1) {
|
||||
currentPos += sprintf(printBuffer + currentPos, ", ");
|
||||
currentPos += sprintf(printBuffer + currentPos, ",");
|
||||
if(i > 0 and (i + 1) % maxCharPerLine == 0) {
|
||||
currentPos += sprintf(printBuffer + currentPos, "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
#if FSFW_DISABLE_PRINTOUT == 0
|
||||
printf("[%s]\n", printBuffer);
|
||||
printf("dec [%s]\n", printBuffer);
|
||||
#endif /* FSFW_DISABLE_PRINTOUT == 0 */
|
||||
#endif
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include "fsfw/globalfunctions/bitutility.h"
|
||||
|
||||
void bitutil::bitSet(uint8_t *byte, uint8_t position) {
|
||||
void bitutil::set(uint8_t *byte, uint8_t position) {
|
||||
if(position > 7) {
|
||||
return;
|
||||
}
|
||||
@@ -8,7 +8,7 @@ void bitutil::bitSet(uint8_t *byte, uint8_t position) {
|
||||
*byte |= 1 << shiftNumber;
|
||||
}
|
||||
|
||||
void bitutil::bitToggle(uint8_t *byte, uint8_t position) {
|
||||
void bitutil::toggle(uint8_t *byte, uint8_t position) {
|
||||
if(position > 7) {
|
||||
return;
|
||||
}
|
||||
@@ -16,7 +16,7 @@ void bitutil::bitToggle(uint8_t *byte, uint8_t position) {
|
||||
*byte ^= 1 << shiftNumber;
|
||||
}
|
||||
|
||||
void bitutil::bitClear(uint8_t *byte, uint8_t position) {
|
||||
void bitutil::clear(uint8_t *byte, uint8_t position) {
|
||||
if(position > 7) {
|
||||
return;
|
||||
}
|
||||
@@ -24,10 +24,11 @@ void bitutil::bitClear(uint8_t *byte, uint8_t position) {
|
||||
*byte &= ~(1 << shiftNumber);
|
||||
}
|
||||
|
||||
bool bitutil::bitGet(const uint8_t *byte, uint8_t position) {
|
||||
bool bitutil::get(const uint8_t *byte, uint8_t position, bool& bit) {
|
||||
if(position > 7) {
|
||||
return false;
|
||||
}
|
||||
uint8_t shiftNumber = position + (7 - 2 * position);
|
||||
return *byte & (1 << shiftNumber);
|
||||
bit = *byte & (1 << shiftNumber);
|
||||
return true;
|
||||
}
|
||||
|
@@ -5,13 +5,36 @@
|
||||
|
||||
namespace bitutil {
|
||||
|
||||
/* Helper functions for manipulating the individual bits of a byte.
|
||||
Position refers to n-th bit of a byte, going from 0 (most significant bit) to
|
||||
7 (least significant bit) */
|
||||
void bitSet(uint8_t* byte, uint8_t position);
|
||||
void bitToggle(uint8_t* byte, uint8_t position);
|
||||
void bitClear(uint8_t* byte, uint8_t position);
|
||||
bool bitGet(const uint8_t* byte, uint8_t position);
|
||||
// Helper functions for manipulating the individual bits of a byte.
|
||||
// Position refers to n-th bit of a byte, going from 0 (most significant bit) to
|
||||
// 7 (least significant bit)
|
||||
|
||||
/**
|
||||
* @brief Set the bit in a given byte
|
||||
* @param byte
|
||||
* @param position
|
||||
*/
|
||||
void set(uint8_t* byte, uint8_t position);
|
||||
/**
|
||||
* @brief Toggle the bit in a given byte
|
||||
* @param byte
|
||||
* @param position
|
||||
*/
|
||||
void toggle(uint8_t* byte, uint8_t position);
|
||||
/**
|
||||
* @brief Clear the bit in a given byte
|
||||
* @param byte
|
||||
* @param position
|
||||
*/
|
||||
void clear(uint8_t* byte, uint8_t position);
|
||||
/**
|
||||
* @brief Get the bit in a given byte
|
||||
* @param byte
|
||||
* @param position
|
||||
* @param If the input is valid, this will be set to true if the bit is set and false otherwise.
|
||||
* @return False if position is invalid, True otherwise
|
||||
*/
|
||||
bool get(const uint8_t* byte, uint8_t position, bool& bit);
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,8 +2,9 @@
|
||||
#define TIMEVALOPERATIONS_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <fsfw/platform.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef PLATFORM_WIN
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
|
13
src/fsfw/memory/FileSystemArgsIF.h
Normal file
13
src/fsfw/memory/FileSystemArgsIF.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef FSFW_SRC_FSFW_MEMORY_FILESYSTEMARGS_H_
|
||||
#define FSFW_SRC_FSFW_MEMORY_FILESYSTEMARGS_H_
|
||||
|
||||
/**
|
||||
* Empty base interface which can be implemented by to pass arguments via the HasFileSystemIF.
|
||||
* Users can then dynamic_cast the base pointer to the require child pointer.
|
||||
*/
|
||||
class FileSystemArgsIF {
|
||||
public:
|
||||
virtual~ FileSystemArgsIF() {};
|
||||
};
|
||||
|
||||
#endif /* FSFW_SRC_FSFW_MEMORY_FILESYSTEMARGS_H_ */
|
@@ -1,9 +1,10 @@
|
||||
#ifndef FSFW_MEMORY_HASFILESYSTEMIF_H_
|
||||
#define FSFW_MEMORY_HASFILESYSTEMIF_H_
|
||||
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../returnvalues/FwClassIds.h"
|
||||
#include "../ipc/messageQueueDefinitions.h"
|
||||
#include "FileSystemArgsIF.h"
|
||||
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||
#include "fsfw/returnvalues/FwClassIds.h"
|
||||
#include "fsfw/ipc/messageQueueDefinitions.h"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
@@ -59,7 +60,7 @@ public:
|
||||
*/
|
||||
virtual ReturnValue_t appendToFile(const char* repositoryPath,
|
||||
const char* filename, const uint8_t* data, size_t size,
|
||||
uint16_t packetNumber, void* args = nullptr) = 0;
|
||||
uint16_t packetNumber, FileSystemArgsIF* args = nullptr) = 0;
|
||||
|
||||
/**
|
||||
* @brief Generic function to create a new file.
|
||||
@@ -72,7 +73,7 @@ public:
|
||||
*/
|
||||
virtual ReturnValue_t createFile(const char* repositoryPath,
|
||||
const char* filename, const uint8_t* data = nullptr,
|
||||
size_t size = 0, void* args = nullptr) = 0;
|
||||
size_t size = 0, FileSystemArgsIF* args = nullptr) = 0;
|
||||
|
||||
/**
|
||||
* @brief Generic function to delete a file.
|
||||
@@ -82,23 +83,29 @@ public:
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t removeFile(const char* repositoryPath,
|
||||
const char* filename, void* args = nullptr) = 0;
|
||||
const char* filename, FileSystemArgsIF* args = nullptr) = 0;
|
||||
|
||||
/**
|
||||
* @brief Generic function to create a directory
|
||||
* @param repositoryPath
|
||||
* @param Equivalent to the -p flag in Unix systems. If some required parent directories
|
||||
* do not exist, create them as well
|
||||
* @param args Any other arguments which an implementation might require
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t createDirectory(const char* repositoryPath, void* args = nullptr) = 0;
|
||||
virtual ReturnValue_t createDirectory(const char* repositoryPath, const char* dirname,
|
||||
bool createParentDirs, FileSystemArgsIF* args = nullptr) = 0;
|
||||
|
||||
/**
|
||||
* @brief Generic function to remove a directory
|
||||
* @param repositoryPath
|
||||
* @param args Any other arguments which an implementation might require
|
||||
*/
|
||||
virtual ReturnValue_t removeDirectory(const char* repositoryPath,
|
||||
bool deleteRecurively = false, void* args = nullptr) = 0;
|
||||
virtual ReturnValue_t removeDirectory(const char* repositoryPath, const char* dirname,
|
||||
bool deleteRecurively = false, FileSystemArgsIF* args = nullptr) = 0;
|
||||
|
||||
virtual ReturnValue_t renameFile(const char* repositoryPath, const char* oldFilename,
|
||||
const char* newFilename, FileSystemArgsIF* args = nullptr) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
@@ -1,29 +1,30 @@
|
||||
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||
Clock.cpp
|
||||
BinarySemaphore.cpp
|
||||
CountingSemaphore.cpp
|
||||
FixedTimeslotTask.cpp
|
||||
InternalErrorCodes.cpp
|
||||
MessageQueue.cpp
|
||||
Mutex.cpp
|
||||
MutexFactory.cpp
|
||||
PeriodicPosixTask.cpp
|
||||
PosixThread.cpp
|
||||
QueueFactory.cpp
|
||||
SemaphoreFactory.cpp
|
||||
TaskFactory.cpp
|
||||
tcpipHelpers.cpp
|
||||
unixUtility.cpp
|
||||
target_sources(${LIB_FSFW_NAME}
|
||||
PRIVATE
|
||||
Clock.cpp
|
||||
BinarySemaphore.cpp
|
||||
CountingSemaphore.cpp
|
||||
FixedTimeslotTask.cpp
|
||||
InternalErrorCodes.cpp
|
||||
MessageQueue.cpp
|
||||
Mutex.cpp
|
||||
MutexFactory.cpp
|
||||
PeriodicPosixTask.cpp
|
||||
PosixThread.cpp
|
||||
QueueFactory.cpp
|
||||
SemaphoreFactory.cpp
|
||||
TaskFactory.cpp
|
||||
tcpipHelpers.cpp
|
||||
unixUtility.cpp
|
||||
)
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
target_link_libraries(${LIB_FSFW_NAME} PRIVATE
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
rt
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
rt
|
||||
)
|
||||
|
||||
target_link_libraries(${LIB_FSFW_NAME} INTERFACE
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
)
|
||||
|
||||
|
@@ -285,10 +285,10 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
|
||||
|
||||
utility::printUnixErrorGeneric(CLASS_NAME, "sendMessageFromMessageQueue", "EBADF");
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "mq_send to " << sendTo << " sent from "
|
||||
<< sentFrom << " failed" << std::endl;
|
||||
sif::warning << "mq_send to: " << sendTo << " sent from "
|
||||
<< sentFrom << "failed" << std::endl;
|
||||
#else
|
||||
sif::printWarning("mq_send to %d sent from %d failed\n", sendTo, sentFrom);
|
||||
sif::printWarning("mq_send to: %d sent from %d failed\n", sendTo, sentFrom);
|
||||
#endif
|
||||
return DESTINATION_INVALID;
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief These adapters provides an interface to use the SerializeIF functions
|
||||
* with arbitrary template objects to facilitate and simplify the
|
||||
* serialization of classes with different multiple different data types
|
||||
@@ -20,174 +20,250 @@
|
||||
*/
|
||||
class SerializeAdapter {
|
||||
public:
|
||||
/***
|
||||
* This function can be used to serialize a trivial copy-able type or a
|
||||
* child of SerializeIF.
|
||||
* The right template to be called is determined in the function itself.
|
||||
* For objects of non trivial copy-able type this function is almost never
|
||||
* called by the user directly. Instead helpers for specific types like
|
||||
* SerialArrayListAdapter or SerialLinkedListAdapter is the right choice here.
|
||||
*
|
||||
* @param[in] object Object to serialize, the used type is deduced from this pointer
|
||||
* @param[in/out] buffer Buffer to serialize into. Will be moved by the function.
|
||||
* @param[in/out] size Size of current written buffer. Will be incremented by the function.
|
||||
* @param[in] maxSize Max size of Buffer
|
||||
* @param[in] streamEndianness Endianness of serialized element as in according to SerializeIF::Endianness
|
||||
* @return
|
||||
* - @c BUFFER_TOO_SHORT The given buffer in is too short
|
||||
* - @c RETURN_FAILED Generic Error
|
||||
* - @c RETURN_OK Successful serialization
|
||||
*/
|
||||
template<typename T>
|
||||
static ReturnValue_t serialize(const T *object, uint8_t **buffer,
|
||||
size_t *size, size_t maxSize,
|
||||
SerializeIF::Endianness streamEndianness) {
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
return adapter.serialize(object, buffer, size, maxSize,
|
||||
streamEndianness);
|
||||
}
|
||||
/**
|
||||
* Function to return the serialized size of the object in the pointer.
|
||||
* May be a trivially copy-able object or a Child of SerializeIF
|
||||
*
|
||||
* @param object Pointer to Object
|
||||
* @return Serialized size of object
|
||||
*/
|
||||
template<typename T>
|
||||
static size_t getSerializedSize(const T *object){
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
return adapter.getSerializedSize(object);
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* Deserializes a object from a given buffer of given size.
|
||||
* Object Must be trivially copy-able or a child of SerializeIF.
|
||||
*
|
||||
* @details
|
||||
* Buffer will be moved to the current read location. Size will be decreased by the function.
|
||||
*
|
||||
* @param[in/out] buffer Buffer to deSerialize from. Will be moved by the function.
|
||||
* @param[in/out] size Remaining size of the buffer to read from. Will be decreased by function.
|
||||
* @param[in] streamEndianness Endianness as in according to SerializeIF::Endianness
|
||||
* @return
|
||||
* - @c STREAM_TOO_SHORT The input stream is too short to deSerialize the object
|
||||
* - @c TOO_MANY_ELEMENTS The buffer has more inputs than expected
|
||||
* - @c RETURN_FAILED Generic Error
|
||||
* - @c RETURN_OK Successful deserialization
|
||||
*/
|
||||
template<typename T>
|
||||
static ReturnValue_t deSerialize(T *object, const uint8_t **buffer,
|
||||
size_t *size, SerializeIF::Endianness streamEndianness) {
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
return adapter.deSerialize(object, buffer, size, streamEndianness);
|
||||
}
|
||||
/***
|
||||
* @brief Serialize a trivial copy-able type or a child of SerializeIF.
|
||||
* @details
|
||||
* The right template to be called is determined in the function itself.
|
||||
* For objects of non trivial copy-able type this function is almost never
|
||||
* called by the user directly. Instead helpers for specific types like
|
||||
* SerialArrayListAdapter or SerialLinkedListAdapter are the right choice here.
|
||||
*
|
||||
* @param[in] object: Object to serialize, the used type is deduced from this pointer
|
||||
* @param[in/out] buffer: Pointer to the buffer to serialize into. Buffer position will be
|
||||
* incremented by the function.
|
||||
* @param[in/out] size: Pointer to size of current written buffer.
|
||||
* SIze will be incremented by the function.
|
||||
* @param[in] maxSize: Max size of Buffer
|
||||
* @param[in] streamEndianness: Endianness of serialized element as in according to
|
||||
* SerializeIF::Endianness
|
||||
* @return
|
||||
* - @c BUFFER_TOO_SHORT The given buffer in is too short
|
||||
* - @c RETURN_FAILED Generic Error
|
||||
* - @c RETURN_OK Successful serialization
|
||||
*/
|
||||
template<typename T>
|
||||
static ReturnValue_t serialize(const T *object, uint8_t **buffer,
|
||||
size_t *size, size_t maxSize,
|
||||
SerializeIF::Endianness streamEndianness) {
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
return adapter.serialize(object, buffer, size, maxSize,
|
||||
streamEndianness);
|
||||
}
|
||||
|
||||
/***
|
||||
* This function can be used to serialize a trivial copy-able type or a child of SerializeIF.
|
||||
* The right template to be called is determined in the function itself.
|
||||
* For objects of non trivial copy-able type this function is almost never
|
||||
* called by the user directly. Instead helpers for specific types like
|
||||
* SerialArrayListAdapter or SerialLinkedListAdapter are the right choice here.
|
||||
*
|
||||
* @param[in] object: Object to serialize, the used type is deduced from this pointer
|
||||
* @param[in/out] buffer: Buffer to serialize into.
|
||||
* @param[out] serSize: Serialized size
|
||||
* @param[in] maxSize: Max size of buffer
|
||||
* @param[in] streamEndianness: Endianness of serialized element as in according to
|
||||
* SerializeIF::Endianness
|
||||
* @return
|
||||
* - @c BUFFER_TOO_SHORT The given buffer in is too short
|
||||
* - @c RETURN_FAILED Generic Error
|
||||
* - @c RETURN_OK Successful serialization
|
||||
*/
|
||||
template<typename T>
|
||||
static ReturnValue_t serialize(const T *object, uint8_t* const buffer, size_t* serSize,
|
||||
size_t maxSize, SerializeIF::Endianness streamEndianness) {
|
||||
if(object == nullptr or buffer == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
uint8_t** tempPtr = const_cast<uint8_t**>(&buffer);
|
||||
size_t tmpSize = 0;
|
||||
ReturnValue_t result = adapter.serialize(object, tempPtr, &tmpSize, maxSize,
|
||||
streamEndianness);
|
||||
if(serSize != nullptr) {
|
||||
*serSize = tmpSize;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function to return the serialized size of the object in the pointer.
|
||||
* @details
|
||||
* May be a trivially copy-able object or a child of SerializeIF.
|
||||
*
|
||||
* @param object Pointer to Object
|
||||
* @return Serialized size of object
|
||||
*/
|
||||
template<typename T>
|
||||
static size_t getSerializedSize(const T *object){
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
return adapter.getSerializedSize(object);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deserializes a object from a given buffer of given size.
|
||||
*
|
||||
* @details
|
||||
* Object Must be trivially copy-able or a child of SerializeIF.
|
||||
* Buffer will be moved to the current read location. Size will be decreased by the function.
|
||||
*
|
||||
* @param[in] object: Pointer to object to deserialize
|
||||
* @param[in/out] buffer: Pointer to the buffer to deSerialize from. Buffer position will be
|
||||
* incremented by the function
|
||||
* @param[in/out] size: Pointer to remaining size of the buffer to read from.
|
||||
* Will be decreased by function.
|
||||
* @param[in] streamEndianness: Endianness as in according to SerializeIF::Endianness
|
||||
* @return
|
||||
* - @c STREAM_TOO_SHORT The input stream is too short to deSerialize the object
|
||||
* - @c TOO_MANY_ELEMENTS The buffer has more inputs than expected
|
||||
* - @c RETURN_FAILED Generic Error
|
||||
* - @c RETURN_OK Successful deserialization
|
||||
*/
|
||||
template<typename T>
|
||||
static ReturnValue_t deSerialize(T *object, const uint8_t **buffer,
|
||||
size_t *size, SerializeIF::Endianness streamEndianness) {
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
return adapter.deSerialize(object, buffer, size, streamEndianness);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deserializes a object from a given buffer of given size.
|
||||
*
|
||||
* @details
|
||||
* Object Must be trivially copy-able or a child of SerializeIF.
|
||||
*
|
||||
* @param[in] object: Pointer to object to deserialize
|
||||
* @param[in] buffer: Buffer to deSerialize from
|
||||
* @param[out] deserSize: Deserialized length
|
||||
* @param[in] streamEndianness: Endianness as in according to SerializeIF::Endianness
|
||||
* @return
|
||||
* - @c STREAM_TOO_SHORT The input stream is too short to deSerialize the object
|
||||
* - @c TOO_MANY_ELEMENTS The buffer has more inputs than expected
|
||||
* - @c RETURN_FAILED Generic Error
|
||||
* - @c RETURN_OK Successful deserialization
|
||||
*/
|
||||
template<typename T>
|
||||
static ReturnValue_t deSerialize(T *object, const uint8_t* buffer,
|
||||
size_t* deserSize, SerializeIF::Endianness streamEndianness) {
|
||||
if(object == nullptr or buffer == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
const uint8_t** tempPtr = &buffer;
|
||||
size_t maxVal = -1;
|
||||
ReturnValue_t result = adapter.deSerialize(object, tempPtr, &maxVal, streamEndianness);
|
||||
if(deserSize != nullptr) {
|
||||
*deserSize = -1 - maxVal;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* Internal template to deduce the right function calls at compile time
|
||||
*/
|
||||
template<typename T, bool> class InternalSerializeAdapter;
|
||||
/**
|
||||
* Internal template to deduce the right function calls at compile time
|
||||
*/
|
||||
template<typename T, bool> class InternalSerializeAdapter;
|
||||
|
||||
/**
|
||||
* Template to be used if T is not a child of SerializeIF
|
||||
*
|
||||
* @tparam T T must be trivially_copyable
|
||||
*/
|
||||
template<typename T>
|
||||
class InternalSerializeAdapter<T, false> {
|
||||
static_assert (std::is_trivially_copyable<T>::value,
|
||||
"If a type needs to be serialized it must be a child of "
|
||||
"SerializeIF or trivially copy-able");
|
||||
public:
|
||||
static ReturnValue_t serialize(const T *object, uint8_t **buffer,
|
||||
size_t *size, size_t max_size,
|
||||
SerializeIF::Endianness streamEndianness) {
|
||||
size_t ignoredSize = 0;
|
||||
if (size == nullptr) {
|
||||
size = &ignoredSize;
|
||||
}
|
||||
// Check remaining size is large enough and check integer
|
||||
// overflow of *size
|
||||
size_t newSize = sizeof(T) + *size;
|
||||
if ((newSize <= max_size) and (newSize > *size)) {
|
||||
T tmp;
|
||||
switch (streamEndianness) {
|
||||
case SerializeIF::Endianness::BIG:
|
||||
tmp = EndianConverter::convertBigEndian<T>(*object);
|
||||
break;
|
||||
case SerializeIF::Endianness::LITTLE:
|
||||
tmp = EndianConverter::convertLittleEndian<T>(*object);
|
||||
break;
|
||||
default:
|
||||
case SerializeIF::Endianness::MACHINE:
|
||||
tmp = *object;
|
||||
break;
|
||||
}
|
||||
std::memcpy(*buffer, &tmp, sizeof(T));
|
||||
*size += sizeof(T);
|
||||
(*buffer) += sizeof(T);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return SerializeIF::BUFFER_TOO_SHORT;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Template to be used if T is not a child of SerializeIF
|
||||
*
|
||||
* @tparam T T must be trivially_copyable
|
||||
*/
|
||||
template<typename T>
|
||||
class InternalSerializeAdapter<T, false> {
|
||||
static_assert (std::is_trivially_copyable<T>::value,
|
||||
"If a type needs to be serialized it must be a child of "
|
||||
"SerializeIF or trivially copy-able");
|
||||
public:
|
||||
static ReturnValue_t serialize(const T *object, uint8_t **buffer,
|
||||
size_t *size, size_t max_size,
|
||||
SerializeIF::Endianness streamEndianness) {
|
||||
size_t ignoredSize = 0;
|
||||
if (size == nullptr) {
|
||||
size = &ignoredSize;
|
||||
}
|
||||
// Check remaining size is large enough and check integer
|
||||
// overflow of *size
|
||||
size_t newSize = sizeof(T) + *size;
|
||||
if ((newSize <= max_size) and (newSize > *size)) {
|
||||
T tmp;
|
||||
switch (streamEndianness) {
|
||||
case SerializeIF::Endianness::BIG:
|
||||
tmp = EndianConverter::convertBigEndian<T>(*object);
|
||||
break;
|
||||
case SerializeIF::Endianness::LITTLE:
|
||||
tmp = EndianConverter::convertLittleEndian<T>(*object);
|
||||
break;
|
||||
default:
|
||||
case SerializeIF::Endianness::MACHINE:
|
||||
tmp = *object;
|
||||
break;
|
||||
}
|
||||
std::memcpy(*buffer, &tmp, sizeof(T));
|
||||
*size += sizeof(T);
|
||||
(*buffer) += sizeof(T);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return SerializeIF::BUFFER_TOO_SHORT;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t deSerialize(T *object, const uint8_t **buffer,
|
||||
size_t *size, SerializeIF::Endianness streamEndianness) {
|
||||
T tmp;
|
||||
if (*size >= sizeof(T)) {
|
||||
*size -= sizeof(T);
|
||||
std::memcpy(&tmp, *buffer, sizeof(T));
|
||||
switch (streamEndianness) {
|
||||
case SerializeIF::Endianness::BIG:
|
||||
*object = EndianConverter::convertBigEndian<T>(tmp);
|
||||
break;
|
||||
case SerializeIF::Endianness::LITTLE:
|
||||
*object = EndianConverter::convertLittleEndian<T>(tmp);
|
||||
break;
|
||||
default:
|
||||
case SerializeIF::Endianness::MACHINE:
|
||||
*object = tmp;
|
||||
break;
|
||||
}
|
||||
ReturnValue_t deSerialize(T *object, const uint8_t **buffer,
|
||||
size_t *size, SerializeIF::Endianness streamEndianness) {
|
||||
T tmp;
|
||||
if (*size >= sizeof(T)) {
|
||||
*size -= sizeof(T);
|
||||
std::memcpy(&tmp, *buffer, sizeof(T));
|
||||
switch (streamEndianness) {
|
||||
case SerializeIF::Endianness::BIG:
|
||||
*object = EndianConverter::convertBigEndian<T>(tmp);
|
||||
break;
|
||||
case SerializeIF::Endianness::LITTLE:
|
||||
*object = EndianConverter::convertLittleEndian<T>(tmp);
|
||||
break;
|
||||
default:
|
||||
case SerializeIF::Endianness::MACHINE:
|
||||
*object = tmp;
|
||||
break;
|
||||
}
|
||||
|
||||
*buffer += sizeof(T);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return SerializeIF::STREAM_TOO_SHORT;
|
||||
}
|
||||
}
|
||||
*buffer += sizeof(T);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return SerializeIF::STREAM_TOO_SHORT;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t getSerializedSize(const T *object) {
|
||||
return sizeof(T);
|
||||
}
|
||||
};
|
||||
uint32_t getSerializedSize(const T *object) {
|
||||
return sizeof(T);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Template for objects that inherit from SerializeIF
|
||||
*
|
||||
* @tparam T A child of SerializeIF
|
||||
*/
|
||||
template<typename T>
|
||||
class InternalSerializeAdapter<T, true> {
|
||||
public:
|
||||
ReturnValue_t serialize(const T *object, uint8_t **buffer, size_t *size,
|
||||
size_t max_size,
|
||||
SerializeIF::Endianness streamEndianness) const {
|
||||
size_t ignoredSize = 0;
|
||||
if (size == nullptr) {
|
||||
size = &ignoredSize;
|
||||
}
|
||||
return object->serialize(buffer, size, max_size, streamEndianness);
|
||||
}
|
||||
size_t getSerializedSize(const T *object) const {
|
||||
return object->getSerializedSize();
|
||||
}
|
||||
/**
|
||||
* Template for objects that inherit from SerializeIF
|
||||
*
|
||||
* @tparam T A child of SerializeIF
|
||||
*/
|
||||
template<typename T>
|
||||
class InternalSerializeAdapter<T, true> {
|
||||
public:
|
||||
ReturnValue_t serialize(const T *object, uint8_t **buffer, size_t *size,
|
||||
size_t max_size,
|
||||
SerializeIF::Endianness streamEndianness) const {
|
||||
size_t ignoredSize = 0;
|
||||
if (size == nullptr) {
|
||||
size = &ignoredSize;
|
||||
}
|
||||
return object->serialize(buffer, size, max_size, streamEndianness);
|
||||
}
|
||||
size_t getSerializedSize(const T *object) const {
|
||||
return object->getSerializedSize();
|
||||
}
|
||||
|
||||
ReturnValue_t deSerialize(T *object, const uint8_t **buffer,
|
||||
size_t *size, SerializeIF::Endianness streamEndianness) {
|
||||
return object->deSerialize(buffer, size, streamEndianness);
|
||||
}
|
||||
};
|
||||
ReturnValue_t deSerialize(T *object, const uint8_t **buffer,
|
||||
size_t *size, SerializeIF::Endianness streamEndianness) {
|
||||
return object->deSerialize(buffer, size, streamEndianness);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
#endif /* _FSFW_SERIALIZE_SERIALIZEADAPTER_H_ */
|
||||
|
@@ -62,8 +62,7 @@ protected:
|
||||
struct ChildInfo {
|
||||
MessageQueueId_t commandQueue;
|
||||
Mode_t mode;
|
||||
Submode_t submode;
|
||||
bool healthChanged;
|
||||
Submode_t submode;bool healthChanged;
|
||||
};
|
||||
|
||||
Mode_t mode;
|
||||
|
@@ -73,16 +73,16 @@ namespace spacepacket {
|
||||
|
||||
constexpr uint16_t getSpacePacketIdFromApid(bool isTc, uint16_t apid,
|
||||
bool secondaryHeaderFlag = true) {
|
||||
return (((isTc << 5) & 0x10) | ((secondaryHeaderFlag << 4) & 0x08) |
|
||||
return ((isTc << 4) | (secondaryHeaderFlag << 3) |
|
||||
((apid >> 8) & 0x07)) << 8 | (apid & 0x00ff);
|
||||
}
|
||||
|
||||
constexpr uint16_t getTcSpacketIdFromApid(uint16_t apid,
|
||||
constexpr uint16_t getTcSpacePacketIdFromApid(uint16_t apid,
|
||||
bool secondaryHeaderFlag = true) {
|
||||
return getSpacePacketIdFromApid(true, apid, secondaryHeaderFlag);
|
||||
}
|
||||
|
||||
constexpr uint16_t getTmSpacketIdFromApid(uint16_t apid,
|
||||
constexpr uint16_t getTmSpacePacketIdFromApid(uint16_t apid,
|
||||
bool secondaryHeaderFlag = true) {
|
||||
return getSpacePacketIdFromApid(false, apid, secondaryHeaderFlag);
|
||||
}
|
||||
|
@@ -1,8 +1,9 @@
|
||||
|
||||
if(FSFW_ADD_INTERNAL_TESTS)
|
||||
add_subdirectory(internal)
|
||||
endif()
|
||||
|
||||
if(FSFW_BUILD_UNITTESTS)
|
||||
add_subdirectory(unit)
|
||||
else()
|
||||
add_subdirectory(integration)
|
||||
endif()
|
||||
|
4
tests/src/fsfw_tests/integration/CMakeLists.txt
Normal file
4
tests/src/fsfw_tests/integration/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
add_subdirectory(assemblies)
|
||||
add_subdirectory(controller)
|
||||
add_subdirectory(devices)
|
||||
add_subdirectory(task)
|
@@ -0,0 +1,3 @@
|
||||
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||
TestAssembly.cpp
|
||||
)
|
201
tests/src/fsfw_tests/integration/assemblies/TestAssembly.cpp
Normal file
201
tests/src/fsfw_tests/integration/assemblies/TestAssembly.cpp
Normal file
@@ -0,0 +1,201 @@
|
||||
#include "TestAssembly.h"
|
||||
|
||||
#include <fsfw/objectmanager/ObjectManager.h>
|
||||
|
||||
|
||||
TestAssembly::TestAssembly(object_id_t objectId, object_id_t parentId, object_id_t testDevice0,
|
||||
object_id_t testDevice1):
|
||||
AssemblyBase(objectId, parentId), deviceHandler0Id(testDevice0),
|
||||
deviceHandler1Id(testDevice1) {
|
||||
ModeListEntry newModeListEntry;
|
||||
newModeListEntry.setObject(testDevice0);
|
||||
newModeListEntry.setMode(MODE_OFF);
|
||||
newModeListEntry.setSubmode(SUBMODE_NONE);
|
||||
|
||||
commandTable.insert(newModeListEntry);
|
||||
|
||||
newModeListEntry.setObject(testDevice1);
|
||||
newModeListEntry.setMode(MODE_OFF);
|
||||
newModeListEntry.setSubmode(SUBMODE_NONE);
|
||||
|
||||
commandTable.insert(newModeListEntry);
|
||||
|
||||
}
|
||||
|
||||
TestAssembly::~TestAssembly() {
|
||||
}
|
||||
|
||||
ReturnValue_t TestAssembly::commandChildren(Mode_t mode,
|
||||
Submode_t submode) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestAssembly: Received command to go to mode " << mode <<
|
||||
" submode " << (int) submode << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestAssembly: Received command to go to mode %d submode %d\n", mode, submode);
|
||||
#endif
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
if(mode == MODE_OFF){
|
||||
commandTable[0].setMode(MODE_OFF);
|
||||
commandTable[0].setSubmode(SUBMODE_NONE);
|
||||
commandTable[1].setMode(MODE_OFF);
|
||||
commandTable[1].setSubmode(SUBMODE_NONE);
|
||||
}
|
||||
else if(mode == DeviceHandlerIF::MODE_NORMAL) {
|
||||
if(submode == submodes::SINGLE){
|
||||
commandTable[0].setMode(MODE_OFF);
|
||||
commandTable[0].setSubmode(SUBMODE_NONE);
|
||||
commandTable[1].setMode(MODE_OFF);
|
||||
commandTable[1].setSubmode(SUBMODE_NONE);
|
||||
// We try to prefer 0 here but we try to switch to 1 even if it might fail
|
||||
if(isDeviceAvailable(deviceHandler0Id)) {
|
||||
if (childrenMap[deviceHandler0Id].mode == MODE_ON) {
|
||||
commandTable[0].setMode(mode);
|
||||
commandTable[0].setSubmode(SUBMODE_NONE);
|
||||
}
|
||||
else {
|
||||
commandTable[0].setMode(MODE_ON);
|
||||
commandTable[0].setSubmode(SUBMODE_NONE);
|
||||
result = NEED_SECOND_STEP;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (childrenMap[deviceHandler1Id].mode == MODE_ON) {
|
||||
commandTable[1].setMode(mode);
|
||||
commandTable[1].setSubmode(SUBMODE_NONE);
|
||||
}
|
||||
else{
|
||||
commandTable[1].setMode(MODE_ON);
|
||||
commandTable[1].setSubmode(SUBMODE_NONE);
|
||||
result = NEED_SECOND_STEP;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
// Dual Mode Normal
|
||||
if (childrenMap[deviceHandler0Id].mode == MODE_ON) {
|
||||
commandTable[0].setMode(mode);
|
||||
commandTable[0].setSubmode(SUBMODE_NONE);
|
||||
}
|
||||
else{
|
||||
commandTable[0].setMode(MODE_ON);
|
||||
commandTable[0].setSubmode(SUBMODE_NONE);
|
||||
result = NEED_SECOND_STEP;
|
||||
}
|
||||
if (childrenMap[deviceHandler1Id].mode == MODE_ON) {
|
||||
commandTable[1].setMode(mode);
|
||||
commandTable[1].setSubmode(SUBMODE_NONE);
|
||||
}
|
||||
else{
|
||||
commandTable[1].setMode(MODE_ON);
|
||||
commandTable[1].setSubmode(SUBMODE_NONE);
|
||||
result = NEED_SECOND_STEP;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
//Mode ON
|
||||
if(submode == submodes::SINGLE){
|
||||
commandTable[0].setMode(MODE_OFF);
|
||||
commandTable[0].setSubmode(SUBMODE_NONE);
|
||||
commandTable[1].setMode(MODE_OFF);
|
||||
commandTable[1].setSubmode(SUBMODE_NONE);
|
||||
// We try to prefer 0 here but we try to switch to 1 even if it might fail
|
||||
if(isDeviceAvailable(deviceHandler0Id)){
|
||||
commandTable[0].setMode(MODE_ON);
|
||||
commandTable[0].setSubmode(SUBMODE_NONE);
|
||||
}
|
||||
else{
|
||||
commandTable[1].setMode(MODE_ON);
|
||||
commandTable[1].setSubmode(SUBMODE_NONE);
|
||||
}
|
||||
}
|
||||
else{
|
||||
commandTable[0].setMode(MODE_ON);
|
||||
commandTable[0].setSubmode(SUBMODE_NONE);
|
||||
commandTable[1].setMode(MODE_ON);
|
||||
commandTable[1].setSubmode(SUBMODE_NONE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
HybridIterator<ModeListEntry> iter(commandTable.begin(),
|
||||
commandTable.end());
|
||||
executeTable(iter);
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t TestAssembly::isModeCombinationValid(Mode_t mode,
|
||||
Submode_t submode) {
|
||||
switch (mode) {
|
||||
case MODE_OFF:
|
||||
if (submode == SUBMODE_NONE) {
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
return INVALID_SUBMODE;
|
||||
}
|
||||
case DeviceHandlerIF::MODE_NORMAL:
|
||||
case MODE_ON:
|
||||
if (submode < 3) {
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
return INVALID_SUBMODE;
|
||||
}
|
||||
}
|
||||
return INVALID_MODE;
|
||||
}
|
||||
|
||||
ReturnValue_t TestAssembly::initialize() {
|
||||
ReturnValue_t result = AssemblyBase::initialize();
|
||||
if(result != RETURN_OK){
|
||||
return result;
|
||||
}
|
||||
handler0 = ObjectManager::instance()->get<TestDevice>(deviceHandler0Id);
|
||||
handler1 = ObjectManager::instance()->get<TestDevice>(deviceHandler1Id);
|
||||
if((handler0 == nullptr) or (handler1 == nullptr)){
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
handler0->setParentQueue(this->getCommandQueue());
|
||||
handler1->setParentQueue(this->getCommandQueue());
|
||||
|
||||
|
||||
result = registerChild(deviceHandler0Id);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = registerChild(deviceHandler1Id);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t TestAssembly::checkChildrenStateOn(
|
||||
Mode_t wantedMode, Submode_t wantedSubmode) {
|
||||
if(submode == submodes::DUAL){
|
||||
for(const auto& info:childrenMap) {
|
||||
if(info.second.mode != wantedMode or info.second.mode != wantedSubmode){
|
||||
return NOT_ENOUGH_CHILDREN_IN_CORRECT_STATE;
|
||||
}
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
else if(submode == submodes::SINGLE) {
|
||||
for(const auto& info:childrenMap) {
|
||||
if(info.second.mode == wantedMode and info.second.mode != wantedSubmode){
|
||||
return RETURN_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
return INVALID_SUBMODE;
|
||||
}
|
||||
|
||||
bool TestAssembly::isDeviceAvailable(object_id_t object) {
|
||||
if(healthHelper.healthTable->getHealth(object) == HasHealthIF::HEALTHY){
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
56
tests/src/fsfw_tests/integration/assemblies/TestAssembly.h
Normal file
56
tests/src/fsfw_tests/integration/assemblies/TestAssembly.h
Normal file
@@ -0,0 +1,56 @@
|
||||
#ifndef MISSION_ASSEMBLIES_TESTASSEMBLY_H_
|
||||
#define MISSION_ASSEMBLIES_TESTASSEMBLY_H_
|
||||
|
||||
#include <fsfw/devicehandlers/AssemblyBase.h>
|
||||
#include "../devices/TestDeviceHandler.h"
|
||||
|
||||
class TestAssembly: public AssemblyBase {
|
||||
public:
|
||||
TestAssembly(object_id_t objectId, object_id_t parentId, object_id_t testDevice0,
|
||||
object_id_t testDevice1);
|
||||
virtual ~TestAssembly();
|
||||
ReturnValue_t initialize() override;
|
||||
|
||||
enum submodes: Submode_t{
|
||||
SINGLE = 0,
|
||||
DUAL = 1
|
||||
};
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Command children to reach [mode,submode] combination
|
||||
* Can be done by setting #commandsOutstanding correctly,
|
||||
* or using executeTable()
|
||||
* @param mode
|
||||
* @param submode
|
||||
* @return
|
||||
* - @c RETURN_OK if ok
|
||||
* - @c NEED_SECOND_STEP if children need to be commanded again
|
||||
*/
|
||||
ReturnValue_t commandChildren(Mode_t mode, Submode_t submode) override;
|
||||
/**
|
||||
* Check whether desired assembly mode was achieved by checking the modes
|
||||
* or/and health states of child device handlers.
|
||||
* The assembly template class will also call this function if a health
|
||||
* or mode change of a child device handler was detected.
|
||||
* @param wantedMode
|
||||
* @param wantedSubmode
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t isModeCombinationValid(Mode_t mode, Submode_t submode)
|
||||
override;
|
||||
|
||||
ReturnValue_t checkChildrenStateOn(Mode_t wantedMode,
|
||||
Submode_t wantedSubmode) override;
|
||||
private:
|
||||
FixedArrayList<ModeListEntry, 2> commandTable;
|
||||
object_id_t deviceHandler0Id = 0;
|
||||
object_id_t deviceHandler1Id = 0;
|
||||
TestDevice* handler0 = nullptr;
|
||||
TestDevice* handler1 = nullptr;
|
||||
|
||||
|
||||
bool isDeviceAvailable(object_id_t object);
|
||||
};
|
||||
|
||||
#endif /* MISSION_ASSEMBLIES_TESTASSEMBLY_H_ */
|
@@ -0,0 +1,3 @@
|
||||
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||
TestController.cpp
|
||||
)
|
@@ -0,0 +1,48 @@
|
||||
#include "TestController.h"
|
||||
|
||||
#include <fsfw/datapool/PoolReadGuard.h>
|
||||
#include <fsfw/objectmanager/ObjectManager.h>
|
||||
#include <fsfw/serviceinterface/ServiceInterface.h>
|
||||
|
||||
TestController::TestController(object_id_t objectId, object_id_t parentId,
|
||||
size_t commandQueueDepth):
|
||||
ExtendedControllerBase(objectId, parentId, commandQueueDepth) {
|
||||
}
|
||||
|
||||
TestController::~TestController() {
|
||||
}
|
||||
|
||||
ReturnValue_t TestController::handleCommandMessage(CommandMessage *message) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void TestController::performControlOperation() {
|
||||
|
||||
}
|
||||
|
||||
void TestController::handleChangedDataset(sid_t sid, store_address_t storeId, bool* clearMessage) {
|
||||
|
||||
}
|
||||
|
||||
void TestController::handleChangedPoolVariable(gp_id_t globPoolId, store_address_t storeId,
|
||||
bool* clearMessage) {
|
||||
}
|
||||
|
||||
LocalPoolDataSetBase* TestController::getDataSetHandle(sid_t sid) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ReturnValue_t TestController::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||
LocalDataPoolManager &poolManager) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t TestController::initializeAfterTaskCreation() {
|
||||
return ExtendedControllerBase::initializeAfterTaskCreation();
|
||||
}
|
||||
|
||||
ReturnValue_t TestController::checkModeCommand(Mode_t mode, Submode_t submode,
|
||||
uint32_t *msToReachTheMode) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
38
tests/src/fsfw_tests/integration/controller/TestController.h
Normal file
38
tests/src/fsfw_tests/integration/controller/TestController.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#ifndef MISSION_CONTROLLER_TESTCONTROLLER_H_
|
||||
#define MISSION_CONTROLLER_TESTCONTROLLER_H_
|
||||
|
||||
#include "../devices/devicedefinitions/testDeviceDefinitions.h"
|
||||
#include <fsfw/controller/ExtendedControllerBase.h>
|
||||
|
||||
|
||||
class TestController:
|
||||
public ExtendedControllerBase {
|
||||
public:
|
||||
TestController(object_id_t objectId, object_id_t parentId, size_t commandQueueDepth = 10);
|
||||
virtual~ TestController();
|
||||
protected:
|
||||
|
||||
// Extended Controller Base overrides
|
||||
ReturnValue_t handleCommandMessage(CommandMessage *message) override;
|
||||
void performControlOperation() override;
|
||||
|
||||
// HasLocalDatapoolIF callbacks
|
||||
virtual void handleChangedDataset(sid_t sid, store_address_t storeId,
|
||||
bool* clearMessage) override;
|
||||
virtual void handleChangedPoolVariable(gp_id_t globPoolId, store_address_t storeId,
|
||||
bool* clearMessage) override;
|
||||
|
||||
LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override;
|
||||
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
||||
LocalDataPoolManager& poolManager) override;
|
||||
|
||||
ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
|
||||
uint32_t *msToReachTheMode) override;
|
||||
|
||||
ReturnValue_t initializeAfterTaskCreation() override;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif /* MISSION_CONTROLLER_TESTCONTROLLER_H_ */
|
@@ -0,0 +1,18 @@
|
||||
#ifndef MISSION_CONTROLLER_CTRLDEFINITIONS_TESTCTRLDEFINITIONS_H_
|
||||
#define MISSION_CONTROLLER_CTRLDEFINITIONS_TESTCTRLDEFINITIONS_H_
|
||||
|
||||
#include <fsfw/objectmanager/SystemObjectIF.h>
|
||||
#include <OBSWConfig.h>
|
||||
|
||||
namespace testcontroller {
|
||||
|
||||
enum sourceObjectIds: object_id_t {
|
||||
DEVICE_0_ID = objects::TEST_DEVICE_HANDLER_0,
|
||||
DEVICE_1_ID = objects::TEST_DEVICE_HANDLER_1,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* MISSION_CONTROLLER_CTRLDEFINITIONS_TESTCTRLDEFINITIONS_H_ */
|
5
tests/src/fsfw_tests/integration/devices/CMakeLists.txt
Normal file
5
tests/src/fsfw_tests/integration/devices/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||
TestCookie.cpp
|
||||
TestDeviceHandler.cpp
|
||||
TestEchoComIF.cpp
|
||||
)
|
14
tests/src/fsfw_tests/integration/devices/TestCookie.cpp
Normal file
14
tests/src/fsfw_tests/integration/devices/TestCookie.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "TestCookie.h"
|
||||
|
||||
TestCookie::TestCookie(address_t address, size_t replyMaxLen):
|
||||
address(address), replyMaxLen(replyMaxLen) {}
|
||||
|
||||
TestCookie::~TestCookie() {}
|
||||
|
||||
address_t TestCookie::getAddress() const {
|
||||
return address;
|
||||
}
|
||||
|
||||
size_t TestCookie::getReplyMaxLen() const {
|
||||
return replyMaxLen;
|
||||
}
|
22
tests/src/fsfw_tests/integration/devices/TestCookie.h
Normal file
22
tests/src/fsfw_tests/integration/devices/TestCookie.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef MISSION_DEVICES_TESTCOOKIE_H_
|
||||
#define MISSION_DEVICES_TESTCOOKIE_H_
|
||||
|
||||
#include <fsfw/devicehandlers/CookieIF.h>
|
||||
#include <cstddef>
|
||||
|
||||
/**
|
||||
* @brief Really simple cookie which does not do a lot.
|
||||
*/
|
||||
class TestCookie: public CookieIF {
|
||||
public:
|
||||
TestCookie(address_t address, size_t maxReplyLen);
|
||||
virtual ~TestCookie();
|
||||
|
||||
address_t getAddress() const;
|
||||
size_t getReplyMaxLen() const;
|
||||
private:
|
||||
address_t address = 0;
|
||||
size_t replyMaxLen = 0;
|
||||
};
|
||||
|
||||
#endif /* MISSION_DEVICES_TESTCOOKIE_H_ */
|
798
tests/src/fsfw_tests/integration/devices/TestDeviceHandler.cpp
Normal file
798
tests/src/fsfw_tests/integration/devices/TestDeviceHandler.cpp
Normal file
@@ -0,0 +1,798 @@
|
||||
#include "TestDeviceHandler.h"
|
||||
#include "FSFWConfig.h"
|
||||
|
||||
#include "fsfw/datapool/PoolReadGuard.h"
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
TestDevice::TestDevice(object_id_t objectId, object_id_t comIF,
|
||||
CookieIF * cookie, testdevice::DeviceIndex deviceIdx, bool fullInfoPrintout,
|
||||
bool changingDataset):
|
||||
DeviceHandlerBase(objectId, comIF, cookie), deviceIdx(deviceIdx),
|
||||
dataset(this), fullInfoPrintout(fullInfoPrintout) {
|
||||
}
|
||||
|
||||
TestDevice::~TestDevice() {}
|
||||
|
||||
void TestDevice::performOperationHook() {
|
||||
if(periodicPrintout) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::performOperationHook: Alive!" << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::performOperationHook: Alive!", deviceIdx);
|
||||
#endif
|
||||
}
|
||||
|
||||
if(oneShot) {
|
||||
oneShot = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TestDevice::doStartUp() {
|
||||
if(fullInfoPrintout) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::doStartUp: Switching On" << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::doStartUp: Switching On\n", static_cast<int>(deviceIdx));
|
||||
#endif
|
||||
}
|
||||
|
||||
setMode(_MODE_TO_ON);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void TestDevice::doShutDown() {
|
||||
if(fullInfoPrintout) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::doShutDown: Switching Off" << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::doShutDown: Switching Off\n", static_cast<int>(deviceIdx));
|
||||
#endif
|
||||
}
|
||||
|
||||
setMode(_MODE_SHUT_DOWN);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t TestDevice::buildNormalDeviceCommand(DeviceCommandId_t* id) {
|
||||
using namespace testdevice;
|
||||
*id = TEST_NORMAL_MODE_CMD;
|
||||
if(DeviceHandlerBase::isAwaitingReply()) {
|
||||
return NOTHING_TO_SEND;
|
||||
}
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
|
||||
ReturnValue_t TestDevice::buildTransitionDeviceCommand(DeviceCommandId_t* id) {
|
||||
if(mode == _MODE_TO_ON) {
|
||||
if(fullInfoPrintout) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::buildTransitionDeviceCommand: Was called"
|
||||
" from _MODE_TO_ON mode" << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::buildTransitionDeviceCommand: "
|
||||
"Was called from _MODE_TO_ON mode\n", deviceIdx);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
if(mode == _MODE_TO_NORMAL) {
|
||||
if(fullInfoPrintout) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::buildTransitionDeviceCommand: Was called "
|
||||
"from _MODE_TO_NORMAL mode" << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::buildTransitionDeviceCommand: Was called from "
|
||||
" _MODE_TO_NORMAL mode\n", deviceIdx);
|
||||
#endif
|
||||
}
|
||||
|
||||
setMode(MODE_NORMAL);
|
||||
}
|
||||
if(mode == _MODE_SHUT_DOWN) {
|
||||
if(fullInfoPrintout) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::buildTransitionDeviceCommand: Was called "
|
||||
"from _MODE_SHUT_DOWN mode" << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::buildTransitionDeviceCommand: Was called from "
|
||||
"_MODE_SHUT_DOWN mode\n", deviceIdx);
|
||||
#endif
|
||||
}
|
||||
|
||||
setMode(MODE_OFF);
|
||||
}
|
||||
return NOTHING_TO_SEND;
|
||||
}
|
||||
|
||||
void TestDevice::doTransition(Mode_t modeFrom, Submode_t submodeFrom) {
|
||||
if(mode == _MODE_TO_NORMAL) {
|
||||
if(fullInfoPrintout) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::doTransition: Custom transition to "
|
||||
"normal mode" << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::doTransition: Custom transition to normal mode\n",
|
||||
deviceIdx);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
DeviceHandlerBase::doTransition(modeFrom, submodeFrom);
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t TestDevice::buildCommandFromCommand(
|
||||
DeviceCommandId_t deviceCommand, const uint8_t* commandData,
|
||||
size_t commandDataLen) {
|
||||
using namespace testdevice;
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
switch(deviceCommand) {
|
||||
case(TEST_NORMAL_MODE_CMD): {
|
||||
commandSent = true;
|
||||
result = buildNormalModeCommand(deviceCommand, commandData, commandDataLen);
|
||||
break;
|
||||
}
|
||||
|
||||
case(TEST_COMMAND_0): {
|
||||
commandSent = true;
|
||||
result = buildTestCommand0(deviceCommand, commandData, commandDataLen);
|
||||
break;
|
||||
}
|
||||
|
||||
case(TEST_COMMAND_1): {
|
||||
commandSent = true;
|
||||
result = buildTestCommand1(deviceCommand, commandData, commandDataLen);
|
||||
break;
|
||||
}
|
||||
case(TEST_NOTIF_SNAPSHOT_VAR): {
|
||||
if(changingDatasets) {
|
||||
changingDatasets = false;
|
||||
}
|
||||
|
||||
PoolReadGuard readHelper(&dataset.testUint8Var);
|
||||
if(deviceIdx == testdevice::DeviceIndex::DEVICE_0) {
|
||||
/* This will trigger a variable notification to the demo controller */
|
||||
dataset.testUint8Var = 220;
|
||||
dataset.testUint8Var.setValid(true);
|
||||
}
|
||||
else if(deviceIdx == testdevice::DeviceIndex::DEVICE_1) {
|
||||
/* This will trigger a variable snapshot to the demo controller */
|
||||
dataset.testUint8Var = 30;
|
||||
dataset.testUint8Var.setValid(true);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case(TEST_NOTIF_SNAPSHOT_SET): {
|
||||
if(changingDatasets) {
|
||||
changingDatasets = false;
|
||||
}
|
||||
|
||||
PoolReadGuard readHelper(&dataset.testFloat3Vec);
|
||||
|
||||
if(deviceIdx == testdevice::DeviceIndex::DEVICE_0) {
|
||||
/* This will trigger a variable notification to the demo controller */
|
||||
dataset.testFloat3Vec.value[0] = 60;
|
||||
dataset.testFloat3Vec.value[1] = 70;
|
||||
dataset.testFloat3Vec.value[2] = 55;
|
||||
dataset.testFloat3Vec.setValid(true);
|
||||
}
|
||||
else if(deviceIdx == testdevice::DeviceIndex::DEVICE_1) {
|
||||
/* This will trigger a variable notification to the demo controller */
|
||||
dataset.testFloat3Vec.value[0] = -60;
|
||||
dataset.testFloat3Vec.value[1] = -70;
|
||||
dataset.testFloat3Vec.value[2] = -55;
|
||||
dataset.testFloat3Vec.setValid(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
result = DeviceHandlerIF::COMMAND_NOT_SUPPORTED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t TestDevice::buildNormalModeCommand(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t* commandData, size_t commandDataLen) {
|
||||
if(fullInfoPrintout) {
|
||||
#if OBSW_VERBOSE_LEVEL >= 3
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice::buildTestCommand1: Building normal command" << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice::buildTestCommand1: Building command from TEST_COMMAND_1\n");
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
#endif /* OBSW_VERBOSE_LEVEL >= 3 */
|
||||
}
|
||||
|
||||
if(commandDataLen > MAX_BUFFER_SIZE - sizeof(DeviceCommandId_t)) {
|
||||
return DeviceHandlerIF::INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS;
|
||||
}
|
||||
/* The command is passed on in the command buffer as it is */
|
||||
passOnCommand(deviceCommand, commandData, commandDataLen);
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t TestDevice::buildTestCommand0(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t* commandData, size_t commandDataLen) {
|
||||
using namespace testdevice;
|
||||
if(fullInfoPrintout) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::buildTestCommand0: Executing simple command "
|
||||
" with completion reply" << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::buildTestCommand0: Executing simple command with "
|
||||
"completion reply\n", deviceIdx);
|
||||
#endif
|
||||
}
|
||||
|
||||
if(commandDataLen > MAX_BUFFER_SIZE - sizeof(DeviceCommandId_t)) {
|
||||
return DeviceHandlerIF::INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS;
|
||||
}
|
||||
|
||||
/* The command is passed on in the command buffer as it is */
|
||||
passOnCommand(deviceCommand, commandData, commandDataLen);
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t TestDevice::buildTestCommand1(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t* commandData,
|
||||
size_t commandDataLen) {
|
||||
using namespace testdevice;
|
||||
if(commandDataLen < 7) {
|
||||
return DeviceHandlerIF::INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS;
|
||||
}
|
||||
if(fullInfoPrintout) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::buildTestCommand1: Executing command with "
|
||||
"data reply" << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d:buildTestCommand1: Executing command with data reply\n",
|
||||
deviceIdx);
|
||||
#endif
|
||||
}
|
||||
|
||||
deviceCommand = EndianConverter::convertBigEndian(deviceCommand);
|
||||
memcpy(commandBuffer, &deviceCommand, sizeof(deviceCommand));
|
||||
|
||||
/* Assign and check parameters */
|
||||
uint16_t parameter1 = 0;
|
||||
size_t size = commandDataLen;
|
||||
ReturnValue_t result = SerializeAdapter::deSerialize(¶meter1,
|
||||
&commandData, &size, SerializeIF::Endianness::BIG);
|
||||
if(result == HasReturnvaluesIF::RETURN_FAILED) {
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Parameter 1 needs to be correct */
|
||||
if(parameter1 != testdevice::COMMAND_1_PARAM1) {
|
||||
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
||||
}
|
||||
uint64_t parameter2 = 0;
|
||||
result = SerializeAdapter::deSerialize(¶meter2,
|
||||
&commandData, &size, SerializeIF::Endianness::BIG);
|
||||
if(parameter2!= testdevice::COMMAND_1_PARAM2){
|
||||
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
|
||||
}
|
||||
|
||||
/* Pass on the parameters to the Echo IF */
|
||||
commandBuffer[4] = (parameter1 & 0xFF00) >> 8;
|
||||
commandBuffer[5] = (parameter1 & 0xFF);
|
||||
parameter2 = EndianConverter::convertBigEndian(parameter2);
|
||||
memcpy(commandBuffer + 6, ¶meter2, sizeof(parameter2));
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = sizeof(deviceCommand) + sizeof(parameter1) +
|
||||
sizeof(parameter2);
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
void TestDevice::passOnCommand(DeviceCommandId_t command, const uint8_t *commandData,
|
||||
size_t commandDataLen) {
|
||||
DeviceCommandId_t deviceCommandBe = EndianConverter::convertBigEndian(command);
|
||||
memcpy(commandBuffer, &deviceCommandBe, sizeof(deviceCommandBe));
|
||||
memcpy(commandBuffer + 4, commandData, commandDataLen);
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = sizeof(deviceCommandBe) + commandDataLen;
|
||||
}
|
||||
|
||||
void TestDevice::fillCommandAndReplyMap() {
|
||||
namespace td = testdevice;
|
||||
insertInCommandAndReplyMap(testdevice::TEST_NORMAL_MODE_CMD, 5, &dataset);
|
||||
insertInCommandAndReplyMap(testdevice::TEST_COMMAND_0, 5);
|
||||
insertInCommandAndReplyMap(testdevice::TEST_COMMAND_1, 5);
|
||||
|
||||
/* No reply expected for these commands */
|
||||
insertInCommandMap(td::TEST_NOTIF_SNAPSHOT_SET);
|
||||
insertInCommandMap(td::TEST_NOTIF_SNAPSHOT_VAR);
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t TestDevice::scanForReply(const uint8_t *start, size_t len,
|
||||
DeviceCommandId_t *foundId, size_t *foundLen) {
|
||||
using namespace testdevice;
|
||||
|
||||
/* Unless a command was sent explicitely, we don't expect any replies and ignore this
|
||||
the packet. On a real device, there might be replies which are sent without a previous
|
||||
command. */
|
||||
if(not commandSent) {
|
||||
return DeviceHandlerBase::IGNORE_FULL_PACKET;
|
||||
}
|
||||
else {
|
||||
commandSent = false;
|
||||
}
|
||||
|
||||
if(len < sizeof(object_id_t)) {
|
||||
return DeviceHandlerIF::LENGTH_MISSMATCH;
|
||||
}
|
||||
|
||||
size_t size = len;
|
||||
ReturnValue_t result = SerializeAdapter::deSerialize(foundId, &start, &size,
|
||||
SerializeIF::Endianness::BIG);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
DeviceCommandId_t pendingCmd = this->getPendingCommand();
|
||||
|
||||
switch(pendingCmd) {
|
||||
|
||||
case(TEST_NORMAL_MODE_CMD): {
|
||||
if(fullInfoPrintout) {
|
||||
#if OBSW_VERBOSE_LEVEL >= 3
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice::scanForReply: Reply for normal commnand (ID " <<
|
||||
TEST_NORMAL_MODE_CMD << ") received!" << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::scanForReply: Reply for normal command (ID %d) "
|
||||
"received!\n", deviceIdx, TEST_NORMAL_MODE_CMD);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
*foundLen = len;
|
||||
*foundId = pendingCmd;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
case(TEST_COMMAND_0): {
|
||||
if(len < TEST_COMMAND_0_SIZE) {
|
||||
return DeviceHandlerIF::LENGTH_MISSMATCH;
|
||||
}
|
||||
if(fullInfoPrintout) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::scanForReply: Reply for simple command "
|
||||
"(ID " << TEST_COMMAND_0 << ") received!" << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::scanForReply: Reply for simple command (ID %d) "
|
||||
"received!\n", deviceIdx, TEST_COMMAND_0);
|
||||
#endif
|
||||
}
|
||||
|
||||
*foundLen = TEST_COMMAND_0_SIZE;
|
||||
*foundId = pendingCmd;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
case(TEST_COMMAND_1): {
|
||||
if(fullInfoPrintout) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::scanForReply: Reply for data command "
|
||||
"(ID " << TEST_COMMAND_1 << ") received!" << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::scanForReply: Reply for data command (ID %d) "
|
||||
"received\n", deviceIdx, TEST_COMMAND_1);
|
||||
#endif
|
||||
}
|
||||
|
||||
*foundLen = len;
|
||||
*foundId = pendingCmd;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
default:
|
||||
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t TestDevice::interpretDeviceReply(DeviceCommandId_t id,
|
||||
const uint8_t* packet) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
switch(id) {
|
||||
/* Periodic replies */
|
||||
case testdevice::TEST_NORMAL_MODE_CMD: {
|
||||
result = interpretingNormalModeReply();
|
||||
break;
|
||||
}
|
||||
/* Simple reply */
|
||||
case testdevice::TEST_COMMAND_0: {
|
||||
result = interpretingTestReply0(id, packet);
|
||||
break;
|
||||
}
|
||||
/* Data reply */
|
||||
case testdevice::TEST_COMMAND_1: {
|
||||
result = interpretingTestReply1(id, packet);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return DeviceHandlerIF::DEVICE_REPLY_INVALID;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t TestDevice::interpretingNormalModeReply() {
|
||||
CommandMessage directReplyMessage;
|
||||
if(changingDatasets) {
|
||||
PoolReadGuard readHelper(&dataset);
|
||||
if(dataset.testUint8Var.value == 0) {
|
||||
dataset.testUint8Var.value = 10;
|
||||
dataset.testUint32Var.value = 777;
|
||||
dataset.testFloat3Vec.value[0] = 2.5;
|
||||
dataset.testFloat3Vec.value[1] = -2.5;
|
||||
dataset.testFloat3Vec.value[2] = 2.5;
|
||||
dataset.setValidity(true, true);
|
||||
}
|
||||
else {
|
||||
dataset.testUint8Var.value = 0;
|
||||
dataset.testUint32Var.value = 0;
|
||||
dataset.testFloat3Vec.value[0] = 0.0;
|
||||
dataset.testFloat3Vec.value[1] = 0.0;
|
||||
dataset.testFloat3Vec.value[2] = 0.0;
|
||||
dataset.setValidity(false, true);
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
PoolReadGuard readHelper(&dataset);
|
||||
if(dataset.testUint8Var.value == 0) {
|
||||
/* Reset state */
|
||||
dataset.testUint8Var.value = 128;
|
||||
}
|
||||
else if(dataset.testUint8Var.value > 200) {
|
||||
if(not resetAfterChange) {
|
||||
/* This will trigger an update notification to the controller */
|
||||
dataset.testUint8Var.setChanged(true);
|
||||
resetAfterChange = true;
|
||||
/* Decrement by 30 automatically. This will prevent any additional notifications. */
|
||||
dataset.testUint8Var.value -= 30;
|
||||
}
|
||||
}
|
||||
/* If the value is greater than 0, it will be decremented in a linear way */
|
||||
else if(dataset.testUint8Var.value > 128) {
|
||||
size_t sizeToDecrement = 0;
|
||||
if(dataset.testUint8Var.value > 128 + 30) {
|
||||
sizeToDecrement = 30;
|
||||
}
|
||||
else {
|
||||
sizeToDecrement = dataset.testUint8Var.value - 128;
|
||||
resetAfterChange = false;
|
||||
}
|
||||
dataset.testUint8Var.value -= sizeToDecrement;
|
||||
}
|
||||
else if(dataset.testUint8Var.value < 50) {
|
||||
if(not resetAfterChange) {
|
||||
/* This will trigger an update snapshot to the controller */
|
||||
dataset.testUint8Var.setChanged(true);
|
||||
resetAfterChange = true;
|
||||
}
|
||||
else {
|
||||
/* Increment by 30 automatically. */
|
||||
dataset.testUint8Var.value += 30;
|
||||
}
|
||||
}
|
||||
/* Increment in linear way */
|
||||
else if(dataset.testUint8Var.value < 128) {
|
||||
size_t sizeToIncrement = 0;
|
||||
if(dataset.testUint8Var.value < 128 - 20) {
|
||||
sizeToIncrement = 20;
|
||||
}
|
||||
else {
|
||||
sizeToIncrement = 128 - dataset.testUint8Var.value;
|
||||
resetAfterChange = false;
|
||||
}
|
||||
dataset.testUint8Var.value += sizeToIncrement;
|
||||
}
|
||||
|
||||
/* TODO: Same for vector */
|
||||
float vectorMean = (dataset.testFloat3Vec.value[0] + dataset.testFloat3Vec.value[1] +
|
||||
dataset.testFloat3Vec.value[2]) / 3.0;
|
||||
|
||||
/* Lambda (private local function) */
|
||||
auto sizeToAdd = [](bool tooHigh, float currentVal) {
|
||||
if(tooHigh) {
|
||||
if(currentVal - 20.0 > 10.0) {
|
||||
return -10.0;
|
||||
}
|
||||
else {
|
||||
return 20.0 - currentVal;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(std::abs(currentVal + 20.0) > 10.0) {
|
||||
return 10.0;
|
||||
}
|
||||
else {
|
||||
return -20.0 - currentVal;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if(vectorMean > 20.0 and std::abs(vectorMean - 20.0) > 1.0) {
|
||||
if(not resetAfterChange) {
|
||||
dataset.testFloat3Vec.setChanged(true);
|
||||
resetAfterChange = true;
|
||||
}
|
||||
else {
|
||||
float sizeToDecrementVal0 = 0;
|
||||
float sizeToDecrementVal1 = 0;
|
||||
float sizeToDecrementVal2 = 0;
|
||||
|
||||
sizeToDecrementVal0 = sizeToAdd(true, dataset.testFloat3Vec.value[0]);
|
||||
sizeToDecrementVal1 = sizeToAdd(true, dataset.testFloat3Vec.value[1]);
|
||||
sizeToDecrementVal2 = sizeToAdd(true, dataset.testFloat3Vec.value[2]);
|
||||
|
||||
dataset.testFloat3Vec.value[0] += sizeToDecrementVal0;
|
||||
dataset.testFloat3Vec.value[1] += sizeToDecrementVal1;
|
||||
dataset.testFloat3Vec.value[2] += sizeToDecrementVal2;
|
||||
}
|
||||
}
|
||||
else if (vectorMean < -20.0 and std::abs(vectorMean + 20.0) < 1.0) {
|
||||
if(not resetAfterChange) {
|
||||
dataset.testFloat3Vec.setChanged(true);
|
||||
resetAfterChange = true;
|
||||
}
|
||||
else {
|
||||
float sizeToDecrementVal0 = 0;
|
||||
float sizeToDecrementVal1 = 0;
|
||||
float sizeToDecrementVal2 = 0;
|
||||
|
||||
sizeToDecrementVal0 = sizeToAdd(false, dataset.testFloat3Vec.value[0]);
|
||||
sizeToDecrementVal1 = sizeToAdd(false, dataset.testFloat3Vec.value[1]);
|
||||
sizeToDecrementVal2 = sizeToAdd(false, dataset.testFloat3Vec.value[2]);
|
||||
|
||||
dataset.testFloat3Vec.value[0] += sizeToDecrementVal0;
|
||||
dataset.testFloat3Vec.value[1] += sizeToDecrementVal1;
|
||||
dataset.testFloat3Vec.value[2] += sizeToDecrementVal2;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(resetAfterChange) {
|
||||
resetAfterChange = false;
|
||||
}
|
||||
}
|
||||
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t TestDevice::interpretingTestReply0(DeviceCommandId_t id, const uint8_t* packet) {
|
||||
CommandMessage commandMessage;
|
||||
if(fullInfoPrintout) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice::interpretingTestReply0: Generating step and finish reply" <<
|
||||
std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice::interpretingTestReply0: Generating step and finish reply\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
MessageQueueId_t commander = getCommanderQueueId(id);
|
||||
/* Generate one step reply and the finish reply */
|
||||
actionHelper.step(1, commander, id);
|
||||
actionHelper.finish(true, commander, id);
|
||||
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t TestDevice::interpretingTestReply1(DeviceCommandId_t id,
|
||||
const uint8_t* packet) {
|
||||
CommandMessage directReplyMessage;
|
||||
if(fullInfoPrintout) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::interpretingReply1: Setting data reply" <<
|
||||
std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::interpretingReply1: Setting data reply\n", deviceIdx);
|
||||
#endif
|
||||
}
|
||||
|
||||
MessageQueueId_t commander = getCommanderQueueId(id);
|
||||
/* Send reply with data */
|
||||
ReturnValue_t result = actionHelper.reportData(commander, id, packet,
|
||||
testdevice::TEST_COMMAND_1_SIZE, false);
|
||||
|
||||
if (result != RETURN_OK) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "TestDevice" << deviceIdx << "::interpretingReply1: Sending data "
|
||||
"reply failed!" << std::endl;
|
||||
#else
|
||||
sif::printError("TestDevice%d::interpretingReply1: Sending data reply failed!\n",
|
||||
deviceIdx);
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
if(result == HasReturnvaluesIF::RETURN_OK) {
|
||||
/* Finish reply */
|
||||
actionHelper.finish(true, commander, id);
|
||||
}
|
||||
else {
|
||||
/* Finish reply */
|
||||
actionHelper.finish(false, commander, id, result);
|
||||
}
|
||||
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
uint32_t TestDevice::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) {
|
||||
return 5000;
|
||||
}
|
||||
|
||||
void TestDevice::enableFullDebugOutput(bool enable) {
|
||||
this->fullInfoPrintout = enable;
|
||||
}
|
||||
|
||||
ReturnValue_t TestDevice::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||
LocalDataPoolManager &poolManager) {
|
||||
namespace td = testdevice;
|
||||
localDataPoolMap.emplace(td::PoolIds::TEST_UINT8_ID, new PoolEntry<uint8_t>({0}));
|
||||
localDataPoolMap.emplace(td::PoolIds::TEST_UINT32_ID, new PoolEntry<uint32_t>({0}));
|
||||
localDataPoolMap.emplace(td::PoolIds::TEST_FLOAT_VEC_3_ID,
|
||||
new PoolEntry<float>({0.0, 0.0, 0.0}));
|
||||
|
||||
sid_t sid(this->getObjectId(), td::TEST_SET_ID);
|
||||
/* Subscribe for periodic HK packets but do not enable reporting for now.
|
||||
Non-diangostic with a period of one second */
|
||||
poolManager.subscribeForPeriodicPacket(sid, false, 1.0, false);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t TestDevice::getParameter(uint8_t domainId, uint8_t uniqueId,
|
||||
ParameterWrapper* parameterWrapper, const ParameterWrapper* newValues,
|
||||
uint16_t startAtIndex) {
|
||||
using namespace testdevice;
|
||||
switch (uniqueId) {
|
||||
case ParameterUniqueIds::TEST_UINT32_0: {
|
||||
if(fullInfoPrintout) {
|
||||
uint32_t newValue = 0;
|
||||
ReturnValue_t result = newValues->getElement<uint32_t>(&newValue, 0, 0);
|
||||
if(result == HasReturnvaluesIF::RETURN_OK) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::getParameter: Setting parameter 0 to "
|
||||
"new value " << newValue << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::getParameter: Setting parameter 0 to new value %lu\n",
|
||||
deviceIdx, static_cast<unsigned long>(newValue));
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
}
|
||||
}
|
||||
parameterWrapper->set(testParameter0);
|
||||
break;
|
||||
}
|
||||
case ParameterUniqueIds::TEST_INT32_1: {
|
||||
if(fullInfoPrintout) {
|
||||
int32_t newValue = 0;
|
||||
ReturnValue_t result = newValues->getElement<int32_t>(&newValue, 0, 0);
|
||||
if(result == HasReturnvaluesIF::RETURN_OK) {
|
||||
#if OBSW_DEVICE_HANDLER_PRINTOUT == 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::getParameter: Setting parameter 1 to "
|
||||
"new value " << newValue << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::getParameter: Setting parameter 1 to new value %lu\n",
|
||||
deviceIdx, static_cast<unsigned long>(newValue));
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
#endif /* OBSW_DEVICE_HANDLER_PRINTOUT == 1 */
|
||||
}
|
||||
}
|
||||
parameterWrapper->set(testParameter1);
|
||||
break;
|
||||
}
|
||||
case ParameterUniqueIds::TEST_FLOAT_VEC3_2: {
|
||||
if(fullInfoPrintout) {
|
||||
float newVector[3];
|
||||
if(newValues->getElement<float>(newVector, 0, 0) != RETURN_OK or
|
||||
newValues->getElement<float>(newVector + 1, 0, 1) != RETURN_OK or
|
||||
newValues->getElement<float>(newVector + 2, 0, 2) != RETURN_OK) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
#if OBSW_DEVICE_HANDLER_PRINTOUT == 1
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::getParameter: Setting parameter 3 to "
|
||||
"(float vector with 3 entries) to new values [" << newVector[0] << ", " <<
|
||||
newVector[1] << ", " << newVector[2] << "]" << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::getParameter: Setting parameter 3 to new values "
|
||||
"[%f, %f, %f]\n", deviceIdx, newVector[0], newVector[1], newVector[2]);
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
#endif /* OBSW_DEVICE_HANDLER_PRINTOUT == 1 */
|
||||
}
|
||||
parameterWrapper->setVector(vectorFloatParams2);
|
||||
break;
|
||||
}
|
||||
case(ParameterUniqueIds::PERIODIC_PRINT_ENABLED): {
|
||||
if(fullInfoPrintout) {
|
||||
uint8_t enabled = 0;
|
||||
ReturnValue_t result = newValues->getElement<uint8_t>(&enabled, 0, 0);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
char const* printout = nullptr;
|
||||
if (enabled) {
|
||||
printout = "enabled";
|
||||
}
|
||||
else {
|
||||
printout = "disabled";
|
||||
}
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::getParameter: Periodic printout " <<
|
||||
printout << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::getParameter: Periodic printout %s", printout);
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
}
|
||||
|
||||
parameterWrapper->set(periodicPrintout);
|
||||
break;
|
||||
}
|
||||
case(ParameterUniqueIds::CHANGING_DATASETS): {
|
||||
|
||||
uint8_t enabled = 0;
|
||||
ReturnValue_t result = newValues->getElement<uint8_t>(&enabled, 0, 0);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
if(not enabled) {
|
||||
PoolReadGuard readHelper(&dataset);
|
||||
dataset.testUint8Var.value = 0;
|
||||
dataset.testUint32Var.value = 0;
|
||||
dataset.testFloat3Vec.value[0] = 0.0;
|
||||
dataset.testFloat3Vec.value[0] = 0.0;
|
||||
dataset.testFloat3Vec.value[1] = 0.0;
|
||||
}
|
||||
|
||||
if(fullInfoPrintout) {
|
||||
char const* printout = nullptr;
|
||||
if (enabled) {
|
||||
printout = "enabled";
|
||||
}
|
||||
else {
|
||||
printout = "disabled";
|
||||
}
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "TestDevice" << deviceIdx << "::getParameter: Changing datasets " <<
|
||||
printout << std::endl;
|
||||
#else
|
||||
sif::printInfo("TestDevice%d::getParameter: Changing datasets %s", printout);
|
||||
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
||||
}
|
||||
|
||||
parameterWrapper->set(changingDatasets);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return INVALID_IDENTIFIER_ID;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
LocalPoolObjectBase* TestDevice::getPoolObjectHandle(lp_id_t localPoolId) {
|
||||
namespace td = testdevice;
|
||||
if (localPoolId == td::PoolIds::TEST_UINT8_ID) {
|
||||
return &dataset.testUint8Var;
|
||||
}
|
||||
else if (localPoolId == td::PoolIds::TEST_UINT32_ID) {
|
||||
return &dataset.testUint32Var;
|
||||
}
|
||||
else if(localPoolId == td::PoolIds::TEST_FLOAT_VEC_3_ID) {
|
||||
return &dataset.testFloat3Vec;
|
||||
}
|
||||
else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
142
tests/src/fsfw_tests/integration/devices/TestDeviceHandler.h
Normal file
142
tests/src/fsfw_tests/integration/devices/TestDeviceHandler.h
Normal file
@@ -0,0 +1,142 @@
|
||||
#ifndef TEST_TESTDEVICES_TESTDEVICEHANDLER_H_
|
||||
#define TEST_TESTDEVICES_TESTDEVICEHANDLER_H_
|
||||
|
||||
#include "devicedefinitions/testDeviceDefinitions.h"
|
||||
|
||||
#include "fsfw/devicehandlers/DeviceHandlerBase.h"
|
||||
#include "fsfw/globalfunctions/PeriodicOperationDivider.h"
|
||||
#include "fsfw/timemanager/Countdown.h"
|
||||
|
||||
/**
|
||||
* @brief Basic dummy device handler to test device commanding without a physical device.
|
||||
* @details
|
||||
* This test device handler provided a basic demo for the device handler object.
|
||||
* It can also be commanded with the following PUS services, using
|
||||
* the specified object ID of the test device handler.
|
||||
*
|
||||
* 1. PUS Service 8 - Functional commanding
|
||||
* 2. PUS Service 2 - Device access, raw commanding
|
||||
* 3. PUS Service 20 - Parameter Management
|
||||
* 4. PUS Service 3 - Housekeeping
|
||||
|
||||
* @author R. Mueller
|
||||
* @ingroup devices
|
||||
*/
|
||||
class TestDevice: public DeviceHandlerBase {
|
||||
public:
|
||||
/**
|
||||
* Build the test device in the factory.
|
||||
* @param objectId This ID will be assigned to the test device handler.
|
||||
* @param comIF The ID of the Communication IF used by test device handler.
|
||||
* @param cookie Cookie object used by the test device handler. This is
|
||||
* also used and passed to the comIF object.
|
||||
* @param onImmediately This will start a transition to MODE_ON immediately
|
||||
* so the device handler jumps into #doStartUp. Should only be used
|
||||
* in development to reduce need of commanding while debugging.
|
||||
* @param changingDataset
|
||||
* Will be used later to change the local datasets containeds in the device.
|
||||
*/
|
||||
TestDevice(object_id_t objectId, object_id_t comIF, CookieIF * cookie,
|
||||
testdevice::DeviceIndex deviceIdx = testdevice::DeviceIndex::DEVICE_0,
|
||||
bool fullInfoPrintout = false, bool changingDataset = true);
|
||||
|
||||
/**
|
||||
* This can be used to enable and disable a lot of demo print output.
|
||||
* @param enable
|
||||
*/
|
||||
void enableFullDebugOutput(bool enable);
|
||||
|
||||
virtual ~ TestDevice();
|
||||
|
||||
//! Size of internal buffer used for communication.
|
||||
static constexpr uint8_t MAX_BUFFER_SIZE = 255;
|
||||
|
||||
//! Unique index if the device handler is created multiple times.
|
||||
testdevice::DeviceIndex deviceIdx = testdevice::DeviceIndex::DEVICE_0;
|
||||
|
||||
protected:
|
||||
testdevice::TestDataSet dataset;
|
||||
//! This is used to reset the dataset after a commanded change has been made.
|
||||
bool resetAfterChange = false;
|
||||
bool commandSent = false;
|
||||
|
||||
/** DeviceHandlerBase overrides (see DHB documentation) */
|
||||
|
||||
/**
|
||||
* Hook into the DHB #performOperation call which is executed
|
||||
* periodically.
|
||||
*/
|
||||
void performOperationHook() override;
|
||||
|
||||
virtual void doStartUp() override;
|
||||
virtual void doShutDown() override;
|
||||
|
||||
virtual ReturnValue_t buildNormalDeviceCommand(
|
||||
DeviceCommandId_t * id) override;
|
||||
virtual ReturnValue_t buildTransitionDeviceCommand(
|
||||
DeviceCommandId_t * id) override;
|
||||
virtual ReturnValue_t buildCommandFromCommand(DeviceCommandId_t
|
||||
deviceCommand, const uint8_t * commandData,
|
||||
size_t commandDataLen) override;
|
||||
|
||||
virtual void fillCommandAndReplyMap() override;
|
||||
|
||||
virtual ReturnValue_t scanForReply(const uint8_t *start, size_t len,
|
||||
DeviceCommandId_t *foundId, size_t *foundLen) override;
|
||||
virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id,
|
||||
const uint8_t *packet) override;
|
||||
virtual uint32_t getTransitionDelayMs(Mode_t modeFrom,
|
||||
Mode_t modeTo) override;
|
||||
|
||||
virtual void doTransition(Mode_t modeFrom, Submode_t subModeFrom) override;
|
||||
|
||||
virtual ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
||||
LocalDataPoolManager& poolManager) override;
|
||||
virtual LocalPoolObjectBase* getPoolObjectHandle(lp_id_t localPoolId) override;
|
||||
|
||||
/* HasParametersIF overrides */
|
||||
virtual ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId,
|
||||
ParameterWrapper *parameterWrapper,
|
||||
const ParameterWrapper *newValues, uint16_t startAtIndex) override;
|
||||
|
||||
uint8_t commandBuffer[MAX_BUFFER_SIZE];
|
||||
|
||||
bool fullInfoPrintout = false;
|
||||
bool oneShot = true;
|
||||
|
||||
/* Variables for parameter service */
|
||||
uint32_t testParameter0 = 0;
|
||||
int32_t testParameter1 = -2;
|
||||
float vectorFloatParams2[3] = {};
|
||||
|
||||
/* Change device handler functionality, changeable via parameter service */
|
||||
uint8_t periodicPrintout = false;
|
||||
uint8_t changingDatasets = false;
|
||||
|
||||
ReturnValue_t buildNormalModeCommand(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t* commandData, size_t commandDataLen);
|
||||
ReturnValue_t buildTestCommand0(DeviceCommandId_t deviceCommand, const uint8_t* commandData,
|
||||
size_t commandDataLen);
|
||||
ReturnValue_t buildTestCommand1(DeviceCommandId_t deviceCommand, const uint8_t* commandData,
|
||||
size_t commandDataLen);
|
||||
void passOnCommand(DeviceCommandId_t command, const uint8_t* commandData,
|
||||
size_t commandDataLen);
|
||||
|
||||
ReturnValue_t interpretingNormalModeReply();
|
||||
ReturnValue_t interpretingTestReply0(DeviceCommandId_t id,
|
||||
const uint8_t* packet);
|
||||
ReturnValue_t interpretingTestReply1(DeviceCommandId_t id,
|
||||
const uint8_t* packet);
|
||||
ReturnValue_t interpretingTestReply2(DeviceCommandId_t id, const uint8_t* packet);
|
||||
|
||||
/* Some timer utilities */
|
||||
uint8_t divider1 = 2;
|
||||
PeriodicOperationDivider opDivider1 = PeriodicOperationDivider(divider1);
|
||||
uint8_t divider2 = 10;
|
||||
PeriodicOperationDivider opDivider2 = PeriodicOperationDivider(divider2);
|
||||
static constexpr uint32_t initTimeout = 2000;
|
||||
Countdown countdown1 = Countdown(initTimeout);
|
||||
};
|
||||
|
||||
|
||||
#endif /* TEST_TESTDEVICES_TESTDEVICEHANDLER_H_ */
|
86
tests/src/fsfw_tests/integration/devices/TestEchoComIF.cpp
Normal file
86
tests/src/fsfw_tests/integration/devices/TestEchoComIF.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
#include "TestEchoComIF.h"
|
||||
#include "TestCookie.h"
|
||||
|
||||
#include <fsfw/serialize/SerializeAdapter.h>
|
||||
#include <fsfw/serviceinterface/ServiceInterface.h>
|
||||
#include <fsfw/tmtcservices/CommandingServiceBase.h>
|
||||
#include <fsfw/tmtcpacket/pus/tm.h>
|
||||
|
||||
|
||||
TestEchoComIF::TestEchoComIF(object_id_t objectId):
|
||||
SystemObject(objectId) {
|
||||
}
|
||||
|
||||
TestEchoComIF::~TestEchoComIF() {}
|
||||
|
||||
ReturnValue_t TestEchoComIF::initializeInterface(CookieIF * cookie) {
|
||||
TestCookie* dummyCookie = dynamic_cast<TestCookie*>(cookie);
|
||||
if(dummyCookie == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "TestEchoComIF::initializeInterface: Invalid cookie!" << std::endl;
|
||||
#else
|
||||
sif::printWarning("TestEchoComIF::initializeInterface: Invalid cookie!\n");
|
||||
#endif
|
||||
return NULLPOINTER;
|
||||
}
|
||||
|
||||
auto resultPair = replyMap.emplace(
|
||||
dummyCookie->getAddress(), ReplyBuffer(dummyCookie->getReplyMaxLen()));
|
||||
if(not resultPair.second) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t TestEchoComIF::sendMessage(CookieIF *cookie,
|
||||
const uint8_t * sendData, size_t sendLen) {
|
||||
TestCookie* dummyCookie = dynamic_cast<TestCookie*>(cookie);
|
||||
if(dummyCookie == nullptr) {
|
||||
return NULLPOINTER;
|
||||
}
|
||||
|
||||
ReplyBuffer& replyBuffer = replyMap.find(dummyCookie->getAddress())->second;
|
||||
if(sendLen > replyBuffer.capacity()) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "TestEchoComIF::sendMessage: Send length " << sendLen << " larger than "
|
||||
"current reply buffer length!" << std::endl;
|
||||
#else
|
||||
sif::printWarning("TestEchoComIF::sendMessage: Send length %d larger than current "
|
||||
"reply buffer length!\n", sendLen);
|
||||
#endif
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
replyBuffer.resize(sendLen);
|
||||
memcpy(replyBuffer.data(), sendData, sendLen);
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t TestEchoComIF::getSendSuccess(CookieIF *cookie) {
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t TestEchoComIF::requestReceiveMessage(CookieIF *cookie,
|
||||
size_t requestLen) {
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t TestEchoComIF::readReceivedMessage(CookieIF *cookie,
|
||||
uint8_t **buffer, size_t *size) {
|
||||
TestCookie* dummyCookie = dynamic_cast<TestCookie*>(cookie);
|
||||
if(dummyCookie == nullptr) {
|
||||
return NULLPOINTER;
|
||||
}
|
||||
|
||||
ReplyBuffer& replyBuffer = replyMap.find(dummyCookie->getAddress())->second;
|
||||
*buffer = replyBuffer.data();
|
||||
*size = replyBuffer.size();
|
||||
|
||||
dummyReplyCounter ++;
|
||||
if(dummyReplyCounter == 10) {
|
||||
// add anything that needs to be read periodically by dummy handler
|
||||
dummyReplyCounter = 0;
|
||||
}
|
||||
return RETURN_OK;
|
||||
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user