public override void OnServicesDiscovered(BluetoothGatt gatt, [GeneratedEnum] GattStatus status) { base.OnServicesDiscovered(gatt, status); if (status == GattStatus.Success) { if (!_commandQueue.Any()) { SubscribeToCharacteristic(GattMapper.UuidForType <GlucoseService>(), GattMapper.UuidForType <GlucoseMeasurement>()); AddCommand(GlucoseMeasurement.EnableNotifications()); SubscribeToCharacteristic(GattMapper.UuidForType <GlucoseService>(), GattMapper.UuidForType <GlucoseMeasurementContext>()); AddCommand(GlucoseMeasurementContext.EnableNotifications()); //always query all of the data upon a new connection to prevent data tampering. if (Autosync) { AddCommand(RecordAccessControlPoint.QueryAllRecords()); } } if (status == GattStatus.Success) { ExecuteNextCommand(); } else { ExecutePreviousCommand(); } } }
public static Command EnableNotifications() { return(new Command(CommandType.Write) { InteractionTarget = GattMapper.UuidForType <GlucoseMeasurement>(), Note = $"Enabling Notification Permissions for Glucose Measurements", Method = (server) => { var service = server.GetService(GattMapper.UuidForType <GlucoseService>()); var characteristic = service.GetCharacteristic(GattMapper.UuidForType <GlucoseMeasurement>()); var descriptor = characteristic.GetDescriptor(GattMapper.UuidForType <ClientCharacteristicConfiguration>()); descriptor.SetValue(BluetoothGattDescriptor.EnableNotificationValue.ToArray()); return server.WriteDescriptor(descriptor); } }); }
public static Command QueryAllRecords() { return(new Command(CommandType.Write) { InteractionTarget = GattMapper.UuidForType <RecordAccessControlPoint>(), Note = "Querying all records", Method = (server) => { var rcap = server.GetService(GattMapper.UuidForType <GlucoseService>()) ?.GetCharacteristic(GattMapper.UuidForType <RecordAccessControlPoint>()); if (rcap == null) { return false; } rcap.SetValue(new[] { OpcodeReportRecords, AllRecords }); return server.WriteCharacteristic(rcap); } }); }