Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        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;
            }
        }
 public iOSBluetoothDeviceProximityProbeCentralManagerDelegate(CBMutableService service, CBMutableCharacteristic characteristic, iOSBluetoothDeviceProximityProbe probe)
 {
     _service        = service;
     _characteristic = characteristic;
     _probe          = probe;
     _peripheralCentralTimestamps = new List <Tuple <CBPeripheral, CBCentralManager, DateTimeOffset> >();
 }
Exemplo n.º 4
0
        public void Start(BleDevice device, BleCharacteristic[] characteristics)
        {
            string dataServiceUUIDsKey               = "71DA3FD1-7E10-41C1-B16F-4430B5060000";
            string customBeaconServiceUUIDsKey       = "71DA3FD1-7E10-41C1-B16F-4430B5060001";
            string customBeaconCharacteristicUUIDKey = "71DA3FD1-7E10-41C1-B16F-4430B5060002";
            string identifier = "71DA3FD1-7E10-41C1-B16F-4430B5060003";

            peripheralManager = new CBPeripheralManager(this, DispatchQueue.DefaultGlobalQueue);
            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.");
                }
            };


            var customBeaconServiceUUID        = CBUUID.FromString(customBeaconServiceUUIDsKey);
            var customBeaconCharacteristicUUID = CBUUID.FromString(customBeaconCharacteristicUUIDKey);

            var service  = new CBMutableService(customBeaconServiceUUID, true);
            var dataUUID = NSData.FromString(identifier, NSStringEncoding.UTF8);

            var characteristic = new CBMutableCharacteristic(
                customBeaconCharacteristicUUID,
                CBCharacteristicProperties.Read,
                dataUUID,
                CBAttributePermissions.Readable);

            service.Characteristics = new CBCharacteristic[] { characteristic };
            peripheralManager.AddService(service);

            var localName = new NSString("CustomBeacon");

            //var advertisingData = new NSDictionary( CBAdvertisement.DataLocalNameKey, localName,
            //    CBAdvertisement.IsConnectable, false,
            //    CBAdvertisement.DataManufacturerDataKey, CBUUID.FromString(dataServiceUUIDsKey),
            //    CBAdvertisement.DataServiceUUIDsKey, CBUUID.FromString(dataServiceUUIDsKey));

            //peripheralManager.StartAdvertising(advertisingData);



            var UUI = new CBUUID[] { CBUUID.FromString("71DA3FD1-7E10-41C1-B16F-4430B5060000") };

            NSArray arry = NSArray.FromObjects(UUI);
            var     test = NSObject.FromObject(arry);
            var     ad   = new NSDictionary(CBAdvertisement.DataServiceUUIDsKey, test);

            peripheralManager.StartAdvertising(ad);
        }
Exemplo n.º 5
0
        protected override async Task InitializeAsync()
        {
            await base.InitializeAsync();

            // create device id characteristic
            _deviceIdCharacteristic = new CBMutableCharacteristic(CBUUID.FromString(DEVICE_ID_CHARACTERISTIC_UUID),
                                                                  CBCharacteristicProperties.Read,
                                                                  NSData.FromArray(Encoding.UTF8.GetBytes(SensusServiceHelper.Get().DeviceId)),
                                                                  CBAttributePermissions.Readable);

            // create service with device id characteristic
            _deviceIdService = new CBMutableService(CBUUID.FromString(Protocol.Id), true);
            _deviceIdService.Characteristics = new CBCharacteristic[] { _deviceIdCharacteristic };
        }
Exemplo n.º 6
0
        protected override void Initialize()
        {
            // the following code relies on SensusServiceHelper singleton, which will not be available above in the constructor.

            // create device id characteristic
            _deviceIdCharacteristic = new CBMutableCharacteristic(CBUUID.FromString(DEVICE_ID_CHARACTERISTIC_UUID),
                                                                  CBCharacteristicProperties.Read,
                                                                  NSData.FromArray(Encoding.UTF8.GetBytes(SensusServiceHelper.Get().DeviceId)),
                                                                  CBAttributePermissions.Readable);

            // create service with device id characteristic
            _deviceIdService = new CBMutableService(CBUUID.FromString(DEVICE_ID_SERVICE_UUID), true);
            _deviceIdService.Characteristics = new CBCharacteristic[] { _deviceIdCharacteristic };
        }
Exemplo n.º 7
0
        public GattCharacteristic(CBPeripheralManager manager,
                                  IGattService service,
                                  Guid characteristicUuid,
                                  CharacteristicProperties properties,
                                  GattPermissions permissions) : base(service, characteristicUuid, properties, permissions)
        {
            this.manager     = manager;
            this.subscribers = new ConcurrentDictionary <NSUuid, IDevice>();

            this.Native = new CBMutableCharacteristic(
                characteristicUuid.ToCBUuid(),
                properties.ToNative(),
                null,
                (CBAttributePermissions)(int)permissions   // TODO
                );
        }
 public iOSBluetoothDeviceProximityProbePeripheralManagerDelegate(CBMutableService service, CBMutableCharacteristic characteristic, iOSBluetoothDeviceProximityProbe probe)
 {
     _service        = service;
     _characteristic = characteristic;
     _probe          = probe;
 }
Exemplo n.º 9
0
 public void UpdateSubscribers(CBPeripheralManager peripheralManager, CBMutableCharacteristic characteristic)
 {
     peripheralManager.UpdateValue(null, characteristic, characteristic.SubscribedCentrals);
 }