Skip to content

Commit

Permalink
#108 Added Mid2506
Browse files Browse the repository at this point in the history
  • Loading branch information
Rickedb committed Nov 17, 2023
1 parent d3d615d commit bbadb7d
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 2 deletions.
35 changes: 35 additions & 0 deletions src/MIDTesters.Core/ParameterSet/TestMid2506.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenProtocolInterpreter.ParameterSet;

namespace MIDTesters.Core.ParameterSet
{
[TestClass]
[TestCategory("ParameterSet")]
public class TestMid2506 : DefaultMidTests<Mid2506>
{
[TestMethod]
[TestCategory("Revision 1"), TestCategory("ASCII")]
public void Mid2506Revision1()
{
string package = "00272506001 0030201";
var mid = _midInterpreter.Parse<Mid2506>(package);

Assert.AreNotEqual(0, mid.ProgramId);
Assert.AreNotEqual(0, (int)mid.NodeType);
AssertEqualPackages(package, mid);
}

[TestMethod]
[TestCategory("Revision 1"), TestCategory("ByteArray")]
public void Mid2506ByteRevision1()
{
string package = "00272506001 0030201";
byte[] bytes = GetAsciiBytes(package);
var mid = _midInterpreter.Parse<Mid2506>(bytes);

Assert.AreNotEqual(0, mid.ProgramId);
Assert.AreNotEqual(0, (int)mid.NodeType);
AssertEqualPackages(bytes, mid);
}
}
}
18 changes: 18 additions & 0 deletions src/OpenProtocolInterpreter/Enums/NodeType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace OpenProtocolInterpreter
{
public enum NodeType
{
ParameterSet = 1,
Multistage = 2,
Job = 3,

TighteningProgram = 100,
TighteningStep = 101,
Restriction = 102,
Check = 103,
SpeedRamp = 104,
Monitoring = 105,

MultistepTighteningProgram = 201
}
}
67 changes: 67 additions & 0 deletions src/OpenProtocolInterpreter/ParameterSet/Mid2506.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System.Collections.Generic;

namespace OpenProtocolInterpreter.ParameterSet
{
/// <summary>
/// Tightening Program Delete
/// <para>Message sent by: Integrator</para>
/// <para>
/// Answer: <see cref="Communication.Mid0005"/> Command accepted or
/// <see cref="Communication.Mid0004"/> Command error
/// </para>
/// <para> This message deletes one or all programs in controller. </para>
/// <para> <b>Note</b>: If a running program is included in MID 2506 deletion the program shall finish before deletion. </para>
/// <para> <b>Note</b>: Deleting programs included in other nodes may give unwanted behaviour. It will behave identical to a manual delete of the program. </para>
/// </summary>
public class Mid2506 : Mid, IParameterSet, IIntegrator, IAcceptableCommand, IDeclinableCommand
{
public const int MID = 2506;

public IEnumerable<Error> DocumentedPossibleErrors => [];

Check failure on line 20 in src/OpenProtocolInterpreter/ParameterSet/Mid2506.cs

View workflow job for this annotation

GitHub Actions / build

The feature 'collection literals' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.

public int ProgramId
{
get => GetField(1, DataFields.ProgramId).GetValue(OpenProtocolConvert.ToInt32);
set => GetField(1, DataFields.ProgramId).SetValue(OpenProtocolConvert.ToString, value);
}
public NodeType NodeType
{
get => (NodeType)GetField(1, DataFields.NodeType).GetValue(OpenProtocolConvert.ToInt32);
set => GetField(1, DataFields.NodeType).SetValue(OpenProtocolConvert.ToString, value);
}

public Mid2506() : this(new Header()
{
Mid = MID,
Revision = DEFAULT_REVISION
})
{

}

public Mid2506(Header header) : base(header)
{

}

protected override Dictionary<int, List<DataField>> RegisterDatafields()
{
return new Dictionary<int, List<DataField>>()
{
{
1, new List<DataField>()
{
DataField.Number(DataFields.ProgramId, 20, 4, false),
DataField.Number(DataFields.NodeType, 24, 3, false),
}
}
};
}

protected enum DataFields
{
ProgramId,
NodeType
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public ParameterSetMessages() : base()
{ Mid0023.MID, new MidCompiledInstance(typeof(Mid0023)) },
{ Mid0024.MID, new MidCompiledInstance(typeof(Mid0024)) },
{ Mid2504.MID, new MidCompiledInstance(typeof(Mid2504)) },
{ Mid2505.MID, new MidCompiledInstance(typeof(Mid2505)) }
{ Mid2505.MID, new MidCompiledInstance(typeof(Mid2505)) },
{ Mid2506.MID, new MidCompiledInstance(typeof(Mid2506)) }
};
}

Expand All @@ -43,6 +44,6 @@ public ParameterSetMessages(InterpreterMode mode) : this()
FilterSelectedMids(mode);
}

public override bool IsAssignableTo(int mid) => mid > 9 && mid < 26 || mid > 2499 && mid < 2506;
public override bool IsAssignableTo(int mid) => mid > 9 && mid < 26 || mid > 2499 && mid < 2507;
}
}

0 comments on commit bbadb7d

Please sign in to comment.