Skip to content

Commit b3d00d4

Browse files
committed
clean up load_reg / process row
added regions, and better var names
1 parent d79fdb7 commit b3d00d4

1 file changed

Lines changed: 38 additions & 21 deletions

File tree

classes/protocol_settings.py

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -389,12 +389,14 @@ def determine_delimiter(first_row) -> str:
389389

390390
def process_row(row):
391391
# Initialize variables to hold numeric and character parts
392-
numeric_part = 1
393-
character_part = ''
392+
unit_multiplier : float = 1
393+
unit_symbol : str = ''
394394

395395
#clean up doc name, for extra parsing
396396
row['documented name'] = row['documented name'].strip().lower().replace(' ', '_')
397397

398+
399+
#region overrides
398400
if overrides != None:
399401
#apply overrides using documented name or register
400402
override_row = None
@@ -412,21 +414,35 @@ def process_row(row):
412414
if override_value: # Only replace if override value is non-empty
413415
row[field] = override_value
414416

417+
#endregion overrides
418+
419+
#region unit
420+
415421
#if or is in the unit; ignore unit
416422
if "or" in row['unit'].lower() or ":" in row['unit'].lower():
417-
numeric_part = 1
418-
character_part = row['unit']
423+
unit_multiplier = 1
424+
unit_symbol = row['unit']
419425
else:
420426
# Use regular expressions to extract numeric and character parts
421427
matches = re.findall(r'(\-?[0-9.]+)|(.*?)$', row['unit'])
422428

423429
# Iterate over the matches and assign them to appropriate variables
424430
for match in matches:
425431
if match[0]: # If it matches a numeric part
426-
numeric_part = float(match[0])
432+
unit_multiplier = float(match[0])
427433
elif match[1]: # If it matches a character part
428-
character_part = match[1].strip()
429-
#print(str(row['documented name']) + " Unit: " + str(character_part) )
434+
unit_symbol = match[1].strip()
435+
436+
#convert to float
437+
try:
438+
unit_multiplier = float(unit_multiplier)
439+
except:
440+
unit_multiplier = float(1)
441+
442+
if unit_multiplier == 0:
443+
unit_multiplier = float(1)
444+
445+
#endregion unit
430446

431447

432448
variable_name = row['variable name'] if row['variable name'] else row['documented name']
@@ -435,21 +451,11 @@ def process_row(row):
435451
if re.search(r"[^a-zA-Z0-9\_]", variable_name) :
436452
self._log.warning("Invalid Name : " + str(variable_name) + " reg: " + str(row['register']) + " doc name: " + str(row['documented name']) + " path: " + str(path))
437453

438-
#convert to float
439-
try:
440-
numeric_part = float(numeric_part)
441-
except:
442-
numeric_part = float(1)
443454

444-
if numeric_part == 0:
445-
numeric_part = float(1)
446455

447-
data_type = Data_Type.USHORT
448456

449-
450-
if 'values' not in row:
451-
row['values'] = ""
452-
self._log.warning("No Value Column : path: " + str(path))
457+
#region data type
458+
data_type = Data_Type.USHORT
453459

454460
data_type_len : int = -1
455461
#optional row, only needed for non-default data types
@@ -461,7 +467,14 @@ def process_row(row):
461467
else:
462468
data_type = Data_Type.fromString(row['data type'])
463469

470+
471+
if 'values' not in row:
472+
row['values'] = ""
473+
self._log.warning("No Value Column : path: " + str(path))
464474

475+
#endregion data type
476+
477+
#region values
465478
#get value range for protocol analyzer
466479
values : list = []
467480
value_min : int = 0
@@ -511,7 +524,9 @@ def process_row(row):
511524

512525
if not matched: #single value
513526
values.append(row['values'])
527+
#endregion values
514528

529+
#region register
515530
concatenate : bool = False
516531
concatenate_registers : list[int] = []
517532

@@ -559,6 +574,8 @@ def process_row(row):
559574
else:
560575
r = range(1)
561576

577+
#endregion register
578+
562579
read_command = None
563580
if "read command" in row and row['read command']:
564581
if row['read command'][0] == 'x':
@@ -578,8 +595,8 @@ def process_row(row):
578595
register_byte= register_byte,
579596
variable_name= variable_name,
580597
documented_name = row['documented name'],
581-
unit= str(character_part),
582-
unit_mod= numeric_part,
598+
unit= str(unit_symbol),
599+
unit_mod= unit_multiplier,
583600
data_type= data_type,
584601
data_type_size = data_type_len,
585602
concatenate = concatenate,

0 commit comments

Comments
 (0)