@@ -9,7 +9,7 @@ use bluer::{
9
9
use futures:: StreamExt ;
10
10
use simplelog:: * ;
11
11
use std:: sync:: Arc ;
12
- use std:: time:: Duration ;
12
+ use std:: time:: { Duration , Instant } ;
13
13
use tokio:: io:: AsyncReadExt ;
14
14
use tokio:: io:: AsyncWriteExt ;
15
15
use tokio:: sync:: Notify ;
@@ -250,10 +250,16 @@ async fn send_message(
250
250
Ok ( stream. write ( & packet) . await ?)
251
251
}
252
252
253
- async fn read_message ( stream : & mut Stream , stage : u8 , id : MessageId ) -> Result < usize > {
253
+ async fn read_message (
254
+ stream : & mut Stream ,
255
+ stage : u8 ,
256
+ id : MessageId ,
257
+ started : Instant ,
258
+ ) -> Result < usize > {
254
259
let mut buf = vec ! [ 0 ; HEADER_LEN ] ;
255
260
let n = stream. read_exact ( & mut buf) . await ?;
256
261
debug ! ( "received {} bytes: {:02X?}" , n, buf) ;
262
+ let elapsed = started. elapsed ( ) ;
257
263
258
264
let len: usize = u16:: from_be_bytes ( buf[ 0 ..=1 ] . try_into ( ) ?) . into ( ) ;
259
265
let message_id = u16:: from_be_bytes ( buf[ 2 ..=3 ] . try_into ( ) ?) ;
@@ -267,8 +273,12 @@ async fn read_message(stream: &mut Stream, stage: u8, id: MessageId) -> Result<u
267
273
. into ( ) ) ;
268
274
}
269
275
info ! (
270
- "{} 📨 stage #{} of {}: Received <yellow>{:?}</> frame from phone" ,
271
- NAME , stage, STAGES , id
276
+ "{} 📨 stage #{} of {}: Received <yellow>{:?}</> frame from phone (⏱️ {} ms)" ,
277
+ NAME ,
278
+ stage,
279
+ STAGES ,
280
+ id,
281
+ ( elapsed. as_secs( ) * 1_000 ) + ( elapsed. subsec_nanos( ) / 1_000_000 ) as u64 ,
272
282
) ;
273
283
274
284
// read and discard the remaining bytes
@@ -333,6 +343,7 @@ pub async fn bluetooth_setup_connection(
333
343
use WifiInfoResponse :: WifiInfoResponse ;
334
344
use WifiStartRequest :: WifiStartRequest ;
335
345
let mut stage = 1 ;
346
+ let mut started;
336
347
337
348
let ( state, mut stream) = power_up_and_wait_for_connection ( advertise, connect) . await ?;
338
349
@@ -342,7 +353,8 @@ pub async fn bluetooth_setup_connection(
342
353
start_req. set_port ( TCP_SERVER_PORT ) ;
343
354
send_message ( & mut stream, stage, MessageId :: WifiStartRequest , start_req) . await ?;
344
355
stage += 1 ;
345
- read_message ( & mut stream, stage, MessageId :: WifiInfoRequest ) . await ?;
356
+ started = Instant :: now ( ) ;
357
+ read_message ( & mut stream, stage, MessageId :: WifiInfoRequest , started) . await ?;
346
358
347
359
let mut info = WifiInfoResponse :: new ( ) ;
348
360
info. set_ssid ( String :: from ( WLAN_SSID ) ) ;
@@ -357,9 +369,11 @@ pub async fn bluetooth_setup_connection(
357
369
stage += 1 ;
358
370
send_message ( & mut stream, stage, MessageId :: WifiInfoResponse , info) . await ?;
359
371
stage += 1 ;
360
- read_message ( & mut stream, stage, MessageId :: WifiStartResponse ) . await ?;
372
+ started = Instant :: now ( ) ;
373
+ read_message ( & mut stream, stage, MessageId :: WifiStartResponse , started) . await ?;
361
374
stage += 1 ;
362
- read_message ( & mut stream, stage, MessageId :: WifiConnectStatus ) . await ?;
375
+ started = Instant :: now ( ) ;
376
+ read_message ( & mut stream, stage, MessageId :: WifiConnectStatus , started) . await ?;
363
377
tcp_start. notify_one ( ) ;
364
378
let _ = stream. shutdown ( ) . await ?;
365
379
0 commit comments