server

package
v0.5.3-server Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2024 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RefTypeIDHasComponent = id.HasComponent
	RefTypeIDOrganizes    = id.Organizes
)

Variables

View Source
var (
	ObjectsFolder = ua.NewNumericNodeID(0, id.ObjectsFolder)
	RootFolder    = ua.NewNumericNodeID(0, id.RootFolder)
)

Functions

This section is empty.

Types

type AttrValue

type AttrValue struct {
	Value           *ua.Variant
	SourceTimestamp time.Time
}

func NewAttrValue

func NewAttrValue(v *ua.Variant) *AttrValue

type AttributeService

type AttributeService struct {
	// contains filtered or unexported fields
}

AttributeService implements the Attribute Service Set.

https://reference.opcfoundation.org/Core/Part4/v105/docs/5.10

type Attributes

type Attributes map[ua.AttributeID]*ua.Variant

type DiscoveryService

type DiscoveryService struct {
	// contains filtered or unexported fields
}

DiscoveryService implements the Discovery Service Set

https://reference.opcfoundation.org/Core/Part4/v105/docs/5.4

type Handler

type Handler func(*uasc.SecureChannel, ua.Request, uint32) (ua.Response, error)

type Logger

type Logger interface {
	Debug(msg string, args ...any)
	Error(msg string, args ...any)
	Info(msg string, args ...any)
	Warn(msg string, args ...any)
}

this logger interface is used to allow the user to provide their own logger it is compatible with slog.Logger

type MapNamespace

type MapNamespace struct {
	Mu   sync.RWMutex
	Data map[string]any

	// This can be used to be alerted when a value is changed from the opc server
	ExternalNotification chan string
	// contains filtered or unexported fields
}

This namespaces give a convenient way to have data mapped to the OPC server without having to map your application data to the OCP-UA data abstraction

It (currently) supports ints, floats, strings, and timestamps. No maps inside of maps and no arrays.

To notify subscribers of changes, be sure to call ChangeNotification(key) after changing the value. To be notified of changes from the opc-ua server to the map, receive on ExternalNotification channel

func NewMapNamespace

func NewMapNamespace(srv *Server, name string) *MapNamespace

func (*MapNamespace) AddNode

func (ns *MapNamespace) AddNode(n *Node) *Node

func (*MapNamespace) Attribute

func (ns *MapNamespace) Attribute(n *ua.NodeID, a ua.AttributeID) *ua.DataValue

func (*MapNamespace) Browse

func (ns *MapNamespace) Browse(bd *ua.BrowseDescription) *ua.BrowseResult

func (*MapNamespace) ChangeNotification

func (s *MapNamespace) ChangeNotification(key string)

This function is used to notify OPC UA subscribers if a key was changed without using the SetValue() function

func (*MapNamespace) GetValue

func (s *MapNamespace) GetValue(key string) any

Get the value associated with key from the MapNamespace. This function handles locking and getting the value.

Returns nil if the value doesn't exist.

func (*MapNamespace) ID

func (s *MapNamespace) ID() uint16

func (*MapNamespace) Name

func (ns *MapNamespace) Name() string

func (*MapNamespace) Node

func (ns *MapNamespace) Node(id *ua.NodeID) *Node

func (*MapNamespace) Objects

func (ns *MapNamespace) Objects() *Node

func (*MapNamespace) Root

func (ns *MapNamespace) Root() *Node

func (*MapNamespace) SetAttribute

func (s *MapNamespace) SetAttribute(node *ua.NodeID, attr ua.AttributeID, val *ua.DataValue) ua.StatusCode

func (*MapNamespace) SetID

func (ns *MapNamespace) SetID(id uint16)

func (*MapNamespace) SetValue

func (s *MapNamespace) SetValue(key string, value any)

update the value associated with a key and trigger the change notification to the OPC server

type MethodService

type MethodService struct {
	// contains filtered or unexported fields
}

MethodService implements the Method Service Set.

https://reference.opcfoundation.org/Core/Part4/v105/docs/5.11

type MonitoredItem

type MonitoredItem struct {
	ID  uint32
	Sub *Subscription
	Req *ua.MonitoredItemCreateRequest

	//TODO: use this
	Mode ua.MonitoringMode
}

type MonitoredItemService

