Skip to content

Commit

Permalink
Syntax improvement for datafields
Browse files Browse the repository at this point in the history
  • Loading branch information
Rickedb committed Nov 16, 2023
1 parent 5afd88c commit a90af5f
Show file tree
Hide file tree
Showing 97 changed files with 1,857 additions and 1,776 deletions.
1 change: 0 additions & 1 deletion src/MIDTesters.Core/MultipleIdentifiers/TestMid0150.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public void Mid0150ShouldTruncateIdentifier()

var mid0150 = new Mid0150() { IdentifierData = identifier };
Assert.IsNotNull(mid0150.IdentifierData);
Assert.AreEqual(identifier.Substring(0, 100), mid0150.IdentifierData);
Assert.IsTrue(mid0150.Pack().Length == 120);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/MIDTesters.Core/PLCUserData/TestMid0240.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public void Mid0240ShouldTrucanteUserData()

var mid0240 = new Mid0240() { UserData = userData };
Assert.IsNotNull(mid0240.UserData);
Assert.AreEqual(userData.Substring(0, 200), mid0240.UserData);
Assert.IsTrue(mid0240.Pack().Length == 220);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/MIDTesters.Core/PLCUserData/TestMid0245.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public void Mid0245ShouldTruncateUserData()
var mid0245 = new Mid0245(2) { Offset = 0, UserData = userData };
Assert.IsNotNull(mid0245.Offset);
Assert.IsNotNull(mid0245.UserData);
Assert.AreEqual(userData.Substring(0, 200), mid0245.UserData);
Assert.IsTrue(mid0245.Pack().Length == 223);
}
}
Expand Down
32 changes: 16 additions & 16 deletions src/OpenProtocolInterpreter/Alarm/Mid0071.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@ public class Mid0071 : Mid, IAlarm, IController, IAcknowledgeable<Mid0072>

public string ErrorCode
{
get => GetField(1, (int)DataFields.ErrorCode).Value;
set => GetField(1, (int)DataFields.ErrorCode).SetValue(value);
get => GetField(1, DataFields.ErrorCode).Value;
set => GetField(1, DataFields.ErrorCode).SetValue(value);
}
public bool ControllerReadyStatus
{
get => GetField(1, (int)DataFields.ControllerReadyStatus).GetValue(OpenProtocolConvert.ToBoolean);
set => GetField(1, (int)DataFields.ControllerReadyStatus).SetValue(OpenProtocolConvert.ToString, value);
get => GetField(1, DataFields.ControllerReadyStatus).GetValue(OpenProtocolConvert.ToBoolean);
set => GetField(1, DataFields.ControllerReadyStatus).SetValue(OpenProtocolConvert.ToString, value);
}
public bool ToolReadyStatus
{
get => GetField(1, (int)DataFields.ToolReadyStatus).GetValue(OpenProtocolConvert.ToBoolean);
set => GetField(1, (int)DataFields.ToolReadyStatus).SetValue(OpenProtocolConvert.ToString, value);
get => GetField(1, DataFields.ToolReadyStatus).GetValue(OpenProtocolConvert.ToBoolean);
set => GetField(1, DataFields.ToolReadyStatus).SetValue(OpenProtocolConvert.ToString, value);
}
public DateTime Time
{
get => GetField(1, (int)DataFields.Time).GetValue(OpenProtocolConvert.ToDateTime);
set => GetField(1, (int)DataFields.Time).SetValue(OpenProtocolConvert.ToString, value);
get => GetField(1, DataFields.Time).GetValue(OpenProtocolConvert.ToDateTime);
set => GetField(1, DataFields.Time).SetValue(OpenProtocolConvert.ToString, value);
}
//Rev 2
public string AlarmText
{
get => GetField(2, (int)DataFields.AlarmText).Value;
set => GetField(2, (int)DataFields.AlarmText).SetValue(value);
get => GetField(2, DataFields.AlarmText).Value;
set => GetField(2, DataFields.AlarmText).SetValue(value);
}

