-
-
Notifications
You must be signed in to change notification settings - Fork 784
/
Copy pathcs_core.go
108 lines (82 loc) · 2.75 KB
/
cs_core.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
package ocpp
import (
"github.com/lorenzodonini/ocpp-go/ocpp1.6/core"
"github.com/lorenzodonini/ocpp-go/ocpp1.6/types"
)
// cp actions
func (cs *CS) OnAuthorize(id string, request *core.AuthorizeRequest) (*core.AuthorizeConfirmation, error) {
// no cp handler
res := &core.AuthorizeConfirmation{
IdTagInfo: &types.IdTagInfo{
Status: types.AuthorizationStatusAccepted,
},
}
return res, nil
}
func (cs *CS) OnBootNotification(id string, request *core.BootNotificationRequest) (*core.BootNotificationConfirmation, error) {
if cp, err := cs.ChargepointByID(id); err == nil {
return cp.OnBootNotification(request)
}
res := &core.BootNotificationConfirmation{
CurrentTime: types.Now(),
Interval: int(Timeout.Seconds()),
Status: core.RegistrationStatusPending, // not accepted during startup
}
return res, nil
}
func (cs *CS) OnDataTransfer(id string, request *core.DataTransferRequest) (*core.DataTransferConfirmation, error) {
// no cp handler
res := &core.DataTransferConfirmation{
Status: core.DataTransferStatusAccepted,
}
return res, nil
}
func (cs *CS) OnHeartbeat(id string, request *core.HeartbeatRequest) (*core.HeartbeatConfirmation, error) {
// no cp handler
res := &core.HeartbeatConfirmation{
CurrentTime: types.Now(),
}
return res, nil
}
func (cs *CS) OnMeterValues(id string, request *core.MeterValuesRequest) (*core.MeterValuesConfirmation, error) {
if cp, err := cs.ChargepointByID(id); err == nil {
return cp.OnMeterValues(request)
}
return new(core.MeterValuesConfirmation), nil
}
func (cs *CS) OnStatusNotification(id string, request *core.StatusNotificationRequest) (*core.StatusNotificationConfirmation, error) {
if cp, err := cs.ChargepointByID(id); err == nil {
return cp.OnStatusNotification(request)
}
cs.mu.Lock()
defer cs.mu.Unlock()
// cache status for future cp connection
if reg, ok := cs.regs[id]; ok {
reg.mu.Lock()
reg.status = request
reg.mu.Unlock()
}
return new(core.StatusNotificationConfirmation), nil
}
func (cs *CS) OnStartTransaction(id string, request *core.StartTransactionRequest) (*core.StartTransactionConfirmation, error) {
if cp, err := cs.ChargepointByID(id); err == nil {
return cp.OnStartTransaction(request)
}
res := &core.StartTransactionConfirmation{
IdTagInfo: &types.IdTagInfo{
Status: types.AuthorizationStatusAccepted,
},
}
return res, nil
}
func (cs *CS) OnStopTransaction(id string, request *core.StopTransactionRequest) (*core.StopTransactionConfirmation, error) {
if cp, err := cs.ChargepointByID(id); err == nil {
cp.OnStopTransaction(request)
}
res := &core.StopTransactionConfirmation{
IdTagInfo: &types.IdTagInfo{
Status: types.AuthorizationStatusAccepted, // accept old pending stop message during startup
},
}
return res, nil
}