@@ -8,20 +8,14 @@ import (
88)
99
1010type 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.
3730func (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.
249237func (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.
268252func (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.
319294func (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:
0 commit comments