-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added CLI test command 'reset' for OCPP v1.6/v2.1
- Loading branch information
Showing
8 changed files
with
567 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
WWCP_OCPPv1.6_CentralSystem/CLI/CLICommands/DefaultStrings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright (c) 2014-2024 GraphDefined GmbH <achim.friedland@graphdefined.com> | ||
* This file is part of WWCP OCPP <https://github.com/OpenChargingCloud/WWCP_OCPP> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace cloud.charging.open.protocols.OCPPv1_6.CentralSystem.CommandLine | ||
{ | ||
|
||
public static class DefaultStrings | ||
{ | ||
|
||
public const String OCPPv1_6 = "OCPPv1.6"; | ||
|
||
} | ||
|
||
} |
147 changes: 147 additions & 0 deletions
147
WWCP_OCPPv1.6_CentralSystem/CLI/CLICommands/ResetCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
/* | ||
* Copyright (c) 2014-2024 GraphDefined GmbH <achim.friedland@graphdefined.com> | ||
* This file is part of WWCP OCPP <https://github.com/OpenChargingCloud/WWCP_OCPP> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#region Usings | ||
|
||
using org.GraphDefined.Vanaheimr.CLI; | ||
using org.GraphDefined.Vanaheimr.Illias; | ||
|
||
using cloud.charging.open.protocols.OCPPv1_6.CS; | ||
|
||
#endregion | ||
|
||
namespace cloud.charging.open.protocols.OCPPv1_6.CentralSystem.CommandLine | ||
{ | ||
|
||
/// <summary> | ||
/// Reset the current networking node | ||
/// </summary> | ||
/// <param name="CLI">The command line interface</param> | ||
//[CLIContext([ DefaultStrings.OCPPv1_6 ])] | ||
public class ResetCommand(ICentralSystemCLI CLI) : ACLICommand<ICentralSystemCLI>(CLI), | ||
ICLICommand | ||
{ | ||
|
||
#region Data | ||
|
||
public static readonly String CommandName = nameof(ResetCommand)[..^7].ToLowerFirstChar(); | ||
|
||
#endregion | ||
|
||
#region Suggest(Arguments) | ||
|
||
public override IEnumerable<SuggestionResponse> Suggest(String[] Arguments) | ||
{ | ||
|
||
// No suggestions without a defined RemoteSystemId and matching OCPP version! | ||
if (!cli.RemoteSystemIdIsSet() || | ||
cli.GetRemoteSystemOCPPVersion() != DefaultStrings.OCPPv1_6) | ||
{ | ||
return []; | ||
} | ||
|
||
|
||
if (Arguments.Length > 2 && | ||
CommandName.Equals(Arguments[0], StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
Arguments = Arguments.Take(2).ToArray(); | ||
} | ||
|
||
|
||
if (Arguments.Length == 2 && | ||
CommandName.Equals(Arguments[0], StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
|
||
foreach (var resetType in ResetType.All) | ||
{ | ||
|
||
if (resetType.ToString().Equals (Arguments[1], StringComparison.OrdinalIgnoreCase)) | ||
return [ SuggestionResponse.ParameterCompleted($"{Arguments[0]} {resetType.ToString().ToLower()}") ]; | ||
|
||
if (resetType.ToString().StartsWith(Arguments[1], StringComparison.OrdinalIgnoreCase)) | ||
return [ SuggestionResponse.ParameterPrefix ($"{Arguments[0]} {resetType.ToString().ToLower()}") ]; | ||
|
||
} | ||
|
||
return [ SuggestionResponse.CommandCompleted(CommandName) ]; | ||
|
||
} | ||
|
||
|
||
if (Arguments.Length == 1) | ||
{ | ||
|
||
if (CommandName.Equals (Arguments[0], StringComparison.OrdinalIgnoreCase)) | ||
return [ SuggestionResponse.CommandHelp(Help()) ]; | ||
|
||
if (CommandName.StartsWith(Arguments[0], StringComparison.OrdinalIgnoreCase)) | ||
return [ SuggestionResponse.CommandCompleted(CommandName) ]; | ||
|
||
} | ||
|
||
return []; | ||
|
||
} | ||
|
||
#endregion | ||
|
||
#region Execute(Arguments, CancellationToken) | ||
|
||
public override async Task<String[]> Execute(String[] Arguments, | ||
CancellationToken CancellationToken) | ||
{ | ||
|
||
// No execution without a defined RemoteSystemId! | ||
var sourceRoute = cli.GetRemoteSystemSourceRoute(); | ||
if (sourceRoute is null) | ||
return []; | ||
|
||
|
||
if (Arguments.Length == 2 && | ||
ResetType.TryParse(Arguments[1], out var resetType)) | ||
{ | ||
|
||
var response = await cli.OCPP.OUT.Reset( | ||
new ResetRequest( | ||
Destination: sourceRoute, | ||
ResetType: resetType | ||
) | ||
); | ||
|
||
return [ | ||
$"{Arguments.AggregateWith(" ")} => {response.Runtime.TotalMilliseconds} ms", | ||
response.ToJSON().ToString(Newtonsoft.Json.Formatting.Indented) | ||
]; | ||
|
||
} | ||
|
||
return [ $"Usage: {CommandName} <{ResetType.All.Select(_ => _.ToString()).AggregateWith("|")}>" ]; | ||
|
||
} | ||
|
||
#endregion | ||
|
||
#region Help() | ||
|
||
public override String Help() | ||
=> $"{CommandName} <{ResetType.All.Select(_ => _.ToString()).AggregateWith("|")}> - Reset the current networking node"; | ||
|
||
#endregion | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright (c) 2014-2024 GraphDefined GmbH <achim.friedland@graphdefined.com> | ||
* This file is part of WWCP OCPP <https://github.com/OpenChargingCloud/WWCP_OCPP> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#region Usings | ||
|
||
using org.GraphDefined.Vanaheimr.CLI; | ||
|
||
using cloud.charging.open.protocols.WWCP.NetworkingNode; | ||
using cloud.charging.open.protocols.OCPPv1_6.NetworkingNode; | ||
|
||
#endregion | ||
|
||
namespace cloud.charging.open.protocols.OCPPv1_6.CentralSystem.CommandLine | ||
{ | ||
|
||
public static class ICentralSystemCLIExtensions | ||
{ | ||
|
||
public static Boolean RemoteSystemIdIsSet(this ICentralSystemCLI CLI) | ||
{ | ||
|
||
if (CLI.Environment.TryGetValue(EnvironmentKey.RemoteSystemId, out var values) && | ||
values.Count > 0) | ||
{ | ||
return true; | ||
} | ||
|
||
return false; | ||
|
||
} | ||
|
||
public static NetworkingNode_Id? GetRemoteSystemId(this ICentralSystemCLI CLI) | ||
{ | ||
|
||
if (CLI.Environment.TryGetValue(EnvironmentKey.RemoteSystemId, out var values) && | ||
values.Count > 0 && | ||
NetworkingNode_Id.TryParse(values.First(), out var remoteSystemId)) | ||
{ | ||
return remoteSystemId; | ||
} | ||
|
||
return null; | ||
|
||
} | ||
|
||
public static SourceRouting? GetRemoteSystemSourceRoute(this ICentralSystemCLI CLI) | ||
{ | ||
|
||
if (CLI.Environment.TryGetValue(EnvironmentKey.RemoteSystemId, out var values) && | ||
values.Count > 0 && | ||
NetworkingNode_Id.TryParse(values.First(), out var remoteSystemId)) | ||
{ | ||
return SourceRouting.To(remoteSystemId); | ||
} | ||
|
||
return null; | ||
|
||
} | ||
|
||
public static String? GetRemoteSystemOCPPVersion(this ICentralSystemCLI CLI) | ||
{ | ||
|
||
if (CLI.Environment.TryGetValue(EnvironmentKey.RemoteSystemOCPPVersion, out var values) && | ||
values.Count > 0) | ||
{ | ||
return values.First(); | ||
} | ||
|
||
return null; | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
public interface ICentralSystemCLI : ICLI | ||
{ | ||
|
||
OCPPAdapter OCPP { get; } | ||
|
||
IEnumerable<NetworkingNode_Id> ConnectedNetworkingNodeIds { get; } | ||
|
||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2014-2024 GraphDefined GmbH <achim.friedland@graphdefined.com> | ||
* This file is part of WWCP OCPP <https://github.com/OpenChargingCloud/WWCP_OCPP> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace cloud.charging.open.protocols.OCPPv2_1.CSMS.CommandLine | ||
{ | ||
|
||
public static class DefaultStrings | ||
{ | ||
|
||
public const String OCPPv2_0_1 = "OCPPv2.0.1"; | ||
public const String OCPPv2_1 = "OCPPv2.1"; | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.