Example #1
0
        public void SsmPacketMultipleReadResponse()
        {
            List <byte> values = new List <byte>();

            values.Add(0x00);
            values.Add(0x09);
            SsmPacket    packet   = SsmPacket.CreateMultipleReadResponse(values);
            IList <byte> expected = SamplePacketData.MultipleReadResponse;

            Utility.CompareArrays("MultipleReadResponse", expected, packet.Data);
            Assert.AreEqual(SsmDirection.FromEcu, packet.Direction, "Direction");
            Assert.AreEqual(SsmCommand.ReadAddressesResponse, packet.Command, "Command");
            Assert.AreEqual(2, packet.Values.Count, "Values.Count");
            Assert.AreEqual((byte)0x00, packet.Values[0], "Values[0]");
            Assert.AreEqual((byte)0x09, packet.Values[1], "Values[1]");
        }
Example #2
0
        public void SsmPacketReadOverlongFromStream()
        {
            IList <int>  addresses = new int[] { 1, 2, 3 };
            SsmPacket    request   = SsmPacket.CreateMultipleReadRequest(addresses);
            IList <byte> values    = new byte[] { 1, 2, 3 };
            SsmPacket    response  = SsmPacket.CreateMultipleReadResponse(values);
            List <byte>  buffer    = new List <byte>(request.Data);

            buffer.AddRange(response.Data);
            buffer.AddRange(new byte[] { 0, 0, 0, 0 });
            MemoryStream stream = new MemoryStream(buffer.ToArray());

            SsmPacket actual = SsmPacketParser.ReadFromStream(stream);

            Utility.CompareArrays("ReadFromStream", response.Data, actual.Data);
        }
Example #3
0
        public void MockEcuStreamMultipleAddressRead()
        {
            MockEcuStream stream    = MockEcuStream.CreateInstance();
            List <int>    addresses = new List <int>();

            addresses.Add(0x000029);
            addresses.Add(0x000020);
            SsmPacket send = SsmPacket.CreateMultipleReadRequest(addresses);

            List <byte> payload = new List <byte>();

            payload.Add(127);
            payload.Add(39);
            SsmPacket receive = SsmPacket.CreateMultipleReadResponse(payload);

            MockEcuStreamTest.SendReceive("Read", stream, send, receive);
        }
Example #4
0
        private void ReadFromStream(bool fragmented)
        {
            IList <int>  addresses = new int[] { 1, 2, 3 };
            SsmPacket    request   = SsmPacket.CreateMultipleReadRequest(addresses);
            IList <byte> values    = new byte[] { 1, 2, 3 };
            SsmPacket    response  = SsmPacket.CreateMultipleReadResponse(values);
            List <byte>  buffer    = new List <byte>(request.Data);

            buffer.AddRange(response.Data);
            MemoryStream stream = new MemoryStream(buffer.ToArray());

            if (fragmented)
            {
                stream = FragmentedStream.GetInstance(stream);
            }

            SsmPacket actual = SsmPacketParser.ReadFromStream(stream);

            Utility.CompareArrays("ReadFromStream", response.Data, actual.Data);
        }
Example #5
0
        private void ReadFromStreamAsync(bool fragmented)
        {
            IList <int>  addresses = new int[] { 1, 2, 3 };
            SsmPacket    request   = SsmPacket.CreateMultipleReadRequest(addresses);
            IList <byte> values    = new byte[] { 1, 2, 3 };
            SsmPacket    response  = SsmPacket.CreateMultipleReadResponse(values);
            List <byte>  buffer    = new List <byte>(request.Data);

            buffer.AddRange(response.Data);
            MemoryStream stream = new MemoryStream(buffer.ToArray());

            if (fragmented)
            {
                stream = FragmentedStream.GetInstance(stream);
            }

            SsmPacketParser parser      = SsmPacketParser.CreateInstance();
            IAsyncResult    asyncResult = parser.BeginReadFromStream(stream, ReadCompleted, parser);

            asyncResult.AsyncWaitHandle.WaitOne();
            Utility.CompareArrays("ReadFromStreamAsync", response.Data, this.packet.Data);
        }