-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
123 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using OpenProtocolInterpreter.Tool; | ||
|
||
namespace MIDTesters.Core.Tool | ||
{ | ||
[TestClass] | ||
[TestCategory("Tool")] | ||
public class TestMid0704 : DefaultMidTests<Mid0704> | ||
{ | ||
[TestMethod] | ||
[TestCategory("Revision 1"), TestCategory("ASCII")] | ||
public void Mid0704Revision1() | ||
{ | ||
string package = "00700704001 00201200012040000000QST50-150CTT012150010200000003"; | ||
var mid = _midInterpreter.Parse<Mid0704>(package); | ||
|
||
Assert.AreNotEqual(0, mid.NumberOfDataFields); | ||
Assert.IsNotNull(mid.VariableDataFields); | ||
Assert.AreNotEqual(0, mid.VariableDataFields.Count); | ||
AssertEqualPackages(package, mid); | ||
} | ||
|
||
[TestMethod] | ||
[TestCategory("Revision 1"), TestCategory("ByteArray")] | ||
public void Mid0704ByteRevision1() | ||
{ | ||
string package = "01050704001 "; | ||
byte[] bytes = GetAsciiBytes(package); | ||
var mid = _midInterpreter.Parse<Mid0704>(bytes); | ||
|
||
Assert.AreNotEqual(0, mid.NumberOfDataFields); | ||
Assert.IsNotNull(mid.VariableDataFields); | ||
Assert.AreNotEqual(0, mid.VariableDataFields.Count); | ||
AssertEqualPackages(bytes, mid); | ||
} | ||
} | ||
} |
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,83 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace OpenProtocolInterpreter.Tool | ||
{ | ||
/// <summary> | ||
/// Tool Data status reply with generic data | ||
/// <para> | ||
/// Upload requested parameters from given tool. | ||
/// </para> | ||
/// <para>Message sent by: Controller</para> | ||
/// <para> | ||
/// Answer: None | ||
/// </para> | ||
/// <para> | ||
/// The list will contain requested parameters from the tool. | ||
/// </para> | ||
/// </summary> | ||
public class Mid0704 : Mid, ITool, IController | ||
{ | ||
public const int MID = 704; | ||
|
||
public int NumberOfDataFields | ||
{ | ||
get => GetField(1, DataFields.NumberOfDataFields).GetValue(OpenProtocolConvert.ToInt32); | ||
set => GetField(1, DataFields.NumberOfDataFields).SetValue(OpenProtocolConvert.ToString, value); | ||
} | ||
public List<VariableDataField> VariableDataFields { get; set; } | ||
|
||
public Mid0704() : this(new Header() | ||
{ | ||
Mid = MID, | ||
Revision = DEFAULT_REVISION | ||
}) | ||
{ | ||
|
||
} | ||
|
||
public Mid0704(Header header) : base(header) | ||
{ | ||
} | ||
|
||
public override string Pack() | ||
{ | ||
var revision = Header.StandardizedRevision; | ||
GetField(revision, DataFields.VariableDataFields).SetValue(OpenProtocolConvert.ToString(VariableDataFields)); | ||
|
||
var index = 1; | ||
return string.Concat(BuildHeader(), base.Pack(revision, ref index)); | ||
} | ||
|
||
public override Mid Parse(string package) | ||
{ | ||
Header = ProcessHeader(package); | ||
|
||
var field = GetField(1, DataFields.VariableDataFields); | ||
field.Size = Header.Length - field.Index; | ||
base.Parse(package); | ||
VariableDataFields = VariableDataField.ParseAll(field.Value).ToList(); | ||
return this; | ||
} | ||
|
||
protected override Dictionary<int, List<DataField>> RegisterDatafields() | ||
{ | ||
return new Dictionary<int, List<DataField>>() | ||
{ | ||
{ | ||
1, new List<DataField>() | ||
{ | ||
DataField.Number(DataFields.NumberOfDataFields, 20, 3, false), | ||
DataField.Volatile(DataFields.VariableDataFields, 23, false) | ||
} | ||
} | ||
}; | ||
} | ||
|
||
protected enum DataFields | ||
{ | ||
NumberOfDataFields, | ||
VariableDataFields | ||
} | ||
} | ||
} |
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