public Mid0071() : this(DEFAULT_REVISION)
Expand Down Expand Up @@ -74,16 +74,16 @@ protected override Dictionary<int, List<DataField>> RegisterDatafields()
{
1, new List<DataField>()
{
new((int)DataFields.ErrorCode, 20, 4, ' ', PaddingOrientation.LeftPadded),
new((int)DataFields.ControllerReadyStatus, 26, 1),
new((int)DataFields.ToolReadyStatus, 29, 1, ' '),
new((int)DataFields.Time, 32, 19)
DataField.String(DataFields.ErrorCode, 20, 4, PaddingOrientation.LeftPadded),
DataField.Boolean(DataFields.ControllerReadyStatus, 26),
DataField.Boolean(DataFields.ToolReadyStatus, 29),
DataField.Timestamp(DataFields.Time, 32)
}
},
{
2, new List<DataField>()
{
new((int)DataFields.AlarmText, 54, 50, ' '),
DataField.String(DataFields.AlarmText, 54, 50),
}
}
};
Expand All @@ -102,7 +102,7 @@ private void HandleRevision()
}

int index = errorCodeField.Index + errorCodeField.Size;
for (int i = (int)DataFields.ControllerReadyStatus; i < RevisionsByFields[1].Count; i++)
for (int i = DataFields.ControllerReadyStatus.GetHashCode(); i < RevisionsByFields[1].Count; i++)
{
var field = GetField(1, i);
field.Index = 2 + index;
Expand Down
6 changes: 3 additions & 3 deletions src/OpenProtocolInterpreter/Alarm/Mid0074.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class Mid0074 : Mid, IAlarm, IController, IAcknowledgeable<Mid0075>

public string ErrorCode
{
get => GetField(1, (int)DataFields.ErrorCode).Value;
set => GetField(1, (int)DataFields.ErrorCode).SetValue(value);
get => GetField(1, DataFields.ErrorCode).Value;
set => GetField(1, DataFields.ErrorCode).SetValue(value);
}

public Mid0074() : this(DEFAULT_REVISION)
Expand Down Expand Up @@ -55,7 +55,7 @@ protected override Dictionary<int, List<DataField>> RegisterDatafields()
{
1, new List<DataField>()
{
new((int)DataFields.ErrorCode, 20, 4, ' ', PaddingOrientation.LeftPadded, false)
DataField.String(DataFields.ErrorCode, 20, 4, PaddingOrientation.LeftPadded, false)
}
}
};
Expand Down
38 changes: 19 additions & 19 deletions src/OpenProtocolInterpreter/Alarm/Mid0076.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,33 @@ public class Mid0076 : Mid, IAlarm, IController, IAcknowledgeable<Mid0077>

