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

Add support of GetLocalListVersion and SendLocalList commands #24

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions OCPP.Core.Server/ControllerOCPP16.GetLocalListVersion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using OCPP.Core.Server.Messages_OCPP16;
using System;

namespace OCPP.Core.Server
{
public partial class ControllerOCPP16
{
public void HandleGetLocalListVersion(OCPPMessage msgIn, OCPPMessage msgOut)
{
Logger.LogInformation("GetLocalListVersion answer: ChargePointId={0} / MsgType={1} / ErrCode={2}",
ChargePointStatus.Id, msgIn.MessageType, msgIn.ErrorCode);

try
{
GetLocalListVersionResponse response = JsonConvert.DeserializeObject<GetLocalListVersionResponse>(msgIn.JsonPayload);
Logger.LogInformation("HandleGetLocalListVersion => Answer status: {0}", response?.ListVersion);
WriteMessageLog(ChargePointStatus?.Id, null, msgOut.Action, response?.ListVersion.ToString(), msgIn.ErrorCode);

if (msgOut.TaskCompletionSource != null)
{
// set API response as TaskCompletion result
string apiResult = "{\"listVersion\": " + JsonConvert.ToString(response?.ListVersion.ToString()) + "}";
Logger.LogTrace("HandleGetLocalListVersion => API response: {0}", apiResult);

msgOut.TaskCompletionSource.SetResult(apiResult);
}
}
catch (Exception exp)
{
Logger.LogError(exp, "HandleGetLocalListVersion => Exception: {0}", exp.Message);
}
}
}
}
36 changes: 36 additions & 0 deletions OCPP.Core.Server/ControllerOCPP16.SendLocalList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using OCPP.Core.Server.Messages_OCPP16;
using System;

namespace OCPP.Core.Server
{
public partial class ControllerOCPP16
{
public void HandleSendLocalList(OCPPMessage msgIn, OCPPMessage msgOut)
{
Logger.LogInformation("SendLocalList answer: ChargePointId={0} / MsgType={1} / ErrCode={2}",
ChargePointStatus.Id, msgIn.MessageType, msgIn.ErrorCode);

try
{
SendLocalListResponse response = JsonConvert.DeserializeObject<SendLocalListResponse>(msgIn.JsonPayload);
Logger.LogInformation("HandleSendLocalList => Answer status: {0}", response?.Status);
WriteMessageLog(ChargePointStatus?.Id, null, msgOut.Action, response?.Status.ToString(), msgIn.ErrorCode);

if (msgOut.TaskCompletionSource != null)
{
// set API response as TaskCompletion result
string apiResult = "{\"status\": " + JsonConvert.ToString(response?.Status.ToString()) + "}";
Logger.LogTrace("HandleSendLocalList => API response: {0}", apiResult);

msgOut.TaskCompletionSource.SetResult(apiResult);
}
}
catch (Exception exp)
{
Logger.LogError(exp, "HandleSendLocalList => Exception: {0}", exp.Message);
}
}
}
}
8 changes: 8 additions & 0 deletions OCPP.Core.Server/ControllerOCPP16.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ public void ProcessAnswer(OCPPMessage msgIn, OCPPMessage msgOut)
HandleUnlockConnector(msgIn, msgOut);
break;

case "GetLocalListVersion":
HandleGetLocalListVersion(msgIn, msgOut);
break;

case "SendLocalList":
HandleSendLocalList(msgIn, msgOut);
break;

default:
WriteMessageLog(ChargePointStatus.Id, null, msgIn.Action, msgIn.JsonPayload, "Unknown answer");
break;
Expand Down
36 changes: 36 additions & 0 deletions OCPP.Core.Server/ControllerOCPP20.GetLocalListVersion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using OCPP.Core.Server.Messages_OCPP20;
using System;

namespace OCPP.Core.Server
{
public partial class ControllerOCPP20
{
public void HandleGetLocalListVersion(OCPPMessage msgIn, OCPPMessage msgOut)
{
Logger.LogInformation("GetLocalListVersion answer: ChargePointId={0} / MsgType={1} / ErrCode={2}",
ChargePointStatus.Id, msgIn.MessageType, msgIn.ErrorCode);

try
{
GetLocalListVersionResponse response = JsonConvert.DeserializeObject<GetLocalListVersionResponse>(msgIn.JsonPayload);
Logger.LogInformation("HandleGetLocalListVersion => Answer status: {0}", response?.VersionNumber);
WriteMessageLog(ChargePointStatus?.Id, null, msgOut.Action, response?.VersionNumber.ToString(), msgIn.ErrorCode);

if (msgOut.TaskCompletionSource != null)
{
// set API response as TaskCompletion result
string apiResult = "{\"versionNumber\": " + JsonConvert.ToString(response?.VersionNumber.ToString()) + "}";
Logger.LogTrace("HandleGetLocalListVersion => API response: {0}", apiResult);

msgOut.TaskCompletionSource.SetResult(apiResult);
}
}
catch (Exception exp)
{
Logger.LogError(exp, "HandleGetLocalListVersion => Exception: {0}", exp.Message);
}
}
}
}
36 changes: 36 additions & 0 deletions OCPP.Core.Server/ControllerOCPP20.SendLocalList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using OCPP.Core.Server.Messages_OCPP20;
using System;

