コード例 #1
0
ファイル: Adapter.cs プロジェクト: DHMechatronicAG/BloubulLE
        protected override async Task <bool> StartScanningForDevicesNativeAsync(Guid[] serviceUuids,
                                                                                Boolean allowDuplicatesKey, CancellationToken scanCancellationToken)
        {
            // Wait for the PoweredOn state
            await this.WaitForState(CBCentralManagerState.PoweredOn, scanCancellationToken).ConfigureAwait(false);

            if (scanCancellationToken.IsCancellationRequested)
            {
                throw new TaskCanceledException("StartScanningForDevicesNativeAsync cancelled");
            }

            Trace.Message("Adapter: Starting a scan for devices.");

            CBUUID[] serviceCbuuids = null;
            if (serviceUuids != null && serviceUuids.Any())
            {
                serviceCbuuids = serviceUuids.Select(u => CBUUID.FromString(u.ToString())).ToArray();
                Trace.Message("Adapter: Scanning for " + serviceCbuuids.First());
            }

            this.DiscoveredDevices.Clear();
            this._centralManager.ScanForPeripherals(serviceCbuuids,
                                                    new PeripheralScanningOptions {
                AllowDuplicatesKey = allowDuplicatesKey
            });

            return(true);
        }
コード例 #2
0
        public static BeaconInfo BeaconInfoForUIDFrameData(NSDictionary advertisementFrameList, NSData telemetry, int rssi)
        {
            var frameData = advertisementFrameList.ObjectForKey(CBUUID.FromString("FEAA")) as NSData;

            if (frameData.Length > 1)
            {
                var frameBytes = frameData.ToArray();

                if (frameBytes[0] != EddystoneUIDFrameTypeID)
                {
                    System.Diagnostics.Debug.WriteLine("Unexpected non UID Frame passed to BeaconInfoForUIDFrameData.");
                    return(null);
                }
                else if (frameBytes.Length < 18)
                {
                    System.Diagnostics.Debug.WriteLine("Frame Data for UID Frame unexpectedly truncated in BeaconInfoForUIDFrameData.");
                }

                var txPower = Convert.ToInt32(frameBytes[1]);

                var beaconID = new byte [frameBytes.Length - 2];
                Array.Copy(frameBytes, 2, beaconID, 0, beaconID.Length);

                var bid = new BeaconID(BeaconType.Eddystone, beaconID);

                return(new BeaconInfo(bid, txPower, rssi, telemetry));
            }

            return(null);
        }
コード例 #3
0
ファイル: CBUUID.cs プロジェクト: beeradmoore/xamarin-macios
        public void FullRandomEquals()
        {
            var guid = Guid.NewGuid();

            Assert.That(CBUUID.FromBytes(guid.ToByteArray()),
                        Is.EqualTo(CBUUID.FromBytes(guid.ToByteArray())));
        }
コード例 #4
0
            public override void DiscoveredService(CBPeripheral peripheral, NSError error)
            {
                var descriptor = peripheral.ToDeviceDescriptor();

                if (error != null)
                {
                    _deviceManager.HandleDeviceCommunicationDiscoveryServiceError(descriptor, error.LocalizedFailureReason, (d) =>
                    {
                        _centralManager.CancelPeripheralConnection(peripheral);
                    });
                    return;
                }

                CBUUID uuidCharacteristic = CBUUID.FromString(_tracingInformation.CharacteristicId);
                CBUUID uuidService        = CBUUID.FromString(_tracingInformation.ServiceId);
                var    service            = peripheral.Services.FirstOrDefault(x => x.UUID == uuidService);

                if (service != null)
                {
                    _deviceManager.HandleDeviceCommunicationDiscoveredService(descriptor, (d) =>
                    {
                        peripheral.DiscoverCharacteristics(new[] { uuidCharacteristic }, service);
                    });
                }
                else
                {
                    _deviceManager.HandleIncorrectDevice(descriptor);
                    _centralManager.CancelPeripheralConnection(peripheral);
                }
            }
コード例 #5
0
        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
        }
