Skip to content

Commit 9bad56a

Browse files
authored
Merge pull request #206 from c-jimenez/develop
Release 1.5.2
2 parents 84837fc + d553904 commit 9bad56a

File tree

11 files changed

+133
-63
lines changed

11 files changed

+133
-63
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
cmake_minimum_required(VERSION 3.13)
66

77
project(OpenOCPP DESCRIPTION "Open Source C++ implementation of the OCPP 1.6 protocol"
8-
VERSION 1.5.1
8+
VERSION 1.5.2
99
)
1010

1111
# Definitions for Version.h file

src/centralsystem/chargepoint/ChargePointProxy.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ ChargePointProxy::ChargePointProxy(ICentralSystem&
7878

7979
/** @brief Destructor */
8080
ChargePointProxy::~ChargePointProxy()
81+
{
82+
unregisterFromRpcSpy();
83+
}
84+
85+
/** @brief Unregister to the IRpc::ISpy interface messages */
86+
void ChargePointProxy::unregisterFromRpcSpy()
8187
{
8288
m_rpc->unregisterSpy(*this);
8389
}

src/centralsystem/chargepoint/ChargePointProxy.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ class ChargePointProxy : public ICentralSystem::IChargePoint, public ocpp::rpc::
5858
/** @brief Destructor */
5959
virtual ~ChargePointProxy();
6060

61+
/** @brief Unregister to the IRpc::ISpy interface messages */
62+
void unregisterFromRpcSpy();
63+
6164
// ICentralSystem::IChargePoint interface
6265

6366
/** @copydoc ICentralSystem&& ICentralSystem::IChargePoint::centralSystem() */

src/chargepoint/reservation/ReservationManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ bool ReservationManager::handleMessage(const ocpp::messages::ReserveNowReq& requ
185185
if (connector)
186186
{
187187
// Check if reservation is allowed on connector
188-
if (((request.connectorId != 0) || ((request.connectorId == 0) && m_ocpp_config.reserveConnectorZeroSupported()))
189-
&&( m_ocpp_config.supportedFeatureProfiles().find("Reservation")!= std::string::npos) )
188+
if (((request.connectorId != 0) || ((request.connectorId == 0) && m_ocpp_config.reserveConnectorZeroSupported())) &&
189+
(m_ocpp_config.supportedFeatureProfiles().find("Reservation") != std::string::npos))
190190
{
191191
std::lock_guard<std::mutex> lock(connector->mutex);
192192

src/chargepoint/smartcharging/SmartChargingManager.cpp

Lines changed: 35 additions & 13 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,
@@ -356,9 +367,26 @@ bool SmartChargingManager::handleMessage(const ocpp::messages::GetCompositeSched
356367
(void)error_code;
357368
(void)error_message;
358369

370+
ocpp::types::ChargingRateUnitType charging_rate_unit;
371+
if (!request.chargingRateUnit.isSet())
372+
{
373+
if (m_ocpp_config.chargingScheduleAllowedChargingRateUnit().find("Power") != std::string::npos)
374+
{
375+
charging_rate_unit = types::ChargingRateUnitType::W;
376+
}
377+
else
378+
{
379+
charging_rate_unit = types::ChargingRateUnitType::A;
380+
}
381+
}
382+
else
383+
{
384+
charging_rate_unit = request.chargingRateUnit.value();
385+
}
386+
359387
LOG_INFO << "GetCompositeSchedule requested : connectorId = " << request.connectorId << " - duration = " << request.duration
360-
<< " - chargingRateUnit = "
361-
<< (request.chargingRateUnit.isSet() ? ChargingRateUnitTypeHelper.toString(request.chargingRateUnit) : "not set");
388+
<< " - chargingRateUnit = " << ChargingRateUnitTypeHelper.toString(charging_rate_unit)
389+
<< (!request.chargingRateUnit.isSet() ? " (from allowed charging unit)" : "");
362390

363391
// Lock profiles
364392
std::lock_guard<std::mutex> lock(m_mutex);
@@ -442,14 +470,8 @@ bool SmartChargingManager::handleMessage(const ocpp::messages::GetCompositeSched
442470

443471
ChargingSchedule& schedule = response.chargingSchedule.value();
444472
schedule.duration = 0;
445-
if (request.chargingRateUnit.isSet())
446-
{
447-
schedule.chargingRateUnit = request.chargingRateUnit;
448-
}
449-
else
450-
{
451-
schedule.chargingRateUnit = ChargingRateUnitType::A;
452-
}
473+
schedule.chargingRateUnit = charging_rate_unit;
474+
453475
// Adjust start if needed since first period must start at 0
454476
time_t offset = periods[0].start;
455477
schedule.startSchedule = DateTime(now.timestamp() + offset);

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 */

src/localcontroller/chargepoint/ChargePointProxy.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ std::shared_ptr<IChargePointProxy> IChargePointProxy::createFrom(
5656

5757
// Associate both
5858
centralsystem->setChargePointProxy(proxy);
59+
60+
// Unregister old proxy from RPC spy events
61+
cs_proxy->unregisterFromRpcSpy();
5962
}
6063

6164
return proxy;

src/messages/IMessageConverter.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,19 +290,25 @@ class IMessageConverter
290290
class MessageType##ReqConverter : public IMessageConverter<MessageType##Req> \
291291
{ \
292292
public: \
293-
IMessageConverter<MessageType##Req>* clone() const override { return new MessageType##ReqConverter(); } \
293+
IMessageConverter<MessageType##Req>* clone() const override \
294+
{ \
295+
return new MessageType##ReqConverter(); \
296+
} \
294297
bool fromJson(const rapidjson::Value& json, MessageType##Req& data, std::string& error_code, std::string& error_message) override; \
295298
bool toJson(const MessageType##Req& data, rapidjson::Document& json) override; \
296299
}; \
297300
class MessageType##ConfConverter : public IMessageConverter<MessageType##Conf> \
298301
{ \
299302
public: \
300-
IMessageConverter<MessageType##Conf>* clone() const override { return new MessageType##ConfConverter(); } \
301-
bool fromJson(const rapidjson::Value& json, \
302-
MessageType##Conf& data, \
303-
std::string& error_code, \
304-
std::string& error_message) override; \
305-
bool toJson(const MessageType##Conf& data, rapidjson::Document& json) override; \
303+
IMessageConverter<MessageType##Conf>* clone() const override \
304+
{ \
305+
return new MessageType##ConfConverter(); \
306+
} \
307+
bool fromJson(const rapidjson::Value& json, \
308+
MessageType##Conf& data, \
309+
std::string& error_code, \
310+
std::string& error_message) override; \
311+
bool toJson(const MessageType##Conf& data, rapidjson::Document& json) override; \
306312
};
307313

308314
} // namespace messages

tests/tools/test_database.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,8 @@ TEST_SUITE("Database class test suite")
135135
CHECK_EQ(query.get(), nullptr);
136136
}
137137

138-
TEST_CASE("Cleanup") { std::filesystem::remove(test_database_path); }
138+
TEST_CASE("Cleanup")
139+
{
140+
std::filesystem::remove(test_database_path);
141+
}
139142
}

tests/tools/test_logs.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,10 @@ TEST_SUITE("Database class test suite")
201201
CHECK_FALSE(query->next());
202202
}
203203

204-
TEST_CASE("Cleanup") { std::filesystem::remove(test_database_path); }
204+
TEST_CASE("Cleanup")
205+
{
206+
std::filesystem::remove(test_database_path);
207+
}
205208
}
206209

207210
#endif // EXTERNAL_LOGGER

0 commit comments

Comments
 (0)