namespace OCPP.Core.Server
{
public partial class ControllerOCPP20
{
public void HandleSendLocalList(OCPPMessage msgIn, OCPPMessage msgOut)
{
Logger.LogInformation("SendLocalList answer: ChargePointId={0} / MsgType={1} / ErrCode={2}",
ChargePointStatus.Id, msgIn.MessageType, msgIn.ErrorCode);

try
{
SendLocalListResponse response = JsonConvert.DeserializeObject<SendLocalListResponse>(msgIn.JsonPayload);
Logger.LogInformation("HandleSendLocalList => Answer status: {0}", response?.Status);
WriteMessageLog(ChargePointStatus?.Id, null, msgOut.Action, response?.Status.ToString(), msgIn.ErrorCode);

if (msgOut.TaskCompletionSource != null)
{
// set API response as TaskCompletion result
string apiResult = "{\"status\": " + JsonConvert.ToString(response?.Status.ToString()) + "}";
Logger.LogTrace("HandleSendLocalList => API response: {0}", apiResult);

msgOut.TaskCompletionSource.SetResult(apiResult);
}
}
catch (Exception exp)
{
Logger.LogError(exp, "HandleSendLocalList => Exception: {0}", exp.Message);
}
}
}
}
8 changes: 8 additions & 0 deletions OCPP.Core.Server/ControllerOCPP20.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ public void ProcessAnswer(OCPPMessage msgIn, OCPPMessage msgOut)
HandleReset(msgIn, msgOut);
break;

case "GetLocalListVersion":
HandleGetLocalListVersion(msgIn, msgOut);
break;

case "SendLocalList":
HandleSendLocalList(msgIn, msgOut);
break;

case "UnlockConnector":
HandleUnlockConnector(msgIn, msgOut);
break;
Expand Down
11 changes: 11 additions & 0 deletions OCPP.Core.Server/Messages_OCPP16/GetLocalListVersionRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Drawing;

namespace OCPP.Core.Server.Messages_OCPP16
{
/// <summary>
/// This contains the field definition of the <see langword="GetLocalListVersion.req"/> PDU
/// sent by the Central System to the Charge Point.
/// </summary>
public class GetLocalListVersionRequest
{ }
}
19 changes: 19 additions & 0 deletions OCPP.Core.Server/Messages_OCPP16/GetLocalListVersionResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace OCPP.Core.Server.Messages_OCPP16
{
/// <summary>
/// This contains the field definition of the <see langword="GetLocalListVersion.conf"/> PDU
/// sent by the Charge Point to Central System
/// in response to a <see langword="GetLocalListVersion.req"/>
/// (i.e. <see cref="GetLocalListVersionRequest"/>) PDU.
/// </summary>
public class GetLocalListVersionResponse
{
/// <summary>
/// Required. <br/>
/// This contains the current version number of the local authorization list in the Charge Point.
/// </summary>
[Newtonsoft.Json.JsonProperty("listVersion", Required = Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)]
public System.Int32 ListVersion { get; set; }
}
}
86 changes: 86 additions & 0 deletions OCPP.Core.Server/Messages_OCPP16/SendLocalListRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;

