Home » Eclipse Projects » 4DIAC - Framework for Distributed Industrial Automation and Control » json com layer(top level layer for putting data into JSON formate)
|json com layer [message #1754454]
||Fri, 17 February 2017 22:57
| Ernst Murnleitner
Registered: December 2016
I attach the source code for a new top level communication layer which we use on top of the mqtt layer.|
Additional to the more complicated example which is described below,
it can also be used more simple:
... is used as ID of one of the PUBLISH FB, ...
this mqtt message will be published:
... where XXX is the value which is connected to the SD_1 of PUBLISH1 (or ...2 etc)
== Introduction ==
jsoncomlayer adds a top level layer to FORTE.
It receives a string in JSON formate, extracts one or more values and transfers the values to the function block (e.g. SUBSCRIBE).
It reads values from a function block (e.g. PUBLISH) and writes them into a JSON-Object, which is transferred to the bottom layer.
It was tested using mqtt as the bottom layer.
== Files ==
in directory src/core/cominfra:
Helper functions for json parsing:
add to CMakeLists.txt:
forte_add_network_layer(JSON ON "json" CJsonComLayer jsoncomlayer "Enable Forte json communication")
add -DFORTE_RTTI_AND_EXCEPTIONS=ON to the call of cmake, e.g. in setup_posix.sh
== Usage ==
Use the Publish/Subscribe function blocks of 4DIAC and configure it's ID data input as follows:
json[Index:(structure/)Variable(:type), Index2:(structure2/)Variable2(:type), ...].mqtt[tcp://ip:port, cientID, topic]
Whitespaces can be ommitted.
Index is the number of the input/output variable of the Funktionblock, beginning with 1.
The structure is optional. The levels of nested objects are seperated by "/".
The variable is the name of the value.
The optional type forces the data into a certain formate.
type can be one of: auto, number, real, int, bool, null, any.
The type influences, how the conversion between 4DIAC IEC type and JSON variable type is made.
auto: automatic conversion between 4DIAC IEC type and JSON variable type (e.g. json int fits to all int types, json bool fits to bool type etc.)
number: converts numbers (bool, int, real) but not string. The smallest possible representation is chosen (e.g. a IEC bool is representated by a JSON bool (values: true, false)
string: converts values to string
real: converts any number to a real (number with decimal point)
int: converts any number into an int (number without decimal point)
bool: converts any number into a bool (only the two states true or false)
any: like auto, but a string fits to a number and a number fits to string also
== Example ==
ID string for the Function block:
A JSON object which fits:
Values assigned from JSON to the Function block:
1: the value "111" is a JSON string type (because the enclosing quotes). It can only be assigned to a string.
2: the value 234 is a JSON int type (because no decimal point and no quotes). It can only be assinged to one of the IEC int types.
3: the value "45" is a JSON string. It can be assignd to any IEC type (bool, integer, real, string), because the type "any" is used in the ID string.
(c) Ernst Murnleitner, Awite Bionergie GmbH 2016
Current Time: Mon Feb 19 15:56:13 GMT 2018
Powered by FUDForum
. Page generated in 0.02088 seconds