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
Nikola Balog
osie
Commits
19633145
Commit
19633145
authored
Apr 21, 2022
by
Ivan Tyagov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move to a dedicated file.
parent
211bcc7a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
58 deletions
+67
-58
coupler/opc-ua-server/keep_alive.h
coupler/opc-ua-server/keep_alive.h
+64
-0
coupler/opc-ua-server/server.c
coupler/opc-ua-server/server.c
+3
-58
No files found.
coupler/opc-ua-server/keep_alive.h
View file @
19633145
/*
Keep alive implementation for couplers based on OPC UA's pub/sub mechanism
*/
// global HEART BEATs of coupler$
static
unsigned
int
HEART_BEATS
=
0
;
// the heart beat interval$
static
int
HEART_BEAT_INTERVAL
=
250
;
// both publisher and subscriber should use same publisher id
const
int
PUBLISHER_ID
=
2234
;
...
...
@@ -137,3 +144,60 @@ static void addPubSubDataSetField(UA_Server *server, PublishedVariable varDetail
UA_Server_addDataSetField
(
server
,
publishedDataSetIdent
,
&
dataSetFieldConfig
,
&
dataSetFieldIdent
);
}
void
callbackTicHeartBeat
()
{
/* Increase periodically heart beats of the server */
HEART_BEATS
+=
1
;
UA_LOG_INFO
(
UA_Log_Stdout
,
UA_LOGCATEGORY_USERLAND
,
"heart_beat %d"
,
HEART_BEATS
);
// set OPC UA's heat_beat node value
UA_NodeId
myIntegerNodeId
=
UA_NODEID_STRING
(
1
,
"heart_beat"
);
UA_UInt32
myInteger
=
HEART_BEATS
;
UA_Variant
myVar
;
UA_Variant_init
(
&
myVar
);
UA_Variant_setScalar
(
&
myVar
,
&
myInteger
,
&
UA_TYPES
[
UA_TYPES_UINT32
]);
UA_Server_writeValue
(
server
,
myIntegerNodeId
,
myVar
);
}
static
void
enablePublishHeartBeat
(
UA_Server
*
erver
,
UA_ServerConfig
*
config
){
int
i
;
// add a callback which will increment heart beat tics
UA_UInt64
callbackId
=
1
;
UA_Server_addRepeatedCallback
(
server
,
callbackTicHeartBeat
,
NULL
,
HEART_BEAT_INTERVAL
,
&
callbackId
);
UA_UInt32
defaultUInt32
=
0
;
UA_UInt32
couplerID
=
COUPLER_ID
;
const
PublishedVariable
publishedVariableArray
[]
=
{
// representing time in millis since start of process
{
.
name
=
"heart_beat"
,
.
description
=
"Heart beat"
,
.
pdefaultValue
=
&
defaultUInt32
,
.
type
=
UA_TYPES_UINT32
},
// representing the ID of the coupler
{
.
name
=
"id"
,
.
description
=
"ID"
,
.
pdefaultValue
=
&
couplerID
,
.
type
=
UA_TYPES_UINT32
}
};
UA_String
transportProfile
=
UA_STRING
(
"http://opcfoundation.org/UA-Profile/Transport/pubsub-udp-uadp"
);
UA_NetworkAddressUrlDataType
networkAddressUrl
=
{
UA_STRING_NULL
,
UA_STRING
(
"opc.udp://224.0.0.22:4840/"
)};
UA_ServerConfig_addPubSubTransportLayer
(
config
,
UA_PubSubTransportLayerUDPMP
());
addPubSubConnection
(
server
,
&
transportProfile
,
&
networkAddressUrl
);
addPublishedDataSet
(
server
);
for
(
i
=
0
;
i
<
countof
(
publishedVariableArray
);
i
++
)
{
addPubSubVariable
(
server
,
publishedVariableArray
[
i
]);
addPubSubDataSetField
(
server
,
publishedVariableArray
[
i
]);
}
addWriterGroup
(
server
);
addDataSetWriter
(
server
);
}
coupler/opc-ua-server/server.c
View file @
19633145
...
...
@@ -25,7 +25,6 @@
#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>
...
...
@@ -37,15 +36,11 @@
// global Id of coupler
static
int
COUPLER_ID
=
0
;
// global HEART BEATs of coupler
static
unsigned
int
HEART_BEATS
=
0
;
// the heart beat interval
static
int
HEART_BEAT_INTERVAL
=
250
;
// global server
UA_Server
*
server
;
#include "keep_alive.h"
// The default port of OPC-UA server
const
int
DEFAULT_OPC_UA_PORT
=
4840
;
const
int
DEFAULT_MODE
=
0
;
...
...
@@ -131,20 +126,6 @@ static void stopHandler(int sign)
running
=
false
;
}
void
callbackTicHeartBeat
()
{
/* Increase periodically heart beats of the server */
HEART_BEATS
+=
1
;
UA_LOG_INFO
(
UA_Log_Stdout
,
UA_LOGCATEGORY_USERLAND
,
"heart_beat %d"
,
HEART_BEATS
);
// set OPC UA's heat_beat node value
UA_NodeId
myIntegerNodeId
=
UA_NODEID_STRING
(
1
,
"heart_beat"
);
UA_UInt32
myInteger
=
HEART_BEATS
;
UA_Variant
myVar
;
UA_Variant_init
(
&
myVar
);
UA_Variant_setScalar
(
&
myVar
,
&
myInteger
,
&
UA_TYPES
[
UA_TYPES_UINT32
]);
UA_Server_writeValue
(
server
,
myIntegerNodeId
,
myVar
);
}
int
main
(
int
argc
,
char
**
argv
)
{
...
...
@@ -254,43 +235,7 @@ int main(int argc, char **argv)
#endif
// enable keep-alive
// add a callback which will increment heart beat tics
UA_UInt64
callbackId
=
1
;
UA_Server_addRepeatedCallback
(
server
,
callbackTicHeartBeat
,
NULL
,
HEART_BEAT_INTERVAL
,
&
callbackId
);
UA_UInt32
defaultUInt32
=
0
;
UA_UInt32
couplerID
=
COUPLER_ID
;
const
PublishedVariable
publishedVariableArray
[]
=
{
// representing time in millis since start of process
{
.
name
=
"heart_beat"
,
.
description
=
"Heart beat"
,
.
pdefaultValue
=
&
defaultUInt32
,
.
type
=
UA_TYPES_UINT32
},
// representing the ID of the coupler
{
.
name
=
"id"
,
.
description
=
"ID"
,
.
pdefaultValue
=
&
couplerID
,
.
type
=
UA_TYPES_UINT32
}
};
UA_String
transportProfile
=
UA_STRING
(
"http://opcfoundation.org/UA-Profile/Transport/pubsub-udp-uadp"
);
UA_NetworkAddressUrlDataType
networkAddressUrl
=
{
UA_STRING_NULL
,
UA_STRING
(
"opc.udp://224.0.0.22:4840/"
)};
UA_ServerConfig_addPubSubTransportLayer
(
config
,
UA_PubSubTransportLayerUDPMP
());
addPubSubConnection
(
server
,
&
transportProfile
,
&
networkAddressUrl
);
addPublishedDataSet
(
server
);
for
(
i
=
0
;
i
<
countof
(
publishedVariableArray
);
i
++
)
{
addPubSubVariable
(
server
,
publishedVariableArray
[
i
]);
addPubSubDataSetField
(
server
,
publishedVariableArray
[
i
]);
}
addWriterGroup
(
server
);
addDataSetWriter
(
server
);
enablePublishHeartBeat
(
server
,
config
);
// run server
UA_StatusCode
retval
=
UA_Server_run
(
server
,
&
running
);
...
...
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