type MonitoredItemService struct {
	SubService *SubscriptionService
	Mu         sync.Mutex

	// items tracked by ID
	Items map[uint32]*MonitoredItem
	// items tracked by node
	Nodes map[string][]*MonitoredItem
	// items tracked by subscription
	Subs map[uint32][]*MonitoredItem
	// contains filtered or unexported fields
}

MonitoredItemService implements the MonitoredItem Service Set.

https://reference.opcfoundation.org/Core/Part4/v105/docs/5.12

func (*MonitoredItemService) ChangeNotification

func (s *MonitoredItemService) ChangeNotification(n *ua.NodeID)

func (*MonitoredItemService) DeleteMonitoredItem

func (s *MonitoredItemService) DeleteMonitoredItem(id uint32)

function to get rid of all references to a specific Monitored Item (by ID number)

func (*MonitoredItemService) DeleteSub

func (s *MonitoredItemService) DeleteSub(id uint32)

function to delete all monitored items associated with a specific sub (as indicated by id number)

func (*MonitoredItemService) NextID

func (s *MonitoredItemService) NextID() uint32

type NameSpace

type NameSpace interface {
	// Name of the namespace.  Per the standard it should be an URI.
	Name() string

	// This function should create a new node
	AddNode(n *Node) *Node

	// This function should lookup and return the node indicated by the Node ID
	Node(id *ua.NodeID) *Node

	// This function should return the base Objects node that contains other nodes
	Objects() *Node

	// This function should return the root node
	Root() *Node

	// This is the function to list all available nodes to the client that is browsing.
	// The BrowseDescription has the root node of the browse and what kind of nodes the
	// client is looking for.  The Browse Result should have the list of matching nodes.
	Browse(req *ua.BrowseDescription) *ua.BrowseResult

	// ID and SetID are the namespace ID number of this namespace.  When you add it to the server
	// with srv.AddNamespace(xxx) it will set these for you.
	ID() uint16
	SetID(uint16)

	// These are the functions for reading and writing arbitrary attributes.  The most common
	// is the value attribute, but many clients also read the datatype and description attributes.
	// as well as attributes related to array bounds
	Attribute(*ua.NodeID, ua.AttributeID) *ua.DataValue
	SetAttribute(*ua.NodeID, ua.AttributeID, *ua.DataValue) ua.StatusCode
}

These are all the functions a namespace needs in order to provide nodes into the server

type Node

type Node struct {
	// contains filtered or unexported fields
}

func CurrentTimeNode

func CurrentTimeNode() *Node

func NamespacesNode

func NamespacesNode(s *Server) *Node

func NewFolderNode

func NewFolderNode(nodeID *ua.NodeID, name string) *Node

func NewNode

func NewNode(id *ua.NodeID, attr Attributes, refs References, val ValueFunc) *Node

func NewVariableNode

func NewVariableNode(nodeID *ua.NodeID, name string, value any) *Node

func RootNode

func RootNode() *Node

func ServerCapabilitiesNodes

func ServerCapabilitiesNodes(s *Server) []*Node

func ServerStatusNodes

func ServerStatusNodes(s *Server, ServerNode *Node) []*Node

func (*Node) AddObject

func (n *Node) AddObject(o *Node) *Node

func (*Node) AddRef

func (n *Node) AddRef(o *Node, rt RefType, forward bool)

func (*Node) AddVariable

func (n *Node) AddVariable(o *Node) *Node

func (*Node) Attribute

func (n *Node) Attribute(id ua.AttributeID) (*AttrValue, error)

func (*Node) BrowseName

func (n *Node) BrowseName() *ua.QualifiedName

func (*Node) DataType

func (n *Node) DataType() *ua.ExpandedNodeID

func (*Node) Description

func (n *Node) Description() *ua.LocalizedText

func (*Node) DisplayName

func (n *Node) DisplayName() *ua.LocalizedText

func (*Node) ID

func (n *Node) ID() *ua.NodeID

func (*Node) NodeClass

func (n *Node) NodeClass() ua.NodeClass

func (*Node) SetAttribute

func (n *Node) SetAttribute(id ua.AttributeID, val ua.DataValue) error

func (*Node) SetBrowseName

func (n *Node) SetBrowseName(s string)

func (*Node) SetDescription

func (n *Node) SetDescription(text, locale string)

