コード例 #1
0
ファイル: GattCharacteristic.cs プロジェクト: shinyorg/shiny
        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);
        }
コード例 #2
0
    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
        }
    }
コード例 #3
0
ファイル: GattCharacteristic.cs プロジェクト: shinyorg/shiny
        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);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: wujiaze/Test
        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();
        }
コード例 #5
0
ファイル: GattCharacteristic.cs プロジェクト: shinyorg/shiny
        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);
        }
コード例 #6
0
    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
        }
    }
コード例 #7
0
 public static BLECharacteristicProperty ToShared(this CBCharacteristicProperties properties)
 => (BLECharacteristicProperty)properties;