@@ -19,6 +19,7 @@ public sealed class GattLocalCharacteristic
1919 // Each Characteristic will have unique _CharacteristicId for event lookup
2020 internal ushort _characteristicId ;
2121
22+ private ushort _descriptorNextID ;
2223 private readonly byte [ ] _characteristicUuid ;
2324 private readonly GattProtectionLevel _writeProtectionLevel ;
2425 private readonly GattProtectionLevel _readProtectionLevel ;
@@ -71,6 +72,8 @@ internal GattLocalCharacteristic(Guid characteristicUuid, GattLocalCharacteristi
7172
7273 // Give it next id
7374 _characteristicId = NextCharacteristicIndex ( ) ;
75+ // Start at 1 for descriptors
76+ _descriptorNextID = 1 ;
7477
7578 _userDescription = parameters . UserDescription ;
7679 if ( ! string . IsNullOrEmpty ( _userDescription ) )
@@ -82,7 +85,7 @@ internal GattLocalCharacteristic(Guid characteristicUuid, GattLocalCharacteristi
8285 dr . WriteString ( _userDescription ) ;
8386 dp . StaticValue = dr . DetachBuffer ( ) ;
8487
85- _userDescriptionDescriptor = new GattLocalDescriptor ( GattDescriptorUuids . CharacteristicUserDescription , dp , this ) ;
88+ _userDescriptionDescriptor = new GattLocalDescriptor ( GattDescriptorUuids . CharacteristicUserDescription , dp , this , _descriptorNextID ++ ) ;
8689 }
8790
8891 _presentationFormats = new ArrayList ( ) ;
@@ -103,7 +106,7 @@ internal GattLocalCharacteristic(Guid characteristicUuid, GattLocalCharacteristi
103106 GattLocalDescriptorParameters dp = new GattLocalDescriptorParameters ( ) ;
104107 dp . StaticValue = dr . DetachBuffer ( ) ;
105108
106- _presentationFormatsDescriptors . Add ( new GattLocalDescriptor ( GattDescriptorUuids . CharacteristicPresentationFormat , dp , this ) ) ;
109+ _presentationFormatsDescriptors . Add ( new GattLocalDescriptor ( GattDescriptorUuids . CharacteristicPresentationFormat , dp , this , _descriptorNextID ++ ) ) ;
107110 }
108111
109112 // Register with Events
@@ -147,8 +150,8 @@ public GattLocalDescriptorResult CreateDescriptor(Guid descriptorUuid, GattLocal
147150
148151 if ( result == BluetoothError . Success )
149152 {
150- decriptor = new GattLocalDescriptor ( descriptorUuid , parameters , this ) ;
151- _descriptors . Add ( new GattLocalDescriptor ( descriptorUuid , parameters , this ) ) ;
153+ decriptor = new GattLocalDescriptor ( descriptorUuid , parameters , this , _descriptorNextID ++ ) ;
154+ _descriptors . Add ( decriptor ) ;
152155 }
153156
154157 return new GattLocalDescriptorResult ( decriptor , result ) ;
@@ -262,15 +265,16 @@ internal void OnReadRequested(ushort descritorId, GattReadRequestedEventArgs e)
262265 bool handled = false ;
263266
264267 // Static value for Characteristic ?
265- if ( _staticValue != null && descritorId == 0 )
268+ int descritorIndex = ( descritorId >> 8 ) ;
269+ if ( _staticValue != null && descritorIndex == 0 )
266270 {
267271 handled = true ;
268272 // Handle static values internally, don't fire an event
269273 DataWriter writer = new DataWriter ( ) ;
270274 writer . WriteBuffer ( _staticValue ) ;
271275 e . GetRequest ( ) . RespondWithValue ( _staticValue ) ;
272276 }
273- else if ( descritorId != 0 )
277+ else if ( descritorIndex != 0 )
274278 {
275279 // Descriptor event, let descriptor handle it
276280 GattLocalDescriptor des = FindDescriptor ( descritorId ) ;
@@ -299,8 +303,10 @@ internal void OnWriteRequested(ushort descritorId, GattWriteRequestedEventArgs e
299303
300304 if ( WriteRequested != null )
301305 {
306+ int descritorIndex = ( descritorId >> 8 ) ;
307+
302308 // LocalCharacteristic event ?
303- if ( descritorId == 0 )
309+ if ( descritorIndex == 0 )
304310 {
305311 handled = true ;
306312 WriteRequested ? . Invoke ( this , e ) ;
0 commit comments