fix(ab-transport): harden Task 7 codecs (read status, 32-bit start instance, empty-More, size range)
This commit is contained in:
@@ -29,6 +29,9 @@ public static class ConnectionManagerServices
|
||||
|
||||
public static byte[] ForwardOpen(ForwardOpenParams p)
|
||||
{
|
||||
if (p.ConnectionSize < 1 || p.ConnectionSize > (p.Large ? 0xFFFF : 0x1FF))
|
||||
throw new ArgumentOutOfRangeException(nameof(p), p.ConnectionSize,
|
||||
p.Large ? "Large connection size must be 1..65535." : "Regular connection size must be 1..511.");
|
||||
var connPath = new CipWriter().Bytes(p.Route).Bytes(CipPath.MessageRouter).ToArray();
|
||||
var w = new CipWriter().U8(p.Large ? (byte)0x5B : (byte)0x54).U8(2).Bytes(CipPath.ConnectionManager)
|
||||
.U8(PriorityTick).U8(TimeoutTicks)
|
||||
|
||||
@@ -29,6 +29,8 @@ public static class LogixServices
|
||||
|
||||
public static (ushort TypeCode, ushort? StructHandle, ReadOnlyMemory<byte> Data) ParseReadReply(CipReply reply)
|
||||
{
|
||||
if (reply.GeneralStatus is not (0x00 or 0x06))
|
||||
throw new AbTransportException(reply.Status, $"Read failed: general 0x{reply.GeneralStatus:X2}.");
|
||||
var r = new CipReader(reply.Data.Span);
|
||||
var type = r.U16();
|
||||
ushort? handle = type == LogixTypeCode.Struct ? r.U16() : null;
|
||||
|
||||
@@ -16,7 +16,10 @@ public static class SymbolObjectServices
|
||||
var a = Encoding.ASCII.GetBytes(programName.StartsWith("Program:", StringComparison.Ordinal) ? programName : "Program:" + programName);
|
||||
path.U8(0x91).U8((byte)a.Length).Bytes(a).PadToEven();
|
||||
}
|
||||
path.U8(0x20).U8(0x6B).U8(0x25).U8(0).U16((ushort)startInstance);
|
||||
path.U8(0x20).U8(0x6B);
|
||||
// 16-bit instance segment even for small values (libplctag's form, see capture); 32-bit above 0xFFFF.
|
||||
if (startInstance <= 0xFFFF) path.U8(0x25).U8(0).U16((ushort)startInstance);
|
||||
else path.U8(0x26).U8(0).U32(startInstance);
|
||||
var p = path.ToArray();
|
||||
return new CipWriter().U8(0x55).U8((byte)(p.Length / 2)).Bytes(p)
|
||||
.U16(4).U16(2).U16(7).U16(8).U16(1).ToArray();
|
||||
@@ -39,6 +42,9 @@ public static class SymbolObjectServices
|
||||
var nameLen = r.U16();
|
||||
r.Bytes(nameLen);
|
||||
}
|
||||
return (span.ToArray(), last, reply.GeneralStatus == 0x06);
|
||||
var more = reply.GeneralStatus == 0x06;
|
||||
if (more && span.IsEmpty)
|
||||
throw new AbTransportException(AbStatus.BadReply, "Symbol listing reported more data but returned no entries.");
|
||||
return (span.ToArray(), last, more);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user