-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelperfunctions.go
121 lines (109 loc) · 2.89 KB
/
helperfunctions.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package resources
import (
"encoding/xml"
"fmt"
"os"
"runtime/debug"
"time"
)
func StringInSlice(a string, list []string) bool {
for _, b := range list {
if b == a {
return true
}
}
return false
}
func CheckError(err error) {
if err != nil {
fmt.Println(err.Error())
debug.PrintStack()
os.Exit(1)
}
}
// Max returns the larger of x or y.
func Max(x, y int) int {
if x < y {
return y
}
return x
}
func xmlToString(in interface{}) string {
bytes, err := xml.Marshal(in)
CheckError(err)
return string(bytes)
}
func timestampNow() string {
current_time := time.Now()
return fmt.Sprintf("%d-%02d-%02dT%02d:%02d:%02d.0Z",
current_time.Year(), current_time.Month(), current_time.Day(),
current_time.Hour(), current_time.Minute(), current_time.Second())
}
func makeEntities(device *DeviceModel) []*NodeManagementDetailedDiscoveryEntityInformationType {
var all []*NodeManagementDetailedDiscoveryEntityInformationType
entities := device.Entities
for _, entity := range entities {
all = append(all, &NodeManagementDetailedDiscoveryEntityInformationType{
Description: &NetworkManagementEntityDescritpionDataType{
EntityAddress: &EntityAddressType{
Device: device.DeviceAddress,
Entity: entity.EntityAddress,
},
EntityType: entity.EntityType,
Description: entity.Description,
},
})
}
return all
}
func makeFeatures(device *DeviceModel) []*NodeManagementDetailedDiscoveryFeatureInformationType {
var all []*NodeManagementDetailedDiscoveryFeatureInformationType
entities := device.Entities
for _, entity := range entities {
for _, feature := range entity.Features {
all = append(all, &NodeManagementDetailedDiscoveryFeatureInformationType{
Description: &NetworkManagementFeatureInformationType{
FeatureAddress: &FeatureAddressType{
Device: device.DeviceAddress,
Entity: entity.EntityAddress,
Feature: feature.FeatureAddress,
},
FeatureType: feature.FeatureType,
Description: feature.Description,
Role: feature.Role,
},
})
}
}
return all
}
func (device *DeviceModel) MakeHeader(entity int, feature int, addressDestination *FeatureAddressType, cmdClassifier string, msgCounter int, ackRequest bool) *HeaderType {
return &HeaderType{
SpecificationVersion: SPECIFICATION_VERSION,
AddressSource: &FeatureAddressType{
Device: device.DeviceAddress,
Entity: entity,
Feature: feature,
},
AddressDestination: addressDestination,
MsgCounter: msgCounter,
CmdClassifier: cmdClassifier,
Timestamp: timestampNow(),
AckRequest: ackRequest,
}
}
func MakePayload(FunctionName string, Function interface{}) *PayloadType {
return &PayloadType{
Cmd: &CmdType{
FunctionName,
xmlToString(Function),
},
}
}
func MakeFeatureAddress(device string, entity int, feature int) *FeatureAddressType {
return &FeatureAddressType{
device,
entity,
feature,
}
}