diff --git a/.clang-format b/.clang-format index 987bf4d..2929558 100644 --- a/.clang-format +++ b/.clang-format @@ -1,13 +1,13 @@ +BasedOnStyle: Google AccessModifierOffset: -4 AllowAllArgumentsOnNextLine: false AllowAllParametersOfDeclarationOnNextLine: false -AllowShortBlocksOnASingleLine: Never AllowShortEnumsOnASingleLine: false AllowShortFunctionsOnASingleLine: None -AllowShortLambdasOnASingleLine: None -BasedOnStyle: Chromium BinPackArguments: false BinPackParameters: false ColumnLimit: 120 +DerivePointerAlignment: false IndentWidth: 4 InsertBraces: true +InsertNewlineAtEOF: true diff --git a/.clang-tidy b/.clang-tidy index 16270e3..240576b 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,53 +1,54 @@ --- -Checks: '*, - -altera-struct-pack-align, - -altera-unroll-loops, - -android-cloexec-accept, - -android-cloexec-socket, - -bugprone-easily-swappable-parameters, - -cert-err34-c, - -cert-err58-cpp, - -cert-msc30-c, - -cert-msc32-c, - -cert-msc50-cpp, - -cert-msc51-cpp, - -concurrency-mt-unsafe, - -cppcoreguidelines-avoid-c-arrays, - -cppcoreguidelines-avoid-do-while, - -cppcoreguidelines-avoid-magic-numbers, - -cppcoreguidelines-avoid-non-const-global-variables, - -cppcoreguidelines-macro-usage, - -cppcoreguidelines-non-private-member-variables-in-classes, - -cppcoreguidelines-owning-memory, - -cppcoreguidelines-pro-bounds-array-to-pointer-decay, - -cppcoreguidelines-pro-bounds-constant-array-index, - -cppcoreguidelines-pro-bounds-pointer-arithmetic, - -cppcoreguidelines-pro-type-vararg, - -cppcoreguidelines-pro-type-reinterpret-cast, - -fuchsia-default-arguments-calls, - -fuchsia-default-arguments-declarations, - -fuchsia-statically-constructed-objects, - -google-build-using-namespace, - -google-runtime-int, - -hicpp-avoid-c-arrays, - -hicpp-no-array-decay, - -hicpp-vararg, - -hicpp-signed-bitwise, - -llvmlibc-callee-namespace, - -llvmlibc-implementation-in-namespace, - -llvmlibc-restrict-system-libc-headers, - -misc-non-private-member-variables-in-classes, - -modernize-use-trailing-return-type, - -readability-function-cognitive-complexity, - -readability-identifier-length, - -readability-magic-numbers' +Checks: '*, + -altera-struct-pack-align, + -altera-unroll-loops, + -android-cloexec-accept, + -android-cloexec-socket, + -bugprone-easily-swappable-parameters, + -cert-err34-c, + -cert-err58-cpp, + -cert-msc30-c, + -cert-msc32-c, + -cert-msc50-cpp, + -cert-msc51-cpp, + -concurrency-mt-unsafe, + -cppcoreguidelines-avoid-c-arrays, + -cppcoreguidelines-avoid-do-while, + -cppcoreguidelines-avoid-magic-numbers, + -cppcoreguidelines-avoid-non-const-global-variables, + -cppcoreguidelines-macro-usage, + -cppcoreguidelines-non-private-member-variables-in-classes, + -cppcoreguidelines-owning-memory, + -cppcoreguidelines-pro-bounds-array-to-pointer-decay, + -cppcoreguidelines-pro-bounds-constant-array-index, + -cppcoreguidelines-pro-bounds-pointer-arithmetic, + -cppcoreguidelines-pro-type-vararg, + -cppcoreguidelines-pro-type-reinterpret-cast, + -fuchsia-default-arguments-calls, + -fuchsia-default-arguments-declarations, + -fuchsia-statically-constructed-objects, + -google-build-using-namespace, + -google-runtime-int, + -hicpp-avoid-c-arrays, + -hicpp-no-array-decay, + -hicpp-vararg, + -hicpp-signed-bitwise, + -llvm-include-order, + -llvmlibc-callee-namespace, + -llvmlibc-implementation-in-namespace, + -llvmlibc-restrict-system-libc-headers, + -misc-non-private-member-variables-in-classes, + -modernize-use-trailing-return-type, + -readability-function-cognitive-complexity, + -readability-identifier-length, + -readability-magic-numbers' CheckOptions: - - { key: readability-identifier-naming.ClassCase, value: CamelCase } - - { key: readability-identifier-naming.PublicMethodCase, value: CamelCase } - - { key: readability-identifier-naming.ProtectedMethodCase, value: CamelCase } - - { key: readability-identifier-naming.PrivateMethodCase, value: CamelCase } - - { key: readability-identifier-naming.PrivateMemberCase, value: camelBack } - - { key: readability-identifier-naming.PrivateMemberPrefix, value: '_' } - - { key: readability-implicit-bool-conversion.AllowPointerConditions, value: 1} +- { key: readability-identifier-naming.ClassCase, value: CamelCase } +- { key: readability-identifier-naming.PublicMethodCase, value: CamelCase } +- { key: readability-identifier-naming.ProtectedMethodCase, value: CamelCase } +- { key: readability-identifier-naming.PrivateMethodCase, value: CamelCase } +- { key: readability-identifier-naming.PrivateMemberCase, value: camelBack } +- { key: readability-identifier-naming.PrivateMemberPrefix, value: '_' } +- { key: readability-implicit-bool-conversion.AllowPointerConditions, value: 1} ... diff --git a/benchmark/BenchmarkBusBuffer.cpp b/benchmark/BenchmarkBusBuffer.cpp index 3a308b1..7bf5167 100644 --- a/benchmark/BenchmarkBusBuffer.cpp +++ b/benchmark/BenchmarkBusBuffer.cpp @@ -1,6 +1,7 @@ // Copyright dSPACE GmbH. All rights reserved. #include + #include #include diff --git a/benchmark/BenchmarkIoBuffer.cpp b/benchmark/BenchmarkIoBuffer.cpp index 71e2aca..6460324 100644 --- a/benchmark/BenchmarkIoBuffer.cpp +++ b/benchmark/BenchmarkIoBuffer.cpp @@ -1,6 +1,7 @@ // Copyright dSPACE GmbH. All rights reserved. #include + #include #include diff --git a/benchmark/Communication/BenchmarkChannel.cpp b/benchmark/Communication/BenchmarkChannel.cpp index 16c8ae6..5258db1 100644 --- a/benchmark/Communication/BenchmarkChannel.cpp +++ b/benchmark/Communication/BenchmarkChannel.cpp @@ -1,6 +1,7 @@ // Copyright dSPACE GmbH. All rights reserved. #include + #include #include #include diff --git a/benchmark/OsAbstraction/BenchmarkNamedEvent.cpp b/benchmark/OsAbstraction/BenchmarkNamedEvent.cpp index d57e044..c99d9b8 100644 --- a/benchmark/OsAbstraction/BenchmarkNamedEvent.cpp +++ b/benchmark/OsAbstraction/BenchmarkNamedEvent.cpp @@ -3,6 +3,7 @@ #ifdef _WIN32 #include + #include #include diff --git a/benchmark/OsAbstraction/BenchmarkSocket.cpp b/benchmark/OsAbstraction/BenchmarkSocket.cpp index 14f2423..92dfce6 100644 --- a/benchmark/OsAbstraction/BenchmarkSocket.cpp +++ b/benchmark/OsAbstraction/BenchmarkSocket.cpp @@ -1,6 +1,7 @@ // Copyright dSPACE GmbH. All rights reserved. #include + #include #include #include diff --git a/compile_flags.txt b/compile_flags.txt index 787f8cd..b962db2 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -1,5 +1,5 @@ -xc++ --std=c++20 +-std=c++17 -DDSVEOSCOSIM_EXPORT -DWIN32_LEAN_AND_MEAN -D_CRT_SECURE_NO_WARNINGS diff --git a/doc/documentation.html b/doc/documentation.html deleted file mode 100644 index d5267e8..0000000 --- a/doc/documentation.html +++ /dev/null @@ -1,4219 +0,0 @@ - - - -documentation.md - - - - - - - - - - - - -

Table of Contents

- -

Basics on Co-Simulation

-

Basics on Co-Simulation with VEOS

-

Introduction

-

dSPACE provides the VEOS co-simulation interface for implementing co-simulations with VEOS. This lets you couple VEOS with domain-specific simulators, -such as data replay tools and sensor signal simulators.

-

The co-simulation interface enables the exchange of simulated CAN, LIN, and Ethernet bus messages as well as I/O signals.

-

Co-simulation architecture

-

Co-simulation with VEOS is implemented in a client-server architecture, where the VEOS Simulator provides the overall simulation time for all co-simulation participants.

-

Each participant uses a co-simulation (CoSim) client to connect via TCP to a CoSim server that runs in the VEOS Simulator. Refer to the following illustration.

-
flowchart TB - subgraph VeosSimulator[VEOS Simulator] - subgraph OSA - CoSimServer1[CoSim Server]:::blue - CoSimServer2[CoSim Server]:::blue - CoSimServer3[CoSim Server]:::blue - end - end - subgraph Participant1[Participant] - CoSimClient1[CoSim Client]:::blue - end - subgraph Participant2[Participant] - CoSimClient2[CoSim Client]:::blue - end - subgraph Participant3[Participant] - CoSimClient3[CoSim Client]:::blue - end - CoSimServer1 <--TCP--> Participant1 - CoSimServer2 <--TCP--> Participant2 - CoSimServer3 <--TCP--> Participant3 - classDef blue fill:#CCECFC,stroke:#88D9F8; - classDef white fill:#ffffff,stroke:#000000; - class VeosSimulator white - class OSA white - class Participant1 white - class Participant2 white - class Participant3 white -
-

CoSim server -A CoSim server provides the co-simulation interface for the VEOS Simulator.

-

Each CoSim server is generated from a JSON interface description file.

-

For more information, refer to Basics on CoSim Servers.

-

CoSim client -Each co-simulation participant uses a CoSim client to connect to one or more CoSim servers. The CoSim client is set up via C++ source code and CMake. -Alternatively, it can be set up as a dynamic library if you want to work with the co-simulation interface via Python, for example.

-

For more information, refer to Basics on CoSim Clients.

-

Compatibility and licensing

-

The VEOS co-simulation interface is compatible with VEOS 2023-B and later.

-

It requires the license for the VEOS - AAP (AUTOSAR Adaptive Platform) module.

-

The VEOS co-simulation client interface is licensed as Open Source under the permissive Apache 2.0 license.

-

Limitation

-

You cannot access variables of a co-simulation with experiment software such as ControlDesk.

-

Basics on CoSim Servers

-

Introduction

-

A CoSim server provides the co-simulation interface of the VEOS Simulator that controls the simulation.

-

It is imported as a JSON interface description file into an offline simulation application in VEOS.

-

Refer to the following illustration.

-
flowchart LR - CoSimJson[CoSim JSON]:::blue - VeosImport[VEOS import]:::white - subgraph OSA - CoSimServer[CoSim Server]:::blue - end - CoSimJson --> VeosImport - VeosImport --> CoSimServer - classDef blue fill:#CCECFC,stroke:#88D9F8; - classDef white fill:#ffffff,stroke:#000000; - class OSA white -
-

Configuring a CoSim server

-

To configure a CoSim server for a specific co-simulation client, you have to describe the co-simulation interface in a client-specific JSON description file.

-

The JSON file can provide the following information:

-
    -
  • -

    General information, such as the time step interval for the co-simulation

    -
  • -
  • -

    Bus controller information, such as the baud rate

    -
  • -
  • -

    I/O signal information, such as data types of signals

    -
  • -
-

The JSON schema for the CoSim interface is based on the simulator-extension.base.schema.json schema. You can find both schemas under tools/schemas in the installation directory of your VEOS installation.

-

Specifying the TCP port -By default, the CoSim server provides a dynamic TCP port and a port mapper. The port mapper is automatically started by the first CoSim server in an OSA. For this use case, you do not have to explicitly specify a TCP port in the JSON interface description file.

-

However, for some use cases, you might want to specify a static TCP port. To do this, use the TcpPort property, i.e.,:

-
"TcpPort": { - "type": "number", - "default": 12345, - "minimum": 0, - "maximum": 65535 -} -
-
-

Note

-

When you specify a static TCP port, you have to provide this to the related client. Refer to Connecting to a CoSim server.

-
-

Each VeosCoSim server starts its own TCP server at the TCP port specified in the JSON file and registers this port with the port mapper.

-

The default TCP port of the port mapper is 27027. You can reconfigure it using the VEOS_COSIM_PORTMAPPER_PORT environment variable. You have to do this for the CoSim servers and the CoSim clients.

-

For CoSim servers, you have to set the environment variable before starting the VEOS Kernel.

-

Importing a CoSim JSON file

-

You can import a CoSim JSON into any OSA using the VEOS Player (only on Windows) or the VEOS Model Console (on Windows and Linux).

-

The following listing shows an example of using the VEOS Model Console on Linux to import the CosimServer.json description file into the newly created CoSimOsa.osa in the current working directory.

-
/opt/dspace/veos2023b/bin/veos model import -n ./CoSimOsa.osa -p ./CoSimServer.json -
-

For a working example, refer to How to Prepare the CoSim Demo.

-

Connecting a CoSim server to other VPUs -To connect the I/O signals and controllers of the CoSim server to other VPUs in the same OSA, you can use drag & drop in the VEOS Player (only on Windows) or the VEOS Model Console (on Windows and Linux).

-

In many cases, you can also use the auto-connect functionality of VEOS. You can find an example of this in the CoSim demo. Refer to Example: Using Data Callback Functions to Get Information on CAN Bus Messages.

-

Basics on CoSim Clients

-

Introduction

-

You have to implement a CoSim client in C++ code that uses the CoSim API to interact with the CoSim server.

-

You can then integrate the client as a submodule in the project containing your binary (recommended) or precompile the CoSim sources as a static library to link it to your binary.

-

If you want to access the co-simulation interface via Python, you can also precompile the client sources as a dynamic library.

-

Workflow

-

The following steps outline the workflow for creating a CoSim client:

-
    -
  1. -

    Download the latest veos-cosim-client-<version>.zip archive from veos-cosim-client and extract it to a dedicated folder, e.g., DsVeosCoSim/ThirdParty/veos-cosim-client in your home directory.

    -
  2. -
  3. -

    Depending on your use case, take the following steps:

    -
      -
    • -

      For including the client as a submodule in your project, refer to Example: Setting Up a Basic Co-Simulation.

      -
    • -
    • -

      For precompiling as a dynamic library, execute the following commands in the folder to which you extracted the DsVeosCoSim.zip archive:

      -
      mkdir Debug -cd Debug -cmake .. -DBUILD_SHARED_LIBS=ON -cmake --build . --config=Debug -
      -

      This produces a dynamic library file in the Src/Debug subdirectory.

      -

      Replace Debug with Release in the listing above to create a release version.

      -
    • -
    • -

      For precompiling as a static library, execute the following commands in the folder to which you extracted the DsVeosCoSim.zip archive:

      -
      mkdir Debug -cd Debug -cmake .. -cmake --build . --config Debug -cmake --install . --config Debug --prefix ../install -
      -

      This produces a static library file in the install subdirectory.

      -

      Replace Debug with Release in the listing above to create a release version.

      -
    • -
    -
  4. -
-

Connecting to a CoSim server

-

By default, a CoSim client asks the CoSim port mapper for the actual TCP port of the related CoSim server and then connects to this port. For this to work, you have to specify the server name via DsVeosCoSim_ConnectConfig.serverName.

-

However, if you specified a static TCP port for the CoSim server, you have to explicitly connect to this port by providing it via DsVeosCoSim_ConnectConfig.remotePort in the implementation of your client.

-

If you specify both serverName and remotePort, remotePort is used to establish the connection.

-

If the server is running on a different host, you must specify the IP address using DsVeosCoSim_ConnectConfig.remoteIpAddress.

-

The local port is also created dynamically by default. For special cases like creating a tunnel between client and server, you can overwrite this with a specific port using DsVeosCoSim_ConnectConfig.localPort.

-
-

Tip

-

You can use DsVeosCoSim_ConnectConfig.clientName to provide a name for the client that can be used in VEOS messages for better readability. For example, if you set DsVeosCoSim_ConnectConfig.clientName = "CustomClient", a message might look like this: dSPACE VEOS CoSim client 'CustomClient' at 127.0.0.1:56248 connected..

-
-

Callback-based vs. polling-based co-simulation

-

You can configure the CoSim client for two different co-simulation modes:

-
    -
  • -

    Callback-based: This is a blocking simulation which only stops when the client is disconnected from the server. While it is running, the registered callbacks are processed for each simulation step.

    -

    During each callback, VEOS does not advance the simulation until the callback is finished.

    -

    In the absence of errors, a callback-based co-simulation only returns when the client is disconnected from the server.

    -

    For a basic example, refer to Example: Setting Up a Basic Co-Simulation.

    -
  • -
  • -

    Polling-based: The simulation polls for commands and performs the actions that are specified in the implementation for each command. This can also include callbacks, which are received in the same order as for a callback-based co-simulation.

    -

    This mode can be useful in cases where the CoSim server has to communicate with another API that is callback-based so you do not have to take care of synchronizing the callbacks.

    -

    For an example of implementing a polling-based co-simulation, refer to Example: Running a Polling-Based Simulation.

    -
    -

    Note

    -

    Once one of these modi is selected, it cannot be changed until the client is disconnected from the server.

    -
    -
  • -
-

Basics on callbacks

-

You can use callback functions to get information on state changes of the simulation and on data exchange:

-
    -
  • -

    State changes: Started, stopped, paused, continued, terminated

    -
  • -
  • -

    Steps: begin and end step

    -
  • -
  • -

    Bus message received: CAN, Ethernet, LIN

    -
  • -
  • -

    I/O signal changed (for incoming signals)

    -
  • -
-

Callbacks are optional. However, not registering any callbacks makes sense only for polling-based simulations.

-

Each time the server notifies the client of a new step, the callbacks are received in the following order:

-
    -
  • -

    Begin step

    -
  • -
  • -

    Bus message and I/O signal callbacks in no specific order

    -
  • -
  • -

    End step

    -
  • -
-

Basics on timing

-

Each time VEOS receives the simulation start or continue command, the server begins to send steps to the client and stops when a simulation stop, pause, or terminate command is received.

