Esempio n. 1
0
        public static string PrettifyLevel1VersionTuple(Level1VersionTuple tuple)
        {
            if (tuple?.Code != TupleCodes.CISTPL_VERS_1)
            {
                return(null);
            }

            var sb = new StringBuilder();

            sb.AppendLine("PCMCIA Level 1 Version / Product Information Tuple:");

            sb.AppendFormat("\tCard indicates compliance with PC Card Standard Release {0}.{1}", tuple.MajorVersion,
                            tuple.MinorVersion).AppendLine();

            if (string.IsNullOrEmpty(tuple.Manufacturer))
            {
                sb.AppendLine("\tNo manufacturer information string.");
            }
            else
            {
                sb.AppendFormat("\tManufacturer: {0}", tuple.Manufacturer).AppendLine();
            }

            if (string.IsNullOrEmpty(tuple.Product))
            {
                sb.AppendLine("\tNo product name string.");
            }
            else
            {
                sb.AppendFormat("\tProduct name: {0}", tuple.Product).AppendLine();
            }

            if (tuple.AdditionalInformation == null ||
                tuple.AdditionalInformation.Length == 0)
            {
                sb.AppendLine("\tNo additional information.");
            }
            else
            {
                sb.AppendLine("\tAdditional information:");

                foreach (string info in tuple.AdditionalInformation.Where(info => !string.IsNullOrEmpty(info)))
                {
                    sb.AppendFormat("\t\t{0}", info).AppendLine();
                }
            }

            return(sb.ToString());
        }
Esempio n. 2
0
        public static Level1VersionTuple DecodeLevel1VersionTuple(byte[] data)
        {
            if (data == null)
            {
                return(null);
            }

            if (data.Length < 4)
            {
                return(null);
            }

            List <byte>   buffer       = new List <byte>();
            List <string> strings      = null;
            bool          firstString  = false;
            bool          secondString = false;

            var tuple = new Level1VersionTuple
            {
                Code         = (TupleCodes)data[0],
                Link         = data[1],
                MajorVersion = data[2],
                MinorVersion = data[3]
            };

            for (int position = 4; position < data.Length; position++)
            {
                if (data[position] == 0xFF)
                {
                    break;
                }

                buffer.Add(data[position]);

                if (data[position] != 0x00)
                {
                    continue;
                }

                if (!firstString)
                {
                    tuple.Manufacturer = StringHandlers.CToString(buffer.ToArray());
                    buffer             = new List <byte>();
                    firstString        = true;

                    continue;
                }

                // TODO: Check this
                if (!secondString)
                {
                    tuple.Product = StringHandlers.CToString(buffer.ToArray());
                    buffer        = new List <byte>();
                    firstString   = true;

                    continue;
                }

                if (strings == null)
                {
                    strings = new List <string>();
                }

                strings.Add(StringHandlers.CToString(buffer.ToArray()));
                buffer = new List <byte>();
            }

            if (strings != null)
            {
                tuple.AdditionalInformation = strings.ToArray();
            }

            return(tuple);
        }