Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
osie
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Martin Manchev
osie
Commits
9e57550d
Commit
9e57550d
authored
Apr 12, 2022
by
Ivan Tyagov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP: add publish part.
parent
3cd553d5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
166 additions
and
0 deletions
+166
-0
coupler/opc-ua-server/keep_alive.h
coupler/opc-ua-server/keep_alive.h
+165
-0
coupler/opc-ua-server/server.c
coupler/opc-ua-server/server.c
+1
-0
No files found.
coupler/opc-ua-server/keep_alive.h
0 → 100644
View file @
9e57550d
#include <open62541/plugin/log_stdout.h>
#include <open62541/plugin/pubsub_ethernet.h>
#include <open62541/plugin/pubsub_udp.h>
#include <open62541/server.h>
#include <open62541/server_config_default.h>
#include <signal.h>
UA_NodeId
connectionIdent
,
publishedDataSetIdent
,
writerGroupIdent
;
static
void
addPubSubConnection
(
UA_Server
*
server
,
UA_String
*
transportProfile
,
UA_NetworkAddressUrlDataType
*
networkAddressUrl
){
/* Details about the connection configuration and handling are located
* in the pubsub connection tutorial */
UA_PubSubConnectionConfig
connectionConfig
;
memset
(
&
connectionConfig
,
0
,
sizeof
(
connectionConfig
));
connectionConfig
.
name
=
UA_STRING
(
"UADP Connection 1"
);
connectionConfig
.
transportProfileUri
=
*
transportProfile
;
connectionConfig
.
enabled
=
UA_TRUE
;
UA_Variant_setScalar
(
&
connectionConfig
.
address
,
networkAddressUrl
,
&
UA_TYPES
[
UA_TYPES_NETWORKADDRESSURLDATATYPE
]);
/* Changed to static publisherId from random generation to identify
* the publisher on Subscriber side */
connectionConfig
.
publisherId
.
numeric
=
2234
;
UA_Server_addPubSubConnection
(
server
,
&
connectionConfig
,
&
connectionIdent
);
}
/**
* **PublishedDataSet handling**
*
* The PublishedDataSet (PDS) and PubSubConnection are the toplevel entities and
* can exist alone. The PDS contains the collection of the published fields. All
* other PubSub elements are directly or indirectly linked with the PDS or
* connection. */
static
void
addPublishedDataSet
(
UA_Server
*
server
)
{
/* The PublishedDataSetConfig contains all necessary public
* information for the creation of a new PublishedDataSet */
UA_PublishedDataSetConfig
publishedDataSetConfig
;
memset
(
&
publishedDataSetConfig
,
0
,
sizeof
(
UA_PublishedDataSetConfig
));
publishedDataSetConfig
.
publishedDataSetType
=
UA_PUBSUB_DATASET_PUBLISHEDITEMS
;
publishedDataSetConfig
.
name
=
UA_STRING
(
"Demo PDS"
);
/* Create new PublishedDataSet based on the PublishedDataSetConfig. */
UA_Server_addPublishedDataSet
(
server
,
&
publishedDataSetConfig
,
&
publishedDataSetIdent
);
}
/**
* **DataSetField handling**
*
* The DataSetField (DSF) is part of the PDS and describes exactly one published
* field. */
static
void
addDataSetField
(
UA_Server
*
server
)
{
/* Add a field to the previous created PublishedDataSet */
UA_NodeId
dataSetFieldIdent
;
UA_DataSetFieldConfig
dataSetFieldConfig
;
memset
(
&
dataSetFieldConfig
,
0
,
sizeof
(
UA_DataSetFieldConfig
));
dataSetFieldConfig
.
dataSetFieldType
=
UA_PUBSUB_DATASETFIELD_VARIABLE
;
dataSetFieldConfig
.
field
.
variable
.
fieldNameAlias
=
UA_STRING
(
"Server localtime"
);
dataSetFieldConfig
.
field
.
variable
.
promotedField
=
UA_FALSE
;
dataSetFieldConfig
.
field
.
variable
.
publishParameters
.
publishedVariable
=
UA_NODEID_NUMERIC
(
0
,
UA_NS0ID_SERVER_SERVERSTATUS_CURRENTTIME
);
dataSetFieldConfig
.
field
.
variable
.
publishParameters
.
attributeId
=
UA_ATTRIBUTEID_VALUE
;
UA_Server_addDataSetField
(
server
,
publishedDataSetIdent
,
&
dataSetFieldConfig
,
&
dataSetFieldIdent
);
}
/**
* **WriterGroup handling**
*
* The WriterGroup (WG) is part of the connection and contains the primary
* configuration parameters for the message creation. */
static
void
addWriterGroup
(
UA_Server
*
server
)
{
/* Now we create a new WriterGroupConfig and add the group to the existing
* PubSubConnection. */
UA_WriterGroupConfig
writerGroupConfig
;
memset
(
&
writerGroupConfig
,
0
,
sizeof
(
UA_WriterGroupConfig
));
writerGroupConfig
.
name
=
UA_STRING
(
"Demo WriterGroup"
);
writerGroupConfig
.
publishingInterval
=
100
;
writerGroupConfig
.
enabled
=
UA_FALSE
;
writerGroupConfig
.
writerGroupId
=
100
;
writerGroupConfig
.
encodingMimeType
=
UA_PUBSUB_ENCODING_UADP
;
writerGroupConfig
.
messageSettings
.
encoding
=
UA_EXTENSIONOBJECT_DECODED
;
writerGroupConfig
.
messageSettings
.
content
.
decoded
.
type
=
&
UA_TYPES
[
UA_TYPES_UADPWRITERGROUPMESSAGEDATATYPE
];
/* The configuration flags for the messages are encapsulated inside the
* message- and transport settings extension objects. These extension
* objects are defined by the standard. e.g.
* UadpWriterGroupMessageDataType */
UA_UadpWriterGroupMessageDataType
*
writerGroupMessage
=
UA_UadpWriterGroupMessageDataType_new
();
/* Change message settings of writerGroup to send PublisherId,
* WriterGroupId in GroupHeader and DataSetWriterId in PayloadHeader
* of NetworkMessage */
writerGroupMessage
->
networkMessageContentMask
=
(
UA_UadpNetworkMessageContentMask
)(
UA_UADPNETWORKMESSAGECONTENTMASK_PUBLISHERID
|
(
UA_UadpNetworkMessageContentMask
)
UA_UADPNETWORKMESSAGECONTENTMASK_GROUPHEADER
|
(
UA_UadpNetworkMessageContentMask
)
UA_UADPNETWORKMESSAGECONTENTMASK_WRITERGROUPID
|
(
UA_UadpNetworkMessageContentMask
)
UA_UADPNETWORKMESSAGECONTENTMASK_PAYLOADHEADER
);
writerGroupConfig
.
messageSettings
.
content
.
decoded
.
data
=
writerGroupMessage
;
UA_Server_addWriterGroup
(
server
,
connectionIdent
,
&
writerGroupConfig
,
&
writerGroupIdent
);
UA_Server_setWriterGroupOperational
(
server
,
writerGroupIdent
);
UA_UadpWriterGroupMessageDataType_delete
(
writerGroupMessage
);
}
/**
* **DataSetWriter handling**
*
* A DataSetWriter (DSW) is the glue between the WG and the PDS. The DSW is
* linked to exactly one PDS and contains additional information for the
* message generation. */
static
void
addDataSetWriter
(
UA_Server
*
server
)
{
/* We need now a DataSetWriter within the WriterGroup. This means we must
* create a new DataSetWriterConfig and add call the addWriterGroup function. */
UA_NodeId
dataSetWriterIdent
;
UA_DataSetWriterConfig
dataSetWriterConfig
;
memset
(
&
dataSetWriterConfig
,
0
,
sizeof
(
UA_DataSetWriterConfig
));
dataSetWriterConfig
.
name
=
UA_STRING
(
"Demo DataSetWriter"
);
dataSetWriterConfig
.
dataSetWriterId
=
62541
;
dataSetWriterConfig
.
keyFrameCount
=
10
;
UA_Server_addDataSetWriter
(
server
,
writerGroupIdent
,
publishedDataSetIdent
,
&
dataSetWriterConfig
,
&
dataSetWriterIdent
);
}
/**
* That's it! You're now publishing the selected fields. Open a packet
* inspection tool of trust e.g. wireshark and take a look on the outgoing
* packages. The following graphic figures out the packages created by this
* tutorial.
*
* .. figure:: ua-wireshark-pubsub.png
* :figwidth: 100 %
* :alt: OPC UA PubSub communication in wireshark
*
* The open62541 subscriber API will be released later. If you want to process
* the the datagrams, take a look on the ``ua_network_pubsub_networkmessage.c``
* which already contains the decoding code for UADP messages.
*
* It follows the main server code, making use of the above definitions. */
/*
static int run(UA_String *transportProfile,
UA_NetworkAddressUrlDataType *networkAddressUrl) {
signal(SIGINT, stopHandler);
signal(SIGTERM, stopHandler);
UA_Server *server = UA_Server_new();
UA_ServerConfig *config = UA_Server_getConfig(server);
UA_ServerConfig_setDefault(config);
/*
/* Details about the connection configuration and handling are located in
* the pubsub connection tutorial */
/*
UA_ServerConfig_addPubSubTransportLayer(config, UA_PubSubTransportLayerUDPMP());
#ifdef UA_ENABLE_PUBSUB_ETH_UADP
UA_ServerConfig_addPubSubTransportLayer(config, UA_PubSubTransportLayerEthernet());
#endif
addPubSubConnection(server, transportProfile, networkAddressUrl);
addPublishedDataSet(server);
addDataSetField(server);
addWriterGroup(server);
addDataSetWriter(server);
UA_StatusCode retval = UA_Server_run(server, &running);
UA_Server_delete(server);
return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
}
*/
coupler/opc-ua-server/server.c
View file @
9e57550d
...
...
@@ -25,6 +25,7 @@
#include "common.h"
#include "mod_io_i2c.h"
#include "mod_io_opc_ua.h"
#include "keep_alive.h"
#include <time.h>
#include <open62541/plugin/log_stdout.h>
#include <open62541/server.h>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment