forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserialinterface.go
225 lines (189 loc) · 6.19 KB
/
serialinterface.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
217
218
219
220
221
222
223
224
225
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"reflect"
"github.com/stmcginnis/gofish/common"
)
// The receive and transmit rate of data flow, typically in bits per second (bit/s), over the serial connection.
type BitRate string
const (
// A bit rate of 1200 bit/s.
BitRate1200 BitRate = "1200"
// A bit rate of 2400 bit/s.
BitRate2400 BitRate = "2400"
// A bit rate of 4800 bit/s.
BitRate4800 BitRate = "4800"
// A bit rate of 9600 bit/s.
BitRate9600 BitRate = "9600"
// A bit rate of 19200 bit/s.
BitRate19200 BitRate = "19200"
// A bit rate of 38400 bit/s.
BitRate38400 BitRate = "38400"
// A bit rate of 57600 bit/s.
BitRate57600 BitRate = "57600"
// A bit rate of 115200 bit/s.
BitRate115200 BitRate = "115200"
// A bit rate of 230400 bit/s.
BitRate230400 BitRate = "230400"
)
// The type of connector used for this interface.
type ConnectorType string
const (
// A DB25 Female connector.
DB25FemaleConnector ConnectorType = "DB25 Female"
// A DB25 Male connector.
DB25MaleConnector ConnectorType = "DB25 Male"
// A DB9 Female connector.
DB9FemaleConnector ConnectorType = "DB9 Female"
// A DB9 Male connector.
DB9MaleConnector ConnectorType = "DB9 Male"
// A mUSB connector.
MUSBConnector ConnectorType = "mUSB"
// An RJ11 connector.
RJ11Connector ConnectorType = "RJ11"
// An RJ45 connector.
RJ45Connector ConnectorType = "RJ45"
// A USB connector.
USBConnector ConnectorType = "USB"
// A uUSB connector.
UUSBConnector ConnectorType = "uUSB"
)
// The number of data bits that follow the start bit over the serial connection.
type DataBits string
const (
// Five bits of data following the start bit.
DataBits5 DataBits = "5"
// Six bits of data following the start bit.
DataBits6 DataBits = "6"
// Seven bits of data following the start bit.
DataBits7 DataBits = "7"
// Eight bits of data following the start bit.
DataBits8 DataBits = "8"
)
// The period of time before the next start bit is transmitted.
type StopBits string
const (
// One stop bit following the data bits.
StopBits1 DataBits = "1"
// Two stop bits following the data bits.
StopBits2 DataBits = "2"
)
// The type of flow control, if any, that is imposed on the serial connection.
type SerialConnectionFlowControl string
const (
// Out-of-band flow control imposed.
HardwareSerialConnectionFlowControl SerialConnectionFlowControl = "Hardware"
// No flow control imposed.
NoneSerialConnectionFlowControl SerialConnectionFlowControl = "None"
// XON/XOFF in-band flow control imposed.
SoftwareSerialConnectionFlowControl SerialConnectionFlowControl = "Software"
)
// The type of parity used by the sender and receiver to detect errors over the serial connection.
type Parity string
const (
// An even parity bit.
EvenParityBit Parity = "Even"
// A mark parity bit.
MarkParityBit Parity = "Mark"
// No parity bit.
NoneParityBit Parity = "None"
// An odd parity bit.
OddParityBit Parity = "Odd"
// A space parity bit.
SpaceParityBit Parity = "Space"
)
// The physical pinout configuration for a serial connector.
type PinOutConfiguration string
const (
// The Cisco pinout configuration.
CiscoPinOutConfiguration PinOutConfiguration = "Cisco"
// The Cyclades pinout configuration.
CycladesPinOutConfiguration PinOutConfiguration = "Cyclades"
// The Digi pinout configuration.
DigiPinOutConfiguration PinOutConfiguration = "Digi"
)
// The type of signal used for the communication connection.
type SignalType string
const (
// The serial interface follows RS232.
Rs232SignalType SignalType = "Rs232"
// The serial interface follows RS485.
Rs485SignalType SignalType = "Rs485"
)
// SerialInterface is used to represent Serial Interface resources as part of
// the Redfish specification.
type SerialInterface struct {
common.Entity
// ODataContext is the odata context.
ODataContext string `json:"@odata.context"`
// ODataType is the odata type.
ODataType string `json:"@odata.type"`
// Description provides a description of this resource.
Description string
BitRate BitRate
ConnectorType ConnectorType
DataBits DataBits
FlowControl SerialConnectionFlowControl
InterfaceEnabled bool
Parity Parity
PinOut PinOutConfiguration
SignalType SignalType
StopBits StopBits
Oem json.RawMessage
// OemActions contains all the vendor specific actions.
// It is vendor responsibility to parse this field accordingly
OemActions json.RawMessage
rawData []byte
}
// UnmarshalJSON unmarshals a SerialInterface object from the raw JSON.
func (serialInterface *SerialInterface) UnmarshalJSON(b []byte) error {
type temp SerialInterface
type actions struct {
Oem json.RawMessage // OEM actions will be stored here
}
var t struct {
temp
Actions actions
}
if err := json.Unmarshal(b, &t); err != nil {
return err
}
*serialInterface = SerialInterface(t.temp)
// Extract the links to other entities for later
serialInterface.OemActions = t.Actions.Oem
// This is a read/write object, so we need to save the raw object data for later
serialInterface.rawData = b
return nil
}
// Update commits updates to this object's properties to the running system.
func (serialInterface *SerialInterface) Update() error {
// Get a representation of the object's original state so we can find what
// to update.
original := new(SerialInterface)
if err := original.UnmarshalJSON(serialInterface.rawData); err != nil {
return err
}
readWriteFields := []string{
"BitRate",
"DataBits",
"FlowControl",
"InterfaceEnabled",
"Parity",
"StopBits",
}
originalElement := reflect.ValueOf(original).Elem()
currentElement := reflect.ValueOf(serialInterface).Elem()
return serialInterface.Entity.Update(originalElement, currentElement, readWriteFields)
}
// GetSerialInterface will get a SerialInterface instance from the service.
func GetSerialInterface(c common.Client, uri string) (*SerialInterface, error) {
return common.GetObject[SerialInterface](c, uri)
}
// ListReferencedSerialInterfaces gets the collection of SerialInterface from
// a provided reference.
func ListReferencedSerialInterfaces(c common.Client, link string) ([]*SerialInterface, error) {
return common.GetCollectionObjects[SerialInterface](c, link)
}