コード例 #6
0
        public async Task StartAdvertising(string localName, List <IService> services)
        {
            if (_peripheralManager.State != CBPeripheralManagerState.PoweredOn)
            {
                throw new InvalidStateException((ManagerState)_peripheralManager.State);
            }

            var cbuuIdArray = new NSMutableArray();
            var optionsDict = new NSMutableDictionary();

            if (services != null)
            {
                foreach (Service service in services)
                {
                    cbuuIdArray.Add(CBUUID.FromString(service.Uuid));
                    //_peripheralManager.AddService((CBMutableService) service.NativeService);
                }
                optionsDict[CBAdvertisement.DataServiceUUIDsKey] = cbuuIdArray;
            }


            if (localName != null)
            {
                optionsDict[CBAdvertisement.DataLocalNameKey] = new NSString(localName);
            }

            _peripheralManager.StartAdvertising(optionsDict);
        }
コード例 #7
0
        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);
            };
        }
コード例 #8
0
ファイル: Adapter.cs プロジェクト: TWhidden/Monkey.Robotics
        public async void StartScanningForDevices(Guid serviceUuid, int timeOutSeconds = 10)
        {
            //
            // Wait for the PoweredOn state
            //
            await WaitForState(CBCentralManagerState.PoweredOn);

            Debug.WriteLine("Adapter: Starting a scan for devices.");

            CBUUID[] serviceUuids = null;             // TODO: convert to list so multiple Uuids can be detected
            if (serviceUuid != Guid.Empty)
            {
                var suuid = CBUUID.FromString(serviceUuid.ToString());
                serviceUuids = new CBUUID[] { suuid };
                Debug.WriteLine("Adapter: Scanning for " + suuid);
            }

            // clear out the list
            this._discoveredDevices = new List <IDevice> ();

            // start scanning
            this._isScanning = true;
            this._central.ScanForPeripherals(serviceUuids);

            // in 10 seconds, stop the scan
            await Task.Delay(TimeSpan.FromSeconds(timeOutSeconds));

            // if we're still scanning
            if (this._isScanning)
            {
                Console.WriteLine("BluetoothLEManager: Scan timeout has elapsed.");
                StopScanningForDevices();
                this.ScanTimeoutElapsed(this, new EventArgs());
            }
        }
コード例 #9
0
ファイル: GattCharacteristic.cs プロジェクト: shinyorg/shiny
        public void Build(CBMutableService service)
        {
            this.native = new CBMutableCharacteristic(
                CBUUID.FromString(this.Uuid),
                this.properties,
                null,
                this.permissions
                );
            service.Characteristics = service.Characteristics.Expand(this.native);

            if (this.onWrite != null)
            {
                this.manager.WriteRequestsReceived += this.OnWrite;
            }

            if (this.onRead != null)
            {
                this.manager.ReadRequestReceived += this.OnRead;
            }

            if (this.onSubscribe != null)
            {
                this.manager.CharacteristicSubscribed   += this.OnSubscribed;
                this.manager.CharacteristicUnsubscribed += this.OnUnSubscribed;
            }
        }
コード例 #10
0
        public static CBUUID ToCBUUID(this Guid guid)
        {
            var bytes = guid.ToByteArray();

            return(CBUUID.FromString(guid.ToString()));
            //return CBUUID.FromBytes(guid.ToByteArray());
        }
コード例 #11
0
        public void Start(TracingInformation tracingInformation)
        {
            if (tracingInformation == null || _enabled)
            {
                return;
            }

            _tracingInformation = tracingInformation;
            _peripheralManager.RemoveAllServices();
            CBUUID uuidService        = CBUUID.FromString(tracingInformation.ServiceId);
            CBUUID uuidCharacteristic = CBUUID.FromString(tracingInformation.CharacteristicId);
            var    data           = NSData.FromArray(PayloadFormatter.GetBytesToSend(new PackageData(tracingInformation.DeviceId)));
            var    characteristic = new CBMutableCharacteristic(uuidCharacteristic, CBCharacteristicProperties.Read, data, CBAttributePermissions.Readable);
            var    service        = new CBMutableService(uuidService, true);

            service.Characteristics = new CBCharacteristic[] { characteristic };
            _peripheralManager.AddService(service);
            StartAdvertisingOptions advData = new StartAdvertisingOptions {
                ServicesUUID = new CBUUID[] { uuidService }
            };

            _peripheralManager.StartAdvertising(advData);
            TracingState.Instance.SetAdvertisingState(true);
            _enabled = true;
            _logger.LogDebug("Advertising starting. DeviceId: " + _tracingInformation.DeviceId);
        }
