-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Rule Timothy (VM/EMT3) <Timothy.Rule@de.bosch.com>
- Loading branch information
1 parent
d98e0a9
commit ca15ec3
Showing
8 changed files
with
228 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
cmake_minimum_required(VERSION 3.21) | ||
|
||
project(Transform) | ||
set(MODEL_PATH "examples/transform") | ||
|
||
add_library(ponger SHARED | ||
ponger.c | ||
) | ||
target_include_directories(ponger | ||
PRIVATE | ||
../../../.. | ||
) | ||
target_link_libraries(ponger | ||
PRIVATE | ||
$<$<BOOL:${WIN32}>:${modelc_link_lib}> | ||
) | ||
install(TARGETS ponger | ||
LIBRARY DESTINATION | ||
${MODEL_PATH}/lib | ||
RUNTIME DESTINATION | ||
${MODEL_PATH}/lib | ||
COMPONENT | ||
transform | ||
) | ||
add_library(pingit SHARED | ||
pingit.c | ||
) | ||
target_include_directories(pingit | ||
PRIVATE | ||
../../../.. | ||
) | ||
target_link_libraries(pingit | ||
PRIVATE | ||
$<$<BOOL:${WIN32}>:${modelc_link_lib}> | ||
) | ||
install(TARGETS pingit | ||
LIBRARY DESTINATION | ||
${MODEL_PATH}/lib | ||
RUNTIME DESTINATION | ||
${MODEL_PATH}/lib | ||
COMPONENT | ||
transform | ||
) | ||
install( | ||
FILES | ||
model.yaml | ||
simulation.yaml | ||
DESTINATION | ||
${MODEL_PATH}/data | ||
COMPONENT | ||
transform | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Copyright 2024 Robert Bosch GmbH | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
--- | ||
kind: Model | ||
metadata: | ||
name: Ponger | ||
spec: | ||
runtime: | ||
dynlib: | ||
- os: linux | ||
arch: amd64 | ||
path: lib/libponger.so | ||
- os: linux | ||
arch: x86 | ||
path: lib/libponger.so | ||
- os: windows | ||
arch: x64 | ||
path: lib/libponger.dll | ||
- os: windows | ||
arch: x86 | ||
path: lib/libponger.dll | ||
channels: | ||
- alias: data | ||
selectors: | ||
side: data | ||
--- | ||
kind: Model | ||
metadata: | ||
name: Pingit | ||
spec: | ||
runtime: | ||
dynlib: | ||
- os: linux | ||
arch: amd64 | ||
path: lib/libpingit.so | ||
- os: linux | ||
arch: x86 | ||
path: lib/libpingit.so | ||
- os: windows | ||
arch: x64 | ||
path: lib/libpingit.dll | ||
- os: windows | ||
arch: x86 | ||
path: lib/libpingit.dll | ||
channels: | ||
- alias: data | ||
selectors: | ||
side: data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2024 Robert Bosch GmbH | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include <errno.h> | ||
#include <stddef.h> | ||
#include <dse/modelc/model.h> | ||
|
||
int model_step(ModelDesc* m, double* model_time, double stop_time) | ||
{ | ||
ModelSignalIndex ping = m->index(m, "data", "ping"); | ||
if (ping.scalar == NULL) return -EINVAL; | ||
|
||
double val = *(ping.scalar); | ||
val = (val == 100) ? -100 : 100; | ||
|
||
*(ping.scalar) = val; | ||
*model_time = stop_time; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2024 Robert Bosch GmbH | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include <errno.h> | ||
#include <stddef.h> | ||
#include <dse/modelc/model.h> | ||
|
||
int model_step(ModelDesc* m, double* model_time, double stop_time) | ||
{ | ||
ModelSignalIndex ping = m->index(m, "data", "ping"); | ||
ModelSignalIndex pong = m->index(m, "data", "pong"); | ||
if (ping.scalar == NULL) return -EINVAL; | ||
if (pong.scalar == NULL) return -EINVAL; | ||
|
||
*(pong.scalar) = *(ping.scalar); | ||
|
||
*model_time = stop_time; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Copyright 2024 Robert Bosch GmbH | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
--- | ||
kind: Stack | ||
metadata: | ||
name: transform_stack | ||
spec: | ||
connection: | ||
transport: | ||
redispubsub: | ||
uri: redis://localhost:6379 | ||
timeout: 60 | ||
models: | ||
- name: simbus | ||
model: | ||
name: simbus | ||
channels: | ||
- name: data_channel | ||
expectedModelCount: 2 | ||
- name: ponger_inst | ||
uid: 42 | ||
model: | ||
name: Ponger | ||
channels: | ||
- name: data_channel | ||
alias: data | ||
- name: pingit_inst | ||
uid: 24 | ||
model: | ||
name: Pingit | ||
channels: | ||
- name: data_channel | ||
alias: data | ||
--- | ||
kind: Model | ||
metadata: | ||
name: simbus | ||
--- | ||
kind: SignalGroup | ||
metadata: | ||
name: data | ||
labels: | ||
side: data | ||
spec: | ||
signals: | ||
- signal: ping | ||
- signal: pong | ||
transform: | ||
linear: | ||
factor: 20 | ||
offset: -100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
env NAME=transform_inst | ||
env SIM=dse/modelc/build/_out/examples/transform | ||
|
||
|
||
# TEST: transform example model | ||
exec sh -e $WORK/test.sh | ||
|
||
stdout 'Load YAML File: data/simulation.yaml' | ||
stdout 'Loading symbol: model_create ... not found' | ||
stdout 'Loading symbol: model_step ... ok' | ||
stdout 'Loading symbol: model_destroy ... not found' | ||
stdout 'Run the Simulation ...' | ||
stdout 'Controller exit ...' | ||
stdout 'SignalValue: 2061178551 = 0.000000 \[name=pong\]' | ||
stdout 'SignalValue: 2061178551 = 10.000000 \[name=pong\]' | ||
stdout 'uid=2061178551, val=10.000000, final_val=10.000000, name=pong' | ||
stdout 'uid=375255177, val=-100.000000, final_val=-100.000000, name=ping' | ||
stdout 'model_time=0.002000' | ||
|
||
-- test.sh -- | ||
SIMER="${SIMER:-ghcr.io/boschglobal/dse-simer:latest}" | ||
docker run --name simer -i --rm -v $ENTRYDIR/$SIM:/sim \ | ||
$SIMER -valgrind $NAME -env simbus:SIMBUS_LOGLEVEL=2 |