Exemplo n.º 1
0
 internal IrDADeviceInfo(IrDAAddress id, string name, IrDAHints hints, IrDACharacterSet charset)
 {
     this.address = id;
     this.name    = name;
     this.hints   = hints;
     this.charset = charset;
 }
Exemplo n.º 2
0
 public TestHolderIrDADeviceInfo(IrDAAddress address, String name, IrDAHints hints, IrDACharacterSet charset)
 {
     m_address = address;
     m_name    = name;
     m_hints   = hints;
     m_charset = charset;
 }
Exemplo n.º 3
0
		internal IrDADeviceInfo(IrDAAddress id, string name, IrDAHints hints, IrDACharacterSet charset)
		{
			this.address = id;
			this.name = name;
            this.hints = hints;
            this.charset = charset;
		}
Exemplo n.º 4
0
        /// <summary>
        /// Gets the name of the peer device using the specified socket.
        /// </summary>
        /// <param name="irdaSocket">A connected IrDA <c>Socket</c>.</param>
        /// <returns>The name of the remote device.</returns>
        /// -
        /// <remarks>
        /// This finds the name of the device to which the socket is connection,
        /// an exception will occur if the socket is not connected.
        /// </remarks>
        /// -
        /// <exception cref="T:System.ArgumentNullException">
        /// <c>s</c> is null (<c>Nothing</c> in Visual Basic).
        /// </exception>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        /// The remote device is not present in the list of discovered devices.
        /// </exception>
        /// <exception cref="T:System.InvalidOperationException">
        /// The socket is not connected.
        /// </exception>
        public static string GetRemoteMachineName(Socket irdaSocket)
        {
            if (irdaSocket == null)
            {
                throw new ArgumentNullException("irdaSocket", "GetRemoteMachineName requires a valid Socket");
            }
            if (!irdaSocket.Connected)
            {
                throw new InvalidOperationException("The socket must be connected to a device to get the remote machine name.");
            }
            //get remote endpoint
            IrDAEndPoint ep = (IrDAEndPoint)irdaSocket.RemoteEndPoint;
            IrDAAddress  a  = ep.Address;

            //lookup devices and search for match
            IrDADeviceInfo[] idia = DiscoverDevices(10, irdaSocket);

            foreach (IrDADeviceInfo idi in idia)
            {
                if (a == idi.DeviceAddress)
                {
                    return(idi.DeviceName);
                }
            }

            // See unit-test "CheckExceptionThrownByGetRemoteMachineName".
            throw ExceptionFactory.ArgumentOutOfRangeException(null, "No matching device discovered.");
        }
Exemplo n.º 5
0
 internal IrDADeviceInfo(IrDAAddress id, string name, IrDAHints hints, IrDACharacterSet charset)
 {
     DeviceAddress = id;
     DeviceName    = name;
     Hints         = hints;
     CharacterSet  = charset;
 }
Exemplo n.º 6
0
            //----------------
            private void DoTestParseFails(String s)
            {
                IrDAAddress result = IrDAAddress.Parse(s);

                // Expected an Exception
                Assert.Fail("Expected an error from Parse");
            }
Exemplo n.º 7
0
            public void KeepBadEndianBehaviourByteArray()
            {
                IrDAAddress addr = new IrDAAddress(new byte[] { 0x01, 0x02, 0x03, 0x04, });

                Assert.AreEqual(0x04030201, addr.ToInt32());
                Assert.AreEqual(new byte[] { 0x01, 0x02, 0x03, 0x04, }, addr.ToByteArray());
                Assert.AreEqual("04030201", addr.ToString("N"));
            }
Exemplo n.º 8
0
            private void DoTestTryParse(IrDAAddress expected, String s)
            {
                IrDAAddress result;
                bool        success = IrDAAddress.TryParse(s, out result);

                Assert.IsTrue(success, "TryParse failed.");
                Assert.AreEqual(expected, result);
            }
Exemplo n.º 9
0
            public void MutationNotAllowedViaToByte()
            {
                const String addrAsString = "04030201";
                IrDAAddress  addr         = new IrDAAddress(0x04030201);

                Assert.AreEqual(addrAsString, addr.ToString());
                byte[] internalBytes = addr.ToByteArray();
                internalBytes[1] = 0xFF;    // Attempt to mutate the IrDAAddress!!!
                Assert.AreEqual(addrAsString, addr.ToString());
            }
