Skip to content

Commit a26227a

Browse files
authored
UnlockConnector refactoring (#1006)
Refactored unlock_connector_callback for OCPP1.6: * Callback must now return UnlockStatus instead of bool, because bool could not transmit enough information * Within the UnlockConnector handler, stop_transaction_callback . This callback shall be responsible for this --------- Signed-off-by: Piet Gömpel <pietgoempel@gmail.com>
1 parent 055caef commit a26227a

File tree

6 files changed

+15
-22
lines changed

6 files changed

+15
-22
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.14)
22

33
project(ocpp
4-
VERSION 0.24.0
4+
VERSION 0.24.1
55
DESCRIPTION "A C++ implementation of the Open Charge Point Protocol"
66
LANGUAGES CXX
77
)

include/ocpp/v16/charge_point.hpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -428,13 +428,14 @@ class ChargePoint {
428428
/// \param callback
429429
void register_cancel_reservation_callback(const std::function<bool(int32_t reservation_id)>& callback);
430430

431-
/// \brief registers a \p callback function that can be used to unlock the connector. The unlock_connector_callback
432-
/// is called:
431+
/// \brief registers a \p callback function that can be used to unlock the connector. In case a transaction is
432+
// active at the specified connector, the \p callback shall stop the transaction before unlocking the connector. The
433+
// unlock_connector_callback is called:
433434
/// - when receiving a UnlockConnector.req and
434435
/// - when a transaction has on_transaction_stopped is called and the configuration key
435436
/// UnlockConnectorOnEVSideDisconnect is true
436437
/// \param callback
437-
void register_unlock_connector_callback(const std::function<bool(int32_t connector)>& callback);
438+
void register_unlock_connector_callback(const std::function<UnlockStatus(int32_t connector)>& callback);
438439

439440
/// \brief registers a \p callback function that can be used to trigger an upload of diagnostics. This callback
440441
/// should trigger a process of a diagnostics upload using the given parameters of the request. This process should

include/ocpp/v16/charge_point_impl.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class ChargePointImpl : ocpp::ChargingStationBase {
156156
std::function<void(const std::string& id_token, std::vector<int32_t> referenced_connectors, bool prevalidated)>
157157
provide_token_callback;
158158
std::function<bool(int32_t connector, Reason reason)> stop_transaction_callback;
159-
std::function<bool(int32_t connector)> unlock_connector_callback;
159+
std::function<UnlockStatus(int32_t connector)> unlock_connector_callback;
160160
std::function<bool(int32_t connector, int32_t max_current)> set_max_current_callback;
161161
std::function<bool(const ResetType& reset_type)> is_reset_allowed_callback;
162162
std::function<void(const ResetType& reset_type)> reset_callback;
@@ -732,13 +732,14 @@ class ChargePointImpl : ocpp::ChargingStationBase {
732732
/// \param callback
733733
void register_cancel_reservation_callback(const std::function<bool(int32_t reservation_id)>& callback);
734734

735-
/// \brief registers a \p callback function that can be used to unlock the connector. The unlock_connector_callback
736-
/// is called:
735+
/// \brief registers a \p callback function that can be used to unlock the connector. In case a transaction is
736+
// active at the specified connector, the \p callback shall stop the transaction before unlocking the connector. The
737+
// unlock_connector_callback is called:
737738
/// - when receiving a UnlockConnector.req and
738739
/// - when a transaction has on_transaction_stopped is called and the configuration key
739740
/// UnlockConnectorOnEVSideDisconnect is true
740741
/// \param callback
741-
void register_unlock_connector_callback(const std::function<bool(int32_t connector)>& callback);
742+
void register_unlock_connector_callback(const std::function<UnlockStatus(int32_t connector)>& callback);
742743

743744
/// \brief registers a \p callback function that can be used to trigger an upload of diagnostics. This callback
744745
/// should trigger a process of a diagnostics upload using the given parameters of the request. This process should

lib/ocpp/v16/charge_point.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ void ChargePoint::register_cancel_reservation_callback(const std::function<bool(
230230
this->charge_point->register_cancel_reservation_callback(callback);
231231
}
232232

233-
void ChargePoint::register_unlock_connector_callback(const std::function<bool(int32_t connector)>& callback) {
233+
void ChargePoint::register_unlock_connector_callback(const std::function<UnlockStatus(int32_t connector)>& callback) {
234234
this->charge_point->register_unlock_connector_callback(callback);
235235
}
236236

lib/ocpp/v16/charge_point_impl.cpp

+3-12
Original file line numberDiff line numberDiff line change
@@ -2306,19 +2306,9 @@ void ChargePointImpl::handleUnlockConnectorRequest(ocpp::Call<UnlockConnectorReq
23062306
if (connector <= 0 or connector > this->configuration->getNumberOfConnectors()) {
23072307
response.status = UnlockStatus::NotSupported;
23082308
} else {
2309-
// this message is not intended to remotely stop a transaction, but if a transaction is still ongoing it is
2310-
// advised to stop it first
2311-
if (this->transaction_handler->transaction_active(connector)) {
2312-
EVLOG_info << "Received unlock connector request with active session for this connector.";
2313-
this->stop_transaction_callback(connector, Reason::UnlockCommand);
2314-
}
23152309

23162310
if (this->unlock_connector_callback != nullptr) {
2317-
if (this->unlock_connector_callback(call.msg.connectorId)) {
2318-
response.status = UnlockStatus::Unlocked;
2319-
} else {
2320-
response.status = UnlockStatus::UnlockFailed;
2321-
}
2311+
response.status = this->unlock_connector_callback(call.msg.connectorId);
23222312
} else {
23232313
response.status = UnlockStatus::NotSupported;
23242314
}
@@ -4495,7 +4485,8 @@ void ChargePointImpl::register_cancel_reservation_callback(const std::function<b
44954485
this->cancel_reservation_callback = callback;
44964486
}
44974487

4498-
void ChargePointImpl::register_unlock_connector_callback(const std::function<bool(int32_t connector)>& callback) {
4488+
void ChargePointImpl::register_unlock_connector_callback(
4489+
const std::function<UnlockStatus(int32_t connector)>& callback) {
44994490
this->unlock_connector_callback = callback;
45004491
}
45014492

src/charge_point.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ int main(int argc, char* argv[]) {
195195
charge_point->register_unlock_connector_callback([](int32_t connector) {
196196
std::cout << "Callback: "
197197
<< "Unlock connector#" << connector;
198-
return true;
198+
return ocpp::v16::UnlockStatus::Unlocked;
199199
});
200200

201201
charge_point->register_upload_diagnostics_callback([](const ocpp::v16::GetDiagnosticsRequest& request) {

0 commit comments

Comments
 (0)