/
hs_pin.go
51 lines (41 loc) · 1.33 KB
/
hs_pin.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
package ship
import (
"encoding/json"
"errors"
"github.com/enbility/eebus-go/ship/model"
)
// Handshake Pin covers the states smePin...
func (c *ShipConnection) handshakePin_Init() {
c.setState(smePinStateCheckInit)
pinState := model.ConnectionPinState{
ConnectionPinState: model.ConnectionPinStateType{
PinState: model.PinStateTypeNone,
},
}
if err := c.sendShipModel(model.MsgTypeControl, pinState); err != nil {
c.endHandshakeWithError(err)
return
}
c.setState(smePinStateCheckListen)
}
func (c *ShipConnection) handshakePin_smePinStateCheckListen(message []byte) {
_, data := c.parseMessage(message, true)
var connectionPinState model.ConnectionPinState
if err := json.Unmarshal([]byte(data), &connectionPinState); err != nil {
c.endHandshakeWithError(err)
return
}
switch connectionPinState.ConnectionPinState.PinState {
case model.PinStateTypeNone:
c.setState(smePinStateCheckOk)
c.handleState(false, nil)
case model.PinStateTypeRequired:
c.endHandshakeWithError(errors.New("Got pin state: required (unsupported)"))
case model.PinStateTypeOptional:
c.endHandshakeWithError(errors.New("Got pin state: optional (unsupported)"))
case model.PinStateTypePinOk:
c.endHandshakeWithError(errors.New("Got pin state: ok (unsupported)"))
default:
c.endHandshakeWithError(errors.New("Got invalid pin state"))
}
}