Skip to content

Commit

Permalink
New module FMI ModelC FMU
Browse files Browse the repository at this point in the history
With support for CAN Networks in FMI2 using FMI Strings.

Co-authored-by: Jannik Smidt (CC/EMT3) <[email protected]>
  • Loading branch information
2 people authored and GitHub Enterprise committed Jul 23, 2024
1 parent 48e4ade commit 86c63a2
Show file tree
Hide file tree
Showing 43 changed files with 3,599 additions and 305 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ jobs:
tools:
if: false
#if: startsWith(github.ref, 'refs/tags/')
# if: startsWith(github.ref, 'refs/tags/')
runs-on: [ubuntu-latest]
needs: [build]
steps:
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export DSE_CLIB_VERSION ?= 1.0.17

###############
## DSE Model C Library
export DSE_MODELC_VERSION ?= 2.0.22
export DSE_MODELC_VERSION ?= 2.0.24


###############
Expand All @@ -23,12 +23,12 @@ SIMER_IMAGE ?= ghcr.io/boschglobal/dse-simer:$(DSE_MODELC_VERSION)
###############
## Build parameters.
export NAMESPACE = dse
export MODULE = fmimcl
export MODULE = fmi
export EXTERNAL_BUILD_DIR ?= /tmp/$(NAMESPACE).$(MODULE)
export PACKAGE_ARCH ?= linux-amd64
export PACKAGE_ARCH_LIST ?= $(PACKAGE_ARCH)
export CMAKE_TOOLCHAIN_FILE ?= $(shell pwd -P)/extra/cmake/$(PACKAGE_ARCH).cmake
SUBDIRS = $(NAMESPACE)/$(MODULE)
SUBDIRS = $(NAMESPACE)
export MODELC_SANDBOX_DIR ?= $(shell pwd -P)/dse/modelc/build/_out


Expand All @@ -43,8 +43,8 @@ export PACKAGE_VERSION ?= 0.0.1
DIST_DIR := $(shell pwd -P)/$(NAMESPACE)/$(MODULE)/build/_dist
OSS_DIR = $(NAMESPACE)/__oss__
PACKAGE_DOC_NAME = DSE FMI Library
PACKAGE_NAME = FmiMcl
PACKAGE_NAME_LC = fmimcl
PACKAGE_NAME = Fmi
PACKAGE_NAME_LC = fmi
PACKAGE_PATH = $(NAMESPACE)/dist

###############
Expand Down
83 changes: 74 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,30 @@ FMI Libraries of the Dynamic Simulation Environment (DSE) Core Platform.

<!-- Overview diagram, PlantUML generated, see Network for example. -->

FMI Model Compatibility Layer
: Load FMUs into a Dynamic Simulation Environment (i.e. using ModelC/SimBus).
<dl>
<dt><b>FMI Model Compatibility Layer</b></dt>
<dd>Load FMUs into a Dynamic Simulation Environment (i.e. using ModelC/SimBus).</dd>

<dt><b>FMI ModelC FMU</b></dt>
<dd>FMU capable of running a DSE Simulation (i.e. ModelC based Simulation Stack).</dd>
</dl>

