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

Integrate of send Triggermessage (MeterValues) in empty Connector case of present connectors or reject if non is present #898

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
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
54 changes: 47 additions & 7 deletions lib/ocpp/v16/charge_point_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2423,6 +2423,29 @@ void ChargePointImpl::handleTriggerMessageRequest(ocpp::Call<TriggerMessageReque
valid = false;
}

// We have to reject if there is no metervalue
if (MessageTrigger::MeterValues == call.msg.requestedMessage && valid) {
// the case if connectorId has value
std::vector<bool> thereIsMeterValueForRequest;
if (call.msg.connectorId.has_value()) {
if (this->connectors.find(connector) != this->connectors.end() &&
this->connectors.at(connector)->measurement.has_value()) {
thereIsMeterValueForRequest.push_back(connector);
}
} else {
for (int32_t c = 0; c <= this->configuration->getNumberOfConnectors(); c++) {
if (this->connectors.find(c) != this->connectors.end() &&
this->connectors.at(c)->measurement.has_value()) {
thereIsMeterValueForRequest.push_back(c);
}
}
}
if (thereIsMeterValueForRequest.size() == 0) {
response.status = TriggerMessageStatus::Rejected;
valid = false;
}
}

ocpp::CallResult<TriggerMessageResponse> call_result(response, call.uniqueId);
this->message_dispatcher->dispatch_call_result(call_result);

Expand All @@ -2444,13 +2467,30 @@ void ChargePointImpl::handleTriggerMessageRequest(ocpp::Call<TriggerMessageReque
this->heartbeat(true);
break;
case MessageTrigger::MeterValues: {
const auto meter_value = this->get_latest_meter_value(
connector, this->configuration->getMeterValuesSampledDataVector(), ReadingContext::Trigger);
if (meter_value.has_value()) {
this->send_meter_value(connector, meter_value.value(), true);
} else {
EVLOG_warning << "Could not send triggered meter value for uninitialized measurement at connector#"
<< connector;
for (int32_t c = 0; c <= this->configuration->getNumberOfConnectors(); c++) {
bool doExecute = false;
bool doBreak = false;
if (call.msg.connectorId.has_value()) {
if (call.msg.connectorId.value() == c) {
doBreak = true;
doExecute = true;
}
} else {
doExecute = true;
doBreak = false;
}
if (doExecute) {
const auto meter_value = this->get_latest_meter_value(
c, this->configuration->getMeterValuesSampledDataVector(), ReadingContext::Trigger);
if (meter_value.has_value()) {
this->send_meter_value(c, meter_value.value(), true);
} else {
EVLOG_warning << "Could not send triggered meter value for uninitialized measurement at connector#"
<< c;
}
}
if (doBreak)
break;
}
break;
}
Expand Down
Loading