@@ -19,7 +19,7 @@ def handle_sample(sample):
1919import timeit
2020import atexit
2121import logging
22- import threading
22+ import numpy as np
2323import sys
2424import pdb
2525import glob
@@ -329,7 +329,7 @@ def handleNotification(self, cHandle, data):
329329
330330 """
331331 PARSER:
332- Parses incoming data packet into OpenBCISample -- see docs.
332+ Parses incoming data packet into OpenBCISample -- see docs. Will call the corresponding parse* function depending on the format of the packet.
333333 """
334334 def parse (self , packet ):
335335 # bluepy returnds INT with python3 and STR with python2
@@ -374,18 +374,22 @@ def parseRaw(self, sample_id, packet):
374374 for i in range (0 ,12 ,3 ):
375375 chan_data .append (conv24bitsToInt (packet [i :i + 3 ]))
376376 # save uncompressed raw channel for future use and append whole sample
377- self .lastChannelData = chan_data
378377 sample = OpenBCISample (sample_id , chan_data , [])
379378 self .samples .append (sample )
379+ self .lastChannelData = chan_data
380380 self .updatePacketsCount (sample_id )
381381
382382 def parse19bit (self , sample_id , packet ):
383383 """ Dealing with "19-bit compression without Accelerometer" """
384384 # should get 2 by 4 arrays of uncompressed data
385- data = decompressDeltas19Bit (packet )
386- for d in data :
387- sample = OpenBCISample (sample_id , d , [])
385+ deltas = decompressDeltas19Bit (packet )
386+ for delta in deltas :
387+ # 19bit packets hold deltas between two samples
388+ # TODO: use more broadly numpy
389+ full_data = list (np .array (self .lastChannelData ) - np .array (delta ))
390+ sample = OpenBCISample (sample_id , full_data , [])
388391 self .samples .append (sample )
392+ self .lastChannelData = full_data
389393 self .updatePacketsCount (sample_id )
390394
391395 def updatePacketsCount (self , sample_id ):
@@ -460,7 +464,7 @@ def decompressDeltas19Bit(buffer):
460464 """
461465 Called to when a compressed packet is received.
462466 buffer: Just the data portion of the sample. So 19 bytes.
463- return {Array} - An array of deltas of shape 2x4 (2 samples per packet and 4 channels per sample.)
467+ return {Array} - An array of deltas of shape 2x4 (2 samples per packet and 4 channels per sample.)
464468 """
465469 if len (buffer ) != 19 :
466470 raise ValueError ("Input should be 19 bytes long." )
0 commit comments