Пример #1
0
        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
 public virtual IAsyncResult BeginWriteCharacteristicWithoutResponse(BleCharacteristic characteristic, byte[] value, int offset, int count, BleRequestFlags requestFlags,
                                                                     AsyncCallback callback, object state)
 {
     return(AsyncResult <int> .BeginOperation(delegate()
     {
         WriteCharacteristicWithoutResponse(characteristic, value, offset, count, requestFlags); return 0;
     }, callback, state));
 }
Пример #3
0
        public virtual bool TryGetCharacteristic(BleUuid uuid, out BleCharacteristic characteristic)
        {
            foreach (var c in GetCharacteristics())
            {
                if (c.Uuid == uuid)
                {
                    characteristic = c; return(true);
                }
            }

            characteristic = null; return(false);
        }
Пример #4
0
        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);
        }
Пример #5
0
 public BleEvent(BleCharacteristic characteristic, byte[] value)
 {
     _characteristic = characteristic; _value = value;
 }
Пример #6
0
 public IAsyncResult BeginWriteCharacteristicWithoutResponse(BleCharacteristic characteristic, byte[] value, int offset, int count,
                                                             AsyncCallback callback, object state)
 {
     return(BeginWriteCharacteristicWithoutResponse(characteristic, value, offset, count, RequestFlags, callback, state));
 }
Пример #7
0
 public abstract void WriteCharacteristicWithoutResponse(BleCharacteristic characteristic, byte[] value, int offset, int count, BleRequestFlags requestFlags);
Пример #8
0
 public void WriteCharacteristicWithoutResponse(BleCharacteristic characteristic, byte[] value, int offset, int count)
 {
     WriteCharacteristicWithoutResponse(characteristic, value, offset, count, RequestFlags);
 }
Пример #9
0
 public void WriteCharacteristicWithoutResponse(BleCharacteristic characteristic, byte[] value)
 {
     Throw.If.Null(value, "value");
     WriteCharacteristicWithoutResponse(characteristic, value, 0, value.Length);
 }
Пример #10
0
 public abstract byte[] ReadCharacteristic(BleCharacteristic characteristic, BleRequestFlags requestFlags);
Пример #11
0
 public byte[] ReadCharacteristic(BleCharacteristic characteristic)
 {
     return(ReadCharacteristic(characteristic, RequestFlags));
 }
Пример #12
0
 public void WriteCccd(BleCharacteristic characteristic, BleCccd cccd)
 {
     WriteCccd(characteristic, cccd, RequestFlags);
 }
Пример #13
0
 public BleCccd ReadCccd(BleCharacteristic characteristic)
 {
     return(ReadCccd(characteristic, RequestFlags));
 }