/
application.py
98 lines (65 loc) · 2.5 KB
/
application.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
"""
Application.py
@author: James Fowkes
Entry file for the satellite tracker application
"""
import sys
import argparse
import logging
from ArduinoHardware import ArduinoHardware
from TLEProvider import TLEProvider
from TLEParser import TLEParser
from Tracker import Tracker
import Location
def get_arg_parser():
""" Return a command line argument parser for this module """
arg_parser = argparse.ArgumentParser(
description='TLE Tracker Application for sending azimuth, altitude strings to hardware')
arg_parser.add_argument(
'--tle', dest='tle', default='ISS',
help="Name of the TLE to track")
arg_parser.add_argument(
'--port', dest='port', default=None,
help="The serial port to send data to")
arg_parser.add_argument(
'--baudrate', dest='baudrate', default='115200',
help="The serial port to send data to")
arg_parser.add_argument(
'--az', dest='azimuth', default='0',
help="The starting azimuth of the tracker")
arg_parser.add_argument(
'--al', dest='altitude', default='-90',
help="The starting altitude of the tracker")
arg_parser.add_argument(
'--loc', dest='location', default='Nottingham',
help="The location of the tracker on Earth")
return arg_parser
def try_to_get_tle(tle_name):
""" Attempt to get the TLE for the provided satellite name """
tle_provider = TLEProvider("TLE")
tle = tle_provider.get_local_tle_by_name(tle_name)
if tle is None:
get_module_logger().info("Could not get TLE by name '%s'. Trying default ID of 25544 (ISS).", tle_name)
tle = tle_provider.get_tle_by_id(25544)
else:
get_module_logger().info("Found TLE with name '%s'.", tle_name)
if tle is None:
sys.exit("TLE could not be found.")
return tle, tleProvider
def get_module_logger():
""" Returns logger for this module """
return logging.getLogger(__name__)
def main():
""" Application start """
logging.basicConfig(level=logging.INFO)
get_module_logger().setLevel(logging.INFO)
arg_parser = get_arg_parser()
args = arg_parser.parse_args()
tle, tle_provider = try_to_get_tle(args.tle)
location = Location.get_location(args.location)
tle_parser = TLEParser(location, tle)
motor_control = ArduinoHardware(args.port, args.baudrate, True)
tracker = Tracker(tle_provider, tle_parser, motor_control)
tracker.run(int(args.azimuth), int(args.altitude))
if __name__ == "__main__":
main()