コード例 #1
0
        public static SCR DecodeSCR(byte[] response)
        {
            if (response?.Length != 8)
            {
                return(null);
            }

            var scr = new SCR
            {
                Structure            = (byte)((response[0] & 0xF0) >> 4),
                Spec                 = (byte)(response[0] & 0x0F),
                DataStatusAfterErase = (response[1] & 0x80) == 0x80,
                Security             = (byte)((response[1] & 0x70) >> 4),
                BusWidth             = (BusWidth)(response[1] & 0x0F),
                Spec3                = (response[2] & 0x80) == 0x80,
                ExtendedSecurity     = (byte)((response[2] & 0x78) >> 3),
                Spec4                = (response[2] & 0x04) == 0x04,
                SpecX                = (byte)(((response[2] & 0x03) << 2) + ((response[3] & 0xC0) >> 6)),
                CommandSupport       = (CommandSupport)(response[3] & 0x0F),
                ManufacturerReserved = new byte[4]
            };

            Array.Copy(response, 4, scr.ManufacturerReserved, 0, 4);

            return(scr);
        }
コード例 #2
0
        public static string PrettifySCR(SCR scr)
        {
            if (scr == null)
            {
                return(null);
            }

            var sb = new StringBuilder();

            sb.AppendLine("SecureDigital Device Configuration Register:");

            if (scr.Structure != 0)
            {
                sb.AppendFormat("\tUnknown register version {0}", scr.Structure).AppendLine();
            }

            switch (scr.Spec)
            {
            case 0 when scr.Spec3 == false && scr.Spec4 == false && scr.SpecX == 0:
                sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 1.0x");

                break;

            case 1 when scr.Spec3 == false && scr.Spec4 == false && scr.SpecX == 0:
                sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 1.10");

                break;

            case 2 when scr.Spec3 == false && scr.Spec4 == false && scr.SpecX == 0:
                sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 2.00");

                break;

            case 2 when scr.Spec3 && scr.Spec4 == false && scr.SpecX == 0:
                sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 3.0x");

                break;

            case 2 when scr.Spec3 && scr.Spec4 && scr.SpecX == 0:
                sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 4.xx");

                break;

            case 2 when scr.Spec3:
                switch (scr.SpecX)
                {
                case 1:
                    sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 5.xx");

                    break;

                case 2:
                    sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 6.xx");

                    break;

                case 3:
                    sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 7.xx");

                    break;

                case 4:
                    sb.AppendLine("\tDevice follows SecureDigital Physical Layer Specification version 8.xx");

                    break;
                }

                break;

            default:
                sb.
                AppendFormat("\tDevice follows SecureDigital Physical Layer Specification with unknown version {0}.{1}.{2}.{3}",
                             scr.Spec, scr.Spec3, scr.Spec4, scr.SpecX).AppendLine();

                break;
            }

            switch (scr.Security)
            {
            case 0:
                sb.AppendLine("\tDevice does not support CPRM");

                break;

            case 1:
                sb.AppendLine("\tDevice does not use CPRM");

                break;

            case 2:
                sb.AppendLine("\tDevice uses CPRM according to specification version 1.01");

                break;

            case 3:
                sb.AppendLine("\tDevice uses CPRM according to specification version 2.00");

                break;

            case 4:
                sb.AppendLine("\tDevice uses CPRM according to specification version 3.xx");

                break;

            default:
                sb.AppendFormat("\tDevice uses unknown CPRM specification with code {0}", scr.Security).
                AppendLine();

                break;
            }

            if (scr.BusWidth.HasFlag(BusWidth.OneBit))
            {
                sb.AppendLine("\tDevice supports 1-bit data bus");
            }

            if (scr.BusWidth.HasFlag(BusWidth.FourBit))
            {
                sb.AppendLine("\tDevice supports 4-bit data bus");
            }

            if (scr.ExtendedSecurity != 0)
            {
                sb.AppendLine("\tDevice supports extended security");
            }

            if (scr.CommandSupport.HasFlag(CommandSupport.ExtensionRegisterMultiBlock))
            {
                sb.AppendLine("\tDevice supports extension register multi-block commands");
            }

            if (scr.CommandSupport.HasFlag(CommandSupport.ExtensionRegisterSingleBlock))
            {
                sb.AppendLine("\tDevice supports extension register single-block commands");
            }

            if (scr.CommandSupport.HasFlag(CommandSupport.SetBlockCount))
            {
                sb.AppendLine("\tDevice supports set block count command");
            }

            if (scr.CommandSupport.HasFlag(CommandSupport.SpeedClassControl))
            {
                sb.AppendLine("\tDevice supports speed class control command");
            }

            return(sb.ToString());
        }