From 9ad46d2fd83d6782ccb2500e19c10000703ac16a Mon Sep 17 00:00:00 2001 From: pbosetti Date: Thu, 27 Jun 2024 07:50:45 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20pbosetti?= =?UTF-8?q?/mads=5Fplugin@37cf55b769472e981d4894fb4b985b75200ccf7e=20?= =?UTF-8?q?=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 129 +++++++++++++++++++++++++++---------------- search/all_0.js | 2 +- search/all_1.js | 2 +- search/all_10.html | 37 +++++++++++++ search/all_10.js | 4 ++ search/all_2.js | 2 +- search/all_3.js | 2 +- search/all_4.js | 3 +- search/all_5.js | 3 +- search/all_6.js | 5 +- search/all_7.js | 5 +- search/all_8.js | 2 +- search/all_9.js | 3 +- search/all_a.js | 5 +- search/all_b.js | 7 +-- search/all_c.js | 13 ++--- search/all_d.js | 9 ++- search/all_e.js | 2 +- search/all_f.js | 2 +- search/pages_0.js | 2 +- search/searchdata.js | 4 +- 21 files changed, 158 insertions(+), 85 deletions(-) create mode 100644 search/all_10.html create mode 100644 search/all_10.js diff --git a/index.html b/index.html index a1ed18c..aa05fea 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,7 @@ -plugin: Plugins! +plugin: Availabe plugins @@ -63,58 +63,91 @@
-
Plugins!
+
Availabe plugins
-

Build status

-

This example project explores how to develop a plugin system for a C++ application. It is based on the [pugg plugin system]().

+

-Building

-

To build the project, you need to have CMake installed. Then, you can run the following commands:

-
mkdir build
-
ccmake -Bbuild -DCMAKE_BUILD_TYPE=Release
-
cmake --build build -t install
-

This creates three plugins in the form of executable files that also export symbols, so that they can be externally loaded by the main application. The plugins are named echo.plugin, twice.plugin, and echoj.plugin.

-

The latter plugin is a template for complete plugins, and it is pretty extensible. Indeed, it accepts a JSON object as settings, a JSON object as input, and produces a JSON object as output. The other two plugins are simple examples of how to implement a plugin.

-

Plugins are named Filters, for they are expected to act as filters, taking an input and producing an output. The plugins must be implemented as derived classes of the templated class Filter (see src/filter.hpp).

-

If needed, this project will be extended by adding base classes for other types of plugins, such as Sources (output only) and Sinks (input only).

+Templates +

The available templates are:

+
    +
  • template_source.cpp for implementing source plugins
  • +
  • template_sink.cpp for implementing sink plugins
  • +
  • template_filter.cpp for implementing filter plugins
  • +
+

Use these files as a starting point for your own plugins.

-Executing

-

The install step creates and populates the usr directory in the project root folder. You can run the executable that loads the plugin with the following command:

-
cd usr
-
bin/loaderj bin/echoj.plugin
-

Note that on MacOS only the echoj.plugin file is actually an executable file that exports symbols. It is not a shared library, but it is a plugin that can also be directly executed (using its internal main()) as:

-
bin/echoj.plugin
-

This is a very flexible way for implementing standalone apps that can also be used as plugins within the Miroscic framework of distributed agents.

-

On Windows and Linux, the plugin is a shared library that can only be loaded by the loader executable. Beside the plugin, an equivalent executable is also generated.

+Example plugins +

The followings are example plugins of little practucalu use, but they are good for learning the basics of plugin development.

+
    +
  • clock: a source that provides clock values
  • +
  • echoj: a filter that echoes the input message
  • +
  • random: a source that provides random values
  • +
  • to_console: a sink that prints the input message to the console
  • +
  • twice: a filter that duplicates the input message
  • +

-Plugin Versioning

-

The plugin system uses an internal version number Filter::version to check compatibility between the main application and the plugins. To invalidate a previously released plugin, simply imcrease the version number in the base class.

-

-Derived classes

-

To create a new plugin, fork this repository and implement a derived class of Filter or Source in a new file. At the end of the new derived class definition, add the macros that set up the plugin driver: if it is a source, add

