Skip to content

Commit

Permalink
Remove some more old code, move enum to types.hpp
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Emmers <[email protected]>
  • Loading branch information
marcemmers committed Oct 10, 2023
1 parent a7a7d32 commit 28d9e1e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
8 changes: 1 addition & 7 deletions include/ocpp/v201/charge_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,8 @@ struct Callbacks {
configure_network_connection_profile_callback;
std::optional<std::function<void(const ocpp::DateTime& currentTime)>> time_sync_callback;


enum class OcppMessageDirection {
CSMSToChargingStation,
ChargingStationToCSMS
};
/// @brief callback to be called to congigure ocpp message logging
std::optional<std::function<void(const std::string& message, OcppMessageDirection direction)>> ocpp_messages_callback;
std::optional<std::function<void(const std::string& message, MessageDirection direction)>> ocpp_messages_callback;
};

/// \brief Class implements OCPP2.0.1 Charging Station
Expand Down Expand Up @@ -178,7 +173,6 @@ class ChargePoint : ocpp::ChargingStationBase {
template <class T> bool send(CallResult<T> call_result);
bool send(CallError call_error);
bool send(json message);
std::function<void(const std::string& message)> ocpp_message_callback;

// internal helper functions
void init_websocket();
Expand Down
5 changes: 5 additions & 0 deletions include/ocpp/v201/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ WebsocketConnectionStatusEnum string_to_websocket_connection_status(const std::s
/// \returns an output stream with the WebsocketConnectionStatusEnum written to
std::ostream& operator<<(std::ostream& os, const WebsocketConnectionStatusEnum& websocket_connection_status);

enum class MessageDirection {
CSMSToChargingStation,
ChargingStationToCSMS
};

} // namespace v201
} // namespace ocpp

Expand Down
5 changes: 0 additions & 5 deletions lib/ocpp/common/websocket/websocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ void Websocket::register_message_callback(const std::function<void(const std::st
this->websocket->register_message_callback([this](const std::string& message) { this->message_callback(message); });
}

void Websocket::register_ocpp_message_callback(const std::function<void(const std::string& message)>& callback){
this->ocpp_message_callback = callback;
// this->websocket->register_ocpp_message_callback([this](const std::string& message) { this->ocpp_message_callback(message); });
}

bool Websocket::send(const std::string& message) {
this->logging->charge_point("Unknown", message);
return this->websocket->send(message);
Expand Down
9 changes: 4 additions & 5 deletions lib/ocpp/v201/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,18 +449,17 @@ template <class T> std::future<EnhancedMessage<v201::MessageType>> ChargePoint::
}

template <class T> bool ChargePoint::send(ocpp::CallResult<T> call_result) {
return send(json(call_result));
return this->send(json(call_result));
}

bool ChargePoint::send(CallError call_error) {
return send(json(call_error));
return this->send(json(call_error));
}

bool ChargePoint::send(json message) {
const auto stringified = json(message).dump();
if (this->callbacks.ocpp_messages_callback.has_value()) {
this->callbacks.ocpp_messages_callback.value()(stringified,
Callbacks::OcppMessageDirection::ChargingStationToCSMS);
this->callbacks.ocpp_messages_callback.value()(stringified, MessageDirection::ChargingStationToCSMS);
}
return this->websocket->send(stringified);
}
Expand Down Expand Up @@ -709,7 +708,7 @@ void ChargePoint::message_callback(const std::string& message) {
auto json_message = enhanced_message.message;
this->logging->central_system(conversions::messagetype_to_string(enhanced_message.messageType), message);
if (this->callbacks.ocpp_messages_callback.has_value()) {
this->callbacks.ocpp_messages_callback.value()(message, Callbacks::OcppMessageDirection::CSMSToChargingStation);
this->callbacks.ocpp_messages_callback.value()(message, MessageDirection::CSMSToChargingStation);
}

try {
Expand Down

0 comments on commit 28d9e1e

Please sign in to comment.