Beispiel #1
0
        public override void Start(AdvertisementData adData)
        {
            var settings = new AdvertiseSettings.Builder()
                           .SetAdvertiseMode(AdvertiseMode.Balanced)
                           .SetConnectable(true);

            var data = new AdvertiseData.Builder()
                       .SetIncludeDeviceName(true)
                       .SetIncludeTxPowerLevel(true);

            if (adData.ManufacturerData != null)
            {
                data.AddManufacturerData(adData.ManufacturerData.CompanyId, adData.ManufacturerData.Data);
            }

            foreach (var serviceUuid in adData.ServiceUuids)
            {
                data.AddServiceUuid(serviceUuid.ToParcelUuid());
            }

            this.manager
            .Adapter
            .BluetoothLeAdvertiser
            .StartAdvertising(
                settings.Build(),
                data.Build(),
                this.adCallbacks
                );

            base.Start(adData);
        }
Beispiel #2
0
        public override void Start(AdvertisementData adData)
        {
            if (!CrossBleAdapter.AndroidConfiguration.IsServerSupported)
            {
                throw new BleException("BLE Advertiser needs API Level 23+");
            }

            this.manager     = (BluetoothManager)Application.Context.GetSystemService(Context.BluetoothService);
            this.adCallbacks = new AdvertisementCallbacks();

            var settings = new AdvertiseSettings.Builder()
                           .SetAdvertiseMode(AdvertiseMode.Balanced)
                           .SetConnectable(adData.AndroidIsConnectable);

            var data = new AdvertiseData.Builder()
                       .SetIncludeDeviceName(adData.AndroidUseDeviceName)
                       .SetIncludeTxPowerLevel(true);

            if (adData.ManufacturerData != null)
            {
                data.AddManufacturerData(adData.ManufacturerData.CompanyId, adData.ManufacturerData.Data);
            }

            foreach (var serviceUuid in adData.ServiceUuids)
            {
                data.AddServiceUuid(serviceUuid.ToParcelUuid());
            }

            if (string.IsNullOrEmpty(adData.LocalName) || adData.AndroidUseDeviceName)
            {
                this.manager
                .Adapter
                .BluetoothLeAdvertiser
                .StartAdvertising(
                    settings.Build(),
                    data.Build(),
                    this.adCallbacks
                    );
            }
            else
            {
                this.manager
                .Adapter.SetName(adData.LocalName);
                var scanResponse = new AdvertiseData.Builder()
                                   .SetIncludeDeviceName(true);
                this.manager
                .Adapter
                .BluetoothLeAdvertiser
                .StartAdvertising(
                    settings.Build(),
                    data.Build(),
                    scanResponse.Build(),
                    this.adCallbacks
                    );
            }

            base.Start(adData);
        }
Beispiel #3
0
        public override Task Start(AdvertisementData adData)
        {
            if (this.manager.Advertising)
            {
                return(Task.CompletedTask);
            }

            if (CBPeripheralManager.AuthorizationStatus != CBPeripheralManagerAuthorizationStatus.Authorized)
            {
                throw new ArgumentException("Permission Denied - " + CBPeripheralManager.AuthorizationStatus);
            }

            if (this.manager.State != CBPeripheralManagerState.PoweredOn)
            {
                throw new ArgumentException("Invalid State - " + this.manager.State);
            }


            this.manager.StartAdvertising(new StartAdvertisingOptions
            {
                LocalName    = adData.LocalName,
                ServicesUUID = adData
                               .ServiceUuids
                               .Select(x => CBUUID.FromString(x.ToString()))
                               .ToArray()
            });

            this.services
            .Cast <IIosGattService>()
            .Select(x =>
            {
                x.Native.Characteristics = x
                                           .Characteristics
                                           .OfType <IIosGattCharacteristic>()
                                           .Select(y =>
                {
                    y.Native.Descriptors = y
                                           .Descriptors
                                           .OfType <IIosGattDescriptor>()
                                           .Select(z => z.Native)
                                           .ToArray();
                    return(y.Native);
                })
                                           .ToArray();

                return(x.Native);
            })
            .ToList()
            .ForEach(this.manager.AddService);

            return(Task.CompletedTask);
        }
Beispiel #4
0
        public override void Start(AdvertisementData adData)
        {
            if (!CrossBleAdapter.AndroidConfiguration.IsServerSupported)
            {
                throw new BleException("BLE Advertiser needs API Level 21+");
            }

            if (this.IsStarted)
            {
                throw new BleException("BLE Advertiser is already started");
            }

            var settings = new AdvertiseSettings.Builder()
                           .SetAdvertiseMode(AdvertiseMode.Balanced)
                           .SetConnectable(adData.AndroidIsConnectable);

            var data = new AdvertiseData.Builder()
                       .SetIncludeDeviceName(adData.AndroidIncludeDeviceName)
                       .SetIncludeTxPowerLevel(adData.AndroidIncludeTxPower);

            if (adData.ManufacturerData != null)
            {
                data.AddManufacturerData(adData.ManufacturerData.CompanyId, adData.ManufacturerData.Data);
            }

            foreach (var serviceUuid in adData.ServiceUuids)
            {
                data.AddServiceUuid(serviceUuid.ToParcelUuid());
            }

            if (!string.IsNullOrEmpty(adData.LocalName))
            {
                data.SetIncludeDeviceName(true);
                this.manager.Adapter.SetName(adData.LocalName);
            }

            this.manager
            .Adapter
            .BluetoothLeAdvertiser
            .StartAdvertising(
                settings.Build(),
                data.Build(),
                this.adCallbacks
                );

            base.Start(adData);
        }
Beispiel #5
0
        public override Task Start(AdvertisementData adData)
        {
            if (this.isRunning)
            {
                return(Task.CompletedTask);
            }

            if (adData != null)
            {
                this.StartAdvertising(adData);
            }

            this.StartGatt();
            this.runningSubj.OnNext(true);
            this.isRunning = true;
            return(Task.CompletedTask);
        }
Beispiel #6
0
        public override void Start(AdvertisementData adData)
        {
            this.publisher.Advertisement.Flags = BluetoothLEAdvertisementFlags.ClassicNotSupported;
            this.publisher.Advertisement.ManufacturerData.Clear();
            this.publisher.Advertisement.ServiceUuids.Clear();

            if (adData.ManufacturerData != null)
            {
                using (var writer = new DataWriter())
                {
                    writer.WriteBytes(adData.ManufacturerData.Data);
                    var md = new BluetoothLEManufacturerData(adData.ManufacturerData.CompanyId, writer.DetachBuffer());
                    this.publisher.Advertisement.ManufacturerData.Add(md);
                }
            }

            foreach (var serviceUuid in adData.ServiceUuids)
            {
                this.publisher.Advertisement.ServiceUuids.Add(serviceUuid);
            }

            this.publisher.Start();
        }
 public virtual void Stop()
 {
     this.CurrentAdvertisementData = null;
     this.IsStarted = false;
 }
 public virtual void Start(AdvertisementData adData)
 {
     this.CurrentAdvertisementData = adData;
 }
Beispiel #9
0
 public virtual void Start(AdvertisementData adData)
 {
     this.CurrentAdvertisementData = adData;
     this.IsStarted = true;
 }
Beispiel #10
0
 public abstract Task Start(AdvertisementData adData);