Compare commits

..

24 Commits

Author SHA1 Message Date
16f8262a79 starting a bit with event manage replacements
Some checks failed
fsfw/fsfw/pipeline/pr-development There was a failure building this commit
2022-05-18 11:35:17 +02:00
1a41d37f20 Merge branch 'mueller/tc-packet-pus-improvement' into mueller/refactor-logging-with-fmt 2022-05-18 10:52:50 +02:00
a3b9937f32 freertos and dll replacements 2022-05-18 10:51:38 +02:00
618f76ae78 improved TcPacketPus API
All checks were successful
fsfw/fsfw/pipeline/pr-development This commit looks good
2022-05-17 10:14:34 +02:00
ee2f8d6956 Merge pull request 'Update FSFW from Upstream' (#27) from mueller/update-from-upstream into develop
Reviewed-on: KSat/fsfw#27
2022-05-17 10:06:58 +02:00
b11ae1c11d Merge remote-tracking branch 'upstream/development' into mueller/refactor-logging-with-fmt
All checks were successful
fsfw/fsfw/pipeline/pr-development This commit looks good
2022-05-16 14:59:58 +02:00
aea4e5d42c resolve merge conflict
Some checks failed
fsfw/fsfw/pipeline/pr-development There was a failure building this commit
2022-05-16 14:47:15 +02:00
8d966de735 Merge remote-tracking branch 'upstream/development' into mueller/refactor-logging-with-fmt
Some checks failed
fsfw/fsfw/pipeline/pr-development There was a failure building this commit
2022-05-16 14:41:19 +02:00
842f1b22af Merge branch 'development' into mueller/refactor-logging-with-fmt
Some checks failed
fsfw/fsfw/pipeline/pr-development There was a failure building this commit
2022-05-13 13:21:17 +02:00
cb9c1806ef Merge remote-tracking branch 'origin/development' into mueller/refactor-logging-with-fmt
Some checks failed
fsfw/fsfw/pipeline/pr-development There was a failure building this commit
2022-05-13 13:17:05 +02:00
cdc431ebc5 Merge remote-tracking branch 'origin/development' into mueller/refactor-logging-with-fmt
Some checks failed
fsfw/fsfw/pipeline/pr-development There was a failure building this commit
2022-05-12 19:05:52 +02:00
7ab617accb rudimentary clion support
All checks were successful
fsfw/fsfw/pipeline/pr-development This commit looks good
2022-05-12 18:59:39 +02:00
e2d3158506 remove v prefix from fmt version
Some checks failed
fsfw/fsfw/pipeline/pr-development There was a failure building this commit
2022-05-12 17:40:34 +02:00
23c6145971 Merge remote-tracking branch 'origin/development' into mueller/refactor-logging-with-fmt
Some checks failed
fsfw/fsfw/pipeline/pr-development There was a failure building this commit
2022-05-12 17:38:01 +02:00
eafbab9c65 Merge remote-tracking branch 'origin/mueller/add-lto-support' into mueller/refactor-logging-with-fmt
Some checks failed
fsfw/fsfw/pipeline/pr-development There was a failure building this commit
2022-05-10 10:15:05 +02:00
16bbc0f597 Merge remote-tracking branch 'origin/development' into mueller/refactor-logging-with-fmt
Some checks failed
fsfw/fsfw/pipeline/pr-development There was a failure building this commit
2022-05-10 10:10:56 +02:00
8d85da66f2 remove double added source files
Some checks failed
fsfw/fsfw/pipeline/head There was a failure building this commit
fsfw/fsfw/pipeline/pr-development There was a failure building this commit
2022-05-09 02:20:19 +02:00
fb1d775b52 fmt is publicly linked now, enable lto by default 2022-05-09 02:02:13 +02:00
e8a5f1e095 some format fixes 2022-05-09 01:28:26 +02:00
f518bc53db moved old loggers to archive 2022-05-09 01:14:23 +02:00
b45b6b3758 replace FLOG with LOG variants 2022-05-09 00:25:48 +02:00
83a2882f9d it compiles again 2022-05-09 00:09:13 +02:00
1b34b90ae0 init changing all printout types 2022-05-08 21:45:51 +02:00
77055a1579 first working version with fmt lib
Some checks failed
fsfw/fsfw/pipeline/head There was a failure building this commit
2022-05-08 18:19:44 +02:00
503 changed files with 3097 additions and 4339 deletions

View File

@@ -0,0 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="fsfw-tests_coverage" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="fsfw-tests" TARGET_NAME="fsfw-tests_coverage" CONFIG_NAME="Debug Unittest" RUN_TARGET_PROJECT_NAME="fsfw-tests" RUN_TARGET_NAME="fsfw-tests">
<method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method>
</configuration>
</component>

7
.run/fsfw.run.xml Normal file
View File

@@ -0,0 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="fsfw" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="fsfw-tests" TARGET_NAME="fsfw" CONFIG_NAME="Debug Unittest" RUN_TARGET_PROJECT_NAME="fsfw-tests" RUN_TARGET_NAME="fsfw-tests">
<method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method>
</configuration>
</component>

View File

@@ -8,24 +8,23 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
# [unreleased] # [unreleased]
# [v5.0.0] 25.07.2022 # [v5.0.0]
## Changes ## Changes
- Renamed auto-formatting script to `auto-formatter.sh` and made it more robust.
If `cmake-format` is installed, it will also auto-format the `CMakeLists.txt` files now.
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/625
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/626
- Bump C++ required version to C++17. Every project which uses the FSFW and every modern - Bump C++ required version to C++17. Every project which uses the FSFW and every modern
compiler supports it compiler supports it
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/622 PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/622
- HAL Linux SPI: Set the Clock Default State when setting new SPI speed
and mode
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/573
- GPIO HAL: `Direction`, `GpioOperation` and `Levels` are enum classes now, which prevents
name clashes with Windows defines.
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/572
- New CMake option `FSFW_HAL_LINUX_ADD_LIBGPIOD` to specifically exclude `gpiod` code. - New CMake option `FSFW_HAL_LINUX_ADD_LIBGPIOD` to specifically exclude `gpiod` code.
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/572 PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/572
- HAL Devicehandlers: Periodic printout is run-time configurable now - HAL Devicehandlers: Periodic printout is run-time configurable now
- `oneShotAction` flag in the `TestTask` class is not static anymore - `oneShotAction` flag in the `TestTask` class is not static anymore
- `SimpleRingBuffer::writeData` now checks if the amount is larger than the total size of the
Buffer and rejects such writeData calls with `HasReturnvaluesIF::RETURN_FAILED`
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/586
- Major update for version handling, using `git describe` to fetch version information with git. - Major update for version handling, using `git describe` to fetch version information with git.
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/601 PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/601
- Add helper functions provided by [`cmake-modules`](https://github.com/bilke/cmake-modules) - Add helper functions provided by [`cmake-modules`](https://github.com/bilke/cmake-modules)
@@ -43,41 +42,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
creation call. It allows passing context information and an arbitrary user argument into creation call. It allows passing context information and an arbitrary user argument into
the message queue. Also streamlined and simplified `MessageQueue` implementation for all OSALs the message queue. Also streamlined and simplified `MessageQueue` implementation for all OSALs
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/583 PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/583
- Internal API change: Moved the `fsfw_hal` to the `src` folder and integration and internal
tests part of `fsfw_tests` to `src`. Unittests are now in a dedicated folder called `unittests`
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/653
### Task Module Refactoring
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/636
**Refactoring general task code**
- There was a lot of duplicate/boilerplate code inside the individual task IF OSAL implementations.
Remove it by introducing base classes `PeriodicTaskBase` and `FixedTimeslotTaskBase`.
**Refactor PeriodicTaskIF**
- Convert `virtual ReturnValue_t addComponent(object_id_t object)` to
`virtual ReturnValue_t addComponent(object_id_t object, uint8_t opCode = 0)`, allowing to pass
the operation code passed to `performOperation`. Updated API taking
an `ExecutableObjectIF` accordingly
**Refactor FixedTimeslotTaskIF**
- Add additional `addSlot` function which takes an `ExecutableObjectIF` pointer and its Object ID
**Refactor FixedSequenceSlot**
- Introduce typedef `CustomCheckFunc` for `ReturnValue_t (*customCheckFunction)(const SlotList&)`.
- Convert `ReturnValue_t (*customCheckFunction)(const SlotList&)` to
`ReturnValue_t (*customCheckFunction)(const SlotList&, void*)`, allowing arbitrary user arguments
for the custom checker
**Linux Task Module**
- Use composition instead of inheritance for the `PeriodicPosixTask` and make the `PosixTask` a
member of the class
### HAL ### HAL
@@ -120,13 +84,6 @@ https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/593
## Additions ## Additions
- New constructor for PoolEntry which allows to simply specify the length of the pool entry.
This is also the new default constructor for scalar value with 0 as an initial value
- Added options for CI/CD builds: `FSFW_CICD_BUILD`. This allows the source code to know
whether it is running in CI/CD
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/623
- Basic `clion` support: Update `.gitignore` and add some basic run configurations
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/625
- LTO support: Allow using LTO/IPO by setting `FSFW_ENABLE_LTO=1`. CMake is able to detect whether - LTO support: Allow using LTO/IPO by setting `FSFW_ENABLE_LTO=1`. CMake is able to detect whether
the user compiler supports IPO/LPO. LTO is on by default now. Most modern compilers support it, the user compiler supports IPO/LPO. LTO is on by default now. Most modern compilers support it,
can make good use of it and it usually makes the code faster and/or smaller. can make good use of it and it usually makes the code faster and/or smaller.

View File

@@ -13,7 +13,7 @@ list(APPEND CMAKE_MODULE_PATH
# Version file handling # # Version file handling #
# ############################################################################## # ##############################################################################
set(FSFW_VERSION_IF_GIT_FAILS 5) set(FSFW_VERSION_IF_GIT_FAILS 4)
set(FSFW_SUBVERSION_IF_GIT_FAILS 0) set(FSFW_SUBVERSION_IF_GIT_FAILS 0)
set(FSFW_REVISION_IF_GIT_FAILS 0) set(FSFW_REVISION_IF_GIT_FAILS 0)
@@ -72,9 +72,8 @@ set(FSFW_ETL_LIB_MAJOR_VERSION
20 20
CACHE STRING "ETL library major version requirement") CACHE STRING "ETL library major version requirement")
set(FSFW_ETL_LIB_VERSION set(FSFW_ETL_LIB_VERSION
${FSFW_ETL_LIB_MAJOR_VERSION}.28.0 ${FSFW_ETL_LIB_MAJOR_VERSION}.27.3
CACHE STRING "ETL library exact version requirement") CACHE STRING "ETL library exact version requirement")
set(FSFW_ETL_LINK_TARGET etl::etl)
set(FSFW_CATCH2_LIB_MAJOR_VERSION set(FSFW_CATCH2_LIB_MAJOR_VERSION
3 3
@@ -83,6 +82,15 @@ set(FSFW_CATCH2_LIB_VERSION
v${FSFW_CATCH2_LIB_MAJOR_VERSION}.0.0-preview5 v${FSFW_CATCH2_LIB_MAJOR_VERSION}.0.0-preview5
CACHE STRING "Catch2 library exact version requirement") CACHE STRING "Catch2 library exact version requirement")
set(FSFW_FMT_LIB_NAME fmt)
set(FSFW_FMT_LINK_TARGET fmt::fmt)
set(FSFW_FMT_LIB_MAJOR_VERSION
8
CACHE STRING "{fmt} library major version requirement")
set(FSFW_FMT_LIB_VERSION
${FSFW_FMT_LIB_MAJOR_VERSION}.1.1
CACHE STRING "{fmt} library exact version requirement")
# Keep this off by default for now. See PR: # Keep this off by default for now. See PR:
# https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/616 for information which # https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/616 for information which
# keeping this on by default is problematic # keeping this on by default is problematic
@@ -104,11 +112,10 @@ if(FSFW_GENERATE_SECTIONS)
option(FSFW_REMOVE_UNUSED_CODE "Remove unused code" ON) option(FSFW_REMOVE_UNUSED_CODE "Remove unused code" ON)
endif() endif()
option(FSFW_BUILD_TESTS "Build unittest binary in addition to static library" option(FSFW_BUILD_UNITTESTS
OFF) "Build unittest binary in addition to static library" OFF)
option(FSFW_CICD_BUILD "Build for CI/CD. This can disable problematic test" OFF)
option(FSFW_BUILD_DOCS "Build documentation with Sphinx and Doxygen" OFF) option(FSFW_BUILD_DOCS "Build documentation with Sphinx and Doxygen" OFF)
if(FSFW_BUILD_TESTS) if(FSFW_BUILD_UNITTESTS)
option(FSFW_TESTS_GEN_COV "Generate coverage data for unittests" ON) option(FSFW_TESTS_GEN_COV "Generate coverage data for unittests" ON)
endif() endif()
@@ -140,7 +147,7 @@ if(IPO_SUPPORTED AND FSFW_ENABLE_IPO)
TRUE) TRUE)
endif() endif()
if(FSFW_BUILD_TESTS) if(FSFW_BUILD_UNITTESTS)
message( message(
STATUS STATUS
"${MSG_PREFIX} Building the FSFW unittests in addition to the static library" "${MSG_PREFIX} Building the FSFW unittests in addition to the static library"
@@ -163,17 +170,18 @@ if(FSFW_BUILD_TESTS)
list(APPEND FSFW_FETCH_CONTENT_TARGETS Catch2) list(APPEND FSFW_FETCH_CONTENT_TARGETS Catch2)
endif() endif()
set(FSFW_CONFIG_PATH unittests/testcfg) set(FSFW_CONFIG_PATH tests/src/fsfw_tests/unit/testcfg)
configure_file(unittests/testcfg/FSFWConfig.h.in FSFWConfig.h) configure_file(tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in FSFWConfig.h)
configure_file(unittests/testcfg/TestsConfig.h.in tests/TestsConfig.h) configure_file(tests/src/fsfw_tests/unit/testcfg/TestsConfig.h.in
tests/TestsConfig.h)
project(${FSFW_TEST_TGT} CXX C) project(${FSFW_TEST_TGT} CXX C)
add_executable(${FSFW_TEST_TGT}) add_executable(${FSFW_TEST_TGT})
if(IPO_SUPPORTED AND FSFW_ENABLE_IPO) if(IPO_SUPPORTED AND FSFW_ENABLE_IPO)
set_property(TARGET ${FSFW_TEST_TGT} PROPERTY INTERPROCEDURAL_OPTIMIZATION set_property(TARGET ${FSFW_TEST_TGT} PROPERTY INTERPROCEDURAL_OPTIMIZATION
TRUE) TRUE)
endif() endif()
if(FSFW_TESTS_GEN_COV) if(FSFW_TESTS_GEN_COV)
message(STATUS "${MSG_PREFIX} Generating coverage data for the library") message(STATUS "${MSG_PREFIX} Generating coverage data for the library")
message(STATUS "${MSG_PREFIX} Targets linking against ${LIB_FSFW_NAME} " message(STATUS "${MSG_PREFIX} Targets linking against ${LIB_FSFW_NAME} "
@@ -183,7 +191,7 @@ if(FSFW_BUILD_TESTS)
endif() endif()
endif() endif()
message(STATUS "${MSG_PREFIX} Finding and/or providing ETL library") message(STATUS "${MSG_PREFIX} Finding and/or etl (Embedded Template Library)")
# Check whether the user has already installed ETL first # Check whether the user has already installed ETL first
find_package(${FSFW_ETL_LIB_NAME} ${FSFW_ETL_LIB_MAJOR_VERSION} QUIET) find_package(${FSFW_ETL_LIB_NAME} ${FSFW_ETL_LIB_MAJOR_VERSION} QUIET)
@@ -203,6 +211,26 @@ if(NOT ${FSFW_ETL_LIB_NAME}_FOUND)
list(APPEND FSFW_FETCH_CONTENT_TARGETS ${FSFW_ETL_LIB_NAME}) list(APPEND FSFW_FETCH_CONTENT_TARGETS ${FSFW_ETL_LIB_NAME})
endif() endif()
message(STATUS "Finding and/or providing {fmt} formatting library")
# Check whether the user has already installed ETL first
find_package(fmt ${FSFW_FMT_LIB_MAJOR_VERSION} QUIET)
# Not installed, so use FetchContent to download and provide etl
if(NOT ${FSFW_FMT_LIB_NAME}_FOUND)
message(
STATUS
"No {fmt} installation was found with find_package. Installing and providing "
"{fmt} with FindPackage")
include(FetchContent)
FetchContent_Declare(
${FSFW_FMT_LIB_NAME}
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG ${FSFW_FMT_LIB_VERSION})
list(APPEND FSFW_FETCH_CONTENT_TARGETS ${FSFW_FMT_LIB_NAME})
endif()
# The documentation for FetchContent recommends declaring all the dependencies # The documentation for FetchContent recommends declaring all the dependencies
# before making them available. We make all declared dependency available here # before making them available. We make all declared dependency available here
# after their declaration # after their declaration
@@ -212,7 +240,7 @@ if(FSFW_FETCH_CONTENT_TARGETS)
add_library(${FSFW_ETL_LINK_TARGET} ALIAS ${FSFW_ETL_LIB_NAME}) add_library(${FSFW_ETL_LINK_TARGET} ALIAS ${FSFW_ETL_LIB_NAME})
endif() endif()
if(TARGET Catch2) if(TARGET Catch2)
# Fixes regression -preview4, to be confirmed in later releases Related # Fixes regression -preview4, to be confirmed in later releases. Related
# GitHub issue: https://github.com/catchorg/Catch2/issues/2417 # GitHub issue: https://github.com/catchorg/Catch2/issues/2417
set_target_properties(Catch2 PROPERTIES DEBUG_POSTFIX "") set_target_properties(Catch2 PROPERTIES DEBUG_POSTFIX "")
endif() endif()
@@ -281,15 +309,16 @@ message(
) )
add_subdirectory(src) add_subdirectory(src)
add_subdirectory(contrib) add_subdirectory(tests)
if(FSFW_BUILD_TESTS) if(FSFW_ADD_HAL)
add_subdirectory(unittests) add_subdirectory(hal)
endif() endif()
add_subdirectory(contrib)
if(FSFW_BUILD_DOCS) if(FSFW_BUILD_DOCS)
add_subdirectory(docs) add_subdirectory(docs)
endif() endif()
if(FSFW_BUILD_TESTS) if(FSFW_BUILD_UNITTESTS)
if(FSFW_TESTS_GEN_COV) if(FSFW_TESTS_GEN_COV)
if(CMAKE_COMPILER_IS_GNUCXX) if(CMAKE_COMPILER_IS_GNUCXX)
include(CodeCoverage) include(CodeCoverage)
@@ -446,8 +475,13 @@ target_include_directories(
target_compile_options(${LIB_FSFW_NAME} PRIVATE ${FSFW_WARNING_FLAGS} target_compile_options(${LIB_FSFW_NAME} PRIVATE ${FSFW_WARNING_FLAGS}
${COMPILER_FLAGS}) ${COMPILER_FLAGS})
target_link_libraries(${LIB_FSFW_NAME} PRIVATE ${FSFW_ADDITIONAL_LINK_LIBS}) target_link_libraries(${LIB_FSFW_NAME} PUBLIC ${FSFW_FMT_LINK_TARGET})
target_link_libraries(${LIB_FSFW_NAME} PUBLIC ${FSFW_ETL_LINK_TARGET})
target_link_libraries(
${LIB_FSFW_NAME}
PRIVATE # If any ELT headers are ever exposed inside a header or as part of
# the API, the ETL target needs to be linked PUBLIC
${FSFW_ETL_LINK_TARGET} ${FSFW_ADDITIONAL_LINK_LIBS})
string( string(
CONCAT CONCAT
@@ -457,6 +491,13 @@ string(
"Target OSAL: ${FSFW_OS_NAME}\n" "Target OSAL: ${FSFW_OS_NAME}\n"
"######################################################################\n") "######################################################################\n")
# The additional / is important to remove the last character from the path. Note
# that it does not matter if the OS uses / or \, because we are only saving the
# path size.
string(LENGTH "${CMAKE_SOURCE_DIR}/" FSFW_SOURCE_PATH_SIZE)
target_compile_definitions(
${LIB_FSFW_NAME} PRIVATE "-DFSFW_SOURCE_PATH_SIZE=${FSFW_SOURCE_PATH_SIZE}")
add_custom_command( add_custom_command(
TARGET ${LIB_FSFW_NAME} TARGET ${LIB_FSFW_NAME}
POST_BUILD POST_BUILD

View File

@@ -99,7 +99,7 @@ add and link against the FSFW library in general.
4. Link against the FSFW library 4. Link against the FSFW library
```sh ```cmake
target_link_libraries(${YourProjectName} PRIVATE fsfw) target_link_libraries(${YourProjectName} PRIVATE fsfw)
``` ```
@@ -131,7 +131,7 @@ default. This can be disabled by setting the `FSFW_TESTS_COV_GEN` option to `OFF
You can use the following commands inside the `fsfw` folder to set up the build system You can use the following commands inside the `fsfw` folder to set up the build system
```sh ```sh
mkdir build-tests && cd build-tests mkdir build-Unittest && cd build-Unittest
cmake -DFSFW_BUILD_UNITTESTS=ON -DFSFW_OSAL=host -DCMAKE_BUILD_TYPE=Debug .. cmake -DFSFW_BUILD_UNITTESTS=ON -DFSFW_OSAL=host -DCMAKE_BUILD_TYPE=Debug ..
``` ```
@@ -139,7 +139,7 @@ You can also use `-DFSFW_OSAL=linux` on Linux systems.
Coverage data in HTML format can be generated using the `CodeCoverage` Coverage data in HTML format can be generated using the `CodeCoverage`
[CMake module](https://github.com/bilke/cmake-modules/tree/master). [CMake module](https://github.com/bilke/cmake-modules/tree/master).
To build the unittests, run them and then generate the coverage data in this format, 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 the following command can be used inside the build directory after the build system was set up
```sh ```sh
@@ -188,10 +188,7 @@ and open the documentation conveniently. Try `helper.py -h for more information.
The formatting is done by the `clang-format` tool. The configuration is contained within the 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 `.clang-format` file in the repository root. As long as `clang-format` is installed, you
can run the `auto-format.sh` helper script to format all source files consistently. Furthermore cmake-format is required to format CMake files which can be installed with: can run the `apply-clang-format.sh` helper script to format all source files consistently.
````sh
sudo pip install cmakelang
````
## Index ## Index

View File

@@ -12,9 +12,3 @@ RUN git clone https://github.com/catchorg/Catch2.git && \
git checkout v3.0.0-preview5 && \ git checkout v3.0.0-preview5 && \
cmake -Bbuild -H. -DBUILD_TESTING=OFF && \ cmake -Bbuild -H. -DBUILD_TESTING=OFF && \
cmake --build build/ --target install cmake --build build/ --target install
RUN git clone https://github.com/ETLCPP/etl.git && \
cd etl && \
git checkout 20.28.0 && \
cmake -B build . && \
cmake --install build/

View File

@@ -3,7 +3,7 @@ pipeline {
BUILDDIR = 'build-tests' BUILDDIR = 'build-tests'
} }
agent { agent {
docker { image 'fsfw-ci:d3'} docker { image 'fsfw-ci:d2'}
} }
stages { stages {
stage('Clean') { stage('Clean') {
@@ -14,7 +14,7 @@ pipeline {
stage('Configure') { stage('Configure') {
steps { steps {
dir(BUILDDIR) { dir(BUILDDIR) {
sh 'cmake -DFSFW_OSAL=host -DFSFW_BUILD_TESTS=ON -DFSFW_CICD_BUILD=ON ..' sh 'cmake -DFSFW_OSAL=host -DFSFW_BUILD_UNITTESTS=ON ..'
} }
} }
} }

48
hal/CMakeLists.txt Normal file
View File

@@ -0,0 +1,48 @@
cmake_minimum_required(VERSION 3.13)
# Can also be changed by upper CMakeLists.txt file
find_library(LIB_FSFW_NAME fsfw REQUIRED)
option(FSFW_HAL_ADD_LINUX "Add the Linux HAL to the sources. Requires gpiod library" OFF)
# On by default for now because I did not have an issue including and compiling those files
# and libraries on a Desktop Linux system and the primary target of the FSFW is still embedded
# Linux. The only exception from this is the gpiod library which requires a dedicated installation,
# but CMake is able to determine whether this library is installed with find_library.
option(FSFW_HAL_LINUX_ADD_PERIPHERAL_DRIVERS "Add peripheral drivers for embedded Linux" ON)
option(FSFW_HAL_LINUX_ADD_LIBGPIOD "Target implements libgpiod" ON)
option(FSFW_HAL_ADD_RASPBERRY_PI "Add Raspberry Pi specific code to the sources" OFF)
option(FSFW_HAL_ADD_STM32H7 "Add the STM32H7 HAL to the sources" OFF)
option(FSFW_HAL_WARNING_SHADOW_LOCAL_GCC "Enable -Wshadow=local warning in GCC" ON)
set(LINUX_HAL_PATH_NAME linux)
set(STM32H7_PATH_NAME stm32h7)
add_subdirectory(src)
foreach(INCLUDE_PATH ${FSFW_HAL_ADDITIONAL_INC_PATHS})
if(IS_ABSOLUTE ${INCLUDE_PATH})
set(CURR_ABS_INC_PATH "${INCLUDE_PATH}")
else()
get_filename_component(CURR_ABS_INC_PATH
${INCLUDE_PATH} REALPATH BASE_DIR ${CMAKE_SOURCE_DIR})
endif()
if(CMAKE_VERBOSE)
message(STATUS "FSFW include path: ${CURR_ABS_INC_PATH}")
endif()
list(APPEND FSFW_HAL_ADD_INC_PATHS_ABS ${CURR_ABS_INC_PATH})
endforeach()
target_include_directories(${LIB_FSFW_NAME} PRIVATE
${FSFW_HAL_ADD_INC_PATHS_ABS}
)
target_compile_definitions(${LIB_FSFW_NAME} PRIVATE
${FSFW_HAL_DEFINES}
)
target_link_libraries(${LIB_FSFW_NAME} PRIVATE
${FSFW_HAL_LINK_LIBS}
)

9
hal/src/CMakeLists.txt Normal file
View File

@@ -0,0 +1,9 @@
target_include_directories(${LIB_FSFW_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
)
target_include_directories(${LIB_FSFW_NAME} INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}
)
add_subdirectory(fsfw_hal)

View File

@@ -2,9 +2,9 @@ add_subdirectory(devicehandlers)
add_subdirectory(common) add_subdirectory(common)
if(UNIX) if(UNIX)
add_subdirectory(linux) add_subdirectory(linux)
endif() endif()
if(FSFW_HAL_ADD_STM32H7) if(FSFW_HAL_ADD_STM32H7)
add_subdirectory(stm32h7) add_subdirectory(stm32h7)
endif() endif()

View File

@@ -0,0 +1,3 @@
target_sources(${LIB_FSFW_NAME} PRIVATE
GpioCookie.cpp
)

View File

@@ -1,30 +1,19 @@
#include "fsfw_hal/common/gpio/GpioCookie.h" #include "fsfw_hal/common/gpio/GpioCookie.h"
#include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/serviceinterface.h"
GpioCookie::GpioCookie() {} GpioCookie::GpioCookie() = default;
ReturnValue_t GpioCookie::addGpio(gpioId_t gpioId, GpioBase* gpioConfig) { ReturnValue_t GpioCookie::addGpio(gpioId_t gpioId, GpioBase* gpioConfig) {
if (gpioConfig == nullptr) { if (gpioConfig == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGW("addGpio: gpioConfig is nullpointer\n");
sif::warning << "GpioCookie::addGpio: gpioConfig is nullpointer" << std::endl;
#else
sif::printWarning("GpioCookie::addGpio: gpioConfig is nullpointer\n");
#endif
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
auto gpioMapIter = gpioMap.find(gpioId); auto gpioMapIter = gpioMap.find(gpioId);
if (gpioMapIter == gpioMap.end()) { if (gpioMapIter == gpioMap.end()) {
auto statusPair = gpioMap.emplace(gpioId, gpioConfig); auto statusPair = gpioMap.emplace(gpioId, gpioConfig);
if (statusPair.second == false) { if (!statusPair.second) {
#if FSFW_VERBOSE_LEVEL >= 1 FSFW_LOGW("addGpio: Failed to add GPIO {} to GPIO map\n", gpioId);
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "GpioCookie::addGpio: Failed to add GPIO " << gpioId << " to GPIO map"
<< std::endl;
#else
sif::printWarning("GpioCookie::addGpio: Failed to add GPIO %d to GPIO map\n", gpioId);
#endif
#endif
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;

View File

@@ -0,0 +1,5 @@
target_sources(${LIB_FSFW_NAME} PRIVATE
GyroL3GD20Handler.cpp
MgmRM3100Handler.cpp
MgmLIS3MDLHandler.cpp
)

View File

@@ -60,16 +60,8 @@ ReturnValue_t GyroHandlerL3GD20H::buildTransitionDeviceCommand(DeviceCommandId_t
return buildCommandFromCommand(*id, nullptr, 0); return buildCommandFromCommand(*id, nullptr, 0);
} }
default: default:
#if FSFW_CPP_OSTREAM_ENABLED == 1
/* Might be a configuration error. */ /* Might be a configuration error. */
sif::warning << "GyroL3GD20Handler::buildTransitionDeviceCommand: " FSFW_LOGW("buildTransitionDeviceCommand: Unknown internal state\n");
"Unknown internal state!"
<< std::endl;
#else
sif::printDebug(
"GyroL3GD20Handler::buildTransitionDeviceCommand: "
"Unknown internal state!\n");
#endif
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
@@ -192,17 +184,8 @@ ReturnValue_t GyroHandlerL3GD20H::interpretDeviceReply(DeviceCommandId_t id,
if (periodicPrintout) { if (periodicPrintout) {
if (debugDivider.checkAndIncrement()) { if (debugDivider.checkAndIncrement()) {
/* Set terminal to utf-8 if there is an issue with micro printout. */ /* Set terminal to utf-8 if there is an issue with micro printout. */
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGI("GyroHandlerL3GD20H: Angular velocities (deg/s):\nX {} | Y {} | Z {}\n",
sif::info << "GyroHandlerL3GD20H: Angular velocities (deg/s):" << std::endl; angVelocX, angVelocY, angVelocZ);
sif::info << "X: " << angVelocX << std::endl;
sif::info << "Y: " << angVelocY << std::endl;
sif::info << "Z: " << angVelocZ << std::endl;
#else
sif::printInfo("GyroHandlerL3GD20H: Angular velocities (deg/s):\n");
sif::printInfo("X: %f\n", angVelocX);
sif::printInfo("Y: %f\n", angVelocY);
sif::printInfo("Z: %f\n", angVelocZ);
#endif
} }
} }

View File

@@ -76,21 +76,16 @@ ReturnValue_t MgmLIS3MDLHandler::buildTransitionDeviceCommand(DeviceCommandId_t
} }
default: { default: {
/* might be a configuration error. */ /* might be a configuration error. */
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGW("buildTransitionDeviceCommand: Unknown internal state\n");
sif::warning << "GyroHandler::buildTransitionDeviceCommand: Unknown internal state!"
<< std::endl;
#else
sif::printWarning("GyroHandler::buildTransitionDeviceCommand: Unknown internal state!\n");
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
} }
return buildCommandFromCommand(*id, NULL, 0); return buildCommandFromCommand(*id, nullptr, 0);
} }
uint8_t MgmLIS3MDLHandler::readCommand(uint8_t command, bool continuousCom) { uint8_t MgmLIS3MDLHandler::readCommand(uint8_t command, bool continuousCom) {
command |= (1 << MGMLIS3MDL::RW_BIT); command |= (1 << MGMLIS3MDL::RW_BIT);
if (continuousCom == true) { if (continuousCom) {
command |= (1 << MGMLIS3MDL::MS_BIT); command |= (1 << MGMLIS3MDL::MS_BIT);
} }
return command; return command;
@@ -98,7 +93,7 @@ uint8_t MgmLIS3MDLHandler::readCommand(uint8_t command, bool continuousCom) {
uint8_t MgmLIS3MDLHandler::writeCommand(uint8_t command, bool continuousCom) { uint8_t MgmLIS3MDLHandler::writeCommand(uint8_t command, bool continuousCom) {
command &= ~(1 << MGMLIS3MDL::RW_BIT); command &= ~(1 << MGMLIS3MDL::RW_BIT);
if (continuousCom == true) { if (continuousCom) {
command |= (1 << MGMLIS3MDL::MS_BIT); command |= (1 << MGMLIS3MDL::MS_BIT);
} }
return command; return command;
@@ -186,13 +181,7 @@ ReturnValue_t MgmLIS3MDLHandler::scanForReply(const uint8_t *start, size_t len,
// Check validity by checking config registers // Check validity by checking config registers
if (start[1] != registers[0] or start[2] != registers[1] or start[3] != registers[2] or if (start[1] != registers[0] or start[2] != registers[1] or start[3] != registers[2] or
start[4] != registers[3] or start[5] != registers[4]) { start[4] != registers[3] or start[5] != registers[4]) {
#if FSFW_VERBOSE_LEVEL >= 1 FSFW_LOGW("scanForReply: Invalid registers\n");
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "MGMHandlerLIS3MDL::scanForReply: Invalid registers!" << std::endl;
#else
sif::printWarning("MGMHandlerLIS3MDL::scanForReply: Invalid registers!\n");
#endif
#endif
return DeviceHandlerIF::INVALID_DATA; return DeviceHandlerIF::INVALID_DATA;
} }
if (mode == _MODE_START_UP) { if (mode == _MODE_START_UP) {
@@ -210,17 +199,9 @@ ReturnValue_t MgmLIS3MDLHandler::scanForReply(const uint8_t *start, size_t len,
*foundId = getPendingCommand(); *foundId = getPendingCommand();
if (*foundId == MGMLIS3MDL::IDENTIFY_DEVICE) { if (*foundId == MGMLIS3MDL::IDENTIFY_DEVICE) {
if (start[1] != MGMLIS3MDL::DEVICE_ID) { if (start[1] != MGMLIS3MDL::DEVICE_ID) {
#if FSFW_VERBOSE_LEVEL >= 1 FSFW_LOGW(
#if FSFW_CPP_OSTREAM_ENABLED == 1 "scanForReply: Device identification failed, found ID {} not equal to expected {}\n",
sif::warning << "MGMHandlerLIS3MDL::scanForReply: " start[1], MGMLIS3MDL::DEVICE_ID);
"Device identification failed!"
<< std::endl;
#else
sif::printWarning(
"MGMHandlerLIS3MDL::scanForReply: "
"Device identification failed!\n");
#endif
#endif
return DeviceHandlerIF::INVALID_DATA; return DeviceHandlerIF::INVALID_DATA;
} }
@@ -268,19 +249,10 @@ ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id, cons
if (periodicPrintout) { if (periodicPrintout) {
if (debugDivider.checkAndIncrement()) { if (debugDivider.checkAndIncrement()) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGI(
sif::info << "MGMHandlerLIS3: Magnetic field strength in" "MGMHandlerLIS3: Magnetic field strength in"
" microtesla:" " microtesla (uT):\nX {} | Y {} | Z {}\n",
<< std::endl; mgmX, mgmY, mgmZ);
sif::info << "X: " << mgmX << " uT" << std::endl;
sif::info << "Y: " << mgmY << " uT" << std::endl;
sif::info << "Z: " << mgmZ << " uT" << std::endl;
#else
sif::printInfo("MGMHandlerLIS3: Magnetic field strength in microtesla:\n");
sif::printInfo("X: %f uT\n", mgmX);
sif::printInfo("Y: %f uT\n", mgmY);
sif::printInfo("Z: %f uT\n", mgmZ);
#endif /* FSFW_CPP_OSTREAM_ENABLED == 0 */
} }
} }
@@ -311,15 +283,11 @@ ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id, cons
} }
case MGMLIS3MDL::READ_TEMPERATURE: { case MGMLIS3MDL::READ_TEMPERATURE: {
int16_t tempValueRaw = packet[2] << 8 | packet[1]; auto tempValueRaw = static_cast<int16_t>((packet[2] << 8) | packet[1]);
float tempValue = 25.0 + ((static_cast<float>(tempValueRaw)) / 8.0); float tempValue = 25.0 + ((static_cast<float>(tempValueRaw)) / 8.0);
if (periodicPrintout) { if (periodicPrintout) {
if (debugDivider.check()) { if (debugDivider.check()) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGI("MGMHandlerLIS3: Temperature: {} C\n", tempValue);
sif::info << "MGMHandlerLIS3: Temperature: " << tempValue << " C" << std::endl;
#else
sif::printInfo("MGMHandlerLIS3: Temperature: %f C\n");
#endif
} }
} }

View File

@@ -81,18 +81,8 @@ ReturnValue_t MgmRM3100Handler::buildTransitionDeviceCommand(DeviceCommandId_t *
break; break;
} }
default: default:
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
// Might be a configuration error // Might be a configuration error
sif::warning << "MgmRM3100Handler::buildTransitionDeviceCommand: " FSFW_LOGW("buildTransitionDeviceCommand: Unknown internal state\n");
"Unknown internal state"
<< std::endl;
#else
sif::printWarning(
"MgmRM3100Handler::buildTransitionDeviceCommand: "
"Unknown internal state\n");
#endif
#endif
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
@@ -335,19 +325,10 @@ ReturnValue_t MgmRM3100Handler::handleDataReadout(const uint8_t *packet) {
if (periodicPrintout) { if (periodicPrintout) {
if (debugDivider.checkAndIncrement()) { if (debugDivider.checkAndIncrement()) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGI(
sif::info << "MgmRM3100Handler: Magnetic field strength in" "MgmRM3100Handler: Magnetic field strength in"
" microtesla:" " microtesla(uT)\nX {} | Y {} | Z {}\n",
<< std::endl; fieldStrengthX, fieldStrengthY, fieldStrengthZ);
sif::info << "X: " << fieldStrengthX << " uT" << std::endl;
sif::info << "Y: " << fieldStrengthY << " uT" << std::endl;
sif::info << "Z: " << fieldStrengthZ << " uT" << std::endl;
#else
sif::printInfo("MgmRM3100Handler: Magnetic field strength in microtesla:\n");
sif::printInfo("X: %f uT\n", fieldStrengthX);
sif::printInfo("Y: %f uT\n", fieldStrengthY);
sif::printInfo("Z: %f uT\n", fieldStrengthZ);
#endif
} }
} }

View File

@@ -0,0 +1,25 @@
if(FSFW_HAL_ADD_RASPBERRY_PI)
add_subdirectory(rpi)
endif()
target_sources(${LIB_FSFW_NAME} PRIVATE
UnixFileGuard.cpp
CommandExecutor.cpp
utility.cpp
)
if(FSFW_HAL_LINUX_ADD_PERIPHERAL_DRIVERS)
if(FSFW_HAL_LINUX_ADD_LIBGPIOD)
add_subdirectory(gpio)
endif()
add_subdirectory(uart)
# Adding those does not really make sense on Apple systems which
# are generally host systems. It won't even compile as the headers
# are missing
if(NOT APPLE)
add_subdirectory(i2c)
add_subdirectory(spi)
endif()
endif()
add_subdirectory(uio)

View File

@@ -59,22 +59,16 @@ ReturnValue_t CommandExecutor::close() {
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
void CommandExecutor::printLastError(std::string funcName) const { void CommandExecutor::printLastError(const std::string& funcName) const {
if (lastError != 0) { if (lastError != 0) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGW("{} | pclose failed with code {} | {}\n", funcName, lastError, strerror(lastError));
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, void CommandExecutor::setRingBuffer(SimpleRingBuffer* ringBuffer_,
DynamicFIFO<uint16_t>* sizesFifo) { DynamicFIFO<uint16_t>* sizesFifo_) {
this->ringBuffer = ringBuffer; this->ringBuffer = ringBuffer_;
this->sizesFifo = sizesFifo; this->sizesFifo = sizesFifo_;
} }
ReturnValue_t CommandExecutor::check(bool& replyReceived) { ReturnValue_t CommandExecutor::check(bool& replyReceived) {
@@ -102,23 +96,13 @@ ReturnValue_t CommandExecutor::check(bool& replyReceived) {
ssize_t readBytes = read(currentFd, readVec.data(), readVec.size()); ssize_t readBytes = read(currentFd, readVec.data(), readVec.size());
if (readBytes == 0) { if (readBytes == 0) {
// Should not happen // Should not happen
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGWT("CommandExecutor::check: No bytes read after poll event\n");
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; break;
} else if (readBytes > 0) { } else if (readBytes > 0) {
replyReceived = true; replyReceived = true;
if (printOutput) { if (printOutput) {
// It is assumed the command output is line terminated // It is assumed the command output is line terminated
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGIT("{} | {}", currentCmd, readVec.data());
sif::info << currentCmd << " | " << readVec.data();
#else
sif::printInfo("%s | %s", currentCmd, readVec.data());
#endif
} }
if (ringBuffer != nullptr) { if (ringBuffer != nullptr) {
ringBuffer->writeData(reinterpret_cast<const uint8_t*>(readVec.data()), readBytes); ringBuffer->writeData(reinterpret_cast<const uint8_t*>(readVec.data()), readBytes);
@@ -130,20 +114,11 @@ ReturnValue_t CommandExecutor::check(bool& replyReceived) {
} }
} else { } else {
// Should also not happen // Should also not happen
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGW("check: Error {} | {}\n", errno, strerror(errno));
sif::warning << "CommandExecutor::check: Error " << errno << ": " << strerror(errno)
<< std::endl;
#else
sif::printWarning("CommandExecutor::check: Error %d: %s\n", errno, strerror(errno));
#endif
} }
} }
if (waiter.revents & POLLERR) { if (waiter.revents & POLLERR) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGW("check: Poll error\n");
sif::warning << "CommandExecuter::check: Poll error" << std::endl;
#else
sif::printWarning("CommandExecuter::check: Poll error\n");
#endif
return COMMAND_ERROR; return COMMAND_ERROR;
} }
if (waiter.revents & POLLHUP) { if (waiter.revents & POLLHUP) {
@@ -183,11 +158,7 @@ ReturnValue_t CommandExecutor::executeBlocking() {
while (fgets(readVec.data(), readVec.size(), currentCmdFile) != nullptr) { while (fgets(readVec.data(), readVec.size(), currentCmdFile) != nullptr) {
std::string output(readVec.data()); std::string output(readVec.data());
if (printOutput) { if (printOutput) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGI("{} | {}", currentCmd, output);
sif::info << currentCmd << " | " << output;
#else
sif::printInfo("%s | %s", currentCmd, output);
#endif
} }
if (ringBuffer != nullptr) { if (ringBuffer != nullptr) {
ringBuffer->writeData(reinterpret_cast<const uint8_t*>(output.data()), output.size()); ringBuffer->writeData(reinterpret_cast<const uint8_t*>(output.data()), output.size());

View File

@@ -93,7 +93,7 @@ class CommandExecutor {
States getCurrentState() const; States getCurrentState() const;
int getLastError() const; int getLastError() const;
void printLastError(std::string funcName) const; void printLastError(const std::string& funcName) const;
/** /**
* Assign a ring buffer and a FIFO which will be filled by the executor with the output * Assign a ring buffer and a FIFO which will be filled by the executor with the output

View File

@@ -14,15 +14,8 @@ UnixFileGuard::UnixFileGuard(std::string device, int* fileDescriptor, int flags,
} }
*fileDescriptor = open(device.c_str(), flags); *fileDescriptor = open(device.c_str(), flags);
if (*fileDescriptor < 0) { if (*fileDescriptor < 0) {
#if FSFW_VERBOSE_LEVEL >= 1 FSFW_LOGW("{} | Opening device failed with error code {} | {}\n", diagnosticPrefix, errno,
#if FSFW_CPP_OSTREAM_ENABLED == 1 strerror(errno));
sif::warning << diagnosticPrefix << ": Opening device failed with error code " << errno << ": "
<< strerror(errno) << std::endl;
#else
sif::printWarning("%s: Opening device failed with error code %d: %s\n", diagnosticPrefix, errno,
strerror(errno));
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
openStatus = OPEN_FILE_FAILED; openStatus = OPEN_FILE_FAILED;
} }
} }

View File

@@ -0,0 +1,16 @@
# This abstraction layer requires the gpiod library. You can install this library
# with "sudo apt-get install -y libgpiod-dev". If you are cross-compiling, you need
# to install the package before syncing the sysroot to your host computer.
find_library(LIB_GPIO gpiod)
if(${LIB_GPIO} MATCHES LIB_GPIO-NOTFOUND)
message(STATUS "gpiod library not found, not linking against it")
else()
target_sources(${LIB_FSFW_NAME} PRIVATE
LinuxLibgpioIF.cpp
)
target_link_libraries(${LIB_FSFW_NAME} PRIVATE
${LIB_GPIO}
)
endif()

View File

@@ -0,0 +1,8 @@
target_sources(${LIB_FSFW_NAME} PUBLIC
I2cComIF.cpp
I2cCookie.cpp
)

View File

@@ -26,19 +26,10 @@ ReturnValue_t I2cComIF::initializeInterface(CookieIF* cookie) {
std::string deviceFile; std::string deviceFile;
if (cookie == nullptr) { if (cookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGE("{}", "initializeInterface: Invalid cookie\n");
sif::error << "I2cComIF::initializeInterface: Invalid cookie!" << std::endl;
#endif
return NULLPOINTER; return NULLPOINTER;
} }
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie); auto* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
if (i2cCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "I2cComIF::initializeInterface: Invalid I2C cookie!" << std::endl;
#endif
return NULLPOINTER;
}
i2cAddress = i2cCookie->getAddress(); i2cAddress = i2cCookie->getAddress();
i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress); i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress);
@@ -47,20 +38,14 @@ ReturnValue_t I2cComIF::initializeInterface(CookieIF* cookie) {
I2cInstance i2cInstance = {std::vector<uint8_t>(maxReplyLen), 0}; I2cInstance i2cInstance = {std::vector<uint8_t>(maxReplyLen), 0};
auto statusPair = i2cDeviceMap.emplace(i2cAddress, i2cInstance); auto statusPair = i2cDeviceMap.emplace(i2cAddress, i2cInstance);
if (not statusPair.second) { if (not statusPair.second) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGW("initializeInterface: Failed to insert device with address {} to I2C device map\n",
sif::error << "I2cComIF::initializeInterface: Failed to insert device with address " i2cAddress);
<< i2cAddress << "to I2C device "
<< "map" << std::endl;
#endif
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGE("initializeInterface: Device with address {} already in use\n", i2cAddress);
sif::error << "I2cComIF::initializeInterface: Device with address " << i2cAddress
<< "already in use" << std::endl;
#endif
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
@@ -70,9 +55,7 @@ ReturnValue_t I2cComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, s
std::string deviceFile; std::string deviceFile;
if (sendData == nullptr) { if (sendData == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGW("{}", "sendMessage: Send Data is nullptr\n");
sif::error << "I2cComIF::sendMessage: Send Data is nullptr" << std::endl;
#endif
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
@@ -80,21 +63,16 @@ ReturnValue_t I2cComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, s
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie); auto* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
if (i2cCookie == nullptr) { if (i2cCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGWT("{}", "sendMessage: Invalid I2C Cookie\n");
sif::error << "I2cComIF::sendMessage: Invalid I2C Cookie!" << std::endl;
#endif
return NULLPOINTER; return NULLPOINTER;
} }
address_t i2cAddress = i2cCookie->getAddress(); address_t i2cAddress = i2cCookie->getAddress();
i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress); i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress);
if (i2cDeviceMapIter == i2cDeviceMap.end()) { if (i2cDeviceMapIter == i2cDeviceMap.end()) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGWT("{}", "sendMessage: I2C address of cookie not registered in I2C device map\n");
sif::error << "I2cComIF::sendMessage: i2cAddress of Cookie not "
<< "registered in i2cDeviceMap" << std::endl;
#endif
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
@@ -109,11 +87,8 @@ ReturnValue_t I2cComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, s
} }
if (write(fd, sendData, sendLen) != static_cast<int>(sendLen)) { if (write(fd, sendData, sendLen) != static_cast<int>(sendLen)) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGE("sendMessage: Failed to send data to I2C device with error code {} | {}\n", errno,
sif::error << "I2cComIF::sendMessage: Failed to send data to I2C " strerror(errno));
"device with error code "
<< errno << ". Error description: " << strerror(errno) << std::endl;
#endif
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
@@ -135,11 +110,9 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLe
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie); auto* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
if (i2cCookie == nullptr) { if (i2cCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGWT("{}", "requestReceiveMessage: Invalid I2C Cookie\n");
sif::error << "I2cComIF::requestReceiveMessage: Invalid I2C Cookie!" << std::endl;
#endif
i2cDeviceMapIter->second.replyLen = 0; i2cDeviceMapIter->second.replyLen = 0;
return NULLPOINTER; return NULLPOINTER;
} }
@@ -147,10 +120,8 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLe
address_t i2cAddress = i2cCookie->getAddress(); address_t i2cAddress = i2cCookie->getAddress();
i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress); i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress);
if (i2cDeviceMapIter == i2cDeviceMap.end()) { if (i2cDeviceMapIter == i2cDeviceMap.end()) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGW("requestReceiveMessage: I2C address {} of Cookie not registered in i2cDeviceMap",
sif::error << "I2cComIF::requestReceiveMessage: i2cAddress of Cookie not " i2cAddress);
<< "registered in i2cDeviceMap" << std::endl;
#endif
i2cDeviceMapIter->second.replyLen = 0; i2cDeviceMapIter->second.replyLen = 0;
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
@@ -168,20 +139,13 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLe
uint8_t* replyBuffer = i2cDeviceMapIter->second.replyBuffer.data(); uint8_t* replyBuffer = i2cDeviceMapIter->second.replyBuffer.data();
int readLen = read(fd, replyBuffer, requestLen); ssize_t readLen = read(fd, replyBuffer, requestLen);
if (readLen != static_cast<int>(requestLen)) { if (readLen != static_cast<int>(requestLen)) {
#if FSFW_VERBOSE_LEVEL >= 1 and FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGWT(
sif::error << "I2cComIF::requestReceiveMessage: Reading from I2C " "requestReceiveMessage: Reading from I2C device failed with error code "
<< "device failed with error code " << errno << ". Description" "{} | {}\nRead only {} from {} bytes\n",
<< " of error: " << strerror(errno) << std::endl; errno, strerror(errno), readLen, requestLen);
sif::error << "I2cComIF::requestReceiveMessage: Read only " << readLen << " from " << requestLen
<< " bytes" << std::endl;
#endif
i2cDeviceMapIter->second.replyLen = 0; i2cDeviceMapIter->second.replyLen = 0;
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "I2cComIF::requestReceiveMessage: Read " << readLen << " of " << requestLen
<< " bytes" << std::endl;
#endif
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
@@ -195,21 +159,17 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLe
} }
ReturnValue_t I2cComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) { ReturnValue_t I2cComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) {
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie); auto* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
if (i2cCookie == nullptr) { if (i2cCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGW("{}", "readReceivedMessage: Invalid I2C Cookie\n");
sif::error << "I2cComIF::readReceivedMessage: Invalid I2C Cookie!" << std::endl;
#endif
return NULLPOINTER; return NULLPOINTER;
} }
address_t i2cAddress = i2cCookie->getAddress(); address_t i2cAddress = i2cCookie->getAddress();
i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress); i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress);
if (i2cDeviceMapIter == i2cDeviceMap.end()) { if (i2cDeviceMapIter == i2cDeviceMap.end()) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGE("readReceivedMessage: I2C address {} of cookie not found in I2C device map\n",
sif::error << "I2cComIF::readReceivedMessage: i2cAddress of Cookie not " i2cAddress);
<< "found in i2cDeviceMap" << std::endl;
#endif
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
*buffer = i2cDeviceMapIter->second.replyBuffer.data(); *buffer = i2cDeviceMapIter->second.replyBuffer.data();
@@ -221,16 +181,8 @@ ReturnValue_t I2cComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer,
ReturnValue_t I2cComIF::openDevice(std::string deviceFile, address_t i2cAddress, ReturnValue_t I2cComIF::openDevice(std::string deviceFile, address_t i2cAddress,
int* fileDescriptor) { int* fileDescriptor) {
if (ioctl(*fileDescriptor, I2C_SLAVE, i2cAddress) < 0) { if (ioctl(*fileDescriptor, I2C_SLAVE, i2cAddress) < 0) {
#if FSFW_VERBOSE_LEVEL >= 1 FSFW_LOGWT("openDevice: Specifying target device failed with error code {} | {}\n", errno,
#if FSFW_CPP_OSTREAM_ENABLED == 1 strerror(errno));
sif::warning << "I2cComIF: Specifying target device failed with error code " << errno << "."
<< std::endl;
sif::warning << "Error description " << strerror(errno) << std::endl;
#else
sif::printWarning("I2cComIF: Specifying target device failed with error code %d.\n");
sif::printWarning("Error description: %s\n", strerror(errno));
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;

View File

@@ -0,0 +1,3 @@
target_sources(${LIB_FSFW_NAME} PRIVATE
GpioRPi.cpp
)

View File

@@ -0,0 +1,8 @@
target_sources(${LIB_FSFW_NAME} PUBLIC
SpiComIF.cpp
SpiCookie.cpp
)

View File

@@ -11,6 +11,7 @@
#include <cstring> #include <cstring>
#include "fsfw/FSFW.h" #include "fsfw/FSFW.h"
#include "fsfw/serviceinterface.h"
#include "fsfw_hal/linux/UnixFileGuard.h" #include "fsfw_hal/linux/UnixFileGuard.h"
#include "fsfw_hal/linux/spi/SpiCookie.h" #include "fsfw_hal/linux/spi/SpiCookie.h"
#include "fsfw_hal/linux/utility.h" #include "fsfw_hal/linux/utility.h"
@@ -18,13 +19,7 @@
SpiComIF::SpiComIF(object_id_t objectId, GpioIF* gpioComIF) SpiComIF::SpiComIF(object_id_t objectId, GpioIF* gpioComIF)
: SystemObject(objectId), gpioComIF(gpioComIF) { : SystemObject(objectId), gpioComIF(gpioComIF) {
if (gpioComIF == nullptr) { if (gpioComIF == nullptr) {
#if FSFW_VERBOSE_LEVEL >= 1 FSFW_LOGET("{}", "SpiComIF::SpiComIF: GPIO communication interface invalid\n");
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "SpiComIF::SpiComIF: GPIO communication interface invalid!" << std::endl;
#else
sif::printError("SpiComIF::SpiComIF: GPIO communication interface invalid!\n");
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
} }
spiMutex = MutexFactory::instance()->createMutex(); spiMutex = MutexFactory::instance()->createMutex();
@@ -32,7 +27,7 @@ SpiComIF::SpiComIF(object_id_t objectId, GpioIF* gpioComIF)
ReturnValue_t SpiComIF::initializeInterface(CookieIF* cookie) { ReturnValue_t SpiComIF::initializeInterface(CookieIF* cookie) {
int retval = 0; int retval = 0;
SpiCookie* spiCookie = dynamic_cast<SpiCookie*>(cookie); auto* spiCookie = dynamic_cast<SpiCookie*>(cookie);
if (spiCookie == nullptr) { if (spiCookie == nullptr) {
return NULLPOINTER; return NULLPOINTER;
} }
@@ -45,30 +40,17 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF* cookie) {
SpiInstance spiInstance(bufferSize); SpiInstance spiInstance(bufferSize);
auto statusPair = spiDeviceMap.emplace(spiAddress, spiInstance); auto statusPair = spiDeviceMap.emplace(spiAddress, spiInstance);
if (not statusPair.second) { if (not statusPair.second) {
#if FSFW_VERBOSE_LEVEL >= 1 FSFW_LOGWT(
#if FSFW_CPP_OSTREAM_ENABLED == 1 "SpiComIF::initializeInterface: Failed to insert device with address {} to SPI device "
sif::error << "SpiComIF::initializeInterface: Failed to insert device with address " "map\n",
<< spiAddress << "to SPI device map" << std::endl; spiAddress);
#else
sif::printError(
"SpiComIF::initializeInterface: Failed to insert device with address "
"%lu to SPI device map\n",
static_cast<unsigned long>(spiAddress));
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
/* Now we emplaced the read buffer in the map, we still need to assign that location /* Now we emplaced the read buffer in the map, we still need to assign that location
to the SPI driver transfer struct */ to the SPI driver transfer struct */
spiCookie->assignReadBuffer(statusPair.first->second.replyBuffer.data()); spiCookie->assignReadBuffer(statusPair.first->second.replyBuffer.data());
} else { } else {
#if FSFW_VERBOSE_LEVEL >= 1 FSFW_LOGWT("{}", "initializeInterface: SPI address already exists\n");
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "SpiComIF::initializeInterface: SPI address already exists!" << std::endl;
#else
sif::printError("SpiComIF::initializeInterface: SPI address already exists!\n");
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
@@ -133,7 +115,7 @@ ReturnValue_t SpiComIF::initializeInterface(CookieIF* cookie) {
} }
ReturnValue_t SpiComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) { ReturnValue_t SpiComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) {
SpiCookie* spiCookie = dynamic_cast<SpiCookie*>(cookie); auto* spiCookie = dynamic_cast<SpiCookie*>(cookie);
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
if (spiCookie == nullptr) { if (spiCookie == nullptr) {
@@ -141,19 +123,9 @@ ReturnValue_t SpiComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, s
} }
if (sendLen > spiCookie->getMaxBufferSize()) { if (sendLen > spiCookie->getMaxBufferSize()) {
#if FSFW_VERBOSE_LEVEL >= 1 FSFW_LOGW(
#if FSFW_CPP_OSTREAM_ENABLED == 1 "sendMessage: Too much data sent, send length {} larger than maximum buffer length {}\n",
sif::warning << "SpiComIF::sendMessage: Too much data sent, send length " << sendLen spiCookie->getMaxBufferSize(), sendLen);
<< "larger than maximum buffer length " << spiCookie->getMaxBufferSize()
<< std::endl;
#else
sif::printWarning(
"SpiComIF::sendMessage: Too much data sent, send length %lu larger "
"than maximum buffer length %lu!\n",
static_cast<unsigned long>(sendLen),
static_cast<unsigned long>(spiCookie->getMaxBufferSize()));
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
return DeviceCommunicationIF::TOO_MUCH_DATA; return DeviceCommunicationIF::TOO_MUCH_DATA;
} }
@@ -201,24 +173,12 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie* spiCookie, const
if (gpioId != gpio::NO_GPIO) { if (gpioId != gpio::NO_GPIO) {
result = spiMutex->lockMutex(timeoutType, timeoutMs); result = spiMutex->lockMutex(timeoutType, timeoutMs);
if (result != RETURN_OK) { if (result != RETURN_OK) {
#if FSFW_VERBOSE_LEVEL >= 1 FSFW_LOGET("{}", "sendMessage: Failed to lock mutex\n");
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "SpiComIF::sendMessage: Failed to lock mutex" << std::endl;
#else
sif::printError("SpiComIF::sendMessage: Failed to lock mutex\n");
#endif
#endif
return result; return result;
} }
result = gpioComIF->pullLow(gpioId); result = gpioComIF->pullLow(gpioId);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
#if FSFW_VERBOSE_LEVEL >= 1 FSFW_LOGW("{}", "sendMessage: Pulling low CS pin failed\n");
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "SpiComIF::sendMessage: Pulling low CS pin failed" << std::endl;
#else
sif::printWarning("SpiComIF::sendMessage: Pulling low CS pin failed");
#endif
#endif
return result; return result;
} }
} }
@@ -237,13 +197,7 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie* spiCookie, const
} else { } else {
/* We write with a blocking half-duplex transfer here */ /* We write with a blocking half-duplex transfer here */
if (write(fileDescriptor, sendData, sendLen) != static_cast<ssize_t>(sendLen)) { if (write(fileDescriptor, sendData, sendLen) != static_cast<ssize_t>(sendLen)) {
#if FSFW_VERBOSE_LEVEL >= 1 FSFW_LOGET("{}", "sendMessage: Half-Duplex write operation failed\n");
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "SpiComIF::sendMessage: Half-Duplex write operation failed!" << std::endl;
#else
sif::printWarning("SpiComIF::sendMessage: Half-Duplex write operation failed!\n");
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
result = HALF_DUPLEX_TRANSFER_FAILED; result = HALF_DUPLEX_TRANSFER_FAILED;
} }
} }
@@ -252,9 +206,7 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie* spiCookie, const
gpioComIF->pullHigh(gpioId); gpioComIF->pullHigh(gpioId);
result = spiMutex->unlockMutex(); result = spiMutex->unlockMutex();
if (result != RETURN_OK) { if (result != RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGWT("{}", "sendMessage: Failed to unlock mutex\n");
sif::error << "SpiComIF::sendMessage: Failed to unlock mutex" << std::endl;
#endif
return result; return result;
} }
} }
@@ -264,7 +216,7 @@ ReturnValue_t SpiComIF::performRegularSendOperation(SpiCookie* spiCookie, const
ReturnValue_t SpiComIF::getSendSuccess(CookieIF* cookie) { return HasReturnvaluesIF::RETURN_OK; } ReturnValue_t SpiComIF::getSendSuccess(CookieIF* cookie) { return HasReturnvaluesIF::RETURN_OK; }
ReturnValue_t SpiComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLen) { ReturnValue_t SpiComIF::requestReceiveMessage(CookieIF* cookie, size_t requestLen) {
SpiCookie* spiCookie = dynamic_cast<SpiCookie*>(cookie); auto* spiCookie = dynamic_cast<SpiCookie*>(cookie);
if (spiCookie == nullptr) { if (spiCookie == nullptr) {
return NULLPOINTER; return NULLPOINTER;
} }
@@ -296,22 +248,14 @@ ReturnValue_t SpiComIF::performHalfDuplexReception(SpiCookie* spiCookie) {
if (gpioId != gpio::NO_GPIO) { if (gpioId != gpio::NO_GPIO) {
result = spiMutex->lockMutex(timeoutType, timeoutMs); result = spiMutex->lockMutex(timeoutType, timeoutMs);
if (result != RETURN_OK) { if (result != RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGW("{}", "getSendSuccess: Failed to lock mutex\n");
sif::error << "SpiComIF::getSendSuccess: Failed to lock mutex" << std::endl;
#endif
return result; return result;
} }
gpioComIF->pullLow(gpioId); gpioComIF->pullLow(gpioId);
} }
if (read(fileDescriptor, rxBuf, readSize) != static_cast<ssize_t>(readSize)) { if (read(fileDescriptor, rxBuf, readSize) != static_cast<ssize_t>(readSize)) {
#if FSFW_VERBOSE_LEVEL >= 1 FSFW_LOGW("{}", "sendMessage: Half-Duplex read operation failed\n");
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "SpiComIF::sendMessage: Half-Duplex read operation failed!" << std::endl;
#else
sif::printWarning("SpiComIF::sendMessage: Half-Duplex read operation failed!\n");
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
result = HALF_DUPLEX_TRANSFER_FAILED; result = HALF_DUPLEX_TRANSFER_FAILED;
} }
@@ -319,9 +263,7 @@ ReturnValue_t SpiComIF::performHalfDuplexReception(SpiCookie* spiCookie) {
gpioComIF->pullHigh(gpioId); gpioComIF->pullHigh(gpioId);
result = spiMutex->unlockMutex(); result = spiMutex->unlockMutex();
if (result != RETURN_OK) { if (result != RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGW("{}", "getSendSuccess: Failed to unlock mutex\n");
sif::error << "SpiComIF::getSendSuccess: Failed to unlock mutex" << std::endl;
#endif
return result; return result;
} }
} }
@@ -330,7 +272,7 @@ ReturnValue_t SpiComIF::performHalfDuplexReception(SpiCookie* spiCookie) {
} }
ReturnValue_t SpiComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) { ReturnValue_t SpiComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) {
SpiCookie* spiCookie = dynamic_cast<SpiCookie*>(cookie); auto* spiCookie = dynamic_cast<SpiCookie*>(cookie);
if (spiCookie == nullptr) { if (spiCookie == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
@@ -361,16 +303,10 @@ void SpiComIF::performSpiWiretapping(SpiCookie* spiCookie) {
return; return;
} }
size_t dataLen = spiCookie->getTransferStructHandle()->len; size_t dataLen = spiCookie->getTransferStructHandle()->len;
uint8_t* dataPtr = reinterpret_cast<uint8_t*>(spiCookie->getTransferStructHandle()->tx_buf); auto* dataPtr = reinterpret_cast<uint8_t*>(spiCookie->getTransferStructHandle()->tx_buf);
#if FSFW_CPP_OSTREAM_ENABLED == 1 sif::info("Sent SPI data:\n");
sif::info << "Sent SPI data: " << std::endl;
arrayprinter::print(dataPtr, dataLen, OutputType::HEX, false); arrayprinter::print(dataPtr, dataLen, OutputType::HEX, false);
sif::info << "Received SPI data: " << std::endl; sif::info("Received SPI data:\n");
#else
sif::printInfo("Sent SPI data: \n");
arrayprinter::print(dataPtr, dataLen, OutputType::HEX, false);
sif::printInfo("Received SPI data: \n");
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
dataPtr = reinterpret_cast<uint8_t*>(spiCookie->getTransferStructHandle()->rx_buf); dataPtr = reinterpret_cast<uint8_t*>(spiCookie->getTransferStructHandle()->rx_buf);
arrayprinter::print(dataPtr, dataLen, OutputType::HEX, false); arrayprinter::print(dataPtr, dataLen, OutputType::HEX, false);
} }

View File

@@ -0,0 +1,4 @@
target_sources(${LIB_FSFW_NAME} PUBLIC
UartComIF.cpp
UartCookie.cpp
)

View File

@@ -1,10 +1,10 @@
#include "UartComIF.h" #include "UartComIF.h"
#include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <termios.h> #include <termios.h>
#include <unistd.h> #include <unistd.h>
#include <cerrno>
#include <cstring> #include <cstring>
#include "fsfw/FSFW.h" #include "fsfw/FSFW.h"
@@ -23,11 +23,9 @@ ReturnValue_t UartComIF::initializeInterface(CookieIF* cookie) {
return NULLPOINTER; return NULLPOINTER;
} }
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie); auto* uartCookie = dynamic_cast<UartCookie*>(cookie);
if (uartCookie == nullptr) { if (uartCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGE("{}", "initializeInterface: Invalid UART Cookie\n");
sif::error << "UartComIF::initializeInterface: Invalid UART Cookie!" << std::endl;
#endif
return NULLPOINTER; return NULLPOINTER;
} }
@@ -42,18 +40,12 @@ ReturnValue_t UartComIF::initializeInterface(CookieIF* cookie) {
size_t maxReplyLen = uartCookie->getMaxReplyLen(); size_t maxReplyLen = uartCookie->getMaxReplyLen();
UartElements uartElements = {fileDescriptor, std::vector<uint8_t>(maxReplyLen), 0}; UartElements uartElements = {fileDescriptor, std::vector<uint8_t>(maxReplyLen), 0};
auto status = uartDeviceMap.emplace(deviceFile, uartElements); auto status = uartDeviceMap.emplace(deviceFile, uartElements);
if (status.second == false) { if (!status.second) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGW("initializeInterface: Failed to insert device {} to UART device map\n", deviceFile);
sif::warning << "UartComIF::initializeInterface: Failed to insert device " << deviceFile
<< "to UART device map" << std::endl;
#endif
return RETURN_FAILED; return RETURN_FAILED;
} }
} else { } else {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGW("initializeInterface: UART device {} already in use\n", deviceFile);
sif::warning << "UartComIF::initializeInterface: UART device " << deviceFile
<< " already in use" << std::endl;
#endif
return RETURN_FAILED; return RETURN_FAILED;
} }
@@ -73,19 +65,14 @@ int UartComIF::configureUartPort(UartCookie* uartCookie) {
int fd = open(deviceFile.c_str(), flags); int fd = open(deviceFile.c_str(), flags);
if (fd < 0) { if (fd < 0) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGW("configureUartPort: Failed to open UART {} with error code {} | {}\n", deviceFile,
sif::warning << "UartComIF::configureUartPort: Failed to open uart " << deviceFile errno, strerror(errno));
<< "with error code " << errno << strerror(errno) << std::endl;
#endif
return fd; return fd;
} }
/* Read in existing settings */ /* Read in existing settings */
if (tcgetattr(fd, &options) != 0) { if (tcgetattr(fd, &options) != 0) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGW("configureUartPort: Error {} from tcgetattr: {}\n", errno, strerror(errno));
sif::warning << "UartComIF::configureUartPort: Error " << errno
<< "from tcgetattr: " << strerror(errno) << std::endl;
#endif
return fd; return fd;
} }
@@ -106,10 +93,8 @@ int UartComIF::configureUartPort(UartCookie* uartCookie) {
/* Save option settings */ /* Save option settings */
if (tcsetattr(fd, TCSANOW, &options) != 0) { if (tcsetattr(fd, TCSANOW, &options) != 0) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGW("configureUartPort: Failed to set options with error {} | {}\n", errno,
sif::warning << "UartComIF::configureUartPort: Failed to set options with error " << errno strerror(errno));
<< ": " << strerror(errno);
#endif
return fd; return fd;
} }
return fd; return fd;
@@ -161,9 +146,8 @@ void UartComIF::setDatasizeOptions(struct termios* options, UartCookie* uartCook
options->c_cflag |= CS8; options->c_cflag |= CS8;
break; break;
default: default:
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGW("setDatasizeOptions: Invalid size {} specified\n",
sif::warning << "UartComIF::setDatasizeOptions: Invalid size specified" << std::endl; static_cast<unsigned int>(uartCookie->getBitsPerWord()));
#endif
break; break;
} }
} }
@@ -316,9 +300,7 @@ void UartComIF::configureBaudrate(struct termios* options, UartCookie* uartCooki
break; break;
#endif // ! __APPLE__ #endif // ! __APPLE__
default: default:
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGW("{}", "UartComIF::configureBaudrate: Baudrate not supported\n");
sif::warning << "UartComIF::configureBaudrate: Baudrate not supported" << std::endl;
#endif
break; break;
} }
} }
@@ -333,37 +315,27 @@ ReturnValue_t UartComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData,
} }
if (sendData == nullptr) { if (sendData == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGWT("{}", "sendMessage: Send data is nullptr");
sif::warning << "UartComIF::sendMessage: Send data is nullptr" << std::endl;
#endif
return RETURN_FAILED; return RETURN_FAILED;
} }
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie); auto* uartCookie = dynamic_cast<UartCookie*>(cookie);
if (uartCookie == nullptr) { if (uartCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGWT("{}", "sendMessage: Invalid UART Cookie\n");
sif::warning << "UartComIF::sendMessasge: Invalid UART Cookie!" << std::endl;
#endif
return NULLPOINTER; return NULLPOINTER;
} }
deviceFile = uartCookie->getDeviceFile(); deviceFile = uartCookie->getDeviceFile();
uartDeviceMapIter = uartDeviceMap.find(deviceFile); uartDeviceMapIter = uartDeviceMap.find(deviceFile);
if (uartDeviceMapIter == uartDeviceMap.end()) { if (uartDeviceMapIter == uartDeviceMap.end()) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGWT("{}", "sendMessage: Device file {} not in UART map\n", deviceFile);
sif::debug << "UartComIF::sendMessage: Device file " << deviceFile << "not in UART map"
<< std::endl;
#endif
return RETURN_FAILED; return RETURN_FAILED;
} }
fd = uartDeviceMapIter->second.fileDescriptor; fd = uartDeviceMapIter->second.fileDescriptor;
if (write(fd, sendData, sendLen) != static_cast<int>(sendLen)) { if (write(fd, sendData, sendLen) != static_cast<int>(sendLen)) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGE("sendMessage: Failed to send data with error code {} | {}", errno, strerror(errno));
sif::error << "UartComIF::sendMessage: Failed to send data with error code " << errno
<< ": Error description: " << strerror(errno) << std::endl;
#endif
return RETURN_FAILED; return RETURN_FAILED;
} }
@@ -376,11 +348,9 @@ ReturnValue_t UartComIF::requestReceiveMessage(CookieIF* cookie, size_t requestL
std::string deviceFile; std::string deviceFile;
UartDeviceMapIter uartDeviceMapIter; UartDeviceMapIter uartDeviceMapIter;
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie); auto* uartCookie = dynamic_cast<UartCookie*>(cookie);
if (uartCookie == nullptr) { if (uartCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGWT("{}", "requestReceiveMessage: Invalid UART Cookie\n");
sif::debug << "UartComIF::requestReceiveMessage: Invalid Uart Cookie!" << std::endl;
#endif
return NULLPOINTER; return NULLPOINTER;
} }
@@ -393,10 +363,7 @@ ReturnValue_t UartComIF::requestReceiveMessage(CookieIF* cookie, size_t requestL
} }
if (uartDeviceMapIter == uartDeviceMap.end()) { if (uartDeviceMapIter == uartDeviceMap.end()) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGW("requestReceiveMessage: Device file {} not in UART map\n", deviceFile);
sif::debug << "UartComIF::requestReceiveMessage: Device file " << deviceFile
<< " not in uart map" << std::endl;
#endif
return RETURN_FAILED; return RETURN_FAILED;
} }
@@ -414,7 +381,7 @@ ReturnValue_t UartComIF::handleCanonicalRead(UartCookie& uartCookie, UartDeviceM
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
uint8_t maxReadCycles = uartCookie.getReadCycles(); uint8_t maxReadCycles = uartCookie.getReadCycles();
uint8_t currentReadCycles = 0; uint8_t currentReadCycles = 0;
int bytesRead = 0; ssize_t bytesRead = 0;
size_t currentBytesRead = 0; size_t currentBytesRead = 0;
size_t maxReplySize = uartCookie.getMaxReplyLen(); size_t maxReplySize = uartCookie.getMaxReplyLen();
int fd = iter->second.fileDescriptor; int fd = iter->second.fileDescriptor;
@@ -425,16 +392,7 @@ ReturnValue_t UartComIF::handleCanonicalRead(UartCookie& uartCookie, UartDeviceM
if (currentBytesRead >= maxReplySize) { if (currentBytesRead >= maxReplySize) {
// Overflow risk. Emit warning, trigger event and break. If this happens, // Overflow risk. Emit warning, trigger event and break. If this happens,
// the reception buffer is not large enough or data is not polled often enough. // the reception buffer is not large enough or data is not polled often enough.
#if FSFW_VERBOSE_LEVEL >= 1 FSFW_LOGWT("{}", "requestReceiveMessage: Next read would cause overflow\n");
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::requestReceiveMessage: Next read would cause overflow!"
<< std::endl;
#else
sif::printWarning(
"UartComIF::requestReceiveMessage: "
"Next read would cause overflow!");
#endif
#endif
result = UART_RX_BUFFER_TOO_SMALL; result = UART_RX_BUFFER_TOO_SMALL;
break; break;
} else { } else {
@@ -445,15 +403,7 @@ ReturnValue_t UartComIF::handleCanonicalRead(UartCookie& uartCookie, UartDeviceM
if (bytesRead < 0) { if (bytesRead < 0) {
// EAGAIN: No data available in non-blocking mode // EAGAIN: No data available in non-blocking mode
if (errno != EAGAIN) { if (errno != EAGAIN) {
#if FSFW_VERBOSE_LEVEL >= 1 FSFW_LOGWT("handleCanonicalRead: read failed with code {} | {}\n", errno, strerror(errno));
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::handleCanonicalRead: read failed with code" << errno << ": "
<< strerror(errno) << std::endl;
#else
sif::printWarning("UartComIF::handleCanonicalRead: read failed with code %d: %s\n", errno,
strerror(errno));
#endif
#endif
return RETURN_FAILED; return RETURN_FAILED;
} }
@@ -473,27 +423,16 @@ ReturnValue_t UartComIF::handleNoncanonicalRead(UartCookie& uartCookie, UartDevi
auto bufferPtr = iter->second.replyBuffer.data(); auto bufferPtr = iter->second.replyBuffer.data();
// Size check to prevent buffer overflow // Size check to prevent buffer overflow
if (requestLen > uartCookie.getMaxReplyLen()) { if (requestLen > uartCookie.getMaxReplyLen()) {
#if FSFW_VERBOSE_LEVEL >= 1 FSFW_LOGW("{}", "requestReceiveMessage: Next read would cause overflow\n");
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UartComIF::requestReceiveMessage: Next read would cause overflow!"
<< std::endl;
#else
sif::printWarning(
"UartComIF::requestReceiveMessage: "
"Next read would cause overflow!");
#endif
#endif
return UART_RX_BUFFER_TOO_SMALL; return UART_RX_BUFFER_TOO_SMALL;
} }
int bytesRead = read(fd, bufferPtr, requestLen); ssize_t bytesRead = read(fd, bufferPtr, requestLen);
if (bytesRead < 0) { if (bytesRead < 0) {
return RETURN_FAILED; return RETURN_FAILED;
} else if (bytesRead != static_cast<int>(requestLen)) { } else if (bytesRead != static_cast<int>(requestLen)) {
if (uartCookie.isReplySizeFixed()) { if (uartCookie.isReplySizeFixed()) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGWT("UartComIF::requestReceiveMessage: Only read {} of {} bytes\n", bytesRead,
sif::warning << "UartComIF::requestReceiveMessage: Only read " << bytesRead << " of " requestLen);
<< requestLen << " bytes" << std::endl;
#endif
return RETURN_FAILED; return RETURN_FAILED;
} }
} }
@@ -505,21 +444,16 @@ ReturnValue_t UartComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer,
std::string deviceFile; std::string deviceFile;
UartDeviceMapIter uartDeviceMapIter; UartDeviceMapIter uartDeviceMapIter;
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie); auto* uartCookie = dynamic_cast<UartCookie*>(cookie);
if (uartCookie == nullptr) { if (uartCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGWT("{}", "readReceivedMessage: Invalid uart cookie");
sif::debug << "UartComIF::readReceivedMessage: Invalid uart cookie!" << std::endl;
#endif
return NULLPOINTER; return NULLPOINTER;
} }
deviceFile = uartCookie->getDeviceFile(); deviceFile = uartCookie->getDeviceFile();
uartDeviceMapIter = uartDeviceMap.find(deviceFile); uartDeviceMapIter = uartDeviceMap.find(deviceFile);
if (uartDeviceMapIter == uartDeviceMap.end()) { if (uartDeviceMapIter == uartDeviceMap.end()) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGW("UartComIF::readReceivedMessage: Device file {} not in UART map\n", deviceFile);
sif::debug << "UartComIF::readReceivedMessage: Device file " << deviceFile << " not in uart map"
<< std::endl;
#endif
return RETURN_FAILED; return RETURN_FAILED;
} }
@@ -535,11 +469,9 @@ ReturnValue_t UartComIF::readReceivedMessage(CookieIF* cookie, uint8_t** buffer,
ReturnValue_t UartComIF::flushUartRxBuffer(CookieIF* cookie) { ReturnValue_t UartComIF::flushUartRxBuffer(CookieIF* cookie) {
std::string deviceFile; std::string deviceFile;
UartDeviceMapIter uartDeviceMapIter; UartDeviceMapIter uartDeviceMapIter;
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie); auto* uartCookie = dynamic_cast<UartCookie*>(cookie);
if (uartCookie == nullptr) { if (uartCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGWT("{}", "flushUartRxBuffer: Invalid UART cookie\n");
sif::warning << "UartComIF::flushUartRxBuffer: Invalid uart cookie!" << std::endl;
#endif
return NULLPOINTER; return NULLPOINTER;
} }
deviceFile = uartCookie->getDeviceFile(); deviceFile = uartCookie->getDeviceFile();
@@ -555,11 +487,9 @@ ReturnValue_t UartComIF::flushUartRxBuffer(CookieIF* cookie) {
ReturnValue_t UartComIF::flushUartTxBuffer(CookieIF* cookie) { ReturnValue_t UartComIF::flushUartTxBuffer(CookieIF* cookie) {
std::string deviceFile; std::string deviceFile;
UartDeviceMapIter uartDeviceMapIter; UartDeviceMapIter uartDeviceMapIter;
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie); auto* uartCookie = dynamic_cast<UartCookie*>(cookie);
if (uartCookie == nullptr) { if (uartCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGWT("{}", "flushUartTxBuffer: Invalid uart cookie\n");
sif::warning << "UartComIF::flushUartTxBuffer: Invalid uart cookie!" << std::endl;
#endif
return NULLPOINTER; return NULLPOINTER;
} }
deviceFile = uartCookie->getDeviceFile(); deviceFile = uartCookie->getDeviceFile();
@@ -575,11 +505,9 @@ ReturnValue_t UartComIF::flushUartTxBuffer(CookieIF* cookie) {
ReturnValue_t UartComIF::flushUartTxAndRxBuf(CookieIF* cookie) { ReturnValue_t UartComIF::flushUartTxAndRxBuf(CookieIF* cookie) {
std::string deviceFile; std::string deviceFile;
UartDeviceMapIter uartDeviceMapIter; UartDeviceMapIter uartDeviceMapIter;
UartCookie* uartCookie = dynamic_cast<UartCookie*>(cookie); auto* uartCookie = dynamic_cast<UartCookie*>(cookie);
if (uartCookie == nullptr) { if (uartCookie == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGWT("{}", "flushUartTxAndRxBuf: Invalid UART cookie\n");
sif::warning << "UartComIF::flushUartTxAndRxBuf: Invalid uart cookie!" << std::endl;
#endif
return NULLPOINTER; return NULLPOINTER;
} }
deviceFile = uartCookie->getDeviceFile(); deviceFile = uartCookie->getDeviceFile();

View File

@@ -90,7 +90,7 @@ class UartComIF : public DeviceCommunicationIF, public SystemObject {
* parity settings. * parity settings.
* *
*/ */
void setParityOptions(struct termios* options, UartCookie* uartCookie); static void setParityOptions(struct termios* options, UartCookie* uartCookie);
void setStopBitOptions(struct termios* options, UartCookie* uartCookie); void setStopBitOptions(struct termios* options, UartCookie* uartCookie);

View File

@@ -12,7 +12,7 @@ enum class StopBits { ONE_STOP_BIT, TWO_STOP_BITS };
enum class UartModes { CANONICAL, NON_CANONICAL }; enum class UartModes { CANONICAL, NON_CANONICAL };
enum class BitsPerWord { BITS_5, BITS_6, BITS_7, BITS_8 }; enum class BitsPerWord : unsigned int { BITS_5 = 5, BITS_6 = 6, BITS_7 = 7, BITS_8 = 8 };
enum class UartBaudRate { enum class UartBaudRate {
RATE_50, RATE_50,

View File

@@ -0,0 +1,3 @@
target_sources(${LIB_FSFW_NAME} PUBLIC
UioMapper.cpp
)

View File

@@ -0,0 +1,13 @@
#include "fsfw_hal/linux/utility.h"
#include <cerrno>
#include <cstring>
#include "fsfw/serviceinterface.h"
void utility::handleIoctlError(const char* const customPrintout) {
if (customPrintout != nullptr) {
FSFW_LOGW(customPrintout);
}
FSFW_LOGW("Error code {} | {}\n", errno, strerror(errno));
}

View File

@@ -2,4 +2,6 @@ add_subdirectory(spi)
add_subdirectory(gpio) add_subdirectory(gpio)
add_subdirectory(devicetest) add_subdirectory(devicetest)
target_sources(${LIB_FSFW_NAME} PRIVATE dma.cpp) target_sources(${LIB_FSFW_NAME} PRIVATE
dma.cpp
)

View File

@@ -0,0 +1,3 @@
target_sources(${LIB_FSFW_NAME} PRIVATE
GyroL3GD20H.cpp
)

View File

@@ -10,10 +10,6 @@
#include "stm32h7xx_hal.h" #include "stm32h7xx_hal.h"
#include "stm32h7xx_hal_spi.h" #include "stm32h7xx_hal_spi.h"
#ifndef STM_USE_PERIPHERAL_TX_BUFFER_MPU_PROTECTION
#define STM_USE_PERIPHERAL_TX_BUFFER_MPU_PROTECTION 1
#endif
enum class TransferStates { IDLE, WAIT, SUCCESS, FAILURE }; enum class TransferStates { IDLE, WAIT, SUCCESS, FAILURE };
class GyroL3GD20H { class GyroL3GD20H {

View File

@@ -0,0 +1,3 @@
target_sources(${LIB_FSFW_NAME} PRIVATE
gpio.cpp
)

View File

@@ -0,0 +1,2 @@
target_sources(${LIB_FSFW_NAME} PRIVATE
)

View File

@@ -0,0 +1,9 @@
target_sources(${LIB_FSFW_NAME} PRIVATE
spiCore.cpp
spiDefinitions.cpp
spiInterrupts.cpp
mspInit.cpp
SpiCookie.cpp
SpiComIF.cpp
stm32h743zi.cpp
)

View File

@@ -0,0 +1,2 @@
target_sources(${LIB_FSFW_NAME} PRIVATE
)

View File

@@ -57,10 +57,10 @@ class ServiceInterfaceStream : public std::ostream {
// Forward declaration of interface streams. These should be instantiated in // Forward declaration of interface streams. These should be instantiated in
// main. They can then be used like std::cout or std::cerr. // main. They can then be used like std::cout or std::cerr.
namespace sif { namespace sif {
extern ServiceInterfaceStream debug; // extern ServiceInterfaceStream debug;
extern ServiceInterfaceStream info; // extern ServiceInterfaceStream info;
extern ServiceInterfaceStream warning; // extern ServiceInterfaceStream warning;
extern ServiceInterfaceStream error; // extern ServiceInterfaceStream error;
} // namespace sif } // namespace sif
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ #endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */

View File

@@ -4,10 +4,9 @@ if [[ ! -f README.md ]]; then
fi fi
cmake_fmt="cmake-format" cmake_fmt="cmake-format"
file_selectors="-iname CMakeLists.txt"
if command -v ${cmake_fmt} &> /dev/null; then if command -v ${cmake_fmt} &> /dev/null; then
${cmake_fmt} -i CMakeLists.txt cmake_fmt_cmd="${cmake_fmt} -i CMakeLists.txt"
find ./src ${file_selectors} | xargs ${cmake_fmt} -i eval ${cmake_fmt_cmd}
else else
echo "No ${cmake_fmt} tool found, not formatting CMake files" echo "No ${cmake_fmt} tool found, not formatting CMake files"
fi fi
@@ -15,8 +14,9 @@ fi
cpp_format="clang-format" cpp_format="clang-format"
file_selectors="-iname *.h -o -iname *.cpp -o -iname *.c -o -iname *.tpp" file_selectors="-iname *.h -o -iname *.cpp -o -iname *.c -o -iname *.tpp"
if command -v ${cpp_format} &> /dev/null; then if command -v ${cpp_format} &> /dev/null; then
find ./src ${file_selectors} | xargs ${cpp_format} --style=file -i find ./src ${file_selectors} | xargs clang-format --style=file -i
find ./unittests ${file_selectors} | xargs ${cpp_format} --style=file -i find ./hal ${file_selectors} | xargs clang-format --style=file -i
find ./tests ${file_selectors} | xargs clang-format --style=file -i
else else
echo "No ${cpp_format} tool found, not formatting C++/C files" echo "No ${cpp_format} tool found, not formatting C++/C files"
fi fi

View File

@@ -48,20 +48,6 @@ def main():
action="store_true", action="store_true",
help="Run valgrind on generated test binary", help="Run valgrind on generated test binary",
) )
parser.add_argument(
"-g",
"--generators",
default = "Ninja",
action="store",
help="CMake generators",
)
parser.add_argument(
"-w",
"--windows",
default=False,
action="store_true",
help="Run on windows",
)
args = parser.parse_args() args = parser.parse_args()
if args.all: if args.all:
@@ -129,14 +115,14 @@ def handle_tests_type(args, build_dir_list: list):
if args.create: if args.create:
if os.path.exists(UNITTEST_FOLDER_NAME): if os.path.exists(UNITTEST_FOLDER_NAME):
shutil.rmtree(UNITTEST_FOLDER_NAME) shutil.rmtree(UNITTEST_FOLDER_NAME)
create_tests_build_cfg(args) create_tests_build_cfg()
build_directory = UNITTEST_FOLDER_NAME build_directory = UNITTEST_FOLDER_NAME
elif len(build_dir_list) == 0: elif len(build_dir_list) == 0:
print( print(
"No valid CMake tests build directory found. " "No valid CMake tests build directory found. "
"Trying to set up test build system" "Trying to set up test build system"
) )
create_tests_build_cfg(args) create_tests_build_cfg()
build_directory = UNITTEST_FOLDER_NAME build_directory = UNITTEST_FOLDER_NAME
elif len(build_dir_list) == 1: elif len(build_dir_list) == 1:
build_directory = build_dir_list[0] build_directory = build_dir_list[0]
@@ -161,15 +147,10 @@ def handle_tests_type(args, build_dir_list: list):
os.chdir("..") os.chdir("..")
def create_tests_build_cfg(args): def create_tests_build_cfg():
os.mkdir(UNITTEST_FOLDER_NAME) os.mkdir(UNITTEST_FOLDER_NAME)
os.chdir(UNITTEST_FOLDER_NAME) os.chdir(UNITTEST_FOLDER_NAME)
if args.windows: cmd_runner("cmake -DFSFW_OSAL=host -DFSFW_BUILD_UNITTESTS=ON ..")
cmake_cmd = 'cmake -G "' + args.generators + '" -DFSFW_OSAL=host -DFSFW_BUILD_TESTS=ON \
-DGCOVR_PATH="py -m gcovr" ..'
else:
cmake_cmd = 'cmake -G "' + args.generators + '" -DFSFW_OSAL=host -DFSFW_BUILD_TESTS=ON ..'
cmd_runner(cmake_cmd)
os.chdir("..") os.chdir("..")

View File

@@ -1,11 +1,9 @@
target_include_directories(${LIB_FSFW_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) target_include_directories(${LIB_FSFW_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
)
target_include_directories(${LIB_FSFW_NAME} target_include_directories(${LIB_FSFW_NAME} INTERFACE
INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) ${CMAKE_CURRENT_SOURCE_DIR}
)
add_subdirectory(fsfw) add_subdirectory(fsfw)
if(FSFW_ADD_HAL)
add_subdirectory(fsfw_hal)
endif()
add_subdirectory(fsfw_tests)

View File

@@ -1,4 +1,6 @@
target_sources(${LIB_FSFW_NAME} PRIVATE version.cpp) target_sources(${LIB_FSFW_NAME} PRIVATE
version.cpp
)
# Core # Core
@@ -35,22 +37,22 @@ add_subdirectory(tmtcservices)
# Optional # Optional
if(FSFW_ADD_MONITORING) if(FSFW_ADD_MONITORING)
add_subdirectory(monitoring) add_subdirectory(monitoring)
endif() endif()
if(FSFW_ADD_PUS) if(FSFW_ADD_PUS)
add_subdirectory(pus) add_subdirectory(pus)
endif() endif()
if(FSFW_ADD_TMSTORAGE) if(FSFW_ADD_TMSTORAGE)
add_subdirectory(tmstorage) add_subdirectory(tmstorage)
endif() endif()
if(FSFW_ADD_COORDINATES) if(FSFW_ADD_COORDINATES)
add_subdirectory(coordinates) add_subdirectory(coordinates)
endif() endif()
if(FSFW_ADD_RMAP) if(FSFW_ADD_RMAP)
add_subdirectory(rmap) add_subdirectory(rmap)
endif() endif()
if(FSFW_ADD_DATALINKLAYER) if(FSFW_ADD_DATALINKLAYER)
add_subdirectory(datalinklayer) add_subdirectory(datalinklayer)
endif() endif()
# OSAL # OSAL

Some files were not shown because too many files have changed in this diff Show More