/
ocpp_test_handler.go
81 lines (66 loc) · 3.57 KB
/
ocpp_test_handler.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
package charger
import (
"fmt"
"github.com/lorenzodonini/ocpp-go/ocpp1.6/core"
"github.com/lorenzodonini/ocpp-go/ocpp1.6/remotetrigger"
"github.com/lorenzodonini/ocpp-go/ocpp1.6/types"
)
type ChargePointHandler struct {
triggerC chan remotetrigger.MessageTrigger
}
func (handler *ChargePointHandler) OnChangeAvailability(request *core.ChangeAvailabilityRequest) (confirmation *core.ChangeAvailabilityConfirmation, err error) {
fmt.Printf("%T %+v\n", request, request)
return core.NewChangeAvailabilityConfirmation(core.AvailabilityStatusAccepted), nil
}
func (handler *ChargePointHandler) OnChangeConfiguration(request *core.ChangeConfigurationRequest) (confirmation *core.ChangeConfigurationConfirmation, err error) {
fmt.Printf("%T %+v\n", request, request)
return core.NewChangeConfigurationConfirmation(core.ConfigurationStatusAccepted), nil
}
func (handler *ChargePointHandler) OnClearCache(request *core.ClearCacheRequest) (confirmation *core.ClearCacheConfirmation, err error) {
fmt.Printf("%T %+v\n", request, request)
return core.NewClearCacheConfirmation(core.ClearCacheStatusAccepted), nil
}
func (handler *ChargePointHandler) OnDataTransfer(request *core.DataTransferRequest) (confirmation *core.DataTransferConfirmation, err error) {
fmt.Printf("%T %+v\n", request, request)
return core.NewDataTransferConfirmation(core.DataTransferStatusAccepted), nil
}
func (handler *ChargePointHandler) OnGetConfiguration(request *core.GetConfigurationRequest) (confirmation *core.GetConfigurationConfirmation, err error) {
fmt.Printf("%T %+v\n", request, request)
one := "1"
meter := "Power.Active.Import,Energy.Active.Import.Register"
return core.NewGetConfigurationConfirmation([]core.ConfigurationKey{
{Key: "AuthorizationKey"},
{Key: "NumberOfConnectors", Value: &one},
{Key: "ChargeProfileMaxStackLevel", Value: &one},
{Key: "ChargingScheduleMaxPeriods", Value: &one},
{Key: "MaxChargingProfilesInstalled", Value: &one},
{Key: "ChargingScheduleAllowedChargingRateUnit", Value: &one},
{Key: "MeterValuesSampledData", Value: &meter},
}), nil
}
func (handler *ChargePointHandler) OnRemoteStartTransaction(request *core.RemoteStartTransactionRequest) (confirmation *core.RemoteStartTransactionConfirmation, err error) {
fmt.Printf("%T %+v\n", request, request)
return core.NewRemoteStartTransactionConfirmation(types.RemoteStartStopStatusAccepted), nil
}
func (handler *ChargePointHandler) OnRemoteStopTransaction(request *core.RemoteStopTransactionRequest) (confirmation *core.RemoteStopTransactionConfirmation, err error) {
fmt.Printf("%T %+v\n", request, request)
return core.NewRemoteStopTransactionConfirmation(types.RemoteStartStopStatusAccepted), nil
}
func (handler *ChargePointHandler) OnReset(request *core.ResetRequest) (confirmation *core.ResetConfirmation, err error) {
fmt.Printf("%T %+v\n", request, request)
return core.NewResetConfirmation(core.ResetStatusAccepted), nil
}
func (handler *ChargePointHandler) OnUnlockConnector(request *core.UnlockConnectorRequest) (confirmation *core.UnlockConnectorConfirmation, err error) {
fmt.Printf("%T %+v\n", request, request)
return core.NewUnlockConnectorConfirmation(core.UnlockStatusUnlocked), nil
}
func (handler *ChargePointHandler) OnTriggerMessage(request *remotetrigger.TriggerMessageRequest) (confirmation *remotetrigger.TriggerMessageConfirmation, err error) {
fmt.Printf("%T %+v\n", request, request)
if c := handler.triggerC; request != nil && c != nil {
select {
case c <- request.RequestedMessage:
default:
}
}
return remotetrigger.NewTriggerMessageConfirmation(remotetrigger.TriggerMessageStatusAccepted), nil
}