|
|
This document shows the functions that an **autopilot** (as library) has to implement in order to be loaded and run by the **hardware-emulator**.
|
|
|
|
|
|
These are simple entry points so that the hardware_emulator can easily communicate with the autopilot.
|
|
|
The functions are simple pure C types and thus use simple function calling standards.
|
|
|
|
|
|
These functions can be implemented by including and implementing the [library_interface.h header](https://git.rwth-aachen.de/monticore/EmbeddedMontiArc/simulators/shared_cpp/-/blob/master/library_interface.h) from the `shared_cpp` project.
|
|
|
|
|
|
This interface is implemented by autopilots generated using EMAM2CPP or one of its siblings.
|
|
|
|
|
|
## Functions
|
|
|
|
|
|
### get_interface()
|
|
|
|
|
|
Signature:
|
|
|
|
|
|
```C
|
|
|
EXPORT const char* DI__get_interface();
|
|
|
```
|
|
|
|
|
|
This function must return a JSON string corresponding to the [ProgramInterface](https://git.rwth-aachen.de/monticore/EmbeddedMontiArc/simulators/commons/-/blob/master/src/main/java/de/rwth/montisim/commons/dynamicinterface/ProgramInterface.java) class.
|
|
|
|
|
|
### init()
|
|
|
|
|
|
Signature:
|
|
|
|
|
|
```C
|
|
|
EXPORT void DI__init();
|
|
|
```
|
|
|
|
|
|
Called at the start of a simulation to initialize the autopilot.
|
|
|
|
|
|
### execute()
|
|
|
|
|
|
Signature:
|
|
|
|
|
|
```C
|
|
|
EXPORT void DI__execute();
|
|
|
```
|
|
|
|
|
|
Called each simulation cycle after the ports have been set.
|
|
|
|
|
|
### set_port() and get_port()
|
|
|
|
|
|
Signatures:
|
|
|
|
|
|
```C
|
|
|
EXPORT void DI__set_port(int i, const char* data, int is_json);
|
|
|
EXPORT const char* DI__get_port(int i, int is_json);
|
|
|
```
|
|
|
|
|
|
These functions are used to exchange the port data with the autopilot.
|
|
|
|
|
|
The argument `i` is an index starting at 0. It corresponds to the order of the ports as described in the `ProgramInterface` returned by `DI__get_interface()`.
|
|
|
|
|
|
The `is_json` argument specifies whether the `data` exchanged is JSON or binary.
|
|
|
If `is_json == 0` the content is binary else it is a JSON string.
|
|
|
In the case of **binary**, the first 4 bytes are the length of the rest of the data array.
|
|
|
(This value follows the serialization format of the [BinaryWriter/BinaryReader](https://git.rwth-aachen.de/monticore/EmbeddedMontiArc/simulators/shared_cpp/-/blob/master/buffer.h) used for serializing the binary data.)
|
|
|
|
|
|
In the case of `DI__get_port`, the `is_json` argument is a "request" for the content of the returned array. |