forked from cr/hx870
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread-config.py
More file actions
executable file
·68 lines (56 loc) · 1.83 KB
/
read-config.py
File metadata and controls
executable file
·68 lines (56 loc) · 1.83 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse, os, sys
import coloredlogs, logging
import hxtool
def progress_bar(progress):
sys.stdout.write(".")
sys.stdout.flush()
def config_read(args):
devices = hxtool.device.enumerate(
force_model = args.model,
force_device = args.tty,
)
if len(devices) != 1:
wrong_device_count = 'Multiple devices' if devices else 'No device'
print( f"{wrong_device_count} detected. Try --model or --tty." )
sys.exit(1)
h = devices[0]
if not h.comm.cp_mode or not h.comm.hx_hardware:
print( "Could not open connection." )
sys.exit(1)
# Show device identification, to help users with selecting the right one
mmsi = h.config.read_mmsi()[0]
atis = h.config.read_atis()[0]
callsign = hxtool.callsign.determine(atis)
if not mmsi or mmsi == "FFFFFFFFF":
mmsi = "not set"
if callsign:
callsign = ", call sign " + callsign
elif atis and atis != "FFFFFFFFFF" and mmsi == "not set":
callsign = ", ATIS " + atis
print( "Device MMSI " + mmsi + callsign )
sys.stdout.write( f"Reading {h.handle} memory " )
sys.stdout.flush()
try:
coloredlogs.set_level(logging.WARNING)
config = h.config.config_read(progress_bar)
except Exception as exc:
print( " Error!" )
raise exc
print( " done" )
return config
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-m", "--model")
parser.add_argument("-t", "--tty")
parser.add_argument("filename")
args = parser.parse_args()
try:
config = config_read(args)
except KeyboardInterrupt:
print( "\nAborted. File '" + args.filename + "' unchanged." )
sys.exit(1)
with open(args.filename, "wb") as f:
f.write(config)
main()