コード例 #1
0
ファイル: BleStream.cs プロジェクト: karlo922/Testing_Changes
        public void WriteCccd(BleCharacteristic characteristic, BleCccd cccd, BleRequestFlags requestFlags)
        {
            Throw.If.Null(characteristic, "characteristic");

            BleDescriptor descriptor;

            if (!characteristic.TryGetDescriptor(BleUuids.Cccd, out descriptor))
            {
                HidSharpDiagnostics.Trace("Characteristic {0} does not have a CCCD, so {1} could not be written.", characteristic, cccd);
                return;
            }

            if (cccd == BleCccd.Notification)
            {
                HidSharpDiagnostics.PerformStrictCheck(characteristic.IsNotifiable, "Characteristic doesn't support Notify.");
            }

            if (cccd == BleCccd.Indication)
            {
                HidSharpDiagnostics.PerformStrictCheck(characteristic.IsIndicatable, "Characteristic doesn't support Indicate.");
            }


            var value = new byte[2];

            value[0] = (byte)((ushort)cccd >> 0);
            value[1] = (byte)((ushort)cccd >> 8);
            WriteDescriptor(descriptor, value);
        }
コード例 #2
0
ファイル: BleStream.cs プロジェクト: karlo922/Testing_Changes
        public BleCccd ReadCccd(BleCharacteristic characteristic, BleRequestFlags requestFlags)
        {
            BleDescriptor descriptor;

            if (!characteristic.TryGetDescriptor(BleUuids.Cccd, out descriptor))
            {
                HidSharpDiagnostics.Trace("Characteristic {0} does not have a CCCD, so it could not be read.", characteristic);
                return(BleCccd.None);
            }

            var value = ReadDescriptor(descriptor, requestFlags); var cccd = BleCccd.None;

            if (value.Length >= 1 && value[0] == (byte)BleCccd.Notification)
            {
                cccd = BleCccd.Notification;
            }
            if (value.Length >= 1 && value[0] == (byte)BleCccd.Indication)
            {
                cccd = BleCccd.Indication;
            }
            return(cccd);
        }