You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Checking connection -- timeout and packets dropped
222
227
self.check_connection()
223
-
224
228
225
229
226
230
"""
@@ -239,7 +243,7 @@ def disconnect(self):
239
243
if(self.streaming==True):
240
244
self.stop()
241
245
print("Closing BLE..")
242
-
self.char_discon.write(' ')
246
+
self.char_discon.write(b' ')
243
247
# should not try to read/write anything after that, will crash
244
248
self.gang.disconnect()
245
249
logging.warning('BLE closed')
@@ -260,37 +264,37 @@ def warn(self, text):
260
264
print("Warning: %s"%text)
261
265
262
266
defcheck_connection(self):
267
+
""" Check connection quality in term of lag and number of packets drop. Reinit connection if necessary. FIXME: parameters given to the board will be lost."""
263
268
# stop checking when we're no longer streaming
264
269
ifnotself.streaming:
265
270
return
266
271
#check number of dropped packets and duration without new packets, deco/reco if too large
267
272
ifself.packets_dropped>self.max_packets_to_skip:
268
273
self.warn("Too many packets dropped, attempt to reconnect")
self.warn("Too long since got new data, attempt to reconnect")
271
277
#if error, attempt to reconect
272
278
self.reconnect()
273
279
274
280
defreconnect(self):
281
+
""" In case of poor connection, will shut down and relaunch everything. FIXME: parameters given to the board will be lost."""
275
282
self.warn('Reconnecting')
276
283
self.stop()
277
-
time.sleep(0.5)
278
-
self.ser.write(b'b')
279
-
self.streaming=True
280
-
self.packets_dropped=0
281
-
self.time_last_packet=timeit.default_timer()
282
-
284
+
self.disconnect()
285
+
self.connect()
286
+
self.init_steaming()
283
287
284
288
classOpenBCISample(object):
285
-
"""Object encapulsating a single sample from the OpenBCI board."""
289
+
"""Object encapulsating a single sample from the OpenBCI board. Note for Ganglion board: since most of the time two samples are compressed in one BLE packet, two consecutive samples will likely have the same ID."""
0 commit comments