Init request packet. Does not have specific properties. This packet type is usually created by the tester and sent to the car control unit. (Packet always consists of 6 bytes: 5 byte header + 1 checksum. Typically for engine it is {0x80, 0x10, 0xF0, 0x01, 0xBF, 0x40} )
상속: Ssm2Packet
예제 #1
0
        public void CreateByConstructor()
        {
            // Only 2 standard properties/arguments to specify for this type of packet.
            Ssm2InitRequest p = new Ssm2InitRequest(Ssm2Device.Engine10, Ssm2Device.DiagnosticToolF0);

            AssertProperties1(p);
        }
예제 #2
0
        public void CreateByProperties()
        {
            // Ssm2InitRequest p = new Ssm2InitRequest ();
            // p.Destination = Ssm2Device.Engine10;
            // p.Source = Ssm2Device.DiagnosticToolF0;

            // same effect, using object initializer syntax:
            Ssm2InitRequest p = new Ssm2InitRequest {
                Destination = Ssm2Device.Engine10, Source = Ssm2Device.DiagnosticToolF0
            };

            // Important: packet is still invalid at this point!

            // don't depend on Size yet even though it is correct for this type
            // Assert.AreEqual (packetData.Length, p.Size, "Size");
            // No checksum yet so check will fail.
            Assert.AreEqual(false, p.Check(), "Check()");

            // Important: as with default constructor
            // the object does not know when all properties have been set.
            // This call will calculate the checksum, making packet complete.
            p.Finish();
            // packet is now complete

            AssertProperties1(p);
        }
예제 #3
0
        public void CreateByConstructor()
        {
            // Only 2 standard properties/arguments to specify for this type of packet.
            Ssm2InitRequest p = new Ssm2InitRequest (Ssm2Device.Engine10, Ssm2Device.DiagnosticToolF0);

            AssertProperties1 (p);
        }
예제 #4
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);
        }
예제 #5
0
        public void NewFromBytesBase()
        {
            // same results as casting to specific type (Ssm2InitRequest)
            // sufficient to use base type here since this packet type has no specific data
            var p = Ssm2InitRequest.NewFromBytes(EcuInit1);

            // object reference gets type Ssm2Packet

            AssertProperties1(p);
        }
예제 #6
0
        public void FromBytes()
        {
            byte[] packetData = EcuInit1;
            // inefficient for parsing, since constructor allocates a buffer
            Ssm2InitRequest p = new Ssm2InitRequest ();
            // take given buffer, discarding previous implicit buffer
            p.FromBytes (packetData);

            AssertProperties1 (p);
        }
예제 #7
0
        public void FromBytes()
        {
            byte[] packetData = EcuInit1;
            // inefficient for parsing, since constructor allocates a buffer
            Ssm2InitRequest p = new Ssm2InitRequest();

            // take given buffer, discarding previous implicit buffer
            p.FromBytes(packetData);

            AssertProperties1(p);
        }
예제 #8
0
        public void NewFromBytes()
        {
            byte[] packetData = EcuInit1;
            // best for parsing as it does not allocate anything
            Ssm2InitRequest p = (Ssm2InitRequest)Ssm2Packet.NewFromBytes(packetData);

            // Same static method can also be accessed like this:
            // Ssm2InitRequest.NewFromBytes (...)

            AssertProperties1(p);
        }
예제 #9
0
        public void CreateByProperties()
        {
            // Ssm2InitRequest p = new Ssm2InitRequest ();
            // p.Destination = Ssm2Device.Engine10;
            // p.Source = Ssm2Device.DiagnosticToolF0;

            // same effect, using object initializer syntax:
            Ssm2InitRequest p = new Ssm2InitRequest { Destination = Ssm2Device.Engine10, Source = Ssm2Device.DiagnosticToolF0 };
            // Important: packet is still invalid at this point!

            // don't depend on Size yet even though it is correct for this type
            // Assert.AreEqual (packetData.Length, p.Size, "Size");
            // No checksum yet so check will fail.
            Assert.AreEqual (false, p.Check (), "Check()");

            // Important: as with default constructor
            // the object does not know when all properties have been set.
            // This call will calculate the checksum, making packet complete.
            p.Finish ();
            // packet is now complete

            AssertProperties1 (p);
        }
예제 #10
0
파일: Ssm2Packet.cs 프로젝트: src0x/LibSSM2
        /// <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;
        }