Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added charging schedules definition #582

Merged
merged 9 commits into from
Apr 10, 2024
1 change: 1 addition & 0 deletions interfaces/ocpp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ vars:
object contains one composite charging schedule for each connector id starting
from connector 0. Connector 0 contains a schedule for the whole charging station.
type: object
$ref: /ocpp#/ChargingSchedules
is_connected:
description: Indicates if chargepoint is connected to CSMS
type: boolean
Expand Down
9 changes: 1 addition & 8 deletions interfaces/ocpp_1_6_charge_point.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cmds:
false
get_configuration_key:
description: >-
Gets the response to the requested configuration key containing a list of the values of the requested keys
Gets the response to the requested configuration key containing a list of the values of the requested keys
and a list of the keys that are unknown
arguments:
keys:
Expand Down Expand Up @@ -74,12 +74,6 @@ cmds:
description: Additional information about the occurred security event
type: string
vars:
charging_schedules:
description: >-
Object that contains OCPP charging schedules of all connectors. The
object contains one composite charging schedule for each connector id starting
from connector 0. Connector 0 contains a schedule for the whole charging station.
type: object
is_connected:
description: Indicates if chargepoint is connected to CSMS
type: boolean
Expand All @@ -93,4 +87,3 @@ vars:
description: Published when an internal security event occured
type: object
$ref: /ocpp#/SecurityEvent

11 changes: 7 additions & 4 deletions modules/OCPP/OCPP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright 2020 - 2022 Pionix GmbH and Contributors to EVerest
#include "OCPP.hpp"
#include "generated/types/ocpp.hpp"
#include "ocpp/v16/types.hpp"
#include <fmt/core.h>
#include <fstream>

Expand Down Expand Up @@ -144,11 +145,13 @@ void OCPP::set_external_limits(const std::map<int32_t, ocpp::v16::EnhancedChargi
void OCPP::publish_charging_schedules(
const std::map<int32_t, ocpp::v16::EnhancedChargingSchedule>& charging_schedules) {
// publish the schedule over mqtt
Object j;
for (const auto charging_schedule : charging_schedules) {
j[std::to_string(charging_schedule.first)] = charging_schedule.second;
types::ocpp::ChargingSchedules schedules;
for (const auto& charging_schedule : charging_schedules) {
types::ocpp::ChargingSchedule sch = conversions::to_charging_schedule(charging_schedule.second);
sch.connector = charging_schedule.first;
schedules.schedules.emplace_back(std::move(sch));
}
this->p_ocpp_generic->publish_charging_schedules(j);
this->p_ocpp_generic->publish_charging_schedules(schedules);
}

void OCPP::process_session_event(int32_t evse_id, const types::evse_manager::SessionEvent& session_event) {
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
60 changes: 60 additions & 0 deletions types/ocpp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,66 @@ description: >-
OCPP types (OCPP1.6 and OCPP2.0.1). The types are based more on the type definitions of OCPP201,
as these offer more flexibility and are easier to transfer to OCPP1.6 than vice versa.
types:
ChargingSchedulePeriod:
description: >-
Element providing information on a charging schedule period.
type: object
required:
- start_period
- limit
- stack_level
properties:
start_period:
type: integer
limit:
type: number
number_phases:
type: integer
stack_level:
type: integer
ChargingSchedule:
description: >-
Element providing information on an OCPP charging schedule.
type: object
required:
- connector
- charging_rate_unit
- charging_schedule_period
properties:
evse:
description: The OCPP 2.0.1 EVSE ID (not used in OCPP 1.6).
type: integer
minimum: 0
connector:
type: integer
minimum: 0
hikinggrass marked this conversation as resolved.
Show resolved Hide resolved
charging_rate_unit:
type: string
charging_schedule_period:
type: array
items:
description: schedule periods
type: object
$ref: /ocpp#/ChargingSchedulePeriod
duration:
type: integer
start_schedule:
type: string
min_charging_rate:
type: number
ChargingSchedules:
description: schedules for connectors
type: object
required:
- schedules
properties:
schedules:
description: array of schedules
type: array
items:
description: schedule for a connector
type: object
$ref: /ocpp#/ChargingSchedule
OcppTransactionEvent:
description: >-
Element providing information on OCPP transactions.
Expand Down
Loading