@@ -65,7 +65,8 @@ def __init__(self, debug=False):
65
65
self ._last_packet_rcv_time = 0
66
66
self .is_bt_streaming = True
67
67
self .debug = debug
68
- self .is_unstable = False
68
+ self .unstablility_flag = False
69
+ self .last_bt_unstable_time = 0
69
70
70
71
def subscribe (self , callback , topic ):
71
72
"""Subscribe a function to a topic
@@ -331,14 +332,25 @@ def send_timestamp(self):
331
332
332
333
def update_bt_stability_status (self , current_timestamp ):
333
334
if 'board_id' in self .device_info .keys ():
335
+ if self ._last_packet_timestamp == 0 :
336
+ return
334
337
# device is an explore plus device, check sample timestamps
335
338
timestamp_diff = current_timestamp - self ._last_packet_timestamp
339
+
336
340
# allowed time interval is two samples
337
341
allowed_time_interval = np .round (2 * (1 / self .device_info ['sampling_rate' ]), 3 )
338
- self . is_unstable = timestamp_diff >= allowed_time_interval
342
+ is_unstable = timestamp_diff >= allowed_time_interval
339
343
else :
340
344
# devices is an old device, check if last sample has an earlier timestamp
341
- self .is_unstable = current_timestamp < self ._last_packet_timestamp
345
+ is_unstable = current_timestamp < self ._last_packet_timestamp
346
+
347
+ current_time = get_local_time ()
348
+ if is_unstable :
349
+ self .unstablility_flag = True
350
+ self .last_bt_unstable_time = current_time
351
+ else :
352
+ if current_time - self .last_bt_unstable_time > 10 :
353
+ self .unstablility_flag = False
342
354
343
355
def is_connection_unstable (self ):
344
- return self .is_unstable
356
+ return self .unstablility_flag
0 commit comments