Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Rickedb committed Jul 29, 2024
1 parent 2226813 commit e6aacba
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/OpenProtocolInterpreter/Communication/Mid0008.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ public override Mid Parse(string package)
return this;
}

public void SetExtraDataFromMid<TMid>(TMid mid) where TMid : Mid, ISubscription
{
SubscriptionMid = mid.Header.Mid.ToString("D4");
WantedRevision = mid.Header.Revision;
ExtraData = mid.Pack(mid);

Check failure on line 71 in src/OpenProtocolInterpreter/Communication/Mid0008.cs

View workflow job for this annotation

GitHub Actions / test

No overload for method 'Pack' takes 1 arguments

Check failure on line 71 in src/OpenProtocolInterpreter/Communication/Mid0008.cs

View workflow job for this annotation

GitHub Actions / test

No overload for method 'Pack' takes 1 arguments

Check failure on line 71 in src/OpenProtocolInterpreter/Communication/Mid0008.cs

View workflow job for this annotation

GitHub Actions / test

No overload for method 'Pack' takes 1 arguments

Check failure on line 71 in src/OpenProtocolInterpreter/Communication/Mid0008.cs

View workflow job for this annotation

GitHub Actions / build

No overload for method 'Pack' takes 1 arguments

Check failure on line 71 in src/OpenProtocolInterpreter/Communication/Mid0008.cs

View workflow job for this annotation

GitHub Actions / build

No overload for method 'Pack' takes 1 arguments

Check failure on line 71 in src/OpenProtocolInterpreter/Communication/Mid0008.cs

View workflow job for this annotation

GitHub Actions / build

No overload for method 'Pack' takes 1 arguments

Check failure on line 71 in src/OpenProtocolInterpreter/Communication/Mid0008.cs

View workflow job for this annotation

GitHub Actions / build

No overload for method 'Pack' takes 1 arguments

Check failure on line 71 in src/OpenProtocolInterpreter/Communication/Mid0008.cs

View workflow job for this annotation

GitHub Actions / build

No overload for method 'Pack' takes 1 arguments

Check failure on line 71 in src/OpenProtocolInterpreter/Communication/Mid0008.cs

View workflow job for this annotation

GitHub Actions / build

No overload for method 'Pack' takes 1 arguments

Check failure on line 71 in src/OpenProtocolInterpreter/Communication/Mid0008.cs

View workflow job for this annotation

GitHub Actions / build

No overload for method 'Pack' takes 1 arguments

Check failure on line 71 in src/OpenProtocolInterpreter/Communication/Mid0008.cs

View workflow job for this annotation

GitHub Actions / build

No overload for method 'Pack' takes 1 arguments

Check failure on line 71 in src/OpenProtocolInterpreter/Communication/Mid0008.cs

View workflow job for this annotation

GitHub Actions / build

No overload for method 'Pack' takes 1 arguments

Check failure on line 71 in src/OpenProtocolInterpreter/Communication/Mid0008.cs

View workflow job for this annotation

GitHub Actions / test

No overload for method 'Pack' takes 1 arguments

Check failure on line 71 in src/OpenProtocolInterpreter/Communication/Mid0008.cs

View workflow job for this annotation

GitHub Actions / test

No overload for method 'Pack' takes 1 arguments

Check failure on line 71 in src/OpenProtocolInterpreter/Communication/Mid0008.cs

View workflow job for this annotation

GitHub Actions / test

No overload for method 'Pack' takes 1 arguments
ExtraDataLength = ExtraData.Length;
}

public static Mid0008 New<TMid>(TMid mid) where TMid : Mid, ISubscription
{
var mid8 = new Mid0008();
mid8.SetExtraDataFromMid(mid);
return mid8;
}

protected override Dictionary<int, List<DataField>> RegisterDatafields()
{
return new Dictionary<int, List<DataField>>()
Expand Down
6 changes: 6 additions & 0 deletions src/OpenProtocolInterpreter/IApplicationDataMessageRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace OpenProtocolInterpreter
{
public interface IApplicationDataMessageRequest
{
}
}
11 changes: 9 additions & 2 deletions src/OpenProtocolInterpreter/MID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ public virtual string Pack()
return header;

var builder = new StringBuilder(header);
builder.Append(PackDataFields());
return builder.ToString();
}

public virtual byte[] PackBytes() => Encoding.ASCII.GetBytes(Pack());

internal string PackDataFields()
{
var builder = new StringBuilder();
int prefixIndex = 1;
var revision = (Header.Revision > 0 ? Header.Revision : 1);
for (int i = 1; i <= revision; i++)
Expand All @@ -68,8 +77,6 @@ public virtual string Pack()
return builder.ToString();
}

public virtual byte[] PackBytes() => Encoding.ASCII.GetBytes(Pack());

protected virtual string Pack(int revision, ref int prefixIndex)
{
if (!RevisionsByFields.TryGetValue(revision, out var dataFields))
Expand Down
57 changes: 57 additions & 0 deletions src/OpenProtocolInterpreter/Tightening/Mid0067.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;

namespace OpenProtocolInterpreter.Tightening
{
/// <summary>
/// This message contains a list of tightening results stored in the controller. The result list is sorted ascendingly on result index, and contains a brief summary of each result.
/// <para><see cref="Communication.Mid0006"/> Application Data Message Request shall be used for fetching this message</para>
/// <para>For full results data, request upload of <see cref="Mid1201"/></para>
/// </summary>
public class Mid0067 : Mid, ITightening, IController, IApplicationDataMessageRequest
{
public const int MID = 67;

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

public List<TighteningSummary> ResultData { get; set; }

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

public Mid0067(Header header) : base(header)
{
}

protected override Dictionary<int, List<DataField>> RegisterDatafields()
{
return new Dictionary<int, List<DataField>>()
{
{
1, new List<DataField>()
{
DataField.Number(DataFields.NumberOfResults, 20, 3, false),
DataField.Volatile(DataFields.ResultData, 23, false)
}
}
};
}

protected enum DataFields
{
NumberOfResults,
ResultData
}
}
}
39 changes: 39 additions & 0 deletions src/OpenProtocolInterpreter/Tightening/TighteningSummary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;

namespace OpenProtocolInterpreter.Tightening
{
public class TighteningSummary
{
public long Index { get; set; }
public DateTime StartTime { get; set; }
public bool Status { get; set; }

public string Pack()
{
return OpenProtocolConvert.ToString('0', 10, PaddingOrientation.LeftPadded, Index) +
OpenProtocolConvert.ToString(StartTime) +
OpenProtocolConvert.ToString(Status);
}

public static TighteningSummary Parse(string value)
{
return new TighteningSummary()
{
Index = OpenProtocolConvert.ToInt64(value.Substring(0, 10)),
StartTime = OpenProtocolConvert.ToDateTime(value.Substring(10, 19)),
Status = OpenProtocolConvert.ToBoolean(value.Substring(29, 1))
};
}

public static IEnumerable<TighteningSummary> ParseAll(string value)
{
const int sectionSize = 30;
for (int i = 0; i < value.Length; i += sectionSize)
{
var section = value.Substring(i, sectionSize);
yield return Parse(section);
}
}
}
}

0 comments on commit e6aacba

Please sign in to comment.