-

The first step always takes place at simulation time 0. After that, the simulation is advanced by a step after each time interval specified in the StepSize property in the CoSim server JSON file.

-

The client can intervene via the DsVeosCoSim_SetNextSimulationTime Function, which specifies the condition for the server to send the next step. This can be done for each step or just from time to time. Once the server no longer receives this condition, it proceeds with the predefined step size. If the time specified via the DsVeosCoSim_SetNextSimulationTime Function is in the past or equal to the present time, it is ignored.

-

If no step size is specified in the JSON file, the server sends only one step at simulation time 0. The simulation is only advanced if the client executes the DsVeosCoSim_SetNextSimulationTime Function. Otherwise, the simulation in VEOS continues without the co-simulator.

-

Bus messages and I/O signals are always sent between server and client in the context of a step.

-

Working with the VEOS CoSim Demo

-

Overview of the VEOS CoSim Demo

-

Introduction

-

The VEOS CoSim demo provides instructions for setting up a simple example CoSim server and implementing several kinds of CoSim clients to illustrate the basic co-simulation functionalities.

-

Workflow

-

The VEOS CoSim demo leads you through the following steps:

-
    -
  • -

    Create a simple JSON interface description file for a CoSim server

    -
  • -
  • -

    Create an OSA in VEOS, import the JSON file, and load it to the simulator

    -
  • -
  • -

    Implement a basic CoSim client and start a co-simulation

    -
  • -
  • -

    Modify the basic CoSim client to familiarize yourself with the principal aspects of co-simulation

    -
  • -
-

Overview of the examples

-

Before starting with any of the examples listed below, you must make the preparations described in How to Prepare the CoSim Demo.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ExampleWhat It ShowsRefer to
Basic co-simulationEnable basic loggingExample: Setting Up a Basic Co-Simulation
Implementing simulation state change callbacksTracking simulation state changesExample: Implementing Simulation State Change Callbacks
Accessing the data interfaceGetting information on available bus controllers and I/O signalsExample: Accessing the Data Interface
Using data callbacksGetting information on newly received bus messagesExample: Using Data Callback Functions to Get Information on CAN Bus Messages
Sending dataSending data to VEOSExample: Sending Data
Receiving dataReceiving data from VEOSExample: Receiving Data
Running a polling-based co-simulationRunning a polling-based co-simulationExample: Running a Polling-Based Simulation
Handling I/O signalsHandling I/O signal communication for two client-server pairs.Example: Handling I/O Signals
Optional clientsSimulation behavior for a CoSim server for which a client is optional.Example: Optional Client
-

Requirements

-

You can work with the demo on Windows and Ubuntu 20.04 LTS.

-

Additionally, you must have the following:

-
    -
  • -

    CMake 3.13 or higher

    -
  • -
  • -

    Either of the following compilers:

    -
      -
    • -

      GCC 10 or higher

      -
    • -
    • -

      MSVC 2022 or higher

      -
    • -
    • -

      Clang 10 or higher

      -
    • -
    -
  • -
-

How to Prepare the CoSim Demo

-

Objective

-

To prepare the CoSim demo by performing the following tasks:

-
    -
  1. -

    Setting up the CoSim example server. Refer to Part 1.

    -
  2. -
  3. -

    Setting up a CoSim test client. Refer to Part 2.

    -
  4. -
-

Part 1: To set up the CoSim example server

-
    -
  1. -

    Create the DsVeosCoSimDemo directory in a directory of your choice.

    -
  2. -
  3. -

    In the DsVeosCoSimDemo directory, create a JSON file with the following content, where you have to replace "file:///DsVeosCoSim.schema.json" with the path where the VEOS CoSim JSON schema of your VEOS installation is saved. This defaults to "file:///C:/Program Files/dSPACE VEOS 2023‑B/tools/schemas/DsVeosCoSim.schema.json" on Windows and "file:///opt/dspace/veos2023b/tools/schemas/DsVeosCoSim.schema.json" on Linux.

    -
    { - "$schema": "file:///DsVeosCoSim.schema.json", - "Type": "DsVeosCoSim", - "Name": "CoSimExample", - "StepSize": 0.001, - "Network": { - "CAN": { - "CanController": { - "ClusterName": "HighSpeedCanCluster", - "BitsPerSecond": 500000, - "FlexibleDataRateBitsPerSecond": 2000000 - } - } - }, - "IOSignals": { - "Outgoing": [ - { - "Name": "Signal1", - "DataType": "float64", - "PortName": "Port1" - } - ] - } -} -
    -
  4. -
  5. -

    Save the JSON file under the file name Example.json.

    -
  6. -
  7. -

    In VEOS, create a new OSA and import the JSON file into it:

    -
      -
    • -

      On Windows, you can use VEOS Player:

      -

      Click Home - New to create a new OSA. Import the JSON file via drag & drop. When the import is finished, press F12 to save the OSA under a name of your choice.

      -

      Alternatively, you can use the VEOS Model Console like this:

      -
      <VEOS installation directory>/bin/veos.exe model import -n ./VeosCoSimOsa.osa -p ./Example.json -
      -
    • -
    • -

      On Linux:

      -
      /opt/dspace/veos2023b/bin/veos model import \-n ./VeosCoSimOsa.osa -p ./Example.json -
      -
    • -
    -
  8. -
  9. -

    Load the OSA to the simulator:

    -
      -
    • -

      On Windows, click Simulation - Load or use the VEOS Simulator Console in the command-line:

      -
      <VEOS installation directory>/bin/veos.exe sim load ./VeosCoSimOsa.osa -
      -
    • -
    • -

      On Linux:

      -
      /opt/dspace/veos2023b/bin/veos sim load ./VeosCoSimOsa.osa -
      -
    • -
    -
  10. -
-

Interim result

-

You created a JSON interface description file for a CoSim server, created an OSA in VEOS, imported the JSON file into the OSA, and loaded it to the simulator.

-

The CoSim server waits for a client to connect.

-

Part 2: To set up a CoSim test client

-
    -
  1. -

    Download the latest veos-cosim-client-<version>.zip archive from veos-cosim-client.

    -
  2. -
  3. -

    Create the ThirdParty/veos-cosim-client subdirectory in the DsVeosCoSimDemo directory and extract the ZIP archive to this subfolder.

    -
  4. -
  5. -

    In the DsVeosCoSimDemo directory, create the CMakeLists.txt file with the following content:

    -
    cmake_minimum_required(VERSION 3.13) - -project(DsVeosCoSimDemo VERSION 1.0) - -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_STANDARD_REQUIRED TRUE) - -add_subdirectory(ThirdParty/veos-cosim-client) - -add_executable(${PROJECT_NAME} main.cpp) -target_link_libraries(${PROJECT_NAME} PRIVATE DsVeosCoSim) -
    -
  6. -
  7. -

    Also in the DsVeosCoSimDemo directory, create the main.cpp file with the following content:

    -
    #include <iomanip> -#include <iostream> -#include <sstream> - -#include "DsVeosCoSim/DsVeosCoSim.h" - -int main() { - return 0; -} -
    -
  8. -
  9. -

    In the DsVeosCoSimDemo directory, run the following commands to create a build directory, configure the build project, and compile the test executable:

    -
    mkdir build -cd build -cmake .. -cmake --build . -
    -
    -

    Note

    -

    If you use Visual Studio on Windows, make sure to run these commands in the Visual Studio Developer Command Prompt.

    -
    -
  10. -
  11. -

    Test the executable by running the following command in the build subdirectory:

    -
      -
    • -

      On Windows:

      -
      .\Debug\DsVeosCoSimDemo.exe -
      -
    • -
    • -

      On Linux:

      -
      ./Debug/DsVeosCoSimDemo -
      -
    • -
    -

    The executable simply returns without any message.

    -
  12. -
-

Result

-

You set up a basic CoSim server in VEOS and set up a build project for CoSim clients. You also created a simple test executable to confirm the build project was configured correctly.

-

Next steps

-

You can now proceed to build a simple example CoSim client and use it in a co-simulation with the CoSim server you set up in Part 1.

-

Refer to Example: Setting Up a Basic Co-Simulation.

-

Example: Setting Up a Basic Co-Simulation

-

Introduction

-

This example shows how to create a basic CoSim client which connects to the CoSim server in VEOS and reports on its progress via log callbacks.

-

Precondition

-

You must have made the preparations described in How to Prepare the CoSim Demo.

-

How to set up the client

-
    -
  1. -

    Replace the content of main.cpp with the following code and save it:

    -
    #include <iomanip> -#include <iostream> -#include <sstream> - -#include "DsVeosCoSim/DsVeosCoSim.h" - -void OnLogCallback(DsVeosCoSim_Severity severity, const char* logMessage) { - switch (severity) { - case DsVeosCoSim_Severity_Error: - std::cout << "ERROR " << logMessage << "\n"; - break; - case DsVeosCoSim_Severity_Warning: - std::cout << "WARN " << logMessage << "\n"; - break; - case DsVeosCoSim_Severity_Info: - std::cout << "INFO " << logMessage << "\n"; - break; - case DsVeosCoSim_Severity_Trace: - std::cout << "TRACE " << logMessage << "\n"; - break; - } -} - -// Called after every interval specified in the StepSize parameter of the Example.json file -void OnEndStep(DsVeosCoSim_SimulationTime simulationTime, void* userData) { - std::cout << "Step callback received at " << DSVEOSCOSIM_SIMULATION_TIME_TO_SECONDS(simulationTime) << " s.\n"; -} - -int main() { - // Step 1: Enable logging - DsVeosCoSim_SetLogCallback(OnLogCallback); - - // Step 2: Create a handle for the client - DsVeosCoSim_Handle handle = DsVeosCoSim_Create(); - if (handle == nullptr) { - return 1; - } - - // Step 3: Connect to the Example server that is running in VEOS - DsVeosCoSim_ConnectConfig connectConfig{}; - connectConfig.serverName = "CoSimExample"; - if (DsVeosCoSim_Connect(handle, connectConfig) != DsVeosCoSim_Result_Ok) { - DsVeosCoSim_Destroy(handle); - return 1; - } - - // Step 4: Run a callback-based co-simulation - DsVeosCoSim_Callbacks callbacks{}; - callbacks.simulationEndStepCallback = OnEndStep; - callbacks.userData = handle; // Pass the handle to every callback - if (DsVeosCoSim_RunCallbackBasedCoSimulation(handle, callbacks) != DsVeosCoSim_Result_Disconnected) { - DsVeosCoSim_Disconnect(handle); - DsVeosCoSim_Destroy(handle); - } - - DsVeosCoSim_Destroy(handle); - return 0; -} -
    -
  2. -
  3. -

    In the build directory, call cmake --build . to build the executable.

    -
  4. -
-

What it does

-
    -
  • -

    The OnLogCallback function prints log messages corresponding to the severity level. It is registered by the -DsVeosCoSim_SetLogCallback Function in Step 1.

    -
  • -
  • -

    In Step 2, a handle for the client is created which is used by all the other functions.

    -

    Only one handle can be connected to one CoSim server in the VEOS simulator. However, a client can create multiple handles and connect them to other CoSim -servers on the same or other VEOS simulators.

    -
  • -
  • -

    In Step 3, a connection to the Example server running in VEOS is established via the DsVeosCoSim_Connect Function.

    -

    Tip:

    -
      -
    • -

      The client can also connect to a server that is running on a different computer. In this case, you have to add -connectConfig.remoteIpAddress = "<IP address>";.

      -
    • -
    • -

      The Example server uses a dynamic TCP port and a port mapper. However, if you specified a static TCP port, you have to provide this to the client via -DsVeosCoSim_ConnectConfig.remotePort. For more information, refer to Connecting to a CoSim server.

      -
    • -
    -
  • -
  • -

    In Step 4 a callback-based co-simulation is started. The DsVeosCoSim_RunCallbackBasedCoSimulation Function blocks -until either DsVeosCoSim_Disconnect Function is called by a callback function or the simulation is unloaded in VEOS. Therefore, the -expected return value is DsVeosCoSim_Result_Disconnected instead of DsVeosCoSim_Result_Ok.

    -

    In this example, the simulationEndStepCallback is called at the end of each simulation step and prints the corresponding simulation time in seconds as -specified in the OnEndStep function definition.

    -

    Tip: -You can also run polling-based co-simulations. Refer to Example: Running a Polling-Based Simulation for an example.

    -
  • -
-

Running the co-simulation

-
    -
  1. -

    Load the VeosCoSim.osa you created in How to Prepare the CoSim Demo to the VEOS simulator.

    -
  2. -
  3. -

    From the DsVeosCoSimDemo/build subdirectory, run the executable you built in How to set up the client via

    -
    .\Debug\DsVeosCoSimDemo.exe -
    -

    on Windows or

    -
    ./Debug/DsVeosCoSimDemo -
    -

    on Linux.

    -
  4. -
  5. -

    Start the simulation in VEOS:

    -
      -
    • -

      On Windows, click Simulation - Start in the VEOS Player or use the VEOS Simulator Console in the command-line:

      -
      <VEOS installation directory>/bin/veos.exe sim start -
      -
    • -
    • -

      On Linux:

      -
      /opt/dspace/veos2023b/bin/veos sim start -
      -
    • -
    -
  6. -
-

Client output

-

The following listing shows the output produced by the client:

-
INFO Obtaining TCP port of dSPACE VEOS CoSim server 'CoSimExample' at 127.0.0.1 ... -INFO Connecting to dSPACE VEOS CoSim server 'CoSimExample' at 127.0.0.1:50212 ... -INFO Connected to dSPACE VEOS CoSim server 'CoSimExample' at 127.0.0.1:50212. -Step callback received at 0 s. -Step callback received at 0.001 s. -Step callback received at 0.002 s. -Step callback received at 0.003 s. -... -
-

Example: Implementing Simulation State Change Callbacks

-

Introduction

-

This example shows how to implement simulation state change callbacks in a CoSim client.

-

Preconditions

- -

How to set up the client

