ソースを参照

adding samplingInterval to UA_Client_Subscriptions_addMonitoredItem (#1351)

* adding samplingInterval parameter to UA_Client_Subscriptions_addMonitoredEvent

* adding samplingInterval parameter

* adding samplingInterval parameter

* adding samplingInterval parameter
StalderT 6 年 前
コミット
d96500feb0
共有4 個のファイルを変更した9 個の追加7 個の削除を含む
  1. 1 1
      examples/client.c
  2. 2 1
      include/ua_client_highlevel.h
  3. 4 3
      src/client/ua_client_highlevel_subscriptions.c
  4. 2 2
      tests/client/check_client_subscriptions.c

+ 1 - 1
examples/client.c

@@ -101,7 +101,7 @@ int main(int argc, char *argv[]) {
     UA_NodeId monitorThis = UA_NODEID_STRING(1, "the.answer");
     UA_UInt32 monId = 0;
     UA_Client_Subscriptions_addMonitoredItem(client, subId, monitorThis, UA_ATTRIBUTEID_VALUE,
-                                             &handler_TheAnswerChanged, NULL, &monId);
+                                             &handler_TheAnswerChanged, NULL, &monId, 250);
     if (monId)
         printf("Monitoring 'the.answer', id %u\n", subId);
     /* The first publish request should return the initial value of the variable */

+ 2 - 1
include/ua_client_highlevel.h

@@ -612,7 +612,8 @@ UA_Client_Subscriptions_addMonitoredItem(UA_Client *client,
                                          UA_NodeId nodeId, UA_UInt32 attributeID,
                                          UA_MonitoredItemHandlingFunction hf,
                                          void *hfContext,
-                                         UA_UInt32 *newMonitoredItemId);
+                                         UA_UInt32 *newMonitoredItemId,
+                                         UA_Double samplingInterval);
 
 UA_StatusCode UA_EXPORT
 UA_Client_Subscriptions_removeMonitoredItem(UA_Client *client,

+ 4 - 3
src/client/ua_client_highlevel_subscriptions.c

@@ -202,7 +202,8 @@ UA_StatusCode
 UA_Client_Subscriptions_addMonitoredItem(UA_Client *client, UA_UInt32 subscriptionId,
                                          UA_NodeId nodeId, UA_UInt32 attributeID,
                                          UA_MonitoredItemHandlingFunction hf,
-                                         void *hfContext, UA_UInt32 *newMonitoredItemId) {
+                                         void *hfContext, UA_UInt32 *newMonitoredItemId,
+                                         UA_Double samplingInterval) {
     UA_Client_Subscription *sub = findSubscription(client, subscriptionId);
     if(!sub)
         return UA_STATUSCODE_BADSUBSCRIPTIONIDINVALID;
@@ -222,7 +223,7 @@ UA_Client_Subscriptions_addMonitoredItem(UA_Client *client, UA_UInt32 subscripti
     item.itemToMonitor.attributeId = attributeID;
     item.monitoringMode = UA_MONITORINGMODE_REPORTING;
     item.requestedParameters.clientHandle = ++(client->monitoredItemHandles);
-    item.requestedParameters.samplingInterval = sub->publishingInterval;
+    item.requestedParameters.samplingInterval = samplingInterval;
     item.requestedParameters.discardOldest = true;
     item.requestedParameters.queueSize = 1;
     request.itemsToCreate = &item;
@@ -248,7 +249,7 @@ UA_Client_Subscriptions_addMonitoredItem(UA_Client *client, UA_UInt32 subscripti
     UA_NodeId_copy(&nodeId, &newMon->monitoredNodeId);
     newMon->attributeID = attributeID;
     newMon->clientHandle = client->monitoredItemHandles;
-    newMon->samplingInterval = sub->publishingInterval;
+    newMon->samplingInterval = samplingInterval;
     newMon->queueSize = 1;
     newMon->discardOldest = true;
     newMon->handler = hf;

+ 2 - 2
tests/client/check_client_subscriptions.c

@@ -67,7 +67,7 @@ START_TEST(Client_subscription) {
     UA_UInt32 monId;
     retval = UA_Client_Subscriptions_addMonitoredItem(client, subId, UA_NODEID_NUMERIC(0, 2259),
                                                       UA_ATTRIBUTEID_VALUE, monitoredItemHandler,
-                                                      NULL, &monId);
+                                                      NULL, &monId, 250);
     ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
 
     UA_sleep((UA_UInt32)UA_SubscriptionSettings_default.requestedPublishingInterval + 1);
@@ -101,7 +101,7 @@ START_TEST(Client_methodcall) {
     /* monitor the server state */
     UA_UInt32 monId;
     retval = UA_Client_Subscriptions_addMonitoredItem(client, subId, UA_NODEID_NUMERIC(0, 2259),
-                                                      UA_ATTRIBUTEID_VALUE, NULL, NULL, &monId);
+                                                      UA_ATTRIBUTEID_VALUE, NULL, NULL, &monId, 250);
     ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
 
     /* call a method to get monitored item id */