public void Oee_LoadPrologPattern_WithoutMask() { var sPattern = new BytePattern_v1 { Bytes = "55 3? ?2", }; var element = new OperatingEnvironmentElement(); var pattern = element.LoadBytePattern(sPattern); Assert.AreEqual(new byte[] { 0x55, 0x30, 0x02 }, pattern.Bytes); Assert.AreEqual(new byte[] { 0xFF, 0xF0, 0x0F }, pattern.Mask); }
public MaskedPattern?LoadMaskedPattern(BytePattern_v1 sPattern) { List <byte> bytes; List <byte> mask; if (sPattern.Bytes == null) { return(null); } if (sPattern.Mask == null) { bytes = new List <byte>(); mask = new List <byte>(); int shift = 4; int bb = 0; int mm = 0; for (int i = 0; i < sPattern.Bytes.Length; ++i) { char c = sPattern.Bytes[i]; if (BytePattern.TryParseHexDigit(c, out byte b)) { bb |= (b << shift); mm |= (0x0F << shift); shift -= 4; if (shift < 0) { bytes.Add((byte)bb); mask.Add((byte)mm); shift = 4; bb = mm = 0; } } else if (c == '?' || c == '.') { shift -= 4; if (shift < 0) { bytes.Add((byte)bb); mask.Add((byte)mm); shift = 4; bb = mm = 0; } } } Debug.Assert(bytes.Count == mask.Count); } else { bytes = BytePattern.FromHexBytes(sPattern.Bytes); mask = BytePattern.FromHexBytes(sPattern.Mask); } if (bytes.Count == 0) { return(null); } return(new MaskedPattern { Bytes = bytes.ToArray(), Mask = mask.ToArray() }); }
public BytePattern LoadBytePattern(BytePattern_v1 sPattern) { List <byte> bytes = null; List <byte> mask = null; if (sPattern.Bytes == null) { return(null); } if (sPattern.Mask == null) { bytes = new List <byte>(); mask = new List <byte>(); int shift = 4; int bb = 0; int mm = 0; for (int i = 0; i < sPattern.Bytes.Length; ++i) { char c = sPattern.Bytes[i]; byte b; if (BytePattern.TryParseHexDigit(c, out b)) { bb = bb | (b << shift); mm = mm | (0x0F << shift); shift -= 4; if (shift < 0) { bytes.Add((byte)bb); mask.Add((byte)mm); shift = 4; bb = mm = 0; } } else if (c == '?' || c == '.') { shift -= 4; if (shift < 0) { bytes.Add((byte)bb); mask.Add((byte)mm); shift = 4; bb = mm = 0; } } } Debug.Assert(bytes.Count == mask.Count); } else { bytes = LoadHexPattern(sPattern.Bytes); mask = LoadHexPattern(sPattern.Mask); } if (bytes.Count == 0) { return(null); } else { return new BytePattern { Bytes = bytes.ToArray(), Mask = mask.ToArray() } }; }
public BytePattern LoadBytePattern(BytePattern_v1 sPattern) { List<byte> bytes = null; List<byte> mask = null; if (sPattern.Bytes == null) return null; if (sPattern.Mask == null) { bytes = new List<byte>(); mask = new List<byte>(); int shift = 4; int bb = 0; int mm = 0; for (int i = 0; i < sPattern.Bytes.Length; ++i) { char c = sPattern.Bytes[i]; byte b; if (BytePattern.TryParseHexDigit(c, out b)) { bb = bb | (b << shift); mm = mm | (0x0F << shift); shift -= 4; if (shift < 0) { bytes.Add((byte)bb); mask.Add((byte)mm); shift = 4; bb = mm = 0; } } else if (c == '?' || c == '.') { shift -= 4; if (shift < 0) { bytes.Add((byte)bb); mask.Add((byte)mm); shift = 4; bb = mm = 0; } } } Debug.Assert(bytes.Count == mask.Count); } else { bytes = LoadHexPattern(sPattern.Bytes); mask = LoadHexPattern(sPattern.Mask); } if (bytes.Count == 0) return null; else return new BytePattern { Bytes = bytes.ToArray(), Mask = mask.ToArray() }; }