public void DelegateDataReceivedSplit()
        {
            using TNCInterface tnc = new TNCInterface();
            Queue <byte[]> qDecodedFrames = new Queue <byte[]>();

            tnc.FrameReceivedEvent += (sender, arg) => qDecodedFrames.Enqueue(arg.Data);

            byte[] dataRec1 = new byte[4] {
                0xC0, 0x50, 0x48, 0x65
            };
            byte[] dataRec2 = new byte[4] {
                0x6C, 0x6C, 0x6F, 0xC0
            };

            tnc.DecodeReceivedData(dataRec1);

            byte[][] decodedFrames = qDecodedFrames.ToArray();

            Assert.AreEqual(0, decodedFrames.Length);

            decodedFrames = tnc.DecodeReceivedData(dataRec2);
            Assert.AreEqual(1, decodedFrames.Length);
            Assert.AreEqual(5, decodedFrames[0].Length);
            Assert.AreEqual("Hello", Encoding.ASCII.GetString(decodedFrames[0]));
        }
        public void DataReceivedSplit()
        {
            using TNCInterface tnc = new TNCInterface();

            byte[] dataRec1 = new byte[4] {
                0xC0, 0x50, 0x48, 0x65
            };
            byte[] dataRec2 = new byte[4] {
                0x6C, 0x6C, 0x6F, 0xC0
            };

            byte[][] decodedFrames = tnc.DecodeReceivedData(dataRec1);
            Assert.AreEqual(0, decodedFrames.Length);

            decodedFrames = tnc.DecodeReceivedData(dataRec2);
            Assert.AreEqual(1, decodedFrames.Length);
            Assert.AreEqual(5, decodedFrames[0].Length);
            Assert.AreEqual("Hello", Encoding.ASCII.GetString(decodedFrames[0]));
        }
        public void DataReceivedAtOncePrefacedMultipleFEND()
        {
            using TNCInterface tnc = new TNCInterface();

            byte[] receivedData = new byte[9] {
                (byte)SpecialCharacters.FEND, (byte)SpecialCharacters.FEND, 0xC0, 0x00, 0x54, 0x45, 0x53, 0x54, 0xC0
            };

            byte[][] decodedFrames = tnc.DecodeReceivedData(receivedData);

            Assert.AreEqual(1, decodedFrames.Length);
            Assert.AreEqual(4, decodedFrames[0].Length);
            Assert.AreEqual("TEST", Encoding.ASCII.GetString(decodedFrames[0]));
        }
        public void DataReceivedAtOnce()
        {
            using TNCInterface tnc = new TNCInterface();

            byte[] receivedData = new byte[7] {
                0xC0, 0x00, 0x54, 0x45, 0x53, 0x54, 0xC0
            };

            byte[][] decodedFrames = tnc.DecodeReceivedData(receivedData);

            Assert.AreEqual(1, decodedFrames.Length);
            Assert.AreEqual(4, decodedFrames[0].Length);
            Assert.AreEqual("TEST", Encoding.ASCII.GetString(decodedFrames[0]));
        }
        public void DataReceivedEscapes()
        {
            using TNCInterface tnc = new TNCInterface();

            byte[] recData = new byte[7] {
                0xC0, 0x00, 0xDB, 0xDC, 0xDB, 0xDD, 0xC0
            };

            byte[][] decodedFrames = tnc.DecodeReceivedData(recData);

            Assert.AreEqual(1, decodedFrames.Length);
            Assert.AreEqual(2, decodedFrames[0].Length);
            Assert.AreEqual((byte)SpecialCharacters.FEND, decodedFrames[0][0]);
            Assert.AreEqual((byte)SpecialCharacters.FESC, decodedFrames[0][1]);
        }
        public void MultipleFramesDataReceivedAtOnce()
        {
            using TNCInterface tnc = new TNCInterface();

            byte[] receivedData = new byte[15] {
                0xC0, 0x00, 0x54, 0x45, 0x53, 0x54, 0xC0, 0xC0, 0x50, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0xC0
            };

            byte[][] decodedFrames = tnc.DecodeReceivedData(receivedData);

            Assert.AreEqual(2, decodedFrames.Length);
            Assert.AreEqual(4, decodedFrames[0].Length);
            Assert.AreEqual("TEST", Encoding.ASCII.GetString(decodedFrames[0]));
            Assert.AreEqual(5, decodedFrames[1].Length);
            Assert.AreEqual("Hello", Encoding.ASCII.GetString(decodedFrames[1]));
        }
        public void DelegateDataReceivedAtOncePrefacedMultipleFEND()
        {
            using TNCInterface tnc = new TNCInterface();
            Queue <byte[]> qDecodedFrames = new Queue <byte[]>();

            tnc.FrameReceivedEvent += (sender, arg) => qDecodedFrames.Enqueue(arg.Data);

            byte[] receivedData = new byte[9] {
                (byte)SpecialCharacters.FEND, (byte)SpecialCharacters.FEND, 0xC0, 0x00, 0x54, 0x45, 0x53, 0x54, 0xC0
            };

            tnc.DecodeReceivedData(receivedData);

            byte[][] decodedFrames = qDecodedFrames.ToArray();

            Assert.AreEqual(1, decodedFrames.Length);
            Assert.AreEqual(4, decodedFrames[0].Length);
            Assert.AreEqual("TEST", Encoding.ASCII.GetString(decodedFrames[0]));
        }
        public void DelegateDataReceivedEscapes()
        {
            using TNCInterface tnc = new TNCInterface();
            Queue <byte[]> qDecodedFrames = new Queue <byte[]>();

            tnc.FrameReceivedEvent += (sender, arg) => qDecodedFrames.Enqueue(arg.Data);

            byte[] recData = new byte[7] {
                0xC0, 0x00, 0xDB, 0xDC, 0xDB, 0xDD, 0xC0
            };

            tnc.DecodeReceivedData(recData);

            byte[][] decodedFrames = qDecodedFrames.ToArray();

            Assert.AreEqual(1, decodedFrames.Length);
            Assert.AreEqual(2, decodedFrames[0].Length);
            Assert.AreEqual((byte)SpecialCharacters.FEND, decodedFrames[0][0]);
            Assert.AreEqual((byte)SpecialCharacters.FESC, decodedFrames[0][1]);
        }
        public void DelegateMultipleFramesDataReceivedAtOnce()
        {
            using TNCInterface tnc = new TNCInterface();
            Queue <byte[]> qDecodedFrames = new Queue <byte[]>();

            tnc.FrameReceivedEvent += (sender, arg) => qDecodedFrames.Enqueue(arg.Data);

            byte[] receivedData = new byte[15] {
                0xC0, 0x00, 0x54, 0x45, 0x53, 0x54, 0xC0, 0xC0, 0x50, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0xC0
            };

            tnc.DecodeReceivedData(receivedData);

            byte[][] decodedFrames = qDecodedFrames.ToArray();

            Assert.AreEqual(2, decodedFrames.Length);
            Assert.AreEqual(4, decodedFrames[0].Length);
            Assert.AreEqual("TEST", Encoding.ASCII.GetString(decodedFrames[0]));
            Assert.AreEqual(5, decodedFrames[1].Length);
            Assert.AreEqual("Hello", Encoding.ASCII.GetString(decodedFrames[1]));
        }