Explorar el Código

Subscriptions: Reset the last samples when the MonitoredItem is modified

Julius Pfrommer hace 6 años
padre
commit
730e0998f4

+ 4 - 0
src/server/ua_services_subscription.c

@@ -194,6 +194,10 @@ setMonitoredItemSettings(UA_Server *server, UA_MonitoredItem *mon,
     UA_MonitoredItem_unregisterSampleCallback(server, mon);
     mon->monitoringMode = monitoringMode;
 
+    /* Remove the old samples */
+    UA_ByteString_deleteMembers(&mon->lastSampledValue);
+    UA_Variant_deleteMembers(&mon->lastValue);
+
     /* ClientHandle */
     mon->clientHandle = params->clientHandle;
 

+ 8 - 7
tests/server/check_monitoreditem_filter.c

@@ -252,17 +252,18 @@ START_TEST(Server_MonitoredItemsAbsoluteFilterSetLater) {
 
     UA_ModifyMonitoredItemsResponse_deleteMembers(&modifyResponse);
 
-    // This should not trigger because now we filter
+    // This should trigger only once for the new filter
     notificationReceived = false;
     countNotificationReceived = 0;
+    ck_assert_uint_eq(setDouble(client, outNodeId, 39.0), UA_STATUSCODE_GOOD);
+    ck_assert_uint_eq(waitForNotification(1, 10), UA_STATUSCODE_GOOD);
+    ck_assert_uint_eq(notificationReceived, true);
+    ck_assert_uint_eq(countNotificationReceived, 1);
     ck_assert_uint_eq(setDouble(client, outNodeId, 41.0), UA_STATUSCODE_GOOD);
-    ck_assert_uint_eq(waitForNotification(0, 10), UA_STATUSCODE_GOOD);
-    ck_assert_uint_eq(setDouble(client, outNodeId, 42.0), UA_STATUSCODE_GOOD);
-    ck_assert_uint_eq(waitForNotification(0, 10), UA_STATUSCODE_GOOD);
-    ck_assert_uint_eq(notificationReceived, false);
-    ck_assert_uint_eq(countNotificationReceived, 0);
+    ck_assert_uint_eq(waitForNotification(2, 10), UA_STATUSCODE_GOOD);
+    ck_assert_uint_eq(countNotificationReceived, 1);
 
-    ck_assert(fuzzyLastValueIsEqualTo(40.0));
+    ck_assert(fuzzyLastValueIsEqualTo(39.0));
 
     // This should trigger once at 43.0.
     notificationReceived = false;