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

40 changes: 36 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 @@ -141,14 +142,45 @@ void OCPP::set_external_limits(const std::map<int32_t, ocpp::v16::EnhancedChargi
}
}

namespace {
types::ocpp::ChargingSchedulePeriod to_ChargingSchedulePeriod(const ocpp::v16::EnhancedChargingSchedulePeriod& period) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the conversions.hpp / cpp for these conversions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved functions to conversions.[ch]pp

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),
{},
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
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 = to_ChargingSchedule(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
56 changes: 56 additions & 0 deletions types/ocpp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,62 @@ 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:
- startPeriod
- limit
- stackLevel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- startPeriod
- limit
- stackLevel
- start_period
- limit
- stack_level

properties:
startPeriod:
type: integer
limit:
type: number
numberPhases:
type: integer
stackLevel:
type: integer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
startPeriod:
type: integer
limit:
type: number
numberPhases:
type: integer
stackLevel:
type: integer
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
- chargingRateUnit
- chargingSchedulePeriod
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- chargingRateUnit
- chargingSchedulePeriod
- charging_rate_unit
- charging_schedule_period

properties:
connector:
type: integer
minimum: 0
hikinggrass marked this conversation as resolved.
Show resolved Hide resolved
chargingRateUnit:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
chargingRateUnit:
charging_rate_unit:

type: string
chargingSchedulePeriod:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
chargingSchedulePeriod:
charging_schedule_period:

type: array
items:
description: schedule periods
type: object
$ref: /ocpp#/ChargingSchedulePeriod
duration:
type: integer
startSchedule:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
startSchedule:
start_schedule:

type: string
minChargingRate:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
minChargingRate:
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