Skip to content

Commit 70d574e

Browse files
committed
[wip] Add definition for on_try_switch_network_profile
Signed-off-by: Soumya Subramanya <s.subramanya@alfen.com>
1 parent a5d1c79 commit 70d574e

File tree

2 files changed

+50
-16
lines changed

2 files changed

+50
-16
lines changed

include/ocpp/v201/charge_point.hpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,10 @@ class ChargePoint : ocpp::ChargingStationBase {
268268
bool send(CallError call_error);
269269

270270
// internal helper functions
271-
void init_websocket();
271+
272+
/// @brief Initialize the websocket connection.
273+
/// @param configuration_slot Optional configuration slot to initialize the websocket to.
274+
void init_websocket(std::optional<std::string> config_slot = std::nullopt);
272275
WebsocketConnectionOptions get_ws_connection_options(const int32_t configuration_slot);
273276
void init_certificate_expiration_check_timers();
274277
void scheduled_check_client_certificate_expiration();
@@ -573,8 +576,9 @@ class ChargePoint : ocpp::ChargingStationBase {
573576
/// \brief Stops the ChargePoint. Disconnects the websocket connection and stops MessageQueue and all timers
574577
void stop();
575578

576-
/// \brief Initializes the websocket and connects to CSMS if it is not yet connected
577-
void connect_websocket();
579+
/// @brief Initializes the websocket and connects to CSMS if it is not yet connected.
580+
/// @param configuration_slot Optional configuration slot to connect to
581+
void connect_websocket(std::optional<std::string> config_slot = std::nullopt);
578582

579583
/// \brief Disconnects the the websocket connection to the CSMS if it is connected
580584
/// \param code Optional websocket close status code (default: normal).
@@ -736,6 +740,10 @@ class ChargePoint : ocpp::ChargingStationBase {
736740
return this->device_model->request_value<T>(component_id, variable_id, attribute_enum);
737741
}
738742

743+
/// @brief Switch to a specifc network connection profile given the configuration slot.
744+
/// This disregards the prority
745+
/// @param configuration_slot Slot in which the configuration is stored
746+
/// @return true if the switch is possible.
739747
bool on_try_switch_network_connection_profile(const std::string configuration_slot);
740748
};
741749

lib/ocpp/v201/charge_point.cpp

+39-13
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,10 @@ void ChargePoint::stop() {
200200
this->message_queue->stop();
201201
}
202202

203-
void ChargePoint::connect_websocket() {
203+
void ChargePoint::connect_websocket(std::optional<std::string> config_slot) {
204204
if (!this->websocket->is_connected()) {
205205
this->disable_automatic_websocket_reconnects = false;
206-
this->init_websocket();
206+
this->init_websocket(config_slot);
207207
this->websocket->connect();
208208
}
209209
}
@@ -647,19 +647,23 @@ bool ChargePoint::send(CallError call_error) {
647647
return true;
648648
}
649649

650-
void ChargePoint::init_websocket() {
650+
void ChargePoint::init_websocket(std::optional<std::string> config_slot) {
651+
652+
std::string configuration_slot;
651653
if (this->device_model->get_value<std::string>(ControllerComponentVariables::ChargePointId).find(':') !=
652654
std::string::npos) {
653655
EVLOG_AND_THROW(std::runtime_error("ChargePointId must not contain \':\'"));
654656
}
655657

656-
const auto configuration_slot =
657-
ocpp::get_vector_from_csv(
658-
this->device_model->get_value<std::string>(ControllerComponentVariables::NetworkConfigurationPriority))
659-
.at(this->network_configuration_priority);
660-
661-
EVLOG_info << "congfig -------> : " << configuration_slot.size();
662-
658+
if (config_slot.has_value()) {
659+
EVLOG_info << " using configuration slot --->" << config_slot.value();
660+
configuration_slot = config_slot.value();
661+
} else {
662+
configuration_slot = ocpp::get_vector_from_csv(this->device_model->get_value<std::string>(
663+
ControllerComponentVariables::NetworkConfigurationPriority))
664+
.at(this->network_configuration_priority);
665+
}
666+
EVLOG_info << "config -------> : " << configuration_slot.size();
663667
const auto connection_options = this->get_ws_connection_options(std::stoi(configuration_slot));
664668
const auto network_connection_profile = this->get_network_connection_profile(std::stoi(configuration_slot));
665669

@@ -674,7 +678,7 @@ void ChargePoint::init_websocket() {
674678
switch (status = config_status.wait_for(std::chrono::seconds(config_timeout.value())); status) {
675679
case std::future_status::deferred:
676680
case std::future_status::timeout:
677-
EVLOG_info << "timeout or deferred";
681+
EVLOG_info << "========timeout or deferred========";
678682
EVLOG_warning
679683
<< "NetworkConnectionProfile could not be retrieved or configuration of network with the given "
680684
"profile failed";
@@ -757,7 +761,7 @@ void ChargePoint::init_websocket() {
757761
}
758762
// call the disconnected callback if it exists
759763
if (this->callbacks.websocket_disconnected_callback.has_value()) {
760-
this->callbacks.websocket_disconnected_callback.value();
764+
this->callbacks.websocket_disconnected_callback.value()();
761765
}
762766
this->client_certificate_expiration_check_timer.stop();
763767
this->v2g_certificate_expiration_check_timer.stop();
@@ -774,7 +778,9 @@ void ChargePoint::init_websocket() {
774778
[this, reason]() {
775779
if (reason != websocketpp::close::status::service_restart) {
776780
this->next_network_configuration_priority();
781+
EVLOG_info << "next network config ---->";
777782
}
783+
EVLOG_info << "start websocket after close---->";
778784
this->start_websocket();
779785
},
780786
WEBSOCKET_INIT_DELAY);
@@ -3016,7 +3022,27 @@ void ChargePoint::set_connector_operative_status(int32_t evse_id, int32_t connec
30163022

30173023
bool ChargePoint::on_try_switch_network_connection_profile(const std::string configuration_slot) {
30183024
EVLOG_info << "=============on_try_switch_network_profile============" << configuration_slot;
3019-
return false;
3025+
3026+
// check if the configuration slot is valid
3027+
try
3028+
{
3029+
//call disconnect
3030+
this->disconnect_websocket(); //normal close
3031+
while (!this->is_offline())
3032+
{
3033+
/* code */
3034+
}
3035+
3036+
//call connect with the config_slot option
3037+
this->connect_websocket(configuration_slot);
3038+
return true;
3039+
3040+
}
3041+
catch(std::exception &e)
3042+
{
3043+
EVLOG_info << "ERROR===============>";
3044+
return false;
3045+
}
30203046
}
30213047
bool ChargePoint::are_all_connectors_effectively_inoperative() {
30223048
// Check that all connectors on all EVSEs are inoperative

0 commit comments

Comments
 (0)