Init response packet. This packet type is usually created by control unit and sent to the tester. Packet consists of: 5 byte header + 3 SSMID + 5 ROMID + X capability bytes + 1 checksum. Capability bytes length is not constant, usually 32, 48 or 96 bytes seen so far.
Inheritance: Ssm2Packet
Esempio n. 1
0
        public void Construct1()
        {
            var p = new Ssm2InitResponse(Ssm2Device.DiagnosticToolF0, Ssm2Device.Engine10, SSMID1, ROMID1, Capabilities1);

            AssertKnownProperties1(p);
            AssertContent(p, SSMID1, ROMID1, Capabilities1);
        }
Esempio n. 2
0
        public void SetCapabilities247()
        {
            var p = new Ssm2InitResponse();

            // MaxCapabilities length to fit in a packet is 246
            p.SetCapabilities(new byte[247]);
        }
Esempio n. 3
0
        public void Construct1()
        {
            var p = new Ssm2InitResponse (Ssm2Device.DiagnosticToolF0, Ssm2Device.Engine10, SSMID1, ROMID1, Capabilities1);

            AssertKnownProperties1 (p);
            AssertContent (p, SSMID1, ROMID1, Capabilities1);
        }
Esempio n. 4
0
        static void AssertContent(Ssm2InitResponse packet, byte[] ssmidExpected, byte[] romidExpected, byte[] capabilitesExpected)
        {
            Assert.AreEqual(true, packet.Check(), "Check()");
            Assert.AreEqual(Ssm2Command.InitResponseFF, packet.Command, "Command");

            byte[] ssmID = packet.GetSsmID();
            Assert.AreEqual(3, ssmID.Length, "ssmID.Length");
            for (int i = 0; i < ssmID.Length; i++)
            {
                Assert.AreEqual(ssmidExpected[i], ssmID[i], "ssmID");
            }

            // array implements IList<T>
            IList <byte> ssmIDlist = packet.GetSsmID();

            for (int i = 0; i < ssmIDlist.Count; i++)
            {
                Assert.AreEqual(ssmidExpected[i], ssmIDlist[i], "ssmID IList<byte>");
            }

            byte[] romID = packet.GetRomID();
            Assert.AreEqual(5, romID.Length, "romID.Length");
            for (int i = 0; i < romID.Length; i++)
            {
                Assert.AreEqual(romidExpected[i], romID[i], "romID");
            }

            Assert.AreEqual(capabilitesExpected.Length, packet.CapabilitiesLength, "CapabilitiesLength");
            byte[] capabilities = packet.GetCapabilities();
            Assert.AreEqual(capabilitesExpected.Length, capabilities.Length, "capabilities.Length");
            for (int i = 0; i < capabilities.Length; i++)
            {
                Assert.AreEqual(capabilitesExpected[i], capabilities[i], "capabilities");
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Returns a specific Ssm2Packet type based on given content.
        /// Does not validate the packet, so manually call the Check method afterwards!
        /// </summary>
        /// <param name="bytes">
        /// A <see cref="System.Byte[]"/> containing the packet.
        /// The packet must start at index 0 though the array may be larger than needed.
        /// </param>
        /// <returns>
        /// A <see cref="Ssm2Packet"/> subclass or null if the packet type could not be recognized.
        /// </returns>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        public static Ssm2Packet NewFromBytes(byte[] bytes)
        {
            if (bytes == null)
            {
                throw new ArgumentNullException();
            }
            // check generic minimum size in order to get command byte
            if (bytes.Length < PacketSizeMin)
            {
                throw new ArgumentOutOfRangeException("bytes.Length < Minimum (6)");
            }

            Ssm2Packet p;

            // Read type directly from command byte (5th byte).
            // Each derived class constructor checks its requirements.
            switch ((Ssm2Command)bytes[(int)Ssm2PacketIndex.Command])
            {
            case Ssm2Command.ReadAddressesRequestA8:
                p = new Ssm2ReadAddressesRequest(bytes);
                break;

            case Ssm2Command.ReadAddressesResponseE8:
                p = new Ssm2ReadAddressesResponse(bytes);
                break;

            case Ssm2Command.WriteAddressRequestB8:
                p = new Ssm2WriteAddressRequest(bytes);
                break;

            case Ssm2Command.WriteAddressResponseF8:
                p = new Ssm2WriteAddressResponse(bytes);
                break;

            case Ssm2Command.InitRequestBF:
                p = new Ssm2InitRequest(bytes);
                break;

            case Ssm2Command.InitResponseFF:
                p = new Ssm2InitResponse(bytes);
                break;

            case Ssm2Command.ReadBlockRequestA0:
                p = new Ssm2ReadBlockRequest(bytes);
                break;

            case Ssm2Command.ReadBlockResponseE0:
                p = new Ssm2ReadBlockResponse(bytes);
                break;

            default:
                return(null);
            }
            p.FromBytes(bytes);
            return(p);
        }
Esempio n. 6
0
        public void Parse1()
        {
            byte[] packetData = TestPacket1;
            var    p          = new Ssm2InitResponse();

            p.FromBytes(packetData);

            AssertKnownProperties1(p);
            AssertContent(p, SSMID1, ROMID1, Capabilities1);
        }
Esempio n. 7
0
        static void AssertKnownProperties1(Ssm2InitResponse p)
        {
            byte[] bytes = p.ToBytesCopy();

            Assert.AreEqual(bytes.Length, p.Size, "Size");

            Assert.AreEqual(true, p.Check(), "Check()");
            Assert.AreEqual(0x1f, p.ChecksumCalculated, "ChecksumCalculated");

            Assert.AreEqual(Ssm2Device.DiagnosticToolF0, p.Destination, "Destination");
            Assert.AreEqual(Ssm2Device.Engine10, p.Source, "Source");
        }
Esempio n. 8
0
        public void Parse1()
        {
            byte[] packetData = TestPacket1;
            var p = new Ssm2InitResponse ();
            p.FromBytes (packetData);

            AssertKnownProperties1 (p);
            AssertContent (p, SSMID1, ROMID1, Capabilities1);
        }
Esempio n. 9
0
 public void SetRomID6()
 {
     var p = new Ssm2InitResponse ();
     p.SetRomID (new byte[6]);
 }
Esempio n. 10
0
        public void SetCapabilitiesNull()
        {
            var p = new Ssm2InitResponse();

            p.SetCapabilities(null);
        }
Esempio n. 11
0
 public void SetSsmID3()
 {
     var p = new Ssm2InitResponse ();
     p.SetSsmID (new List<byte> (3).ToArray ());
 }
Esempio n. 12
0
 public void SetCapabilitiesNull()
 {
     var p = new Ssm2InitResponse ();
     p.SetCapabilities (null);
 }
Esempio n. 13
0
        public void SetRomID6()
        {
            var p = new Ssm2InitResponse();

            p.SetRomID(new byte[6]);
        }
Esempio n. 14
0
        public void SetSsmID2()
        {
            var p = new Ssm2InitResponse();

            p.SetSsmID(new byte[2]);
        }
Esempio n. 15
0
 public void SetSsmID4()
 {
     var p = new Ssm2InitResponse ();
     p.SetSsmID (new byte[4]);
 }
Esempio n. 16
0
 public void SetSsmIDNull()
 {
     var p = new Ssm2InitResponse ();
     p.SetSsmID (null);
 }
Esempio n. 17
0
        static void AssertKnownProperties1(Ssm2InitResponse p)
        {
            byte[] bytes = p.ToBytesCopy ();

            Assert.AreEqual (bytes.Length, p.Size, "Size");

            Assert.AreEqual (true, p.Check (), "Check()");
            Assert.AreEqual (0x1f, p.ChecksumCalculated, "ChecksumCalculated");

            Assert.AreEqual (Ssm2Device.DiagnosticToolF0, p.Destination, "Destination");
            Assert.AreEqual (Ssm2Device.Engine10, p.Source, "Source");
        }
Esempio n. 18
0
        static void AssertContent(Ssm2InitResponse packet, byte[] ssmidExpected, byte[] romidExpected, byte[] capabilitesExpected)
        {
            Assert.AreEqual (true, packet.Check (), "Check()");
            Assert.AreEqual (Ssm2Command.InitResponseFF, packet.Command, "Command");

            byte[] ssmID = packet.GetSsmID ();
            Assert.AreEqual (3, ssmID.Length, "ssmID.Length");
            for (int i = 0; i < ssmID.Length; i++) {
                Assert.AreEqual (ssmidExpected[i], ssmID[i], "ssmID");
            }

            // array implements IList<T>
            IList<byte> ssmIDlist = packet.GetSsmID ();
            for (int i = 0; i < ssmIDlist.Count; i++) {
                Assert.AreEqual (ssmidExpected[i], ssmIDlist[i], "ssmID IList<byte>");
            }

            byte[] romID = packet.GetRomID ();
            Assert.AreEqual (5, romID.Length, "romID.Length");
            for (int i = 0; i < romID.Length; i++) {
                Assert.AreEqual (romidExpected[i], romID[i], "romID");
            }

            Assert.AreEqual (capabilitesExpected.Length, packet.CapabilitiesLength, "CapabilitiesLength");
            byte[] capabilities = packet.GetCapabilities ();
            Assert.AreEqual (capabilitesExpected.Length, capabilities.Length, "capabilities.Length");
            for (int i = 0; i < capabilities.Length; i++) {
                Assert.AreEqual (capabilitesExpected[i], capabilities[i], "capabilities");
            }
        }
Esempio n. 19
0
        public void SetSsmIDNull()
        {
            var p = new Ssm2InitResponse();

            p.SetSsmID(null);
        }
Esempio n. 20
0
        public void SetSsmID3()
        {
            var p = new Ssm2InitResponse();

            p.SetSsmID(new List <byte> (3).ToArray());
        }
Esempio n. 21
0
        /// <summary>
        /// Returns a specific Ssm2Packet type based on given content.
        /// Does not validate the packet, so manually call the Check method afterwards!
        /// </summary>
        /// <param name="bytes">
        /// A <see cref="System.Byte[]"/> containing the packet.
        /// The packet must start at index 0 though the array may be larger than needed.
        /// </param>
        /// <returns>
        /// A <see cref="Ssm2Packet"/> subclass or null if the packet type could not be recognized.
        /// </returns>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        public static Ssm2Packet NewFromBytes(byte[] bytes)
        {
            if (bytes == null)
                throw new ArgumentNullException ();
            // check generic minimum size in order to get command byte
            if (bytes.Length < PacketSizeMin)
                throw new ArgumentOutOfRangeException ("bytes.Length < Minimum (6)");

            Ssm2Packet p;
            // Read type directly from command byte (5th byte).
            // Each derived class constructor checks its requirements.
            switch ((Ssm2Command)bytes[(int)Ssm2PacketIndex.Command]) {
            case Ssm2Command.ReadAddressesRequestA8:
                p = new Ssm2ReadAddressesRequest (bytes);
                break;
            case Ssm2Command.ReadAddressesResponseE8:
                p = new Ssm2ReadAddressesResponse (bytes);
                break;
            case Ssm2Command.WriteAddressRequestB8:
                p = new Ssm2WriteAddressRequest (bytes);
                break;
            case Ssm2Command.WriteAddressResponseF8:
                p = new Ssm2WriteAddressResponse (bytes);
                break;
            case Ssm2Command.InitRequestBF:
                p = new Ssm2InitRequest (bytes);
                break;
            case Ssm2Command.InitResponseFF:
                p = new Ssm2InitResponse (bytes);
                break;
            case Ssm2Command.ReadBlockRequestA0:
                p = new Ssm2ReadBlockRequest (bytes);
                break;
            case Ssm2Command.ReadBlockResponseE0:
                p = new Ssm2ReadBlockResponse (bytes);
                break;
            default:
                return null;
            }
            p.FromBytes (bytes);
            return p;
        }
Esempio n. 22
0
 public void SetCapabilities247()
 {
     var p = new Ssm2InitResponse ();
     // MaxCapabilities length to fit in a packet is 246
     p.SetCapabilities (new byte[247]);
 }