Skip to content

Commit ceb2aa4

Browse files
mheistephenredhat
authored andcommitted
Add helper methods to set common charge point data (EVerest#1026)
The idea is to overwrite this data later, for example if other data sources are available than those available at the time of initialization. For this, 3 new methods are introduced which covers the three common data domains like general common data, modem and meter related data. Signed-off-by: Michael Heimpold <[email protected]>
1 parent c731e7e commit ceb2aa4

6 files changed

Lines changed: 144 additions & 1 deletion

File tree

include/ocpp/v16/charge_point.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include <ocpp/v2/messages/SignCertificate.hpp>
3333
#include <ocpp/v2/messages/TriggerMessage.hpp>
3434

35+
#include <optional>
36+
3537
namespace ocpp {
3638
namespace v16 {
3739
class ChargePointImpl;
@@ -81,6 +83,26 @@ class ChargePoint {
8183
/// @} // End constructors 1.6 group
8284
/// @} // End chargepoint constructors topic
8385

86+
/// \brief Allow to update the ChargePoint core information which will be sent in BootNotification.req
87+
/// While `vendor` and `model` strings are both required, all other values are optional.
88+
/// Passing `std::nullopt` keeps the current existing value, i.e. does not touch the current
89+
/// value at all, other strings replace the corresponding current value.
90+
void update_chargepoint_information(const std::string& vendor, const std::string& model,
91+
const std::optional<std::string>& serialnumber,
92+
const std::optional<std::string>& chargebox_serialnumber,
93+
const std::optional<std::string>& firmware_version);
94+
95+
/// \brief Allow to update the ChargePoint's modem information which will be sent in BootNotification.req
96+
/// Passing `std::nullopt` keeps the current existing value, i.e. does not touch the current value at all.
97+
/// Passing other strings replace the corresponding current value.
98+
void update_modem_information(const std::optional<std::string>& iccid, const std::optional<std::string>& imsi);
99+
100+
/// \brief Allow to update the ChargePoint's meter information which will be sent in BootNotification.req
101+
/// Passing `std::nullopt` keeps the current existing value, i.e. does not touch the current value at all,
102+
/// other strings replace the corresponding current value.
103+
void update_meter_information(const std::optional<std::string>& meter_serialnumber,
104+
const std::optional<std::string>& meter_type);
105+
84106
/// \brief Initializes the ChargePoint and all of it's connectors, the state machine and message queue. This method
85107
/// should be called if a more granular start of the process is necessary. Notably if it is necessary for the state
86108
/// machine and the connectors (and their statuses) need to be updated prior to initiating connection with the CSMS.

include/ocpp/v16/charge_point_configuration.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#define OCPP_V16_CHARGE_POINT_CONFIGURATION_HPP
55

66
#include <mutex>
7+
#include <optional>
78
#include <set>
89

910
#include <ocpp/common/support_older_cpp_versions.hpp>
@@ -40,10 +41,20 @@ class ChargePointConfiguration {
4041

4142
bool checkTimeOffset(const std::string& offset);
4243

44+
void setChargepointInformationProperty(json& user_config, const std::string& key,
45+
const std::optional<std::string>& value);
46+
4347
public:
4448
ChargePointConfiguration(const std::string& config, const fs::path& ocpp_main_path,
4549
const fs::path& user_config_path);
46-
50+
void setChargepointInformation(const std::string& chargePointVendor, const std::string& chargePointModel,
51+
const std::optional<std::string>& chargePointSerialNumber,
52+
const std::optional<std::string>& chargeBoxSerialNumber,
53+
const std::optional<std::string>& firmwareVersion);
54+
void setChargepointModemInformation(const std::optional<std::string>& ICCID,
55+
const std::optional<std::string>& IMSI);
56+
void setChargepointMeterInformation(const std::optional<std::string>& meterSerialNumber,
57+
const std::optional<std::string>& meterType);
4758
// Internal config options
4859
std::string getChargePointId();
4960
KeyValue getChargePointIdKeyValue();

include/ocpp/v16/charge_point_impl.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <iostream>
1111
#include <mutex>
1212
#include <ocpp/common/support_older_cpp_versions.hpp>
13+
#include <optional>
1314
#include <set>
1415

1516
#include <everest/timer.hpp>
@@ -418,6 +419,19 @@ class ChargePointImpl : ocpp::ChargingStationBase {
418419
~ChargePointImpl() {
419420
}
420421

422+
/// \brief Allow to update the ChargePoint core information which will be sent in BootNotification.req
423+
void update_chargepoint_information(const std::string& vendor, const std::string& model,
424+
const std::optional<std::string>& serialnumber,
425+
const std::optional<std::string>& chargebox_serialnumber,
426+
const std::optional<std::string>& firmware_version);
427+
428+
/// \brief Allow to update the ChargePoint modem information
429+
void update_modem_information(const std::optional<std::string>& iccid, const std::optional<std::string>& imsi);
430+
431+
/// \brief Allow to update the ChargePoint meter information
432+
void update_meter_information(const std::optional<std::string>& meter_serialnumber,
433+
const std::optional<std::string>& meter_type);
434+
421435
/// \brief Initializes the ChargePoint and all of it's connectors, the state machine and message queue. This method
422436
/// should be called if a more granular start of the process is necessary. Notably if it is necessary for the state
423437
/// machine and the connectors (and their statuses) need to be updated prior to initiating connection with the CSMS.

lib/ocpp/v16/charge_point.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@ ChargePoint::ChargePoint(const std::string& config, const fs::path& share_path,
2121

2222
ChargePoint::~ChargePoint() = default;
2323

24+
void ChargePoint::update_chargepoint_information(const std::string& vendor, const std::string& model,
25+
const std::optional<std::string>& serialnumber,
26+
const std::optional<std::string>& chargebox_serialnumber,
27+
const std::optional<std::string>& firmware_version) {
28+
this->charge_point->update_chargepoint_information(vendor, model, serialnumber, chargebox_serialnumber,
29+
firmware_version);
30+
}
31+
32+
void ChargePoint::update_modem_information(const std::optional<std::string>& iccid,
33+
const std::optional<std::string>& imsi) {
34+
this->charge_point->update_modem_information(iccid, imsi);
35+
}
36+
37+
void ChargePoint::update_meter_information(const std::optional<std::string>& meter_serialnumber,
38+
const std::optional<std::string>& meter_type) {
39+
this->charge_point->update_meter_information(meter_serialnumber, meter_type);
40+
}
41+
2442
bool ChargePoint::init(const std::map<int, ChargePointStatus>& connector_status_map,
2543
const std::set<std::string>& resuming_session_ids) {
2644
return this->charge_point->init(connector_status_map, resuming_session_ids);

lib/ocpp/v16/charge_point_configuration.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,66 @@ void ChargePointConfiguration::init_supported_measurands() {
270270
}
271271
}
272272

273+
void ChargePointConfiguration::setChargepointInformationProperty(json& user_config, const std::string& key,
274+
const std::optional<std::string>& value) {
275+
// std::nullopt value leaves the current value untouched
276+
if (value.has_value()) {
277+
this->config["Internal"][key] = value.value();
278+
user_config["Internal"][key] = value.value();
279+
}
280+
}
281+
282+
void ChargePointConfiguration::setChargepointInformation(const std::string& chargePointVendor,
283+
const std::string& chargePointModel,
284+
const std::optional<std::string>& chargePointSerialNumber,
285+
const std::optional<std::string>& chargeBoxSerialNumber,
286+
const std::optional<std::string>& firmwareVersion) {
287+
// load current persistent configuration from disk
288+
json user_config = this->get_user_config();
289+
290+
this->config["Internal"]["ChargePointVendor"] = chargePointVendor;
291+
user_config["Internal"]["ChargePointVendor"] = chargePointVendor;
292+
293+
this->config["Internal"]["ChargePointModel"] = chargePointModel;
294+
user_config["Internal"]["ChargePointModel"] = chargePointModel;
295+
296+
setChargepointInformationProperty(user_config, "ChargePointSerialNumber", chargePointSerialNumber);
297+
setChargepointInformationProperty(user_config, "ChargeBoxSerialNumber", chargeBoxSerialNumber);
298+
setChargepointInformationProperty(user_config, "FirmwareVersion", firmwareVersion);
299+
300+
// save the changes back
301+
std::ofstream ofs(this->user_config_path.c_str());
302+
ofs << user_config << std::endl;
303+
ofs.close();
304+
}
305+
306+
void ChargePointConfiguration::setChargepointModemInformation(const std::optional<std::string>& ICCID,
307+
const std::optional<std::string>& IMSI) {
308+
// load current persistent configuration from disk
309+
json user_config = this->get_user_config();
310+
311+
setChargepointInformationProperty(user_config, "ICCID", ICCID);
312+
setChargepointInformationProperty(user_config, "IMSI", IMSI);
313+
314+
// save the changes back
315+
std::ofstream ofs(this->user_config_path.c_str());
316+
ofs << user_config << std::endl;
317+
ofs.close();
318+
}
319+
void ChargePointConfiguration::setChargepointMeterInformation(const std::optional<std::string>& meterSerialNumber,
320+
const std::optional<std::string>& meterType) {
321+
// load current persistent configuration from disk
322+
json user_config = this->get_user_config();
323+
324+
setChargepointInformationProperty(user_config, "MeterSerialNumber", meterSerialNumber);
325+
setChargepointInformationProperty(user_config, "MeterType", meterType);
326+
327+
// save the changes back
328+
std::ofstream ofs(this->user_config_path.c_str());
329+
ofs << user_config << std::endl;
330+
ofs.close();
331+
}
332+
273333
// Internal config options
274334
std::string ChargePointConfiguration::getChargePointId() {
275335
return this->config["Internal"]["ChargePointId"];

lib/ocpp/v16/charge_point_impl.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,24 @@ void ChargePointImpl::reset_pricing_triggers(const int32_t connector_number) {
10901090
}
10911091
}
10921092

1093+
void ChargePointImpl::update_chargepoint_information(const std::string& vendor, const std::string& model,
1094+
const std::optional<std::string>& serialnumber,
1095+
const std::optional<std::string>& chargebox_serialnumber,
1096+
const std::optional<std::string>& firmware_version) {
1097+
this->configuration->setChargepointInformation(vendor, model, serialnumber, chargebox_serialnumber,
1098+
firmware_version);
1099+
}
1100+
1101+
void ChargePointImpl::update_modem_information(const std::optional<std::string>& iccid,
1102+
const std::optional<std::string>& imsi) {
1103+
this->configuration->setChargepointModemInformation(iccid, imsi);
1104+
}
1105+
1106+
void ChargePointImpl::update_meter_information(const std::optional<std::string>& meter_serialnumber,
1107+
const std::optional<std::string>& meter_type) {
1108+
this->configuration->setChargepointMeterInformation(meter_serialnumber, meter_type);
1109+
}
1110+
10931111
bool ChargePointImpl::init(const std::map<int, ChargePointStatus>& connector_status_map,
10941112
const std::set<std::string>& resuming_session_ids) {
10951113
// push transaction messages including SecurityEventNotification.req onto the message queue

0 commit comments

Comments
 (0)