forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmessages.go
163 lines (141 loc) · 4.5 KB
/
messages.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package semp
import "encoding/xml"
const (
urnUPNPDevice = "urn:schemas-upnp-org:device-1-0"
urnSEMPService = "urn:schemas-simple-energy-management-protocol:service-1-0"
)
// DeviceDescription message definition
type DeviceDescription struct {
XMLName xml.Name `xml:"root"`
Xmlns string `xml:"xmlns,attr"`
SpecVersion SpecVersion `xml:"specVersion"`
Device Device `xml:"device"`
}
// SpecVersion message definition
type SpecVersion struct {
Major int `xml:"major"`
Minor int `xml:"minor"`
}
// Device message definition
type Device struct {
DeviceType string `xml:"deviceType"`
FriendlyName string `xml:"friendlyName"`
Manufacturer string `xml:"manufacturer"`
ModelName string `xml:"modelName"`
UDN string `xml:"UDN"`
PresentationURL string `xml:"presentationURL"`
ServiceDefinition ServiceDefinition `xml:"semp:X_SEMPSERVICE"`
ServiceList []Service `xml:"serviceList"` // optional
}
// Service message definition
type Service struct {
ServiceType string `xml:"serviceType"`
ServiceID string `xml:"serviceId"`
SCPDURL string `xml:"SCPDURL"`
ControlURL string `xml:"controlURL"`
EventSubURL string `xml:"eventSubURL"`
}
// ServiceDefinition message definition
type ServiceDefinition struct {
Xmlns string `xml:"xmlns:semp,attr"`
Server string `xml:"semp:server"`
BasePath string `xml:"semp:basePath"`
Transport string `xml:"semp:transport"`
ExchangeFormat string `xml:"semp:exchangeFormat"`
WsVersion string `xml:"semp:wsVersion"`
}
// Device2EM is the device to EM message
type Device2EM struct {
Xmlns string `xml:"xmlns,attr"`
DeviceInfo []DeviceInfo `xml:",omitempty"`
DeviceStatus []DeviceStatus `xml:",omitempty"`
PlanningRequest []PlanningRequest `xml:",omitempty"`
}
// DeviceInfo message definition
type DeviceInfo struct {
Identification Identification
Characteristics Characteristics
Capabilities Capabilities
}
// Identification message definition
type Identification struct {
DeviceID string `xml:"DeviceId"`
DeviceName string
DeviceType string
DeviceSerial string
DeviceVendor string
}
// Characteristics message definition
type Characteristics struct {
MinPowerConsumption int
MaxPowerConsumption int
MinOnTime int `xml:",omitempty"`
MinOffTime int `xml:",omitempty"`
}
// method definitions
const (
MethodMeasurement = "Measurement"
MethodEstimation = "Estimation"
)
// Capabilities message definition
type Capabilities struct {
CurrentPowerMethod string `xml:"CurrentPower>Method"`
AbsoluteTimestamps bool `xml:"Timestamps>AbsoluteTimestamps"`
InterruptionsAllowed bool `xml:"Interruptions>InterruptionsAllowed"`
OptionalEnergy bool `xml:"Requests>OptionalEnergy"`
}
// status definitions
const (
StatusOn = "On"
StatusOff = "Off"
)
// DeviceStatus message definition
type DeviceStatus struct {
DeviceID string `xml:"DeviceId"`
EMSignalsAccepted bool
Status string
PowerInfo PowerInfo `xml:"PowerConsumption>PowerInfo"`
}
// PowerInfo message definition
type PowerInfo struct {
AveragePower int
Timestamp int
AveragingInterval int
}
// PlanningRequest message definition
type PlanningRequest struct {
Timeframe []Timeframe
}
// Timeframe message definition
type Timeframe struct {
DeviceID string `xml:"DeviceId"`
EarliestStart int
LatestEnd int
MinRunningTime *int `xml:",omitempty"`
MaxRunningTime *int `xml:",omitempty"`
MinEnergy *int `xml:",omitempty"` // AN EVCharger
MaxEnergy *int `xml:",omitempty"` // AN EVCharger
MaxPowerConsumption *int `xml:",omitempty"` // SMA EV CHARGER style
MinPowerConsumption *int `xml:",omitempty"` // SMA EV CHARGER style
}
// EM2Device is the EM to device message
type EM2Device struct {
Xmlns string `xml:"xmlns,attr"`
DeviceControl []DeviceControl `xml:",omitempty"`
}
// DeviceControl message definition
type DeviceControl struct {
DeviceID string `xml:"DeviceId"`
On bool
RecommendedPowerConsumption float64 // AN EVCharger
Timestamp int
}
// Device2EMMsg is the XML message container
func Device2EMMsg() Device2EM {
msg := Device2EM{
Xmlns: "http://www.sma.de/communication/schema/SEMP/v1",
DeviceInfo: make([]DeviceInfo, 0),
DeviceStatus: make([]DeviceStatus, 0),
}
return msg
}