Commit 4e786e68 authored by Ivan Tyagov's avatar Ivan Tyagov

WIP:Implement heart_beats in this format <coupler_id>.heart_beats

parent 72a1342f
...@@ -141,7 +141,25 @@ void callbackTicHeartBeat() ...@@ -141,7 +141,25 @@ void callbackTicHeartBeat()
// 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");
UA_Float myFloat = HEART_BEATS;
// XXX: implement heart_beat like <ID>.<heart_beats>
int len = snprintf(NULL, 0, "%f", HEART_BEATS);
char *result1 = malloc(len + 1);
snprintf(result1, len + 1, "%d", HEART_BEATS);
int len1 = snprintf(NULL, 0, "%d", COUPLER_ID);
char *result2 = malloc(len1 + 1);
snprintf(result2, len1 + 1, "%d", COUPLER_ID);
// concat
strcat(result2, ".");
strcat(result2, result1);
char * end_ptr;
float final_result = strtof(result2, &end_ptr );
printf( "final_result: %f\n", 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]);
......
...@@ -26,10 +26,12 @@ static void dataChangeNotificationCallback(UA_Server *server, UA_UInt32 monitore ...@@ -26,10 +26,12 @@ static void dataChangeNotificationCallback(UA_Server *server, UA_UInt32 monitore
void *nodeContext, UA_UInt32 attributeId, void *nodeContext, UA_UInt32 attributeId,
const UA_DataValue *var) { const UA_DataValue *var) {
unsigned long int milli_seconds_now = getMilliSecondsSinceEpoch(); unsigned long int milli_seconds_now = getMilliSecondsSinceEpoch();
unsigned int coupler_id;
// filter out ID from Data Set // filter out ID from Data Set
/*
if(UA_Variant_hasScalarType(&var->value, &UA_TYPES[UA_TYPES_UINT32])) { if(UA_Variant_hasScalarType(&var->value, &UA_TYPES[UA_TYPES_UINT32])) {
unsigned int coupler_id = *(UA_UInt32*) var->value.data; coupler_id = *(UA_UInt32*) var->value.data;
// care for other coupler_id NOT ourselves // care for other coupler_id NOT ourselves
if (coupler_id!=COUPLER_ID) { if (coupler_id!=COUPLER_ID) {
UA_LOG_INFO(UA_Log_Stdout, \ UA_LOG_INFO(UA_Log_Stdout, \
...@@ -47,11 +49,22 @@ static void dataChangeNotificationCallback(UA_Server *server, UA_UInt32 monitore ...@@ -47,11 +49,22 @@ static void dataChangeNotificationCallback(UA_Server *server, UA_UInt32 monitore
} }
} }
*/
// 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); // split <ID>.<heart_beats>, just converting to int is enough
coupler_id = (int) heart_beat;
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "heart_beat = %f, id=%d", heart_beat, coupler_id);
// convert coupler_id to str
char* coupler_id_str = convertInt2Str(coupler_id);
// convert micro seconds to str
char* milli_seconds_now_str = convertLongInt2Str(milli_seconds_now);
// Add to our local linked list
addItem(&SUBSCRIBER_DICT, coupler_id_str, milli_seconds_now_str);
} }
} }
......
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