Skip to content

Commit

Permalink
J01- Non transaction meter values
Browse files Browse the repository at this point in the history
- evseId =0 values
* Send IdleMeasurements
* Add phase rotation varaible
  • Loading branch information
SNSubramanya authored Oct 17, 2023
1 parent 2b4f3ea commit 8292d0c
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 2 deletions.
15 changes: 15 additions & 0 deletions config/v201/component_schemas/standardized/ChargingStation.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@
"description": "This variable reports current availability state for the ChargingStation",
"type": "string"
},
"ChargingStationPhaseRotation": {
"variable_name": "PhaseRotation",
"characteristics": {
"supportsMonitoring": true,
"dataType": "string"
},
"attributes": [
{
"type": "Actual",
"mutability": "ReadWrite"
}
],
"description": "This variable describes the phase rotation of a Component relative to its parent Component, using a three letter string consisting of the letters: R, S, T and x.",
"type": "string"
},
"ChargingStationAvailable": {
"variable_name": "Available",
"characteristics": {
Expand Down
14 changes: 13 additions & 1 deletion config/v201/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,12 @@
"attributes": {
"Actual": "Energy.Active.Import.Register"
}
},
"AlignedDataSendDuringIdle": {
"variable_name": "SendDuringIdle",
"attributes": {
"Actual": false
}
}
}
},
Expand Down Expand Up @@ -497,6 +503,12 @@
"attributes": {
"Actual": 42
}
},
"ChargingStationPhaseRotation": {
"variable_name": "PhaseRotation",
"attributes": {
"Actual": "RST"
}
}
}
},
Expand Down Expand Up @@ -658,4 +670,4 @@
}
}
}
]
]
8 changes: 8 additions & 0 deletions include/ocpp/v201/charge_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ class ChargePoint : ocpp::ChargingStationBase {
std::map<EvseConnectorPair, ConnectorStatusEnum> conn_state_per_evse;
std::chrono::time_point<std::chrono::steady_clock> time_disconnected;

MeterValue meter_value; // represents evseId = 0 meter value
std::mutex meter_value_mutex;

/// \brief Used when an 'OnIdle' reset is requested, to perform the reset after the charging has stopped.
bool reset_scheduled;
/// \brief If `reset_scheduled` is true and the reset is for a specific evse id, it will be stored in this member.
Expand Down Expand Up @@ -262,6 +265,11 @@ class ChargePoint : ocpp::ChargingStationBase {
/// @brief Get the value optional offline flag
/// @return true if the charge point is offline. std::nullopt if it is online;
bool is_offline();

/// \brief Returns the last present meter value for evseId 0
/// \return MeterValue
MeterValue get_meter_value();

/* OCPP message requests */

// Functional Block A: Security
Expand Down
31 changes: 30 additions & 1 deletion lib/ocpp/v201/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,18 @@ void ChargePoint::on_session_finished(const int32_t evse_id, const int32_t conne
}

void ChargePoint::on_meter_value(const int32_t evse_id, const MeterValue& meter_value) {
this->evses.at(evse_id)->on_meter_value(meter_value);
if (evse_id == 0) {
std::lock_guard<std::mutex> lk(this->meter_value_mutex);
// if evseId = 0 then store in the chargepoint metervalues
this->meter_value = meter_value;
} else {
this->evses.at(evse_id)->on_meter_value(meter_value);
}
}

MeterValue ChargePoint::get_meter_value() {
std::lock_guard<std::mutex> lk(this->meter_value_mutex);
return this->meter_value;
}

void ChargePoint::on_unavailable(const int32_t evse_id, const int32_t connector_id) {
Expand Down Expand Up @@ -897,6 +908,7 @@ void ChargePoint::update_aligned_data_interval() {
EVLOG_debug << "Next meter value will be sent at: " << next_timestamp.value().to_rfc3339();
this->aligned_meter_values_timer.at(
[this]() {
bool transaction_active = false;
for (auto const& [evse_id, evse] : this->evses) {
auto _meter_value = evse->get_meter_value();
// this will apply configured measurands and possibly reduce the entries of sampledValue
Expand All @@ -906,6 +918,7 @@ void ChargePoint::update_aligned_data_interval() {
ControllerComponentVariables::AlignedDataMeasurands);

if (evse->has_active_transaction()) {
transaction_active = true;
// because we do not actively read meter values at clock aligned timepoint, we switch the
// ReadingContext here
for (auto& sampled_value : _meter_value.sampledValue) {
Expand All @@ -926,12 +939,28 @@ void ChargePoint::update_aligned_data_interval() {
this->device_model
->get_optional_value<bool>(ControllerComponentVariables::AlignedDataSendDuringIdle)
.value_or(false)) {
transaction_active = false;
if (!meter_value.sampledValue.empty()) {
// J01.FR.14 this is the only case where we send a MeterValue.req
this->meter_values_req(evse_id, std::vector<ocpp::v201::MeterValue>(1, meter_value));
}
}
}
// also send meter values for evseId 0 if no transactions are on going
if (!transaction_active) {
auto _meter_value = this->get_meter_value();

// this will apply configured measurands and possibly reduce the entries of sampledValue
// according to the configuration
const auto meter_value =
get_latest_meter_value_filtered(_meter_value, ReadingContextEnum::Sample_Clock,
ControllerComponentVariables::AlignedDataMeasurands);

if (!meter_value.sampledValue.empty()) {
this->meter_values_req(0, std::vector<ocpp::v201::MeterValue>(1, meter_value));
}
}

this->update_aligned_data_interval();
},
next_timestamp.value().to_time_point());
Expand Down
8 changes: 8 additions & 0 deletions lib/ocpp/v201/ctrlr_component_variables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,14 @@ const ComponentVariable& ChargingStationAvailabilityState = {
"AvailabilityState",
}),
};
const ComponentVariable& ChargingStationPhaseRotation = {
ControllerComponents::ChargingStation,
std::nullopt,
std::optional<Variable>({
"PhaseRotation",
}),
};

const ComponentVariable& ChargingStationAvailable = {
ControllerComponents::ChargingStation,
std::nullopt,
Expand Down

0 comments on commit 8292d0c

Please sign in to comment.