NOISSUE - Add details to browsed OPC-UA nodes (#1019)

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
This commit is contained in:
Manuel Imperiale 2020-01-27 12:25:16 +01:00 committed by Nikola Marčetić
parent 575d1d6bbf
commit 7b62f1ce8a
7 changed files with 22 additions and 14 deletions

View File

@ -26,10 +26,7 @@ func browseEndpoint(svc opcua.Service) endpoint.Endpoint {
}
res := browseRes{
Nodes: []string{},
}
for _, node := range nodes {
res.Nodes = append(res.Nodes, node)
Nodes: nodes,
}
return res, nil

View File

@ -130,7 +130,7 @@ func (lm loggingMiddleware) DisconnectThing(mfxChanID, mfxThingID string) (err e
return lm.svc.DisconnectThing(mfxChanID, mfxThingID)
}
func (lm loggingMiddleware) Browse(serverURI, nodeID string) (nodes []string, err error) {
func (lm loggingMiddleware) Browse(serverURI, nodeID string) (nodes []opcua.BrowsedNode, err error) {
defer func(begin time.Time) {
message := fmt.Sprintf("browse server URI %s and node ID %s, took %s to complete", serverURI, nodeID, time.Since(begin))
if err != nil {

View File

@ -99,7 +99,7 @@ func (mm *metricsMiddleware) DisconnectThing(mfxChanID, mfxThingID string) error
return mm.svc.DisconnectThing(mfxChanID, mfxThingID)
}
func (mm *metricsMiddleware) Browse(serverURI, nodeID string) ([]string, error) {
func (mm *metricsMiddleware) Browse(serverURI, nodeID string) ([]opcua.BrowsedNode, error) {
defer func(begin time.Time) {
mm.counter.With("method", "browse").Add(1)
mm.latency.With("method", "browse").Observe(time.Since(begin).Seconds())

View File

@ -7,12 +7,13 @@ import (
"net/http"
"github.com/mainflux/mainflux"
"github.com/mainflux/mainflux/opcua"
)
var _ mainflux.Response = (*browseRes)(nil)
type browseRes struct {
Nodes []string `json:"nodes"`
Nodes []opcua.BrowsedNode `json:"nodes"`
}
func (res browseRes) Code() int {

View File

@ -3,8 +3,15 @@
package opcua
// BrowsedNode represents the details of a browsed OPC-UA node.
type BrowsedNode struct {
NodeID string
Type string
Description string
}
// Browser represents the OPC-UA Server Nodes browser.
type Browser interface {
// Browse availlable Nodes for a given URI.
Browse(string, string) ([]string, error)
Browse(string, string) ([]BrowsedNode, error)
}

View File

@ -5,7 +5,6 @@ package gopcua
import (
"context"
"fmt"
opcuaGopcua "github.com/gopcua/opcua"
"github.com/gopcua/opcua/id"
@ -45,7 +44,7 @@ func NewBrowser(ctx context.Context, log logger.Logger) opcua.Browser {
}
}
func (c browser) Browse(serverURI, nodeID string) ([]string, error) {
func (c browser) Browse(serverURI, nodeID string) ([]opcua.BrowsedNode, error) {
opts := []opcuaGopcua.Option{
opcuaGopcua.SecurityMode(uaGopcua.MessageSecurityModeNone),
}
@ -66,9 +65,13 @@ func (c browser) Browse(serverURI, nodeID string) ([]string, error) {
return nil, err
}
nodes := []string{}
nodes := []opcua.BrowsedNode{}
for _, s := range nodeList {
node := fmt.Sprintf("ns=%d;%s", s.NodeID.Namespace(), s.NodeID.String())
node := opcua.BrowsedNode{
NodeID: s.NodeID.String(),
Type: s.DataType,
Description: s.Description,
}
nodes = append(nodes, node)
}

View File

@ -45,7 +45,7 @@ type Service interface {
DisconnectThing(string, string) error
// Browse browses available nodes for a given OPC-UA Server URI and NodeID
Browse(string, string) ([]string, error)
Browse(string, string) ([]BrowsedNode, error)
}
// Config OPC-UA Server
@ -131,7 +131,7 @@ func (as *adapterService) ConnectThing(mfxChanID, mfxThingID string) error {
return as.connectRM.Save(c, c)
}
func (as *adapterService) Browse(serverURI, nodeID string) ([]string, error) {
func (as *adapterService) Browse(serverURI, nodeID string) ([]BrowsedNode, error) {
nodes, err := as.browser.Browse(serverURI, nodeID)
if err != nil {
return nil, err