Last active
December 31, 2015 07:18
-
-
Save cwoodall/7952754 to your computer and use it in GitHub Desktop.
Extract data from data_file which is a "binary string". Returns it in the format (Data[31 downto 8], Data[7 downto 0]) which is technically data, ADC channel... Created this after talking to Dean DeCarli.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import struct | |
from itertools import izip_longest | |
def grouper(n, iterable, fillvalue=None): | |
"grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx... From stackoverflow" | |
args = [iter(iterable)] * n | |
return izip_longest(fillvalue=fillvalue, *args) | |
# Extract data from data_file which is a "binary string". Returns it in the format (Data[31 downto 8], Data[7 downto 0]) | |
# which is technically data, ADC channel | |
data_file = "\x81\x82\x83\x01\x84\x85\x86\x02\x21\x30\xf1\x01" | |
[(h>>8, h&0xff) for i in grouper(4, data_file) for h in struct.unpack("!I",''.join(i))] | |
# Better solution | |
[struct.unpack("!IB",'\x00' + (''.join(i))) for i in grouper(4, data_file)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment