Skip to content

Commit 3d894d5

Browse files
committed
libiso15118: Add response message interval control
There are EV implementations that can configure request messages within a few milliseconds, which can currently trigger a flood of internal communication. To avoid performance issues, we should therefore wait a certain amount of time after receiving a request message before sending the next response message. The delay of maximum 100 ms should not cause any problems, as the most critical time of the ISO 15118-20 (V2G_SECC_Msg_Performance_Time of the charging loop) is 250 ms. Changes: - introduce MIN_RESPONSE_INTERVAL_MS to manage time between responses - add last_response_tx_time to track last response timestamp - implement delay to ensure minimum interval between response messages Signed-off-by: Fabian Hartung <fabian.hartung@chargebyte.com>
1 parent d8b8a69 commit 3d894d5

File tree

2 files changed

+16
-0
lines changed
  • lib/everest/iso15118

2 files changed

+16
-0
lines changed

lib/everest/iso15118/include/iso15118/session/iso.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class Session {
7272

7373
d20::Timeouts timeouts;
7474

75+
std::optional<TimePoint> last_response_tx_time; // timestamp of the last response message sent
76+
7577
void handle_connection_event(io::ConnectionEvent event);
7678
};
7779

lib/everest/iso15118/src/iso15118/session/iso.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
namespace iso15118 {
1717

1818
static constexpr auto SESSION_IDLE_TIMEOUT_MS = 5000;
19+
static constexpr auto MIN_RESPONSE_INTERVAL_MS = 100; // minimum time between two response messages
1920

2021
static void log_sdp_packet(const iso15118::io::SdpPacket& sdp) {
2122
static constexpr auto ESCAPED_BYTE_CHAR_COUNT = 4;
@@ -226,8 +227,21 @@ TimePoint const& Session::poll() {
226227
const auto [got_response, payload_size, payload_type, response_type] = message_exchange.check_and_clear_response();
227228

228229
if (got_response) {
230+
// Before we send back the response message, we check the time between two response messages
231+
// sent out. If this is less than MIN_RESPONSE_INTERVAL_MS, we delay the response message to
232+
// avoid potential performance issues.
233+
if (last_response_tx_time.has_value()) {
234+
const auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(get_current_time_point() -
235+
last_response_tx_time.value());
236+
const auto min_delay = std::chrono::milliseconds(MIN_RESPONSE_INTERVAL_MS);
237+
if (elapsed < min_delay) {
238+
std::this_thread::sleep_for(min_delay - elapsed);
239+
}
240+
}
241+
229242
const auto response_size = setup_response_header(response_buffer, payload_type, payload_size);
230243
connection->write(response_buffer, response_size);
244+
last_response_tx_time = get_current_time_point();
231245

232246
timeouts.start_timeout(d20::TimeoutType::SEQUENCE, d20::TIMEOUT_SEQUENCE);
233247

0 commit comments

Comments
 (0)