예제 #1
0
        public BatteryServiceWrapper(IBluetoothManager bluetoothManager)
        {
            IGattServiceBuilder builder = bluetoothManager.NewGattServiceBuilder();

            builder.SetUuid(BATTERY_SERVICE_UUID).SetServiceType(GattServiceType.Primary);
            BatteryLevelCharacteristicWrapper = new BatteryLevelCharacteristicWrapper(bluetoothManager);
            builder.AddCharacteristics(BatteryLevelCharacteristicWrapper.GattServerCharacteristic);
            GattServerService = builder.Build();
        }
        public GyroscopeServiceWrapper(IBluetoothManager bluetoothManager)
        {
            BluetoothManager = bluetoothManager;
            AngularVelocityCharacteristicWrapper = new GyroscopeAngularVelocityCharacteristicWrapper(this);
            IGattServiceBuilder builder = bluetoothManager.NewGattServiceBuilder();

            GattServerService = builder.SetUuid(Constant.GyroscopeServiceGuid)
                                .AddCharacteristics(AngularVelocityCharacteristicWrapper.GattServerCharacteristic)
                                .Build();
        }
예제 #3
0
        public DeviceInfomationServiceBuilder(IBluetoothManager bluetoothManager)
        {
            BluetoothManager = bluetoothManager;
            var manufacturerNameStringCharacteristic = new ManufacturerNameStringCharacteristicBuilder(BluetoothManager).Build();

            manufacturerNameStringCharacteristic.OnRead  += OnManufacturerNameStringCharacteristicRead;
            manufacturerNameStringCharacteristic.OnWrite += OnManufacturerNameStringCharacteristicWrite;
            _ServiceBuilder = BluetoothManager.NewGattServiceBuilder().SetUuid(SERVICE_DEVICE_INFORMATION)
                              .SetServiceType(GattServiceType.Primary)
                              .AddCharacteristics(manufacturerNameStringCharacteristic);
        }
예제 #4
0
        public TestServiceWrapper(IBluetoothManager bluetoothManager)
        {
            IGattServiceBuilder builder = bluetoothManager.NewGattServiceBuilder();

            builder.SetUuid(SERVICE_UUID).SetServiceType(GattServiceType.Primary);
            TestCharacteristicWrapper          = new TestCharacteristicWrapper(bluetoothManager);
            KeepNotifyingCharacteristicWrapper = new KeepNotifyingCharacteristicWrapper(bluetoothManager);
            builder.AddCharacteristics(TestCharacteristicWrapper.GattServerCharacteristic);
            builder.AddCharacteristics(KeepNotifyingCharacteristicWrapper.GattServerCharacteristic);
            GattServerService = builder.Build();
        }
예제 #5
0
        public TcpTranspondServiceWrapper(IBluetoothManager bluetoothManager)
        {
            BluetoothManager = bluetoothManager;
            TranspondCharacteristicWrapper = new TranspondCharacteristicWrapper(bluetoothManager);
            IGattServiceBuilder builder = bluetoothManager.NewGattServiceBuilder();

            GattServerService = builder.SetUuid(Uuid)
                                .AddCharacteristics(TranspondCharacteristicWrapper.GattServerCharacteristic)
                                .Build();
            TranspondCharacteristicWrapper.GattServerCharacteristic.OnRead  += GattServerCharacteristic_OnRead;
            TranspondCharacteristicWrapper.GattServerCharacteristic.OnWrite += GattServerCharacteristic_OnWrite;
            State     = TcpConnState.Created;
            TcpClient = new TcpClient();
        }
        public TestGattServiceWrapper(IBluetoothManager bluetoothManager, Int32 shortUuid)
        {
            Name = "No Name M**********r";
            GattRequestViewModels     = new ObservableCollection <GattRequestViewModel>();
            BluetoothManager          = bluetoothManager;
            TestCharacteristicWrapper = new TestCharacteristicWrapper(bluetoothManager);

            IGattServiceBuilder builder = bluetoothManager.NewGattServiceBuilder();

            GattServerService = builder.SetUuid(BluetoothUtils.ShortValueUuid(shortUuid))
                                .AddCharacteristics(TestCharacteristicWrapper.GattServerCharacteristic)
                                .Build();

            TestCharacteristicWrapper.GattServerCharacteristic.OnWrite += _OnCharacteristicWrite;
            TestCharacteristicWrapper.GattServerCharacteristic.OnRead  += _OnCharacteristicRead;
            value = BitConverter.GetBytes(232);
        }
예제 #7
0
        void BuildService(IGattServiceBuilder serviceBuilder)
        {
            serviceBuilder.AddCharacteristic(
                Characteristic1Uuid,
                cb =>
            {
                cb.SetWrite(request =>
                {
                    this.LastWriteValue = Encoding.UTF8.GetString(request.Data, 0, request.Data.Length);
                    this.LastWriteTime  = DateTime.Now.ToString();
                    return(GattState.Success);
                });

                cb.SetRead(request =>
                {
                    var ticks = DateTime.Now.Ticks;
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        this.LastReadValue = ticks.ToString();
                        this.LastReadTime  = DateTime.Now.ToString();
                    });
                    var data = BitConverter.GetBytes(ticks);
                    return(ReadResult.Success(data));
                });
            }
                );

            this.push = serviceBuilder.AddCharacteristic(
                Characteristic2Uuid,
                cb => cb.SetNotification(cs =>
            {
                var c = cs.Characteristic.SubscribedCentrals.Count;
                Device.BeginInvokeOnMainThread(() => this.Subscribers = c);

                if (c == 0)
                {
                    this.notifierSub?.Dispose();
                }
                else
                {
                    this.notifierSub = Observable
                                       .Interval(TimeSpan.FromSeconds(2))
                                       .Select(_ => Observable.FromAsync(async() =>
                    {
                        var ticks = DateTime.Now.Ticks;
                        var data  = BitConverter.GetBytes(ticks);
                        await this.push.Notify(data);

                        return(ticks);
                    }))
                                       .SubOnMainThread(x =>
                                                        this.SubscribersLastValue = x.ToString()
                                                        );
                }
            })
                );

            serviceBuilder.AddCharacteristic(
                Characteristic3Uuid,
                cb =>
            {
                cb.SetWrite(request =>
                {
                    Device.BeginInvokeOnMainThread(() => ++ this.SpeedWrites);
                    return(GattState.Success);
                });

                cb.SetRead(request =>
                {
                    Device.BeginInvokeOnMainThread(() => ++ this.SpeedReads);
                    var data = BitConverter.GetBytes(DateTime.Now.Ticks);
                    return(ReadResult.Success(data));
                });
            }
                );
        }
예제 #8
0
 public static IGattCharacteristic AddWriteCharacteristic(this IGattServiceBuilder builder, string uuid, Action <byte[]> onWrite) =>
 builder.AddCharacteristic(uuid, cb => cb.SetWrite(request =>
 {
     onWrite(request.Data);
     return(GattState.Success);
 }));
예제 #9
0
 public static IGattCharacteristic AddReadCharacteristic(this IGattServiceBuilder builder, string uuid, Func <byte[]> readRequest) =>
 builder.AddCharacteristic(uuid, cb => cb.SetRead(request => ReadResult.Success(readRequest())));