internal IrDADeviceInfo(IrDAAddress id, string name, IrDAHints hints, IrDACharacterSet charset)
		{
			this.address = id;
			this.name = name;
            this.hints = hints;
            this.charset = charset;
		}
Exemple #2
0
 internal IrDADeviceInfo(IrDAAddress id, string name, IrDAHints hints, IrDACharacterSet charset)
 {
     this.address = id;
     this.name    = name;
     this.hints   = hints;
     this.charset = charset;
 }
Exemple #3
0
 public TestHolderIrDADeviceInfo(IrDAAddress address, String name, IrDAHints hints, IrDACharacterSet charset)
 {
     m_address = address;
     m_name    = name;
     m_hints   = hints;
     m_charset = charset;
 }
Exemple #4
0
 internal IrDADeviceInfo(IrDAAddress id, string name, IrDAHints hints, IrDACharacterSet charset)
 {
     DeviceAddress = id;
     DeviceName    = name;
     Hints         = hints;
     CharacterSet  = charset;
 }
	// Constructor.
	internal IrDADeviceInfo(byte[] data, int posn)
			{
				deviceID = new byte [4];
				deviceID[0] = data[posn];
				deviceID[1] = data[posn + 1];
				deviceID[2] = data[posn + 2];
				deviceID[3] = data[posn + 3];
				int offset = posn + 4;
				StringBuilder builder = new StringBuilder();
				while(offset < (posn + 26) && data[offset] != 0)
				{
					builder.Append((char)(data[offset]));
					++offset;
				}
				deviceName = builder.ToString();
				hints = (IrDAHints)(data[posn + 26] | (data[posn + 27] << 8));
				characterSet = (IrDACharacterSet)(data[posn + 28]);
			}
Exemple #6
0
        // Constructor.
        internal IrDADeviceInfo(byte[] data, int posn)
        {
            deviceID    = new byte [4];
            deviceID[0] = data[posn];
            deviceID[1] = data[posn + 1];
            deviceID[2] = data[posn + 2];
            deviceID[3] = data[posn + 3];
            int           offset  = posn + 4;
            StringBuilder builder = new StringBuilder();

            while (offset < (posn + 26) && data[offset] != 0)
            {
                builder.Append((char)(data[offset]));
                ++offset;
            }
            deviceName   = builder.ToString();
            hints        = (IrDAHints)(data[posn + 26] | (data[posn + 27] << 8));
            characterSet = (IrDACharacterSet)(data[posn + 28]);
        }
