Skip to content

Commit

Permalink
E04: all offline trsactions must contain "offline" = true flag
Browse files Browse the repository at this point in the history
  • Loading branch information
SNSubramanya committed Sep 15, 2023
1 parent e74bbc1 commit 14c22d2
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions lib/ocpp/v201/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,16 @@ ChargePoint::ChargePoint(const std::map<int32_t, int32_t>& evse_connector_struct
const auto filtered_meter_value = utils::get_meter_value_with_measurands_applied(
_meter_value, utils::get_measurands_vec(this->device_model->get_value<std::string>(
ControllerComponentVariables::SampledDataTxUpdatedMeasurands)));

std::optional<bool> offline;
if (this->websocket_connection_status == WebsocketConnectionStatusEnum::Disconnected) {
offline = true;
}

this->transaction_event_req(TransactionEventEnum::Updated, DateTime(), transaction,
TriggerReasonEnum::MeterValuePeriodic, seq_no, std::nullopt, std::nullopt,
std::nullopt, std::vector<MeterValue>(1, filtered_meter_value), std::nullopt,
std::nullopt, reservation_id);
offline, reservation_id);
};

this->evses.insert(
Expand Down Expand Up @@ -177,11 +183,12 @@ void ChargePoint::on_transaction_started(

auto evse = this->evses.at(evse_id)->get_evse_info();
evse.connectorId.emplace(connector_id);
std::optional<bool> offline;

std::optional<bool> offline;
if (this->websocket_connection_status == WebsocketConnectionStatusEnum::Disconnected) {
offline = true;
}

this->transaction_event_req(TransactionEventEnum::Started, timestamp, transaction, trigger_reason,
enhanced_transaction->get_seq_no(), std::nullopt, evse, enhanced_transaction->id_token,
std::vector<MeterValue>(1, meter_value), std::nullopt, offline, reservation_id);
Expand Down Expand Up @@ -222,8 +229,13 @@ void ChargePoint::on_transaction_finished(const int32_t evse_id, const DateTime&
id_token_opt = _id_token;
}

std::optional<bool> offline;
if (this->websocket_connection_status == WebsocketConnectionStatusEnum::Disconnected) {
offline = true;
}

this->transaction_event_req(TransactionEventEnum::Ended, timestamp, transaction, trigger_reason, seq_no,
std::nullopt, std::nullopt, id_token_opt, meter_values, std::nullopt, std::nullopt,
std::nullopt, std::nullopt, id_token_opt, meter_values, std::nullopt, offline,
std::nullopt);

bool send_reset = false;
Expand Down Expand Up @@ -311,10 +323,16 @@ bool ChargePoint::on_charging_state_changed(const uint32_t evse_id, ChargingStat
this->evses.at(static_cast<int32_t>(evse_id))->get_transaction();
if (transaction != nullptr) {
transaction->chargingState = charging_state;

std::optional<bool> offline;
if (this->websocket_connection_status == WebsocketConnectionStatusEnum::Disconnected) {
offline = true;
}

this->transaction_event_req(TransactionEventEnum::Updated, DateTime(), transaction->get_transaction(),
TriggerReasonEnum::ChargingStateChanged, transaction->get_seq_no(),
std::nullopt, this->evses.at(static_cast<int32_t>(evse_id))->get_evse_info(),
std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt);
std::nullopt, std::nullopt, std::nullopt, offline, std::nullopt);
return true;
} else {
EVLOG_warning << "Can not change charging state: no transaction for evse id " << evse_id;
Expand Down Expand Up @@ -777,11 +795,17 @@ void ChargePoint::update_aligned_data_interval() {
// add meter value to transaction meter values
const auto& enhanced_transaction = evse->get_transaction();
enhanced_transaction->meter_values.push_back(_meter_value);

std::optional<bool> offline;
if (this->websocket_connection_status == WebsocketConnectionStatusEnum::Disconnected) {
offline = true;
}

this->transaction_event_req(
TransactionEventEnum::Updated, DateTime(), enhanced_transaction->get_transaction(),
TriggerReasonEnum::MeterValueClock, enhanced_transaction->get_seq_no(), std::nullopt,
std::nullopt, std::nullopt, std::vector<MeterValue>(1, meter_value), std::nullopt,
std::nullopt, std::nullopt);
offline, std::nullopt);
} else if (!evse->has_active_transaction() and
this->device_model
->get_optional_value<bool>(ControllerComponentVariables::AlignedDataSendDuringIdle)
Expand Down Expand Up @@ -1624,10 +1648,16 @@ void ChargePoint::handle_trigger_message(Call<TriggerMessageRequest> call) {
ControllerComponentVariables::SampledDataTxUpdatedMeasurands);

const auto& enhanced_transaction = evse.get_transaction();

std::optional<bool> offline;
if (this->websocket_connection_status == WebsocketConnectionStatusEnum::Disconnected) {
offline = true;
}

this->transaction_event_req(
TransactionEventEnum::Updated, DateTime(), enhanced_transaction->get_transaction(),
TriggerReasonEnum::Trigger, enhanced_transaction->get_seq_no(), std::nullopt, std::nullopt,
std::nullopt, std::vector<MeterValue>(1, meter_value), std::nullopt, std::nullopt, std::nullopt);
std::nullopt, std::vector<MeterValue>(1, meter_value), std::nullopt, offline, std::nullopt);
};
send_evse_message(send_transaction);
} break;
Expand Down

0 comments on commit 14c22d2

Please sign in to comment.