Commit f5265d02 authored by Ivan Tyagov's avatar Ivan Tyagov

When a coupler is in a DOWN state it must NOT

increase it heart beats which itself will cause
dependent couplers to detect that a coupler is DOWN.
parent 5d3573e2
...@@ -39,7 +39,7 @@ char *NETWORK_INTERFACE = ""; ...@@ -39,7 +39,7 @@ char *NETWORK_INTERFACE = "";
static unsigned int HEART_BEATS = 0; static unsigned int HEART_BEATS = 0;
// handling coupler's state // handling coupler's state
static unsigned int CURRENT_STATE; static int CURRENT_STATE=-1;
const int STATE_UP = 1; const int STATE_UP = 1;
const int STATE_DOWN = 0; const int STATE_DOWN = 0;
const int STATE_NO_INITIAL_HEART_BEAT = 2; const int STATE_NO_INITIAL_HEART_BEAT = 2;
......
...@@ -147,33 +147,35 @@ static void addPubSubDataSetField(UA_Server *server, PublishedVariable varDetail ...@@ -147,33 +147,35 @@ static void addPubSubDataSetField(UA_Server *server, PublishedVariable varDetail
void callbackTicHeartBeat() void callbackTicHeartBeat()
{ {
/* Increase periodically heart beats of the server */ if (CURRENT_STATE != STATE_DOWN) {
HEART_BEATS += 1; /* Increase periodically heart beats of the server */
HEART_BEATS += 1;
// set OPC UA's heat_beat node value // set OPC UA's heat_beat node value
UA_NodeId myFloatNodeId = UA_NODEID_STRING(1, "heart_beat"); UA_NodeId myFloatNodeId = UA_NODEID_STRING(1, "heart_beat");
// heart_beat format is <ID_of_coupler>.<heart_beats> // heart_beat format is <ID_of_coupler>.<heart_beats>
int len = snprintf(NULL, 0, "%d", HEART_BEATS); int len = snprintf(NULL, 0, "%d", HEART_BEATS);
char *result1 = malloc(len + 1); char *result1 = malloc(len + 1);
snprintf(result1, len + 1, "%d", HEART_BEATS); snprintf(result1, len + 1, "%d", HEART_BEATS);
int len1 = snprintf(NULL, 0, "%d", COUPLER_ID); int len1 = snprintf(NULL, 0, "%d", COUPLER_ID);
char *result2 = malloc(len1 + 1); char *result2 = malloc(len1 + 1);
snprintf(result2, len1 + 1, "%d", COUPLER_ID); snprintf(result2, len1 + 1, "%d", COUPLER_ID);
// concat // concat
strcat(result2, "."); strcat(result2, ".");
strcat(result2, result1); strcat(result2, result1);
char * end_ptr; char * end_ptr;
float final_result = strtof(result2, &end_ptr ); float final_result = strtof(result2, &end_ptr );
UA_Float myFloat = final_result; UA_Float myFloat = final_result;
UA_Variant myVar; UA_Variant myVar;
UA_Variant_init(&myVar); UA_Variant_init(&myVar);
UA_Variant_setScalar(&myVar, &myFloat, &UA_TYPES[UA_TYPES_FLOAT]); UA_Variant_setScalar(&myVar, &myFloat, &UA_TYPES[UA_TYPES_FLOAT]);
UA_Server_writeValue(server, myFloatNodeId, myVar); UA_Server_writeValue(server, myFloatNodeId, myVar);
}
} }
static void enablePublishHeartBeat(UA_Server *server){ static void enablePublishHeartBeat(UA_Server *server){
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment