@@ -19,7 +19,7 @@ struct Client {
1919
2020/// A table of CCCD values.
2121#[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
22- #[ derive( Clone ) ]
22+ #[ derive( Clone , Debug ) ]
2323pub struct CccdTable < const ENTRIES : usize > {
2424 inner : [ ( u16 , CCCD ) ; ENTRIES ] ,
2525}
@@ -33,6 +33,16 @@ impl<const ENTRIES: usize> Default for CccdTable<ENTRIES> {
3333}
3434
3535impl < const ENTRIES : usize > CccdTable < ENTRIES > {
36+ /// Create a new CCCD table from an array of (handle, cccd) pairs.
37+ pub fn new ( cccd_values : [ ( u16 , CCCD ) ; ENTRIES ] ) -> Self {
38+ Self { inner : cccd_values }
39+ }
40+
41+ /// Get the inner array of (handle, cccd) pairs.
42+ pub fn inner ( & self ) -> & [ ( u16 , CCCD ) ; ENTRIES ] {
43+ & self . inner
44+ }
45+
3646 fn add_handle ( & mut self , cccd_handle : u16 ) {
3747 for ( handle, _) in self . inner . iter_mut ( ) {
3848 if * handle == 0 {
@@ -198,6 +208,19 @@ impl<M: RawMutex, const CCCD_MAX: usize, const CONN_MAX: usize> CccdTables<M, CC
198208 None
199209 } )
200210 }
211+
212+ fn set_cccd_table ( & self , peer_address : & BdAddr , table : CccdTable < CCCD_MAX > ) {
213+ self . state . lock ( |n| {
214+ let mut n = n. borrow_mut ( ) ;
215+ for ( client, t) in n. iter_mut ( ) {
216+ if client. address == * peer_address {
217+ trace ! ( "Setting cccd table {:?} for {:?}" , table, peer_address) ;
218+ * t = table;
219+ break ;
220+ }
221+ }
222+ } )
223+ }
201224}
202225
203226/// A GATT server capable of processing the GATT protocol using the provided table of attributes.
@@ -700,8 +723,13 @@ impl<'values, M: RawMutex, const ATT_MAX: usize, const CCCD_MAX: usize, const CO
700723 & self . att_table
701724 }
702725
703- /// Get a reference to the CCCD tables
704- pub fn cccd_tables ( & self , connection : & Connection ) -> Option < CccdTable < CCCD_MAX > > {
726+ /// Get the CCCD table for a connection
727+ pub fn get_cccd_table ( & self , connection : & Connection ) -> Option < CccdTable < CCCD_MAX > > {
705728 self . cccd_tables . get_cccd_table ( & connection. peer_address ( ) )
706729 }
730+
731+ /// Set the CCCD table for a connection
732+ pub fn set_cccd_table ( & self , connection : & Connection , table : CccdTable < CCCD_MAX > ) {
733+ self . cccd_tables . set_cccd_table ( & connection. peer_address ( ) , table) ;
734+ }
707735}
0 commit comments