-
INSTALL_SOURCE_DRIVER(MySourceClassName, json)
-
#define INSTALL_SOURCE_DRIVER(klass, type)
Call this macro after defining a source class to install it into the kernel.
Definition: common.hpp:19
-

If it is a filter, add

-
INSTALL_FILTER_DRIVER(MyFilterClassName, json, json)
-
#define INSTALL_FILTER_DRIVER(klass, type_in, type_out)
Call this macro after defining a filter class to install it into the kernel.
Definition: common.hpp:38
-

If it is a sink, add

-
INSTALL_SINK_DRIVER(MySinkClassName, json)
-
#define INSTALL_SINK_DRIVER(klass, type)
Call this macro after defining a source class to install it into the kernel.
Definition: common.hpp:57
-

Finally, create a new target in the CMakeLists.txt file that compiles the new plugin. Something like:

-
add_plugin(webcam LIBS LibsNeeded)
-

-HTTPS Client Certificates

-

To connect with the Siemens Edge device, we need a SSL client certificate. To configure it, follow the next steps:

-
    -
  1. on the Siemens Edge miniweb interface, create a new certificate in .p12 format (if it is not exsiting yet)
  2. -
  3. download the certificate in this project root folder: when exporting, check the "Export key" option and give a passphrase
  4. -
  5. now the encripted certificate must be extracted in two separate files: the certificate itself and the private key. To do so, run the following commands (which will ask you the same passphrase used in the previous step):
  6. -
-
openssl pkcs12 -in amwcapture.p12 -clcerts -nokeys -out amwcapture.crt -legacy
-
openssl pkcs12 -in amwcapture.p12 -nocerts -nodes -out amwcapture.key -legacy
-

The executable will look for these two files in the current working directory.

-
+Plugins of actual use +

+MQTT

+

This acts as a source plugin, which reads messages from an MQTT broker and sends them to the MADS broker.

+

Note that the plugin only subscribes to the topic as specified in the configuration file and does not publish any messages.

+

The frequency of messages depends on when they are received from the MQTT broker. The plugin will send the messages to the MADS broker as soon as they are received.

+

+Parameters

+

The accepted parameters are:

+
[mqtt]
+
broker_host = "localhost"
+
broker_port = 1883
+
topic = "capture/#"
+

+Notes

+

The MQTT broker must be running on the same address that has been set into the Siemens MindSphere settings. The root publishing topic (e.g. capture) is defined in the settings of the Siemens MindSphere application, while each acquisition procedure defined in the Edge internal webapp will append a unique identifier to the root topic (e.g. capture/mads). So, you typically want to subscribe to capture/# to get all the messages.

+

+Serial Reader

+

This acts as a source plugin, which reads messages from a serial port (typically connected to an Arduino) and sends them to the MADS broker.

+

The frequency of messages depends on the configuration of the Arduino board. The plugin will send the messages to the MADS broker as soon as they are received from the Arduino board. In turn, this frequency can be set in the configuration file (cfg_cmd parameter).

+

+Parameters

+

The accepted parameters are:

+
[serial_reader]
+
port="/dev/ttyACM0"
+
baudrate=115200
+
# Arduino config serial command
+
cfg_cmd = "40p"
+

+Notes

+

The cfg_cmd parameter is used to configure the Arduino board. The default value is 40p, which sets the Arduino board to send a message every 40 ms.

+

+Running average

+

This acts as a filter plugin, which calculates the running average of the input values.

+

+Parameters

+

The accepted parameters are:

+
[running_avg]
+
sub_topic = ["serial_reader"]
+
capa = 10 # running window size
+
field = "data" # agerage all values in the dictionary "data"
+
out_field = "avg" # output field
+

+Notes

+

It searches for a field in the message payload having the name specified in the field parameter. the data field must be a dictionary. of numerical values, e.g.:

+
{
+
"data": {
+
"value1": 1,
+
"value2": 2,
+
"value3": 3
+
}
+
}
+

The plugin will calculate the average of all the values in the dictionary and store it in a new field, whose name is specified in the out_field parameter:

+
{
+
"avg": {
+
"value1": 1,
+
"value2": 2,
+
"value3": 3
+
}
+
}
+