public bool AlarmStatus
{
get => GetField(1, (int)DataFields.AlarmStatus).GetValue(OpenProtocolConvert.ToBoolean);
set => GetField(1, (int)DataFields.AlarmStatus).SetValue(OpenProtocolConvert.ToString, value);
get => GetField(1, DataFields.AlarmStatus).GetValue(OpenProtocolConvert.ToBoolean);
set => GetField(1, DataFields.AlarmStatus).SetValue(OpenProtocolConvert.ToString, value);
}
public string ErrorCode
{
get => GetField(1, (int)DataFields.ErrorCode).Value;
set => GetField(1, (int)DataFields.ErrorCode).SetValue(value);
get => GetField(1, DataFields.ErrorCode).Value;
set => GetField(1, DataFields.ErrorCode).SetValue(value);
}
public bool ControllerReadyStatus
{
get => GetField(1, (int)DataFields.ControllerReadyStatus).GetValue(OpenProtocolConvert.ToBoolean);
set => GetField(1, (int)DataFields.ControllerReadyStatus).SetValue(OpenProtocolConvert.ToString, value);
get => GetField(1, DataFields.ControllerReadyStatus).GetValue(OpenProtocolConvert.ToBoolean);
set => GetField(1, DataFields.ControllerReadyStatus).SetValue(OpenProtocolConvert.ToString, value);
}
public bool ToolReadyStatus
{
get => GetField(1, (int)DataFields.ToolReadyStatus).GetValue(OpenProtocolConvert.ToBoolean);
set => GetField(1, (int)DataFields.ToolReadyStatus).SetValue(OpenProtocolConvert.ToString, value);
get => GetField(1, DataFields.ToolReadyStatus).GetValue(OpenProtocolConvert.ToBoolean);
set => GetField(1, DataFields.ToolReadyStatus).SetValue(OpenProtocolConvert.ToString, value);
}
public DateTime Time
{
get => GetField(1, (int)DataFields.Time).GetValue(OpenProtocolConvert.ToDateTime);
set => GetField(1, (int)DataFields.Time).SetValue(OpenProtocolConvert.ToString, value);
get => GetField(1, DataFields.Time).GetValue(OpenProtocolConvert.ToDateTime);
set => GetField(1, DataFields.Time).SetValue(OpenProtocolConvert.ToString, value);
}
public ToolHealth ToolHealth
{
get => (ToolHealth)GetField(3, (int)DataFields.ToolHealth).GetValue(OpenProtocolConvert.ToInt32);
set => GetField(3, (int)DataFields.ToolHealth).SetValue(OpenProtocolConvert.ToString, (int)value);
get => (ToolHealth)GetField(3, DataFields.ToolHealth).GetValue(OpenProtocolConvert.ToInt32);
set => GetField(3, DataFields.ToolHealth).SetValue(OpenProtocolConvert.ToString, value);
}

public Mid0076() : this(DEFAULT_REVISION)
Expand Down Expand Up @@ -79,25 +79,25 @@ protected override Dictionary<int, List<DataField>> RegisterDatafields()
{
1, new List<DataField>()
{
new((int)DataFields.AlarmStatus, 20, 1),
new((int)DataFields.ErrorCode, 23, 4, ' ', PaddingOrientation.LeftPadded),
new((int)DataFields.ControllerReadyStatus, 29, 1),
new((int)DataFields.ToolReadyStatus, 32, 1),
new((int)DataFields.Time, 35, 19)
DataField.Boolean(DataFields.AlarmStatus, 20),
DataField.String(DataFields.ErrorCode, 23, 4, PaddingOrientation.LeftPadded),
DataField.Boolean(DataFields.ControllerReadyStatus, 29),
DataField.Boolean(DataFields.ToolReadyStatus, 32),
DataField.Timestamp(DataFields.Time, 35)
}
},
{
3, new List<DataField>()
{
new((int)DataFields.ToolHealth, 57, 1),
DataField.Number(DataFields.ToolHealth, 57, 1),
}
}
};
}

