SpaceTeam / STS1_COBC_SW

Software for the communication and onboard computer (COBC) of SpaceTeamSat1 (STS1)
MIT License
10 stars 2 forks source link

STS1 COBC SW

This project contains the software for the communication and onboard computer (COBC) of SpaceTeamSat1 (STS1).

Contents

Building and developing

The recommended way to develop and build this project is to use the Docker image tuwienspaceteam/sts1-cobc as a dev container. It is specifically built for that purpose, i.e., it comes with all required compilers, libraries and tools. This makes it easier to get started but also ensures reliable and consistent builds. See this page on our internal wiki for more information.

If you don't want to use Docker, it is still best to check out the Dockerfiles (here and here) to see how to properly install everything.

Presets

This project makes use of CMake presets to simplify the process of configuring the project. As a developer, you should create a CMakeUserPresets.json file at the top-level directory of the repository. If you use the Docker image, the file should look something like the following:

CMakeUserPresets.json ~~~json { "version": 3, "cmakeMinimumRequired": { "major": 3, "minor": 22, "patch": 0 }, "configurePresets": [ { "name": "dev-common", "hidden": true, "inherits": [ "dev-mode", "clang-tidy", "ci-unix", "include-what-you-use" ], "generator": "Ninja", "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug", "CMAKE_EXPORT_COMPILE_COMMANDS": "ON", "BUILD_MCSS_DOCS": "ON", "HW_VERSION": "27" } }, { "name": "dev-linux-x86", "binaryDir": "${sourceDir}/build/linux-x86", "inherits": "dev-common", "toolchainFile": "/linux-x86.cmake" }, { "name": "dev-cobc", "binaryDir": "${sourceDir}/build/cobc", "inherits": "dev-common", "toolchainFile": "/stm32f411.cmake", "cacheVariables": { "HSE_VALUE": "12000000" } }, { "name": "dev-coverage", "binaryDir": "${sourceDir}/build/coverage", "inherits": [ "dev-mode", "coverage-unix" ], "toolchainFile": "/linux-x86.cmake" } ], "buildPresets": [ { "name": "dev-linux-x86", "configurePreset": "dev-linux-x86", "configuration": "Debug", "jobs": 4 }, { "name": "dev-cobc", "configurePreset": "dev-cobc", "configuration": "Debug", "jobs": 4 } ], "testPresets": [ { "name": "dev-linux-x86", "configurePreset": "dev-linux-x86", "configuration": "Debug", "output": { "outputOnFailure": true }, "execution": { "jobs": 4 } } ] } ~~~

The paths to the toolchain files depend on your setup. If you don't use Docker you mostly likely have to change them. The number of jobs given in the build and test presets must be adapted by you as well and should ideally be set to the number of threads available on your CPU. In general, CMakeUserPresets.json is the perfect place in which you can put all sorts of things that depend on your personal setup or preference, and that you would otherwise want to pass to the CMake command in the terminal.

Include What You Use

To ensure that source files include only the header files they need, we use Include What You Use (IWYU), a tool built on top of Clang. IWYU supports a mapping file for more precise configuration, allowing us to make sure it works the way we want it to. In particular, this means that we have to do the following additional steps when adding a header (.hpp) or inline implementation (.ipp) file:

The complete mapping file is called iwyu.imp and is located in the top-level directory.

Configure, build and test

The following instructions assume that you added the above CMakeUserPresets.json and that the commands are executed from within the Docker container. This is easy with VS Code since it allows directly developing inside a container. If you don't use VS Code you must execute all commands via docker run. In this case it is convenient to use an alias like the following:

# Version 1: always mounts the STS1_COBC_SW folder
alias dr-sts1="docker run -it -v /path/to/STS1_COBC_SW:/project -w='/project' tuwienspaceteam/sts1-cobc:0.7.0"

# Version 2: mounts the current working directory. This means that you must be in the
# top-level directory of the COBC SW repo when executing the build commands.
alias dr-sts1="docker run -it -v $(pwd):/project -w='/project' tuwienspaceteam/sts1-cobc:0.7.0"

You can configure, build and test the linux-x86 parts of the project with the following commands:

cmake --preset=dev-linux-x86
cmake --build --preset=dev-linux-x86
cmake --build build/linux-x86 -t Tests
ctest --preset=dev-linux-x86

To run a dummy program on Linux execute

./build/linux-x86/HelloDummy

To cross-compile for the COBC run

cmake --preset=dev-cobc
cmake --build --preset=dev-cobc

If you want to build a specific target, e.g., the hardware test for the FRAM you must execute

cmake --prest=dev-cobc
cmake --build --preset=dev-cobc --target Sts1CobcSwTests_Fram

Project layout

The following ideas are mainly stolen from P1204R0 – Canonical Project Structure.

The following shows what the directory structure could actually look like.

Directory structure ~~~ Sts1CobcSw/ ├── .github/ ├── CMake/ ├── Docs/ ├── Sts1CobcSw/ │ ├── Hal/ │ │ ├── PinNames.hpp │ │ ├── IoNames.hpp │ │ ├── Usart.cpp │ │ ├── Usart.hpp │ │ ├── Spi.cpp │ │ ├── Spi.hpp │ │ ├── Communication.hpp (maybe just this instead?) │ │ └── ... │ │ │ ├── Periphery/ │ │ ├── Edu.cpp │ │ ├── Edu.hpp │ │ ├── W25q01jvzeiq.cpp (Name of the flash chip) │ │ ├── W25q01jvzeiq.hpp │ │ ├── AnotherChipName.cpp │ │ ├── AnotherChipName.hpp │ │ └── ... │ │ │ ├── ShouldThisEvenBeInASubfolder/ │ │ ├── TelemetryMemory.cpp │ │ ├── TelemetryMemory.hpp │ │ ├── CobcFileSystem.cpp │ │ ├── CobcFileSystem.hpp │ │ ├── PersistantState.cpp │ │ ├── PersistantState.hpp │ │ └── ... │ │ │ ├── AntennaDeploymentThread.cpp │ ├── AntennaDeploymentThread.hpp │ ├── SensorThread.cpp │ ├── SensorThread.hpp │ ├── CommandParser.cpp │ ├── CommandParser.hpp | └── ... │ ├── Tests/ | ├── GoldenTests/ │ │ ├── ExpectedOutputs/ │ │ ├── Scripts/ │ │ ├── ICantThingOfAGoodName.test.cpp │ │ └── ... │ ├── HardwareTests/ │ │ ├── GpioPins.test.cpp │ │ ├── Usart.test.cpp │ │ ├── W25q01jvzeiq.test.cpp │ │ └── ... │ ├── UnitTests/ │ │ ├── CommandParser.test.cpp │ │ └── ... │ └── ... │ ├── .clang-format ├── .gitignore ├── CMakeLists.txt ├── CMakePresets.json ├── LICENSE ├── README.md └── ... ~~~

Contributing

Only contributions from members of the TU Wien Space Team are accepted.

Licensing

See the LICENSE document.