Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subscription: add SetMonitoringMode functionality #712

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ Here is the current set of supported services. For low-level access use the clie
| MonitoredItems Service Set | CreateMonitoredItems | Yes | |
| | DeleteMonitoredItems | Yes | |
| | ModifyMonitoredItems | Yes | |
| | SetMonitoringMode | | |
| | SetMonitoringMode | Yes | |
| | SetTriggering | | |
| Subscription Service Set | CreateSubscription | Yes | |
| | ModifySubscription | | |
Expand Down
44 changes: 42 additions & 2 deletions subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,22 +177,28 @@ func (s *Subscription) ModifyMonitoredItems(ctx context.Context, ts ua.Timestamp
stats.Subscription().Add("ModifyMonitoredItems", 1)
stats.Subscription().Add("ModifiedMonitoredItems", int64(len(items)))

var err error
s.itemsMu.Lock()
for _, item := range items {
id := item.MonitoredItemID
if _, exists := s.items[id]; !exists {
return nil, fmt.Errorf("sub %d: cannot modify unknown monitored item id: %d", s.SubscriptionID, id)
err = fmt.Errorf("sub %d: cannot modify unknown monitored item id: %d", s.SubscriptionID, id)
break
}
}
s.itemsMu.Unlock()

if err != nil {
return nil, err
}

req := &ua.ModifyMonitoredItemsRequest{
SubscriptionID: s.SubscriptionID,
TimestampsToReturn: ts,
ItemsToModify: items,
}
var res *ua.ModifyMonitoredItemsResponse
err := s.c.Send(ctx, req, func(v interface{}) error {
err = s.c.Send(ctx, req, func(v interface{}) error {
return safeAssign(v, &res)
})
if err != nil {
Expand Down Expand Up @@ -220,6 +226,40 @@ func (s *Subscription) ModifyMonitoredItems(ctx context.Context, ts ua.Timestamp
return res, nil
}

func (s *Subscription) SetMonitoringMode(ctx context.Context, monitoringMode ua.MonitoringMode, monitoredItemIDs ...uint32) (*ua.SetMonitoringModeResponse, error) {
stats.Subscription().Add("SetMonitoringMode", 1)
stats.Subscription().Add("SetMonitoringModeMonitoredItems", int64(len(monitoredItemIDs)))

var err error
s.itemsMu.Lock()
for _, id := range monitoredItemIDs {
if _, exists := s.items[id]; !exists {
err = fmt.Errorf("sub %d: cannot set monitoring mode for unknown monitored item id: %d", s.SubscriptionID, id)
break
}
}
s.itemsMu.Unlock()

if err != nil {
return nil, err
}

req := &ua.SetMonitoringModeRequest{
SubscriptionID: s.SubscriptionID,
MonitoringMode: monitoringMode,
MonitoredItemIDs: monitoredItemIDs,
}
var res *ua.SetMonitoringModeResponse
err = s.c.Send(ctx, req, func(v interface{}) error {
return safeAssign(v, &res)
})
if err != nil {
return nil, err
}

return res, nil
}

// SetTriggering sends a request to the server to add and/or remove triggering links from a triggering item.
// To add links from a triggering item to an item to report provide the server assigned ID(s) in the `add` argument.
// To remove links from a triggering item to an item to report provide the server assigned ID(s) in the `remove` argument.
Expand Down
Loading