コード例 #12
0
        public async void StartScanningForDevices(Guid serviceUuid)
        {
            await WaitForState(CBCentralManagerState.PoweredOn);

            Debug.WriteLine("Adapter: Starting a scan for devices.");
            CBUUID[] serviceUuids = null; // TODO: convert to list so multiple Uuids can be detected
            if (serviceUuid != Guid.Empty)
            {
                var suuid = CBUUID.FromString(serviceUuid.ToString());
                serviceUuids = new CBUUID[] { suuid };
                Debug.WriteLine("Adapter: Scanning for " + suuid);
            }
            this._discoveredDevices = new List <IDevice>();
            this._isScanning        = true;
            this._central.ScanForPeripherals(serviceUuids);
            await Task.Delay(10000);

            if (this._isScanning)
            {
                Console.WriteLine("BluetoothLEManager: Scan timeout has elapsed.");
                this._isScanning = false;
                this._central.StopScan();
                this.ScanTimeoutElapsed(this, new EventArgs());
            }
        }
コード例 #13
0
        public async void StartScanningForDevices(Guid serviceUuid)
        {
            await WaitForState(CBCentralManagerState.PoweredOn);

            Debug.WriteLine("Adapter: Starting a scan for devices.");

            CBUUID[] serviceUuids = null; // TODO: convert to list so multiple Uuids can be detected
            if (serviceUuid != Guid.Empty)
            {
                var suuid = CBUUID.FromString(serviceUuid.ToString());
                serviceUuids = new CBUUID[] { suuid };

                Debug.WriteLine("Adapter: Scanning for " + suuid);
            }

            // clear out the list
            DiscoveredDevices = new List <IDevice>();

            // start scanning
            IsScanning = true;
            CentralManager.ScanForPeripherals(serviceUuids);

            // in 10 seconds, stop the scan
            await Task.Delay(10000);

            // if we're still scanning
            if (IsScanning)
            {
                Console.WriteLine("Adapter: Scan timeout has elapsed.");
                IsScanning = false;
                CentralManager.StopScan();
                ScanTimeoutElapsed(this, new EventArgs());
            }
        }
コード例 #14
0
        public static EddystoneFrameType FrameTypeForFrame(NSDictionary advertisementFrameList)
        {
            var uuid      = CBUUID.FromString("FEAA");
            var frameData = advertisementFrameList[uuid] as NSData;

            if (frameData != null)
            {
                var count = frameData.Length;
                if (count > 1)
                {
                    var frameBytes = Enumerable.Repeat((byte)0, (int)count).ToArray();
                    Marshal.Copy(frameData.Bytes, frameBytes, 0, (int)count);
                    if (frameBytes[0] == BeaconInfo.EddystoneUIDFrameTypeID)
                    {
                        return(BeaconInfo.EddystoneFrameType.UIDFrameType);
                    }
                    else if (frameBytes[0] == BeaconInfo.EddystoneTLMFrameTypeID)
                    {
                        return(BeaconInfo.EddystoneFrameType.TelemetryFrameType);
                    }
                    else if (frameBytes[0] == BeaconInfo.EddystoneEIDFrameTypeID)
                    {
                        return(BeaconInfo.EddystoneFrameType.EIDFrameType);
                    }
                    else if (frameBytes[0] == BeaconInfo.EddystoneURLFrameTypeID)
                    {
                        return(BeaconInfo.EddystoneFrameType.URLFrameType);
                    }
                }
            }
            return(EddystoneFrameType.UnknownFrameType);
        }
コード例 #15
0
 public void StartScan(BleDevice device)
 {
     _CentralManager = new CBCentralManager(this, null);
     if (device == null)
     {
         throw new Exception("Could not start client without a service type to scan for.");
     }
     _CentralManager.DiscoveredPeripheral += (o, e) =>
     {
         DeviceFound?.Invoke(this, new DeviceEventArgs {
             Device = new BleDevice {
                 Guid = e.Peripheral.UUID.Uuid
             }
         });
     };
     _CentralManager.ConnectedPeripheral += (o, e) =>
     {
         DeviceConnected?.Invoke(this, new DeviceEventArgs {
             Device = new BleDevice {
                 Guid = e.Peripheral.UUID.Uuid
             }
         });
     };
     //_CentralManager.ScanForPeripherals(CBUUID.FromPartial(device.GuidValue));
     _CentralManager.ScanForPeripherals(CBUUID.FromString(device.Guid));
 }
