@@ -49,6 +49,14 @@ func (l *Listener) ProcessStop() bool {
49
49
return false
50
50
}
51
51
52
+ type ModelYear int64
53
+
54
+ const (
55
+ ModelYearUnknown ModelYear = iota
56
+ ModelYear14
57
+ ModelYear18
58
+ )
59
+
52
60
// A Client is a TCP client to a Phev.
53
61
type Client struct {
54
62
// Recv is a channel where incoming messages from the Phev are sent.
@@ -66,6 +74,9 @@ type Client struct {
66
74
67
75
key * protocol.SecurityKey
68
76
77
+ // Keep track of the model year so we can use the correct registers
78
+ ModelYear ModelYear
79
+
69
80
closed bool
70
81
}
71
82
@@ -88,6 +99,7 @@ func New(opts ...Option) (*Client, error) {
88
99
listeners : []* Listener {},
89
100
address : DefaultAddress ,
90
101
key : & protocol.SecurityKey {},
102
+ ModelYear : ModelYearUnknown ,
91
103
}
92
104
for _ , o := range opts {
93
105
o (cl )
@@ -257,6 +269,7 @@ func (c *Client) manage() {
257
269
Xor : m .Xor ,
258
270
}
259
271
case protocol .CmdInMy18StartReq :
272
+ c .ModelYear = ModelYear18
260
273
c .Send <- & protocol.PhevMessage {
261
274
Type : protocol .CmdOutMy18StartResp ,
262
275
Register : 0x1 ,
@@ -267,6 +280,7 @@ func (c *Client) manage() {
267
280
log .Debug ("%%PHEV_START18_RECV%%" )
268
281
c .started <- struct {}{}
269
282
case protocol .CmdInMy14StartReq :
283
+ c .ModelYear = ModelYear14
270
284
c .Send <- & protocol.PhevMessage {
271
285
Type : protocol .CmdOutMy14StartResp ,
272
286
Register : 0x1 ,
0 commit comments