Skip to content

Commit

Permalink
Merge pull request #203 from c-jimenez/fix/boot_notif_set_charging_pr…
Browse files Browse the repository at this point in the history
…ofile

Fix/boot notif set charging profile
  • Loading branch information
c-jimenez authored Apr 18, 2024
2 parents 2bd05e4 + f33d005 commit f8fcb33
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 41 deletions.
17 changes: 14 additions & 3 deletions src/chargepoint/smartcharging/SmartChargingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,19 @@ bool SmartChargingManager::handleMessage(const ocpp::messages::SetChargingProfil
// Check if a transaction is in progress for the specific connector
if (connector->transaction_id != 0)
{
// Add profile
ret = true;
if (request.csChargingProfiles.transactionId.isSet())
{
if (request.csChargingProfiles.transactionId.value() == connector->transaction_id)
{
// Add profile
ret = true;
}
}
else
{
// Add profile
ret = true;
}
}
}
break;
Expand Down Expand Up @@ -340,7 +351,7 @@ bool SmartChargingManager::handleMessage(const ocpp::messages::SetChargingProfil
LOG_INFO << "Set charging profile status rejected : " << error_message;
}

return ret;
return true;
}

/** @copydoc bool GenericMessageHandler<RequestType, ResponseType>::handleMessage(const RequestType& request,
Expand Down
97 changes: 60 additions & 37 deletions src/chargepoint/status/StatusManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ StatusManager::StatusManager(const ocpp::config::IChargePointConfig& sta
m_msg_sender(msg_sender),
m_registration_status(RegistrationStatus::Rejected),
m_force_boot_notification(false),
m_boot_notification_sent(false),
m_boot_notification_timer(timer_pool, "Boot notification"),
m_heartbeat_timer(timer_pool, "Heartbeat")
{
Expand Down Expand Up @@ -401,56 +402,78 @@ bool StatusManager::handleMessage(const ocpp::messages::ChangeAvailabilityReq& r
/** @brief Boot notification process thread */
void StatusManager::bootNotificationProcess()
{
// Fill boot notification request
BootNotificationReq boot_req;
boot_req.chargeBoxSerialNumber.value().assign(m_stack_config.chargeBoxSerialNumber());
boot_req.chargePointModel.assign(m_stack_config.chargePointModel());
boot_req.chargePointSerialNumber.value().assign(m_stack_config.chargePointSerialNumber());
boot_req.chargePointVendor.assign(m_stack_config.chargePointVendor());
boot_req.firmwareVersion.value().assign(m_stack_config.firmwareVersion());
boot_req.iccid.value().assign(m_stack_config.iccid());
boot_req.imsi.value().assign(m_stack_config.imsi());
boot_req.meterSerialNumber.value().assign(m_stack_config.meterSerialNumber());

// Send BootNotificationRequest
BootNotificationConf boot_conf;
CallResult result = m_msg_sender.call(BOOT_NOTIFICATION_ACTION, boot_req, boot_conf);
if (result == CallResult::Ok)
if (m_boot_notification_sent == false)
{
m_registration_status = boot_conf.status;
if (m_registration_status == RegistrationStatus::Accepted)
// Fill boot notification request
BootNotificationReq boot_req;
boot_req.chargeBoxSerialNumber.value().assign(m_stack_config.chargeBoxSerialNumber());
boot_req.chargePointModel.assign(m_stack_config.chargePointModel());
boot_req.chargePointSerialNumber.value().assign(m_stack_config.chargePointSerialNumber());
boot_req.chargePointVendor.assign(m_stack_config.chargePointVendor());
boot_req.firmwareVersion.value().assign(m_stack_config.firmwareVersion());
boot_req.iccid.value().assign(m_stack_config.iccid());
boot_req.imsi.value().assign(m_stack_config.imsi());
boot_req.meterSerialNumber.value().assign(m_stack_config.meterSerialNumber());

m_registration_status = RegistrationStatus::Rejected;

// Send BootNotificationRequest
BootNotificationConf boot_conf;
CallResult result = m_msg_sender.call(BOOT_NOTIFICATION_ACTION, boot_req, boot_conf);
if (result == CallResult::Ok)
{
// Send first status notifications
for (unsigned int id = 0; id <= m_connectors.getCount(); id++)
if (boot_conf.status == RegistrationStatus::Accepted)
{
statusNotificationProcess(id);
m_boot_notification_sent = true;

// Send first status notifications
for (unsigned int id = 0; id <= m_connectors.getCount(); id++)
{
statusNotificationProcess(id);
}

// Configure hearbeat
std::chrono::seconds interval(boot_conf.interval);
m_ocpp_config.heartbeatInterval(interval);
m_heartbeat_timer.start(std::chrono::milliseconds(interval));
}
else
{
// Schedule next retry
m_boot_notification_timer.start(std::chrono::seconds(boot_conf.interval), true);
}

m_registration_status = boot_conf.status;
std::string registration_status = RegistrationStatusHelper.toString(m_registration_status);
LOG_INFO << "Registration status : " << registration_status;

// Configure hearbeat
std::chrono::seconds interval(boot_conf.interval);
m_ocpp_config.heartbeatInterval(interval);
m_heartbeat_timer.start(std::chrono::milliseconds(interval));
// Save registration status
m_force_boot_notification = false;
m_internal_config.setKey(LAST_REGISTRATION_STATUS_KEY, registration_status);

// Notify boot
m_events_handler.bootNotification(m_registration_status, boot_conf.currentTime);
}
else
{
// Schedule next retry
m_boot_notification_timer.start(std::chrono::seconds(boot_conf.interval), true);
m_boot_notification_timer.start(m_stack_config.retryInterval(), true);
}

std::string registration_status = RegistrationStatusHelper.toString(m_registration_status);
LOG_INFO << "Registration status : " << registration_status;

// Save registration status
m_force_boot_notification = false;
m_internal_config.setKey(LAST_REGISTRATION_STATUS_KEY, registration_status);

// Notify boot
m_events_handler.bootNotification(m_registration_status, boot_conf.currentTime);
}
else
{
// Schedule next retry
m_boot_notification_timer.start(m_stack_config.retryInterval(), true);
// If the status of a connector has changed since the last notification
// to the central system, send the new connector status
for (const Connector* connector : m_connectors.getConnectors())
{
if (connector->status != connector->last_notified_status)
{
statusNotificationProcess(connector->id);
}
}

// Configure hearbeat
m_heartbeat_timer.start(m_ocpp_config.heartbeatInterval());
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/chargepoint/status/StatusManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ class StatusManager
ocpp::types::RegistrationStatus m_registration_status;
/** @brief Indicate if the boot notification message must be inconditionnaly sent on connection */
bool m_force_boot_notification;

/** @brief Indicate if the boot notification message has been sent */
bool m_boot_notification_sent;
/** @brief Boot notification process timer */
ocpp::helpers::Timer m_boot_notification_timer;
/** @brief Heartbeat timer */
Expand Down

0 comments on commit f8fcb33

Please sign in to comment.