This is an old revision of the document!
Table of Contents
Using the TransSecs Native Wrapper to Characterize a Tool and Define a Host from C++
To use the TransSecs native wrapper for characterizing a tool and defining a host in C++, you will need the following files:
- 'transsecs.h'
- 'transsecs.hpp'
- 'transsecs.dll' (for Windows) or 'libtranssecs.so' (for Linux)
This article will guide you through the steps needed to define and start a host, characterize the tool, send messages, subscribe to topics, and define reports with associated CEIDs.
Defining and Starting a Host
To define and start a host, you need to set several configuration parameters using the 'publish' method. Once configured, you can start the host with the 'startMain' method. Here is an example:
#include <iostream> #include "transsecs.hpp" #include <thread> #include <chrono> #include <fstream> int main(int argc, char **argv) { transsecs::TransSecsWrapper* wrapper = new transsecs::TransSecsWrapper(); int port = 5010; wrapper->publish("gemhost/configuration/persistencefilename", "/tmp/testpersistence"); wrapper->publish("gemhost/configuration/equipmenthostname", "localhost"); wrapper->publish("gemhost/configuration/deviceid", 1); wrapper->publish("gemhost/configuration/activeport", port); // For most cases, this should always be "GEMHost" wrapper->startMain("GEMHost"); // Additional code follows... }
Characterizing the Tool
Characterizing the tool involves capturing the GEM model configuration. The 'characterize' method generates a JSON representation of the tool's configuration, which can be saved to a file:
// Characterizing the tool and saving the JSON to a file std::string json = wrapper->characterize(); std::ofstream outputFile("characterized.json"); outputFile << json; outputFile.close();
Sending Messages
To send messages, use the 'publish' method with the appropriate topic and message content. Here is an example of sending an 's2f41' (host command) and an 's1f3' (SVID request):
// Send an example s2f41 (host command). std::string s2f41 = R"({"Command":{"value":"START","type":20},"CommandParams":{"values":[{"values":["PPID","recipe_name"]},{"values":[{"value":"slotmap","type":20},{"values":[0,1,1,0],"type":51}]}]}})"; wrapper->publish("gemhost/hostcommand/sendmessage", s2f41); wrapper->publish("gemhost/svidrequest/sendmessage", "{\"SVID\": { \"value\":\"33003\", \"type\":54 }}");
Summary of JSON Format for publishing
In this JSON format:
- The 'value' property is used to represent a single item.
- The 'values' property is used to represent an array of items.
In both cases, the value itself must be a JSON string, and not a number, even for numeric types.
Note that types are SECS standard types.
'value' Property
- Holds a single object or primitive value.
- Example:
{ "value": "START", "type": 20 }
'values' Property
- Holds an array of items.
- There are two ways to write an array in this format:
- With a single 'type' for the entire array:
- The 'type' specifies the type for all elements in the array.
- Example:
{ "values": ["PPID", "recipe_name"], "type": 20 }
- With nested objects having individual 'type' properties:
- Each element can have its own 'value' and 'type'.
- Example:
{ "values": [ { "value": "slotmap", "type": 20 }, { "values": [0, 1, 1, 0], "type": 51 } ] }
This format allows flexibility in defining both simple and complex data structures with explicit type information for each element.
Defining a HostCommand (S2F41)
Root Object
- Contains two main properties: '“Command”' and '“CommandParams”'.
"Command" Object
- Properties:
'“value”': A string representing the command (e.g., '“START”').
'"type"': An integer representing the
SECS type (e.g., '20' for ASCII strings).
"CommandParams" Object
- Property:
'“values”': An array containing parameter objects.
Parameter Objects
- Each parameter can either be a simple list or a nested structure.
- Simple List:
Contains a '“values”' array and a '“type”' indicating the type of the list elements.
Example:
{ "values": ["PPID", "recipe_name"], "type": 20 }
- Nested Structure:
Contains a '“values”' array with nested objects, each with their own '“value”' and '“type”'.
Example:
{ "values": [ { "value": "slotmap", "type": 20 }, { "values": [0, 1, 1, 0], "type": 51 } ] }
Publishing
Publish your json to “gemhost/hostcommand/sendmessage”
Defining an SVIDRequest (S1F3)
SVID request is much simpler; you publish a single value to “gemhost/svidrequest/sendmessage” into an “SVID” key. For example:
{ "SVID": "33003", "type": 54 }
Notice again that the SVID must be a string, even though it has a numeric type.
Subscribing to Topics
Subscribing to topics allows you to receive updates for specific variables. Use the 'subscribe' method to listen for changes on desired topics:
<code cpp>
// Subscribe to CEID events
wrapper->subscribe("gemhost/variables/ceid/loaded",
[](const char* topic, the transsecs::TransSecsValueObject* value) {
std::cout << "Received topic: " << topic << std::endl;
std::cout << "Received value: " << value->getValue()->getStringValue() << std
