Ejemplo n.º 1
0
        private static void TestBitPacker()
        {
            BitPacker bitPacker = new BitPacker();

            bitPacker.WriteValue(80, 32);
            bitPacker.WriteValue(0x800800, 32);

            Console.WriteLine(bitPacker.ToString());
            bitPacker.OverrideValue(4160749567, 32, 16);
            Console.WriteLine(bitPacker.ToString());
            bitPacker.PushTempInBuffer();
            Console.WriteLine(bitPacker.ToString());
        }
Ejemplo n.º 2
0
        private static void TestCRC()
        {
            // Sender side
            // ============================================================================================
            BitPacker bufferSender = new BitPacker();

            bufferSender.WriteValue(0x39, 6);
            bufferSender.WriteValue(0x2B, 6);
            Console.WriteLine("Data envoyées sans CRC :" + bufferSender.ToString());

            Parameters parameters = CrcStdParams.StandartParameters[CrcAlgorithms.Crc32];
            Crc        crcSender  = new Crc(parameters);

            crcSender.ComputeHash(bufferSender.GetByteBuffer());
            uint value = (uint)CrcHelper.FromBigEndian(crcSender.Hash, crcSender.HashSize);

            bufferSender.AlignToNextWriteByte();
            bufferSender.WriteValue(value, 32);

            /*
             * Console.WriteLine("Data envoyées avec CRC :" + bufferSender.ToString());
             *
             * // Trucage des données pour test du CRC
             * bufferSender = new BitPacking();
             * bufferSender.WriteValue(0x39, BitsRequired(0, 63));
             * bufferSender.WriteValue(0x2B, BitsRequired(0, 63));
             *
             * bufferSender.AlignToNextByte();
             * bufferSender.WriteValue(value, (uint)crcSender.HashSize);
             * bufferSender.PushTempInBuffer();
             * // Console.WriteLine("Valeur du CRC :" + Convert.ToString(value, toBase: 16));
             *
             * Console.WriteLine("=================================================================");
             */
            // Receiver side
            // ============================================================================================
            BitPacker bufferReceiver = BitPacker.FromArray(bufferSender.GetByteBuffer());
            //Console.WriteLine("Réception data avec CRC :" + bufferReceiver.ToString());

            Crc crcReceiver = new Crc(parameters);

            uint crcValue = bufferReceiver.ReadValue(crcReceiver.HashSize, true, bufferReceiver.BitLength - 32);

            Console.WriteLine("Réception data sans CRC :" + bufferReceiver.ToString());

            parameters.Check = crcValue;

            if (crcReceiver.IsRight(bufferReceiver.GetByteBuffer()))
            {
                Console.WriteLine("Paquet accepté !");
            }
            else
            {
                Console.WriteLine("Refused packet !");
            }
        }
Ejemplo n.º 3
0
        private static void Devlog()
        {
            BitPacker bitPacker = new BitPacker();

            bitPacker.WriteValue(80, 7);
            bitPacker.WriteValue(3850, 12);
            bitPacker.WriteValue(750, 10);

            bitPacker.PushTempInBuffer();
            Console.WriteLine(bitPacker.ToString());

            byte[] data = bitPacker.GetByteBuffer();

            Console.WriteLine("Reader Creation : ");
            BitPacker reader = BitPacker.FromArray(data);

            Console.WriteLine(reader.ReadValue(7));
            Console.WriteLine(reader.ReadValue(12));
            Console.WriteLine(reader.ReadValue(10));
        }