Exemple #7
0
        public static IrDADeviceInfo[] ParseDeviceList(byte[] buffer)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            const int BytesInAnInt32 = 4;

            if (buffer.Length < BytesInAnInt32)
            {
                throw new ArgumentException("DEVICE_LIST buffer must be at least four bytes long.");
            }
            //
            int count = BitConverter.ToInt32(buffer, 0);

            //create array for results
            IrDADeviceInfo[] idia       = new IrDADeviceInfo[count];
            const int        devInfoLen = 29;

            //We could check that the buffer is big enough to suit its 'count' value.
            //If this ever happened currently we would just fail with IndexOutOfRangeException
            //int expectedLength = BytesInAnInt32 + count * devInfoLen;
            //if (expectedLength > buffer.Length) {
            //    throw new ArgumentException("Buffer is smaller than the count of items requires.");
            //}

            for (int iDev = 0; iDev < count; iDev++)
            {
                byte[] id = new byte[4];
                Buffer.BlockCopy(buffer, 4 + (iDev * devInfoLen), id, 0, 4);
                IrDAAddress devid = new IrDAAddress(id);

                //hints
                IrDAHints hints = (IrDAHints)BitConverter.ToInt16(buffer, 30 + (iDev * devInfoLen));
                //charset
                IrDACharacterSet charset = (IrDACharacterSet)buffer[32 + (iDev * devInfoLen)];

                //name
                Encoding e = null;
                switch (charset)
                {
                case IrDACharacterSet.ASCII:
                    e = Encoding.ASCII;
                    break;

                case IrDACharacterSet.Unicode:
                    e = Encoding.Unicode;
                    break;

                default:
                    e = Encoding.GetEncoding(28590 + (int)charset);
                    break;
                }
                string name      = e.GetString(buffer, 8 + (iDev * devInfoLen), 22);
                int    nullIndex = name.IndexOf('\0');
                //trim nulls
                if (nullIndex > -1)
                {
                    name = name.Substring(0, nullIndex);
                }
#if NETCF
                // PPC doesn't fill the charset field! :-(  We'll attempt
                // to detect the Unicode encoding, but not the ISO-8859-X ones:
                // as their strings will display at least partially -- dropping
                // the high chars, but also because those encodings are not
                // really supported by CF anyway.
                if (Environment.OSVersion.Platform == PlatformID.WinCE)
                {
                    // This assert is valid, but very annoying when running the
                    // unit-tests so we'll remove it for now.
                    // System.Diagnostics.Debug.Assert(charset == 0, "should charset==0 as field unset on CE");
                    try {
                        e = Encoding.Unicode;
                        string nameGuessUnicode = e.GetString(buffer, 8 + (iDev * devInfoLen), 22);
                        //trim nulls
                        int nullIndexGU = nameGuessUnicode.IndexOf('\0');
                        if (nullIndexGU > -1)
                        {
                            nameGuessUnicode = nameGuessUnicode.Substring(0, nullIndexGU);
                        }
                        // If more sense was made of the bytes as Unicode, then return
                        // that string.
                        // e.g. a unicode string "abc" is 61-00-62-00-63-00 which
                        // ASCII will see as "A" and Unicode as "ABC"
                        if (nameGuessUnicode.Length > name.Length)
                        {
                            name = nameGuessUnicode;
                        }
                    } catch { }
                }
#endif

                idia[iDev] = new IrDADeviceInfo(devid, name, hints, charset);
            }

            return(idia);
        }
Exemple #8
0
        public static IrDADeviceInfo[] ParseDeviceList(byte[] buffer)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            const int BytesInAnInt32 = 4;

            if (buffer.Length < BytesInAnInt32)
            {
                throw new ArgumentException("DEVICE_LIST buffer must be at least four bytes long.");
            }
            //
            int count = BitConverter.ToInt32(buffer, 0);

            //create array for results
            IrDADeviceInfo[] idia       = new IrDADeviceInfo[count];
            const int        devInfoLen = 29;

            //We could check that the buffer is big enough to suit its 'count' value.
            //If this ever happened currently we would just fail with IndexOutOfRangeException
            //int expectedLength = BytesInAnInt32 + count * devInfoLen;
            //if (expectedLength > buffer.Length) {
            //    throw new ArgumentException("Buffer is smaller than the count of items requires.");
            //}

            for (int iDev = 0; iDev < count; iDev++)
            {
                byte[] id = new byte[4];
                Buffer.BlockCopy(buffer, 4 + (iDev * devInfoLen), id, 0, 4);
                IrDAAddress devid = new IrDAAddress(id);

                //hints
                IrDAHints hints = (IrDAHints)BitConverter.ToInt16(buffer, 30 + (iDev * devInfoLen));
                //charset
                IrDACharacterSet charset = (IrDACharacterSet)buffer[32 + (iDev * devInfoLen)];

                //name
                Encoding e = Encoding.ASCII;
                switch (charset)
                {
                case IrDACharacterSet.ASCII:
                    e = Encoding.ASCII;
                    break;

                case IrDACharacterSet.Unicode:
                    e = Encoding.Unicode;
                    break;

                default:
                    e = Encoding.GetEncoding(28590 + (int)charset);
                    break;
                }

                string name      = e.GetString(buffer, 8 + (iDev * devInfoLen), 22);
                int    nullIndex = name.IndexOf('\0');
                // trim nulls
                if (nullIndex > -1)
                {
                    name = name.Substring(0, nullIndex);
                }

                idia[iDev] = new IrDADeviceInfo(devid, name, hints, charset);
            }

            return(idia);
        }
Exemple #9
0
 public TestHolderIrDADeviceInfo(Int32 address, String name, IrDAHints hints, IrDACharacterSet charset)
     : this(new IrDAAddress(address), name, hints, charset)
 {
 }