Esempio n. 1
0
        public void OPP()
        {
            //Guid uuid = BluetoothService.ObexObjectPush;
            Guid uuid = new Guid(0x1105, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb);

            Assert.AreEqual("ObexObjectPush", BluetoothService.GetName(uuid));
        }
Esempio n. 2
0
        public void VideoDistribution()
        {
            //Guid uuid = BluetoothService.VideoDistribution ;
            Guid uuid = new Guid(0x1305, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb);

            Assert.AreEqual("VideoDistribution", BluetoothService.GetName(uuid));
        }
Esempio n. 3
0
 public void Empty()
 {
     // Should it special-case Empty and return null?
     Assert.AreEqual("Empty",
                     //Assert.IsNull(
                     BluetoothService.GetName(Guid.Empty));
 }
Esempio n. 4
0
        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string temp = string.Empty;

            foreach (var guid in value as Guid[])
            {
                string name = BluetoothService.GetName(guid);
                temp += (string.IsNullOrEmpty(name) ? guid.ToString() : name) + ", ";
            }
            return(temp);
        }
        public static async Task <BluetoothServiceItem> GetBluetoothServiceItemAsync(BluetoothAddress address, Guid service)
        {
            BluetoothServiceItem item = new BluetoothServiceItem();

            item.FriendlyName = BluetoothService.GetName(service);
            item.endPoint     = new BluetoothEndPoint(address, service);
            try
            {
                BluetoothClient client = new BluetoothClient();
                await Task.Factory.FromAsync(client.BeginConnect, client.EndConnect, item.endPoint, null);

                item.peerStream       = client.GetStream();
                item.reader           = new StreamReader(item.peerStream, Encoding.ASCII);
                item.writer           = new StreamWriter(item.peerStream, Encoding.ASCII);
                item.writer.AutoFlush = true;
                return(item);
            }
            catch (Exception) { return(null); }
        }
