-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgs_shell.py
More file actions
168 lines (134 loc) · 5.67 KB
/
gs_shell.py
File metadata and controls
168 lines (134 loc) · 5.67 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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
"""
Provides a basic shell-like interface to send and receive data from the satellite
"""
import sys # noqa
sys.path.append("lib") # noqa
from shell_utils import *
from gs_shell_tasks import *
from gs_setup import *
import tasko
try:
import supervisor
except ImportError:
supervisor = None
# prevent board from reloading in the middle of the test
if supervisor is not None:
supervisor.disable_autoreload()
prompt_options = {"Receive loop": ("r", "receive"),
"Beacon request loop": ("b", "beacon"),
"Upload file": ("u", "upload"),
"Request file": ("rf", "request"),
"Send command": ("c", "command"),
"Set time": ("st", "settime"),
"Get time": ("gt", "gettime"),
"Help": ("h", "print_help"),
"Toggle verbose debug prints": ("v", "verbose"),
"Quit": ("q", "quit")}
flattend_prompt_options = [v for pov in prompt_options.values() for v in pov]
def print_help():
print(f"\n{yellow}Groundstation shell help:{normal}")
for po in prompt_options:
print(f"{bold}{po}{normal}: {prompt_options[po]}")
# setup
print(f"\n{bold}{yellow}PyCubed-Mini Groundstation Shell{normal}\n")
board_str = get_input_discrete(
f"""Select the board/radio:
{bold}(s){normal} satellite,
{bold}(f){normal} feather,
{bold}(p){normal} raspberry pi,
{bold}(t){normal} RPiGS TX,
{bold}(r){normal} RPiGS RX,
""",
["s", "f", "p", "t", "r"]
)
if board_str == "s":
spi, cs, reset = satellite_spi_config()
print(f"{bold}{green}Satellite{normal} selected")
elif board_str == "f":
spi, cs, reset = feather_spi_config()
print(f"{bold}{green}Feather{normal} selected")
elif board_str == "p":
spi, cs, reset = pi_spi_config()
print(f"{bold}{green}Raspberry Pi{normal} selected")
elif board_str == "t":
spi, cs, reset = rpigs_tx_spi_config()
print(f"{bold}{green}Raspberry Pi{normal} selected")
elif board_str == "r":
spi, cs, reset = rpigs_rx_spi_config()
print(f"{bold}{green}Raspberry Pi{normal} selected")
else:
raise ValueError(f"Board string {board_str} invalid")
radio = initialize_radio(spi, cs, reset)
print_radio_configuration(radio)
if get_input_discrete(
f"Change radio parameters? {bold}(y/N){normal}", ["", "y", "n"]) == "y":
manually_configure_radio(radio)
print_radio_configuration(radio)
print_help()
def gs_shell_main_loop():
verbose = True
while True:
try:
choice = get_input_discrete(f"\n{blue}Choose an action{normal}", flattend_prompt_options)
if choice in prompt_options["Receive loop"]:
print("Entering receive loop. CTRL-C to exit")
while True:
tasko.add_task(read_loop(radio, debug=verbose), 1)
tasko.run()
elif choice in prompt_options["Beacon request loop"]:
beacon_period = get_input_range("Request period (seconds)", (10, 1000), allow_default=False)
beacon_frequency_hz = 1.0 / float(beacon_period)
logname = input("log file name (empty to not log) = ")
def get_beacon_noargs(): return get_beacon(radio, debug=verbose, logname=logname)
tasko.schedule(beacon_frequency_hz, get_beacon_noargs, 10)
tasko.run()
elif choice in prompt_options["Upload file"]:
source = input('source path = ')
dest = input('destination path = ')
tasko.add_task(upload_file(radio, source, dest, debug=verbose), 1)
tasko.run()
tasko.reset()
elif choice in prompt_options["Request file"]:
source = input('source path = ')
tasko.add_task(request_file(radio, source, debug=verbose), 1)
tasko.run()
tasko.reset()
elif choice in prompt_options["Send command"]:
command_name = get_input_discrete("Select a command", list(commands_by_name.keys())).upper()
command_bytes = commands_by_name[command_name]["bytes"]
will_respond = commands_by_name[command_name]["will_respond"]
args = input('arguments = ')
tasko.add_task(send_command_task(radio, command_bytes, args, will_respond, debug=verbose), 1)
tasko.run()
tasko.reset()
elif choice in prompt_options["Set time"]:
while True:
t = input("seconds since epoch (empty for system time) = ")
if t == "":
t = None
break
else:
try:
t = int(t)
break
except ValueError:
print("Invalid time - must be empty or an integer")
tasko.add_task(set_time(radio, t, debug=verbose), 1)
tasko.run()
tasko.reset()
elif choice in prompt_options["Get time"]:
tasko.add_task(get_time_task(radio, debug=verbose), 1)
tasko.run()
tasko.reset()
elif choice in prompt_options["Help"]:
print_help()
elif choice in prompt_options["Toggle verbose debug prints"]:
verbose = not verbose
print(f"Verbose: {verbose}")
elif choice in prompt_options["Quit"]:
break
except KeyboardInterrupt:
print(f"\n{red}Enter q to quit{normal}")
tasko.reset()
pass
gs_shell_main_loop()