Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supported Measurands for OCPP1.6 #492

Merged
merged 2 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config/v16/profile_schemas/Internal.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@
"type": "integer",
"readOnly": true,
"minimum": 1
},
"SupportedMeasurands": {
"$comment": "Comma seperated list of supported measurands of the powermeter",
Pietfried marked this conversation as resolved.
Show resolved Hide resolved
"type": "string",
"readOnly": true,
"default": "Energy.Active.Import.Register,Energy.Active.Export.Register,Power.Active.Import,Voltage,Current.Import,Frequency,Current.Offered,Power.Offered"
}
},
"additionalProperties": false
Expand Down
3 changes: 3 additions & 0 deletions include/ocpp/v16/charge_point_configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ChargePointConfiguration {
bool measurands_supported(std::string csv);
json get_user_config();
void setInUserConfig(std::string profile, std::string key, json value);
void init_supported_measurands();

bool isConnectorPhaseRotationValid(std::string str);

Expand Down Expand Up @@ -84,6 +85,8 @@ class ChargePointConfiguration {
bool getVerifyCsmsCommonName();
KeyValue getVerifyCsmsCommonNameKeyValue();
bool getUseTPM();
std::string getSupportedMeasurands();
KeyValue getSupportedMeasurandsKeyValue();

int32_t getRetryBackoffRandomRange();
void setRetryBackoffRandomRange(int32_t retry_backoff_random_range);
Expand Down
76 changes: 65 additions & 11 deletions lib/ocpp/v16/charge_point_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <boost/algorithm/string/split.hpp>

#include <ocpp/common/schemas.hpp>
#include <ocpp/common/utils.hpp>
#include <ocpp/v16/charge_point_configuration.hpp>
#include <ocpp/v16/types.hpp>

Expand Down Expand Up @@ -96,17 +97,12 @@ ChargePointConfiguration::ChargePointConfiguration(const std::string& config, co
throw std::runtime_error("Core profile not listed in SupportedFeatureProfiles. This is required.");
}

// TODO(kai): get this from config
this->supported_measurands = {{Measurand::Energy_Active_Import_Register, {Phase::L1, Phase::L2, Phase::L3}}, // Wh
{Measurand::Energy_Active_Export_Register, {Phase::L1, Phase::L2, Phase::L3}}, // Wh
{Measurand::Power_Active_Import, {Phase::L1, Phase::L2, Phase::L3}}, // W
{Measurand::Voltage, {Phase::L1, Phase::L2, Phase::L3}}, // V
{Measurand::Current_Import, {Phase::L1, Phase::L2, Phase::L3, Phase::N}}, // A
{Measurand::Frequency, {Phase::L1, Phase::L2, Phase::L3}}, // Hz
{Measurand::Current_Offered, {}}}; // A
this->init_supported_measurands();

if (!this->validate_measurands(this->config)) {
EVLOG_AND_THROW(std::runtime_error("Given Measurands are invalid"));
EVLOG_AND_THROW(std::runtime_error("Given Measurands of either MeterValuesAlignedData, MeterValuesSampledData, "
"StopTxnAlignedData or StopTxnSampledData are invalid or do not match the "
"Measurands configured in SupportedMeasurands"));
}

this->supported_message_types_from_charge_point = {
Expand Down Expand Up @@ -207,6 +203,49 @@ std::string to_csl(const std::vector<std::string>& vec) {
return csl;
}

void ChargePointConfiguration::init_supported_measurands() {
const auto _supported_measurands = ocpp::get_vector_from_csv(this->config["Internal"]["SupportedMeasurands"]);
for (const auto& measurand : _supported_measurands) {
try {
const auto _measurand = conversions::string_to_measurand(measurand);
switch (_measurand) {
case Measurand::Energy_Active_Export_Register:
case Measurand::Energy_Active_Import_Register:
case Measurand::Energy_Reactive_Export_Register:
case Measurand::Energy_Reactive_Import_Register:
case Measurand::Energy_Active_Export_Interval:
case Measurand::Energy_Active_Import_Interval:
case Measurand::Energy_Reactive_Export_Interval:
case Measurand::Energy_Reactive_Import_Interval:
case Measurand::Power_Active_Export:
case Measurand::Power_Active_Import:
case Measurand::Voltage:
case Measurand::Frequency:
case Measurand::Power_Reactive_Export:
case Measurand::Power_Reactive_Import:
this->supported_measurands[_measurand] = {Phase::L1, Phase::L2, Phase::L3};
break;
case Measurand::Current_Import:
case Measurand::Current_Export:
this->supported_measurands[_measurand] = {Phase::L1, Phase::L2, Phase::L3, Phase::N};
break;
case Measurand::Power_Factor:
case Measurand::Current_Offered:
case Measurand::Power_Offered:
case Measurand::Temperature:
case Measurand::SoC:
case Measurand::RPM:
this->supported_measurands[_measurand] = {};
break;
default:
EVLOG_AND_THROW(std::runtime_error("Given SupportedMeasurands are invalid"));
}
} catch (std::out_of_range& o) {
EVLOG_AND_THROW(std::runtime_error("Given SupportedMeasurands are invalid"));
}
}
}

// Internal config options
std::string ChargePointConfiguration::getChargePointId() {
return this->config["Internal"]["ChargePointId"];
Expand Down Expand Up @@ -313,6 +352,10 @@ bool ChargePointConfiguration::getUseTPM() {
return this->config["Internal"]["UseTPM"];
}

std::string ChargePointConfiguration::getSupportedMeasurands() {
return this->config["Internal"]["SupportedMeasurands"];
}

KeyValue ChargePointConfiguration::getChargePointIdKeyValue() {
KeyValue kv;
kv.key = "ChargePointId";
Expand Down Expand Up @@ -502,6 +545,14 @@ KeyValue ChargePointConfiguration::getVerifyCsmsCommonNameKeyValue() {
return kv;
}

KeyValue ChargePointConfiguration::getSupportedMeasurandsKeyValue() {
KeyValue kv;
kv.key = "SupportedMeasurands";
kv.readonly = true;
kv.value.emplace(this->getSupportedMeasurands());
return kv;
}

KeyValue ChargePointConfiguration::getWebsocketPingPayloadKeyValue() {
KeyValue kv;
kv.key = "WebsocketPingPayload";
Expand Down Expand Up @@ -581,7 +632,7 @@ std::vector<MeasurandWithPhase> ChargePointConfiguration::csv_to_measurand_with_
MeasurandWithPhase measurand_with_phase;
Measurand measurand = conversions::string_to_measurand(component);
// check if this measurand can be provided on multiple phases
if (this->supported_measurands[measurand].size() > 0) {
if (this->supported_measurands.count(measurand) and this->supported_measurands.at(measurand).size() > 0) {
// multiple phases are available
// also add the measurand without a phase as a total value
measurand_with_phase.measurand = measurand;
Expand Down Expand Up @@ -623,7 +674,7 @@ bool ChargePointConfiguration::validate_measurands(const json& config) {
measurands_vector.push_back(config["Core"]["StopTxnAlignedData"]);
measurands_vector.push_back(config["Core"]["StopTxnSampledData"]);

for (const auto& measurands : measurands_vector) {
for (const auto measurands : measurands_vector) {
if (!this->measurands_supported(measurands)) {
return false;
}
Expand Down Expand Up @@ -2224,6 +2275,9 @@ std::optional<KeyValue> ChargePointConfiguration::get(CiString<50> key) {
if (key == "HostName") {
return this->getHostNameKeyValue();
}
if (key == "SupportedMeasurands") {
return this->getSupportedMeasurandsKeyValue();
}

// Core Profile
if (key == "AllowOfflineTxForUnknownId") {
Expand Down
Loading