-
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
4 changed files
with
157 additions
and
3 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
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,83 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace OpenProtocolInterpreter.Tightening | ||
{ | ||
public class Mid0902 : Mid, ITightening, IIntegrator | ||
{ | ||
public const int Mid = 902; | ||
|
||
public long Capacity { get; set; } | ||
public long OldestSequenceNumber { get; set; } | ||
public DateTime OldestTime { get; set; } | ||
public long NewestSequenceNumber { get; set; } | ||
public DateTime NewestTime { get; set; } | ||
public int NumberOfPIDs { get; set; } | ||
public List<TighteningResultDataField> TighteningDataFields { get; set; } | ||
|
||
public Mid0902() : this(new Header() | ||
{ | ||
Mid = Mid, | ||
Revision = DEFAULT_REVISION | ||
}) | ||
{ | ||
|
||
} | ||
|
||
public Mid0902(Header header) : base(header) | ||
{ | ||
} | ||
|
||
public override string Pack() | ||
{ | ||
var revision = Header.StandardizedRevision; | ||
GetField(revision, DataFields.DataFields).SetValue(OpenProtocolConvert.ToString(TighteningDataFields)); | ||
|
||
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.DataFields); | ||
field.Size = Header.Length - field.Index; | ||
base.Parse(package); | ||
TighteningDataFields = TighteningResultDataField.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.Capacity, 20, 10, false), | ||
DataField.Number(DataFields.OldestSequenceNumber, 30, 10, false), | ||
DataField.Timestamp(DataFields.OldestTime, 40, false), | ||
DataField.Number(DataFields.NewestSequenceNumber, 59, 10, false), | ||
DataField.Timestamp(DataFields.NewestTime, 69, false), | ||
DataField.Number(DataFields.NumberOfPIDs, 88, 10, false), | ||
DataField.Volatile(DataFields.DataFields, 98, false) | ||
} | ||
} | ||
}; | ||
} | ||
|
||
protected enum DataFields | ||
{ | ||
Capacity, | ||
OldestSequenceNumber, | ||
OldestTime, | ||
NewestSequenceNumber, | ||
NewestTime, | ||
NumberOfPIDs, | ||
DataFields | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/OpenProtocolInterpreter/Tightening/TighteningResultDataField.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,60 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace OpenProtocolInterpreter.Tightening | ||
{ | ||
public class TighteningResultDataField | ||
{ | ||
public int ParameterId { get; set; } | ||
public int Length { get; set; } | ||
public DataTypeDefinition DataType { get; set; } | ||
public DataUnitType Unit { get; set; } | ||
public string DataValue { get; set; } | ||
|
||
public string Pack() | ||
{ | ||
return OpenProtocolConvert.ToString('0', 5, PaddingOrientation.LeftPadded, ParameterId) + | ||
OpenProtocolConvert.ToString('0', 3, PaddingOrientation.LeftPadded, Length) + | ||
OpenProtocolConvert.ToString('0', 2, PaddingOrientation.LeftPadded, DataType) + | ||
OpenProtocolConvert.ToString('0', 3, PaddingOrientation.LeftPadded, Unit) + | ||
OpenProtocolConvert.TruncatePadded(' ', Length, PaddingOrientation.RightPadded, DataValue); | ||
} | ||
|
||
public static TighteningResultDataField Parse(string value) | ||
{ | ||
var length = OpenProtocolConvert.ToInt32(value.Substring(5, 3)); | ||
return Parse(value, length); | ||
} | ||
|
||
public static IEnumerable<TighteningResultDataField> ParseAll(string value) | ||
{ | ||
if (string.IsNullOrWhiteSpace(value)) | ||
{ | ||
yield break; | ||
} | ||
|
||
int valueLength; | ||
const int fixedLength = 13; | ||
for (int i = 0; i < value.Length; i += fixedLength + valueLength) | ||
{ | ||
valueLength = OpenProtocolConvert.ToInt32(value.Substring(i + 5, 3)); | ||
var section = value.Substring(i, fixedLength + valueLength); | ||
yield return Parse(section, valueLength); | ||
} | ||
} | ||
|
||
private static TighteningResultDataField Parse(string value, int length) | ||
{ | ||
return new TighteningResultDataField() | ||
{ | ||
ParameterId = OpenProtocolConvert.ToInt32(value.Substring(0, 5)), | ||
Length = length, | ||
DataType = (DataTypeDefinition)OpenProtocolConvert.ToInt32(value.Substring(8, 2)), | ||
Unit = (DataUnitType)OpenProtocolConvert.ToInt32(value.Substring(10, 3)), | ||
DataValue = value.Substring(13, length) | ||
}; | ||
} | ||
|
||
} | ||
} |