Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into brukeropus/master
Browse files Browse the repository at this point in the history
  • Loading branch information
joshduran committed May 13, 2024
2 parents 12c79aa + 29baa04 commit e20c07b
Show file tree
Hide file tree
Showing 7 changed files with 855 additions and 576 deletions.
21 changes: 12 additions & 9 deletions brukeropus/file/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,10 @@ class FileBlockInfo:
start: pointer to start location of the block within the file
keys: tuple of three char keys contained in parameter blocks. This attribute is set by the OPUSFile class only
when the block is parameter block. This enables grouping parameters by block if desired.
bytes: raw bytes of file block (currently only set for unknown blocks)
'''

__slots__ = ('type', 'size', 'start', 'keys')
__slots__ = ('type', 'size', 'start', 'keys', 'bytes')

keys: tuple

Expand All @@ -176,10 +177,6 @@ def __str__(self):
label = self.get_label()
return 'Block Info: ' + label + ' (size: ' + str(self.size) + ' bytes; start: ' + str(self.start) + ')'

def is_valid(self):
'''Returns False if FileBlockInfo is undefined (i.e. FileBlockInfo.type == (0, 0, 0, 0, 0, 0))'''
return self.type != (0, 0, 0, 0, 0, 0)

def is_data_status(self):
'''Returns True if FileBlockInfo is a data status parameter block'''
return self.type[2] == 1
Expand All @@ -190,7 +187,7 @@ def is_rf_param(self):

def is_param(self):
'''Returns True if FileBlockInfo is a parameter block'''
return self.type[2] > 1
return self.type[2] > 1 or self.type == (0, 0, 0, 0, 0, 1)

def is_directory(self):
'''Returns True if FileBlockInfo is the directory block'''
Expand All @@ -202,7 +199,7 @@ def is_file_log(self):

def is_data(self):
'''Returns True if FileBlockInfo is a data block or 3D data block'''
return self.type[2] == 0 and self.type[3] > 0 and self.type[3] != 13
return self.type[0] > 0 and self.type[1] > 0 and self.type[2] == 0 and self.type[3] > 0

def is_3d_data(self):
'''Returns True if FileBlockInfo is a 3D data block (i.e. data series)'''
Expand Down Expand Up @@ -466,10 +463,12 @@ class FileDirectory:
file_log_block: `FileBlockInfo` of the file log (changes, etc.)
data_and_status_block_pairs: (data: `FileBlockInfo`, data_status: `FileBlockInfo`) which pairs the data status
parameter block (time, x units, y units, etc.) with the data block it informs
unknown_blocks: list of `FileBlockInfo` with an unrecognized type (i.e. not sure how to parse)
'''

__slots__ = ('version', 'start', 'max_blocks', 'num_blocks', 'data_blocks', 'data_status_blocks', 'param_blocks',
'rf_param_blocks', 'directory_block', 'file_log_block', 'data_and_status_block_pairs')
'rf_param_blocks', 'directory_block', 'file_log_block', 'data_and_status_block_pairs',
'unknown_blocks')

def __init__(self, filebytes: bytes):
self.version, self.start, self.max_blocks, self.num_blocks = parse_header(filebytes)
Expand All @@ -479,6 +478,7 @@ def __init__(self, filebytes: bytes):
self.rf_param_blocks: list = []
self.directory_block: FileBlockInfo
self.file_log_block: FileBlockInfo
self.unknown_blocks: list = []
for block_type, size, start in parse_directory(filebytes, self.start, self.num_blocks):
block = FileBlockInfo(block_type=block_type, size=size, start=start)
if block.is_data_status():
Expand All @@ -491,8 +491,11 @@ def __init__(self, filebytes: bytes):
self.directory_block = block
elif block.is_file_log():
self.file_log_block = block
elif block.is_valid():
elif block.is_data():
self.data_blocks.append(block)
else:
block.bytes = filebytes[block.start:block.start + block.size]
self.unknown_blocks.append(block)
self.data_and_status_block_pairs = []
self._pair_data_and_status_blocks()

Expand Down
10 changes: 5 additions & 5 deletions brukeropus/file/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def _parse_block_and_print(filebytes, block_info, width):
param_col_labels = ('Key', 'Friendly Name', 'Value')
if block_info[0] != (0, 0, 0, 13, 0, 0):
_print_block_header(get_block_type_label(block_info[0]), width)
if block_info[0][2] > 0:
if block_info[0][2] > 0 or block_info[0] == (0, 0, 0, 0, 0, 1):
_print_cols(param_col_labels, param_col_widths)
for key, val in parse_param_block(filebytes, block_info[1], block_info[2]):
_print_cols((key, get_param_label(key), val), param_col_widths)
Expand All @@ -213,12 +213,12 @@ def _parse_block_and_print(filebytes, block_info, width):
_print_centered('Num Blocks: ' + str(data['num_blocks']), width)
_print_centered('Store Table: ' + str(data['store_table']), width)
print(data['y'])
elif block_info[0] == (0, 0, 0, 0, 0, 0):
_print_centered('Undefined Block Type: Raw Bytes', width)
print(filebytes[block_info[1]: block_info[1] + block_info[2]])
else:
elif block_info[0][0] > 0 and block_info[0][1] > 0 and block_info[0][2] == 0 and block_info[0][3] > 0:
array = parse_data_block(filebytes, block_info[1], block_info[2])
print(array)
else:
_print_centered('Undefined Block Type: Raw Bytes', width)
print(filebytes[block_info[2]: block_info[2] + block_info[1]])


def _print_cols(vals, col_widths,):
Expand Down
4 changes: 4 additions & 0 deletions docs/brukeropus/control/dde.html
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,11 @@ <h1 class="modulename">
<div class="attr function">

<span class="def">def</span>
<<<<<<< HEAD
<span class="name">get_winfunc</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="n">libname</span>,</span><span class="param"> <span class="n">funcname</span>,</span><span class="param"> <span class="n">restype</span><span class="o">=</span><span class="kc">None</span>,</span><span class="param"> <span class="n">argtypes</span><span class="o">=</span><span class="p">()</span>,</span><span class="param"> <span class="n">_libcache</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;user32&#39;</span><span class="p">:</span> <span class="o">&lt;</span><span class="n">WinDLL</span> <span class="s1">&#39;user32&#39;</span><span class="p">,</span> <span class="n">handle</span> <span class="mi">7</span><span class="n">fffa9710000</span><span class="o">&gt;</span><span class="p">}</span></span><span class="return-annotation">):</span></span>
=======
<span class="name">get_winfunc</span><span class="signature pdoc-code multiline">(<span class="param"> <span class="n">libname</span>,</span><span class="param"> <span class="n">funcname</span>,</span><span class="param"> <span class="n">restype</span><span class="o">=</span><span class="kc">None</span>,</span><span class="param"> <span class="n">argtypes</span><span class="o">=</span><span class="p">()</span>,</span><span class="param"> <span class="n">_libcache</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;user32&#39;</span><span class="p">:</span> <span class="o">&lt;</span><span class="n">WinDLL</span> <span class="s1">&#39;user32&#39;</span><span class="p">,</span> <span class="n">handle</span> <span class="mi">7</span><span class="n">fff631d0000</span><span class="o">&gt;</span><span class="p">}</span></span><span class="return-annotation">):</span></span>
>>>>>>> origin/master

<label class="view-source-button" for="get_winfunc-view-source"><span>View Source</span></label>

Expand Down
Loading

0 comments on commit e20c07b

Please sign in to comment.