private void ConvertAttributesToCharacteristics(BlePeripheralService service)
        {
            #region Example attr table

//			*=== Service: 42 48 12 4a 7f 2c 48 47 b9 de 04 a9 02 00 06 d5
//			*====== Att: 26 - 00 28
//			*====== Att: 27 - 03 28
//			*====== Att: 28 - 42 48 12 4a 7f 2c 48 47 b9 de 04 a9 02 04 06 d5
//			*====== Att: 29 - 02 29
//			*====== Att: 30 - 03 28
//			*====== Att: 31 - 42 48 12 4a 7f 2c 48 47 b9 de 04 a9 02 05 06 d5
//			*====== Att: 32 - 02 29

            #endregion

            BlePeripheralCharacteristic current = null;
            bool createCharacteristic           = false;

            foreach (BlePeripheralAttribute attr in service.Attributes)
            {
                if (attr.AttributeUUID.Equals(BlePeripheralAttribute.SERVICE_UUID))
                {
                    // defines service - do nothing
                }
                else if (attr.AttributeUUID.Equals(BlePeripheralAttribute.CHARACTERISTIC_UUID))
                {
                    // finish previous characteristic
                    current = null;

                    // crete characteristic from next attribute
                    createCharacteristic = true;
                }
                else if (attr.AttributeUUID.Equals(BlePeripheralAttribute.CHARACTERISTIC_CCC_UUID))
                {
                    // add ccc capabilities to characteristic
                    current.SetCCCHandle(attr.Handle);
                }
                else
                {
                    // if new characteristic begins - create it else skip and do nothing
                    if (createCharacteristic)
                    {
                        current = new BlePeripheralCharacteristic(attr.AttributeUUID, attr.Handle);
                        createCharacteristic = false;

                        service.Characteristics.Add(current);
                    }
                }
            }
        }
Пример #2
0
        public void WriteClientCharacteristicConfiguration(Bytes uuid, BleCCCValue value)
        {
            BlePeripheralCharacteristic characteristic = this.PeripheralMap.FindCharacteristicByUUID(uuid);

            if (!characteristic.HasCCC)
            {
                throw new ArgumentException($"Client characteristic {uuid} doesn't have a configuration attribute!");
            }

            ByteSerializer bs = new ByteSerializer();

            bs.Serialize(value);

            ushort attrHandle = characteristic.HandleCCC;

            this.WriteAttribute(attrHandle, bs.GetBuffer());
        }
Пример #3
0
        public BleCCCValue ReadClientCharacteristicConfiguration(Bytes uuid)
        {
            BleCCCValue ccc;

            BlePeripheralCharacteristic characteristic = this.PeripheralMap.FindCharacteristicByUUID(uuid);

            if (!characteristic.HasCCC)
            {
                throw new ArgumentException("Client characteristic {uuid} doesn't have a configuration attribute!");
            }

            ushort attrHandle = characteristic.HandleCCC;
            Bytes  rawValue   = this.ReadAttribute(attrHandle);

            using (ByteDeserializer bd = new ByteDeserializer(rawValue))
            {
                ccc = bd.DeSerializeBleCCValue();
            }

            return(ccc);
        }