コード例 #16
0
ファイル: IOSBluetooth.cs プロジェクト: juchong/ProtoRIO
 public BtError enumerateDevices()
 {
     if (!isScanning)
     {
         devices.Clear();
         deviceAddresses.Clear();
         serviceObjects.Clear();
         characteristicObjects.Clear();
         descriptorObjects.Clear();
         var error = checkBtSupport();
         if (error != BtError.None)
         {
             return(error);
         }
         var uuids = new List <CBUUID>();
         foreach (var s in scanServices)
         {
             uuids.Add(CBUUID.FromString(s));
         }
         var options = new PeripheralScanningOptions();
         options.AllowDuplicatesKey = true;
         centralManager.ScanForPeripherals(uuids.ToArray(), options);
         isScanning = true;
         return(BtError.None);
     }
     else
     {
         return(BtError.AlreadyRunning);
     }
 }
コード例 #17
0
        public static EddystoneFrameType FrameTypeForFrame(NSDictionary advertisementFrameList)
        {
            var frameData = advertisementFrameList.ObjectForKey(CBUUID.FromString("FEAA")) as NSData;

            if (frameData != null && frameData.Length >= 1)
            {
                var frameBytes = frameData.ToArray();

                if (frameBytes[0] == EddystoneUIDFrameTypeID)
                {
                    return(EddystoneFrameType.UIDFrameType);
                }
                else if (frameBytes[0] == EddystoneTLMFrameTypeID)
                {
                    return(EddystoneFrameType.TelemetryFrameType);
                }
                else if (frameBytes[0] == EddystoneEIDFrameTypeID)
                {
                    return(EddystoneFrameType.EIDFrameType);
                }
                else if (frameBytes[0] == EddystoneURLFrameTypeID)
                {
                    return(EddystoneFrameType.URLFrameType);
                }
                else
                {
                    return(EddystoneFrameType.UnknownFrameType);
                }
            }

            return(EddystoneFrameType.UnknownFrameType);
        }
コード例 #18
0
        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,
                });
            }
        }
コード例 #19
0
        /// <summary>
        /// Gets the paired devices.
        /// </summary>
        /// <returns>Task&lt;IReadOnlyList&lt;IBluetoothDevice&gt;&gt;.</returns>
        public async Task <IReadOnlyList <IBluetoothDevice> > GetPairedDevices()
        {
            return(await Task.Factory.StartNew(() =>
            {
                var devices = new List <IBluetoothDevice>();

                var action = new EventHandler <CBPeripheralsEventArgs>((s, e) =>
                                                                       devices.AddRange(e.Peripherals.Select(a => new BluetoothDevice(a))));

                this.manager.RetrievedPeripherals += action;

                this.manager.RetrievedConnectedPeripherals += ManagerOnRetrievedConnectedPeripherals;
                this.manager.DiscoveredPeripheral += manager_DiscoveredPeripheral;
                //CBUUID id = null;

                // Bug in Xamarin? https://bugzilla.xamarin.com/show_bug.cgi?id=5808
                //this.manager.ScanForPeripherals(id, null);
                this.manager.ScanForPeripherals(CBUUID.FromString(TransferServiceUuid));

                this.manager.RetrievePeripherals(CBUUID.FromString(TransferServiceUuid));
                //this.manager.RetrieveConnectedPeripherals(new[] { CBUUID.FromString(TransferServiceUuid) });
                this.manager.RetrievedPeripherals -= action;
                this.manager.RetrievedConnectedPeripherals -= ManagerOnRetrievedConnectedPeripherals;
                this.manager.DiscoveredPeripheral -= manager_DiscoveredPeripheral;

                return devices;
            }));
        }
コード例 #20
0
ファイル: CBUUID.cs プロジェクト: beeradmoore/xamarin-macios
 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
     }));
 }
コード例 #21
0
        public async Task <CBService> GetService(CBPeripheral peripheral, string serviceUuid)
        {
            var service = this.GetServiceIfDiscovered(peripheral, serviceUuid);

            if (service != null)
            {
                return(service);
            }

            var taskCompletion = new TaskCompletionSource <bool>();
            var task           = taskCompletion.Task;
            EventHandler <NSErrorEventArgs> handler = (s, e) =>
            {
                if (this.GetServiceIfDiscovered(peripheral, serviceUuid) != null)
                {
                    taskCompletion.SetResult(true);
                }
            };

            try
            {
                peripheral.DiscoveredService += handler;
                peripheral.DiscoverServices(new[] { CBUUID.FromString(serviceUuid) });
                await this.WaitForTaskWithTimeout(task, ConnectionTimeout);

                return(this.GetServiceIfDiscovered(peripheral, serviceUuid));
            }
            finally
            {
                peripheral.DiscoveredService -= handler;
            }
        }
