-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolar_test.py
163 lines (125 loc) · 3.99 KB
/
solar_test.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
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
# radio_test.py
# V1.0 June 24, 2024
# Authored by: Michael Pham
# The is a test script to facilitate a simple ping pong style communications test between two radios.
import time
from pysquared import cubesat
test_message = 'Hello There!'
debug_mode = True
number_of_attempts = 0
# Radio Configuration Setup Here
radio_cfg = {
'spreading_factor': 8,
'tx_power': 13, #Set as a default that works for any radio
'node': 0x00,
'destination': 0x00,
'receive_timeout': 5,
'enable_crc': False
}
options = ['A', 'B']
# Setting the Radio
cubesat.radio1.spreading_factor=radio_cfg['spreading_factor']
if cubesat.radio1.spreading_factor>8:
cubesat.radio1.low_datarate_optimize=True
else:
cubesat.radio1.low_datarate_optimize=False
cubesat.radio1.tx_power=radio_cfg['tx_power']
cubesat.radio1.receive_timeout=radio_cfg['receive_timeout']
cubesat.radio1.enable_crc=False
print(
'''
=======================================
| |
| WELCOME! |
| Radio Test Version 1.0 |
| |
=======================================
| Please Select Your Node |
| 'A': Device Under Test |
| 'B': Receiver |
=======================================
'''
)
def debug_print(message):
if debug_mode:
print(message)
def device_under_test(attempts):
debug_print("Device Under Test Selected")
debug_print("Setting up Radio...")
cubesat.radio1.node=0xfa
cubesat.radio1.destination=0xff
debug_print("Radio Setup Complete")
debug_print("Sending Ping...")
print(f"Attempt: {attempts}")
cubesat.radio1.send(test_message)
debug_print("Ping Sent")
debug_print("Awaiting Response...")
heard_something = cubesat.radio1.await_rx(timeout=10)
if heard_something:
handle_ping()
else:
debug_print("No Response Received")
cubesat.radio1.send('Nothing Received')
debug_print("Echo Sent")
def receiver():
debug_print("Receiver Selected")
debug_print("Setting up Radio...")
cubesat.radio1.node=0xff
cubesat.radio1.destination=0xfa
debug_print("Radio Setup Complete")
debug_print("Awaiting Ping...")
heard_something = cubesat.radio1.await_rx(timeout=10)
if heard_something:
handle_ping()
else:
debug_print("No Ping Received")
cubesat.radio1.send('Nothing Received')
debug_print("Echo Sent")
def handle_ping():
response = cubesat.radio1.receive(keep_listening=True)
if response is not None:
debug_print("Ping Received")
print('msg: {}, RSSI: {}'.format(response,cubesat.radio1.last_rssi-137))
cubesat.radio1.send('Ping Received! Echo:{}'.format(cubesat.radio1.last_rssi-137))
debug_print("Echo Sent")
else:
debug_print("No Ping Received")
cubesat.radio1.send('Nothing Received')
debug_print("Echo Sent")
device_selection = input()
if device_selection not in options:
print("Invalid Selection.")
print("Please refresh the device and try again.")
else:
print(
'''
=======================================
| |
| Verbose Output? (Y/N) |
| |
=======================================
'''
)
verbose_selection = input()
if verbose_selection == 'Y':
debug_mode = True
elif verbose_selection == 'N':
debug_mode = False
print(
'''
=======================================
| |
| Beginning Radio Test |
| Radio Test Version 1.0 |
| |
=======================================
'''
)
while True:
if device_selection == 'A':
time.sleep(1)
device_under_test(number_of_attempts)
number_of_attempts += 1
elif device_selection == 'B':
time.sleep(1)
receiver()