Skip to content

Commit

Permalink
#108 Added Mid0704
Browse files Browse the repository at this point in the history
  • Loading branch information
Rickedb committed Dec 10, 2023
1 parent 6d13359 commit 768f673
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 2 deletions.
37 changes: 37 additions & 0 deletions src/MIDTesters.Core/Tool/TestMid0704.cs
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);
}
}
}
83 changes: 83 additions & 0 deletions src/OpenProtocolInterpreter/Tool/Mid0704.cs
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
}
}
}
5 changes: 3 additions & 2 deletions src/OpenProtocolInterpreter/Tool/ToolMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public ToolMessages() : base()
{ Mid0048.MID, new MidCompiledInstance(typeof(Mid0048)) },
{ Mid0701.MID, new MidCompiledInstance(typeof(Mid0701)) },
{ Mid0702.MID, new MidCompiledInstance(typeof(Mid0702)) },
{ Mid0703.MID, new MidCompiledInstance(typeof(Mid0703)) }
{ Mid0703.MID, new MidCompiledInstance(typeof(Mid0703)) },
{ Mid0704.MID, new MidCompiledInstance(typeof(Mid0704)) }
};
}

Expand All @@ -38,6 +39,6 @@ public ToolMessages(InterpreterMode mode) : this()
FilterSelectedMids(mode);
}

public override bool IsAssignableTo(int mid) => (mid > 39 && mid < 49) || (mid > 699 && mid < 704);
public override bool IsAssignableTo(int mid) => (mid > 39 && mid < 49) || (mid > 699 && mid < 705);
}
}

0 comments on commit 768f673

Please sign in to comment.