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(); }
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); }
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(); }
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); }
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)); }); } ); }
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); }));
public static IGattCharacteristic AddReadCharacteristic(this IGattServiceBuilder builder, string uuid, Func <byte[]> readRequest) => builder.AddCharacteristic(uuid, cb => cb.SetRead(request => ReadResult.Success(readRequest())));