-
Notifications
You must be signed in to change notification settings - Fork 1
/
types.go
216 lines (167 loc) · 5.33 KB
/
types.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// Copyright 2016 Shannon Wynter. All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.
package aurora
import "fmt"
// Argument is an interface that exposes Byte() to return a single byte
// representation of the given argument
type Argument interface {
Byte() byte
}
// State holds the structure for the inverter state, returned by the State() func
type State struct {
Global GlobalState
Inverter InverterState
Channel1 DCDCState
Channel2 DCDCState
Alarm AlarmState
}
// String returns state as an easy to read string
func (s *State) String() string {
return fmt.Sprintf("Global: %s, Inverter: %s, Channel1: %s, Channel2: %s, Alarm: %s", s.Global, s.Inverter, s.Channel1, s.Channel2, s.Alarm)
}
// Version holds the structure for the inverter version/model, returned byt he Version() func
type Version struct {
Model Product
Regulation ProductSpec
Transformer InverterType
Type InputType
}
// String returns the version as an easy to read string
func (v *Version) String() string {
return fmt.Sprintf("Model: %s, Regulation: %s, Transformer: %s, Type: %s", v.Model, v.Regulation, v.Transformer, v.Type)
}
// outputPayload is a convenient struct for writing binary to the inverter
type outputPayload struct {
Payload [8]byte
CRC uint16
}
// inputPayload is a convenient struct for reading binary from the inverter
type inputPayload struct {
Payload [6]byte
CRC uint16
}
// Byte is a concrete Argument
type Byte byte
// Command is a command to send to the inverter
type Command byte
// Counter is a counter parameter to request from the inverter with the GetCounter command
type Counter byte
// CumulationPeriod is a period parameters to request from the inverter
type CumulationPeriod byte
// DSParameter is a DSP parameter to request from the inverter
type DSParameter byte
// TransmissionState is a status flag returned by the inverter
type TransmissionState byte
// AlarmState is a state of alarm returned by the inverter as part of the State struct or as an
// array of 4 AlarmStates in response to the Last4Alarms request
type AlarmState byte
// ConfigurationState is a state of configuration returned by the inverter
type ConfigurationState byte
// DCDCState is a DCDC status flag from the inverter as part of the State struct
type DCDCState byte
// GlobalState is a global status flag returned by the inverter as part of the State sturct
type GlobalState byte
// Product is a product/model as returned by the inverter as part of the Version struct
type Product byte
// ProductSpec is a product specification/standard returned by the inverter as part of the Version struct
type ProductSpec byte
// InverterState is a status flag returned by the inverter as part of the State struct
type InverterState byte
// InverterType is a value returned as part of the Version struct
type InverterType byte
// InputType is a value returned as part of the Version struct
type InputType byte
// AlarmStates an array of AlarmState returned byt he Last4Alarms request
type AlarmStates []AlarmState
// Byte implement Argument.Byte()
func (b Byte) Byte() byte {
return byte(b)
}
// Byte implement Argument.Byte()
func (c Counter) Byte() byte {
return byte(c)
}
// Byte implement Argument.Byte()
func (c CumulationPeriod) Byte() byte {
return byte(c)
}
// Byte implements Argument.Byte()
func (d DSParameter) Byte() byte {
return byte(d)
}
func (o *outputPayload) String() string {
return fmt.Sprintf("% X (%d)", o.Payload, o.CRC)
}
func (i *inputPayload) String() string {
return fmt.Sprintf("% X (%d)", i.Payload, i.CRC)
}
func (t TransmissionState) String() string {
if str, ok := transmissionStates[t]; ok {
return str
}
return fmt.Sprintf("Unknown TransmissionState(%d)", byte(t))
}
func (a AlarmState) String() string {
if str, ok := alarmStates[a]; ok {
return str
}
return fmt.Sprintf("Unknown AlarmState(%d)", byte(a))
}
func (a AlarmStates) String() string {
return fmt.Sprintf("%s, %s, %s, %s", a[0], a[1], a[2], a[3])
}
func (g GlobalState) String() string {
if str, ok := globalStates[g]; ok {
return str
}
return fmt.Sprintf("Unknown GlobalState(%d)", byte(g))
}
func (c ConfigurationState) String() string {
if str, ok := configStates[c]; ok {
return str
}
return fmt.Sprintf("Unknown ConfigurationState(%d)", byte(c))
}
func (i InverterState) String() string {
if str, ok := inverterStates[i]; ok {
return str
}
return fmt.Sprintf("Unknown InverterState(%d)", byte(i))
}
func (d DCDCState) String() string {
if str, ok := dcdcStates[d]; ok {
return str
}
return fmt.Sprintf("Unknown DCDCState(%d)", byte(d))
}
func (d DSParameter) String() string {
if str, ok := dsParameterStrings[d]; ok {
return str
}
return fmt.Sprintf("Unknown DSParameter(%d)", byte(d))
}
func (p Product) String() string {
if str, ok := productNames[p]; ok {
return str
}
return fmt.Sprintf("Unknown Product (%d)", byte(p))
}
func (p ProductSpec) String() string {
if str, ok := productSpecs[p]; ok {
return str
}
return fmt.Sprintf("Unknown ProductSpec (%d)", byte(p))
}
func (i InverterType) String() string {
if str, ok := inverterTypes[i]; ok {
return str
}
return fmt.Sprintf("Unknown InverterType (%d)", byte(i))
}
func (m InputType) String() string {
if str, ok := inputTypes[m]; ok {
return str
}
return fmt.Sprintf("Unknown InputType (%d)", byte(m))
}