Skip to content

Commit f8fcb33

Browse files
authored
Merge pull request #203 from c-jimenez/fix/boot_notif_set_charging_profile
Fix/boot notif set charging profile
2 parents 2bd05e4 + f33d005 commit f8fcb33

File tree

3 files changed

+76
-41
lines changed

3 files changed

+76
-41
lines changed

src/chargepoint/smartcharging/SmartChargingManager.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,19 @@ bool SmartChargingManager::handleMessage(const ocpp::messages::SetChargingProfil
281281
// Check if a transaction is in progress for the specific connector
282282
if (connector->transaction_id != 0)
283283
{
284-
// Add profile
285-
ret = true;
284+
if (request.csChargingProfiles.transactionId.isSet())
285+
{
286+
if (request.csChargingProfiles.transactionId.value() == connector->transaction_id)
287+
{
288+
// Add profile
289+
ret = true;
290+
}
291+
}
292+
else
293+
{
294+
// Add profile
295+
ret = true;
296+
}
286297
}
287298
}
288299
break;
@@ -340,7 +351,7 @@ bool SmartChargingManager::handleMessage(const ocpp::messages::SetChargingProfil
340351
LOG_INFO << "Set charging profile status rejected : " << error_message;
341352
}
342353

343-
return ret;
354+
return true;
344355
}
345356

346357
/** @copydoc bool GenericMessageHandler<RequestType, ResponseType>::handleMessage(const RequestType& request,

src/chargepoint/status/StatusManager.cpp

Lines changed: 60 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -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 */
402403
void 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

src/chargepoint/status/StatusManager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ class StatusManager
142142
ocpp::types::RegistrationStatus m_registration_status;
143143
/** @brief Indicate if the boot notification message must be inconditionnaly sent on connection */
144144
bool m_force_boot_notification;
145-
145+
/** @brief Indicate if the boot notification message has been sent */
146+
bool m_boot_notification_sent;
146147
/** @brief Boot notification process timer */
147148
ocpp::helpers::Timer m_boot_notification_timer;
148149
/** @brief Heartbeat timer */

0 commit comments

Comments
 (0)