127 lines
3.6 KiB
Go
127 lines
3.6 KiB
Go
package ocpp
|
|
|
|
import (
|
|
"github.com/lorenzodonini/ocpp-go/ocpp1.6/core"
|
|
"github.com/lorenzodonini/ocpp-go/ocpp1.6/security"
|
|
"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) {
|
|
cs.mu.Lock()
|
|
// cache status for future cp connection
|
|
if reg, ok := cs.regs[id]; ok && request != nil {
|
|
reg.mu.Lock()
|
|
reg.status[request.ConnectorId] = request
|
|
reg.mu.Unlock()
|
|
}
|
|
cs.mu.Unlock()
|
|
|
|
if cp, err := cs.ChargepointByID(id); err == nil {
|
|
return cp.OnStatusNotification(request)
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
func (cs *CS) OnSecurityEventNotification(id string, request *security.SecurityEventNotificationRequest) (*security.SecurityEventNotificationResponse, error) {
|
|
// Acknowledge any security event
|
|
return &security.SecurityEventNotificationResponse{}, nil
|
|
}
|
|
|
|
func (cs *CS) OnSignCertificate(id string, request *security.SignCertificateRequest) (*security.SignCertificateResponse, error) {
|
|
// Reject any certificate signing request
|
|
return &security.SignCertificateResponse{
|
|
Status: types.GenericStatusRejected,
|
|
}, nil
|
|
}
|
|
|
|
func (cs *CS) OnCertificateSigned(id string, request *security.CertificateSignedRequest) (*security.CertificateSignedResponse, error) {
|
|
// Acknowledge any certificate
|
|
return &security.CertificateSignedResponse{
|
|
Status: security.CertificateSignedStatusAccepted,
|
|
}, nil
|
|
}
|