Esempio n. 6
0
 private void buttonServices_Click(object sender, EventArgs e)
 {
     if (listboxDevices.SelectedItem == null)
     {
         MessageBox.Show("Musisz wybrać urządzenie.", "OSTRZEŻENIE", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
     else
     {
         var selected = (BTDevice)listboxDevices.SelectedItem;
         if (!selected.Paired)
         {
             MessageBox.Show("Musisz sparować urządzenie.", "OSTRZEŻENIE", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             return;
         }
         var    serviceGuids = selected.DeviceInfo.InstalledServices;
         string list         = "Lista serwisow obslugiwanych przez urzadzenie:\n";
         int    counter      = 1;
         foreach (var guid in serviceGuids)
         {
             try
             {
                 var name = BluetoothService.GetName(guid);
                 if (name != null)
                 {
                     list += "\t";
                     list += counter + ". ";
                     list += name;
                     list += "\n";
                     counter++;
                 }
             }
             catch (Exception)
             {
                 continue;
             }
         }
         MessageBox.Show(list, "LISTA SERWISOW", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Esempio n. 7
0
        private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            BluetoothDeviceInfo device = (sender as ListView).SelectedItem as BluetoothDeviceInfo;

            if (device != null)
            {
                if (device.InstalledServices.Length > 0)
                {
                    Task.Factory.StartNew(() =>
                    {
                        Dispatcher.Invoke(new Action(() =>
                        {
                            IsGatheringInformation = true;
                            TextBoxInfo.Clear();
                        }));
                        try
                        {
                            foreach (var guid in device.InstalledServices)
                            {
                                ServiceRecord[] serviceRecords = device.GetServiceRecords(guid);

                                Dispatcher.Invoke(new Action(() =>
                                {
                                    TextBoxInfo.Text += string.Format("=========== Service: {0} ({1}) ==========={2}{2}", BluetoothService.GetName(guid), guid, Environment.NewLine);
                                    foreach (var serviceRecord in serviceRecords)
                                    {
                                        TextBoxInfo.Text += ServiceRecordUtilities.Dump(serviceRecord) + Environment.NewLine;
                                    }
                                }));
                            }
                        }
                        catch { Dispatcher.Invoke(new Action(() => { TextBoxInfo.Text = string.Format("No available information for '{0}'. Try to connect/turn-on the device.", device.DeviceName); })); }
                    }).ContinueWith((Task task) => { Dispatcher.Invoke(new Action(() => { IsGatheringInformation = false; })); });
                }
                else
                {
                    TextBoxInfo.Text = "No installed services.";
                }
            }
        }
Esempio n. 8
0
        public void OPPs16()
        {
            Int16 value = 0x1105;

            Assert.AreEqual("ObexObjectPush", BluetoothService.GetName(value));
        }
Esempio n. 9
0
        public void OPPu32()
        {
            UInt32 value = 0x1105;

            Assert.AreEqual("ObexObjectPush", BluetoothService.GetName(value));
        }
Esempio n. 10
0
        public void NotExists()
        {
            Guid value = new Guid(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);

            Assert.IsNull(BluetoothService.GetName(value));
        }
Esempio n. 11
0
 private static void DumpElement(TextWriter writer, int depth, ServiceElement elem)
 {
     WritePrefix(writer, depth);
     if (elem.ElementType == ElementType.ElementSequence || elem.ElementType == ElementType.ElementAlternative)
     {
         writer.WriteLine("{0}", elem.ElementType);
         foreach (ServiceElement element in elem.GetValueAsElementList())
         {
             DumpElement(writer, depth + 1, element);
         }//for
     }
     else if (elem.ElementType == ElementType.Nil)
     {
         writer.WriteLine("Nil:");
     }
     else if (elem.ElementType == ElementType.TextString)
     {
         DumpString(writer, depth, elem, null);
     }
     else if (elem.ElementType == ElementType.Boolean ||
              elem.ElementType == ElementType.Url)
     {
         // Non-numeric types
         writer.WriteLine("{0}: {1}", elem.ElementType, elem.Value);
     }
     else
     {
         string name      = null;
         string valueText = null;
         if (elem.ElementTypeDescriptor == ElementTypeDescriptor.Uuid)
         {
             if (elem.ElementType == ElementType.Uuid16)
             {
                 name = BluetoothService.GetName((ushort)elem.Value);
             }
             else if (elem.ElementType == ElementType.Uuid32)
             {
                 name = BluetoothService.GetName((uint)elem.Value);
             }
             else
             {
                 Debug.Assert(elem.ElementType == ElementType.Uuid128);
                 name      = BluetoothService.GetName((Guid)elem.Value);
                 valueText = ((Guid)elem.Value).ToString();
             }
         }//if UUID
         if (valueText == null)
         {
             if (elem.ElementTypeDescriptor == ElementTypeDescriptor.Unknown)
             {
                 valueText = "unknown";
             }
             else if (elem.ElementType == ElementType.UInt128 ||
                      elem.ElementType == ElementType.Int128)
             {
                 valueText = BitConverter.ToString((byte[])elem.Value);
             }
             else
             {
                 valueText = string.Format(System.Globalization.CultureInfo.InvariantCulture, "0x{0:X}", elem.Value);
             }
         }
         if (name == null)
         {
             writer.WriteLine("{0}: {1}", elem.ElementType, valueText);
         }
         else
         {
             writer.WriteLine("{0}: {1} -- {2}", elem.ElementType, valueText, name);
         }
     }//else
 }
Esempio n. 12
0
        //--------
        /// <summary>
        /// Attempt to get the name of the protocol,
        /// and optionally it's enum id if we handle it specially.
        /// </summary>
        /// -
        /// <param name="protocolGuid">The input.
        /// </param>
        /// <param name="protoStr">The protocol's name if known, or its
        /// Guid.ToString if not.
        /// We handle some explicitly, and otherwise we see if there's a
        /// matching value in BluetoothService that has its name suffixed "Protocol".
        /// </param>
        /// -
        /// <returns>The id as a <see cref="T:InTheHand.Net.Bluetooth.ServiceRecordUtilities.HackProtocolId"/>.
        /// We handle some explicitly,
        /// otherwise we see if its a UUID16 and convert it automatically,
        /// finally if neither we return <c>zero</c>.
        /// </returns>
        private static HackProtocolId GuidToHackProtocolId(Guid protocolGuid, out string protoStr)
        {
            HackProtocolId?proto = null;

            if (protocolGuid == BluetoothProtocol.BnepProtocol)
            {
                proto = HackProtocolId.Bnep;
                //else if (protocolGuid == BluetoothService.hid......)
                // Missing to test automatic uint16->HackProtocolId covnersion
                //    return HackProtocolId.Hidp;
            }
            else if (protocolGuid == BluetoothProtocol.L2CapProtocol)
            {
                proto = HackProtocolId.L2Cap;
            }
            else if (protocolGuid == BluetoothProtocol.ObexProtocol)
            {
                proto = HackProtocolId.Obex;
            }
            else if (protocolGuid == BluetoothProtocol.RFCommProtocol)
            {
                proto = HackProtocolId.Rfcomm;
            }
            else if (protocolGuid == BluetoothProtocol.SdpProtocol)
            {
                proto = HackProtocolId.Sdp;
            }
            if (proto.HasValue)
            {
                protoStr = proto.ToString();
                return(proto.Value);
            }
            //
            // Slower ways of picking up the rest.
            // Get HackProtocolId and string name separately.
            if (IsUuid16Value(protocolGuid))
            {
                proto = GetAsUuid16Value(protocolGuid);
            }
            else
            {
                proto = 0;
            }
            //
            if (Enum.IsDefined(typeof(HackProtocolId), proto))
            {
                protoStr = Enum_ToStringNameOrHex(proto);
            }
            else
            {
                string       nameAttempt    = BluetoothService.GetName(protocolGuid);
                const string ProtocolSuffix = "Protocol";
                if (nameAttempt != null && nameAttempt.EndsWith(ProtocolSuffix, StringComparison.Ordinal))
                {
                    // Has a known name
                    Debug.Assert(nameAttempt.Length > 0);
                    Debug.Assert(nameAttempt.Length > ProtocolSuffix.Length);
                    // (Two param version required for NETCF).
                    protoStr = nameAttempt.Remove(nameAttempt.Length - ProtocolSuffix.Length, ProtocolSuffix.Length);
                }
                else if (proto != 0)     // Conver the integer to hex
                {
                    protoStr = Enum_ToStringNameOrHex(proto);
                }
                else     // Not a standard Bluetooth value so dump its UUID
                {
                    protoStr = protocolGuid.ToString();
                }
            }
            return(proto.Value);
        }