|
10 | 10 | lines = open(ecspy_log).readlines()
|
11 | 11 | gpio_data = {}
|
12 | 12 |
|
13 |
| -# Regular expression to parse each line |
14 |
| -line_re = re.compile(r"([A-M]\d): data (\d) mirror (\d) pot (\d) control ([0-9A-Fa-f]{2})") |
| 13 | +# returns a list of positions of bits set to 1 in the integer |
| 14 | +def int_to_bits(n): |
| 15 | + return [i for i in range(n.bit_length()) if n & (1 << i)] |
15 | 16 |
|
| 17 | +# Regular expression to parse each line |
| 18 | +gpr_line_re = re.compile(r"([A-M]\d): data (\d) mirror (\d) pot (\d) control ([0-9A-Fa-f]{2})") |
| 19 | +gcr_line_re = re.compile(r"GCR(\d): 0x([0-9A-Fa-f]{2})") |
16 | 20 | gpr_grouped = {}
|
| 21 | +gcr_grouped = {} |
17 | 22 | for line in lines:
|
18 |
| - match = line_re.match(line) |
19 |
| - if match: |
| 23 | + match_gpr = gpr_line_re.match(line) |
| 24 | + match_gcr = gcr_line_re.match(line) |
| 25 | + if match_gpr: |
20 | 26 | gpr = {}
|
21 |
| - gpr['pin'] = match.group(1) |
22 |
| - gpr['data'] = int(match.group(2)) |
23 |
| - gpr['mirror'] = int(match.group(3)) |
24 |
| - gpr['pot'] = int(match.group(4)) |
25 |
| - gpr['control'] = int(match.group(5), 16) |
| 27 | + gpr['pin'] = match_gpr.group(1) |
| 28 | + gpr['data'] = int(match_gpr.group(2)) |
| 29 | + gpr['mirror'] = int(match_gpr.group(3)) |
| 30 | + gpr['pot'] = int(match_gpr.group(4)) |
| 31 | + gpr['control'] = int(match_gpr.group(5), 16) |
26 | 32 |
|
27 | 33 | port = gpr['pin'][0]
|
28 | 34 | port_number = int(gpr['pin'][1])
|
29 | 35 |
|
30 | 36 | if port not in gpr_grouped:
|
31 | 37 | gpr_grouped[port] = {}
|
32 | 38 | gpr_grouped[port][port_number] = gpr
|
33 |
| - |
34 |
| - |
| 39 | + if match_gcr: |
| 40 | + gcr = {} |
| 41 | + gcr['number'] = int(match_gcr.group(1)) |
| 42 | + gcr['value'] = int(match_gcr.group(2), 16) |
| 43 | + if gcr['number'] not in gcr_grouped: |
| 44 | + gcr_grouped[gcr['number']] = gcr |
| 45 | + |
| 46 | +print("GPR:") |
35 | 47 | for group in gpr_grouped:
|
36 |
| - print(gpr_grouped[group]) |
37 |
| - for reg in group: |
38 |
| - print(reg) |
39 |
| - |
| 48 | + print(f"\n{group}: {gpr_grouped[group]}") |
| 49 | +print("\n\nGCR:") |
| 50 | +for group in gcr_grouped: |
| 51 | + print(f"\n{group}: {gcr_grouped[group]}") |
40 | 52 |
|
0 commit comments