private void HandleRevision()
{
var errorCodeField = GetField(1, (int)DataFields.ErrorCode);
var errorCodeField = GetField(1, DataFields.ErrorCode);
errorCodeField.Size = Header.Revision > 1 ? 5 : 4;

int index = errorCodeField.Index + errorCodeField.Size;
Expand Down
22 changes: 11 additions & 11 deletions src/OpenProtocolInterpreter/ApplicationSelector/Mid0251.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ public class Mid0251 : Mid, IApplicationSelector, IController, IAcknowledgeable<

public int DeviceId
{
get => GetField(1, (int)DataFields.DeviceId).GetValue(OpenProtocolConvert.ToInt32);
set => GetField(1, (int)DataFields.DeviceId).SetValue(OpenProtocolConvert.ToString, value);
get => GetField(1, DataFields.DeviceId).GetValue(OpenProtocolConvert.ToInt32);
set => GetField(1, DataFields.DeviceId).SetValue(OpenProtocolConvert.ToString, value);
}
public int NumberOfSockets
{
get => GetField(1, (int)DataFields.NumberOfSockets).GetValue(OpenProtocolConvert.ToInt32);
set => GetField(1, (int)DataFields.NumberOfSockets).SetValue(OpenProtocolConvert.ToString, value);
get => GetField(1, DataFields.NumberOfSockets).GetValue(OpenProtocolConvert.ToInt32);
set => GetField(1, DataFields.NumberOfSockets).SetValue(OpenProtocolConvert.ToString, value);
}
public List<bool> SocketStatus { get; set; }

Expand All @@ -46,18 +46,18 @@ public Mid0251(Header header) : base(header)

public override string Pack()
{
GetField(1, (int)DataFields.SocketStatus).Size = NumberOfSockets;
GetField(1, (int)DataFields.SocketStatus).Value = PackSocketStatus();
GetField(1, DataFields.SocketStatus).Size = NumberOfSockets;
GetField(1, DataFields.SocketStatus).Value = PackSocketStatus();
return base.Pack();
}

public override Mid Parse(string package)
{
Header = ProcessHeader(package);

GetField(1, (int)DataFields.SocketStatus).Size = Header.Length - 30;
GetField(1, DataFields.SocketStatus).Size = Header.Length - 30;
ProcessDataFields(package);
SocketStatus = ParseSocketStatus(GetField(1, (int)DataFields.SocketStatus).Value);
SocketStatus = ParseSocketStatus(GetField(1, DataFields.SocketStatus).Value);
return this;
}

Expand Down Expand Up @@ -86,9 +86,9 @@ protected override Dictionary<int, List<DataField>> RegisterDatafields()
{
1, new List<DataField>()
{
new((int)DataFields.DeviceId, 20, 2, '0', PaddingOrientation.LeftPadded),
new((int)DataFields.NumberOfSockets, 24, 2, '0', PaddingOrientation.LeftPadded),
new((int)DataFields.SocketStatus, 28, 0)
DataField.Number(DataFields.DeviceId, 20, 2),
DataField.Number(DataFields.NumberOfSockets, 24, 2),
DataField.Volatile(DataFields.SocketStatus, 28)
}
}
};
Expand Down
12 changes: 6 additions & 6 deletions src/OpenProtocolInterpreter/ApplicationSelector/Mid0254.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class Mid0254 : Mid, IApplicationSelector, IIntegrator, IAcceptableComman

public int DeviceId
{
get => GetField(1, (int)DataFields.DeviceId).GetValue(OpenProtocolConvert.ToInt32);
set => GetField(1, (int)DataFields.DeviceId).SetValue(OpenProtocolConvert.ToString, value);
get => GetField(1, DataFields.DeviceId).GetValue(OpenProtocolConvert.ToInt32);
set => GetField(1, DataFields.DeviceId).SetValue(OpenProtocolConvert.ToString, value);
}
public List<LightCommand> GreenLights { get; set; }

Expand All @@ -47,14 +47,14 @@ public Mid0254(Header header) : base(header)

public override string Pack()
{
GetField(1, (int)DataFields.GreenLightCommand).Value = PackGreenLights();
GetField(1, DataFields.GreenLightCommand).Value = PackGreenLights();
return base.Pack();
}

public override Mid Parse(string package)
{
base.Parse(package);
GreenLights = ParseGreenLights(GetField(1, (int)DataFields.GreenLightCommand).Value).ToList();
GreenLights = ParseGreenLights(GetField(1, DataFields.GreenLightCommand).Value).ToList();
return this;
}

Expand Down Expand Up @@ -83,8 +83,8 @@ protected override Dictionary<int, List<DataField>> RegisterDatafields()
{
1, new List<DataField>()
{
new((int)DataFields.DeviceId, 20, 2, '0', PaddingOrientation.LeftPadded),
new((int)DataFields.GreenLightCommand, 24, 8)
DataField.Number(DataFields.DeviceId, 20, 2),
new(DataFields.GreenLightCommand, 24, 8)
}
}
};
Expand Down
14 changes: 7 additions & 7 deletions src/OpenProtocolInterpreter/ApplicationSelector/Mid0255.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public class Mid0255 : Mid, IApplicationSelector, IIntegrator, IAcceptableComman