The FMI Library is implemented with support of the [DSE Model C Library](https://github.com/boschglobal/dse.modelc)
and [DSE C Library](https://github.com/boschglobal/dse.clib).
The FMI Library is implemented with support of:
* [DSE Model C Library](https://github.com/boschglobal/dse.modelc)
* [DSE C Library](https://github.com/boschglobal/dse.clib)
* [DSE Network Codec](https://github.com/boschglobal/dse.standards/tree/main/dse/ncodec)


### Project Structure

```text
L- dse
L- dse/fmimcl FMI related Library source code.
L- extra Build infrastructure.
L- tools Containerised tools.
L- licenses Third Party Licenses.
L- tests Unit and E2E tests.
L- dse/fmimcl FMI MCL source code.
L- dse/fmimodelc FMI ModelC FMU source code.
L- extra Build infrastructure.
L- tools Containerised tools.
L- licenses Third Party Licenses.
L- tests Unit and E2E tests.
```


Expand All @@ -44,6 +51,64 @@ L- tests Unit and E2E tests.
<!-- Usage example showing all steps, see Network for example. -->


### FMI ModelC FMU

<!-- Usage example showing all steps, see Network for example. -->


#### Example: Network FMU with CAN Network Topology

The FMI ModelC FMU includes an example Network FMU which demonstrates how a
CAN Network Topology can be realised using FMI2 String variables and a wrapped
ModelC Simulation Stack with models which implement a [Network Codec](https://github.com/boschglobal/dse.standards/tree/main/dse/ncodec).


__Network FMU Layout:__

```text
L- network_fmu The example Network FMU.
L- bin/fmi2importer Importer (simple) which can run the Network FMU.
L- fmu FMU Package.
L- modelDescription.xml Model description for the FMU.
L- lib/linux-amd64
L- fmi2modelcfmu.so FMU shared library.
L- resources/sim ModelC Simulation Stack.
L- data
L- simulation.yaml Simulation Stack specification.
L- model.yaml Model specification.
L- lib
L- target.so The ModelC model shared library.
```


__Network FMU Operation:__

```bash
# Build the DSE FMI and examples.
$ git clone https://github.com/boschglobal/dse.fmi.git
$ cd dse.fmi
$ make

# Change to the FMU directory and run the Importer/FMU.
$ cd dse/build/_out/fmimodelc/examples/network_fmu/fmu
$ ../bin/fmi2importer lib/linux-amd64/fmi2modelcfmu.so
Importer: Loading FMU: lib/linux-amd64/fmi2modelcfmu.so ...
ModelCFmu: Create the FMU Model Instance Data
ModelCFmu: Resource location: resource
ModelCFmu: Allocate the RuntimeModelDesc object
ModelCFmu: Create the Model Runtime object
ModelCFmu: Call model_runtime_create() ...
Runtime: Version: 2.0.24
Runtime: Platform: linux-amd64
Runtime: Simulation Path: resources/sim
Runtime: Simulation YAML: resources/sim/data/simulation.yaml
Runtime: Model: network_fmu
Load YAML File: resources/sim/data/simulation.yaml
Load YAML File: resources/sim/data/model.yaml
...
```


## Build

> Note : see the following section on configuring toolchains.
Expand Down
139 changes: 139 additions & 0 deletions dse/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# Copyright 2024 Robert Bosch GmbH
#
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.21)

# set(CMAKE_VERBOSE_MAKEFILE ON)
set(VERSION "$ENV{PACKAGE_VERSION}")

project(Fmi
VERSION ${VERSION}
DESCRIPTION "Dynamic Simulation Environment - FMI Library"
HOMEPAGE_URL "$ENV{PROJECT_URL}"
)

include(GNUInstallDirs)
include(FetchContent)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/_out)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED TRUE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_C_FLAGS_DEBUG "-g -ggdb")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O3")
list(APPEND C_CXX_WARNING_FLAGS
-Wall
-W
-Wwrite-strings
-Wno-missing-field-initializers
-Wno-misleading-indentation
)
add_compile_options(${C_CXX_WARNING_FLAGS})
add_compile_definitions(DLL_BUILD)
set(CMAKE_SHARED_LIBRARY_PREFIX "")


# External Project - DSE C Lib
# ----------------------------
FetchContent_Declare(dse_clib
URL ${ExternalProject__CLIB__URL}
HTTP_USERNAME ${ExternalProject__CLIB__USERNAME}
HTTP_PASSWORD ${ExternalProject__CLIB__PASSWORD}
SOURCE_DIR "$ENV{EXTERNAL_BUILD_DIR}/dse.clib"
)
FetchContent_MakeAvailable(dse_clib)
set(DSE_CLIB_SOURCE_DIR ${dse_clib_SOURCE_DIR}/dse)
set(DSE_CLIB_INCLUDE_DIR "${DSE_CLIB_SOURCE_DIR}/..")


# External Project - DSE ModelC
# -----------------------------
FetchContent_Declare(dse_modelc
URL ${ExternalProject__MODELC__URL}
HTTP_USERNAME ${ExternalProject__MODELC__USERNAME}
HTTP_PASSWORD ${ExternalProject__MODELC__PASSWORD}
SOURCE_DIR "$ENV{EXTERNAL_BUILD_DIR}/dse.modelc"
)
FetchContent_MakeAvailable(dse_modelc)
set(DSE_MODELC_SOURCE_DIR ${dse_modelc_SOURCE_DIR}/dse/modelc)


# External Project - DSE ModelC LIB
# ---------------------------------
FetchContent_Declare(dse_modelc_lib
URL ${ExternalProject__MODELC_LIB__URL}
HTTP_USERNAME ${ExternalProject__MODELC_LIB__USERNAME}
HTTP_PASSWORD ${ExternalProject__MODELC_LIB__PASSWORD}
SOURCE_DIR "$ENV{EXTERNAL_BUILD_DIR}/dse.modelc.lib"
)
FetchContent_MakeAvailable(dse_modelc_lib)
set(DSE_MODELC_INCLUDE_DIR "${dse_modelc_lib_SOURCE_DIR}/include")


# External Project - yaml
# -----------------------
set(YAML_SOURCE_DIR "$ENV{EXTERNAL_BUILD_DIR}/yaml")
set(YAML_BINARY_DIR "$ENV{EXTERNAL_BUILD_DIR}/yaml")
find_library(YAML_LIB
NAMES
libyaml.a
PATHS
${YAML_BINARY_DIR}
REQUIRED
NO_DEFAULT_PATH
)
add_library(yaml STATIC IMPORTED GLOBAL)
set_target_properties(yaml
PROPERTIES
IMPORTED_LOCATION "${YAML_LIB}"
INTERFACE_INCLUDE_DIRECTORIES "${YAML_BINARY_DIR}"
)


# External Project - dlfcn-win32
# ------------------------------
if(WIN32)
set(DLFCNWIN32_SOURCE_DIR "$ENV{EXTERNAL_BUILD_DIR}/dlfcnwin32/src")
set(DLFCNWIN32_BINARY_DIR "$ENV{EXTERNAL_BUILD_DIR}/dlfcnwin32-build/lib")
find_library(DLFCNWIN32_LIB
NAMES
libdl.a
PATHS
${DLFCNWIN32_BINARY_DIR}
REQUIRED
NO_DEFAULT_PATH
)
add_library(dl STATIC IMPORTED GLOBAL)
set_target_properties(dl
PROPERTIES
IMPORTED_LOCATION "${DLFCNWIN32_LIB}"
INTERFACE_INCLUDE_DIRECTORIES "${DLFCNWIN32_SOURCE_DIR}"
)
endif()



# Sub Modules
# ===========
add_subdirectory(fmimcl)
add_subdirectory(fmimodelc)



# Common Targets
# ==============
install(
DIRECTORY
../licenses
DESTINATION
licenses
)
install(
FILES
${CMAKE_BINARY_DIR}/compile_commands.json
DESTINATION
doc
)
56 changes: 56 additions & 0 deletions dse/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright 2024 Robert Bosch GmbH
#
# SPDX-License-Identifier: Apache-2.0

export NAMESPACE = dse
export MODULE = fmi
export SUBMODULES = fmimcl
export EXTERNAL_BUILD_DIR ?= /tmp/$(NAMESPACE).$(MODULE)
export REPO_MIRRORS ?= $(shell pwd -P)/../repo_mirrors.cmake
export PACKAGE_ARCH ?= linux-amd64
export CMAKE_TOOLCHAIN_FILE ?= $(shell pwd -P)/../extra/cmake/$(PACKAGE_ARCH).cmake
export PROJECT_URL ?= https://github.com/boschglobal/$(NAMESPACE).fmi.git
export PACKAGE_VERSION ?= 0.0.2


default: build

external:
$(MAKE) -C ../extra/external

build: external
# Build from scratch if no build dir.
if [ ! -d "build" ]; then \
mkdir -p build; \
cd build; \
cmake -DCMAKE_TOOLCHAIN_FILE=$(CMAKE_TOOLCHAIN_FILE) .. ; \
fi
# Build incremental.
cd build; make
cd build; make install
@echo ""
@echo "Sandbox files: - $$(pwd)/build/_out"
@echo "--------------"
@find build/_out/ -type f -name '*' -exec ls -sh --color=auto {} \;

package:
@echo "Package parameters:"
@echo "-------------------"
@echo "NAMESPACE : $(NAMESPACE)"
@echo "MODULE : $(MODULE)"
@echo "VERSION : $(PACKAGE_VERSION)"
@echo "ARCH : $(PACKAGE_ARCH)"
cd build; make package
@echo ""
@echo "Package files: - $$(pwd)/build/_dist"
@echo "--------------"
@find build/_dist/ -type f -name '*' -exec ls -sh --color=auto {} \;

clean:
$(MAKE) -C ../extra/external clean
rm -rf build

cleanall: clean
$(MAKE) -C ../extra/external cleanall

.PHONY: default build external package clean cleanall
Loading

0 comments on commit 86c63a2

Please sign in to comment.