From fa3f464ad08d681d362212db2ef549fd4614f770 Mon Sep 17 00:00:00 2001 From: James Chapman Date: Thu, 14 Mar 2024 15:28:09 +0000 Subject: [PATCH] fix: addressed PR comments on use of snake_case fix: moved conversions to separate file Signed-off-by: James Chapman --- modules/OCPP/OCPP.cpp | 32 +------------------------------- modules/OCPP/conversions.cpp | 29 +++++++++++++++++++++++++++++ modules/OCPP/conversions.hpp | 7 +++++++ types/ocpp.yaml | 22 +++++++++++----------- 4 files changed, 48 insertions(+), 42 deletions(-) diff --git a/modules/OCPP/OCPP.cpp b/modules/OCPP/OCPP.cpp index 6e39c7f60..677778ffb 100644 --- a/modules/OCPP/OCPP.cpp +++ b/modules/OCPP/OCPP.cpp @@ -142,42 +142,12 @@ void OCPP::set_external_limits(const std::map& charging_schedules) { // publish the schedule over mqtt types::ocpp::ChargingSchedules schedules; for (const auto& charging_schedule : charging_schedules) { - types::ocpp::ChargingSchedule sch = to_ChargingSchedule(charging_schedule.second); + types::ocpp::ChargingSchedule sch = conversions::to_charging_schedule(charging_schedule.second); sch.connector = charging_schedule.first; schedules.schedules.emplace_back(std::move(sch)); } diff --git a/modules/OCPP/conversions.cpp b/modules/OCPP/conversions.cpp index 746fcbba5..a923998c3 100644 --- a/modules/OCPP/conversions.cpp +++ b/modules/OCPP/conversions.cpp @@ -359,5 +359,34 @@ to_everest_authorization_status(const ocpp::v201::AuthorizationStatusEnum status } } +types::ocpp::ChargingSchedulePeriod +to_charging_schedule_period(const ocpp::v16::EnhancedChargingSchedulePeriod& period) { + types::ocpp::ChargingSchedulePeriod csp = { + period.startPeriod, + period.limit, + period.stackLevel, + period.numberPhases, + }; + return csp; +} + +types::ocpp::ChargingSchedule to_charging_schedule(const ocpp::v16::EnhancedChargingSchedule& schedule) { + types::ocpp::ChargingSchedule csch = { + 0, + ocpp::v16::conversions::charging_rate_unit_to_string(schedule.chargingRateUnit), + {}, + std::nullopt, + schedule.duration, + std::nullopt, + schedule.minChargingRate}; + for (const auto& i : schedule.chargingSchedulePeriod) { + csch.charging_schedule_period.emplace_back(to_charging_schedule_period(i)); + } + if (schedule.startSchedule.has_value()) { + csch.start_schedule = schedule.startSchedule.value().to_rfc3339(); + } + return csch; +} + } // namespace conversions } // namespace module diff --git a/modules/OCPP/conversions.hpp b/modules/OCPP/conversions.hpp index 5f6633ba8..9e3524a31 100644 --- a/modules/OCPP/conversions.hpp +++ b/modules/OCPP/conversions.hpp @@ -89,6 +89,13 @@ types::authorization::AuthorizationStatus to_everest_authorization_status(const types::authorization::AuthorizationStatus to_everest_authorization_status(const ocpp::v201::AuthorizationStatusEnum status); +/// \brief Convert ocpp::v16::EnhancedChargingSchedulePeriod to types::ocpp::ChargingSchedulePeriod +types::ocpp::ChargingSchedulePeriod +to_charging_schedule_period(const ocpp::v16::EnhancedChargingSchedulePeriod& period); + +/// \brief Convert ocpp::v16::EnhancedChargingSchedule to types::ocpp::ChargingSchedule +types::ocpp::ChargingSchedule to_charging_schedule(const ocpp::v16::EnhancedChargingSchedule& schedule); + } // namespace conversions } // namespace module diff --git a/types/ocpp.yaml b/types/ocpp.yaml index c528c9c78..811d4bc50 100644 --- a/types/ocpp.yaml +++ b/types/ocpp.yaml @@ -7,17 +7,17 @@ types: Element providing information on a charging schedule period. type: object required: - - startPeriod + - start_period - limit - - stackLevel + - stack_level properties: - startPeriod: + start_period: type: integer limit: type: number - numberPhases: + number_phases: type: integer - stackLevel: + stack_level: type: integer ChargingSchedule: description: >- @@ -25,8 +25,8 @@ types: type: object required: - connector - - chargingRateUnit - - chargingSchedulePeriod + - charging_rate_unit + - charging_schedule_period properties: evse: description: The OCPP 2.0.1 EVSE ID (not used in OCPP 1.6). @@ -35,9 +35,9 @@ types: connector: type: integer minimum: 0 - chargingRateUnit: + charging_rate_unit: type: string - chargingSchedulePeriod: + charging_schedule_period: type: array items: description: schedule periods @@ -45,9 +45,9 @@ types: $ref: /ocpp#/ChargingSchedulePeriod duration: type: integer - startSchedule: + start_schedule: type: string - minChargingRate: + min_charging_rate: type: number ChargingSchedules: description: schedules for connectors