Skip to content

Commit

Permalink
Adressed requested changes
Browse files Browse the repository at this point in the history
Signed-off-by: Piet Gömpel <[email protected]>
  • Loading branch information
Pietfried committed Nov 14, 2024
1 parent 3a07d82 commit ffc407d
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 91 deletions.
51 changes: 51 additions & 0 deletions doc/message_dispatching.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Message Dispatching Class Diagram

Check notice on line 1 in doc/message_dispatching.md

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

doc/message_dispatching.md#L1

Expected: [None]; Actual: # Message Dispatching Class Diagram

```mermaid
classDiagram
class MessageDispatcherInterface {
+dispatch_call(const json& call, bool triggered = false)
+dispatch_call_async(const json& call, bool triggered = false): std::future~EnhancedMessage~T~~
+dispatch_call_result(const json& call_result)
+dispatch_call_error(const json& call_error)
}
class v16_MessageDispatcher {
- MessageQueue& message_queue
- ChargePointConfiguration& configuration
- RegistrationStatus& registration_status
}
class v201_MessageDispatcher {
- MessageQueue& message_queue
- DeviceModel& device_model
- ConnectivityManager& connectivity_manager
- RegistrationStatusEnum& registration_status
}
class v201_DataTransferInterface {
+data_transfer_req(request: DataTransferRequest): std::optional~DataTransferResponse~
+handle_data_transfer_req(call: Call~DataTransferRequest~)
}
class v201_DataTransfer {
-MessageDispatcherInterface &message_dispatcher
-std::optional~function~ data_transfer_callback
}
class v201_ChargePoint {
std::unique_ptr~MessageDispatcherInterface~ message_dispatcher
std::unique_ptr~v201_DataTransferInterface~ data_transfer
}
class v16_ChargePoint {
std::unique_ptr~MessageDispatcherInterface~ message_dispatcher
}
MessageDispatcherInterface <|-- v16_MessageDispatcher
MessageDispatcherInterface <|-- v201_MessageDispatcher
v201_DataTransferInterface <|-- v201_DataTransfer
MessageDispatcherInterface *-- v201_DataTransfer
MessageDispatcherInterface *-- v201_ChargePoint
v201_DataTransferInterface *-- v201_ChargePoint
MessageDispatcherInterface *-- v16_ChargePoint
```
Binary file removed doc/message_dispatching.png
Binary file not shown.
51 changes: 0 additions & 51 deletions doc/message_dispatching.puml

This file was deleted.

76 changes: 36 additions & 40 deletions lib/ocpp/v201/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,7 @@ ChargePoint::ChargePoint(const std::map<int32_t, int32_t>& evse_connector_struct
EVLOG_AND_THROW(std::invalid_argument("Database handler should not be null"));
}

if (!this->message_queue) {
EVLOG_AND_THROW(std::invalid_argument("Message Queue should not be null"));
}

initialize(evse_connector_structure, message_log_path);

this->message_dispatcher =
std::make_unique<MessageDispatcher>(*this->message_queue, *this->device_model, registration_status);
}

