/
sensorSimService.go
56 lines (49 loc) · 1.48 KB
/
sensorSimService.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package services
import (
"fmt"
"github.com/amine-amaach/simulators/ioTSensorsOPCUA/utils"
"github.com/awcullen/opcua/server"
"github.com/awcullen/opcua/ua"
)
type SensorSimService struct {
host string
port int
userIds []ua.UserNameIdentity
Srv *UaSrvService
}
func NewSensorSimService(host string, port int, userIds []ua.UserNameIdentity, certificateAdditions *utils.Certificate) *SensorSimService {
return &SensorSimService{
host: host,
port: port,
userIds: userIds,
Srv: NewUaSrvService(host, port, userIds, certificateAdditions),
}
}
func (sensorSim SensorSimService) CreateNewVariableNode(nsi uint16, nodeName string) *server.VariableNode {
return server.NewVariableNode(
sensorSim.Srv.server,
ua.NodeIDString{NamespaceIndex: nsi, ID: nodeName},
ua.QualifiedName{NamespaceIndex: nsi, Name: nodeName},
ua.LocalizedText{Text: nodeName},
ua.LocalizedText{Text: fmt.Sprint(nodeName, " IoT Sensor Simulator")},
nil,
[]ua.Reference{
{
ReferenceTypeID: ua.ReferenceTypeIDHasProperty,
IsInverse: true,
TargetID: ua.ExpandedNodeID{NodeID: ua.NodeIDString{NamespaceIndex: nsi, ID: "IoTSensors"}},
},
},
ua.DataValue{},
ua.DataTypeIDDouble,
ua.ValueRankScalar,
[]uint32{},
ua.AccessLevelsCurrentRead|ua.AccessLevelsHistoryRead,
250.0,
false,
sensorSim.Srv.server.Historian(),
)
}
func (sensorSim SensorSimService) AddVariableNode(node server.Node) {
sensorSim.Srv.server.NamespaceManager().AddNode(node)
}