-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrain-config.py
executable file
·81 lines (61 loc) · 2.34 KB
/
brain-config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python3
import argparse, brain, sys
def read_item(brain, item):
print('{}: {}'.format(item, brain[item]))
def write_item(brain, str):
if str.count('=') != 1:
raise ValueError('Invalid name=val write string')
item, val = str.split('=')
val = int(val, 0)
old = brain[item]
brain[item] = val
print('{}: {} -> {}'.format(item, old, brain[item]))
def read_all(b):
for it in brain.GLOBAL_FIELDS:
read_item(b, 'global.'+it)
for i in range(3):
for it in brain.SETUP_FIELDS:
read_item(b, 'setup{}.{}'.format(i+1, it))
# We've done enough.
sys.exit(0)
def main():
parser = argparse.ArgumentParser(description='Modify Brain FBL unit configuration',
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog='''
Read and write configuration parameters to a Brain FBL unit. A configuration
parameter is a two-level entity, with a namespace of either "global", "setup1",
"setup2", or "setup3". Global and setup have differing permitted fields (listed
in fields.py).
When writing, the value is a 16-bit integer which may be given in either decimal
or hexadecimal form.
Example usage:
$ ./brain-config.py /dev/ttyUSB0 --read global.GovDiv
global.GovDiv: 2100
$ ./brain-config.py /dev/ttyUSB0 --write global.GovDiv=42
global.GovDiv: 2100 -> 42
$ ./brain-config.py /dev/ttyUSB0 --write global.GovDiv=0x834
global.GovDiv: 42 -> 2100
$ ./brain-config.py /dev/ttyUSB0 --read setup1.TailGainA
setup1.TailGainA: 32767
''')
parser.add_argument('device')
parser.add_argument('--read', action='append', help='Read a configuration parameter. E.g. global.RxType')
parser.add_argument('--read-all', action='store_true', help='Read all known configuration parameters')
parser.add_argument('--write', action='append', help='Write a configuation parameter. Expects name=val pairs')
try:
args = parser.parse_args()
except:
print('Error: invalid arguments on command line')
parser.print_help()
sys.exit(1)
b = brain.Brain(args.device)
if args.read_all:
read_all(b)
if args.read:
for parm in args.read:
read_item(b, parm)
if args.write:
for parm in args.write:
write_item(b, parm)
if __name__ == '__main__':
main()