ChargePoint::ChargePoint(const std::map<int32_t, int32_t>& evse_connector_structure,
Expand All @@ -95,39 +88,6 @@ ChargePoint::ChargePoint(const std::map<int32_t, int32_t>& evse_connector_struct
std::make_shared<DatabaseHandler>(
std::make_unique<common::DatabaseConnection>(fs::path(core_database_path) / "cp.db"), sql_init_path),
nullptr /* message_queue initialized in this constructor */, message_log_path, evse_security, callbacks) {
std::set<v201::MessageType> message_types_discard_for_queueing;
try {
const auto message_types_discard_for_queueing_csl = ocpp::split_string(
this->device_model
->get_optional_value<std::string>(ControllerComponentVariables::MessageTypesDiscardForQueueing)
.value_or(""),
',');
std::transform(message_types_discard_for_queueing_csl.begin(), message_types_discard_for_queueing_csl.end(),
std::inserter(message_types_discard_for_queueing, message_types_discard_for_queueing.end()),
[](const std::string element) { return conversions::string_to_messagetype(element); });
} catch (const StringToEnumException& e) {
EVLOG_warning << "Could not convert configured MessageType value of MessageTypesDiscardForQueueing. Please "
"check you configuration: "
<< e.what();
} catch (...) {
EVLOG_warning << "Could not apply MessageTypesDiscardForQueueing configuration";
}

this->message_queue = std::make_unique<ocpp::MessageQueue<v201::MessageType>>(
[this](json message) -> bool { return this->connectivity_manager->send_to_websocket(message.dump()); },
MessageQueueConfig<v201::MessageType>{
this->device_model->get_value<int>(ControllerComponentVariables::MessageAttempts),
this->device_model->get_value<int>(ControllerComponentVariables::MessageAttemptInterval),
this->device_model->get_optional_value<int>(ControllerComponentVariables::MessageQueueSizeThreshold)
.value_or(DEFAULT_MESSAGE_QUEUE_SIZE_THRESHOLD),
this->device_model->get_optional_value<bool>(ControllerComponentVariables::QueueAllMessages)
.value_or(false),
message_types_discard_for_queueing,
this->device_model->get_value<int>(ControllerComponentVariables::MessageTimeout)},
this->database_handler);

this->message_dispatcher =
std::make_unique<MessageDispatcher>(*this->message_queue, *this->device_model, registration_status);
}

ChargePoint::ChargePoint(const std::map<int32_t, int32_t>& evse_connector_structure,
Expand Down Expand Up @@ -1176,6 +1136,42 @@ void ChargePoint::initialize(const std::map<int32_t, int32_t>& evse_connector_st
this->connectivity_manager->set_websocket_connection_failed_callback(
std::bind(&ChargePoint::websocket_connection_failed, this, std::placeholders::_1));

if (this->message_queue == nullptr) {
std::set<v201::MessageType> message_types_discard_for_queueing;
try {
const auto message_types_discard_for_queueing_csl = ocpp::split_string(
this->device_model
->get_optional_value<std::string>(ControllerComponentVariables::MessageTypesDiscardForQueueing)
.value_or(""),
',');
std::transform(message_types_discard_for_queueing_csl.begin(), message_types_discard_for_queueing_csl.end(),
std::inserter(message_types_discard_for_queueing, message_types_discard_for_queueing.end()),
[](const std::string element) { return conversions::string_to_messagetype(element); });
} catch (const StringToEnumException& e) {
EVLOG_warning << "Could not convert configured MessageType value of MessageTypesDiscardForQueueing. Please "
"check you configuration: "
<< e.what();
} catch (...) {
EVLOG_warning << "Could not apply MessageTypesDiscardForQueueing configuration";
}

this->message_queue = std::make_unique<ocpp::MessageQueue<v201::MessageType>>(
[this](json message) -> bool { return this->connectivity_manager->send_to_websocket(message.dump()); },
MessageQueueConfig<v201::MessageType>{
this->device_model->get_value<int>(ControllerComponentVariables::MessageAttempts),
this->device_model->get_value<int>(ControllerComponentVariables::MessageAttemptInterval),
this->device_model->get_optional_value<int>(ControllerComponentVariables::MessageQueueSizeThreshold)
.value_or(DEFAULT_MESSAGE_QUEUE_SIZE_THRESHOLD),
this->device_model->get_optional_value<bool>(ControllerComponentVariables::QueueAllMessages)
.value_or(false),
message_types_discard_for_queueing,
this->device_model->get_value<int>(ControllerComponentVariables::MessageTimeout)},
this->database_handler);
}

this->message_dispatcher =
std::make_unique<MessageDispatcher>(*this->message_queue, *this->device_model, registration_status);

if (this->callbacks.configure_network_connection_profile_callback.has_value()) {
this->connectivity_manager->set_configure_network_connection_profile_callback(
this->callbacks.configure_network_connection_profile_callback.value());
Expand Down

0 comments on commit ffc407d

Please sign in to comment.