forked from cr/hx870
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread-config.py
executable file
·55 lines (46 loc) · 1.35 KB
/
read-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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import time, sys, os
import hxtool
def progress_bar(progress):
sys.stdout.write(".")
sys.stdout.flush()
class HxToolArgs(object):
def __init__(self):
self.model = None
self.tty = None
self.simulator = None
def config_read():
h = hxtool.get(HxToolArgs())
try:
if not h.comm.cp_mode:
raise Exception("not in CP mode (region mismatch?)")
h.comm.sync()
mmsi = h.config.read_mmsi()[0]
except Exception as exc:
print( "Could not open connection to HX870." )
sys.exit(1)
print( "Device MMSI " + (mmsi if mmsi != "ffffffffff" else "not set") )
sys.stdout.write( "Reading HX870 memory " )
sys.stdout.flush()
try:
h.config.set_progress_callback(progress_bar)
config = h.config.config_read()
except Exception as exc:
print( " Error!" )
raise exc
print( " done" )
return config
def main():
if not len(sys.argv) == 2:
sys.stderr.write("Usage:\n %s <file_name>\n" % os.path.basename(sys.argv[0]))
sys.exit(1)
filename = sys.argv[1]
try:
config = config_read()
except KeyboardInterrupt:
print( "\nAborted. File '" + filename + "' unchanged." )
sys.exit(1)
with open(filename, "wb") as f:
f.write(config)
main()