Exemplo n.º 10
0
            public void MutationNotAllowedViaArrayCtor()
            {
                const String addrAsString = "04030201";

                byte[]      bytes = { 0x01, 0x02, 0x03, 0x04 };
                IrDAAddress addr  = new IrDAAddress(bytes);

                Assert.AreEqual(addrAsString, addr.ToString());
                bytes[1] = 0xFF;    // Attempt to mutate the IrDAAddress!!!
                Assert.AreEqual(addrAsString, addr.ToString());
            }
Exemplo n.º 11
0
            private static void DoTestTryParseFails(String s)
            {
                IrDAAddress addr;

                try {
                    bool success = IrDAAddress.TryParse(s, out addr);
                    Assert.IsFalse(success);
                } catch {
                    Assert.Fail("TryParse should never throw an Exception.");
                }
            }
Exemplo n.º 12
0
            //--------------------------------------------------------------
            private void DoTestParse(IrDAAddress expected, String s)
            {
                IrDAAddress result = IrDAAddress.Parse(s);

                Assert.AreEqual(expected, result);
            }
Exemplo n.º 13
0
            public void PCodeAddrZeros()
            {
                IrDAAddress addr = new IrDAAddress(0);

                DoTest("00.00.00.00", addr, FcodePeriods);
            }
Exemplo n.º 14
0
            public void PCodeAddrA()
            {
                IrDAAddress addr = new IrDAAddress(0x01020304);

                DoTest("01.02.03.04", addr, FcodePeriods);
            }
Exemplo n.º 15
0
            public void CCodeAddrZeros()
            {
                IrDAAddress addr = new IrDAAddress(0);

                DoTest("00:00:00:00", addr, FcodeColons);
            }
Exemplo n.º 16
0
            public void CCodeAddrA()
            {
                IrDAAddress addr = new IrDAAddress(0x01020304);

                DoTest("01:02:03:04", addr, FcodeColons);
            }
Exemplo n.º 17
0
            public void NCodeAddrZeros()
            {
                IrDAAddress addr = new IrDAAddress(0);

                DoTest("00000000", addr, FcodePlainNumbers);
            }
Exemplo n.º 18
0
            public void AddrAllOnes()
            {
                IrDAAddress addr = new IrDAAddress(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF });

                DoTest("FFFFFFFF", addr);
            }
Exemplo n.º 19
0
            public void EmptyCodeAddrZeros()
            {
                IrDAAddress addr = new IrDAAddress(0);

                DoTest("00000000", addr, FcodeEmpty);
            }
Exemplo n.º 20
0
            public void AddrB()
            {
                IrDAAddress addr = new IrDAAddress(new byte[] { 0x01, 0x02, 0x03, 0x04 });

                DoTest("04030201", addr);
            }
Exemplo n.º 21
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);
        }
Exemplo n.º 22
0
            public void BadCode()
            {
                IrDAAddress addr = new IrDAAddress(0x01020304);

                DoTest("01020304", addr, FcodeNotExists);
            }
Exemplo n.º 23
0
            public void AddrNone()
            {
                IrDAAddress addr = IrDAAddress.None;

                DoTest("00000000", addr);
            }
Exemplo n.º 24
0
            public void AddrNegativeOne()
            {
                IrDAAddress addr = new IrDAAddress(-1);

                DoTest("FFFFFFFF", addr);
            }
Exemplo n.º 25
0
            public void AddrA()
            {
                IrDAAddress addr = new IrDAAddress(0x01020304);

                DoTest("01020304", addr);
            }
Exemplo n.º 26
0
            public void NCodeAddrA()
            {
                IrDAAddress addr = new IrDAAddress(0x01020304);

                DoTest("01020304", addr, FcodePlainNumbers);
            }
Exemplo n.º 27
0
            public void EmptyCodeAddrA()
            {
                IrDAAddress addr = new IrDAAddress(0x01020304);

                DoTest("01020304", addr, FcodeEmpty);
            }
Exemplo n.º 28
0
            public void AddrZeros()
            {
                IrDAAddress addr = new IrDAAddress(0);

                DoTest("00000000", addr);
            }
Exemplo n.º 29
0
            public void NullCodeAddrA()
            {
                IrDAAddress addr = new IrDAAddress(0x01020304);

                DoTest("01020304", addr, FcodeNull);
            }
Exemplo n.º 30
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);
        }
Exemplo n.º 31
0
            public void NullCodeAddrZeros()
            {
                IrDAAddress addr = new IrDAAddress(0);

                DoTest("00000000", addr, FcodeNull);
            }
Exemplo n.º 32
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 PocketPC
                // 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;
        }