| 1 |
|
| 2 |
|
| 3 |
""" |
| 4 |
DEPRECATED: Will be removed in v1.0 |
| 5 |
""" |
| 6 |
|
| 7 |
import warnings |
| 8 |
|
| 9 |
import ais |
| 10 |
import sys |
| 11 |
import ais.compatibility.gpsd |
| 12 |
import ais.stream |
| 13 |
|
| 14 |
try: |
| 15 |
import json |
| 16 |
except: |
| 17 |
json = None |
| 18 |
try: |
| 19 |
import msgpack |
| 20 |
except: |
| 21 |
msgpack = None |
| 22 |
|
| 23 |
|
| 24 |
warnings.warn( |
| 25 |
"This utility is deprecated and will be removed in 1.0", |
| 26 |
FutureWarning, |
| 27 |
stacklevel=2) |
| 28 |
|
| 29 |
|
| 30 |
args = {"encoding": "json"} |
| 31 |
files = [] |
| 32 |
for arg in sys.argv[1:]: |
| 33 |
if arg.startswith("--"): |
| 34 |
arg = arg[2:] |
| 35 |
if '=' in arg: |
| 36 |
arg, value = arg.split("=", 1) |
| 37 |
args[arg] = value |
| 38 |
else: |
| 39 |
args[arg] = True |
| 40 |
else: |
| 41 |
files.append(arg) |
| 42 |
|
| 43 |
|
| 44 |
if 'validateChecksum' in args: args['validate_checksum'] = args.pop('validateChecksum') |
| 45 |
if 'allowUnknown' in args: args['allow_unknown'] = args.pop('allowUnknown') |
| 46 |
if 'treatABequal' in args: args['treat_ab_equal'] = args.pop('treatABequal') |
| 47 |
|
| 48 |
for key in ("uscg", "validate_checksum", "verbose", "allow_unknown", "treat_ab_equal", "pass_invalid_checksums", "allow_missing_timestamps"): |
| 49 |
if key in args and isinstance(args[key], str): |
| 50 |
args[key] = args[key] == 'True' |
| 51 |
|
| 52 |
if "help" in args: |
| 53 |
print("""Usage: aisdecode [OPTIONS] < INFILE.nmea > OUTFILE.json |
| 54 |
Available opptions: |
| 55 |
--gpsd Use gpsd compatible output |
| 56 |
--copy-tagblock-timestamp=False |
| 57 |
|
| 58 |
--encoding=msgpack Use msgpack encoding |
| 59 |
--encoding=json Use json encoding (default) |
| 60 |
|
| 61 |
--keep_nmea Include the raw nmea as a field in the decoded output |
| 62 |
|
| 63 |
--verbose |
| 64 |
--max_errors=NUM Terminate if error rate is > NUM%. |
| 65 |
--allow_unknown |
| 66 |
--ignore_tagblock_station |
| 67 |
--treat_ab_equal |
| 68 |
--pass_invalid_checksums |
| 69 |
--allow_missing_timestamps |
| 70 |
|
| 71 |
--uscg=False |
| 72 |
--validate_checksum=False |
| 73 |
""") |
| 74 |
sys.exit(0) |
| 75 |
|
| 76 |
encoding = args.pop('encoding', 'json') |
| 77 |
if encoding == 'json': |
| 78 |
def write(msg): |
| 79 |
json.dump(msg, sys.stdout) |
| 80 |
sys.stdout.write("\n") |
| 81 |
|
| 82 |
if encoding == 'msgpack': |
| 83 |
def write(msg): |
| 84 |
msgpack.pack(msg, sys.stdout) |
| 85 |
|
| 86 |
use_gpsd = args.pop("gpsd", False) |
| 87 |
copy_tagblock_timestamp = args.pop("copy-tagblock-timestamp", True) |
| 88 |
|
| 89 |
|
| 90 |
if 'window' in args: |
| 91 |
args['window'] = int('window') |
| 92 |
|
| 93 |
if "max_errors" in args: |
| 94 |
args["max_errors"] = float(args["max_errors"]) |
| 95 |
|
| 96 |
gpsd_mangle = ais.compatibility.gpsd.Mangler(copy_tagblock_timestamp=copy_tagblock_timestamp) |
| 97 |
|
| 98 |
for msg in ais.stream.decode(sys.stdin, **args): |
| 99 |
if use_gpsd: |
| 100 |
msg = gpsd_mangle(msg) |
| 101 |
write(msg) |