コード例 #22
0
        public Characteristic(Guid uuid, CharacterisiticPermissionType permissions, CharacteristicPropertyType properties)
        {
            CBAttributePermissions nativePermissions = 0;

            nativePermissions     = GetNativePermissions(permissions);
            _nativeCharacteristic = new CBMutableCharacteristic(CBUUID.FromString(uuid.ToString()), (CBCharacteristicProperties)properties, null, nativePermissions);
        }
コード例 #23
0
        public Task <byte[]> ReadValue(string characteristicGuid, bool important = false)
        {
            var cbuuid = CBUUID.FromString(characteristicGuid);

            // TODO: Check for connected devices?
            if (_characteristics.ContainsKey(cbuuid) == false)
            {
                // TODO Error?
                return(null);
            }

            // Already awaiting it.
            if (_readQueue.ContainsKey(cbuuid))
            {
                return(_readQueue[cbuuid].Task);
            }

            var taskCompletionSource = new TaskCompletionSource <byte[]>();

            if (important)
            {
                // TODO: Put this at the start of the queue.
                _readQueue.Add(cbuuid, taskCompletionSource);
            }
            else
            {
                _readQueue.Add(cbuuid, taskCompletionSource);
            }


            _peripheral.ReadValue(_characteristics[cbuuid]);

            return(taskCompletionSource.Task);
        }
コード例 #24
0
 public static Guid ToGuid(this CBUUID guid)
 {
     return(Guid.Parse(guid.ToString()));
     //var bytes = guid.ToByteArray();
     //return CBUUID.FromString(guid.ToString());
     //return CBUUID.FromBytes(guid.ToByteArray());
 }
コード例 #25
0
        public void Equality_PartialsOfDifferentSizeNotEqual()
        {
#if MONOMAC
            Assert.That(CBUUID.FromPartial(0x1234), Is.Not.EqualTo(
                            CBUUID.FromBytes(new byte [] { 0x12, 0x34, 0x56, 0x78 })));
#endif
        }
コード例 #26
0
ファイル: Bluetooth.cs プロジェクト: EtienneThompson/Sphero
        public void WakeUp(CBPeripheral peripheral)
        {
            // Method that sends commands to sphero in specific order to wake it up

            // Create required data
            NSData antiDOS = NSData.FromString("011i3");
            var    txdata  = new byte[1];

            txdata[0] = 0x07;
            NSData TXdata     = NSData.FromArray(txdata);
            var    wakeupdata = new byte[1];

            wakeupdata[0] = 0x01;
            NSData WakeupData = NSData.FromArray(wakeupdata);

            // Notes
            // peripheral.Services[0].Characteristics is Control/Response Characteristics
            // Control first, then Response
            // peripheral.Services[1].Characteristics is Radio Service Characteristics
            // peripheral.Services[2].Characteristics is Device Info Characteristics
            // peripheral.Services[3].Characteristics is Device Information

            // Sending the wake up commands to the sphero
            // Can be simplified (either if discovery of services and characteristics are static, or by sorting the arrays
            // that information is contained in. For now this is just a working version.


            foreach (var characteristic in peripheral.Services[1].Characteristics)
            {
                if (characteristic.UUID == CBUUID.FromString("22bb746f-2bbd-7554-2D6F-726568705327"))
                {
                    Console.WriteLine("Writing to Anti DOS");
                    peripheral.WriteValue(antiDOS, characteristic, CBCharacteristicWriteType.WithResponse);
                }
            }
            foreach (var characteristic in peripheral.Services[1].Characteristics)
            {
                if (characteristic.UUID == CBUUID.FromString("22bb746f-2bb2-7554-2D6F-726568705327"))
                {
                    Console.WriteLine("Writing to TX Power");
                    peripheral.WriteValue(TXdata, characteristic, CBCharacteristicWriteType.WithResponse);
                }
            }
            foreach (var characteristic in peripheral.Services[1].Characteristics)
            {
                if (characteristic.UUID == CBUUID.FromString("22bb746f-2bbf-7554-2D6F-726568705327"))
                {
                    Console.WriteLine("Writing to Wakeup");
                    peripheral.WriteValue(WakeupData, characteristic, CBCharacteristicWriteType.WithResponse);
                }
            }


            /*
             * peripheral.WriteValue(antiDOS, peripheral.Services[1].Characteristics[3], CBCharacteristicWriteType.WithResponse);
             * peripheral.WriteValue(TXdata, peripheral.Services[1].Characteristics[0], CBCharacteristicWriteType.WithResponse);
             * peripheral.WriteValue(WakeupData, peripheral.Services[1].Characteristics[5], CBCharacteristicWriteType.WithResponse);
             */
        }
