|
|
The **DataType** system is a *meta-type* system to dynamically exchange type information in the simulator.
|
|
|
This system is for example used between the *autopilot adapter* and the `Computer` component to dynamically discover the data-ports of the autopilot.
|
|
|
It is also used in the EE-system to check that the correct types are sent between the various EE-components.
|
|
|
|
|
|
## Structure
|
|
|
|
|
|
The interface type [DataType](https://git.rwth-aachen.de/monticore/EmbeddedMontiArc/simulators/commons/-/blob/master/src/main/java/de/rwth/montisim/commons/dynamicinterface/DataType.java) is used to represent a dynamic data-type.
|
|
|
It can be set to any of its child classes:
|
|
|
|
|
|
- `BasicType`: Contains a enum that can be set to the following types: `Q`, `Z`, `N`, `N1`, `C`, `BOOLEAN`, `DOUBLE` (=`Q`), `INT` (=`Z`), `EMPTY`, `VEC2` or `VEC3`.
|
|
|
- `VectorType`: An array of any `DataType`.
|
|
|
- `MatrixType`: A 2D matrix of any `DataType`.
|
|
|
- `EnumType`: List the name of the enum variants of an enumeration.
|
|
|
- `StructType`: Specifies the name of the struct as well as the name and `DataType` of its fields.
|
|
|
- `SimplePacketType`: A special data-type used to represent a simple network packet.
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
Using the `DataType` system allows to do the following:
|
|
|
|
|
|
- Compare `DataTypes` for equality.
|
|
|
- Serialize an object of dynamic type to (and from) **JSON** (`toJson()` and `fromJson()` methods).
|
|
|
- Serialize an object of dynamic type to (and from) **binary** (`toBinary()` and `fromBinary()` methods).
|
|
|
- Print an object of dynamic type in a readable way (`toString(Object)` method).
|
|
|
|
|
|
TODO make c++ code for data types available.
|
|
|
|
|
|
## JSON examples
|
|
|
|
|
|
A `DataType` structure itself is serializable to (and from) JSON. Here are some examples for every `DataType`.
|
|
|
|
|
|
```json
|
|
|
# Basic Types
|
|
|
{
|
|
|
"type": "basic",
|
|
|
"base_type": "Q"
|
|
|
}
|
|
|
# Or
|
|
|
{
|
|
|
"type": "basic",
|
|
|
"base_type": "VEC2"
|
|
|
}
|
|
|
# ...
|
|
|
|
|
|
# Vector type
|
|
|
# Here 'base_type' can be any type
|
|
|
{
|
|
|
"type": "vector",
|
|
|
"size": 10,
|
|
|
"base_type": {
|
|
|
"type": "basic",
|
|
|
"base_type": "Q"
|
|
|
}
|
|
|
}
|
|
|
|
|
|
# Matrix type
|
|
|
# Here 'base_type' can be any type
|
|
|
{
|
|
|
"type": "matrix",
|
|
|
"rows": 3,
|
|
|
"columns": 5,
|
|
|
"base_type": {
|
|
|
"type": "basic",
|
|
|
"base_type": "Q"
|
|
|
}
|
|
|
}
|
|
|
|
|
|
# Enum type
|
|
|
{
|
|
|
"type": "enum",
|
|
|
"variants": ["SOMETHING", "OTHER_VARIANT", "THIRD_VARIANT"]
|
|
|
}
|
|
|
|
|
|
# Struct Type
|
|
|
# The fields objects contains the name of a field as key and its corresponding DataType as value
|
|
|
{
|
|
|
"type": "struct",
|
|
|
"name": "MyStruct",
|
|
|
"fields": {
|
|
|
"field1": {
|
|
|
"type": "basic",
|
|
|
"base_type": "Q"
|
|
|
},
|
|
|
"other_field": {
|
|
|
"type": "basic",
|
|
|
"base_type": "VEC2"
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
# SimplePacketType
|
|
|
# Here 'payloadType' can be any type
|
|
|
{
|
|
|
"type": "simple_packet",
|
|
|
"payloadType": {
|
|
|
"type": "basic",
|
|
|
"base_type": "VEC2"
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
|
|
|
## Type mappings
|
|
|
|
|
|
The following table shows how an object of dynamic type is represented in the different languages.
|
|
|
Note that all binary numbers are written in *Network Byte Order* (Big-endian/MSB first).
|
|
|
|
|
|
| DataType | Java | JSON | Binary | C++ | Constraint |
|
|
|
| -------- | ---- | ---- | ------ | --- | ---------- |
|
|
|
| `BasicType`: `Q` & `DOUBLE` | `Double` | (floating-point) number | `double` -> 8 bytes | `double` | |
|
|
|
| `BasicType`: `Z` & `INT` | `Integer` | number | `int` -> 4 bytes | `int32_t` | |
|
|
|
| `BasicType`: `N` | `int` | number | `int` -> 4 bytes | `int32_t` | The number must be >= 0. |
|
|
|
| `BasicType`: `N1` | `int` | number | `int` -> 4 bytes | `int32_t` | The number must be **>** 0. |
|
|
|
| `BasicType`: `C` | TODO | Array with 2 numbers | 2 doubles | ? | |
|
|
|
| `BasicType`: `BOOLEAN` | `Boolean` | JSON boolean (`true` or `false`) | 1 byte (`1` or `0`) | `bool` | |
|
|
|
| `BasicType`: `EMPTY` | `null` | nothing? | nothing | nothing | |
|
|
|
| `BasicType`: `VEC2` | [`Vec2` class](https://git.rwth-aachen.de/monticore/EmbeddedMontiArc/simulators/commons/-/blob/master/src/main/java/de/rwth/montisim/commons/utils/Vec2.java) | Array with 2 numbers | 2 doubles | ? | |
|
|
|
| `BasicType`: `VEC3` | [`Vec3` class](https://git.rwth-aachen.de/monticore/EmbeddedMontiArc/simulators/commons/-/blob/master/src/main/java/de/rwth/montisim/commons/utils/Vec3.java) | Array with 3 numbers | 3 doubles | ? | |
|
|
|
| `VectorType` | An Object array (`Object[]`) with every entry. | JSON Array with every entry. | A short (2 bytes) with the number elements followed by these elements. | ? | |
|
|
|
| `MatrixType` | TODO |
|
|
|
| `EnumType` | TODO |
|
|
|
| `StructType` | TODO |
|
|
|
| `SimplePacketType` | TODO |
|
|
|
|