-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/data transfer functional block (#871)
* Added message handler interface to be implemented by specific functional blocks * Moved DataTransfer functionality to DataTransfer functional block using the targeted design. Added test cases for the new functional block --------- Signed-off-by: Piet Gömpel <[email protected]>
- Loading branch information
Showing
10 changed files
with
527 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Pionix GmbH and Contributors to EVerest | ||
|
||
#pragma once | ||
|
||
#include <ocpp/v201/message_dispatcher.hpp> | ||
#include <ocpp/v201/message_handler.hpp> | ||
#include <ocpp/v201/messages/DataTransfer.hpp> | ||
|
||
namespace ocpp { | ||
namespace v201 { | ||
|
||
class DataTransferInterface : public MessageHandlerInterface { | ||
|
||
public: | ||
virtual ~DataTransferInterface(){}; | ||
|
||
/// \brief Sends a DataTransfer.req message to the CSMS using the given parameters | ||
/// \param vendorId | ||
/// \param messageId | ||
/// \param data | ||
/// \return DataTransferResponse containing the result from CSMS | ||
virtual std::optional<DataTransferResponse> data_transfer_req(const CiString<255>& vendorId, | ||
const std::optional<CiString<50>>& messageId, | ||
const std::optional<json>& data) = 0; | ||
|
||
/// \brief Sends a DataTransfer.req message to the CSMS using the given \p request | ||
/// \param request message shall be sent to the CSMS | ||
/// \return DataTransferResponse containing the result from CSMS. In case no response is received from the CSMS | ||
/// because the message timed out or the charging station is offline, std::nullopt is returned | ||
virtual std::optional<DataTransferResponse> data_transfer_req(const DataTransferRequest& request) = 0; | ||
}; | ||
|
||
class DataTransfer : public DataTransferInterface { | ||
|
||
private: | ||
MessageDispatcherInterface<MessageType>& message_dispatcher; | ||
std::optional<std::function<DataTransferResponse(const DataTransferRequest& request)>> data_transfer_callback; | ||
std::chrono::seconds response_timeout; | ||
|
||
public: | ||
DataTransfer(MessageDispatcherInterface<MessageType>& message_dispatcher, | ||
const std::optional<std::function<DataTransferResponse(const DataTransferRequest& request)>>& | ||
data_transfer_callback, | ||
const std::chrono::seconds response_timeout) : | ||
message_dispatcher(message_dispatcher), | ||
data_transfer_callback(data_transfer_callback), | ||
response_timeout(response_timeout){}; | ||
|
||
void handle_message(const EnhancedMessage<MessageType>& message) override; | ||
|
||
std::optional<DataTransferResponse> data_transfer_req(const CiString<255>& vendorId, | ||
const std::optional<CiString<50>>& messageId, | ||
const std::optional<json>& data) override; | ||
|
||
std::optional<DataTransferResponse> data_transfer_req(const DataTransferRequest& request) override; | ||
}; | ||
|
||
} // namespace v201 | ||
} // namespace ocpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Pionix GmbH and Contributors to EVerest | ||
|
||
#pragma once | ||
|
||
#include <ocpp/common/message_queue.hpp> | ||
|
||
namespace ocpp { | ||
namespace v201 { | ||
|
||
/// \brief Interface for handling OCPP2.0.1 CALL messages from the CSMS. Classes implementing a functional block shall | ||
/// extend this interface. | ||
class MessageHandlerInterface { | ||
|
||
public: | ||
virtual ~MessageHandlerInterface() { | ||
} | ||
/// \brief Handles the given \p message from the CSMS. This includes dispatching a CALLRESULT as a response to the | ||
/// incoming \p message . | ||
/// @param message | ||
virtual void handle_message(const EnhancedMessage<MessageType>& message) = 0; | ||
}; | ||
|
||
class MessageTypeNotImplementedException : public std::exception { | ||
private: | ||
std::string message; | ||
|
||
public: | ||
MessageTypeNotImplementedException(MessageType message_type) : | ||
message("Message is not implemented: " + conversions::messagetype_to_string(message_type)) { | ||
} | ||
|
||
const char* what() const noexcept override { | ||
return message.c_str(); | ||
} | ||
}; | ||
|
||
} // namespace v201 | ||
} // namespace ocpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.