Skip to content

Commit

Permalink
Smart Charging - SetChargingProfile object and data types (#26)
Browse files Browse the repository at this point in the history
* Objects for Tokens authorization logic

* add new lines at end of files

* Smart Charging - SetChargingProfile object and data types

* new lines at end of files

* add ToString Methods

* improve ToString

* Name fix

* Align class names with lib conventaion

* CR fixes

* remove required attribute and make all properties nullable

---------

Co-authored-by: Lior Ben Ari <[email protected]>
  • Loading branch information
LiorBenAri and Lior Ben Ari authored Feb 8, 2024
1 parent 045ba08 commit 94301a3
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 3 deletions.
78 changes: 78 additions & 0 deletions src/OCPI.Net.Contracts/ChargingProfiles/OcpiChargingProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System.Text;
using System.Text.Json.Serialization;
using OCPI.Enums.SmartCharging;

namespace OCPI.Contracts.ChargingProfiles;

public class OcpiChargingProfile
{
/// <summary>
/// Starting point of an absolute profile. If absent the profile
/// will be relative to start of charging.
/// </summary>
[JsonPropertyName("start_date_time")]
public DateTime? StartDateTime { get; set; }

/// <summary>
/// Duration of the charging profile in seconds. If the
/// duration is left empty, the last period will continue
/// indefinitely or until end of the transaction in case
/// start_date_time is absent.
/// </summary>
[JsonPropertyName("duration")]
public int? Duration { get; set; }

/// <summary>
/// The unit of measure.
/// </summary>
[JsonPropertyName("charging_rate_unit")]
public ChargingRateUnit? ChargingRateUnit { get; set; }

/// <summary>
/// Minimum charging rate supported by the EV. The unit
/// of measure is defined by the chargingRateUnit.This
/// parameter is intended to be used by a local smart
/// charging algorithm to optimize the power allocation for
/// in the case a charging process is inefficient at lower
/// charging rates.Accepts at most one digit fraction.
/// </summary>
[JsonPropertyName("min_charging_rate")]
public decimal? MinChargingRate { get; set; }

/// <summary>
/// List of ChargingProfilePeriod elements defining
/// maximum power or current usage over time.
/// </summary>
[JsonPropertyName("charging_profile_period")]
public IEnumerable<OcpiChargingProfilePeriod>? ChargingProfilePeriods { get; set; }

public override string ToString()
{
var toStringBuilder = new StringBuilder();

toStringBuilder.Append($"Start date time: {StartDateTime}, ");
toStringBuilder.AppendLine($"Duration: {Duration},");
toStringBuilder.Append($"Charging rate unit: {ChargingRateUnit}, ");
toStringBuilder.AppendLine($"Minimum charging rate: {MinChargingRate},");

var chargingProfilePeriodToString = ChargingProfilePeriodsToString();
toStringBuilder.Append(chargingProfilePeriodToString);

return toStringBuilder.ToString();
}

private string ChargingProfilePeriodsToString()
{
if (ChargingProfilePeriods is null || !ChargingProfilePeriods.Any())
return string.Empty;

var toStringBuilder = new StringBuilder();
toStringBuilder.AppendLine("ChargingProfilePeriods:");

var periodNum = 1;
foreach (var period in ChargingProfilePeriods)
toStringBuilder.Append($"Period #{periodNum++}: {period}; ");

return toStringBuilder.ToString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Text.Json.Serialization;

namespace OCPI.Contracts.ChargingProfiles;

public class OcpiChargingProfilePeriod
{
/// <summary>
/// Start of the period, in seconds from the start of profile. The value of StartPeriod
/// also defines the stop time of the previous period.
/// </summary>
[JsonPropertyName("start_period")]
public int? StartPeriod { get; set; }

/// <summary>
/// Charging rate limit during the profile period, in the applicable chargingRateUnit,
/// for example in Amperes(A) or Watts(W). Accepts at most one digit fraction.
/// </summary>
[JsonPropertyName("limit")]
public decimal? Limit { get; set; }

public override string ToString() => $"Start Period: {StartPeriod}, Limit: {Limit}";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Text.Json.Serialization;
using OCPI.Enums.SmartCharging;

namespace OCPI.Contracts.ChargingProfiles;
public class OcpiChargingProfileResponse
{
/// <summary>
/// Response from the CPO on the ChargingProfile request.
/// </summary>
[JsonPropertyName("result")]
public ChargingProfileResponseType? Result { get; set; }

/// <summary>
/// Response from the CPO on the ChargingProfile request.
/// </summary>
[JsonPropertyName("timeout")]
public int? Timeout { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Text.Json.Serialization;

namespace OCPI.Contracts.ChargingProfiles;
public class OcpiSetChargingProfileRequest
{
/// <summary>
/// Contains limits for the available power or current over time.
/// </summary>
[JsonPropertyName("charging_profile")]
public OcpiChargingProfile? ChargingProfile { get; set; }

/// <summary>
/// URL that the ChargingProfileResult POST should be send to. This
/// URL might contain an unique ID to be able to distinguish between
/// GET ActiveChargingProfile requests.
/// </summary>
[JsonPropertyName("response_url")]
public string? ResponseUrl { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace OCPI.Contracts;

public class AuthorizationInfo
public class OcpiAuthorizationInfo
{
/// <summary>
/// Status of the Token, and whether charging is allowed at the optionally
Expand All @@ -23,7 +23,7 @@ public class AuthorizationInfo
/// EV driver is allowed to charge at are returned.
/// </summary>
[JsonPropertyName("location")]
public LocationReferences? LocationReferences { get; set; }
public OcpiLocationReferences? LocationReferences { get; set; }

/// <summary>
/// Reference to the authorization given by the eMSP, when given, this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace OCPI.Contracts;

public class LocationReferences
public class OcpiLocationReferences
{
/// <summary>
/// Unique identifier for the location.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.Runtime.Serialization;

namespace OCPI.Enums.SmartCharging;

public enum ChargingProfileResponseType : byte
{
//====================1x: Success========================

/// <summary>
/// ChargingProfile request accepted by the CPO, request will be forwarded to the EVSE.
/// </summary>
[EnumMember(Value = "ACCEPTED")]
Accepted = 11,

//====================2x: Rejected========================

/// <summary>
/// ChargingProfile request rejected by the CPO. (Session might not be from a customer of the eMSP
/// that send this request)
/// </summary>
[EnumMember(Value = "REJECTED")]
Rejected = 21,

/// <summary>
/// ChargingProfile request rejected by the CPO, requests are send more often then allowed.
/// </summary>
[EnumMember(Value = "TOO_OFTEN")]
TooOften = 22,

//====================3x: Fail========================

/// <summary>
/// The ChargingProfiles not supported by this CPO, Charge Point, EVSE etc.
/// </summary>
[EnumMember(Value = "NOT_SUPPORTED")]
NotSupported = 31,

/// <summary>
/// The Session in the requested command is not known by this CPO.
/// </summary>
[EnumMember(Value = "UNKNOWN_SESSION")]
UnknownSession = 32,
}
27 changes: 27 additions & 0 deletions src/OCPI.Net.Core/Enums/ChargingProfiles/ChargingRateUnit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Runtime.Serialization;

namespace OCPI.Enums.SmartCharging;

public enum ChargingRateUnit : byte
{
/// <summary>
/// Watts (power)
/// This is the TOTAL allowed charging power. If used for AC Charging, the phase current should be
/// calculated via: Current per phase = Power / (Line Voltage * Number of Phases). The "Line Voltage"
/// used in the calculation is the Line to Neutral Voltage (VLN). In Europe and Asia VLN is typically
/// 220V or 230V and the corresponding Line to Line Voltage (VLL) is 380V and 400V. The "Number of
/// Phases" is the numberPhases from the ChargingProfilePeriod. It is usually more convenient to use
/// this for DC charging. Note that if numberPhases in a ChargingProfilePeriod is absent, 3 SHALL be
/// assumed.
/// </summary>
[EnumMember(Value = "W")]
Watts = 11,

/// <summary>
/// Amperes (current)
/// The amount of Ampere per phase, not the sum of all phases. It is usually more convenient to use
/// this for AC charging.
/// </summary>
[EnumMember(Value = "A")]
Amperes = 12,
}

0 comments on commit 94301a3

Please sign in to comment.