namespace OCPP.Core.Server.Messages_OCPP16
{
#region SendLocalListRequest Specific Members
/// <summary>
/// Type of update for a <see langword="SendLocalList.req"/> (i.e. <see cref="SendLocalListRequest"/>).
/// </summary>
public enum UpdateType
{
/// <summary>
/// Indicates that the current Local Authorization List must be updated with the values in this message.
/// </summary>
[EnumMember(Value = @"Differential")]
Differential,

/// <summary>
/// Indicates that the current Local Authorization List must be replaced by the values in this message.
/// </summary>
[EnumMember(Value = @"Full")]
Full
}

/// <summary>
/// Elements that constitute an entry of a Local Authorization List update.
/// </summary>
public class AuthorizationData
{
/// <summary>
/// Required. <br/>
/// The identifier to which this authorization applies.
/// </summary>
[JsonProperty("idTag", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
[StringLength(20)]
public string IdTag { get; set; }

[JsonProperty("idTagInfo", Required = Required.Default)]
public IdTagInfo IdTagInfo { get; set; }
}
#endregion

/// <summary>
/// This contains the field definition of the <see langword="SendLocalList.req"/> PDU
/// sent by the Central System to the Charge Point.
/// </summary>
/// <remarks>
/// If no (empty) <see langword="localAuthorizationList"/> is given
/// and the <see langword="updateType"/> is Full, all identifications are removed from the list.
/// Requesting a Differential update without (empty) <see langword="localAuthorizationList"/> will have no effect on the list.
/// All idTags in the <see langword="localAuthorizationList"/> <strong>MUST</strong> be unique, no duplicate values are
/// allowed.
/// </remarks>
public class SendLocalListRequest
{
/// <summary>
/// Required. <br/>
/// In case of a full update this is the version number of the full list.
/// In case of a differential update it is the version number of the list after the update has been applied.
/// </summary>
[JsonProperty("listVersion", Required = Required.Always)]
[Required(AllowEmptyStrings = true)]
public int ListVersion { get; set; }

/// <summary>
/// Optional. <br/>
/// In case of a full update this contains the list of values that form the new local authorization list.
/// In case of a differential update it contains the changes to be applied to the local authorization list in the Charge Point.
/// Maximum number of AuthorizationData elements is available in the configuration key: SendLocalListMaxLength.
/// </summary>
[JsonProperty("localAuthorizationList", Required = Required.Always)]
[Required(AllowEmptyStrings = true)]
public List<AuthorizationData> LocalAuthorizationList { get; set; }

/// <summary>
/// Required. <br/>
/// This contains the type of update (full or differential) of this request.
/// </summary>
[JsonProperty("updateType", Required = Required.Always)]
[Required(AllowEmptyStrings = true)]
[JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
public UpdateType Type { get; set; }
}
}
55 changes: 55 additions & 0 deletions OCPP.Core.Server/Messages_OCPP16/SendLocalListResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;

namespace OCPP.Core.Server.Messages_OCPP16
{
#region SendLocalListResponse Specific Members
/// <summary>
/// Type of update for a <see langword="SendLocalList.req"/>
/// (i.e. <see cref="SendLocalListRequest"/>).
/// </summary>
public enum UpdateStatus
{
/// <summary>
/// Local Authorization List successfully updated.
/// </summary>
[EnumMember(Value = @"Accepted")]
Accepted,

/// <summary>
/// Failed to update the Local Authorization List.
/// </summary>
[EnumMember(Value = @"Failed")]
Failed,

/// <summary>
/// Update of Local Authorization List is not supported by Charge Point.
/// </summary>
[EnumMember(Value = @"NotSupported")]
NotSupported,

/// <summary>
/// Version number in the request for a differential update is less or equal then version number of current list
/// </summary>
[EnumMember(Value = @"VersionMismatch")]
VersionMismatch
}
#endregion

/// <summary>
/// This contains the field definition of the <see langword="SendLocalList.conf"/> PDU
/// sent by the Charge Point to the Central System
/// in response to a <see langword="SendLocalList.req"/> PDU (i.e. <see cref="SendLocalListRequest"/>).
/// </summary>
public class SendLocalListResponse
{
/// <summary>
/// Required. <br/>
/// This indicates whether the Charge Point has successfully received and applied the update of the local authorization list.
/// </summary>
[JsonProperty("status", Required = Required.Always)]
[Required(AllowEmptyStrings = true)]
public UpdateStatus Status { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace OCPP.Core.Server.Messages_OCPP20
{
/// <summary>
/// This contains the field definition of the GetLocalListVersionRequest PDU sent by the CSMS to the Charging Station.
/// No fields are defined.
/// </summary>
public class GetLocalListVersionRequest
{ }
}
19 changes: 19 additions & 0 deletions OCPP.Core.Server/Messages_OCPP20/GetLocalListVersionResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;

namespace OCPP.Core.Server.Messages_OCPP20
{
/// <summary>
/// This contains the field definition of the GetLocalListVersionResponse PDU sent by the Charging Station to CSMS
/// in response to a <see cref="GetLocalListVersionRequest"/>.
/// </summary>
public class GetLocalListVersionResponse
{
/// <summary>
/// Required. This contains the current version number of the local authorization list in the Charging Station.
/// </summary>
[JsonProperty("versionNumber", Required = Required.Always)]
[Required(AllowEmptyStrings = false)]
public int VersionNumber { get; set; }
}
}
Loading