Skip to content

Commit

Permalink
fix: addressed PR comments on use of snake_case
Browse files Browse the repository at this point in the history
fix: moved conversions to separate file

Signed-off-by: James Chapman <[email protected]>
  • Loading branch information
james-ctc committed Mar 14, 2024
1 parent bfe1aa6 commit fa3f464
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 42 deletions.
32 changes: 1 addition & 31 deletions modules/OCPP/OCPP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,42 +142,12 @@ void OCPP::set_external_limits(const std::map<int32_t, ocpp::v16::EnhancedChargi
}
}

namespace {
types::ocpp::ChargingSchedulePeriod to_ChargingSchedulePeriod(const ocpp::v16::EnhancedChargingSchedulePeriod& period) {
types::ocpp::ChargingSchedulePeriod csp = {
period.startPeriod,
period.limit,
period.stackLevel,
period.numberPhases,
};
return csp;
}

types::ocpp::ChargingSchedule to_ChargingSchedule(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.chargingSchedulePeriod.emplace_back(to_ChargingSchedulePeriod(i));
}
if (schedule.startSchedule.has_value()) {
csch.startSchedule = schedule.startSchedule.value().to_rfc3339();
}
return csch;
}
} // namespace

void OCPP::publish_charging_schedules(
const std::map<int32_t, ocpp::v16::EnhancedChargingSchedule>& 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));
}
Expand Down
29 changes: 29 additions & 0 deletions modules/OCPP/conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions modules/OCPP/conversions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 11 additions & 11 deletions types/ocpp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ 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: >-
Element providing information on an OCPP charging schedule.
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).
Expand All @@ -35,19 +35,19 @@ types:
connector:
type: integer
minimum: 0
chargingRateUnit:
charging_rate_unit:
type: string
chargingSchedulePeriod:
charging_schedule_period:
type: array
items:
description: schedule periods
type: object
$ref: /ocpp#/ChargingSchedulePeriod
duration:
type: integer
startSchedule:
start_schedule:
type: string
minChargingRate:
min_charging_rate:
type: number
ChargingSchedules:
description: schedules for connectors
Expand Down

0 comments on commit fa3f464

Please sign in to comment.