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
1
Merge Requests
1
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
nexedi
osie
Commits
a46874c3
Commit
a46874c3
authored
Apr 28, 2022
by
Ivan Tyagov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add heart beat check to an asynchronous callback.
parent
96f3df31
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
25 deletions
+33
-25
coupler/opc-ua-server/coupler1.sh
coupler/opc-ua-server/coupler1.sh
+1
-1
coupler/opc-ua-server/coupler2.sh
coupler/opc-ua-server/coupler2.sh
+1
-1
coupler/opc-ua-server/coupler3.sh
coupler/opc-ua-server/coupler3.sh
+1
-1
coupler/opc-ua-server/keep_alive_subscriber.h
coupler/opc-ua-server/keep_alive_subscriber.h
+30
-22
No files found.
coupler/opc-ua-server/coupler1.sh
View file @
a46874c3
#!/bin/bash
#!/bin/bash
./server
-m
1
-b
1
-i
1
-l
2,3
-t
1
00
./server
-m
1
-b
1
-i
1
-l
2,3
-t
5
00
coupler/opc-ua-server/coupler2.sh
View file @
a46874c3
#!/bin/bash
#!/bin/bash
./server
-p
4841
-m
1
-b
1
-i
2
-l
1,3
-t
1
00
./server
-p
4841
-m
1
-b
1
-i
2
-l
1,3
-t
5
00
coupler/opc-ua-server/coupler3.sh
View file @
a46874c3
#!/bin/bash
#!/bin/bash
./server
-p
4842
-m
1
-b
1
-i
3
-l
1,2
-t
1
00
./server
-p
4842
-m
1
-b
1
-i
3
-l
1,2
-t
5
00
coupler/opc-ua-server/keep_alive_subscriber.h
View file @
a46874c3
...
@@ -34,40 +34,20 @@ static void dataChangeNotificationCallback(UA_Server *server, UA_UInt32 monitore
...
@@ -34,40 +34,20 @@ static void dataChangeNotificationCallback(UA_Server *server, UA_UInt32 monitore
if
(
coupler_id
!=
COUPLER_ID
)
{
if
(
coupler_id
!=
COUPLER_ID
)
{
//HEART_BEAT_ID_LIST
//HEART_BEAT_ID_LIST
UA_LOG_INFO
(
UA_Log_Stdout
,
UA_LOGCATEGORY_USERLAND
,
"Got heart beat from ID = %d, timestamp=%ld"
,
coupler_id
,
micro_seconds
);
UA_LOG_INFO
(
UA_Log_Stdout
,
UA_LOGCATEGORY_USERLAND
,
"Got heart beat from ID = %d, timestamp=%ld"
,
coupler_id
,
micro_seconds
);
// convert coupler_id to str
// convert coupler_id to str
char
*
coupler_id_str
=
convertInt2Str
(
coupler_id
);
char
*
coupler_id_str
=
convertInt2Str
(
coupler_id
);
// convert micro seconds to str
// convert micro seconds to str
char
*
micro_seconds_str
=
convertLongInt2Str
(
micro_seconds
);
char
*
micro_seconds_str
=
convertLongInt2Str
(
micro_seconds
);
// XXX: implement check for dead couplers using asynchronous callbacks from open62541
int
i
,
id
;
size_t
n
=
sizeof
(
HEART_BEAT_ID_LIST
)
/
sizeof
(
HEART_BEAT_ID_LIST
[
0
]);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
id
=
HEART_BEAT_ID_LIST
[
i
];
if
(
id
>
0
)
{
// convert to str as this is the hash key
char
*
id_str
=
convertInt2Str
(
id
);
char
*
last_seen_timestamp
=
getItem
(
SUBSCRIBER_DICT
,
id_str
);
UA_LOG_INFO
(
UA_Log_Stdout
,
UA_LOGCATEGORY_USERLAND
,
"
\t
check ID=%s, last_seen=%s"
,
id_str
,
last_seen_timestamp
);
if
(
last_seen_timestamp
!=
NULL
){
// we do have timestamp for this coupler ID
int
last_seen_timestamp_int
=
atoi
(
last_seen_timestamp
);
int
timestamp_delta
=
micro_seconds
-
last_seen_timestamp_int
;
bool
is_down
=
(
timestamp_delta
>
1000
);
UA_LOG_INFO
(
UA_Log_Stdout
,
UA_LOGCATEGORY_USERLAND
,
"
\t\t
delta=%d, is_down=%d"
,
timestamp_delta
,
is_down
);
}
}
}
// Add to our local linked list
// Add to our local linked list
addItem
(
&
SUBSCRIBER_DICT
,
coupler_id_str
,
micro_seconds_str
);
addItem
(
&
SUBSCRIBER_DICT
,
coupler_id_str
,
micro_seconds_str
);
}
}
}
}
// filter out heart_beat
from Data Set
// filter out heart_beat from Data Set
if
(
UA_Variant_hasScalarType
(
&
var
->
value
,
&
UA_TYPES
[
UA_TYPES_FLOAT
]))
{
if
(
UA_Variant_hasScalarType
(
&
var
->
value
,
&
UA_TYPES
[
UA_TYPES_FLOAT
]))
{
float
heart_beat
=
*
(
UA_Float
*
)
var
->
value
.
data
;
float
heart_beat
=
*
(
UA_Float
*
)
var
->
value
.
data
;
//UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "heart_beat = %f", heart_beat);
//UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "heart_beat = %f", heart_beat);
...
@@ -275,6 +255,30 @@ static void fillTestDataSetMetaData(UA_DataSetMetaDataType *pMetaData) {
...
@@ -275,6 +255,30 @@ static void fillTestDataSetMetaData(UA_DataSetMetaDataType *pMetaData) {
pMetaData
->
fields
[
1
].
valueRank
=
-
1
;
/* scalar */
pMetaData
->
fields
[
1
].
valueRank
=
-
1
;
/* scalar */
}
}
void
callbackCheckHeartBeat
()
{
int
i
,
coupler_id
;
long
int
micro_seconds
=
getMicroSeconds
();
size_t
n
=
sizeof
(
HEART_BEAT_ID_LIST
)
/
sizeof
(
HEART_BEAT_ID_LIST
[
0
]);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
coupler_id
=
HEART_BEAT_ID_LIST
[
i
];
if
(
coupler_id
>
0
)
{
// convert to str as this is the hash key
char
*
coupler_id_str
=
convertInt2Str
(
coupler_id
);
char
*
last_seen_timestamp
=
getItem
(
SUBSCRIBER_DICT
,
coupler_id_str
);
UA_LOG_INFO
(
UA_Log_Stdout
,
UA_LOGCATEGORY_USERLAND
,
"Check ID=%s, last_seen=%s"
,
coupler_id_str
,
last_seen_timestamp
);
if
(
last_seen_timestamp
!=
NULL
){
// we do have timestamp for this coupler ID
int
last_seen_timestamp_int
=
atoi
(
last_seen_timestamp
);
int
timestamp_delta
=
micro_seconds
-
last_seen_timestamp_int
;
bool
is_down
=
(
timestamp_delta
>
1000
);
UA_LOG_INFO
(
UA_Log_Stdout
,
UA_LOGCATEGORY_USERLAND
,
"
\t
delta=%d, is_down=%d"
,
timestamp_delta
,
is_down
);
}
}
}
}
static
int
enableSubscribeToHeartBeat
(
UA_Server
*
server
,
UA_ServerConfig
*
config
){
static
int
enableSubscribeToHeartBeat
(
UA_Server
*
server
,
UA_ServerConfig
*
config
){
// enable subscribe to keep-alive messages
// enable subscribe to keep-alive messages
UA_String
transportProfile
=
UA_STRING
(
DEFAULT_TRANSPORT_PROFILE
);
UA_String
transportProfile
=
UA_STRING
(
DEFAULT_TRANSPORT_PROFILE
);
...
@@ -289,4 +293,8 @@ static int enableSubscribeToHeartBeat(UA_Server *server, UA_ServerConfig *config
...
@@ -289,4 +293,8 @@ static int enableSubscribeToHeartBeat(UA_Server *server, UA_ServerConfig *config
/* Add SubscribedVariables to the created DataSetReader */
/* Add SubscribedVariables to the created DataSetReader */
addSubscribedVariables
(
server
,
readerIdentifier
);
addSubscribedVariables
(
server
,
readerIdentifier
);
// add a callback which will check related coupler's heart beats
UA_UInt64
callbackId
=
2
;
UA_Server_addRepeatedCallback
(
server
,
callbackCheckHeartBeat
,
NULL
,
HEART_BEAT_INTERVAL
,
&
callbackId
);
}
}
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