public void NewFromBytes2() { byte[] packetData = TestPacket2; var p = Ssm2ReadAddressesRequest.NewFromBytes(packetData); Assert.IsInstanceOfType(typeof(Ssm2ReadAddressesRequest), p, "type"); }
public void NewFromBytes1() { byte[] packetData = TestPacket1; var p = Ssm2ReadAddressesRequest.NewFromBytes(packetData); Assert.IsInstanceOfType(typeof(Ssm2WriteAddressResponse), p, "type"); }
public void NotAllPropertiesSet3() { Ssm2ReadAddressesRequest p = new Ssm2ReadAddressesRequest(); p.Destination = Ssm2Device.Engine10; p.Source = Ssm2Device.DiagnosticToolF0; p.Finish(); }
public void NotAllPropertiesSet2() { Ssm2ReadAddressesRequest p = new Ssm2ReadAddressesRequest(); p.Destination = Ssm2Device.Engine10; p.Addresses = new int[] { 0 }; p.Finish(); }
public void NotAllPropertiesSet1() { Ssm2ReadAddressesRequest p = new Ssm2ReadAddressesRequest(); p.Source = Ssm2Device.DiagnosticToolF0; p.Addresses = new int[] { 0 }; p.Finish(); }
/// <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); }
public void ConstructByPropertiesAndModify1() { byte[] packetData = TestPacket1; // will allocate full buffer since number of addresses is unknown Ssm2ReadAddressesRequest p = new Ssm2ReadAddressesRequest(); p.Source = Ssm2Device.DiagnosticToolF0; p.Destination = Ssm2Device.Engine10; p.Addresses = new int[] { 0x123456 }; // should be ok after setting Data Assert.AreEqual(packetData.Length, p.Size, "Size before Construct"); // necessary to create checksum, making packet complete p.Finish(); byte[] actual = p.ToBytesCopy(); for (int i = 0; i < packetData.Length; i++) { Assert.AreEqual(packetData[i], actual[i], "actual[" + i.ToString() + "]"); } 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.ReadAddressesRequestA8, p.Command, "Command"); IList <int> addresses = p.Addresses; Assert.AreEqual(1, addresses.Count, "addrList.Count"); Assert.AreEqual(1, p.AddressesCount, "AddressesCount"); Assert.AreEqual(0x123456, addresses[0], "adr[0]"); // change properties that don't affect packet length p.Source = Ssm2Device.Engine10; p.Destination = Ssm2Device.DiagnosticToolF0; p.Addresses = new[] { 1, 2, 3 }; p.Finish(); Assert.AreEqual(true, p.Check(), "Check2"); Assert.AreEqual(Ssm2Device.DiagnosticToolF0, p.Destination, "Destination2"); Assert.AreEqual(Ssm2Device.Engine10, p.Source, "Source2"); Assert.AreEqual(Ssm2Command.ReadAddressesRequestA8, p.Command, "Command2"); Assert.AreEqual(3, p.AddressesCount, "AddressesCount2"); addresses = p.Addresses; Assert.AreEqual(3, addresses.Count, "addrList.Count2"); Assert.AreEqual(1, addresses[0], "adr2[0]"); Assert.AreEqual(2, addresses[1], "adr2[1]"); Assert.AreEqual(3, addresses[2], "adr2[2]"); }
public void NewFromBytes1() { byte[] packetData = TestPacket1; // Static method NewFromBytes () analyzes packet type, // and returns a specific packet object. // Based on given data in this case we know upfront, // it'll be an read-addresses-request. var p = Ssm2ReadAddressesRequest.NewFromBytes(packetData); Assert.IsInstanceOfType(typeof(Ssm2ReadAddressesRequest), p, "type"); }
public void NewFromBytes1() { byte[] packetData = TestPacket1; var p = (Ssm2InitResponse)Ssm2ReadAddressesRequest.NewFromBytes(packetData); Assert.IsInstanceOfType(typeof(Ssm2InitResponse), p, "type"); Assert.IsInstanceOfType(typeof(Ssm2Packet), p, "base type"); AssertKnownProperties1(p); AssertContent(p, SSMID1, ROMID1, Capabilities1); }
public void ConstructByPropertiesAndModify1() { byte[] packetData = TestPacket1; // will allocate full buffer since number of addresses is unknown Ssm2ReadAddressesRequest p = new Ssm2ReadAddressesRequest (); p.Source = Ssm2Device.DiagnosticToolF0; p.Destination = Ssm2Device.Engine10; p.Addresses = new int[] { 0x123456 }; // should be ok after setting Data Assert.AreEqual (packetData.Length, p.Size, "Size before Construct"); // necessary to create checksum, making packet complete p.Finish (); byte[] actual = p.ToBytesCopy (); for (int i = 0; i < packetData.Length; i++) { Assert.AreEqual (packetData[i], actual[i], "actual[" + i.ToString () + "]"); } 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.ReadAddressesRequestA8, p.Command, "Command"); IList<int> addresses = p.Addresses; Assert.AreEqual (1, addresses.Count, "addrList.Count"); Assert.AreEqual (1, p.AddressesCount, "AddressesCount"); Assert.AreEqual (0x123456, addresses[0], "adr[0]"); // change properties that don't affect packet length p.Source = Ssm2Device.Engine10; p.Destination = Ssm2Device.DiagnosticToolF0; p.Addresses = new[] { 1, 2, 3 }; p.Finish (); Assert.AreEqual (true, p.Check (), "Check2"); Assert.AreEqual (Ssm2Device.DiagnosticToolF0, p.Destination, "Destination2"); Assert.AreEqual (Ssm2Device.Engine10, p.Source, "Source2"); Assert.AreEqual (Ssm2Command.ReadAddressesRequestA8, p.Command, "Command2"); Assert.AreEqual (3, p.AddressesCount, "AddressesCount2"); addresses = p.Addresses; Assert.AreEqual (3, addresses.Count, "addrList.Count2"); Assert.AreEqual (1, addresses[0], "adr2[0]"); Assert.AreEqual (2, addresses[1], "adr2[1]"); Assert.AreEqual (3, addresses[2], "adr2[2]"); }
public void Parse2() { byte[] packetData = TestPacket2; Ssm2ReadAddressesRequest p = new Ssm2ReadAddressesRequest(); p.FromBytes(packetData); 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.ReadAddressesRequestA8, p.Command, "Command"); IList <int> addresses = p.Addresses; Assert.AreEqual(2, addresses.Count, "addrList.Count"); Assert.AreEqual(2, p.AddressesCount, "AddressesCount"); Assert.AreEqual(0x123456, addresses[0], "adr[0]"); Assert.AreEqual(0x1c, addresses[1], "adr[1]"); }
public void IncreaseAddressesCount1() { Ssm2ReadAddressesRequest.MaxAddressesPerPacket = 30; var p = new Ssm2ReadAddressesRequest(Ssm2Device.Engine10, Ssm2Device.DiagnosticToolF0, new int[] { 1, 2, 3, 4, 5, 6 }); // modify p.Addresses = new int[] { 1, 2, 3, 4, 5, 6, 7 }; p.Finish(); // 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.ReadAddressesRequestA8, p.Command, "Command"); IList <int> addresses = p.Addresses; Assert.AreEqual(7, addresses.Count, "addrList.Count"); Assert.AreEqual(7, p.AddressesCount, "AddressesCount"); // Assert.AreEqual (0x123456, addresses[0], "adr[0]"); }
public void ConstructorComplete1() { // Create a ReadAddressesRequest, requesting one address. // This constructor takes all needed information, // allocates optimal buffer size and constructs a complete packet. Ssm2ReadAddressesRequest p = new Ssm2ReadAddressesRequest( Ssm2Device.Engine10, Ssm2Device.DiagnosticToolF0, new[] { 0x123456 } ); // Predetermined packet bytes to compare with. byte[] expected = TestPacket1; // check standard properties Assert.AreEqual(expected.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.ReadAddressesRequestA8, p.Command, "Command"); // check packet type specifics IList <int> addrList = p.Addresses; Assert.AreEqual(1, addrList.Count, "addrList.Count"); Assert.AreEqual(1, p.AddressesCount, "AddressesCount"); Assert.AreEqual(0x123456, addrList[0], "adr[0]"); // take raw packet bytes byte[] buffer = p.ToBytesCopy(); // compare raw packet bytes for (int i = 0; i < expected.Length; i++) { Assert.AreEqual(expected[i], buffer[i], "buffer[" + i.ToString() + "]"); } }
public void ConstructorComplete1() { // Create a ReadAddressesRequest, requesting one address. // This constructor takes all needed information, // allocates optimal buffer size and constructs a complete packet. Ssm2ReadAddressesRequest p = new Ssm2ReadAddressesRequest ( Ssm2Device.Engine10, Ssm2Device.DiagnosticToolF0, new[] { 0x123456 } ); // Predetermined packet bytes to compare with. byte[] expected = TestPacket1; // check standard properties Assert.AreEqual (expected.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.ReadAddressesRequestA8, p.Command, "Command"); // check packet type specifics IList<int> addrList = p.Addresses; Assert.AreEqual (1, addrList.Count, "addrList.Count"); Assert.AreEqual (1, p.AddressesCount, "AddressesCount"); Assert.AreEqual (0x123456, addrList[0], "adr[0]"); // take raw packet bytes byte[] buffer = p.ToBytesCopy (); // compare raw packet bytes for (int i = 0; i < expected.Length; i++) { Assert.AreEqual (expected[i], buffer[i], "buffer[" + i.ToString () + "]"); } }
/// <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; }
public void Parse2() { byte[] packetData = TestPacket2; Ssm2ReadAddressesRequest p = new Ssm2ReadAddressesRequest (); p.FromBytes (packetData); 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.ReadAddressesRequestA8, p.Command, "Command"); IList<int> addresses = p.Addresses; Assert.AreEqual (2, addresses.Count, "addrList.Count"); Assert.AreEqual (2, p.AddressesCount, "AddressesCount"); Assert.AreEqual (0x123456, addresses[0], "adr[0]"); Assert.AreEqual (0x1c, addresses[1], "adr[1]"); }
public void NotAllPropertiesSet3() { Ssm2ReadAddressesRequest p = new Ssm2ReadAddressesRequest (); p.Destination = Ssm2Device.Engine10; p.Source = Ssm2Device.DiagnosticToolF0; p.Finish (); }
public void NotAllPropertiesSet2() { Ssm2ReadAddressesRequest p = new Ssm2ReadAddressesRequest (); p.Destination = Ssm2Device.Engine10; p.Addresses = new int[] { 0 }; p.Finish (); }
public void NotAllPropertiesSet1() { Ssm2ReadAddressesRequest p = new Ssm2ReadAddressesRequest (); p.Source = Ssm2Device.DiagnosticToolF0; p.Addresses = new int[] { 0 }; p.Finish (); }
public void IncreaseAddressesCount1() { Ssm2ReadAddressesRequest.MaxAddressesPerPacket = 30; var p = new Ssm2ReadAddressesRequest (Ssm2Device.Engine10, Ssm2Device.DiagnosticToolF0, new int[] { 1, 2, 3, 4, 5, 6 }); // modify p.Addresses = new int[] { 1, 2, 3, 4, 5, 6, 7 }; p.Finish (); // 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.ReadAddressesRequestA8, p.Command, "Command"); IList<int> addresses = p.Addresses; Assert.AreEqual (7, addresses.Count, "addrList.Count"); Assert.AreEqual (7, p.AddressesCount, "AddressesCount"); // Assert.AreEqual (0x123456, addresses[0], "adr[0]"); }