SebyOne Srl – Solo Logo Centrale

How to create a DaaS-Qt node

Overview

This documentation describes the implementation of a QDaaSnode application using Qt. The application provides a graphical interface for initializing, configuring, and managing communication between DaaS nodes.

Application Structure

Main Application (main.cpp)

The main application file initializes the Qt environment and registers the QDaaS backend with the QML engine.

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <qdaas.h>

int main(int argc, char *argv[])
{
   QGuiApplication
app(argc, argv);
   
   QQmlApplicationEngine engine;

   QDaaS daas;
   qmlRegisterType<QDaaS>(
"QDaaS", 1, 0, "QDaaS");
   engine.rootContext()->setContextProperty(
"QDaaS", &daas);

   QObject::connect(
       &engine,
       &QQmlApplicationEngine::objectCreationFailed,
       &app,
       []() { QCoreApplication::
exit(-1); },
       Qt::QueuedConnection);
   engine.loadFromModule(
"QDaaSNode", "Main");

   
return app.exec();
}

Description: The main function creates the GUI application and sets up the QML engine. It registers the QDaaS class as a QML type and makes it available to the QML interface through the context property "QDaaS". The application loads the Main.qml file from the "QDaaSNode" module.

Key Components:

  • QGuiApplication: Manages the GUI application lifecycle
  • QQmlApplicationEngine: Handles QML file loading and execution
  • QDaaS Registration: Makes the C++ QDaaS class available to QML
  • Error Handling: Exits the application if QML object creation fails

Main.qml

The QML interface provides a comprehensive control panel for managing DaaS node operations.

Application Window Configuration

ApplicationWindow {
   
visible: true
   
title: "QDaaS Node"
   
maximumWidth: 600
   
minimumWidth: 600
   
maximumHeight: 750
   
minimumHeight: 750
   
   
property int staticHeight: 40;
   
property int locatedDin: 0;
}

Description: Defines the main application window with fixed dimensions (600×750) and establishes global properties for UI element height and the currently located DIN.

Settings Menu

Menu {
   
id: menu
   
MenuItem {
       
text: "Save configuration"
       
onClicked: {
           
if(sid.text !== "" &&
              din.text !==
"" &&
              link_t_enable.currentIndex !==
0 &&
              uri_enable !==
""){
              saveConfig(sid.text, din.text, link_t_enable.currentIndex, uri_enable.text);
               doneText.text  =
"Configuration saved!"
               done.open();
           }
else{
               errorText.text  =
"You must initializate driver and enable it first!";
               error.open();
           }
       }
   }
   
MenuItem{
       
text: "Take existing configuration"
       
onClicked: configNode()
   }
}

Description: Provides configuration management functionality allowing users to save current settings or load existing configurations. The save operation validates that all required fields are populated before proceeding.

Node Initialization

Row {
   
id: initialization
   
TextField {
       
id: sid
       
placeholderText: "SID"
   }
   
TextField {
       
id: din
       
placeholderText: "DIN"
   }
   
Button {
       
text: "Initialize"
       
onClicked: {
           
var init_status = QDaaS.doInit(sid.text, din.text);
           
if (init_status > -1){
               doneText.text =
"Agent initialized!\nSID: " + sid.text + " with DIN: " + din.text;
               done.open();
               sid.enabled =
false
               din.enabled =
false
               initButton.enabled =
false
           }
else{
               errorText.text = (
"Enable error (" + QDaaS.getError(init_status) + ")");
               error.open();
           }
       }
   }
}

Description: Handles node initialization by collecting SID (System Identifier) and DIN (Device Identifier) values from the user and calling the QDaaS.doInit() method. Upon successful initialization, the input fields are disabled to prevent modification.

Parameters:

  • SID: System/Network identifier
  • DIN: Device identifier within the network

Return Handling:

  • Success (>-1): Displays confirmation message and disables input fields
  • Failure (≤-1): Shows error message with specific error code

Driver Configuration

Row {
   
id: enableDriver
   
ComboBox {
       
id: link_t_enable
       
model: ["None", "DAAS", "INET4", "MQTT5", "UART"]
   }
   
TextField {
       
id: uri_enable
       
placeholderText: "URI"
   }
   
Button {
       
text: "Enable driver"
       
onClicked: {
           
var enable_status = QDaaS.enableDriver(link_t_enable.currentIndex, uri_enable.text);
           
if(link_t_enable.currentIndex > 0 && uri_enable.text !== ""){
               
if (enable_status === 0){
                   doneText.text = (
"Current DIN enabled on link: " + link_t_enable.currentIndex + "\n with uri: " + uri_enable.text);
                   done.open();
                   link_t_enable.enabled =
false;
                   uri_enable.enabled =
false;
               }
else{
                   errorText.text = (
"Enable error (" + QDaaS.getError(enable_status) + ")");
                   error.open();
               }
           }
       }
   }
}

Description: Configures and enables communication drivers for the node. Users select a connection type from the dropdown and specify the corresponding URI. The interface validates that both fields are properly configured before enabling the driver.