public int DeviceId
{
get => GetField(1, (int)DataFields.DeviceId).GetValue(OpenProtocolConvert.ToInt32);
set => GetField(1, (int)DataFields.DeviceId).SetValue(OpenProtocolConvert.ToString, value);
get => GetField(1, DataFields.DeviceId).GetValue(OpenProtocolConvert.ToInt32);
set => GetField(1, DataFields.DeviceId).SetValue(OpenProtocolConvert.ToString, value);
}
public List<LightCommand> RedLights { get; set; }

Expand All @@ -46,22 +46,22 @@ public Mid0255(Header header) : base(header)

public override string Pack()
{
GetField(1, (int)DataFields.RedLightCommand).Value = PackRedLights();
GetField(1, DataFields.RedLightCommand).Value = PackRedLights();
return base.Pack();
}

public override Mid Parse(string package)
{
base.Parse(package);
RedLights = ParseRedLights(GetField(1, (int)DataFields.RedLightCommand).Value);
RedLights = ParseRedLights(GetField(1, DataFields.RedLightCommand).Value);
return this;
}

protected virtual string PackRedLights()
{
var builder = new StringBuilder(RedLights.Count);
foreach (var e in RedLights)
builder.Append(OpenProtocolConvert.ToString((int)e));
builder.Append(OpenProtocolConvert.ToString(e));

return builder.ToString();
}
Expand All @@ -82,8 +82,8 @@ protected override Dictionary<int, List<DataField>> RegisterDatafields()
{
1, new List<DataField>()
{
new((int)DataFields.DeviceId, 20, 2, '0', PaddingOrientation.LeftPadded),
new((int)DataFields.RedLightCommand, 24, 8)
DataField.Number(DataFields.DeviceId, 20, 2),
new(DataFields.RedLightCommand, 24, 8)
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class Mid0262 : Mid, IApplicationToolLocationSystem, IController, IAcknow

public string ToolTagId
{
get => GetField(1,(int)DataFields.ToolTagId).Value;
set => GetField(1,(int)DataFields.ToolTagId).SetValue(value);
get => GetField(1, DataFields.ToolTagId).Value;
set => GetField(1, DataFields.ToolTagId).SetValue(value);
}

public Mid0262() : base(MID, DEFAULT_REVISION)
Expand All @@ -35,7 +35,7 @@ protected override Dictionary<int, List<DataField>> RegisterDatafields()
{
1, new List<DataField>()
{
new((int)DataFields.ToolTagId, 20, 8)
DataField.String(DataFields.ToolTagId, 20, 8)
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public class Mid0265 : Mid, IApplicationToolLocationSystem, IIntegrator, IAccept

public string ToolTagId
{
get => GetField(1,(int)DataFields.ToolTagId).Value;
set => GetField(1,(int)DataFields.ToolTagId).SetValue(value);
get => GetField(1, DataFields.ToolTagId).Value;
set => GetField(1, DataFields.ToolTagId).SetValue(value);
}
public ToolStatus ToolStatus
{
get => (ToolStatus)GetField(1,(int)DataFields.ToolStatus).GetValue(OpenProtocolConvert.ToInt32);
set => GetField(1,(int)DataFields.ToolStatus).SetValue(OpenProtocolConvert.ToString, (int)value);
get => (ToolStatus)GetField(1, DataFields.ToolStatus).GetValue(OpenProtocolConvert.ToInt32);
set => GetField(1, DataFields.ToolStatus).SetValue(OpenProtocolConvert.ToString, value);
}

public Mid0265() : this(new Header()
Expand All @@ -31,7 +31,7 @@ public Mid0265() : this(new Header()
Revision = DEFAULT_REVISION
})
{

}

public Mid0265(Header header) : base(header)
Expand All @@ -46,8 +46,8 @@ protected override Dictionary<int, List<DataField>> RegisterDatafields()
{
1, new List<DataField>()
{
new((int)DataFields.ToolTagId, 20, 8),
new((int)DataFields.ToolStatus, 30, 2, '0', PaddingOrientation.LeftPadded)
DataField.String(DataFields.ToolTagId, 20, 8),
DataField.Number(DataFields.ToolStatus, 30, 2)
}
}
};
Expand Down
Loading

0 comments on commit a90af5f

Please sign in to comment.