ToBytesCopy() public method

Returns a copy of the actual packet bytes. May return empty array or less bytes if packet is incomplete. Guaranteed to not return null. Use method Check () before to assure validity.
public ToBytesCopy ( ) : byte[]
return byte[]
Ejemplo n.º 1
0
        static void AssertProperties1(Ssm2Packet p)
        {
            byte[] expectedPacketData = EcuInit1;

            Assert.IsInstanceOfType(typeof(Ssm2InitRequest), p, "type");
            Assert.IsInstanceOfType(typeof(Ssm2Packet), p, "base type");

            Assert.AreEqual(expectedPacketData.Length, p.Size, "Size");
            Assert.AreEqual(true, p.Check(), "Check()");

            Assert.AreEqual(Ssm2Device.Engine10, p.Destination, "Destination");
            Assert.AreEqual(Ssm2Device.DiagnosticToolF0, p.Source, "Source");
            Assert.AreEqual(Ssm2Command.InitRequestBF, p.Command, "Command");

            byte[] bytes = p.ToBytesCopy();
            for (int i = 0; i < expectedPacketData.Length; i++)
            {
                Assert.AreEqual(expectedPacketData[i], bytes[i], "bytes[]");
            }
        }
Ejemplo n.º 2
0
        public void DefaultPacket()
        {
            Ssm2Packet p = new Ssm2Packet();

            Assert.AreEqual(false, p.Check(), "Check");

            // Following tests are very implementation specific
            // and rather for debugging purposes!
            // Real code should not depend on most packet properties
            // except Check(), Capacity, Size.

            // packet is almost empty since no properties haven't been set yet
            Assert.AreEqual(Ssm2Packet.PacketSizeMin, p.Size, "Size");
            // only 1st byte is set to 128, all other bytes are 0,
            // therefore checksum is 128, too.
            Assert.AreEqual(128, p.ChecksumCalculated, "ChecksumCalculated");

            // not useful, just demonstrating that packet is invalid
            byte[] buf = p.ToBytesCopy();

            // generic packet type has minimum size
            Assert.AreEqual(Ssm2Packet.PacketSizeMin, buf.Length, "buf.Length");
        }
Ejemplo n.º 3
0
        static void AssertProperties1(Ssm2Packet p)
        {
            byte[] expectedPacketData = EcuInit1;

            Assert.IsInstanceOfType (typeof(Ssm2InitRequest), p, "type");
            Assert.IsInstanceOfType (typeof(Ssm2Packet), p, "base type");

            Assert.AreEqual (expectedPacketData.Length, p.Size, "Size");
            Assert.AreEqual (true, p.Check (), "Check()");

            Assert.AreEqual (Ssm2Device.Engine10, p.Destination, "Destination");
            Assert.AreEqual (Ssm2Device.DiagnosticToolF0, p.Source, "Source");
            Assert.AreEqual (Ssm2Command.InitRequestBF, p.Command, "Command");

            byte[] bytes = p.ToBytesCopy ();
            for (int i = 0; i < expectedPacketData.Length; i++) {
                Assert.AreEqual (expectedPacketData[i], bytes[i], "bytes[]");
            }
        }