Esempio n. 1
0
        public void Given_TheAddressIncrementIsIncorrect_When_ParseIsCalled_Then_NullIsReturned()
        {
            List <byte> bytes                  = new List <byte>();
            UInt16      propertyCount          = 5;
            byte        length                 = (byte)(DMPLayer.MinLength + propertyCount);
            UInt16      expectedFlagsAndLength = (UInt16)(0x7 << 12 | length);

            bytes.AddRange(new byte[] { 0x7 << 4, (length) });             // flags and length
            DMPLayerVector expectedVector = DMPLayerVector.VECTOR_DMP_SET_PROPERTY;

            bytes.Add((byte)expectedVector);             // Vector
            byte expectedAddressAndDataType = DMPLayer.AddressTypeAndDataType;

            bytes.Add(expectedAddressAndDataType);

            bytes.AddRange(new byte[] { 0, 0 });                   // first property address
            bytes.AddRange(new byte[] { 0, 42 });                  // address increment
            bytes.AddRange(new byte[] { 0, (byte)propertyCount }); // property count

            var expectedProperties = Enumerable.Range(0, propertyCount).Select(x => (byte)x);

            bytes.Add(0);             // start code
            bytes.AddRange(expectedProperties);

            var dmpLayer = DMPLayer.Parse(bytes.ToArray());

            Assert.Null(dmpLayer);
        }
Esempio n. 2
0
        public static List <byte> GetDMPLayer(IEnumerable <byte> properties)
        {
            List <byte> bytes         = new List <byte>();
            UInt16      propertyCount = (UInt16)properties.Count();
            byte        length        = (byte)(DMPLayer.MinLength + propertyCount);

            bytes.AddRange(new byte[] { 0x7 << 4, (length) });             // flags and length
            DMPLayerVector expectedVector = DMPLayerVector.VECTOR_DMP_SET_PROPERTY;

            bytes.Add((byte)expectedVector);             // Vector
            byte expectedAddressAndDataType = DMPLayer.AddressTypeAndDataType;

            bytes.Add(expectedAddressAndDataType);

            bytes.AddRange(new byte[] { 0, 0 });                         // first property address
            bytes.AddRange(new byte[] { 0, 1 });                         // address increment
            bytes.AddRange(new byte[] { 0, (byte)(propertyCount + 1) }); // property count

            bytes.Add(0);                                                // start code
            bytes.AddRange(properties);

            return(bytes);
        }