func (*Node) SetDisplayName

func (n *Node) SetDisplayName(text, locale string)

func (*Node) SetNodeClass

func (n *Node) SetNodeClass(nc ua.NodeClass)

func (*Node) Value

func (n *Node) Value() *ua.Variant

type NodeManagementService

type NodeManagementService struct {
	// contains filtered or unexported fields
}

NodeManagementService implements the Node Management Service Set.

https://reference.opcfoundation.org/Core/Part4/v105/docs/5.7

type NodeNameSpace

type NodeNameSpace struct {
	ExternalNotification chan *ua.NodeID
	// contains filtered or unexported fields
}

the base "node-centric" namespace

func NewNameSpace

func NewNameSpace(name string) *NodeNameSpace

func NewNodeNameSpace

func NewNodeNameSpace(srv *Server, name string) *NodeNameSpace

func (*NodeNameSpace) AddNewVariableNode

func (as *NodeNameSpace) AddNewVariableNode(name string, value any) *Node

func (*NodeNameSpace) AddNewVariableStringNode

func (as *NodeNameSpace) AddNewVariableStringNode(name string, value any) *Node

func (*NodeNameSpace) AddNode

func (as *NodeNameSpace) AddNode(n *Node) *Node

func (*NodeNameSpace) Attribute

func (as *NodeNameSpace) Attribute(id *ua.NodeID, attr ua.AttributeID) *ua.DataValue

func (*NodeNameSpace) Browse

func (*NodeNameSpace) ChangeNotification

func (s *NodeNameSpace) ChangeNotification(nodeid *ua.NodeID)

This function is to notify opc subscribers if a node was changed without using the SetAttribute method

func (*NodeNameSpace) GetNextNodeID

func (ns *NodeNameSpace) GetNextNodeID() uint32

func (*NodeNameSpace) ID

func (ns *NodeNameSpace) ID() uint16

func (*NodeNameSpace) Name

func (ns *NodeNameSpace) Name() string

func (*NodeNameSpace) Node

func (as *NodeNameSpace) Node(id *ua.NodeID) *Node

func (*NodeNameSpace) Objects

func (as *NodeNameSpace) Objects() *Node

func (*NodeNameSpace) Root

func (as *NodeNameSpace) Root() *Node

func (*NodeNameSpace) SetAttribute

func (as *NodeNameSpace) SetAttribute(id *ua.NodeID, attr ua.AttributeID, val *ua.DataValue) ua.StatusCode

func (*NodeNameSpace) SetID

func (ns *NodeNameSpace) SetID(id uint16)

type OperationalLimits

type OperationalLimits struct {
	MaxNodesPerRead uint32
}

type Option

type Option func(*serverConfig)

Option is an option function type to modify the configuration.

func Certificate

func Certificate(cert []byte) Option

Certificate sets the client X509 certificate in the secure channel configuration and also detects and sets the ApplicationURI from the URI within the certificate

func EnableAuthMode

func EnableAuthMode(tokenType ua.UserTokenType) Option

EnableAuthMode registers a new user authentication mode to the server. All AuthModes except Anonymous require encryption by default, so EnableSecurity() must also be called with at least one non-"None" SecurityPolicy

func EnableSecurity

func EnableSecurity(secPolicy string, secMode ua.MessageSecurityMode) Option

EnableSecurity registers a new endpoint security mode to the server. This will also register the security policy against each enabled auth mode

func EndPoint

func EndPoint(host string, port int) Option

EndPointHostName adds an additional endpoint to the server based on the host name

func ManufacturerName

func ManufacturerName(name string) Option

func PrivateKey

func PrivateKey(key *rsa.PrivateKey) Option

PrivateKey sets the RSA private key in the secure channel configuration.

func ProductName

func ProductName(name string) Option

func ServerName

func ServerName(name string) Option

func SetLogger

func SetLogger(logger Logger) Option

the server.SetLogger takes a server.Logger interface. This interface is met by slog.Logger{}. A simple wrapper could be made for other loggers if they don't already meet the interface.

func SoftwareVersion

func SoftwareVersion(name string) Option

type PubReq

type PubReq struct {
	// The data of the publish request
	Req *ua.PublishRequest

	// The request ID (from the header) of the publish request.  This has to be used when replying.
	ID uint32
}

