Commit 22351ff7 authored by Javier Quinteros's avatar Javier Quinteros
Browse files

Parse data. Still needs to be checked.

parent cf33053b
......@@ -79,6 +79,9 @@ def main():
if ((ToCmask & kTocMetaData) and not dataOffset):
logs.error('Flag indicates Metadata but its length is 0!')
if (ToCmask & kTocDAQmxRawData):
logs.warning('DAQmx raw data is still not supported!')
logs.info((tag, ToCmask, version, segmentOffset, dataOffset))
# Metadata
......@@ -86,9 +89,12 @@ def main():
numObjects = struct.unpack('%cI' % endian, fi.read(4))[0]
logs.info('Number of objects in metadata: %s' % numObjects)
numChannels = 0
chunkSize = 0
for obj in range(numObjects):
channelSize = 0
objPath = readstring(fi, endian)
logs.info('Object %s: %s' % (obj, objPath))
logs.debug('Object %s: %s' % (obj, objPath))
rawDataIdx = struct.unpack('%cI' % endian, fi.read(4))[0]
......@@ -100,6 +106,7 @@ def main():
logs.info('Raw data index in this segment matches the index the same object had in the previous segment')
else:
numChannels = numChannels + 1
# There is raw data!
sizeBytes = None
datatype, arraylen, numValues = struct.unpack('%cIIQ' % endian, fi.read(16))
......@@ -109,11 +116,42 @@ def main():
if arraylen != 1:
logs.error('Array length MUST be 1! Actual value: %s' % arraylen)
logs.debug('rawDataIdx %s; datatype: %s; numValues: %s' % (rawDataIdx, datatype, numValues))
# logs.debug('obj %s; datatype: %s; numValues: %s; size: %s' % (obj, datatype, numValues,
# data2mask[datatype][1]*numValues))
channelSize = channelSize + data2mask[datatype][1]*numValues
readproperties(fi, endian)
print(fi.tell())
logs.debug('channelSize: %s bytes' % channelSize)
chunkSize = chunkSize + channelSize
samples = int((segmentOffset - dataOffset)/numChannels/data2mask[datatype][1])
logs.info('chunkSize: %s bytes' % chunkSize)
logs.info('Total chunks size: %s' % (segmentOffset - dataOffset))
logs.info('Length of channel: %d' % ((segmentOffset - dataOffset)/numChannels/data2mask[datatype][1]))
# New or changed objects
newObjects = struct.unpack('%cI' % endian, fi.read(4))[0]
# Got to the beginning of the raw data
fi.seek(dataOffset + HEADERLEN, 0)
result = readdata(fi, data2mask[datatype][0], data2mask[datatype][1], samples, ToCmask & kTocInterleavedData,
numChannels, endian)
print(result)
def readdata(fi, datatype, datasize, samples, interleaved, numChannels, endian='<'):
if not interleaved:
# Read from first channel
result = struct.unpack('%c%s' % (endian, datatype*samples), fi.read(datasize*samples))
result = list(result)
else:
result = list()
for ch in range(samples):
# Read from first channel (0)
result.append(struct.unpack('%c%s' % (endian, datatype*numChannels), fi.read(datasize*numChannels))[0])
return result
def readproperties(fi, endian='<'):
logs = logging.getLogger('readproperties')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment