Skip to content

Commit 52c1ec0

Browse files
Ivorforcegitrust
authored andcommitted
Add some stability fixes for files that are missing information.
1 parent 9b82938 commit 52c1ec0

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

scpformat.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def __init__(self, tags):
1414

1515
def format_tag_int(self, tag, start, end):
1616
for _tag in self.tags:
17-
if _tag.tag == tag:
17+
if _tag.tag == tag and _tag.data is not None:
1818
return b2i(_tag.data[start:end])
1919
return ''
2020

@@ -28,7 +28,7 @@ def get_tag(self, id):
2828
def format_tag(self, tag):
2929
"""Format given tag"""
3030
for _tag in self.tags:
31-
if _tag.tag == tag:
31+
if _tag.tag == tag and _tag.data is not None:
3232
return bdecode(_tag.data)
3333
return ''
3434

@@ -81,12 +81,14 @@ def format(self, printer):
8181
printer.p('LowPass Filter', self.format_tag_int(28, 0, 2))
8282
FilterBitMapFormatter(self.tag_data(29)).format(printer)
8383
for t in self.tag_list(30):
84-
printer.p('Text', bdecode(t.data))
84+
if t.data is not None:
85+
printer.p('Text', bdecode(t.data))
8586
printer.p('Ecg Seq.', self.format_tag(31))
8687
ElectrodeConfigFormatter(self.tag_data(33)).format(printer)
8788
DateTimeZoneFormatter(self.tag_data(34)).format(printer)
8889
for t in self.tag_list(35):
89-
printer.p('Med. History', bdecode(t.data))
90+
if t.data is not None:
91+
printer.p('Med. History', bdecode(t.data))
9092

9193

9294
# Lead Format
@@ -337,17 +339,23 @@ def __init__(self, bytes):
337339
self.devId = b2i(bytes[4:4])
338340
self.devType = b2i(bytes[6:6])
339341
self.model = bdecode(bytes[9:14])
342+
else:
343+
self.instNr = ''
344+
self.depNr = ''
345+
self.devId = ''
346+
self.devType = ''
347+
self.model = ''
340348

341349
def __str__(self):
342350
return '--'
343351

344352
def format(self, printer):
345353
printer.p('Acq. Device MachineID', '----')
346-
printer.p('InstNr', self.instNr)
347-
printer.p('DepNr', self.depNr)
348-
printer.p('DevId', self.devId)
349-
printer.p('DevType', self.devType)
350-
printer.p('Model', self.model)
354+
printer.p('InstNr', self.instNr or '<missing>')
355+
printer.p('DepNr', self.depNr or '<missing>')
356+
printer.p('DevId', self.devId or '<missing>')
357+
printer.p('DevType', self.devType or '<missing>')
358+
printer.p('Model', self.model or '<missing>')
351359
printer.p('', '----')
352360

353361

@@ -378,7 +386,7 @@ def format_section0(s0, printer):
378386
# section 0
379387
printer.p('--Section0--', '----')
380388
format_header(s0.h, printer)
381-
389+
382390
printer.p('Pointer Count', len(s0.p))
383391
printer.p('Pointers', ', '.join(str(p) for p in s0.p))
384392

@@ -504,7 +512,7 @@ def format_section7(s7, printer):
504512
def format_section4(s, printer):
505513
if not s.p.section_has_data():
506514
return
507-
515+
508516
print()
509517
printer.p('--Section4--', '----')
510518
format_header(s.h, printer)
@@ -528,7 +536,7 @@ def format_section_default(s, section_id, printer):
528536
print()
529537
printer.p('--Section' + str(section_id) + '--', '----')
530538
format_header(s.h, printer)
531-
539+
532540
def format_header(h, printer):
533541
printer.p('--Header--', '----')
534542
printer.p('CRC', h.crc)

0 commit comments

Comments
 (0)