type QueryService

type QueryService struct {
	// contains filtered or unexported fields
}

QueryService implements the Query Service Set.

https://reference.opcfoundation.org/Core/Part4/v105/docs/5.9

type RefType

type RefType int

type References

type References []*ua.ReferenceDescription

type Server

type Server struct {
	SubscriptionService  *SubscriptionService
	MonitoredItemService *MonitoredItemService
	// contains filtered or unexported fields
}

Server is a high-level OPC-UA Server

func New

func New(opts ...Option) *Server

New returns an initialized OPC-UA server. Call Start() afterwards to begin listening and serving connections

func (*Server) AddNamespace

func (s *Server) AddNamespace(ns NameSpace) int

for now, the address space of the server is split up into namespaces. this means that when we look up a node, we need to ask the specific namespace it belongs to for it instead of just a general lookup by ID

the refRoot and refObjects flags can be used to automatically add a reference to the new Namespaces root or objects object respectively to the namespace 0

func (*Server) ChangeNotification

func (s *Server) ChangeNotification(n *ua.NodeID)

func (*Server) Close

func (s *Server) Close() error

Close gracefully shuts the server down by closing all open connections, and stops listening on all endpoints

func (*Server) Endpoints

func (s *Server) Endpoints() []*ua.EndpointDescription

func (*Server) ImportNodeSet

func (srv *Server) ImportNodeSet(nodes *schema.UANodeSet) error

func (*Server) Namespace

func (s *Server) Namespace(id int) (NameSpace, error)

func (*Server) Namespaces

func (s *Server) Namespaces() []NameSpace

func (*Server) Node

func (s *Server) Node(nid *ua.NodeID) *Node

func (*Server) RegisterHandler

func (s *Server) RegisterHandler(typeID uint16, h Handler)

This function allows you to overwrite a handler before you call start.

func (*Server) Session

func (s *Server) Session(hdr *ua.RequestHeader) *session

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start initializes and starts a Server listening on addr If s was not initialized with NewServer(), addr defaults to localhost:0 to let the OS select a random port

func (*Server) Status

func (s *Server) Status() *ua.ServerStatusDataType

Status returns the current server status.

func (*Server) URLs

func (s *Server) URLs() []string

URLs returns opc endpoint that the server is listening on.

type ServerCapabilities

type ServerCapabilities struct {
	OperationalLimits OperationalLimits
}

type SessionService

type SessionService struct {
	// contains filtered or unexported fields
}

SessionService implements the Session Service Set.

https://reference.opcfoundation.org/Core/Part4/v105/docs/5.6

type Subscription

type Subscription struct {
	Session                   *session
	ID                        uint32
	RevisedPublishingInterval float64
	RevisedLifetimeCount      uint32
	RevisedMaxKeepAliveCount  uint32
	Channel                   *uasc.SecureChannel
	SequenceID                uint32
	//SeqNums                   map[uint32]struct{}
	T *time.Ticker

	NotifyChannel chan *ua.MonitoredItemNotification
	ModifyChannel chan *ua.ModifySubscriptionRequest

	// the running flag and shutdown channel are used to signal the background task that it should stop.
	// multiple places can kill the subscription so make sure you check the running flag using the mutex
	// before closing the shutdown channel.
	Mu sync.Mutex
	// contains filtered or unexported fields
}

This is the type that with its run() function will work in the bakground fullfilling subscription publishes.

MonitoredItems will send updates on the NotifyChannel to let the background task know that an event has occured that needs to be published.

func NewSubscription

func NewSubscription() *Subscription

func (*Subscription) Start

func (s *Subscription) Start()

func (*Subscription) Update

func (s *Subscription) Update(req *ua.ModifySubscriptionRequest)

type SubscriptionService

type SubscriptionService struct {

	// pub sub stuff
	Mu   sync.Mutex
	Subs map[uint32]*Subscription
	// contains filtered or unexported fields
}

SubscriptionService implements the Subscription Service Set.

https://reference.opcfoundation.org/Core/Part4/v105/docs/5.13

func (*SubscriptionService) DeleteSubscription

func (s *SubscriptionService) DeleteSubscription(id uint32)

get rid of all references to a subscription and all monitored items that are pointed at this subscription.

type ValueFunc

type ValueFunc func() *ua.Variant

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL