Commit d37dad6a authored by Ivan Tyagov's avatar Ivan Tyagov

Use floats for heart_beat and int for Id so we can distinguish fields inside a...

Use floats for heart_beat and int for Id so we can distinguish fields inside a data set at subscriber side.
parent c04bb689
...@@ -157,12 +157,12 @@ void callbackTicHeartBeat() ...@@ -157,12 +157,12 @@ void callbackTicHeartBeat()
//UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "heart_beat %d", HEART_BEATS); //UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "heart_beat %d", HEART_BEATS);
// set OPC UA's heat_beat node value // set OPC UA's heat_beat node value
UA_NodeId myIntegerNodeId = UA_NODEID_STRING(1, "heart_beat"); UA_NodeId myFloatNodeId = UA_NODEID_STRING(1, "heart_beat");
UA_UInt32 myInteger = HEART_BEATS; UA_Float myFloat = HEART_BEATS;
UA_Variant myVar; UA_Variant myVar;
UA_Variant_init(&myVar); UA_Variant_init(&myVar);
UA_Variant_setScalar(&myVar, &myInteger, &UA_TYPES[UA_TYPES_UINT32]); UA_Variant_setScalar(&myVar, &myFloat, &UA_TYPES[UA_TYPES_FLOAT]);
UA_Server_writeValue(server, myIntegerNodeId, myVar); UA_Server_writeValue(server, myFloatNodeId, myVar);
} }
...@@ -174,13 +174,14 @@ static void enablePublishHeartBeat(UA_Server *server, UA_ServerConfig *config){ ...@@ -174,13 +174,14 @@ static void enablePublishHeartBeat(UA_Server *server, UA_ServerConfig *config){
UA_UInt32 defaultUInt32 = 0; UA_UInt32 defaultUInt32 = 0;
UA_UInt32 couplerID = COUPLER_ID; UA_UInt32 couplerID = COUPLER_ID;
UA_Float defaultFloat = 0.0;
const PublishedVariable publishedVariableArray[] = { const PublishedVariable publishedVariableArray[] = {
// representing time in millis since start of process // representing time in millis since start of process
{ {
.name = "heart_beat", .name = "heart_beat",
.description = "Heart beat", .description = "Heart beat",
.pdefaultValue = &defaultUInt32, .pdefaultValue = &defaultFloat,
.type = UA_TYPES_UINT32 .type = UA_TYPES_FLOAT
}, },
// representing the ID of the coupler // representing the ID of the coupler
{ {
......
...@@ -28,10 +28,17 @@ static void dataChangeNotificationCallback(UA_Server *server, UA_UInt32 monitore ...@@ -28,10 +28,17 @@ static void dataChangeNotificationCallback(UA_Server *server, UA_UInt32 monitore
void *monitoredItemContext, const UA_NodeId *nodeId, void *monitoredItemContext, const UA_NodeId *nodeId,
void *nodeContext, UA_UInt32 attributeId, void *nodeContext, UA_UInt32 attributeId,
const UA_DataValue *var) { const UA_DataValue *var) {
// 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;
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
"Received Notification with value %d", "ID = %d", coupler_id);
*(UA_UInt32*) var->value.data); }
// filter out heart_beat from Data Set
if(UA_Variant_hasScalarType(&var->value, &UA_TYPES[UA_TYPES_FLOAT])) {
float heart_beat = *(UA_Float*) var->value.data;
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
"heart_beat = %f", heart_beat);
} }
} }
...@@ -221,9 +228,9 @@ static void fillTestDataSetMetaData(UA_DataSetMetaDataType *pMetaData) { ...@@ -221,9 +228,9 @@ static void fillTestDataSetMetaData(UA_DataSetMetaDataType *pMetaData) {
/* heartbeat */ /* heartbeat */
UA_FieldMetaData_init (&pMetaData->fields[0]); UA_FieldMetaData_init (&pMetaData->fields[0]);
UA_NodeId_copy (&UA_TYPES[UA_TYPES_UINT32].typeId, UA_NodeId_copy (&UA_TYPES[UA_TYPES_FLOAT].typeId,
&pMetaData->fields[0].dataType); &pMetaData->fields[0].dataType);
pMetaData->fields[0].builtInType = UA_NS0ID_UINT32; pMetaData->fields[0].builtInType = UA_NS0ID_FLOAT;
pMetaData->fields[0].name = UA_STRING ("Heartbeat (subscribed)"); pMetaData->fields[0].name = UA_STRING ("Heartbeat (subscribed)");
pMetaData->fields[0].valueRank = -1; /* scalar */ pMetaData->fields[0].valueRank = -1; /* scalar */
......
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