Esempio n. 1
0
        public void AddHeader(ref byte[] buffer)
        {
            // Add Function Code
            UsefulMethods.InsertElementArray(ref buffer, 0, FunctionCode);

            // Add Application Control
            UsefulMethods.InsertElementArray(ref buffer, 0, ApplicationControl);
        }
Esempio n. 2
0
        private static byte[] InsertBytes(byte[] buffer, ushort data)
        {
            byte lsb = (byte)(data & 0xFF);
            byte hsb = (byte)((data >> 8) & 0xFF);

            UsefulMethods.InsertElementArray(ref buffer, 0, hsb);
            UsefulMethods.InsertElementArray(ref buffer, 0, lsb);
            return(buffer);
        }
Esempio n. 3
0
        public void serialize(ref byte[] buffer)
        {
            // Add Header
            byte header = 0;

            header |= (byte)(FIN << 7);
            header |= (byte)(FIR << 6);
            header |= seq;
            UsefulMethods.InsertElementArray(ref buffer, 0, header);
        }
Esempio n. 4
0
        private UInt16 GetInts(ref byte[] buffer)
        {
            if (buffer == null || buffer.Length == 0)
            {
                return(0);
            }
            byte lsb    = UsefulMethods.RemoveHeader(ref buffer, 0);
            byte hsb    = UsefulMethods.RemoveHeader(ref buffer, 0);
            var  merged = (UInt16)((hsb << 8) + lsb);

            return(merged);
        }
Esempio n. 5
0
        public void deserialize(ref byte[] buffer)
        {
            if (buffer == null || buffer.Length == 0)
            {
                return;
            }
            // Extract Header
            ApplicationControl = UsefulMethods.RemoveHeader(ref buffer, 0);
            FunctionCode       = UsefulMethods.RemoveHeader(ref buffer, 0);

            // Set the data
            ApplicationData = buffer;
        }
Esempio n. 6
0
        public void deserialize(ref byte[] buffer)
        {
            if (buffer == null || buffer.Length == 0)
            {
                return;
            }
            // Extract Header
            var transHeader = UsefulMethods.RemoveHeader(ref buffer, 0);

            seq = (byte)(transHeader & 0x3F);
            FIR = (byte)((transHeader >> 6) & 0x01);
            FIN = (byte)((transHeader >> 7) & 0x01);

            TransportData = buffer;
        }
Esempio n. 7
0
        public void AddHeader(ref byte[] buffer)
        {
            // Add Crc
            UInt16 Crc = GetCRC(ref buffer);

            buffer = InsertBytes(buffer, Crc);

            // Add src and dest
            buffer = InsertBytes(buffer, source);
            buffer = InsertBytes(buffer, destination);

            // Add Control byte
            UsefulMethods.InsertElementArray(ref buffer, 0, controlByte);

            // Add Length
            length = (byte)(buffer.Count()); // yet to add the start bytes but remove the CRC bytes
            UsefulMethods.InsertElementArray(ref buffer, 0, length);

            // Add Start Bytes
            startBytes = 0x6405;
            buffer     = InsertBytes(buffer, startBytes);
        }
Esempio n. 8
0
        public void deserialize(ref byte[] buffer)
        {
            // Extract Start bytes
            startBytes = GetInts(ref buffer);

            // Extract length
            length = UsefulMethods.RemoveHeader(ref buffer, 0);

            // Extract Control byte
            controlByte = UsefulMethods.RemoveHeader(ref buffer, 0);

            // Process Control byte
            ProcessControlByte(controlByte);

            // Extract destination
            destination = GetInts(ref buffer);

            //Extract Source
            source = GetInts(ref buffer);

            // Extract crc
            crc = GetInts(ref buffer);

            // Verify crc
            bool verify = ValidateCRC(ref buffer, crc);

            if (verify)
            {
                Console.WriteLine("verified data");
            }

            else
            {
                return;
            }
        }