コード例 #27
0
ファイル: GattService.cs プロジェクト: shinyorg/shiny
 public GattService(CBPeripheralManager manager, string uuid, bool primary)
 {
     this.manager         = manager;
     this.Native          = new CBMutableService(CBUUID.FromString(uuid), primary);
     this.characteristics = new List <GattCharacteristic>();
     this.Uuid            = uuid;
     this.Primary         = primary;
 }
コード例 #28
0
ファイル: UuidTest.cs プロジェクト: tondat/xamarin-macios
        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
        }
コード例 #29
0
 public void ClearUnusedConnections()
 {
     connectionLookup.Clear();
     foreach (var device in ion.deviceManager.knownDevices)
     {
         connectionLookup[CBUUID.FromString(device.connection.address)] = device.connection;
     }
 }
コード例 #30
0
ファイル: IOSBluetooth.cs プロジェクト: juchong/ProtoRIO
        public void subscribeToUartChars()
        {
            var tx = getCharacteristic(CBUUID.FromString(BTValues.txCharacteristic));

            if (tx != null && connectedPeripheral != null)
            {
                connectedPeripheral.SetNotifyValue(true, tx);
            }
        }
コード例 #31
0
ファイル: Service.cs プロジェクト: yelkrebb/Core.BLE.iOS
		public static Guid ServiceUuidToGuid ( CBUUID uuid)
		{
			//this sometimes returns only the significant bits, e.g.
			//180d or whatever. so we need to add the full string
			string id = uuid.ToString ();
			if (id.Length == 4) {
				id = "0000" + id + "-0000-1000-8000-00805f9b34fb";
			}
			return Guid.ParseExact (id, "d");
		}
コード例 #32
0
 private NSDictionary CreateAdvertisementData(string name, CBUUID serviceUuid)
 {
     return NSDictionary.FromObjectsAndKeys(
         new NSObject[]
         {
             NSArray.FromNSObjects(serviceUuid),    new NSString(name)
         },
         new NSObject[]
         {
             CBAdvertisement.DataServiceUUIDsKey,   CBAdvertisement.DataLocalNameKey
         });
 }
コード例 #33
0
 public static bool IsUuidEqual(this CBCharacteristic characteristic, CBUUID uuid)
 {
     var result = characteristic.UUID == uuid;
     return result;
 }
コード例 #34
0
ファイル: Adapter.cs プロジェクト: Roddoric/Monkey.Robotics
		public async void StartScanningForDevices (Guid serviceUuid)
		{
			//
			// Wait for the PoweredOn state
			//
			await WaitForState (CBCentralManagerState.PoweredOn);

			Debug.WriteLine ("Adapter: Starting a scan for devices.");

			CBUUID[] serviceUuids = null; // TODO: convert to list so multiple Uuids can be detected
			if (serviceUuid != Guid.Empty) {
				var suuid = CBUUID.FromString (serviceUuid.ToString ());
				serviceUuids = new CBUUID[] { suuid };
				Debug.WriteLine ("Adapter: Scanning for " + suuid);
			}

			// clear out the list
			this._discoveredDevices = new List<IDevice> ();

			// start scanning
			this._isScanning = true;
			this._central.ScanForPeripherals ( serviceUuids );

			// in 10 seconds, stop the scan
			await Task.Delay (10000);

			// if we're still scanning
			if (this._isScanning) {
				Console.WriteLine ("BluetoothLEManager: Scan timeout has elapsed.");
				this._isScanning = false;
				this._central.StopScan ();
				this.ScanTimeoutElapsed (this, new EventArgs ());
			}
		}