Exemple #1
0
        private byte[] CRC(bt msg, bool badcrc)
        {
            byte data_s;

            data_s = 4;
            int    len;
            ushort crc;

            ////////////////////////////////////
            //CRC
            len        = 3 + data_s;
            crc        = 0xFFFF;
            buffer_out = StructureToByteArray(msg);

            for (int pos = 0; pos < len; pos++)
            {
                crc ^= buffer_out[pos];    // XOR byte into least sig. byte of crc

                for (int i = 8; i != 0; i--)
                {                  // Loop over each bit
                    if ((crc & 0x0001) != 0)
                    {              // If the LSB is set
                        crc >>= 1; // Shift right and XOR 0xA001
                        crc  ^= 0xA001;
                    }
                    else                            // Else LSB is not set  checkBoxBadCRC1
                    {
                        crc >>= 1;                  // Just shift right
                    }
                }
            }
            if (badcrc)
            {
                inject_failure1 = true;
            }
            if (!badcrc)
            {
                inject_failure1 = false;
            }



            if (!inject_failure1)
            {
                buffer_out[len + 0] = (byte)(crc & 0xFF);
                buffer_out[len + 1] = (byte)((crc >> 8) & 0xFF);
                len = len + 2;
            }
            else
            {
                buffer_out[len + 0] = 0;
                buffer_out[len + 1] = 0;
                len = len + 2;
            }
            ///////////   end of CRC  ///////////////
            return(buffer_out);
        }
Exemple #2
0
        byte[] StructureToByteArray(bt obj)
        {
            int len = Marshal.SizeOf(obj);

            byte[] arr = new byte[len];

            IntPtr ptr = Marshal.AllocHGlobal(len);

            Marshal.StructureToPtr(obj, ptr, true);

            Marshal.Copy(ptr, arr, 0, len);

            Marshal.FreeHGlobal(ptr);

            return(arr);
        }
Exemple #3
0
 : dsl is BankingFree <A> .BankTransactions bt?GetBankTransactions(bt, bank)
     : dsl is BankingFree <A> .Accounts ac?Accounts(ac, bank)