Skip to content

Commit 03b5898

Browse files
committed
Update ocpp2.0 documentation
Signed-off-by: Lorenzo Donini <[email protected]>
1 parent 9cccbe4 commit 03b5898

File tree

8 files changed

+152
-118
lines changed

8 files changed

+152
-118
lines changed

ocpp2.0/boot_notification.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (c BootNotificationConfirmation) GetFeatureName() string {
112112

113113
// Creates a new BootNotificationRequest, containing all required fields. Optional fields may be set afterwards.
114114
func NewBootNotificationRequest(reason BootReason, model string, vendorName string) *BootNotificationRequest {
115-
return &BootNotificationRequest{Reason: reason, ChargingStation:ChargingStationType{Model: model, VendorName: vendorName}}
115+
return &BootNotificationRequest{Reason: reason, ChargingStation: ChargingStationType{Model: model, VendorName: vendorName}}
116116
}
117117

118118
// Creates a new BootNotificationConfirmation. There are no optional fields for this message.

ocpp2.0/charging_station.go

Lines changed: 35 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,14 @@ import (
88
)
99

1010
type chargingStation struct {
11-
client *ocppj.ChargePoint
12-
coreListener ChargePointCoreListener
13-
//localAuthListListener ChargePointLocalAuthListListener
14-
//firmwareListener ChargePointFirmwareManagementListener
15-
//reservationListener ChargePointReservationListener
16-
//remoteTriggerListener ChargePointRemoteTriggerListener
17-
//smartChargingListener ChargePointSmartChargingListener
11+
client *ocppj.ChargePoint
12+
messageHandler ChargingStationHandler
1813
confirmationListener chan ocpp.Confirmation
1914
errorListener chan error
2015
}
2116

22-
// Sends a BootNotificationRequest to the central system, along with information about the charge point.
23-
func (cp *chargingStation) BootNotification(reason BootReason, chargePointModel string, chargePointVendor string, props ...func(request *BootNotificationRequest)) (*BootNotificationConfirmation, error) {
24-
request := NewBootNotificationRequest(reason, chargePointModel, chargePointVendor)
17+
func (cp *chargingStation) BootNotification(reason BootReason, model string, chargePointVendor string, props ...func(request *BootNotificationRequest)) (*BootNotificationConfirmation, error) {
18+
request := NewBootNotificationRequest(reason, model, chargePointVendor)
2519
for _, fn := range props {
2620
fn(request)
2721
}
@@ -33,7 +27,6 @@ func (cp *chargingStation) BootNotification(reason BootReason, chargePointModel
3327
}
3428
}
3529

36-
// Requests explicit authorization to the central system, provided a valid IdTag (typically the client's). The central system may either authorize or reject the client.
3730
func (cp *chargingStation) Authorize(idToken string, tokenType IdTokenType, props ...func(request *AuthorizeRequest)) (*AuthorizeConfirmation, error) {
3831
request := NewAuthorizationRequest(idToken, tokenType)
3932
for _, fn := range props {
@@ -47,7 +40,7 @@ func (cp *chargingStation) Authorize(idToken string, tokenType IdTokenType, prop
4740
}
4841
}
4942

50-
func (cp *chargingStation) ClearChargingLimit(chargingLimitSource ChargingLimitSourceType, props ...func(request *ClearedChargingLimitRequest)) (*ClearedChargingLimitConfirmation, error) {
43+
func (cp *chargingStation) ClearedChargingLimit(chargingLimitSource ChargingLimitSourceType, props ...func(request *ClearedChargingLimitRequest)) (*ClearedChargingLimitConfirmation, error) {
5144
request := NewClearedChargingLimitRequest(chargingLimitSource)
5245
for _, fn := range props {
5346
fn(request)
@@ -212,9 +205,8 @@ func (cp *chargingStation) GetCertificateStatus(ocspRequestData OCSPRequestDataT
212205
// }
213206
//}
214207

215-
// Registers a handler for incoming core profile messages
216-
func (cp *chargingStation) SetChargePointCoreListener(listener ChargePointCoreListener) {
217-
cp.coreListener = listener
208+
func (cp *chargingStation) SetMessageHandler(handler ChargingStationHandler) {
209+
cp.messageHandler = handler
218210
}
219211

220212
//// Registers a handler for incoming local authorization profile messages
@@ -242,10 +234,6 @@ func (cp *chargingStation) SetChargePointCoreListener(listener ChargePointCoreLi
242234
// cp.smartChargingListener = listener
243235
//}
244236

245-
// Sends a request to the central system.
246-
// The central system will respond with a confirmation, or with an error if the request was invalid or could not be processed.
247-
// In case of network issues (i.e. the remote host couldn't be reached), the function also returns an error.
248-
// The request is synchronous blocking.
249237
func (cp *chargingStation) SendRequest(request ocpp.Request) (ocpp.Confirmation, error) {
250238
// TODO: check for supported feature
251239
err := cp.client.SendRequest(request)
@@ -261,10 +249,6 @@ func (cp *chargingStation) SendRequest(request ocpp.Request) (ocpp.Confirmation,
261249
}
262250
}
263251

264-
// Sends an asynchronous request to the central system.
265-
// The central system will respond with a confirmation messages, or with an error if the request was invalid or could not be processed.
266-
// This result is propagated via a callback, called asynchronously.
267-
// In case of network issues (i.e. the remote host couldn't be reached), the function returns an error directly. In this case, the callback is never called.
268252
func (cp *chargingStation) SendRequestAsync(request ocpp.Request, callback func(confirmation ocpp.Confirmation, err error)) error {
269253
switch request.GetFeatureName() {
270254
case AuthorizeFeatureName, BootNotificationFeatureName, ClearedChargingLimitFeatureName, DataTransferFeatureName, FirmwareStatusNotificationFeatureName, Get15118EVCertificateFeatureName, GetCertificateStatusFeatureName:
@@ -302,20 +286,11 @@ func (cp *chargingStation) sendResponse(confirmation ocpp.Confirmation, err erro
302286
}
303287
}
304288

305-
// Connects to the central system and starts the charge point routine.
306-
// The function doesn't block and returns right away, after having attempted to open a connection to the central system.
307-
// If the connection couldn't be opened, an error is returned.
308-
//
309-
// Optional client options must be set before calling this function. Refer to NewChargingStation.
310-
//
311-
// No auto-reconnect logic is implemented as of now, but is planned for the future.
312-
func (cp *chargingStation) Start(centralSystemUrl string) error {
289+
func (cp *chargingStation) Start(csmsUrl string) error {
313290
// TODO: implement auto-reconnect logic
314-
return cp.client.Start(centralSystemUrl)
291+
return cp.client.Start(csmsUrl)
315292
}
316293

317-
// Stops the charge point routine, disconnecting it from the central system.
318-
// Any pending requests are discarded.
319294
func (cp *chargingStation) Stop() {
320295
cp.client.Stop()
321296
}
@@ -345,7 +320,7 @@ func (cp *chargingStation) handleIncomingRequest(request ocpp.Request, requestId
345320
} else {
346321
switch profile.Name {
347322
case CoreProfileName:
348-
if cp.coreListener == nil {
323+
if cp.messageHandler == nil {
349324
cp.notSupportedError(requestId, action)
350325
return
351326
}
@@ -382,55 +357,55 @@ func (cp *chargingStation) handleIncomingRequest(request ocpp.Request, requestId
382357
var err error = nil
383358
switch action {
384359
case CancelReservationFeatureName:
385-
confirmation, err = cp.coreListener.OnCancelReservation(request.(*CancelReservationRequest))
360+
confirmation, err = cp.messageHandler.OnCancelReservation(request.(*CancelReservationRequest))
386361
case CertificateSignedFeatureName:
387-
confirmation, err = cp.coreListener.OnCertificateSigned(request.(*CertificateSignedRequest))
362+
confirmation, err = cp.messageHandler.OnCertificateSigned(request.(*CertificateSignedRequest))
388363
case ChangeAvailabilityFeatureName:
389-
confirmation, err = cp.coreListener.OnChangeAvailability(request.(*ChangeAvailabilityRequest))
364+
confirmation, err = cp.messageHandler.OnChangeAvailability(request.(*ChangeAvailabilityRequest))
390365
//case ChangeConfigurationFeatureName:
391-
// confirmation, err = cp.coreListener.OnChangeConfiguration(request.(*ChangeConfigurationRequest))
366+
// confirmation, err = cp.messageHandler.OnChangeConfiguration(request.(*ChangeConfigurationRequest))
392367
case ClearCacheFeatureName:
393-
confirmation, err = cp.coreListener.OnClearCache(request.(*ClearCacheRequest))
368+
confirmation, err = cp.messageHandler.OnClearCache(request.(*ClearCacheRequest))
394369
case ClearChargingProfileFeatureName:
395-
confirmation, err = cp.coreListener.OnClearChargingProfile(request.(*ClearChargingProfileRequest))
370+
confirmation, err = cp.messageHandler.OnClearChargingProfile(request.(*ClearChargingProfileRequest))
396371
case ClearDisplayFeatureName:
397-
confirmation, err = cp.coreListener.OnClearDisplay(request.(*ClearDisplayRequest))
372+
confirmation, err = cp.messageHandler.OnClearDisplay(request.(*ClearDisplayRequest))
398373
case ClearVariableMonitoringFeatureName:
399-
confirmation, err = cp.coreListener.OnClearVariableMonitoring(request.(*ClearVariableMonitoringRequest))
374+
confirmation, err = cp.messageHandler.OnClearVariableMonitoring(request.(*ClearVariableMonitoringRequest))
400375
case CostUpdatedFeatureName:
401-
confirmation, err = cp.coreListener.OnCostUpdated(request.(*CostUpdatedRequest))
376+
confirmation, err = cp.messageHandler.OnCostUpdated(request.(*CostUpdatedRequest))
402377
case CustomerInformationFeatureName:
403-
confirmation, err = cp.coreListener.OnCustomerInformation(request.(*CustomerInformationRequest))
378+
confirmation, err = cp.messageHandler.OnCustomerInformation(request.(*CustomerInformationRequest))
404379
case DataTransferFeatureName:
405-
confirmation, err = cp.coreListener.OnDataTransfer(request.(*DataTransferRequest))
380+
confirmation, err = cp.messageHandler.OnDataTransfer(request.(*DataTransferRequest))
406381
case DeleteCertificateFeatureName:
407-
confirmation, err = cp.coreListener.OnDeleteCertificate(request.(*DeleteCertificateRequest))
382+
confirmation, err = cp.messageHandler.OnDeleteCertificate(request.(*DeleteCertificateRequest))
408383
case GetBaseReportFeatureName:
409-
confirmation, err = cp.coreListener.OnGetBaseReport(request.(*GetBaseReportRequest))
384+
confirmation, err = cp.messageHandler.OnGetBaseReport(request.(*GetBaseReportRequest))
410385
case GetChargingProfilesFeatureName:
411-
confirmation, err = cp.coreListener.OnGetChargingProfiles(request.(*GetChargingProfilesRequest))
386+
confirmation, err = cp.messageHandler.OnGetChargingProfiles(request.(*GetChargingProfilesRequest))
412387
case GetCompositeScheduleFeatureName:
413-
confirmation, err = cp.coreListener.OnGetCompositeSchedule(request.(*GetCompositeScheduleRequest))
388+
confirmation, err = cp.messageHandler.OnGetCompositeSchedule(request.(*GetCompositeScheduleRequest))
414389
case GetDisplayMessagesFeatureName:
415-
confirmation, err = cp.coreListener.OnGetDisplayMessages(request.(*GetDisplayMessagesRequest))
390+
confirmation, err = cp.messageHandler.OnGetDisplayMessages(request.(*GetDisplayMessagesRequest))
416391
case GetInstalledCertificateIdsFeatureName:
417-
confirmation, err = cp.coreListener.OnGetInstalledCertificateIds(request.(*GetInstalledCertificateIdsRequest))
392+
confirmation, err = cp.messageHandler.OnGetInstalledCertificateIds(request.(*GetInstalledCertificateIdsRequest))
418393
case GetLocalListVersionFeatureName:
419-
confirmation, err = cp.coreListener.OnGetLocalListVersion(request.(*GetLocalListVersionRequest))
394+
confirmation, err = cp.messageHandler.OnGetLocalListVersion(request.(*GetLocalListVersionRequest))
420395
case GetLogFeatureName:
421-
confirmation, err = cp.coreListener.OnGetLog(request.(*GetLogRequest))
396+
confirmation, err = cp.messageHandler.OnGetLog(request.(*GetLogRequest))
422397
case GetMonitoringReportFeatureName:
423-
confirmation, err = cp.coreListener.OnGetMonitoringReport(request.(*GetMonitoringReportRequest))
398+
confirmation, err = cp.messageHandler.OnGetMonitoringReport(request.(*GetMonitoringReportRequest))
424399
//case GetConfigurationFeatureName:
425-
// confirmation, err = cp.coreListener.OnGetConfiguration(request.(*GetConfigurationRequest))
400+
// confirmation, err = cp.messageHandler.OnGetConfiguration(request.(*GetConfigurationRequest))
426401
//case RemoteStartTransactionFeatureName:
427-
// confirmation, err = cp.coreListener.OnRemoteStartTransaction(request.(*RemoteStartTransactionRequest))
402+
// confirmation, err = cp.messageHandler.OnRemoteStartTransaction(request.(*RemoteStartTransactionRequest))
428403
//case RemoteStopTransactionFeatureName:
429-
// confirmation, err = cp.coreListener.OnRemoteStopTransaction(request.(*RemoteStopTransactionRequest))
404+
// confirmation, err = cp.messageHandler.OnRemoteStopTransaction(request.(*RemoteStopTransactionRequest))
430405
//case ResetFeatureName:
431-
// confirmation, err = cp.coreListener.OnReset(request.(*ResetRequest))
406+
// confirmation, err = cp.messageHandler.OnReset(request.(*ResetRequest))
432407
//case UnlockConnectorFeatureName:
433-
// confirmation, err = cp.coreListener.OnUnlockConnector(request.(*UnlockConnectorRequest))
408+
// confirmation, err = cp.messageHandler.OnUnlockConnector(request.(*UnlockConnectorRequest))
434409
//case GetLocalListVersionFeatureName:
435410
// confirmation, err = cp.localAuthListListener.OnGetLocalListVersion(request.(*GetLocalListVersionRequest))
436411
//case SendLocalListFeatureName:

ocpp2.0/clear_variable_monitoring.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ type ClearMonitoringResult struct {
3333

3434
// The field definition of the ClearVariableMonitoring request payload sent by the CSMS to the Charging Station.
3535
type ClearVariableMonitoringRequest struct {
36-
ID []int `json:"id" validate:"required,min=1,dive,gte=0"`
36+
ID []int `json:"id" validate:"required,min=1,dive,gte=0"` // List of the monitors to be cleared, identified by their Id.
3737
}
3838

3939
// This field definition of the ClearVariableMonitoring confirmation payload, sent by the Charging Station to the CSMS in response to a ClearVariableMonitoringRequest.
4040
// In case the request was invalid, or couldn't be processed, an error will be sent instead.
4141
type ClearVariableMonitoringConfirmation struct {
42-
ClearMonitoringResult []ClearMonitoringResult `json:"clearMonitoringResult" validate:"required,min=1,dive"`
42+
ClearMonitoringResult []ClearMonitoringResult `json:"clearMonitoringResult" validate:"required,min=1,dive"` // List of result statuses per monitor.
4343
}
4444

4545
// The CSMS asks the Charging Station to clear a display message that has been configured in the Charging Station to be cleared/removed.

ocpp2.0/csms.go

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
type csms struct {
1111
server *ocppj.CentralSystem
12-
coreListener CentralSystemCoreListener
12+
coreListener CSMSHandler
1313
//localAuthListListener CentralSystemLocalAuthListListener
1414
//firmwareListener CentralSystemFirmwareManagementListener
1515
//reservationListener CentralSystemReservationListener
@@ -84,7 +84,6 @@ func (cs *csms) ChangeAvailability(clientId string, callback func(confirmation *
8484
// return cs.SendRequestAsync(clientId, request, genericCallback)
8585
//}
8686

87-
// Instructs the charge point to clear its current authorization cache. All authorization saved locally will be invalidated.
8887
func (cs *csms) ClearCache(clientId string, callback func(confirmation *ClearCacheConfirmation, err error), props ...func(*ClearCacheRequest)) error {
8988
request := NewClearCacheRequest()
9089
for _, fn := range props {
@@ -537,9 +536,8 @@ func (cs *csms) GetMonitoringReport(clientId string, callback func(*GetMonitorin
537536
// return cs.SendRequestAsync(clientId, request, genericCallback)
538537
//}
539538

540-
// Registers a handler for incoming core profile messages.
541-
func (cs *csms) SetCentralSystemCoreListener(listener CentralSystemCoreListener) {
542-
cs.coreListener = listener
539+
func (cs *csms) SetMessageHandler(handler CSMSHandler) {
540+
cs.coreListener = handler
543541
}
544542

545543
// Registers a handler for incoming local authorization profile messages.
@@ -567,20 +565,14 @@ func (cs *csms) SetCentralSystemCoreListener(listener CentralSystemCoreListener)
567565
// cs.smartChargingListener = listener
568566
//}
569567

570-
// Registers a handler for new incoming charge point connections.
571568
func (cs *csms) SetNewChargingStationHandler(handler func(chargePointId string)) {
572569
cs.server.SetNewChargePointHandler(handler)
573570
}
574571

575-
// Registers a handler for charge point disconnections.
576572
func (cs *csms) SetChargingStationDisconnectedHandler(handler func(chargePointId string)) {
577573
cs.server.SetDisconnectedChargePointHandler(handler)
578574
}
579575

580-
// Sends an asynchronous request to the charge point.
581-
// The charge point will respond with a confirmation message, or with an error if the request was invalid or could not be processed.
582-
// This result is propagated via a callback, called asynchronously.
583-
// In case of network issues (i.e. the remote host couldn't be reached), the function returns an error directly. In this case, the callback is never called.
584576
func (cs *csms) SendRequestAsync(clientId string, request ocpp.Request, callback func(confirmation ocpp.Confirmation, err error)) error {
585577
switch request.GetFeatureName() {
586578
case CancelReservationFeatureName, CertificateSignedFeatureName, ChangeAvailabilityFeatureName, ClearCacheFeatureName, ClearChargingProfileFeatureName, ClearDisplayFeatureName, ClearVariableMonitoringFeatureName, CostUpdatedFeatureName, CustomerInformationFeatureName, DataTransferFeatureName, DeleteCertificateFeatureName, GetBaseReportFeatureName, GetChargingProfilesFeatureName, GetCompositeScheduleFeatureName, GetDisplayMessagesFeatureName, GetInstalledCertificateIdsFeatureName, GetLocalListVersionFeatureName, GetLogFeatureName, GetMonitoringReportFeatureName:
@@ -603,10 +595,6 @@ func (cs *csms) SendRequestAsync(clientId string, request ocpp.Request, callback
603595
return nil
604596
}
605597

606-
// Starts running the central system on the specified port and URL.
607-
// The central system runs as a daemon and handles incoming charge point connections and messages.
608-
609-
// The function blocks forever, so it is suggested to wrap it in a goroutine, in case other functionality needs to be executed on the main program thread.
610598
func (cs *csms) Start(listenPort int, listenPath string) {
611599
cs.server.Start(listenPort, listenPath)
612600
}
@@ -711,15 +699,15 @@ func (cs *csms) handleIncomingRequest(chargePointId string, request ocpp.Request
711699
case GetCertificateStatusFeatureName:
712700
confirmation, err = cs.coreListener.OnGetCertificateStatus(chargePointId, request.(*GetCertificateStatusRequest))
713701
//case HeartbeatFeatureName:
714-
// confirmation, err = cs.coreListener.OnHeartbeat(chargePointId, request.(*HeartbeatRequest))
702+
// confirmation, err = cs.messageHandler.OnHeartbeat(chargePointId, request.(*HeartbeatRequest))
715703
//case MeterValuesFeatureName:
716-
// confirmation, err = cs.coreListener.OnMeterValues(chargePointId, request.(*MeterValuesRequest))
704+
// confirmation, err = cs.messageHandler.OnMeterValues(chargePointId, request.(*MeterValuesRequest))
717705
//case StartTransactionFeatureName:
718-
// confirmation, err = cs.coreListener.OnStartTransaction(chargePointId, request.(*StartTransactionRequest))
706+
// confirmation, err = cs.messageHandler.OnStartTransaction(chargePointId, request.(*StartTransactionRequest))
719707
//case StopTransactionFeatureName:
720-
// confirmation, err = cs.coreListener.OnStopTransaction(chargePointId, request.(*StopTransactionRequest))
708+
// confirmation, err = cs.messageHandler.OnStopTransaction(chargePointId, request.(*StopTransactionRequest))
721709
//case StatusNotificationFeatureName:
722-
// confirmation, err = cs.coreListener.OnStatusNotification(chargePointId, request.(*StatusNotificationRequest))
710+
// confirmation, err = cs.messageHandler.OnStatusNotification(chargePointId, request.(*StatusNotificationRequest))
723711
//case DiagnosticsStatusNotificationFeatureName:
724712
// confirmation, err = cs.firmwareListener.OnDiagnosticsStatusNotification(chargePointId, request.(*DiagnosticsStatusNotificationRequest))
725713
//case FirmwareStatusNotificationFeatureName:

0 commit comments

Comments
 (0)