@@ -9,9 +9,6 @@ use embassy_futures::select::select;
99use microbit_bsp:: { ble:: MultiprotocolServiceLayer , Config , Microbit } ;
1010use trouble_host:: prelude:: * ;
1111
12- /// Size of L2CAP packets (ATT MTU is this - 4)
13- const L2CAP_MTU : usize = 251 ;
14-
1512/// Max number of connections
1613const CONNECTIONS_MAX : usize = 1 ;
1714
5956 let address = Address :: random ( [ 0x42 , 0x6A , 0xE3 , 0x1E , 0x83 , 0xE7 ] ) ;
6057 info ! ( "Our address = {:?}" , address) ;
6158
62- let mut resources: HostResources < CONNECTIONS_MAX , L2CAP_CHANNELS_MAX , L2CAP_MTU > = HostResources :: new ( ) ;
59+ let mut resources: HostResources < DefaultPacketPool , CONNECTIONS_MAX , L2CAP_CHANNELS_MAX > = HostResources :: new ( ) ;
6360 let stack = trouble_host:: new ( controller, & mut resources) . set_random_address ( address) ;
6461 let Host {
6562 mut peripheral, runner, ..
8986}
9087
9188/// This is a background task that is required to run forever alongside any other BLE tasks.
92- async fn ble_task < C : Controller > ( mut runner : Runner < ' _ , C > ) -> Result < ( ) , BleHostError < C :: Error > > {
89+ async fn ble_task < C : Controller , P : PacketPool > ( mut runner : Runner < ' _ , C , P > ) -> Result < ( ) , BleHostError < C :: Error > > {
9390 runner. run ( ) . await
9491}
9592
@@ -98,9 +95,9 @@ async fn ble_task<C: Controller>(mut runner: Runner<'_, C>) -> Result<(), BleHos
9895/// Create an advertiser to use to connect to a BLE Central, and wait for it to connect.
9996async fn advertise < ' a , ' b , C : Controller > (
10097 name : & ' a str ,
101- peripheral : & mut Peripheral < ' a , C > ,
98+ peripheral : & mut Peripheral < ' a , C , DefaultPacketPool > ,
10299 server : & ' b Server < ' _ > ,
103- ) -> Result < GattConnection < ' a , ' b > , BleHostError < C :: Error > > {
100+ ) -> Result < GattConnection < ' a , ' b , DefaultPacketPool > , BleHostError < C :: Error > > {
104101 let mut advertiser_data = [ 0 ; 31 ] ;
105102 AdStructure :: encode_slice (
106103 & [
@@ -127,7 +124,7 @@ async fn advertise<'a, 'b, C: Controller>(
127124
128125/// This function will handle the GATT events and process them.
129126/// This is how we interact with read and write requests.
130- async fn connection_task ( server : & Server < ' _ > , conn : & GattConnection < ' _ , ' _ > ) {
127+ async fn connection_task < P : PacketPool > ( server : & Server < ' _ > , conn : & GattConnection < ' _ , ' _ , P > ) {
131128 let level = server. battery_service . level ;
132129 unwrap ! ( level. set( server, & 42 ) ) ;
133130 loop {
@@ -136,16 +133,13 @@ async fn connection_task(server: &Server<'_>, conn: &GattConnection<'_, '_>) {
136133 info ! ( "[gatt] disconnected: {:?}" , reason) ;
137134 break ;
138135 }
139- GattConnectionEvent :: Gatt { event } => match event {
140- // Server processing emits
141- Ok ( event) => {
142- if let Ok ( reply) = event. accept ( ) {
143- reply. send ( ) . await ;
144- }
136+ GattConnectionEvent :: Gatt { event } => {
137+ match event. accept ( ) {
138+ Ok ( reply) => reply. send ( ) . await ,
139+ Err ( e) => warn ! ( "[gatt] error sending response: {:?}" , e)
145140 }
146- Err ( e) => warn ! ( "[gatt] error processing event: {:?}" , e) ,
147141 }
148- _ => ( ) ,
142+ _ => { }
149143 }
150144 }
151145 info ! ( "[gatt] task finished" ) ;
0 commit comments