Debian Codegraph @

mlat-client

raw symbols SCIP
1 #!/usr/bin/env python3
2 # -*- mode: python; indent-tabs-mode: nil -*-
3
4 # Part of mlat-client - an ADS-B multilateration client.
5 # Copyright 2015, Oliver Jowett <[email protected]>
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 import argparse
21
22 import mlat.client.version
23 import time
24
25 from mlat.client import util
26 from mlat.client.receiver import ReceiverConnection
27 from mlat.client.jsonclient import JsonServerConnection
28 from mlat.client.coordinator import Coordinator
29 from mlat.client import options
30
31
32 def main():
33 parser = argparse.ArgumentParser(description="Client for multilateration.")
34
35 options.make_inputs_group(parser)
36 options.make_results_group(parser)
37
38 location = parser.add_argument_group('Receiver location')
39 location.add_argument('--lat',
40 type=options.latitude,
41 help="Latitude of the receiver, in decimal degrees. Required.",
42 required=True)
43 location.add_argument('--lon',
44 type=options.longitude,
45 help="Longitude of the receiver, in decimal degrees. Required.",
46 required=True)
47 location.add_argument('--alt',
48 type=options.altitude,
49 help="""
50 Altitude of the receiver (height above ellipsoid). Required. Defaults to metres, but units may
51 specified with a 'ft' or 'm' suffix. (Except if they're negative due to option
52 parser weirdness. Sorry!)""",
53 required=True)
54 location.add_argument('--privacy',
55 help="""
56 Sets the privacy flag for this receiver. Currently, this removes the receiver
57 location pin from the coverage maps.""",
58 action='store_true',
59 default=False)
60
61 server = parser.add_argument_group('Multilateration server connection')
62 server.add_argument('--user',
63 help="User information to give to the server. Used to get in touch if there are problems.",
64 required=True)
65 server.add_argument('--server',
66 help="host:port of the multilateration server to connect to",
67 type=options.hostport,
68 default=('feed.adsb.fi', 31090))
69 server.add_argument('--no-udp',
70 dest='udp',
71 help="Don't offer to use UDP transport for sync/mlat messages",
72 action='store_false',
73 default=True)
74 server.add_argument('--uuid-file',
75 dest='uuid_path',
76 help="Send the UUID in this file to the server",
77 required=False)
78 server.add_argument('--uuid',
79 dest='uuid',
80 help="Send this UUID to the server",
81 required=False)
82
83 logOptions = parser.add_argument_group('Log Options')
84 logOptions.add_argument('--log-timestamps',
85 dest='log_timestamps',
86 help="Print timestamps in logging output",
87 action='store_true',
88 default=False)
89
90 args = parser.parse_args()
91
92 util.suppress_log_timestamps = not args.log_timestamps
93
94 if abs(args.lat) < 0.1 and abs(args.lon) < 0.1:
95 util.log("<3>Latitude / Longitude not set, please configure and reboot")
96 time.sleep(3600)
97 raise SystemExit
98
99 util.log("mlat-client {version} starting up", version=mlat.client.version.CLIENT_VERSION)
100
101 outputs = options.build_outputs(args)
102
103 receiver = ReceiverConnection(host=args.input_connect[0], port=args.input_connect[1],
104 mode=options.connection_mode(args))
105
106 uuid_path = None
107 uuid = None
108 if args.uuid is not None:
109 uuid = [ args.uuid ]
110 if args.uuid_path is not None:
111 uuid_path = [ args.uuid_path ]
112 else:
113 uuid_path = [ '/usr/local/share/adsbfi/adsbfi-uuid', '/boot/adsbfi-uuid' ]
114
115 server = JsonServerConnection(host=args.server[0],
116 port=args.server[1],
117 uuid_path=uuid_path,
118 uuid=uuid,
119 handshake_data={'lat': args.lat,
120 'lon': args.lon,
121 'alt': args.alt,
122 'user': args.user,
123 'clock_type': options.clock_type(args),
124 'clock_frequency': options.clock_frequency(args),
125 'clock_epoch': options.clock_epoch(args),
126 'privacy': args.privacy},
127 offer_zlib=True,
128 offer_udp=args.udp,
129 return_results=(len(outputs) > 0))
130
131 coordinator = Coordinator(receiver=receiver, server=server, outputs=outputs, freq=options.clock_frequency(args),
132 allow_anon=args.allow_anon_results, allow_modeac=args.allow_modeac_results)
133
134 server.start()
135 coordinator.run_forever()
136
137
138 if __name__ == '__main__':
139 main()