-
    -
  1. -

    In the main.cpp code, replace the OnEndStep function definition starting in line 22 with the following code:

    -
    void OnEndStep(DsVeosCoSim_SimulationTime simulationTime, void* userData) { - // Disable output for each step to make the messages more readable - // std::cout << "Step callback received at " << DSVEOSCOSIM_SIMULATION_TIME_TO_SECONDS(simulationTime) << " s.\n"; -} - -// Called when the simulation starts -void OnStarted(DsVeosCoSim_SimulationTime simulationTime, void* userData) { - std::cout << "Simulation started at " << DSVEOSCOSIM_SIMULATION_TIME_TO_SECONDS(simulationTime) << " s.\n"; -} - -// Called when the simulation stops -void OnStopped(DsVeosCoSim_SimulationTime simulationTime, void* userData) { - std::cout << "Simulation stopped at " << DSVEOSCOSIM_SIMULATION_TIME_TO_SECONDS(simulationTime) << " s.\n"; -} - -// Called when the simulation pauses -void OnPaused(DsVeosCoSim_SimulationTime simulationTime, void* userData) { - std::cout << "Simulation paused at " << DSVEOSCOSIM_SIMULATION_TIME_TO_SECONDS(simulationTime) << " s.\n"; -} - -// Called when the simulation continues -void OnContinued(DsVeosCoSim_SimulationTime simulationTime, void* userData) { - std::cout << "Simulation continued at " << DSVEOSCOSIM_SIMULATION_TIME_TO_SECONDS(simulationTime) << " s.\n"; -} -
    -
  2. -
  3. -

    In the main function definition, add the following callbacks below line 46 of the original listing:

    -
    callbacks.simulationStartedCallback = OnStarted; -callbacks.simulationStoppedCallback = OnStopped; -callbacks.simulationPausedCallback = OnPaused; -callbacks.simulationContinuedCallback = OnContinued; -
    -
  4. -
  5. -

    Save the main.cpp file and call cmake --build . to build the executable.

    -
  6. -
-

What it does

-

The additional callback functions are called each time the simulation state changes and print corresponding messages.

-

Running the co-simulation

-
    -
  1. -

    Load the DsVeosCoSim.osa you created in How to Prepare the CoSim Demo to the VEOS simulator.

    -
  2. -
  3. -

    From the DsVeosCoSimDemo/build subdirectory, run the executable you built in -Example: Implementing Simulation State Change Callbacks via

    -
    .\Debug\DsVeosCoSimDemo.exe -
    -

    on Windows or

    -
    ./Debug/DsVeosCoSimDemo -
    -

    on Linux.

    -
  4. -
  5. -

    Start the simulation in VEOS:

    -
      -
    • -

      On Windows, click Simulation - Start in the VEOS Player or use the VEOS Simulator Console in the command-line:

      -
      <VEOS installation directory>\bin\veos.exe sim start -
      -
    • -
    • -

      On Linux:

      -
      /opt/dspace/veos2023b/bin/veos sim start -
      -
    • -
    -
  6. -
  7. -

    Change the simulation state, e.g., by pressing Pause, Step, and Stop in the VEOS Player or using the related commands of the VEOS Simulator -Console.

    -
  8. -
-

Client output

-

The following listing shows the client output for the simulation state changes:

-
INFO Obtaining TCP port of dSPACE VEOS CoSim server 'CoSimExample' at 127.0.0.1 ... -INFO Connecting to dSPACE VEOS CoSim server 'CoSimExample' at 127.0.0.1:61385 ... -INFO Connected to dSPACE VEOS CoSim server 'CoSimExample' at 127.0.0.1:61385. -Simulation started at 0 s. -Simulation paused at 3.51 s. -Simulation continued at 3.51 s. -Simulation paused at 3.511 s. -Simulation stopped at 3.511 s. -
-

Example: Accessing the Data Interface

-

Introduction

-

This example shows how to access the VEOS CoSim data interface to get information on available bus controllers and I/O signals.

-

Preconditions

- -

How to set up the client

-
    -
  1. -

    In the main.cpp code of the basic example, add the following declarations directly below the includes:

    -
    uint32_t canControllersCount{}; -const DsVeosCoSim_CanController* canControllers{}; -uint32_t outgoingSignalsCount{}; -const DsVeosCoSim_IoSignal* outgoingSignals{}; -
    -
  2. -
  3. -

    Add the following code to Step 3 of the main function:

    -
    if (DsVeosCoSim_GetCanControllers(handle, &canControllersCount, &canControllers) != DsVeosCoSim_Result_Ok) { - DsVeosCoSim_Disconnect(handle); - DsVeosCoSim_Destroy(handle); - return 1; -} - -for (uint32_t i = 0; i < canControllersCount; i++) { - std::cout << "Found CAN controller '" << canControllers[i].name << "'\n"; -} - -if (DsVeosCoSim_GetOutgoingSignals(handle, &outgoingSignalsCount, &outgoingSignals) != DsVeosCoSim_Result_Ok) { - DsVeosCoSim_Disconnect(handle); - DsVeosCoSim_Destroy(handle); - return 1; -} - -for (uint32_t i = 0; i < outgoingSignalsCount; i++) { - std::cout << "Found outgoing signal '" << outgoingSignals[i].name << "'\n"; -} -
    -
  4. -
  5. -

    Save the main.cpp file and call cmake --build . to build the executable.

    -
  6. -
-

What it does

-
    -
  • -

    First, the client collects information on the available CAN controllers via the DsVeosCoSim_GetCanControllers Function.

    -
  • -
  • -

    It then prints the name of each CAN controller.

    -
  • -
  • -

    Then it does the same for the outgoing I/O signals.

    -
  • -
-

Running the co-simulation

-
    -
  1. -

    Load the DsVeosCoSim.osa you created in How to Prepare the CoSim Demo to the VEOS simulator.

    -
  2. -
  3. -

    From the DsVeosCoSimDemo/build subdirectory, run the executable you built in -Example: Accessing The Data Interface via

    -
    .\Debug\DsVeosCoSimDemo.exe -
    -

    on Windows or

    -
    ./Debug/DsVeosCoSimDemo -
    -

    on Linux.

    -
  4. -
  5. -

    Start the simulation in VEOS:

    -
      -
    • -

      On Windows, click Simulation - Start in the VEOS Player or use the VEOS Simulator Console in the command-line:

      -
      <VEOS installation directory>\bin\veos.exe sim start -
      -
    • -
    • -

      On Linux:

      -
      /opt/dspace/veos2023b/bin/veos sim start -
      -
    • -
    -
  6. -
-

Client output

-

The following listing shows the output produced by the client:

-
Found CAN controller 'CanController' -Found outgoing signal 'Port1/Signal1' -
-

Example: Using Data Callback Functions to Get Information on CAN Bus Messages

-

Introduction

-

This example demonstrates how to use data callbacks to get information on received CAN bus messages.

-

In addition to modifying the basic example client, you have to modify the DsVeosCoSim.osa by adding a V-ECU with -a CAN controller so that there are CAN bus messages for the CoSim server to receive.

-

Preconditions

-
    -
  • -

    You must have made the preparations described in How to Prepare the CoSim Demo.

    -
  • -
  • -

    You must have created the basic CoSim client described in Example: Setting Up a Basic Co-Simulation.

    -
  • -
  • -

    You must have a VEOS installation on Windows and copied the VEOS demos to your Documents folder via File - Copy Demo Files in the VEOS Player.

    -
  • -
  • -

    To work through this example on Linux, you must additionally copy the Controller.vecu from the <Documents folder>\2Ecu_CanBusSimulation folder -of the Windows VEOS installation to the Linux system and build it like this (assuming you copied the Controller.vecu to your current working directory):

    -
    /opt/dspace/veos2023b/bin/veos build classic-vecu ./2Ecu_CanBusSimulationController.vecu -o ./Controller.osa -
    -
  • -
-

How to set up the client

-
    -
  1. -

    In the main.cpp code, comment out the output of the OnEndStep function definition to make the output more readable:

    -
    void OnEndStep(DsVeosCoSim_SimulationTime simulationTime, void* userData) { - // std::cout << "Step callback received at " << DSVEOSCOSIM_SIMULATION_TIME_TO_SECONDS(simulationTime) << " s.\n" -} -
    -
  2. -
  3. -

    Add the following code above the main function:

    -
    std::string DataToString(const uint8_t* data, uint32_t dataLength, char separator = 0) { - std::ostringstream oss; - oss << std::hex << std::setfill('0'); - for (uint32_t i = 0; i < dataLength; i++) { - oss << std::setw(2) << static_cast<int>(data[i]); - if ((i < dataLength - 1) && separator != 0) { - oss << separator; - } - } - - return oss.str(); -} - -// Will be called when a CAN message was received -void OnCanMessage(DsVeosCoSim_SimulationTime simulationTime, - const DsVeosCoSim_CanController* canController, - const DsVeosCoSim_CanMessage* message, - void* userData) { - std::cout << "Received CAN message with ID " << message->id << " with data " - << DataToString(message->data, message->length, '-') << " from CAN controller " - << canController->name << " at " - << DSVEOSCOSIM_SIMULATION_TIME_TO_SECONDS(simulationTime) << " s.\n"; -} -
    -
  4. -
  5. -

    In the main function, add the callback:

    -
    callbacks.canMessageReceivedCallback = OnCanMessage; -
    -
  6. -
  7. -

    Save the main.cpp file and call cmake --build . to build the executable.

    -
  8. -
-

What it does

-

Each time the CoSim server receives a CAN bus message, the OnCanMessage callback function prints the message ID, -the name of the CAN controller from which the message was received, and the corresponding simulation time.

-

How to modify the OSA

-
    -
  1. -

    Import the Controller V-ECU from the 2Ecu_CanBusSimulation demo into the DsVeosCoSim.osa:

    -
      -
    • -

      In the VEOS Player:

      -

      Drag & drop the Controller.vecu file from the 2Ecu_CanBusSimulation folder in the Documents folder into the simulation system.

      -

      In the dialog that opens, click Build to complete the import.

      -
    • -
    • -

      In the command line (from the directory in which the DsVeosCoSim.osa is saved):

      -

      On Windows:

      -
      <VEOS installation folder>\bin\veos.exe model import -p <Documents folder>\2Ecu_CanBusSimulation\AR_PosControl_2Ecus_Can.osa --vpus Controller .\DsVeosCoSim.osa -
      -

      On Linux:

      -
      /opt/dspace/veos2023b/bin/veos model import -p <Controller.osa folder>/Controller.osa ./DsVeosCoSim.osa -
      -
    • -
    -
  2. -
  3. -

    Connect the CanCommunicationController of the Controller V-ECU to the CanCluster communication cluster:

    -
      -
    • -

      In the VEOS Player:

      -

      Click on Home - Autoconnect - Autoconnect communication controllers in the VEOS Player.

      -
    • -
    • -

      In the command line (from the directory in which the DsVeosCoSim.osa is saved):

      -

      On Windows:

      -
      <VEOS installation folder>\bin\veos.exe model connect .\DsVeosCoSim.osa --autoconnect-communication-controllers -
      -

      On Linux:

      -
      /opt/dspace/veos2023b/bin/veos model connect ./DsVeosCoSim.osa --autoconnect-communication-controllers -
      -
    • -
    -
  4. -
  5. -

    Save the DsVeosCoSim.osa.

    -
  6. -
-

Running the co-simulation

-
    -
  1. -

    Load the modified DsVeosCoSim.osa to the VEOS simulator.

    -
  2. -
  3. -

    In your DsVeosCoSimDemo/build directory, run the executable you built in -Example: Using Data Callback Functions to Get Information on CAN Bus Messages via

    -
    .\Debug\DsVeosCoSimDemo.exe -
    -

    on Windows or

    -
    ./Debug/DsVeosCoSimDemo -
    -

    on Linux.

    -
  4. -
  5. -

    Start the simulation in VEOS:

    -
      -
    • -

      On Windows, click Simulation - Start in the VEOS Player or use the VEOS Simulator Console in the command-line:

      -
      <VEOS installation directory>/bin/veos.exe sim start -
      -
    • -
    • -

      On Linux:

      -
      /opt/dspace/veos2023b/bin/veos sim start -
      -
    • -
    -
  6. -
-

Client output

-

The following listing shows the output produced by the client:

-
Received CAN message with ID 10 and data 00-00 from bus controller CanController at 0.002 s. -Received CAN message with ID 10 and data 00-00 from bus controller CanController at 0.022 s. -Received CAN message with ID 10 and data 00-00 from bus controller CanController at 0.042 s. -Received CAN message with ID 10 and data 00-00 from bus controller CanController at 0.062 s. -
-

Example: Sending Data

-

Introduction

-

The CoSim client can send data to other co-simulation participants via the CoSim server. This example demonstrates how to send a simple CAN message.

-

Preconditions

- -

How to set up the client

-
    -
  1. -

    In the main.cpp code of Example: Setting Up a Basic Co-Simulation, change the OnEndStep function definition to -this:

    -
    void OnEndStep(DsVeosCoSim_SimulationTime simulationTime, void* userData) { - const uint8_t data[1]{42}; - const DsVeosCoSim_Handle handle = userData; - DsVeosCoSim_CanMessage canMessage{}; - canMessage.id = 12; - canMessage.flags = DsVeosCoSim_CanMessageFlags_FlexibleDataRateFormat; - canMessage.length = 1; - canMessage.data = data; - const DsVeosCoSim_Result result = DsVeosCoSim_TransmitCanMessage(handle, &canMessage); - if (result == DsVeosCoSim_Result_Full) { - // No more space in the internal buffer - } else if (result != DsVeosCoSim_Result_Ok) { - DsVeosCoSim_Disconnect(handle); - return; - } -} -
    -
  2. -
  3. -

    Save the main.cpp file and call cmake --build . to build the executable.

    -
  4. -
-

What it does

-

When the OnEndStep function is called, it specifies a CAN message with the following characteristics:

-
    -
  • -

    Message ID 12

    -
  • -
  • -

    Flexible Data Rate flag, i.e., CAN FD

    -
  • -
  • -

    Message length 1 byte

    -
  • -
  • -

    Payload 42

    -
  • -
-

The function then calls the DsVeosCoSim_TransmitCanMessage Function, which transmits the message to the Controller VPU via the CoSim server.

-

Running the co-simulation

-
    -
  1. -

    Enable the generation of bus log files in VEOS:

    -
      -
    • -

      On Windows, enable the checkbox Generate bus log files in File - Preferences - Log Options in the VEOS Player.

      -

      Alternatively, you can use the VEOS Simulator Console in the command-line:

      -
      <VEOS installation directory>/bin/veos.exe sim config --enable-bus-log -
      -
    • -
    • -

      On Linux:

      -
      /opt/dspace/veos2023b/bin/veos sim config --enable-bus-log -
      -
    • -
    -
  2. -
  3. -

    Load the DsVeosCoSim.osa you created in -Example: Using Data Callback Functions to Get Information on CAN Bus Messages to the -VEOS simulator.

    -

    VEOS displays a message to inform you that bus logging was enabled. In the VEOS Player, direct links to the files are displayed in the Messages pane.

    -
  4. -
  5. -

    In your DsVeosCoSimDemo/build directory, run the executable you built before in Example: Sending Data via

    -
    .\Debug\DsVeosCoSimDemo.exe -
    -

    on Windows or

    -
    ./Debug/DsVeosCoSimDemo -
    -

    on Linux.

    -
  6. -
  7. -

    Start the simulation in VEOS.

    -
  8. -
-

Bus log files

-

The CoSimExample.BusTransfer.log file contains entries for the bus messages transmitted and received by the CoSim server. The following listing shows an -excerpt:

-
Time,DeltaTime,ControllerID,MsgID,Dir,DataLen,Data,Type,DatabaseID -0000.0001,0000.0001,1,12,1,1,2A,C,-1 -0000.0011,0000.0001,1,12,1,1,2A,C,-1 -0000.0013,0000.0002,1,10,0,2,00-00,C,-1 -
-

The first two messages are transmitted messages, which you can see by comparing the MsgID, DataLen, and Data columns with the settings listed in -Example: Sending Data. 2A is the hexadecimal representation of 42. Additionally, the Dir column displays 1 for transmitted -messages and 0 for received messages.

-

The third message is a received message from the Controller V-ECU.

-

You can compare the CoSimExample.BusTransfer.log file to the Controller.BusTransfer.log log file, which shows the same entries except for the Dir column:

-
Time,DeltaTime,ControllerID,MsgID,Dir,DataLen,Data,Type,DatabaseID -0000.0001,0000.0001,0,12,0,1,2A,C,-1 -0000.0011,0000.0001,0,12,0,1,2A,C,-1 -0000.0013,0000.0002,0,10,1,2,00-00,C,-1 -
-

Example: Receiving Data

-

Introduction

-

This example shows how to receive data from other co-simulation participants using receive functions instead of data callbacks.

-

Preconditions

- -

How to set up the client

-
    -
  1. -

    In the main.cpp code of the basic example, change the OnEndStep function definition to this:

    -
    void OnEndStep(DsVeosCoSim_SimulationTime simulationTime, void* userData) { - const DsVeosCoSim_Handle handle = userData; - while (true) { - DsVeosCoSim_CanMessage message{}; - const DsVeosCoSim_Result result = DsVeosCoSim_ReceiveCanMessage(handle, &message); - if (result == DsVeosCoSim_Result_Ok) { - std::cout << "Received CAN message with ID " << message.id << " at " << - DSVEOSCOSIM_SIMULATION_TIME_TO_SECONDS(simulationTime) << " s.\n"; - } else if (result == DsVeosCoSim_Result_Empty) { - // No more messages - break; - } else { - DsVeosCoSim_Disconnect(handle); - return; - } - } -} -
    -
  2. -
  3. -

    Save the main.cpp file and call cmake --build . to build the executable.

    -
  4. -
-

What it does

-

When the OnEndStep function is called at the end of each simulation step, it calls the DsVeosCoSim_ReceiveCanMessage Function repeatedly until this function returns DsVeosCoSim_Result_Empty. For each received message, information on the message ID and the simulation time is printed.

-

Running the co-simulation

-
    -
  1. -

    Enable the generation of bus log files as described in Example: Sending Data.

    -
  2. -
  3. -

    Load the DsVeosCoSim.osa you created in -Example: Using Data Callback Functions to Get Information on CAN Bus Messages to the VEOS -simulator.

    -

    VEOS displays a message to inform you that bus logging was enabled. In the VEOS Player, direct links to the files are displayed in the Messages pane.

    -
  4. -
  5. -

    From your DsVeosCoSimDemo/build directory, run the executable you built in Example: Receiving Data via

    -
    .\Debug\DsVeosCoSimDemo.exe -
    -

    on Windows or

    -
    ./Debug/DsVeosCoSimDemo -
    -

    on Linux.

    -
  6. -
  7. -

    Start the simulation in VEOS:

    -
      -
    • -

      On Windows, click Simulation - Start in the VEOS Player or use the VEOS Simulator Console in the command-line:

      -
      <VEOS installation directory>\bin\veos.exe sim start -
      -
    • -
    • -

      On Linux:

      -
      /opt/dspace/veos2023b/bin/veos sim start -
      -
    • -
    -
  8. -
-

Client output and bus log files

-

The client output looks like this:

-
Received CAN message with ID 10 at 0.002 s. -Received CAN message with ID 10 at 0.022 s. -Received CAN message with ID 10 at 0.042 s. -
-

Compare this to the CoSimExample.BusTransfer.log file:

-
Time,DeltaTime,ControllerID,MsgID,Dir,DataLen,Data,Type,DatabaseID -0000.0012,0000.0002,1,10,0,2,00-00,C,-1 -0000.0212,0000.0002,1,10,0,2,00-00,C,-1 -0000.0412,0000.0002,1,10,0,2,00-00,C,-1 -
-

Example: Running a Polling-Based Simulation

-

Introduction

-

You can configure the CoSim client to operate in polling mode. In this case, the client continually polls for commands from VEOS and performs the actions that are specified for each command.

-

A polling-based co-simulation can be useful in cases where the CoSim server has to communicate with another API that is callback-based. This way, you do not have to take care of synchronizing all the callbacks.

-

Preconditions

- -

How to set up the client

-
    -
  1. -

    In the main.cpp code of the basic example, add the following function definition:

    -
    void OnCanMessage(DsVeosCoSim_SimulationTime simulationTime, - const DsVeosCoSim_CanController* canController, - const DsVeosCoSim_CanMessage* message, - void* userData) { - std::cout << "Received CAN message with ID " << message->id << " with data " - << DataToString(message->data, message->length, '-') << " from CAN controller " - << canController->name << " at " - << DSVEOSCOSIM_SIMULATION_TIME_TO_SECONDS(simulationTime) << " s.\n"; -} -
    -
  2. -
  3. -

    Change Step 4 in the main function like this:

    -
    // Step 4: Run a polling-based co-simulation -DsVeosCoSim_Callbacks callbacks{}; -callbacks.canMessageReceivedCallback = OnCanMessage; -callbacks.userData = handle; // Pass the handle to every callback -if (DsVeosCoSim_StartPollingBasedCoSimulation(handle, callbacks) != DsVeosCoSim_Result_Ok) { - DsVeosCoSim_Disconnect(handle); - DsVeosCoSim_Destroy(handle); - return 1; -} - -while (true) { - DsVeosCoSim_SimulationTime simulationTime{}; - DsVeosCoSim_Command command{}; - if (DsVeosCoSim_PollCommand(handle, &simulationTime, &command) != DsVeosCoSim_Result_Ok) { - DsVeosCoSim_Disconnect(handle); - DsVeosCoSim_Destroy(handle); - return 1; - } - - switch (command) { - case DsVeosCoSim_Command_Step: { - const uint8_t data[1]{42}; - DsVeosCoSim_CanMessage canMessage{}; - canMessage.id = 12; - canMessage.flags = DsVeosCoSim_CanMessageFlags_FlexibleDataRateFormat; - canMessage.length = 1; - canMessage.data = data; - const DsVeosCoSim_Result result = DsVeosCoSim_CanMessageTransmit(handle, &canMessage); - if (result == DsVeosCoSim_Result_Full) { - // No more place in the internal buffer - } else if (result != DsVeosCoSim_Result_Ok) { - DsVeosCoSim_Disconnect(handle); - DsVeosCoSim_Destroy(handle); - return 1; - } - break; - } - case DsVeosCoSim_Command_Start: - std::cout << "Simulation started at " << DSVEOSCOSIM_SIMULATION_TIME_TO_SECONDS(simulationTime) << " s.\n"; - break; - case DsVeosCoSim_Command_Stop: - std::cout << "Simulation stopped at " << DSVEOSCOSIM_SIMULATION_TIME_TO_SECONDS(simulationTime) << " s.\n"; - break; - case DsVeosCoSim_Command_Pause: - std::cout << "Simulation paused at " << DSVEOSCOSIM_SIMULATION_TIME_TO_SECONDS(simulationTime) << " s.\n"; - break; - case DsVeosCoSim_Command_Continue: - std::cout << "Simulation continued at " << DSVEOSCOSIM_SIMULATION_TIME_TO_SECONDS(simulationTime) << " s.\n"; - break; - } - - if (DsVeosCoSim_FinishCommand(handle) != DsVeosCoSim_Result_Ok) { - DsVeosCoSim_Disconnect(handle); - DsVeosCoSim_Destroy(handle); - return 1; - } -} -
    -
  4. -
  5. -

    Save the main.cpp file and call cmake --build . to build the executable.

    -
  6. -
-

What it does

-

First, a callback function for CAN messages is defined. This is passed to the DsVeosCoSim_StartPollingBasedCoSimulation function that starts the polling-based co-simulation.

-

The simulation then proceeds according to the command that is passed via DsVeosCoSim_PollCommand Function and continues polling for commands and executing them until the simulation is unloaded or the DsVeosCoSim_Disconnect Function is called.

-

Each time the Step command is received, a CAN message is sent as specified in the DsVeosCoSim_Command_Step case. This is identical to the CAN message specified in Example: Sending Data.

-

Running the co-simulation

-
    -
  1. -

    Enable the generation of bus log files as described in Example: Sending Data.

    -
  2. -
  3. -

    Load the DsVeosCoSim.osa you created in Example: Using Data Callback Functions to Get Information on CAN Bus Messages to the VEOS simulator.

    -

    VEOS displays a message to inform you that bus logging was enabled. In the VEOS Player, direct links to the files are displayed in the Messages pane.

    -
  4. -
  5. -

    From your DsVeosCoSimDemo/build directory, run the executable you built in Example: Running a Polling-Based Simulation via

    -
    .\Debug\DsVeosCoSimDemo.exe -
    -

    on Windows or

    -
    ./Debug/DsVeosCoSimDemo -
    -

    on Linux.

    -
  6. -
  7. -

    Start the simulation in VEOS:

    -
      -
    • -

      On Windows, click Simulation - Start in the VEOS Player or use the VEOS Simulator Console in the command-line:

      -
      <VEOS installation directory>\bin\veos.exe sim start -
      -
    • -
    • -

      On Linux:

      -
      /opt/dspace/veos2023b/bin/veos sim start -
      -
    • -
    -
  8. -
-

Client output and bus log files

-

The client produces the same output as in Example: Implementing Simulation State Change Callbacks.

-

The bus log files correspond to the bus log files produced by Example: Sending Data.

-

Example: Handling I/O Signals

-

Introduction

-

This example illustrates how to handle I/O signals in a co-simulation using a modification of -Example: Running a Polling-Based Simulation and an additional CoSim server-client pair.

-

The polling-based co-simulation is modified to change the value of the outgoing signal at specified times when the simulation is advanced by a step. The second -client reads the signal from the first one and reports on each signal value change.

-

Preconditions

- -

How to modify the polling-based client

-
    -
  1. -

    In the main.cpp of the polling-based client, add the following declaration:

    -
    const DsVeosCoSim_IoSignal* outgoingSignals{}; -
    -
  2. -
  3. -

    In the main function, change the DsVeosCoSim_Command_Step case like this:

    -
    case DsVeosCoSim_Command_Step: { - std::cout << "Simulation stepped at " << DSVEOSCOSIM_SIMULATION_TIME_TO_SECONDS(simulationTime) << " s.\n"; - if ((simulationTime % 10000000) == 0) { // Only every 10 milliseconds - double value = DSVEOSCOSIM_SIMULATION_TIME_TO_SECONDS(simulationTime); - if (DsVeosCoSim_WriteOutgoingSignal(handle, outgoingSignals[0].id, 1, &value) != DsVeosCoSim_Result_Ok) { - DsVeosCoSim_Disconnect(handle); - DsVeosCoSim_Destroy(handle); - return 1; - } - } -} -
    -
  4. -
  5. -

    Save the main.cpp file and call cmake --build . to build the executable.

    -
  6. -
-

What it does

-

The modification of the polling-based co-simulation makes the client check at each step if the current simulation time is a multiple of 10 milliseconds. If yes, -it changes the value of the outgoing signal to the current simulation time in seconds.

-

Creating the second CoSim client

-
    -
  1. -

    Create the main2.cpp file with the following content:

    -
    #include <iomanip> -#include <iostream> -#include <sstream> - -#include "DsVeosCoSim/DsVeosCoSim.h" - -uint32_t ioSignalsCount{}; -const DsVeosCoSim_IoSignal* ioSignals{}; - -void OnLogCallback(DsVeosCoSim_Severity severity, const char* logMessage) { - switch (severity) { - case DsVeosCoSim_Severity_Error: - std::cout << "ERROR " << logMessage << "\n"; - break; - case DsVeosCoSim_Severity_Warning: - std::cout << "WARN " << logMessage << "\n"; - break; - case DsVeosCoSim_Severity_Info: - std::cout << "INFO " << logMessage << "\n"; - break; - case DsVeosCoSim_Severity_Trace: - std::cout << "TRACE " << logMessage << "\n"; - break; - } -} - -// Called after every interval specified in the StepSize parameter of the CoSim JSON file -void OnEndStep(DsVeosCoSim_SimulationTime simulationTime, void* userData) { - uint32_t length{}; - double value{}; - if (DsVeosCoSim_ReadIncomingSignal(userData, ioSignals[0].id, &length, &value) != DsVeosCoSim_Result_Ok) { - DsVeosCoSim_Disconnect(userData); - return; - } - - std::cout << "Signal has the value " << value << " at " << - DSVEOSCOSIM_SIMULATION_TIME_TO_SECONDS(simulationTime) << " s.\n"; -} - -// Called when an I/O signal has changed -void OnSignal(DsVeosCoSim_SimulationTime simulationTime, - const DsVeosCoSim_IoSignal* ioSignal, - uint32_t length, - const void* value, - void* userData) { - std::cout << "Signal changed to the value " << *(double*)value << " at " << - DSVEOSCOSIM_SIMULATION_TIME_TO_SECONDS(simulationTime) << " s.\n"; -} - -int main() { - DsVeosCoSim_SetLogCallback(OnLogCallback); - - DsVeosCoSim_Handle handle = DsVeosCoSim_Create(); - if (handle == nullptr) { - return 1; - } - - DsVeosCoSim_ConnectConfig connectConfig{}; - connectConfig.serverName = "CoSimExample2"; - if (DsVeosCoSim_Connect(handle, connectConfig) != DsVeosCoSim_Result_Ok) { - DsVeosCoSim_Destroy(handle); - return 1; - } - - if (DsVeosCoSim_GetIncomingSignals(handle, &ioSignalsCount, &ioSignals) != DsVeosCoSim_Result_Ok) { - DsVeosCoSim_Disconnect(handle); - DsVeosCoSim_Destroy(handle); - return 1; - } - - DsVeosCoSim_Callbacks callbacks{}; - callbacks.incomingSignalChangedCallback = OnSignal; - callbacks.simulationEndStepCallback = OnEndStep; - callbacks.userData = handle; // Pass the handle to every callback - if (DsVeosCoSim_RunCallbackBasedCoSimulation(handle, callbacks) != DsVeosCoSim_Result_Ok) { - DsVeosCoSim_Disconnect(handle); - DsVeosCoSim_Destroy(handle); - return 1; - } - - DsVeosCoSim_Destroy(handle); - return 0; -} -
    -
  2. -
  3. -

    Add the following lines to the CMakeLists.txt file and save it:

    -
    add_executable(Client2 main2.cpp) -target_link_libraries(Client2 PRIVATE DsVeosCoSim) -
    -
  4. -
  5. -

    In the DsVeosCoSimDemo/build directory, run the following commands again to configure the build project and build the executable:

    -
    cmake .. -cmake --build . -
    -

    There is now a second executable in the Debug subdirectory, e.g., Client2.exe.

    -
  6. -
-

What it does

-

The second client performs a callback-based simulation in which the OnSignal function is called when the input signal changes. It then prints the new value -and the corresponding simulation time.

-

The OnEndStep function is called at the end of each simulation step. It reads the incoming signal that was received first and prints its value and the -corresponding simulation time.

-

How to create the second CoSim server

-
    -
  1. -

    Create a new JSON interface description file with the following content:

    -
    { - "$schema": "file:///DsVeosCoSim.schema.json", - "Type": "DsVeosCoSim", - "Name": "CoSimExample2", - "StepSize": 0.001, - "IOSignals": { - "Incoming": [ - { - "Name": "Signal1", - "DataType": "float64", - "PortName": "Port1" - } - ] - } -} -
    -
  2. -
  3. -

    Save this file as CoSimExample2.json and import it into the DsVeosCoSim.osa.

    -
  4. -
  5. -

    Connect the Signal1 signal of the CoSimExample server to the Signal1 signal of the CoSimExample2 server:

    -
      -
    • -

      On Windows:

      -
        -
      • -

        In the VEOS Player, click Home - Autoconnect - Autoconnect signals.

        -
      • -
      • -

        In the command-line, you have to use the VEOS Model Console like this:

        -
        <VEOS installation directory>\bin\veos.exe model connect .\DsVeosCoSim.osa --autoconnect-signals -
        -
      • -
      -
    • -
    • -

      On Linux:

      -
      /opt/dspace/veos2023b/bin/veos model connect ./DsVeosCoSim.osa --autoconnect-signals -
      -
    • -
    -
  6. -
  7. -

    Save the DsVeosCoSim.osa.

    -
  8. -
-

Running the co-simulation

-
    -
  1. -

    Load the DsVeosCoSim.osa to the VEOS simulator.

    -
  2. -
  3. -

    From your DsVeosCoSimDemo/build directory, run each executable in a separate terminal:

    -
    .\Debug\DsVeosCoSimDemo.exe -
    -

    and

    -
    .\Debug\Client2.exe -
    -

    on Windows or

    -
    ./Debug/DsVeosCoSimDemo -
    -

    and

    -
    ./Debug/Client2 -
    -

    on Linux.

    -
  4. -
  5. -

    Start the simulation in VEOS:

    -
      -
    • -

      On Windows, click Simulation - Start in the VEOS Player or use the VEOS Simulator Console in the command-line:

      -
      <VEOS installation directory>\bin\veos.exe sim start -
      -
    • -
    • -

      On Linux:

      -
      /opt/dspace/veos2023b/bin/veos sim start -
      -
    • -
    -
  6. -
-

Client output

-

The output of the first client performing the polling-based simulation looks like this:

-
Simulation stepped at 0 s. -Simulation stepped at 0.001 s. -Simulation stepped at 0.002 s. -Simulation stepped at 0.003 s. -Simulation stepped at 0.004 s. -Simulation stepped at 0.005 s. -Simulation stepped at 0.006 s. -Simulation stepped at 0.007 s. -Simulation stepped at 0.008 s. -Simulation stepped at 0.009 s. -Simulation stepped at 0.01 s. -Simulation stepped at 0.011 s. -Simulation stepped at 0.012 s. -Simulation stepped at 0.013 s. -Simulation stepped at 0.014 s. -Simulation stepped at 0.015 s. -Simulation stepped at 0.016 s. -Simulation stepped at 0.017 s. -Simulation stepped at 0.018 s. -Simulation stepped at 0.019 s. -Simulation stepped at 0.02 s. -Simulation stepped at 0.021 s. -
-

The output of the second client performing the callback-based simulation looks like this:

-
Signal has the value 0 at 0 s. -Signal has the value 0 at 0.001 s. -Signal has the value 0 at 0.002 s. -Signal has the value 0 at 0.003 s. -Signal has the value 0 at 0.004 s. -Signal has the value 0 at 0.005 s. -Signal has the value 0 at 0.006 s. -Signal has the value 0 at 0.007 s. -Signal has the value 0 at 0.008 s. -Signal has the value 0 at 0.009 s. -Signal has the value 0 at 0.01 s. -Signal changed to the value 0.01 at 0.011 s. -Signal has the value 0.01 at 0.011 s. -Signal has the value 0.01 at 0.012 s. -Signal has the value 0.01 at 0.013 s. -Signal has the value 0.01 at 0.014 s. -Signal has the value 0.01 at 0.015 s. -Signal has the value 0.01 at 0.016 s. -Signal has the value 0.01 at 0.017 s. -Signal has the value 0.01 at 0.018 s. -Signal has the value 0.01 at 0.019 s. -Signal has the value 0.01 at 0.02 s. -Signal changed to the value 0.02 at 0.021 s. -
-

Example: Optional Client

-

Introduction

-

By default, a co-simulation can only be started if a CoSim client is connected to a server in VEOS. However, by marking a client as optional in the JSON -interface description file of the CoSim server, the simulation can be started even when no client is connected.

-

Preconditions

- -

Modifying the CoSim server

-
    -
  1. -

    Add the following line at the top level of the Example.json file, for example, directly below the StepSize property, and save the file:

    -
    "IsClientOptional": true, -
    -
  2. -
  3. -

    Remove the CoSimExample server from the DsVeosCoSim.osa and import the modified Example.json.

    -
  4. -
-

Running the co-simulation

-
    -
  1. -

    Load the modified DsVeosCoSim.osa to the VEOS simulator.

    -
  2. -
  3. -

    Start the simulation in VEOS:

    -
      -
    • -

      On Windows, click Simulation - Start in the VEOS Player or use the VEOS Simulator Console in the command-line:

      -
      <VEOS installation directory>\bin\veos.exe sim start -
      -
    • -
    • -

      On Linux:

      -
      /opt/dspace/veos2023b/bin/veos sim start -
      -
    • -
    -

    Because the client is now marked as optional, the simulation starts even though no client is connected.

    -
  4. -
  5. -

    From the DsVeosCoSimDemo/build subdirectory, run the basic client executable via

    -
    .\Debug\DsVeosCoSimDemo.exe -
    -

    on Windows or

    -
    ./Debug/DsVeosCoSimDemo -
    -

    on Linux.

    -

    Now the client connects to the server and participates in the co-simulation.

    -
  6. -
  7. -

    Terminate the client executable by pressing Ctrl+C.

    -

    The simulation continues without the client.

    -
  8. -
-

DsVeosCoSim Client API Reference

-

Enumerations

-

DsVeosCoSim_CanMessageFlags Enumeration

-

Description

-

Contains the possible flags of a CAN message.

-

Syntax

-
typedef uint32_t DsVeosCoSim_CanMessageFlags; - -enum { - DsVeosCoSim_CanMessageFlags_Loopback = 1, - DsVeosCoSim_CanMessageFlags_Error = 2, - DsVeosCoSim_CanMessageFlags_Drop = 4, - DsVeosCoSim_CanMessageFlags_ExtendedId = 8, - DsVeosCoSim_CanMessageFlags_BitRateSwitch = 16, - DsVeosCoSim_CanMessageFlags_FlexibleDataRateFormat = 32, -}; -
-

Values

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameDescription
DsVeosCoSim_CanMessageFlags_LoopbackFor transmit and receive messages. Indicates that the CAN message is transmitted back to the sender as well.
DsVeosCoSim_CanMessageFlags_ErrorOnly for receive messages. Indicates that the CAN message transmission failed due to an error from the VEOS CoSim server.
DsVeosCoSim_CanMessageFlags_DropOnly for receive messages. Indicates that the CAN message was dropped due to a full buffer at the VEOS CoSim server.
DsVeosCoSim_CanMessageFlags_ExtendedIdFor transmit and receive messages. Indicates that the CAN message uses the extended ID range.
DsVeosCoSim_CanMessageFlags_BitRateSwitchFor transmit and receive messages. Indicates that the CAN message has a bit rate switch.
DsVeosCoSim_CanMessageFlags_FlexibleDataRateFormatFor transmit and receive messages. Indicates a CAN FD message.
-

DsVeosCoSim_Command Enumeration

-

Description

-

Contains commands for controlling the co-simulation in polling mode.

-

Syntax

-
typedef enum DsVeosCoSim_Command { - DsVeosCoSim_Command_None, - DsVeosCoSim_Command_Step, - DsVeosCoSim_Command_Start, - DsVeosCoSim_Command_Stop, - DsVeosCoSim_Command_Terminate, - DsVeosCoSim_Command_Pause, - DsVeosCoSim_Command_Continue, -} DsVeosCoSim_Command; -
-

Values

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ValueDescription
VeosCoSim_Command_NoneNo simulation command.
DsVeosCoSim_Command_StepAdvance the simulation by one step.
VeosCoSim_Command_StartStart the simulation.
VeosCoSim_Command_StopStop the simulation.
VeosCoSim_Command_TerminateTerminate the simulation.
DsVeosCoSim_Command_PausePause the simulation.
DsVeosCoSim_Command_ContinueContinue the simulation.
-

DsVeosCoSim_ConnectionState Enumeration

-

Description

-

Contains the possible connection states.

-

Syntax

-
typedef enum DsVeosCoSim_ConnectionState { - DsVeosCoSim_ConnectionState_Disconnected, - DsVeosCoSim_ConnectionState_Connected, -} DsVeosCoSim_ConnectionState; -
-

Values

- - - - - - - - - - - - - - - - - -
NameDescription
DsVeosCoSim_ConnectionState_DisconnectedIndicates that the VEOS CoSim client is disconnected from the server.
DsVeosCoSim_ConnectionState_ConnectedIndicates that the VEOS CoSim client is connected to the server.
-

DsVeosCoSim_DataType Enumeration

-

Description

-

Contains valid data types for I/O signals.

-

Syntax

-
typedef enum DsVeosCoSim_DataType { - DsVeosCoSim_DataType_Bool = 1, - DsVeosCoSim_DataType_Int8, - DsVeosCoSim_DataType_Int16, - DsVeosCoSim_DataType_Int32, - DsVeosCoSim_DataType_Int64, - DsVeosCoSim_DataType_UInt8, - DsVeosCoSim_DataType_UInt16, - DsVeosCoSim_DataType_UInt32, - DsVeosCoSim_DataType_UInt64, - DsVeosCoSim_DataType_Float32, - DsVeosCoSim_DataType_Float64 -} DsVeosCoSim_DataType; -
-

Values

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameDescription
DsVeosCoSim_DataType_BoolThe data type of the signal is Boolean. The C data type is uint8_t, where 0 equals false and any other value equals true.
DsVeosCoSim_DataType_Int8The data type of the signal is signed 8-bit integer (int8_t).
DsVeosCoSim_DataType_Int16The data type is signed 16-bit integer (int16_t).
DsVeosCoSim_DataType_Int32The data type is signed 32-bit integer (int32_t).
DsVeosCoSim_DataType_Int64The data type is signed 64-bit integer (int64_t).
DsVeosCoSim_DataType_UInt8The data type is unsigned 8-bit integer (uint8_t).
DsVeosCoSim_DataType_UInt16The data type is unsigned 16-bit integer (uint16_t).
DsVeosCoSim_DataType_UInt32The data type is unsigned 32-bit integer (uint32_t).
DsVeosCoSim_DataType_UInt64The data type is unsigned 64-bit integer (uint64_t).
DsVeosCoSim_DataType_Float32The data type is 32-bit float (float).
DsVeosCoSim_DataType_Float64The data type is 64-bit float (double).
-

DsVeosCoSim_EthMessageFlags Enumeration

-

Description

-

Contains the possible flags of an Ethernet message.

-

Syntax

-
typedef uint32_t DsVeosCoSim_EthMessageFlags; - -enum { - DsVeosCoSim_EthMessageFlags_Loopback = 1, - DsVeosCoSim_EthMessageFlags_Error = 2, - DsVeosCoSim_EthMessageFlags_Drop = 4, -}; -
-

Values

- - - - - - - - - - - - - - - - - - - - - -
NameDescription
DsVeosCoSim_EthMessageFlags_LoopbackFor transmit and receive messages. Indicates that the Ethernet message is transmitted back to the sender as well.
DsVeosCoSim_EthMessageFlags_ErrorOnly for receive messages. Indicates that the Ethernet message transmission failed due to an error from the VEOS CoSim server.
DsVeosCoSim_EthMessageFlags_DropOnly for receive messages. Indicates that the Ethernet message was dropped due to a full buffer at the VEOS CoSim server.
-

DsVeosCoSim_LinControllerType Enumeration

-

Description

-

Contains the LIN controller type.

-

Syntax

-
typedef enum DsVeosCoSim_LinControllerType { - DsVeosCoSim_LinControllerType_Responder = 1, - DsVeosCoSim_LinControllerType_Commander, -} DsVeosCoSim_LinControllerType; -
-

Values

- - - - - - - - - - - - - - - - - -
NameDescription
DsVeosCoSim_LinControllerType_ResponderIndicates that the LIN controller is a responder, i.e., slave.
DsVeosCoSim_LinControllerType_CommanderIndicates that the LIN controller is a commander, i.e,. master.
-

DsVeosCoSim_LinMessageFlags Enumeration

-

Description

-

Contains the possible flags of a LIN message.

-

Syntax

-
typedef uint32_t DsVeosCoSim_LinMessageFlags; - -enum { - DsVeosCoSim_LinMessageFlags_Loopback = 1, - DsVeosCoSim_LinMessageFlags_Error = 2, - DsVeosCoSim_LinMessageFlags_Drop = 4, - DsVeosCoSim_LinMessageFlags_Header = 8, - DsVeosCoSim_LinMessageFlags_Response = 16, - DsVeosCoSim_LinMessageFlags_WakeEvent = 32, - DsVeosCoSim_LinMessageFlags_SleepEvent = 64, - DsVeosCoSim_LinMessageFlags_EnhancedChecksum = 128, - DsVeosCoSim_LinMessageFlags_TransferOnce = 256, - DsVeosCoSim_LinMessageFlags_ParityFailure = 512, - DsVeosCoSim_LinMessageFlags_Collision = 1024, - DsVeosCoSim_LinMessageFlags_NoResponse = 2048, -}; -
-

Values

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameDescription
DsVeosCoSim_LinMessageFlags_LoopbackFor transmit and receive messages. Indicates that the LIN message is transmitted back to the sender as well.
DsVeosCoSim_LinMessageFlags_ErrorOnly for receive messages. Indicates that the LIN message transmission failed due to an error from the VEOS CoSim server.
DsVeosCoSim_LinMessageFlags_DropOnly for receive messages. Indicates that the LIN message was dropped due to a full buffer at the VEOS CoSim server.
DsVeosCoSim_LinMessageFlags_HeaderFor transmit and receive messages. Indicates that the LIN message contains a header.
DsVeosCoSim_LinMessageFlags_ResponseFor transmit and receive messages. Indicates that the LIN message contains a response.
DsVeosCoSim_LinMessageFlags_WakeEventFor transmit and receive messages. Indicates that the LIN message contains a wake command.
DsVeosCoSim_LinMessageFlags_SleepEventFor transmit and receive messages. Indicates that the LIN message contains a sleep command.
DsVeosCoSim_LinMessageFlags_EnhancedChecksumFor transmit and receive messages. Indicates that the LIN message uses the enhanced checksum.
DsVeosCoSim_LinMessageFlags_TransferOnceOnly for transmit messages. This flag only makes sense if the DsVeosCoSim_LinMessageFlags_Response flag is set. Indicates a single ad-hoc transmission of a LIN response message. If the message is not in the allowed response space it will be omitted silently.
DsVeosCoSim_LinMessageFlags_ParityFailureOnly for receive messages. Indicates that the LIN header could not be transmitted, because another LIN header was sent at the same time.
DsVeosCoSim_LinMessageFlags_CollisionOnly for receive messages. Indicates that the LIN response could not be transmitted, because another LIN response was sent at the same time.
DsVeosCoSim_LinMessageFlags_NoResponseOnly for receive messages. Indicates that no response to the last header was received.
-

Note:

-
    -
  • -

    One of the following flags must be set:

    -
      -
    • DsVeosCoSim_LinMessageFlags_Header
    • -
    • DsVeosCoSim_LinMessageFlags_Response
    • -
    • DsVeosCoSim_LinMessageFlags_WakeEvent
    • -
    • DsVeosCoSim_LinMessageFlags_SleepEvent
    • -
    -
  • -
  • -

    If DsVeosCoSim_LinMessageFlags_Header and DsVeosCoSim_LinMessageFlags_Response are set simultaneously, the message contains both header and response.

    -
  • -
  • -

    DsVeosCoSim_LinMessageFlags_WakeEvent and DsVeosCoSim_LinMessageFlags_SleepEvent cannot be combined with each other or with DsVeosCoSim_LinMessageFlags_Header and DsVeosCoSim_LinMessageFlags_Response

    -
  • -
-

DsVeosCoSim_Result Enumeration

-

Description

-

Contains the possible return values of VEOS CoSim functions.

-

Syntax

-
typedef enum DsVeosCoSim_Result { - DsVeosCoSim_Result_Ok, - DsVeosCoSim_Result_Error, - DsVeosCoSim_Result_Empty, - DsVeosCoSim_Result_Full - DsVeosCoSim_Result_InvalidArgument, - DsVeosCoSim_Result_Disconnected -} DsVeosCoSim_Result; -
-

Values

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ValueDescription
DsVeosCoSim_Result_OkThe function call was successful.
DsVeosCoSim_Result_ErrorThe function call failed with an error. In this case, a log message is sent via the DsVeosCoSim_LogCallback function. Refer to DsVeosCoSim_LogCallback Function Pointer.
DsVeosCoSim_Result_EmptyOnly for bus message receive functions. Indicates that no bus message was found in the internal buffer.
DsVeosCoSim_Result_FullOnly for bus message transmit functions. Indicates that no space is left for new bus messages in the internal buffer.
DsVeosCoSim_Result_InvalidArgumentThe function call failed due to an invalid argument.
DsVeosCoSim_Result_DisconnectedThe function detected a disconnection from the VEOS CoSim server.
-

DsVeosCoSim_Severity Enumeration

-

Description

-

Contains all possible severity levels of a log message in descending order of severity.

-

Syntax

-
typedef enum DsVeosCoSim_Severity { - DsVeosCoSim_Severity_Error - DsVeosCoSim_Severity_Warning, - DsVeosCoSim_Severity_Info, - DsVeosCoSim_Severity_Trace, -} DsVeosCoSim_Severity; -
-

Values

- - - - - - - - - - - - - - - - - - - - - - - - - -
NameDescription
DsVeosCoSim_Severity_ErrorThe severity level is error.
DsVeosCoSim_Severity_WarningThe severity level is warning.
DsVeosCoSim_Severity_InfoThe severity level is information.
DsVeosCoSim_Severity_TraceThe severity level is trace.
-

DsVeosCoSim_SizeKind Enumeration

-

Description

-

Contains information on the I/O signal length type.

-

Syntax

-
typedef enum DsVeosCoSim_SizeKind { - DsVeosCoSim_SizeKind_Fixed = 1, - DsVeosCoSim_SizeKind_Variable, -} DsVeosCoSim_SizeKind; -
-

Values

- - - - - - - - - - - - - - - - - -
NameDescription
DsVeosCoSim_SizeKind_FixedIndicates that the I/O signal has a fixed length.
DsVeosCoSim_SizeKind_VariableIndicates that the I/O signal has a variable length in the range of 0 to DsVeosCoSim_IoSignal.length.
-

DsVeosCoSim_TerminateReason Enumeration

-

Description

-

Contains the possible reasons for a termination of the co-simulation.

-

Syntax

-
typedef enum DsVeosCoSim_TerminateReason { - DsVeosCoSim_TerminateReason_Finished, - DsVeosCoSim_TerminateReason_Error, -} DsVeosCoSim_TerminateReason; -
-

Values

- - - - - - - - - - - - - - - - - -
NameDescription
DsVeosCoSim_TerminateReason_FinishedIndicates that the co-simulation was terminated because it finished successfully.
DsVeosCoSim_TerminateReason_ErrorIndicates that the co-simulation was terminated because of an error.
-

Functions

-

DsVeosCoSim_CanMessageReceivedCallback Function Pointer

-

Description

-

Called when a new CAN message is received from the VEOS CoSim server.

-

Note: -If DsVeosCoSim_CanMessageReceivedCallback is registered, you cannot collect CAN messages using the -DsVeosCoSim_ReceiveCanMessage Function.

-

However, if the callback is not registered, each received message is buffered. Currently, the buffer size is 512 messages. If the buffer is full, new messages -are discarded.

-

Syntax

-
typedef void (*DsVeosCoSim_CanMessageReceivedCallback)( - DsVeosCoSim_SimulationTime simulationTime, - const DsVeosCoSim_CanController* busController, - const DsVeosCoSim_CanMessage* message, - void* userData -); -
-

Parameters

- - - - - - - - - - - - - - - - - - - - - - - - - -
NameDescription
simulationTimeThe current simulation time. Refer to DsVeosCoSim_SimulationTime Type.
canControllerThe CAN controller that sent the message. Refer to DsVeosCoSim_CanController Structure.
messageA pointer to the received CAN message. Refer to DsVeosCoSim_CanMessage Structure.
userDataThe user data passed to the co-simulation function via the DsVeosCoSim_SetCallbacks Function. Can be NULL.
-

Return values

-

This function has no return values.

-

DsVeosCoSim_Connect Function

-

Description

-

Connects the dSPACE VEOS CoSim client to the dSPACE VEOS CoSim server.

-

Syntax

-
DSVEOSCOSIM_DECL DsVeosCoSim_Result DsVeosCoSim_Connect( - DsVeosCoSim_Handle handle, - DsVeosCoSim_ConnectConfig connectConfig -); -
-

Parameters

- - - - - - - - - - - - - - - - - -
NameDescription
handleThe handle of the VEOS CoSim client. Refer to DsVeosCoSim_Handle Type.
connectConfigThe data used for connecting to the dSPACE VEOS CoSim sever. Refer to DsVeosCoSim_ConnectConfig Structure.
-

Return values

-

Refer to DsVeosCoSim_Result Enumeration.

-

DsVeosCoSim_Destroy Function

-

Description

-

Destroys the given handle.

-

Syntax

-
DSVEOSCOSIM_DECL void DsVeosCoSim_Destroy(DsVeosCoSim_Handle handle); -
-

Parameters

- - - - - - - - - - - - - -
NameDescription
handleThe handle of the VEOS CoSim client. Refer to DsVeosCoSim_Handle Type.
-

Return values

-

This function has no return values.

-

DsVeosCoSim_Disconnect Function

-

Description

-

Disconnects the VEOS CoSim client from the VEOS CoSim server.

-

If there is no connection to the VEOS CoSim server, the DsVeosCoSim_Disconnect function does not do or return anything.

-

If the connection is closed during a running simulation, the simulation terminates with an error.

-

Syntax

-
DSVEOSCOSIM_DECL DsVeosCoSim_Result DsVeosCoSim_Disconnect( - DsVeosCoSim_Handle handle -); -
-

Parameters

- - - - - - - - - - - - - -
NameDescription
handleThe handle of the VEOS CoSim client. Refer to DsVeosCoSim_Handle Type.
-

Return values

-

Refer to DsVeosCoSim_Result Enumeration.

-

DsVeosCoSim_EthMessageReceivedCallback Function Pointer

-

Description

-

Called when a new Ethernet message is received from the VEOS CoSim server.

-

VeosCoSim_EthMessageReceivedCallback can be registered with the DsVeosCoSim_SetCallbacks Function.

-

Note: -If the DsVeosCoSim_EthMessageReceivedCallback is registered, you cannot collect Ethernet messages using the -DsVeosCoSim_ReceiveEthMessage Function.

-

However, if the callback is not registered, each received message is buffered. Currently, the buffer size is 512 messages. If the buffer is full, new messages -are discarded.

-

Syntax

-
typedef void (*DsVeosCoSim_EthMessageReceivedCallback)( - DsVeosCoSim_SimulationTime simulationTime, - const DsVeosCoSim_EthController* ethController, - const DsVeosCoSim_EthMessage* message, - void* userData -); -
-

Parameters

- - - - - - - - - - - - - - - - - - - - - - - - - -
NameDescription
simulationTimeThe current simulation time. Refer to DsVeosCoSim_SimulationTime Type.
ethControllerThe Ethernet controller that sent the message. Refer to DsVeosCoSim_EthController Structure.
messageA pointer to the received Ethernet message. Refer to DsVeosCoSim_EthMessage Structure.
userDataThe user data passed to the co-simulation function via the DsVeosCoSim_SetCallbacks Function. Can be NULL.
-

Return values

-

This function has no return values.

-

DsVeosCoSim_FinishCommand Function

-

Description

-

Can be used to ensure that a command in a polling-based simulation has finished.

-

Syntax

-
DSVEOSCOSIM_DECL DsVeosCoSim_Result DsVeosCoSim_FinishCommand( - DsVeosCoSim_Handle handle -); -
-

Parameters

- - - - - - - - - - - - - -
NameDescription
handleThe handle of the VEOS CoSim client. Refer to DsVeosCoSim_Handle Type.
-

Return values

-

Refer to DsVeosCoSim_Result Enumeration.

-

DsVeosCoSim_GetCanControllers Function

-

Description

-

Gets all available CAN controllers in the co-simulation.

-

Syntax

-
DSVEOSCOSIM_DECL DsVeosCoSim_Result DsVeosCoSim_GetCanControllers( - DsVeosCoSim_Handle handle, - uint32_t* canControllersCount, - const DsVeosCoSim_CanController** canControllers -); -
-

Parameters

- - - - - - - - - - - - - - - - - - - - - -
NameDescription
handleThe handle of the VEOS CoSim client. Refer to DsVeosCoSim_Handle Type.
canControllersCountA pointer to the counter of CAN controllers.
canControllersA pointer to the array of CAN controllers. Refer to DsVeosCoSim_CanController Structure.
-

Return values

-

Refer to DsVeosCoSim_Result Enumeration.

-

DsVeosCoSim_GetConnectionState Function

-

Description

-

Gets the connection state for a given client handle.

-

Syntax

-
DSVEOSCOSIM_DECL DsVeosCoSim_Result DsVeosCoSim_GetConnectionState( - DsVeosCoSim_Handle handle, - DsVeosCoSim_ConnectionState* connectionState -); -
-

Parameters

- - - - - - - - - - - - - - - - - -
NameDescription
handleThe handle of the VEOS CoSim client. Refer to DsVeosCoSim_Handle Type.
connectionStateThe connection state. Refer to DsVeosCoSim_ConnectionState Enumeration.
-

Return values

-

Refer to DsVeosCoSim_Result Enumeration.

-

DsVeosCoSim_GetEthControllers Function

-

Description

-

Gets all available Ethernet controllers in the co-simulation.

-

Syntax

-
DSVEOSCOSIM_DECL DsVeosCoSim_Result DsVeosCoSim_GetEthControllers( - DsVeosCoSim_Handle handle, - uint32_t* ethControllersCount, - const DsVeosCoSim_EthController** ethControllers -); -
-

Parameters

- - - - - - - - - - - - - - - - - - - - - -
NameDescription
handleThe handle of the VEOS CoSim client. Refer to DsVeosCoSim_Handle Type.
ethControllersCountA pointer to the counter of Ethernet controllers.
ethControllersA pointer to the array of Ethernet controllers. Refer to DsVeosCoSim_EthController Structure.
-

Return values

-

Refer to DsVeosCoSim_Result Enumeration.

-

DsVeosCoSim_GetIncomingSignals Function

-

Description

-

Gets all available incoming signals.

-

Syntax

-
DSVEOSCOSIM_DECL DsVeosCoSim_Result DsVeosCoSim_GetIncomingSignals( - DsVeosCoSim_Handle handle, - uint32_t* incomingSignalsCount, - const DsVeosCoSim_IoSignal** incomingSignals -); -
-

Parameters

- - - - - - - - - - - - - - - - - - - - - -
NameDescription
handleThe handle of the VEOS CoSim client. Refer to DsVeosCoSim_Handle Type.
incomingSignalsCountA pointer to the counter of incoming signals.
incomingSignalsA pointer to the array of incoming signals. Refer to DsVeosCoSim_IoSignal Structure
-

Return values

-

Refer to DsVeosCoSim_Result Enumeration.

-

DsVeosCoSim_GetLinControllers Function

-

Description

-

Gets all available LIN controllers in the co-simulation.

-

Syntax

-
DSVEOSCOSIM_DECL DsVeosCoSim_Result DsVeosCoSim_GetLinControllers( - DsVeosCoSim_Handle handle, - uint32_t* linControllersCount, - const DsVeosCoSim_LinController** linControllers -); -
-

Parameters

- - - - - - - - - - - - - - - - - - - - - -
NameDescription
handleThe handle of the VEOS CoSim client. Refer to DsVeosCoSim_Handle Type.
linControllersCountA pointer to the counter of LIN controllers.
linControllersA pointer to the array of LIN controllers. Refer to DsVeosCoSim_LinController Structure.
-

Return values

-

Refer to DsVeosCoSim_Result Enumeration.

-

DsVeosCoSim_GetOutgoingSignals Function

-

Description

-

Gets all available outgoing signals.

-

Syntax

-
DSVEOSCOSIM_DECL DsVeosCoSim_Result DsVeosCoSim_GetOutgoingSignals( - DsVeosCoSim_Handle handle, - uint32_t* outgoingSignalsCount, - const DsVeosCoSim_IoSignal** outgoingSignals -); -
-

Parameters

- - - - - - - - - - - - - - - - - - - - - -
NameDescription
handleThe handle of the VEOS CoSim client. Refer to DsVeosCoSim_Handle Type.
outgoingSignalsCountA pointer to the counter of outgoing signals.
outgoingSignalsA pointer to the array of outgoing signals. Refer to DsVeosCoSim_IoSignal Structure.
-

Return values

-

Refer to DsVeosCoSim_Result Enumeration.

-

DsVeosCoSim_IncomingSignalChangedCallback Function Pointer

-

Description

-

Called when the value of an incoming I/O signal has changed.

-

Syntax

-
typedef void (*DsVeosCoSim_IncomingSignalChangedCallback)( - DsVeosCoSim_SimulationTime simulationTime, - const DsVeosCoSim_IoSignal* ioSignal, - uint32_t length, - const void* value, - void* userData -); -
-

Parameters

- - - - - - - - - - - - - - - - - - - - - - - - - -
NameDescription
simulationTimeThe current simulation time. Refer to DsVeosCoSim_SimulationTime Type.
ioSignalThe ID of the I/O signal that changed its value. Refer to DsVeosCoSim_IoSignalId Type.
valueA pointer to the current value of the I/O signal.
userDataThe user data passed via the DsVeosCoSim_SetCallbacks function. Refer to DsVeosCoSim_SetCallbacks Function.
-

Return values

-

This function has no return values.

-

DsVeosCoSim_LinMessageReceivedCallback Function Pointer

-

Description

-

Called when a new LIN message is received from the VEOS CoSim server.

-

DsVeosCoSim_LinMessageReceivedCallback can be registered with DsVeosCoSim_SetCallbacks Function.

-

Note: -If DsVeosCoSim_LinMessageReceivedCallback is registered, you cannot collect LIN messages using DsVeosCoSim_ReceiveLinMessage Function.

-

However, if the callback is not registered, each received message is buffered. Currently, the buffer size is 512 messages. If the buffer is full, new messages -are discarded.

-

Syntax

-
typedef void (*DsVeosCoSim_LinMessageReceivedCallback)( - DsVeosCoSim_SimulationTime simulationTime, - const DsVeosCoSim_LinController* linController, - const DsVeosCoSim_LinMessage* message, - void* userData -); -
-

Parameters

- - - - - - - - - - - - - - - - - - - - - - - - - -
NameDescription
simulationTimeThe current simulation time. Refer to DsVeosCoSim_SimulationTime Type.
linControllerThe LIN controller transmitting the message. Refer to DsVeosCoSim_LinController Structure.
messageA pointer to the received LIN message. Refer to DsVeosCoSim_LinMessage Structure.
userDataThe user data passed to the co-simulation function via the DsVeosCoSim_SetCallbacks Function. Can be NULL.
-

Return values

-

This function has no return values.

-

DsVeosCoSim_LogCallback Function Pointer

-

Description

-

Called each time the dSPACE VEOS CoSim client receives a log message.

-

You can register the DsVeosCoSim_LogCallback function pointer using the DsVeosCoSim_SetLogCallback Function.

-

Syntax

-
typedef void (*DsVeosCoSim_LogCallback)( - DsVeosCoSim_Severity severity, - const char* logMessage -); -
-

Parameters

- - - - - - - - - - - - - - - - - -
NameDescription
severityThe severity of the message. Refer to DsVeosCoSim_Severity Enumeration.
logMessageThe log message content.
-

Return values

-

This function has no return values.

-

DsVeosCoSim_PollCommand Function

-

Description

-

Polls the simulator for a command.

-

Syntax

-
DSVEOSCOSIM_DECL DsVeosCoSim_Result DsVeosCoSim_PollCommand( - DsVeosCoSim_Handle handle, - DsVeosCoSim_SimulationTime* simulationTime, - DsVeosCoSim_Command* command -); -
-

Parameters

- - - - - - - - - - - - - - - - - - - - - -
NameDescription
handleThe handle of the VEOS CoSim client. Refer to DsVeosCoSim_Handle Type.
simulationTimeThe current simulation time. Refer to DsVeosCoSim_SimulationTime Type.
commandThe received command. Refer to DsVeosCoSim_Command Enumeration.
-

Return values

-

Refer to DsVeosCoSim_Result Enumeration.

-

DsVeosCoSim_ReadIncomingSignal Function

-

Description

-

Reads a value from an incoming signal of the VEOS CoSim server identified by the given handle.

-

Syntax

-
DSVEOSCOSIM_DECL DsVeosCoSim_Result DsVeosCoSim_ReadIncomingSignal( - DsVeosCoSim_Handle handle, - DsVeosCoSim_IoSignalId incomingSignalId, - uint32_t* length, - void* value -); -
-

Parameters

- - - - - - - - - - - - - - - - - - - - - - - - - -
NameDescription
handleThe handle of the VEOS CoSim client. Refer to DsVeosCoSim_Handle Type.
incomingSignalIdThe ID of the incoming signal. Refer to DsVeosCoSim_IoSignalId Type.
lengthThe length of the incoming signal value.
valueThe value of the incoming signal.
-

Return values

-

Refer to DsVeosCoSim_Result Enumeration.

-

DsVeosCoSim_ReceiveCanMessage Function

-

Description

-

Receives a CAN message from the VEOS CoSim server.

-

Note: -If the DsVeosCoSim_CanMessageReceivedCallback Function Pointer is registered, you cannot collect CAN messages using -the DsVeosCoSim_ReceiveCanMessage function.

-

Syntax

-
DSVEOSCOSIM_DECL DsVeosCoSim_Result DsVeosCoSim_ReceiveCanMessage( - DsVeosCoSim_Handle handle, - DsVeosCoSim_CanMessage* message -); -
-

Parameters

- - - - - - - - - - - - - - - - - -
NameDescription
handleThe handle of the VEOS CoSim client. Refer to DsVeosCoSim_Handle Type.
messageA pointer to the received CAN message. Refer to DsVeosCoSim_CanMessage Structure.
-

Return values

-

Refer to DsVeosCoSim_Result Enumeration.

-

DsVeosCoSim_ReceiveEthMessage Function

-

Description

-

Receives an Ethernet message from the VEOS CoSim server.

-

Note: -If the [DsVeosCoSim_EthMessageReceivedCallback Function Pointer](#dsveoscosim_ethmessagereceivedcallback-function pointer) is registered, you cannot collect Ethernet messages -using the DsVeosCoSim_ReceiveEthMessage function.

-

Syntax

-
DSVEOSCOSIM_DECL DsVeosCoSim_Result DsVeosCoSim_ReceiveEthMessage( - DsVeosCoSim_Handle handle, - DsVeosCoSim_EthMessage* message -); -
-

Parameters

- - - - - - - - - - - - - - - - - -
NameDescription
handleThe handle of the VEOS CoSim client. Refer to DsVeosCoSim_Handle Type.
messageA pointer to the Ethernet message. Refer to DsVeosCoSim_EthMessage Structure.
-

Return values

-

Refer to DsVeosCoSim_Result Enumeration.

-

DsVeosCoSim_ReceiveLinMessage Function

-

Description

-

Receives a LIN message from the VEOS CoSim server.

-

Note: -If the DsVeosCoSim_LinMessageReceivedCallback Function Pointer is registered, you cannot collect LIN messages using -the DsVeosCoSim_ReceiveLinMessage function.

-

Syntax

-
DSVEOSCOSIM_DECL DsVeosCoSim_Result DsVeosCoSim_ReceiveLinMessage( - DsVeosCoSim_Handle handle, - DsVeosCoSim_LinMessage* message -); -
-

Parameters

- - - - - - - - - - - - - - - - - -
NameDescription
handleThe handle of the VEOS CoSim client. Refer to DsVeosCoSim_Handle Type.
messageA pointer to the LIN message. Refer to DsVeosCoSim_LinMessage Structure.
-

Return values

-

Refer to DsVeosCoSim_Result Enumeration.

-

DsVeosCoSim_RunCallbackBasedCoSimulation Function

-

Description

-

Starts a callback-based co-simulation.

-

Syntax

-
DSVEOSCOSIM_DECL DsVeosCoSim_Result DsVeosCoSim_RunCallbackBasedCoSimulation( - DsVeosCoSim_Handle handle, - DsVeosCoSim_Callbacks callbacks -); -
-

Parameters

- - - - - - - - - - - - - - - - - -
NameDescription
handleThe handle of the VEOS CoSim client. Refer to DsVeosCoSim_Handle Type.
callbacksThe callbacks to be set. Refer to DsVeosCoSim_Callbacks Structure.
-

Return values

-

Refer to DsVeosCoSim_Result Enumeration.

-

DsVeosCoSim_SetCallbacks Function

-

Description

-

Sets the callbacks for the VEOS CoSim client specified via the handle.

-

Syntax

-
DSVEOSCOSIM_DECL DsVeosCoSim_Result DsVeosCoSim_SetCallbacks( - DsVeosCoSim_Handle handle, - DsVeosCoSim_Callbacks callbacks -); -
-

Parameters

- - - - - - - - - - - - - - - - - -
NameDescription
handleThe handle of the VEOS CoSim client. Refer to DsVeosCoSim_Handle Type.
callbacksThe callbacks to be set. Refer to DsVeosCoSim_Callbacks Structure.
-

Return values

-

Refer to DsVeosCoSim_Result Enumeration.

-

DsVeosCoSim_SetLogCallback Function

-

Description

-

Specifies the log callback function.

-

Syntax

-
DSVEOSCOSIM_DECL void DsVeosCoSim_SetLogCallback( - DsVeosCoSim_LogCallback logCallback -); -
-

Parameters

- - - - - - - - - - - - - -
NameDescription
logCallbackThe log callback to which log messages will be sent. Refer to DsVeosCoSim_LogCallback Function Pointer.
-

Return values

-

This function has no return values.

-

DsVeosCoSim_SetNextSimulationTime Function

-

Description

-

Sets the next simulation time for the given client handle.

-

Syntax

-
DSVEOSCOSIM_DECL DsVeosCoSim_Result DsVeosCoSim_SetNextSimulationTime( - DsVeosCoSim_Handle handle, - DsVeosCoSim_SimulationTime simulationTime -); -
-

Parameters

- - - - - - - - - - - - - - - - - -
NameDescription
handleThe handle of the VEOS CoSim client. Refer to DsVeosCoSim_Handle Type.
simulationTimeThe next simulation time. Refer to DsVeosCoSim_SimulationTime Type.
-

Return values

-

Refer to DsVeosCoSim_Result Enumeration.

-

DsVeosCoSim_SimulationCallback Function Pointer

-

Description

-

A generic simulation callback function pointer.

-

Syntax

-
typedef void (*DsVeosCoSim_SimulationCallback)( - DsVeosCoSim_SimulationTime simulationTime, - void* userData -); -
-

Parameters

- - - - - - - - - - - - - - - - - -
NameDescription
simulationTimeThe current simulation time. Refer to DsVeosCoSim_SimulationTime Type.
userDataThe user data passed to the co-simulation function via the DsVeosCoSim_SetCallbacks Function. Can be NULL.
-

Return values

-

This function has no return values.

-

DsVeosCoSim_SimulationTerminatedCallback Function Pointer

-

Description

-

Called when a simulation is terminated.

-

Syntax

-
typedef void (*DsVeosCoSim_SimulationTerminatedCallback)( - DsVeosCoSim_SimulationTime simulationTime, - DsVeosCoSim_TerminateReason reason, - void* userData -); -
-

Parameters

- - - - - - - - - - - - - - - - - - - - - -
NameDescription
simulationTimeThe current simulation time. Refer to DsVeosCoSim_SimulationTime Type.
reasonThe reason for the termination. Refer to DsVeosCoSim_TerminateReason Enumeration.
userDataThe user data passed to the co-simulation function via the DsVeosCoSim_SetCallbacks Function. Can be NULL.
-

Return values

-

This function has no return values.

-

DsVeosCoSim_StartPollingBasedCoSimulation Function

-

Description

-

Starts a co-simulation in non-blocking mode.

-

Syntax

-
DSVEOSCOSIM_DECL DsVeosCoSim_Result DsVeosCoSim_StartPollingBasedCoSimulation( - DsVeosCoSim_Handle handle, - DsVeosCoSim_Callbacks callbacks -); -
-

Parameters

- - - - - - - - - - - - - - - - - -
NameDescription
handleThe handle of the VEOS CoSim client. Refer to DsVeosCoSim_Handle Type.
callbacksThe callbacks to be set. Refer to DsVeosCoSim_Callbacks Structure.
-

Return values

-

Refer to DsVeosCoSim_Result Enumeration.

-

DsVeosCoSim_TransmitCanMessage Function

-

Description

-

Transmits a CAN message to the VEOS CoSim server.

-

The DsVeosCoSim_TransmitCanMessage function can be called in any callback handler. The timestamp property of transmission bus messages will be ignored.

-

Note: -Currently, the DsVeosCoSim client cannot buffer more than 512 bus messages for each bus controller. If the buffer is full, the DsVeosCoSim_TransmitCanMessage -function returns DsVeosCoSim_Result_Full.

-

Syntax

-
DSVEOSCOSIM_DECL DsVeosCoSim_Result DsVeosCoSim_TransmitCanMessage( - DsVeosCoSim_Handle handle, - const DsVeosCoSim_CanMessage* message -); -
-

Parameters

- - - - - - - - - - - - - - - - - -
NameDescription
handleThe handle of the VEOS CoSim client. Refer to DsVeosCoSim_Handle Type.
messageA pointer to a CAN message to be transmitted. Refer to DsVeosCoSim_CanMessage Structure.
-

Return values

-

Refer to DsVeosCoSim_Result Enumeration.

-

DsVeosCoSim_TransmitEthMessage Function

-

Description

-

Transmits an Ethernet message to the VEOS CoSim server.

-

The DsVeosCoSim_TransmitEthMessage function can be called in any callback handler. The timestamp property of transmission messages will be ignored.

-

Note: -Currently, the DsVeosCoSim client cannot buffer more than 512 bus messages for each bus controller. If the buffer is full, the DsVeosCoSim_TransmitEthMessage -function returns DsVeosCoSim_Result_Full.

-

Syntax

-
DSVEOSCOSIM_DECL DsVeosCoSim_Result DsVeosCoSim_TransmitEthMessage( - DsVeosCoSim_Handle handle, - const DsVeosCoSim_EthMessage* message -); -
-

Parameters

- - - - - - - - - - - - - - - - - -
NameDescription
handleThe handle of the VEOS CoSim client. Refer to DsVeosCoSim_Handle Type.
messageA pointer to an Ethernet message to be transmitted. Refer to DsVeosCoSim_EthMessage Structure.
-

Return values

-

Refer to DsVeosCoSim_Result Enumeration.

-

DsVeosCoSim_TransmitLinMessage Function

-

Description

-

Transmits a LIN message to the VEOS CoSim server.

-

The DsVeosCoSim_TransmitLinMessage function can be called in any callback handler. The timestamp property of transmitted bus messages will be ignored.

-

Note: -Currently, the VEOS CoSim client cannot buffer more than 512 bus messages for each bus controller. If the buffer is full, the DsVeosCoSim_TransmitLinMessage -function returns DsVeosCoSim_Result_Full.

-

Syntax

-
DSVEOSCOSIM_DECL DsVeosCoSim_Result DsVeosCoSim_TransmitLinMessage( - DsVeosCoSim_Handle handle, - const DsVeosCoSim_LinMessage* message -); -
-

Parameters

- - - - - - - - - - - - - - - - - -
NameDescription
handleThe handle of the VEOS CoSim client. Refer to DsVeosCoSim_Handle Type.
messageA pointer to the LIN message to be transmitted. Refer to DsVeosCoSim_LinMessage Structure.
-

Return values

-

Refer to DsVeosCoSim_Result Enumeration.

-

DsVeosCoSim_WriteOutgoingSignal Function

-

Description

-

Writes a value to an outgoing signal of the VEOS CoSim server identified by the given handle.

-

Syntax

-
DSVEOSCOSIM_DECL DsVeosCoSim_Result DsVeosCoSim_WriteOutgoingSignal( - DsVeosCoSim_Handle handle, - DsVeosCoSim_IoSignalId outgoingSignalId, - uint32_t length, - const void* value -); -
-

Parameters

- - - - - - - - - - - - - - - - - - - - - - - - - -
NameDescription
handleThe handle of the VEOS CoSim client. Refer to DsVeosCoSim_Handle Type.
outgoingSignalIdThe ID of the outgoing signal. Refer to DsVeosCoSim_IoSignalId Type.
lengthThe length of the value to write.
valueThe value to write.
-

Return values

-

Refer to DsVeosCoSim_Result Enumeration.

-

Structures

-

DsVeosCoSim_Callbacks Structure

-

Description

-

Contains the callbacks that can be called during the co-simulation.

-

Syntax

-
typedef struct DsVeosCoSim_Callbacks { - DsVeosCoSim_SimulationCallback simulationStartedCallback; - DsVeosCoSim_SimulationCallback simulationStoppedCallback; - DsVeosCoSim_SimulationTerminatedCallback simulationTerminatedCallback; - DsVeosCoSim_SimulationCallback simulationPausedCallback; - DsVeosCoSim_SimulationCallback simulationContinuedCallback; - DsVeosCoSim_SimulationCallback simulationBeginStepCallback; - DsVeosCoSim_SimulationCallback simulationEndStepCallback; - DsVeosCoSim_IncomingSignalChangedCallback incomingSignalChangedCallback; - DsVeosCoSim_CanMessageReceivedCallback canMessageReceivedCallback; - DsVeosCoSim_EthMessageReceivedCallback ethMessageReceivedCallback; - DsVeosCoSim_LinMessageReceivedCallback linMessageReceivedCallback; - void* userData; -} DsVeosCoSim_Callbacks; -
-

Members

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameDescription
simulationStartedCallbackCalled when the simulation is started in VEOS. Refer to DsVeosCoSim_SimulationCallback Function Pointer.
simulationStoppedCallbackCalled when the simulation is stopped in VEOS. Refer to DsVeosCoSim_SimulationCallback Function Pointer.
simulationTerminatedCallbackCalled when the simulation is terminated in VEOS. Refer to DsVeosCoSim_SimulationTerminatedCallback Function Pointer.
simulationPausedCallbackCalled when the simulation is paused in VEOS. Refer to DsVeosCoSim_SimulationCallback Function Pointer.
simulationContinuedCallbackCalled when the simulation is continued in VEOS. Refer to DsVeosCoSim_SimulationCallback Function Pointer.
simulationBeginStepCallbackCalled at the beginning of a simulation step. Refer to DsVeosCoSim_SimulationCallback Function Pointer.
simulationEndStepCallbackCalled at the end of a simulation step. Refer to DsVeosCoSim_SimulationCallback Function Pointer.
incomingSignalChangedCallbackCalled when an incoming signal value has changed. Refer to DsVeosCoSim_IncomingSignalChangedCallback Function Pointer.
canMessageReceivedCallbackCalled when a CAN message is received from the VEOS CoSim server. Refer to DsVeosCoSim_CanMessageReceivedCallback Function Pointer.
ethMessageReceivedCallbackCalled when an Ethernet message is received from the VEOS CoSim server. Refer to DsVeosCoSim_EthMessageReceivedCallback Function Pointer.
linMessageReceivedCallbackCalled when a LIN message is received from the VEOS CoSim server. Refer to DsVeosCoSim_LinMessageReceivedCallback Function Pointer.
userDataArbitrary user data to be passed to the VEOS CoSim server.
-

DsVeosCoSim_CanController Structure

-

Description

-

Represents a CAN controller.

-

Syntax

-
typedef struct DsVeosCoSim_CanController { - DsVeosCoSim_BusControllerId id; - uint32_t queueSize; - uint64_t bitsPerSecond; - uint64_t flexibleDataRateBitsPerSecond; - const char* name; - const char* channelName; - const char* clusterName; -} DsVeosCoSim_CanController; -
-

Members

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameDescription
idThe unique identifier of the CAN controller. Refer to DsVeosCoSim_BusControllerId Type.
queueSizeThe maximum queue size of the CAN controller.
bitsPerSecondThe baud rate of the CAN controller.
flexibleDataRateBitsPerSecondThe baud rate for CAN FD.
nameThe name of the CAN controller.
channelNameThe name of the CAN channel to use.
clusterNameThe name of the CAN cluster to which the CAN controller is connected.
-

DsVeosCoSim_CanMessage Structure

-

Description

-

Contains information on a CAN message.

-

Syntax

-
typedef struct DsVeosCoSim_CanMessage { - DsVeosCoSim_SimulationTime timestamp; - DsVeosCoSim_BusControllerId controllerId; - uint32_t id; - DsVeosCoSim_CanMessageFlags flags; - uint32_t length; - uint8_t* data; -} DsVeosCoSim_CanMessage; -
-

Members

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameDescription
timestampContains the virtual simulation time at which the CAN message was received. Only for received messages. Refer to DsVeosCoSim_SimulationTime Type.
controllerIdThe ID of the CAN controller over which the CAN message was sent. Refer to DsVeosCoSim_BusControllerId Type.
idThe CAN message ID.
flagsThe flags of the CAN message. Refer to DsVeosCoSim_CanMessageFlags Enumeration.
lengthThe length of the CAN message payload in bytes.
dataThe CAN message payload.
-

DsVeosCoSim_ConnectConfig Structure

-

Description

-

Contains the data that is required for establishing a connection to the VEOS CoSim server.

-

Syntax

-
typedef struct DsVeosCoSim_ConnectConfig { - const char* remoteIpAddress; - const char* serverName; - const char* clientName; - uint16_t remotePort; - uint16_t localPort; -} DsVeosCoSim_ConnectConfig; -
-

Members

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameDescription
remoteIpAddressThe IP address of the VEOS CoSim server. If not specified, this is set to 127.0.0.1.
serverNameThe name of the VEOS CoSim server. If this is not specified, the remotePort is required to establish the connection.
clientNameThe name of the VEOS CoSim Client.
remotePortThe TCP port of the VEOS CoSim server. If this is not specified, the serverName must be given.
localPortThe port of the VEOS CoSim client. Only change this value if tunneled communication is required.
-

DsVeosCoSim_EthController Structure

-

Description

-

Represents an Ethernet controller.

-

Syntax

-
typedef struct DsVeosCoSim_EthController { - DsVeosCoSim_BusControllerId id; - uint32_t queueSize; - uint64_t bitsPerSecond; - uint8_t macAddress[DSVEOSCOSIM_ETH_ADDRESS_LENGTH]; - const char* name; - const char* channelName; - const char* clusterName; -} DsVeosCoSim_EthController; -
-

Members

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameDescription
idThe unique identifier of the Ethernet controller. Refer to DsVeosCoSim_BusControllerId Type.
queueSizeThe maximum queue size of the Ethernet controller.
bitsPerSecondThe baud rate of the Ethernet controller.
macAddressThe MAC address of the Ethernet controller.
nameThe name of the Ethernet controller.
channelNameThe name of the Ethernet channel to use.
clusterNameThe name of the Ethernet cluster to which the Ethernet controller is connected.
-

DsVeosCoSim_EthMessage Structure

-

Description

-

Contains information on an Ethernet message.

-

Syntax

-
typedef struct DsVeosCoSim_EthMessage { - DsVeosCoSim_SimulationTime timestamp; - DsVeosCoSim_BusControllerId controllerId; - uint32_t reserved; - DsVeosCoSim_EthMessageFlags flags; - uint32_t length; - const uint8_t* data; -} DsVeosCoSim_EthMessage; -
-

Members

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameDescription
timestampContains the virtual simulation time at which the Ethernet message was received. Refer to DsVeosCoSim_SimulationTime Type.
controllerIdThe ID of the Ethernet controller over which the Ethernet message was sent. Refer to DsVeosCoSim_BusControllerId Type.
reservedReserved for future use.
flagsThe flags of the Ethernet message. Refer to DsVeosCoSim_EthMessageFlags Enumeration.
lengthThe length of the Ethernet message payload in bytes.
dataThe Ethernet message payload.
-

DsVeosCoSim_IoSignal Structure

-

Description

-

Contains information on an I/O signal.

-

Syntax

-
typedef struct DsVeosCoSim_IoSignal { - DsVeosCoSim_IoSignalId id; - uint32_t length; - DsVeosCoSim_DataType dataType; - DsVeosCoSim_SizeKind sizeKind; - const char* name; -} DsVeosCoSim_IoSignal; -
-

Members

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameDescription
idThe unique identifier of the I/O signal. Refer to DsVeosCoSim_IoSignalId Type.
lengthThe exact length of the I/O signal if it is of fixed length or the maximum length if it is of variable size.
dataTypeThe data type of the I/O signal. Refer to DsVeosCoSim_DataType Enumeration.
sizeKindThe size kind of the the I/O signal, i.e., variable or fixed length. Refer to DsVeosCoSim_SizeKind Enumeration.
nameThe name of the I/O signal.
-

DsVeosCoSim_LinController Structure

-

Description

-

Represents a LIN controller.

-

Syntax

-
typedef struct DsVeosCoSim_LinController { - DsVeosCoSim_BusControllerId id; - uint32_t queueSize; - uint64_t bitsPerSecond; - DsVeosCoSim_LinControllerType type; - const char* name; - const char* channelName; - const char* clusterName; -} DsVeosCoSim_LinController; -
-

Members

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameDescription
idThe unique identifier of the LIN controller. Refer to DsVeosCoSim_BusControllerId Type.
queueSizeThe maximum queue size of the LIN controller.
bitsPerSecondThe baud rate of the LIN controller.
typeThe LIN controller type. Refer to DsVeosCoSim_LinControllerType Enumeration.
nameThe name of the LIN controller.
channelNameThe name of the LIN channel to use.
clusterNameThe name of the LIN cluster to which the LIN controller is connected.
-

DsVeosCoSim_LinMessage Structure

-

Description

-

Contains information on a LIN message.

-

Syntax

-
typedef struct DsVeosCoSim_LinMessage { - DsVeosCoSim_SimulationTime timestamp; - DsVeosCoSim_BusControllerId controllerId; - uint32_t id; - DsVeosCoSim_LinMessageFlags flags; - uint32_t length; - const uint8_t* data; -} DsVeosCoSim_LinMessage; -
-

Members

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameDescription
timestampContains the virtual simulation time at which the LIN message was received. Only for received messages. Refer to DsVeosCoSim_SimulationTime Type.
controllerIdThe ID of the LIN controller over which the LIN message was sent. Refer to DsVeosCoSim_BusControllerId Type.
idThe LIN message ID.
flagsThe flags of the LIN message. Refer to DsVeosCoSim_LinMessageFlags Enumeration.
lengthThe length of the LIN message payload in bytes.
dataThe LIN message payload.
-

Simple Types

-

DsVeosCoSim_BusControllerId Type

-

Description

-

Represents a bus controller ID.

-

Syntax

-
typedef uint32_t DsVeosCoSim_BusControllerId; -
-

DsVeosCoSim_Handle Type

-

Description

-

A handle to represent the VEOS CoSim client.

-

Syntax

-
typedef void* DsVeosCoSim_Handle; -
-

DsVeosCoSim_IoSignalId Type

-

Description

-

Represents an I/O signal ID.

-

Syntax

-
typedef uint32_t DsVeosCoSim_IoSignalId; -
-

DsVeosCoSim_SimulationTime Type

-

Description

-

Represents the simulation time in nanoseconds.

-

Divide by DSVEOSCOSIM_SIMULATION_TIME_RESOLUTION_PER_SECOND to get the simulation time in seconds.

-

Syntax

-
typedef int64_t DsVeosCoSim_SimulationTime; -
-

Macros

-

Description

-

The DsVeosCoSim.h file contains a number of macro definitions which are listed in the table below.

-

Table of macros

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
MacroDescription
DSVEOSCOSIM_SIMULATION_TIME_RESOLUTION_PER_SECOND 1e9Defines the conversion factor between DsVeosCoSim_SimulationTime and seconds. The data type is double.
DSVEOSCOSIM_SIMULATION_TIME_TO_SECONDS(simulationTime) ((double) (simulationTime) / DSVEOSCOSIM_SIMULATION_TIME_RESOLUTION_PER_SECOND)Converts the given simulation time to seconds. The resulting data type is double.
DSVEOSCOSIM_CAN_MESSAGE_MAX_LENGTH 64Defines the maximum length of a CAN message payload.
DSVEOSCOSIM_ETH_MESSAGE_MAX_LENGTH 9018Defines the maximum length of an Ethernet message payload.
DSVEOSCOSIM_LIN_MESSAGE_MAX_LENGTH 8Defines the maximum length of a LIN message payload.
DSVEOSCOSIM_ETH_ADDRESS_LENGTH 6Defines the MAC address length of an Ethernet controller.
- - - diff --git a/doc/documentation.md b/doc/documentation.md index 4c846e3..89cf22e 100644 --- a/doc/documentation.md +++ b/doc/documentation.md @@ -390,11 +390,11 @@ You can work with the demo on Windows and Ubuntu 20.04 LTS. Additionally, you must have the following: -- CMake 3.13 or higher +- CMake 3.15 or higher - Either of the following compilers: - - GCC 10 or higher + - GCC 7 or higher - MSVC 2022 or higher diff --git a/shared/Generator.cpp b/shared/Generator.cpp index 934d7fe..0050c35 100644 --- a/shared/Generator.cpp +++ b/shared/Generator.cpp @@ -3,6 +3,7 @@ #include "Generator.h" #include + #include #include diff --git a/shared/Helper.cpp b/shared/Helper.cpp index 2efb49c..6fc1fd1 100644 --- a/shared/Helper.cpp +++ b/shared/Helper.cpp @@ -15,9 +15,10 @@ #include #include #else -#include #include #include + +#include #endif using namespace DsVeosCoSim; diff --git a/shared/LogHelper.cpp b/shared/LogHelper.cpp index cb22756..c390afd 100644 --- a/shared/LogHelper.cpp +++ b/shared/LogHelper.cpp @@ -3,6 +3,7 @@ #include "LogHelper.h" #include + #include #include "CoSimHelper.h" diff --git a/shared/LogHelper.h b/shared/LogHelper.h index 27535ee..2f79bb4 100644 --- a/shared/LogHelper.h +++ b/shared/LogHelper.h @@ -3,6 +3,7 @@ #pragma once #include + #include #include diff --git a/src/CoSimClient.h b/src/CoSimClient.h index b0cf39f..3f96b08 100644 --- a/src/CoSimClient.h +++ b/src/CoSimClient.h @@ -123,7 +123,7 @@ class CoSimClient final { ResponderMode _responderMode{}; Command _currentCommand{}; - std::atomic _nextCommand; + std::atomic _nextCommand{}; std::vector _incomingSignals; std::vector _outgoingSignals; diff --git a/src/CoSimTypes.h b/src/CoSimTypes.h index 52f50e6..1252ce7 100644 --- a/src/CoSimTypes.h +++ b/src/CoSimTypes.h @@ -447,8 +447,8 @@ enum class Mode { const DsVeosCoSim_IoSignal& ioSignal, uint32_t length, const void* value) { - return DsVeosCoSim_SimulationTimeToString(simulationTime) + "," + ioSignal.name + "," + - std::to_string(length) + "," + DsVeosCoSim_ValueToString(ioSignal.dataType, length, value); + return DsVeosCoSim_SimulationTimeToString(simulationTime) + "," + ioSignal.name + "," + std::to_string(length) + + "," + DsVeosCoSim_ValueToString(ioSignal.dataType, length, value); } struct IoSignal { @@ -588,15 +588,13 @@ struct CanController { const std::string macAddress2 = DataToString(message.data + 6, 6, ':'); const std::string ethernetType = DataToString(message.data + 12, 2); - return DsVeosCoSim_SimulationTimeToString(simulationTime) + "," + controller.name + "," + - macAddress2 + "-" + macAddress1 + "," + std::to_string(length - 14) + "," + - DataToString(data + 14, length - 14, '-') + ",ETH," + ethernetType + "," + - EthMessageFlagsToString(message.flags); + return DsVeosCoSim_SimulationTimeToString(simulationTime) + "," + controller.name + "," + macAddress2 + "-" + + macAddress1 + "," + std::to_string(length - 14) + "," + DataToString(data + 14, length - 14, '-') + + ",ETH," + ethernetType + "," + EthMessageFlagsToString(message.flags); } - return DsVeosCoSim_SimulationTimeToString(simulationTime) + "," + controller.name + "," + - std::to_string(length) + "," + DataToString(data, length, '-') + ",ETH," + - EthMessageFlagsToString(message.flags); + return DsVeosCoSim_SimulationTimeToString(simulationTime) + "," + controller.name + "," + std::to_string(length) + + "," + DataToString(data, length, '-') + ",ETH," + EthMessageFlagsToString(message.flags); } struct EthController { diff --git a/src/Helpers/ShmRingBuffer.h b/src/Helpers/ShmRingBuffer.h index 83828a0..b588a9a 100644 --- a/src/Helpers/ShmRingBuffer.h +++ b/src/Helpers/ShmRingBuffer.h @@ -76,10 +76,10 @@ class ShmRingBuffer final { } private: - uint32_t _capacity{}; // Read by reader and writer - std::atomic _size; // Read and written by reader and writer - uint32_t _readIndex{}; // Read and written by reader - uint32_t _writeIndex{}; // Read and written by writer + uint32_t _capacity{}; // Read by reader and writer + std::atomic _size{}; // Read and written by reader and writer + uint32_t _readIndex{}; // Read and written by reader + uint32_t _writeIndex{}; // Read and written by writer // Zero sized array would be correct here, since the items are inside a shared memory. But that leads to // warnings, so we add set the size to 1 diff --git a/src/OsAbstraction/NamedEvent.cpp b/src/OsAbstraction/NamedEvent.cpp index dc3cf40..2a0b7b0 100644 --- a/src/OsAbstraction/NamedEvent.cpp +++ b/src/OsAbstraction/NamedEvent.cpp @@ -5,6 +5,7 @@ #include "NamedEvent.h" #include + #include #include diff --git a/src/OsAbstraction/NamedMutex.cpp b/src/OsAbstraction/NamedMutex.cpp index a3ceed3..8734e18 100644 --- a/src/OsAbstraction/NamedMutex.cpp +++ b/src/OsAbstraction/NamedMutex.cpp @@ -5,6 +5,7 @@ #include "NamedMutex.h" #include + #include #include diff --git a/src/OsAbstraction/OsUtilities.cpp b/src/OsAbstraction/OsUtilities.cpp index df0aa81..ff4960f 100644 --- a/src/OsAbstraction/OsUtilities.cpp +++ b/src/OsAbstraction/OsUtilities.cpp @@ -5,6 +5,7 @@ #include "OsUtilities.h" #include + #include #include #include diff --git a/src/OsAbstraction/SharedMemory.cpp b/src/OsAbstraction/SharedMemory.cpp index f9e1c23..07e861c 100644 --- a/src/OsAbstraction/SharedMemory.cpp +++ b/src/OsAbstraction/SharedMemory.cpp @@ -5,6 +5,7 @@ #include "SharedMemory.h" #include + #include #include diff --git a/src/OsAbstraction/Socket.cpp b/src/OsAbstraction/Socket.cpp index b40cdf2..ad3bd84 100644 --- a/src/OsAbstraction/Socket.cpp +++ b/src/OsAbstraction/Socket.cpp @@ -12,6 +12,7 @@ #include #include #include + #include #else #include @@ -28,6 +29,7 @@ #include #include #include + #include #endif @@ -472,7 +474,7 @@ void Socket::EnableIpv6Only() const { } ::freeaddrinfo(addressInfo); - return connectedSocket; + return std::optional(std::move(connectedSocket)); } freeaddrinfo(addressInfo); diff --git a/src/PortMapper.cpp b/src/PortMapper.cpp index 7f48b99..e1eec53 100644 --- a/src/PortMapper.cpp +++ b/src/PortMapper.cpp @@ -18,9 +18,7 @@ constexpr uint32_t ClientTimeoutInMilliseconds = 1000; } // namespace PortMapperServer::PortMapperServer(bool enableRemoteAccess) : _server(GetPortMapperPort(), enableRemoteAccess) { - _thread = std::thread([this] { - RunPortMapperServer(); - }); + _thread = std::thread([this] { RunPortMapperServer(); }); } PortMapperServer::~PortMapperServer() noexcept { diff --git a/test/Communication/TestLocalChannel.cpp b/test/Communication/TestLocalChannel.cpp index 0d7e6c4..ffb988b 100644 --- a/test/Communication/TestLocalChannel.cpp +++ b/test/Communication/TestLocalChannel.cpp @@ -3,6 +3,7 @@ #ifdef _WIN32 #include + #include #include #include @@ -38,9 +39,7 @@ TEST_F(TestLocalChannel, ConnectWithoutStart) { // Arrange const std::string name = GenerateName(); - { - LocalChannelServer server(name); - } + { LocalChannelServer server(name); } // Act std::optional connectedChannel = TryConnectToLocalChannel(name); diff --git a/test/Communication/TestTcpChannel.cpp b/test/Communication/TestTcpChannel.cpp index b40f6ec..650ab58 100644 --- a/test/Communication/TestTcpChannel.cpp +++ b/test/Communication/TestTcpChannel.cpp @@ -1,6 +1,7 @@ // Copyright dSPACE GmbH. All rights reserved. #include + #include #include #include diff --git a/test/Communication/TestUdsChannel.cpp b/test/Communication/TestUdsChannel.cpp index 7d24e13..4116158 100644 --- a/test/Communication/TestUdsChannel.cpp +++ b/test/Communication/TestUdsChannel.cpp @@ -1,6 +1,7 @@ // Copyright dSPACE GmbH. All rights reserved. #include + #include #include #include @@ -36,9 +37,7 @@ TEST_F(TestUdsChannel, ConnectWithoutStart) { // Arrange std::string name = GenerateName(); - { - UdsChannelServer server(name); - } + { UdsChannelServer server(name); } // Act std::optional connectedChannel = TryConnectToUdsChannel(name); diff --git a/test/Helpers/TestHelper.cpp b/test/Helpers/TestHelper.cpp index 68dc370..c4f1426 100644 --- a/test/Helpers/TestHelper.cpp +++ b/test/Helpers/TestHelper.cpp @@ -3,6 +3,7 @@ #include "TestHelper.h" #include + #include #include diff --git a/test/Helpers/TestHelper.h b/test/Helpers/TestHelper.h index 85315ce..c7a23f7 100644 --- a/test/Helpers/TestHelper.h +++ b/test/Helpers/TestHelper.h @@ -3,6 +3,7 @@ #pragma once #include + #include #include #include diff --git a/test/OsAbstraction/TestNamedEvent.cpp b/test/OsAbstraction/TestNamedEvent.cpp index d7f6412..ca733c7 100644 --- a/test/OsAbstraction/TestNamedEvent.cpp +++ b/test/OsAbstraction/TestNamedEvent.cpp @@ -3,6 +3,7 @@ #ifdef _WIN32 #include + #include #include diff --git a/test/OsAbstraction/TestNamedMutex.cpp b/test/OsAbstraction/TestNamedMutex.cpp index b59cd79..7a78fb5 100644 --- a/test/OsAbstraction/TestNamedMutex.cpp +++ b/test/OsAbstraction/TestNamedMutex.cpp @@ -3,6 +3,7 @@ #ifdef _WIN32 #include + #include #include "Generator.h" diff --git a/test/OsAbstraction/TestSharedMemory.cpp b/test/OsAbstraction/TestSharedMemory.cpp index 7cb3626..09eb787 100644 --- a/test/OsAbstraction/TestSharedMemory.cpp +++ b/test/OsAbstraction/TestSharedMemory.cpp @@ -3,6 +3,7 @@ #ifdef _WIN32 #include + #include #include "Generator.h" diff --git a/test/OsAbstraction/TestTcpSocket.cpp b/test/OsAbstraction/TestTcpSocket.cpp index 7db496a..48d0e9e 100644 --- a/test/OsAbstraction/TestTcpSocket.cpp +++ b/test/OsAbstraction/TestTcpSocket.cpp @@ -1,7 +1,8 @@ // Copyright dSPACE GmbH. All rights reserved. -#include #include +#include + #include #include diff --git a/test/Program.cpp b/test/Program.cpp index f7d5d2d..436d48c 100644 --- a/test/Program.cpp +++ b/test/Program.cpp @@ -1,6 +1,7 @@ // Copyright dSPACE GmbH. All rights reserved. #include + #include #include "Helper.h" diff --git a/test/TestBusBuffer.cpp b/test/TestBusBuffer.cpp index 4076784..c5b58b0 100644 --- a/test/TestBusBuffer.cpp +++ b/test/TestBusBuffer.cpp @@ -3,6 +3,7 @@ #include #include #include + #include #include #include @@ -59,9 +60,7 @@ void Transfer(ConnectionKind connectionKind, BusBuffer& senderBusBuffer, BusBuff #endif } - std::thread thread([&] { - ASSERT_TRUE(receiverBusBuffer.Deserialize(receiverChannel->GetReader(), {}, {})); - }); + std::thread thread([&] { ASSERT_TRUE(receiverBusBuffer.Deserialize(receiverChannel->GetReader(), {}, {})); }); ASSERT_TRUE(senderBusBuffer.Serialize(senderChannel->GetWriter())); ASSERT_TRUE(senderChannel->GetWriter().EndWrite()); @@ -139,9 +138,8 @@ void Transfer(ConnectionKind connectionKind, }; } - std::thread thread([&] { - ASSERT_TRUE(receiverBusBuffer.Deserialize(receiverChannel->GetReader(), simulationTime, callbacks)); - }); + std::thread thread( + [&] { ASSERT_TRUE(receiverBusBuffer.Deserialize(receiverChannel->GetReader(), simulationTime, callbacks)); }); ASSERT_TRUE(senderBusBuffer.Serialize(senderChannel->GetWriter())); ASSERT_TRUE(senderChannel->GetWriter().EndWrite()); @@ -299,11 +297,8 @@ TYPED_TEST(TestBusBuffer, InitializeControllersWithDuplicatedIds) { FillWithRandom(controller); // Act and assert - ASSERT_THAT( - [&]() { - BusBuffer(coSimType, connectionKind, name, {controller, controller}); - }, - ThrowsMessage(fmt::format("Duplicated controller id {}.", controller.id))); + ASSERT_THAT([&]() { BusBuffer(coSimType, connectionKind, name, {controller, controller}); }, + ThrowsMessage(fmt::format("Duplicated controller id {}.", controller.id))); } #endif diff --git a/test/TestCoSim.cpp b/test/TestCoSim.cpp index 281a28c..f66dc1c 100644 --- a/test/TestCoSim.cpp +++ b/test/TestCoSim.cpp @@ -2,6 +2,7 @@ #include #include + #include #include "CoSimClient.h" @@ -259,9 +260,7 @@ TEST_P(TestCoSim, DisconnectFromServerWithMandatoryClient) { Event stoppedEvent; CoSimServerConfig config = CreateServerConfig(); - config.simulationStoppedCallback = [&](DsVeosCoSim_SimulationTime) { - stoppedEvent.Set(); - }; + config.simulationStoppedCallback = [&](DsVeosCoSim_SimulationTime) { stoppedEvent.Set(); }; CoSimServer server; server.Load(config); diff --git a/test/TestIoBuffer.cpp b/test/TestIoBuffer.cpp index f71ee66..2a5def4 100644 --- a/test/TestIoBuffer.cpp +++ b/test/TestIoBuffer.cpp @@ -41,9 +41,8 @@ void Transfer(IoBuffer& writerIoBuffer, IoBuffer& readerIoBuffer) { SocketChannel senderChannel = ConnectToTcpChannel("127.0.0.1", port); SocketChannel receiverChannel = Accept(server); - std::thread thread([&] { - ASSERT_TRUE(readerIoBuffer.Deserialize(receiverChannel.GetReader(), GenerateI64(), {})); - }); + std::thread thread( + [&] { ASSERT_TRUE(readerIoBuffer.Deserialize(receiverChannel.GetReader(), GenerateI64(), {})); }); ASSERT_TRUE(writerIoBuffer.Serialize(senderChannel.GetWriter())); ASSERT_TRUE(senderChannel.GetWriter().EndWrite()); @@ -79,9 +78,8 @@ void TransferWithEvents(IoBuffer& writerIoBuffer, IoBuffer& readerIoBuffer, std: expectedCallbacks.pop_front(); }; - std::thread thread([&] { - ASSERT_TRUE(readerIoBuffer.Deserialize(receiverChannel.GetReader(), simulationTime, callbacks)); - }); + std::thread thread( + [&] { ASSERT_TRUE(readerIoBuffer.Deserialize(receiverChannel.GetReader(), simulationTime, callbacks)); }); ASSERT_TRUE(writerIoBuffer.Serialize(senderChannel.GetWriter())); ASSERT_TRUE(senderChannel.GetWriter().EndWrite()); diff --git a/test/TestPortMapper.cpp b/test/TestPortMapper.cpp index 5940e74..14fe091 100644 --- a/test/TestPortMapper.cpp +++ b/test/TestPortMapper.cpp @@ -1,8 +1,9 @@ // Copyright dSPACE GmbH. All rights reserved. +#include #include #include -#include + #include #include "Generator.h" @@ -56,12 +57,9 @@ TEST_F(TestPortMapper, GetWithoutSet) { uint16_t port{}; // Act and assert - ASSERT_THAT( - [&]() { - (void)PortMapper_GetPort("127.0.0.1", serverName, port); - }, - ThrowsMessage( - fmt::format("Could not find port for dSPACE VEOS CoSim server '{}'.", serverName))); + ASSERT_THAT([&]() { (void)PortMapper_GetPort("127.0.0.1", serverName, port); }, + ThrowsMessage( + fmt::format("Could not find port for dSPACE VEOS CoSim server '{}'.", serverName))); } #endif @@ -80,12 +78,9 @@ TEST_F(TestPortMapper, GetAfterUnset) { uint16_t port{}; // Act and assert - ASSERT_THAT( - [&]() { - (void)PortMapper_GetPort("127.0.0.1", serverName, port); - }, - ThrowsMessage( - fmt::format("Could not find port for dSPACE VEOS CoSim server '{}'.", serverName))); + ASSERT_THAT([&]() { (void)PortMapper_GetPort("127.0.0.1", serverName, port); }, + ThrowsMessage( + fmt::format("Could not find port for dSPACE VEOS CoSim server '{}'.", serverName))); } #endif diff --git a/test/TestProtocol.cpp b/test/TestProtocol.cpp index 8d9a601..5cfacb5 100644 --- a/test/TestProtocol.cpp +++ b/test/TestProtocol.cpp @@ -61,9 +61,7 @@ class TestProtocol : public testing::TestWithParam { INSTANTIATE_TEST_SUITE_P(, TestProtocol, testing::Values(ConnectionKind::Local, ConnectionKind::Remote), - [](const testing::TestParamInfo& info) { - return ToString(info.param); - }); + [](const testing::TestParamInfo& info) { return ToString(info.param); }); TEST_P(TestProtocol, SendAndReceiveOk) { // Arrange diff --git a/utilities/PerformanceTestClient/ClientEvents.cpp b/utilities/PerformanceTestClient/ClientEvents.cpp index 8dae495..4f5067f 100644 --- a/utilities/PerformanceTestClient/ClientEvents.cpp +++ b/utilities/PerformanceTestClient/ClientEvents.cpp @@ -1,6 +1,7 @@ // Copyright dSPACE GmbH. All rights reserved. #ifdef _WIN32 +#include #include #include @@ -24,15 +25,15 @@ void EventsClientRun([[maybe_unused]] std::string_view host, NamedEvent endEvent = NamedEvent::CreateOrOpen(EndEventName); SharedMemory sharedMemory = SharedMemory::CreateOrOpen(ShmName, BufferSize); - char buffer[BufferSize]{}; + std::array buffer{}; connectedEvent.Set(); while (!isStopped) { - ::memcpy(sharedMemory.data(), buffer, BufferSize); + ::memcpy(sharedMemory.data(), buffer.data(), BufferSize); beginEvent.Set(); endEvent.Wait(); - ::memcpy(buffer, sharedMemory.data(), BufferSize); + ::memcpy(buffer.data(), sharedMemory.data(), BufferSize); buffer[0]++; counter++; diff --git a/utilities/PerformanceTestServer/ServerCoSim.cpp b/utilities/PerformanceTestServer/ServerCoSim.cpp index b03a26a..b26b3bf 100644 --- a/utilities/PerformanceTestServer/ServerCoSim.cpp +++ b/utilities/PerformanceTestServer/ServerCoSim.cpp @@ -24,9 +24,7 @@ void CoSimServerRun() { config.logCallback = OnLogCallback; config.startPortMapper = false; config.registerAtPortMapper = false; - config.simulationStoppedCallback = [&stopSimulation](DsVeosCoSim_SimulationTime) { - stopSimulation = true; - }; + config.simulationStoppedCallback = [&stopSimulation](DsVeosCoSim_SimulationTime) { stopSimulation = true; }; CoSimServer server; server.Load(config); diff --git a/utilities/PerformanceTestServer/ServerEvents.cpp b/utilities/PerformanceTestServer/ServerEvents.cpp index fd7076d..6b7a6c3 100644 --- a/utilities/PerformanceTestServer/ServerEvents.cpp +++ b/utilities/PerformanceTestServer/ServerEvents.cpp @@ -1,6 +1,7 @@ // Copyright dSPACE GmbH. All rights reserved. #ifdef _WIN32 +#include #include #include "LogHelper.h" @@ -14,7 +15,7 @@ void EventsServerRun() { try { LogTrace("Events server listening on SHM {} ...", ShmName); - char buffer[BufferSize]{}; + std::array buffer{}; NamedEvent beginEvent = NamedEvent::CreateOrOpen(BeginEventName); NamedEvent endEvent = NamedEvent::CreateOrOpen(EndEventName); @@ -22,9 +23,9 @@ void EventsServerRun() { while (true) { beginEvent.Wait(); - ::memcpy(buffer, sharedMemory.data(), BufferSize); + ::memcpy(buffer.data(), sharedMemory.data(), BufferSize); buffer[0]++; - ::memcpy(sharedMemory.data(), buffer, BufferSize); + ::memcpy(sharedMemory.data(), buffer.data(), BufferSize); endEvent.Set(); } } catch (const std::exception& e) { diff --git a/utilities/PerformanceTestServer/ServerLocalCommunication.cpp b/utilities/PerformanceTestServer/ServerLocalCommunication.cpp index 0de769f..7d52c14 100644 --- a/utilities/PerformanceTestServer/ServerLocalCommunication.cpp +++ b/utilities/PerformanceTestServer/ServerLocalCommunication.cpp @@ -1,5 +1,6 @@ // Copyright dSPACE GmbH. All rights reserved. +#include #include #include @@ -27,7 +28,7 @@ void LocalCommunicationServerRun() { UdsChannelServer server(LocalName); #endif - char buffer[BufferSize]{}; + std::array buffer{}; while (true) { #ifdef _WIN32 @@ -45,11 +46,11 @@ void LocalCommunicationServerRun() { } while (true) { - if (!acceptedChannel->GetReader().Read(buffer, BufferSize)) { + if (!acceptedChannel->GetReader().Read(buffer.data(), BufferSize)) { break; } - if (!acceptedChannel->GetWriter().Write(buffer, BufferSize)) { + if (!acceptedChannel->GetWriter().Write(buffer.data(), BufferSize)) { break; } diff --git a/utilities/TestClient/Program.cpp b/utilities/TestClient/Program.cpp index 4da64b3..388c08d 100644 --- a/utilities/TestClient/Program.cpp +++ b/utilities/TestClient/Program.cpp @@ -8,6 +8,7 @@ #else #include #include + #include #endif @@ -302,28 +303,36 @@ void LogIoData(DsVeosCoSim_SimulationTime simulationTime, uint32_t length, const void* value, [[maybe_unused]] void* userData) { - fmt::print(fmt::fg(fmt::color::fuchsia), "{}\n", DsVeosCoSim_IoDataToString(simulationTime, *ioSignal, length, value)); + fmt::print(fmt::fg(fmt::color::fuchsia), + "{}\n", + DsVeosCoSim_IoDataToString(simulationTime, *ioSignal, length, value)); } void LogCanMessage(DsVeosCoSim_SimulationTime simulationTime, const DsVeosCoSim_CanController* controller, const DsVeosCoSim_CanMessage* message, [[maybe_unused]] void* userData) { - fmt::print(fmt::fg(fmt::color::dodger_blue), "{}\n", DsVeosCoSim_CanMessageToString(simulationTime, *controller, *message)); + fmt::print(fmt::fg(fmt::color::dodger_blue), + "{}\n", + DsVeosCoSim_CanMessageToString(simulationTime, *controller, *message)); } void LogEthMessage(DsVeosCoSim_SimulationTime simulationTime, const DsVeosCoSim_EthController* controller, const DsVeosCoSim_EthMessage* message, [[maybe_unused]] void* userData) { - fmt::print(fmt::fg(fmt::color::cyan), "{}\n", DsVeosCoSim_EthMessageToString(simulationTime, *controller, *message)); + fmt::print(fmt::fg(fmt::color::cyan), + "{}\n", + DsVeosCoSim_EthMessageToString(simulationTime, *controller, *message)); } void LogLinMessage(DsVeosCoSim_SimulationTime simulationTime, const DsVeosCoSim_LinController* controller, const DsVeosCoSim_LinMessage* message, [[maybe_unused]] void* userData) { - fmt::print(fmt::fg(fmt::color::lime), "{}\n", DsVeosCoSim_LinMessageToString(simulationTime, *controller, *message)); + fmt::print(fmt::fg(fmt::color::lime), + "{}\n", + DsVeosCoSim_LinMessageToString(simulationTime, *controller, *message)); } void OnSimulationPostStepCallback(DsVeosCoSim_SimulationTime simulationTime, [[maybe_unused]] void* userData) { diff --git a/utilities/TestServer/Program.cpp b/utilities/TestServer/Program.cpp index c4008a3..d1ef10a 100644 --- a/utilities/TestServer/Program.cpp +++ b/utilities/TestServer/Program.cpp @@ -8,6 +8,7 @@ #else #include #include + #include #endif