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 }
protected void Initialize() { this._tableSource = new CharacteristicTableSource(); // // when the characteristic is selected in the table, make a request to disover the descriptors for it. this._tableSource.CharacteristicSelected += (object sender, CharacteristicTableSource.CharacteristicSelectedEventArgs e) => { Console.WriteLine("Characteristic: " + e.Characteristic.Name); UIViewController _characteristicDetailScreen = null; if (e.Characteristic.Uuid == CBUUID.FromPartial(0x2A37).ToString()) // heart rate characteristic { _characteristicDetailScreen = new CharacteristicDetailScreen_Hrm(); ((CharacteristicDetailScreen_Hrm)_characteristicDetailScreen).SetDeviceServiceAndCharacteristic(this._connectedDevice, this._currentService, e.Characteristic); } if (_connectedDevice.Name == "TI BLE Sensor Tag") // TI SensorTag device { _characteristicDetailScreen = new CharacteristicDetailScreen_TISensorTag(); ((CharacteristicDetailScreen_TISensorTag)_characteristicDetailScreen).SetDeviceServiceAndCharacteristic(this._connectedDevice, this._currentService, e.Characteristic); } else { _characteristicDetailScreen = new CharacteristicDetailScreen(); ((CharacteristicDetailScreen)_characteristicDetailScreen).SetDeviceServiceAndCharacteristic(this._connectedDevice, this._currentService, e.Characteristic); } this.NavigationController.PushViewController(_characteristicDetailScreen, 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 PartialEqualsFull() { Assert.That(CBUUID.FromPartial(0x0127), Is.EqualTo(MakeFull(0x01, 0x27))); // ObjC exception: Data <abcdef12> does not represent a valid UUID // Assert.That (CBUUID.FromBytes (new byte [] { 0xab, 0xcd, 0xef, 0x12 }), // Is.EqualTo (MakeFull (0xab, 0xcd, 0xef, 0x12))); Assert.That(CBUUID.FromString("1234"), Is.EqualTo(CBUUID.FromString("00001234-0000-1000-8000-00805f9b34fb"))); // ObjC exception: Data <12345678> does not represent a valid UUID // Assert.That (CBUUID.FromString ("12345678"), // Is.EqualTo (CBUUID.FromString ("12345678-0000-1000-8000-00805f9b34fb"))); }
public void SetUp() { // iOS 13 and friends require bluetooth permission if (TestRuntime.CheckXcodeVersion(11, 0)) { TestRuntime.CheckBluetoothPermission(); } //known UUID for a heart monitor, more common, we want to find something and make sure we do not crash heartRateMonitorUUID = CBUUID.FromPartial(0x180D); // Required API is available in macOS 10.8, but it doesn't work (hangs in 10.8-10.9, randomly crashes in 10.10) on the bots. TestRuntime.AssertSystemVersion(PlatformName.MacOSX, 10, 11, throwIfOtherPlatform: false); var e = new AutoResetEvent(false); mgrDelegate = new ManagerDelegate(e); mgr = new CBCentralManager(mgrDelegate, new DispatchQueue("com.xamarin.tests." + TestContext.CurrentContext.Test.Name)); }
static Task <IReadOnlyCollection <BluetoothDevice> > PlatformGetPairedDevices() { #if __IOS__ PairedDeviceHandler deviceHandler = new PairedDeviceHandler(); OnRetrievedPeripherals += deviceHandler.OnRetrievedPeripherals; _manager.RetrieveConnectedPeripherals(CBUUID.FromPartial(0x180F)); return(Task.Run(() => { //deviceHandler.WaitOne(); return deviceHandler.Devices; })); #else return(Task.FromResult((IReadOnlyCollection <BluetoothDevice>) new List <BluetoothDevice>().AsReadOnly())); #endif }
public void Start_old(BleDevice device, BleCharacteristic[] characteristics) { try { if (device == null) { throw new Exception("Could not initialize server without a service description."); } if ((characteristics == null) || (characteristics.Length == 0)) { throw new Exception("Could not initialize server without characteristic descriptions."); } // setup a peripheral manager _PeripheralManager = new CBPeripheralManager(); var uuid = CBUUID.FromPartial(device.GuidValue); System.Diagnostics.Debug.WriteLine(string.Format("*** BleServer.Start - Device Guid: {0}", uuid.Uuid)); _Service = new CBMutableService(uuid, true); _Characteristics = characteristics.Select(ch => new CBMutableCharacteristic(CBUUID.FromPartial(ch.GuidValue), CBCharacteristicProperties.Read, null, CBAttributePermissions.Readable)).ToList(); _Service.Characteristics = _Characteristics.ToArray(); // register services _PeripheralManager.AddService(_Service); _PeripheralManager.AdvertisingStarted += (sender, e) => { if (e.Error != null) { System.Diagnostics.Debug.WriteLine(string.Format("*** BleServer -> Advertising error: {0}", e.Error.Description)); } else { System.Diagnostics.Debug.WriteLine("*** BleServer -> We are advertising."); } }; // advertise services var opt = new StartAdvertisingOptions(); opt.ServicesUUID = new CBUUID[] { _Service.UUID }; _PeripheralManager.StartAdvertising(opt); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(string.Format("*** BleServer.Start - Exception: {0}", ex)); } }
public void SetUp() { // iOS 13 and friends require bluetooth permission if (TestRuntime.CheckXcodeVersion(11, 0)) { TestRuntime.CheckBluetoothPermission(true); } //known UUID for a heart monitor, more common, we want to find something and make sure we do not crash heartRateMonitorUUID = CBUUID.FromPartial(0x180D); // Required API is available in macOS 10.8, but it doesn't work (hangs in 10.8-10.9, randomly crashes in 10.10) on the bots. TestRuntime.AssertSystemVersion(ApplePlatform.MacOSX, 10, 11, throwIfOtherPlatform: false); mgrDelegate = new ManagerDelegate(); mgr = new CBCentralManager(mgrDelegate, new DispatchQueue("com.xamarin.tests." + TestContext.CurrentContext.Test.Name)); if (!mgrDelegate.PoweredOnEvent.WaitOne(TimeSpan.FromSeconds(5))) { Assert.Inconclusive("Bluetooth never turned on."); } }
static Task <IReadOnlyCollection <BluetoothDevice> > PlatformGetPairedDevices() { #if __IOS__ PairedDeviceHandler deviceHandler = new PairedDeviceHandler(); OnRetrievedPeripherals += deviceHandler.OnRetrievedPeripherals; List <BluetoothDevice> devices = new List <BluetoothDevice>(); var periphs = _manager.RetrieveConnectedPeripherals(CBUUID.FromPartial(0x1801)); foreach (var p in periphs) { devices.Add(p); } return(Task.Run(() => { return (IReadOnlyCollection <BluetoothDevice>)devices.AsReadOnly(); })); #else return(Task.FromResult((IReadOnlyCollection <BluetoothDevice>) new List <BluetoothDevice>().AsReadOnly())); #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 PartialsOfDifferentSizeNotEqual() { // ObjC exception: Data <12345678> does not represent a valid UUID Assert.That(CBUUID.FromPartial(0x1234), Is.Not.EqualTo( CBUUID.FromString("12345678-0000-1000-8000-00805f9b34fb"))); }