Skip to content

Commit

Permalink
Fix wrong call type used and use monotonic timer so time of flight ne…
Browse files Browse the repository at this point in the history
…ver becomes negative

Signed-off-by: Marc Emmers <[email protected]>
  • Loading branch information
marcemmers committed Oct 9, 2023
1 parent d542385 commit 9d53fb5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions include/ocpp/v201/charge_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class ChargePoint : ocpp::ChargingStationBase {
Everest::SteadyTimer aligned_meter_values_timer;

// time keeping
ocpp::DateTime heartbeat_request_time;
std::chrono::time_point<std::chrono::steady_clock> heartbeat_request_time;

// states
RegistrationStatusEnum registration_status;
Expand Down Expand Up @@ -305,7 +305,7 @@ class ChargePoint : ocpp::ChargingStationBase {

// Functional Block G: Availability
void handle_change_availability_req(Call<ChangeAvailabilityRequest> call);
void handle_heartbeat_response(Call<HeartbeatResponse> call);
void handle_heartbeat_response(CallResult<HeartbeatResponse> call);

// Functional Block L: Firmware management
void handle_firmware_update_req(Call<UpdateFirmwareRequest> call);
Expand Down
6 changes: 3 additions & 3 deletions lib/ocpp/v201/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ void ChargePoint::status_notification_req(const int32_t evse_id, const int32_t c
void ChargePoint::heartbeat_req() {
HeartbeatRequest req;

heartbeat_request_time = ocpp::DateTime();
heartbeat_request_time = std::chrono::steady_clock::now();
ocpp::Call<HeartbeatRequest> call(req, this->message_queue->createMessageId());
this->send<HeartbeatRequest>(call);
}
Expand Down Expand Up @@ -1933,11 +1933,11 @@ void ChargePoint::handle_change_availability_req(Call<ChangeAvailabilityRequest>
}
}

void ChargePoint::handle_heartbeat_response(Call<HeartbeatResponse> call) {
void ChargePoint::handle_heartbeat_response(CallResult<HeartbeatResponse> call) {
if (this->callbacks.time_sync_callback.has_value()) {
// the received currentTime was the time the CSMS received the heartbeat request
// to get a system time as accurate as possible keep the time-of-flight into account
auto timeOfFlight = (DateTime().to_time_point() - this->heartbeat_request_time.to_time_point()) / 2;
auto timeOfFlight = (std::chrono::steady_clock::now() - this->heartbeat_request_time) / 2;
ocpp::DateTime currentTimeCompensated(call.msg.currentTime.to_time_point() + timeOfFlight);
this->callbacks.time_sync_callback.value()(currentTimeCompensated);
}
Expand Down

0 comments on commit 9d53fb5

Please sign in to comment.