Parameters:

  • Link Type: Index of the selected connection type
  • URI: Connection string for the selected protocol

Remote Node Mapping

Row {
   
id: map
   
TextField {
       
id: remote_din_map
       
placeholderText: "Remote DIN"
   }
   
ComboBox {
       
id: link_t_map
       
model: ["None", "DAAS", "INET4", "MQTT5", "UART"]
   }
   
TextField {
       
id: uri_map
       
placeholderText: "URI"
   }
   
TextField {
       
id: skey_map
       
placeholderText: "SKEY"
   }
   
Button {
       
text: "Map"
       
onClicked: {
           
var map_status = QDaaS.map(remote_din_map.text,
                     link_t_map.currentIndex,
                     uri_map.text,
                     skey_map.text);
           
if (map_status === 0){
               doneText.text = (
"Mapped DIN: " + remote_din_map.text + "\nwith link TYPE: " + link_t_map.text + " and URI: "
                                 + uri_map.text +
"\nmapped with SKEY:" + skey_map.text);
               done.open();
           }
else{
               errorText.text+= (
"Map error (" + QDaaS.getError(map_status) + ")");
               error.open();
           }
       }
   }
}

Description: Establishes a mapping relationship with a remote DaaS node. This process associates the remote node's DIN with connection parameters and optional security credentials.

Parameters:

  • Remote DIN: Identifier of the target remote node
  • Link Type: Communication protocol to use for the connection
  • URI: Connection endpoint for the remote node
  • SKEY: Security key for authenticated communication (optional)

Node Performance Activation

Button {
   
text: "Perform"
   
onClicked: {
       
var perf_status = QDaaS.perform();
       
if (perf_status === 0){
           doneText.text = (
"Performed");
           done.open();
       }
else{
           errorText.text = (
"Perform error (" + QDaaS.getError(locate_status) + ")");
           error.open();
       }
   }
}

Description: Activates the node's operational state by starting all configured drivers and enabling the core communication engine in threaded mode. This step is required before the node can participate in network communications.

Node Location

Row {
   
id: locate
   
TextField {
       
id: locate_remote_din
       
placeholderText: "Remote DIN"
   }
   
Button {
       
text: "Locate"
       
onClicked: {
           locatedDin =
parseInt(locate_remote_din.text);
           
if (!isNaN(locatedDin)) {
               
var locate_status = QDaaS.locate(locate_remote_din.text);
               
if (locate_status === 0){
                   doneText.text = (
"Current DIN: " + locatedDin + " located");
                   done.open();
               }
else{
                   errorText.text = (
"Locate error (" + QDaaS.getError(locate_status) + ")");
                   error.open();
               }
               output_area.text += (
"You are talking with >" + locatedDin + "\n");
           }
else {
               errorText.text =
"Please enter a valid integer for Remote DIN";
               error.open();
           }
       }
   }
}

Description: Performs network discovery to locate and establish communication with a specific remote node. The function validates the DIN format and updates the global locatedDin property for subsequent communication operations.

Parameters:

  • Remote DIN: Target node identifier to locate

Validation:

  • Ensures the input is a valid integer
  • Updates conversation context upon successful location

Message Communication

Row {
   
TextField {
       
id: message_field
       
placeholderText: "Type a message…"
       
width: parent.width * 0.75
   }
   
Button {
       
text: "Send"
       
onClicked: {
           
var push_status = QDaaS.push(locatedDin.toString(),message_field.text,"10");
           
if (push_status === 0){
               doneText.text = (
"Push: " + message_field.text);
               done.open();
           }
else{
               errorText.text =
"Error: " + QDaaS.getError(push_status);
               error.open();
           }
           output_area.text += (message_field.text +
"\n");
       }
   }
}

Description: Provides message transmission functionality to send text data to the currently located remote node. Messages are sent using typeset 10 and displayed in the output area for user reference.

Parameters:

  • Target DIN: Uses the globally stored locatedDin value
  • Message: Text content from the input field
  • Typeset: Fixed value "10" for text message type

Output and Logging

ScrollView {
   
TextArea {
       
id: output_area
       
readOnly: true
       
wrapMode: TextArea.Wrap
       
placeholderText: "Logs and messages will appear here…"
   }
}

ScrollView {
   
TextArea {
       
id: log_area
       
readOnly: true
       
wrapMode: TextArea.Wrap
       
placeholderText: "Logs will appear here…"
   }
}

Description: Provides separate areas for displaying communication messages and system logs. Both areas are read-only and support text wrapping for better readability.

Event Handling

Message Reception

Connections{
   
target: QDaaS
   
onPullEvent: (ddoStatus, payload)=>{
       output_area.text += payload +
"\n";
   }
}

Description: Handles incoming messages from remote nodes. When a message is received, it is automatically displayed in the output area.

System Logging

Connections{
   
target: QDaaS
   
onSendLogs: (log)=>{
       log_area.text += (
"[" +locatedDin + "]" + log + "\n");
   }
}

Description: Processes system log messages and displays them in the dedicated log area with the current target DIN as context.

SebyOne Srl – Ultra Compact Footer