public void ConstructAndChangeProps1() { byte[] packetData = TestPacket1; Ssm2ReadBlockRequest p = new Ssm2ReadBlockRequest(); p.Source = Ssm2Device.DiagnosticToolF0; p.Destination = Ssm2Device.Engine10; p.Address = 0x200000; p.DataCount = 128; // should be ok after setting Data but don't depend on it! Assert.AreEqual(packetData.Length, p.Size, "Size before Construct"); p.Finish(); AssertData1(p); // changing some properties now p.DataCount = 129; // needed to calc new checksum p.Finish(); // check Assert.AreEqual(packetData.Length, p.Size, "Size2"); Assert.AreEqual(true, p.Check(), "Check2()"); Assert.AreEqual(Ssm2Device.Engine10, p.Destination, "Destination2"); Assert.AreEqual(Ssm2Device.DiagnosticToolF0, p.Source, "Source2"); Assert.AreEqual(Ssm2Command.ReadBlockRequestA0, p.Command, "Command2"); Assert.AreEqual(0x200000, p.Address, "Address2"); Assert.AreEqual(129, p.DataCount, "DataCount2"); }
public void ConstructAndChangeProps1() { byte[] packetData = TestPacket1; Ssm2ReadBlockRequest p = new Ssm2ReadBlockRequest (); p.Source = Ssm2Device.DiagnosticToolF0; p.Destination = Ssm2Device.Engine10; p.Address = 0x200000; p.DataCount = 128; // should be ok after setting Data but don't depend on it! Assert.AreEqual (packetData.Length, p.Size, "Size before Construct"); p.Finish (); AssertData1 (p); // changing some properties now p.DataCount = 129; // needed to calc new checksum p.Finish (); // check Assert.AreEqual (packetData.Length, p.Size, "Size2"); Assert.AreEqual (true, p.Check (), "Check2()"); Assert.AreEqual (Ssm2Device.Engine10, p.Destination, "Destination2"); Assert.AreEqual (Ssm2Device.DiagnosticToolF0, p.Source, "Source2"); Assert.AreEqual (Ssm2Command.ReadBlockRequestA0, p.Command, "Command2"); Assert.AreEqual (0x200000, p.Address, "Address2"); Assert.AreEqual (129, p.DataCount, "DataCount2"); }
public void Parse1() { byte[] packetData = TestPacket1; Ssm2ReadBlockRequest p = new Ssm2ReadBlockRequest(packetData); p.FromBytes(packetData); AssertData1(p); }
/// <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); }
static void AssertData1(Ssm2ReadBlockRequest p) { byte[] packetData = TestPacket1; Assert.AreEqual(packetData.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.ReadBlockRequestA0, p.Command, "Command"); Assert.AreEqual(0x200000, p.Address, "Address"); Assert.AreEqual(128, p.DataCount, "Data"); byte[] bytes = p.ToBytesCopy(); for (int i = 0; i < packetData.Length; i++) { Assert.AreEqual(packetData[i], bytes[i], "bytes[i]"); } }
public void ConstructAndChangeProps2() { Ssm2ReadBlockRequest p = new Ssm2ReadBlockRequest (); p.Source = Ssm2Device.DiagnosticToolF0; p.Destination = Ssm2Device.Engine10; p.Address = 0x123456; p.DataCount = 1; p.Finish (); Assert.AreEqual (11, p.Size, "Size"); Assert.AreEqual (true, p.Check (), "Check()"); Assert.AreEqual (Ssm2Device.DiagnosticToolF0, p.Source, "Source"); Assert.AreEqual (Ssm2Device.Engine10, p.Destination, "Destination"); Assert.AreEqual (Ssm2Command.ReadBlockRequestA0, p.Command, "Command"); Assert.AreEqual (0x123456, p.Address, "Address"); Assert.AreEqual (1, p.DataCount, "DataCount"); }
public void ConstructAndChangeProps2() { Ssm2ReadBlockRequest p = new Ssm2ReadBlockRequest(); p.Source = Ssm2Device.DiagnosticToolF0; p.Destination = Ssm2Device.Engine10; p.Address = 0x123456; p.DataCount = 1; p.Finish(); Assert.AreEqual(11, p.Size, "Size"); Assert.AreEqual(true, p.Check(), "Check()"); Assert.AreEqual(Ssm2Device.DiagnosticToolF0, p.Source, "Source"); Assert.AreEqual(Ssm2Device.Engine10, p.Destination, "Destination"); Assert.AreEqual(Ssm2Command.ReadBlockRequestA0, p.Command, "Command"); Assert.AreEqual(0x123456, p.Address, "Address"); Assert.AreEqual(1, p.DataCount, "DataCount"); }
static void AssertData1(Ssm2ReadBlockRequest p) { byte[] packetData = TestPacket1; Assert.AreEqual (packetData.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.ReadBlockRequestA0, p.Command, "Command"); Assert.AreEqual (0x200000, p.Address, "Address"); Assert.AreEqual (128, p.DataCount, "Data"); byte[] bytes = p.ToBytesCopy (); for (int i = 0; i < packetData.Length; i++) { Assert.AreEqual (packetData[i], bytes[i], "bytes[i]"); } }
public void Parse1() { byte[] packetData = TestPacket1; Ssm2ReadBlockRequest p = new Ssm2ReadBlockRequest (packetData); p.FromBytes (packetData); AssertData1 (p); }
/// <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; }