예제 #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);
        }
예제 #2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            // Code to start the Xamarin Test Cloud Agent
            #if ENABLE_TEST_CLOUD
            Xamarin.Calabash.Start ();
            #endif

            Scanner.AccessibilityIdentifier = "Bluetooth Init";
            Scanner.TouchUpInside += delegate {
                del.ScanForBroadcasters(manager, Scanner);
            };

            var options = new StartAdvertisingOptions ();

            peripheral.StartAdvertising (options);

            if (peripheral.Advertising)
                Console.WriteLine ("Advertising");

            //manager.ConnectedPeripheral += (s, e) => {
            //	var activePeripheral = e.Peripheral;
            //	System.Console.WriteLine ("Connected to " + activePeripheral.Name);

            //	if (activePeripheral.Delegate == null) {
            //		activePeripheral.Delegate = new ChoirCBCentralPeripheralDelegate ();
                    //Begins asynchronous discovery of services
            //		activePeripheral.DiscoverServices ();
            //	}
            //};

            //Connect to peripheral, triggering call to ConnectedPeripheral event handled above
            //mgr.ConnectPeripheral (myPeripheral);
        }
예제 #3
0
        public RemoteXServerForIos()
        {
            CBUUID[] cBUUIDs = new CBUUID[1];
            CBUUID   cBUUID  = CBUUID.FromString("AD86E9A5-AB95-4D75-A4BC-2A969F26E028");

            cBPeripheralManager = new CBPeripheralManager();
            remoteService       = new CBMutableService(cBUUID, true);
            cBPeripheralManager.AddService(remoteService);
            cBUUIDs.Append(cBUUID);
            var advertisingOption = new StartAdvertisingOptions
            {
                LocalName = "RemoteX Controller"
            };

            advertisingOption.ServicesUUID = cBUUIDs;
            cBPeripheralManager.StartAdvertising(advertisingOption);
        }
예제 #4
0
        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));
            }
        }