static CBUUID MakeFull(byte a, byte b, byte c, byte d) { return(CBUUID.FromBytes(new byte [] { a, b, c, d, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb })); }
public void FullRandomEquals() { var guid = Guid.NewGuid(); Assert.That(CBUUID.FromBytes(guid.ToByteArray()), Is.EqualTo(CBUUID.FromBytes(guid.ToByteArray()))); }
public void Equality_PartialsOfDifferentSizeNotEqual() { #if MONOMAC Assert.That(CBUUID.FromPartial(0x1234), Is.Not.EqualTo( CBUUID.FromBytes(new byte [] { 0x12, 0x34, 0x56, 0x78 }))); #endif }
public void Equality_PartialEqualsFull() { using (var u1 = CBUUID.FromPartial(0x0127)) using (var u2 = MakeFull(0x01, 0x27)) { Assert.True(u1.Equals((object)u2), "Equals-1a"); Assert.True(u1.Equals((NSObject)u2), "Equals-1b"); Assert.True(u1.Equals((CBUUID)u2), "Equals-1b"); Assert.That(u1.GetHashCode(), Is.EqualTo(u2.GetHashCode()), "GetHashCode-1"); } using (var u1 = CBUUID.FromBytes(new byte [] { 0xab, 0xcd })) using (var u2 = MakeFull(0xab, 0xcd)) { Assert.True(u1.Equals((object)u2), "Equals-2a"); Assert.True(u1.Equals((NSObject)u2), "Equals-2b"); Assert.True(u1.Equals((CBUUID)u2), "Equals-2b"); Assert.That(u1.GetHashCode(), Is.EqualTo(u2.GetHashCode()), "GetHashCode-2"); } using (var u1 = CBUUID.FromString("1234")) using (var u2 = CBUUID.FromString("00001234-0000-1000-8000-00805f9b34fb")) { Assert.True(u1.Equals((object)u2), "Equals-3a"); Assert.True(u1.Equals((NSObject)u2), "Equals-3b"); Assert.True(u1.Equals((CBUUID)u2), "Equals-3b"); Assert.That(u1.GetHashCode(), Is.EqualTo(u2.GetHashCode()), "GetHashCode-3"); } #if MONOMAC Assert.That(CBUUID.FromBytes(new byte [] { 0xab, 0xcd, 0xef, 0x12 }), Is.EqualTo(MakeFull(0xab, 0xcd, 0xef, 0x12))); Assert.That(CBUUID.FromString("12345678"), Is.EqualTo(CBUUID.FromString("12345678-0000-1000-8000-00805f9b34fb"))); #endif }
void UpdateScan() { if (_scanners.Count == 0) { _central.StopScan(); } else { HashSet <ServiceUuid> services = null; if (!_scanners.Any(scn => scn.Services == null)) { // all scanners want only specific services, create a union over all services = new HashSet <ServiceUuid>(); foreach (var scn in _scanners) { services.UnionWith(scn.Services); } } _central.ScanForPeripherals(services?.Select(uuid => CBUUID.FromBytes(uuid.Uuid.ToByteArrayBE())).ToArray(), new PeripheralScanningOptions { AllowDuplicatesKey = true, }); } }
public void Equality_PartialsOfDifferentSizeNotEqual() { TestRuntime.AssertSystemVersion(PlatformName.MacOSX, 10, 10, throwIfOtherPlatform: false); #if MONOMAC Assert.That(CBUUID.FromPartial(0x1234), Is.Not.EqualTo( CBUUID.FromBytes(new byte [] { 0x12, 0x34, 0x56, 0x78 }))); #endif }
public void PartialEquals() { var guid = new byte [] { 0xaa, 0xbb }; Assert.That(CBUUID.FromBytes(guid), Is.EqualTo(CBUUID.FromBytes(guid))); // ObjC exception: Data <aabbccdd> does not represent a valid UUID // guid = new byte [] { 0xaa, 0xbb, 0xcc, 0xdd }; // Assert.That (CBUUID.FromBytes (guid), // Is.EqualTo (CBUUID.FromBytes (guid))); Assert.That(CBUUID.FromPartial(0x1234), Is.EqualTo(CBUUID.FromPartial(0x1234))); Assert.That(CBUUID.FromString("1234"), Is.EqualTo(CBUUID.FromBytes(new byte [] { 0x12, 0x34 }))); // ObjC exception: Data <12345678> does not represent a valid UUID // Assert.That (CBUUID.FromString ("12345678"), // Is.EqualTo (CBUUID.FromBytes (new byte [] { 0x12, 0x34, 0x56, 0x78 }))); }
public void Equality_PartialEquals() { var guid = new byte [] { 0xaa, 0xbb }; using (var u1 = CBUUID.FromBytes(guid)) using (var u2 = CBUUID.FromBytes(guid)) { Assert.True(u1.Equals((object)u2), "Equals-1a"); Assert.True(u1.Equals((NSObject)u2), "Equals-1b"); Assert.True(u1.Equals((CBUUID)u2), "Equals-1b"); Assert.That(u1.GetHashCode(), Is.EqualTo(u2.GetHashCode()), "GetHashCode-1"); } using (var u1 = CBUUID.FromPartial(0x1234)) using (var u2 = CBUUID.FromPartial(0x1234)) { Assert.True(u1.Equals((object)u2), "Equals-2a"); Assert.True(u1.Equals((NSObject)u2), "Equals-2b"); Assert.True(u1.Equals((CBUUID)u2), "Equals-2b"); Assert.That(u1.GetHashCode(), Is.EqualTo(u2.GetHashCode()), "GetHashCode-2"); } using (var u1 = CBUUID.FromString("1234")) using (var u2 = CBUUID.FromBytes(new byte [] { 0x12, 0x34 })) { Assert.True(u1.Equals((object)u2), "Equals-3a"); Assert.True(u1.Equals((NSObject)u2), "Equals-3b"); Assert.True(u1.Equals((CBUUID)u2), "Equals-3b"); Assert.That(u1.GetHashCode(), Is.EqualTo(u2.GetHashCode()), "GetHashCode-3"); } #if MONOMAC if (TestRuntime.CheckSystemVersion(PlatformName.MacOSX, 10, 10)) { guid = new byte [] { 0xaa, 0xbb, 0xcc, 0xdd }; Assert.That(CBUUID.FromBytes(guid), Is.EqualTo(CBUUID.FromBytes(guid))); Assert.That(CBUUID.FromString("12345678"), Is.EqualTo(CBUUID.FromBytes(new byte [] { 0x12, 0x34, 0x56, 0x78 }))); } #endif }
public void FullRandomNotEqual() { Assert.That(CBUUID.FromBytes(Guid.NewGuid().ToByteArray()), Is.Not.EqualTo(CBUUID.FromBytes(Guid.NewGuid().ToByteArray()))); }
private static async Task FindAllAsyncImpl(string aqsFilter, List <DeviceInformation> list) { await Task.Run <IReadOnlyCollection <DeviceInformation> >(async() => { if (BluetoothAdapter.Default.Manager.State != CBCentralManagerState.PoweredOn) { stateHandle.WaitOne(); } string[] filterParts = aqsFilter.Split(':'); bool discover = true; Guid service = Guid.Empty; if (filterParts.Length == 2) { switch (filterParts[0]) { case "bluetoothPairing": discover = !bool.Parse(filterParts[1]); break; case "bluetoothService": service = Guid.Parse(filterParts[1]); break; } } //CBPeripheral[] peripherals = _manager.RetrieveConnectedPeripherals(CBUUID.FromBytes(InTheHand.Devices.Bluetooth.GenericAttributeProfile.GattServiceUuids.GenericAttribute.ToByteArray())); /*CBPeripheral[] peripherals = _manager.RetrievePeripheralsWithIdentifiers(null);// new CBUUID[] { CBUUID.FromBytes(InTheHand.Devices.Bluetooth.GenericAttributeProfile.GattServiceUuids.GenericAttribute.ToByteArray()), CBUUID.FromBytes(InTheHand.Devices.Bluetooth.GenericAttributeProfile.GattServiceUuids.GenericAccess.ToByteArray()), CBUUID.FromBytes(InTheHand.Devices.Bluetooth.GenericAttributeProfile.GattServiceUuids.Battery.ToByteArray()) }); * * * foreach (CBPeripheral p in peripherals) * { * _devices.Add(new DeviceInformation(p)); * }*/ //retrievedHandle.WaitOne(); if (discover) { BluetoothAdapter.Default.DiscoveredDevice += Default_DiscoveredDevice; if (service != Guid.Empty) { BluetoothAdapter.Default.Manager.ScanForPeripherals(new CBUUID[] { CBUUID.FromBytes(service.ToByteArray()) }); } else { BluetoothAdapter.Default.Manager.ScanForPeripherals(new CBUUID[] { }); } await Task.Delay(5000); BluetoothAdapter.Default.DiscoveredDevice -= Default_DiscoveredDevice; BluetoothAdapter.Default.Manager.StopScan(); } else { var peripherals = BluetoothAdapter.Default.Manager.RetrieveConnectedPeripherals(CBUUID.FromBytes(service.ToByteArray())); foreach (CBPeripheral p in peripherals) { _devices.Add(new DeviceInformation(p, p.Name)); } } return(_devices.AsReadOnly()); }); }
public static CBUUID ToCBUuid(this Guid guid) { return(CBUUID.FromBytes(guid.ToByteArray())); }