public IGattCharacteristicBuilder SetRead(Func <ReadRequest, ReadResult> request, bool encrypted = false) { this.onRead = request; this.permissions |= encrypted ? CBAttributePermissions.ReadEncryptionRequired : CBAttributePermissions.Readable; this.properties |= CBCharacteristicProperties.Read; return(this); }
public static void CreateCharacteristic(string uuid, CBCharacteristicProperties properties, CBAttributePermissions permissions, byte[] data, int length, Action <string, byte[]> action) { if (!Application.isEditor) { if (bluetoothDeviceScript != null) { bluetoothDeviceScript.PeripheralReceivedWriteDataAction = action; } #if UNITY_IPHONE _iOSBluetoothLECreateCharacteristic(uuid, (int)properties, (int)permissions, data, length); #endif } }
public IGattCharacteristicBuilder SetNotification(Action <CharacteristicSubscription> onSubscribe = null, NotificationOptions options = NotificationOptions.Notify) { this.onSubscribe = onSubscribe; var enc = options.HasFlag(NotificationOptions.EncryptionRequired); if (options.HasFlag(NotificationOptions.Indicate)) { this.properties |= enc ? CBCharacteristicProperties.IndicateEncryptionRequired : CBCharacteristicProperties.Indicate; } if (options.HasFlag(NotificationOptions.Notify)) { this.properties |= enc ? CBCharacteristicProperties.NotifyEncryptionRequired : CBCharacteristicProperties.Notify; } return(this); }
static void Main(string[] args) { byte b = 200; string str = string.Format("{0:X2}", b); // 转换成16进制输出 Console.WriteLine(str); CBCharacteristicProperties xx = CBCharacteristicProperties.CBCharacteristicPropertyRead | CBCharacteristicProperties.CBCharacteristicPropertyWrite | CBCharacteristicProperties.CBCharacteristicPropertyNotify; Console.WriteLine(CBCharacteristicProperties.CBCharacteristicPropertyRead); Console.WriteLine(CBCharacteristicProperties.CBCharacteristicPropertyWrite); Console.WriteLine(CBCharacteristicProperties.CBCharacteristicPropertyNotify); Console.WriteLine(xx); Program p1 = new Program(); foreach (var VARIABLE in p1) { Console.WriteLine(VARIABLE); } Console.ReadLine(); }
public IGattCharacteristicBuilder SetWrite(Func <WriteRequest, GattState> request, WriteOptions options = WriteOptions.Write) { this.onWrite = request; this.permissions |= options.HasFlag(WriteOptions.EncryptionRequired) ? CBAttributePermissions.WriteEncryptionRequired : CBAttributePermissions.Writeable; if (options.HasFlag(WriteOptions.Write)) { this.properties |= CBCharacteristicProperties.Write; } if (options.HasFlag(WriteOptions.WriteWithoutResponse)) { this.properties |= CBCharacteristicProperties.WriteWithoutResponse; } if (options.HasFlag(WriteOptions.AuthenticatedSignedWrites)) { this.properties |= CBCharacteristicProperties.AuthenticatedSignedWrites; } return(this); }
public static void CreateCharacteristic(string uuid, CBCharacteristicProperties properties, CBAttributePermissions permissions, byte[] data, int length, Action<string, byte[]> action) { if (!Application.isEditor) { if (bluetoothDeviceScript != null) bluetoothDeviceScript.PeripheralReceivedWriteDataAction = action; #if UNITY_IPHONE _iOSBluetoothLECreateCharacteristic (uuid, (int)properties, (int)permissions, data, length); #endif } }
public static BLECharacteristicProperty ToShared(this CBCharacteristicProperties properties) => (BLECharacteristicProperty)properties;