@@ -64,6 +64,7 @@ StatusManager::StatusManager(const ocpp::config::IChargePointConfig& sta
6464 m_msg_sender (msg_sender),
6565 m_registration_status (RegistrationStatus::Rejected),
6666 m_force_boot_notification (false ),
67+ m_boot_notification_sent (false ),
6768 m_boot_notification_timer (timer_pool, " Boot notification" ),
6869 m_heartbeat_timer (timer_pool, " Heartbeat" )
6970{
@@ -401,56 +402,78 @@ bool StatusManager::handleMessage(const ocpp::messages::ChangeAvailabilityReq& r
401402/* * @brief Boot notification process thread */
402403void StatusManager::bootNotificationProcess ()
403404{
404- // Fill boot notification request
405- BootNotificationReq boot_req;
406- boot_req.chargeBoxSerialNumber .value ().assign (m_stack_config.chargeBoxSerialNumber ());
407- boot_req.chargePointModel .assign (m_stack_config.chargePointModel ());
408- boot_req.chargePointSerialNumber .value ().assign (m_stack_config.chargePointSerialNumber ());
409- boot_req.chargePointVendor .assign (m_stack_config.chargePointVendor ());
410- boot_req.firmwareVersion .value ().assign (m_stack_config.firmwareVersion ());
411- boot_req.iccid .value ().assign (m_stack_config.iccid ());
412- boot_req.imsi .value ().assign (m_stack_config.imsi ());
413- boot_req.meterSerialNumber .value ().assign (m_stack_config.meterSerialNumber ());
414-
415- // Send BootNotificationRequest
416- BootNotificationConf boot_conf;
417- CallResult result = m_msg_sender.call (BOOT_NOTIFICATION_ACTION, boot_req, boot_conf);
418- if (result == CallResult::Ok)
405+ if (m_boot_notification_sent == false )
419406 {
420- m_registration_status = boot_conf.status ;
421- if (m_registration_status == RegistrationStatus::Accepted)
407+ // Fill boot notification request
408+ BootNotificationReq boot_req;
409+ boot_req.chargeBoxSerialNumber .value ().assign (m_stack_config.chargeBoxSerialNumber ());
410+ boot_req.chargePointModel .assign (m_stack_config.chargePointModel ());
411+ boot_req.chargePointSerialNumber .value ().assign (m_stack_config.chargePointSerialNumber ());
412+ boot_req.chargePointVendor .assign (m_stack_config.chargePointVendor ());
413+ boot_req.firmwareVersion .value ().assign (m_stack_config.firmwareVersion ());
414+ boot_req.iccid .value ().assign (m_stack_config.iccid ());
415+ boot_req.imsi .value ().assign (m_stack_config.imsi ());
416+ boot_req.meterSerialNumber .value ().assign (m_stack_config.meterSerialNumber ());
417+
418+ m_registration_status = RegistrationStatus::Rejected;
419+
420+ // Send BootNotificationRequest
421+ BootNotificationConf boot_conf;
422+ CallResult result = m_msg_sender.call (BOOT_NOTIFICATION_ACTION, boot_req, boot_conf);
423+ if (result == CallResult::Ok)
422424 {
423- // Send first status notifications
424- for (unsigned int id = 0 ; id <= m_connectors.getCount (); id++)
425+ if (boot_conf.status == RegistrationStatus::Accepted)
425426 {
426- statusNotificationProcess (id);
427+ m_boot_notification_sent = true ;
428+
429+ // Send first status notifications
430+ for (unsigned int id = 0 ; id <= m_connectors.getCount (); id++)
431+ {
432+ statusNotificationProcess (id);
433+ }
434+
435+ // Configure hearbeat
436+ std::chrono::seconds interval (boot_conf.interval );
437+ m_ocpp_config.heartbeatInterval (interval);
438+ m_heartbeat_timer.start (std::chrono::milliseconds (interval));
427439 }
440+ else
441+ {
442+ // Schedule next retry
443+ m_boot_notification_timer.start (std::chrono::seconds (boot_conf.interval ), true );
444+ }
445+
446+ m_registration_status = boot_conf.status ;
447+ std::string registration_status = RegistrationStatusHelper.toString (m_registration_status);
448+ LOG_INFO << " Registration status : " << registration_status;
428449
429- // Configure hearbeat
430- std::chrono::seconds interval (boot_conf.interval );
431- m_ocpp_config.heartbeatInterval (interval);
432- m_heartbeat_timer.start (std::chrono::milliseconds (interval));
450+ // Save registration status
451+ m_force_boot_notification = false ;
452+ m_internal_config.setKey (LAST_REGISTRATION_STATUS_KEY, registration_status);
453+
454+ // Notify boot
455+ m_events_handler.bootNotification (m_registration_status, boot_conf.currentTime );
433456 }
434457 else
435458 {
436459 // Schedule next retry
437- m_boot_notification_timer.start (std::chrono::seconds (boot_conf. interval ), true );
460+ m_boot_notification_timer.start (m_stack_config. retryInterval ( ), true );
438461 }
439-
440- std::string registration_status = RegistrationStatusHelper.toString (m_registration_status);
441- LOG_INFO << " Registration status : " << registration_status;
442-
443- // Save registration status
444- m_force_boot_notification = false ;
445- m_internal_config.setKey (LAST_REGISTRATION_STATUS_KEY, registration_status);
446-
447- // Notify boot
448- m_events_handler.bootNotification (m_registration_status, boot_conf.currentTime );
449462 }
450463 else
451464 {
452- // Schedule next retry
453- m_boot_notification_timer.start (m_stack_config.retryInterval (), true );
465+ // If the status of a connector has changed since the last notification
466+ // to the central system, send the new connector status
467+ for (const Connector* connector : m_connectors.getConnectors ())
468+ {
469+ if (connector->status != connector->last_notified_status )
470+ {
471+ statusNotificationProcess (connector->id );
472+ }
473+ }
474+
475+ // Configure hearbeat
476+ m_heartbeat_timer.start (m_ocpp_config.heartbeatInterval ());
454477 }
455478}
456479
0 commit comments