Skip to content

Commit 216213f

Browse files
committed
Reformat code
1 parent 99208da commit 216213f

16 files changed

+243
-711
lines changed

UI.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ def bue_status_table(base_station) -> Table:
1414
table.add_column("Status", style="yellow", justify="center")
1515

1616
for bue in base_station.connected_bues:
17-
status = (
18-
"🧪 Testing"
19-
if bue in getattr(base_station, "testing_bues", [])
20-
else "💤 Idle"
21-
)
17+
status = "🧪 Testing" if bue in getattr(base_station, "testing_bues", []) else "💤 Idle"
2218
table.add_row(bUEs[str(bue)], status)
2319

2420
if not base_station.connected_bues:
@@ -51,9 +47,7 @@ def bue_ping_table(base_station) -> Table:
5147

5248
def bue_coordinates_table(base_station) -> Table:
5349
"""Make a styled coordinates table."""
54-
table = Table(
55-
title="🌍 bUE Coordinates", show_header=True, header_style="bold blue"
56-
)
50+
table = Table(title="🌍 bUE Coordinates", show_header=True, header_style="bold blue")
5751
table.add_column("bUE ID", style="cyan", justify="center")
5852
table.add_column("Coordinates", style="yellow", justify="left")
5953

@@ -92,9 +86,7 @@ def bue_distance_table(base_station) -> Table:
9286
try:
9387
dist = base_station.get_distance(bue1, bue2)
9488
if dist is not None:
95-
table.add_row(
96-
f"{bUEs[str(bue1)]}{bUEs[str(bue2)]}", f"{dist:.2f}m"
97-
)
89+
table.add_row(f"{bUEs[str(bue1)]}{bUEs[str(bue2)]}", f"{dist:.2f}m")
9890
else:
9991
table.add_row(
10092
f"{bUEs[str(bue1)]}{bUEs[str(bue2)]}",
@@ -117,9 +109,7 @@ def bue_distance_table(base_station) -> Table:
117109

118110
def received_messages_table(base_station) -> Table:
119111
"""Make a styled coordinates table."""
120-
table = Table(
121-
title="💌 Received Messages", show_header=True, header_style="bold blue"
122-
)
112+
table = Table(title="💌 Received Messages", show_header=True, header_style="bold blue")
123113
table.add_column("Messages", style="cyan", justify="center")
124114

125115
for message in base_station.stdout_history:

base_station_gui.py

Lines changed: 83 additions & 248 deletions
Large diffs are not rendered by default.

base_station_main.py

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,7 @@ def ping_bue(self, bue_id, lat="", long=""):
139139

140140
self.bue_timeout_tracker[bue_id] = TIMEOUT + 1
141141
except Exception as e:
142-
logger.bind(bue_id=bue_id).error(
143-
f"ping_bue: Error while handling PING from {bue_id}: {e}"
144-
)
142+
logger.bind(bue_id=bue_id).error(f"ping_bue: Error while handling PING from {bue_id}: {e}")
145143

146144
"""
147145
# This function will cycle through each bUE the base station should be connected to and make sure that
@@ -161,9 +159,7 @@ def check_bue_timeout(self):
161159
logger.bind(bue_id=bue_id).error(f"We missed a PING from {bue_id}")
162160
self.bue_timeout_tracker[bue_id] -= 1
163161
else:
164-
logger.error(
165-
f"We haven't heard from {bue_id} in awhile. Maybe disconnected?"
166-
)
162+
logger.error(f"We haven't heard from {bue_id} in awhile. Maybe disconnected?")
167163

168164
def req_queue_handler(self):
169165
while not self.EXIT:
@@ -187,48 +183,36 @@ def message_listener(self):
187183
bue_id = int(parts[0])
188184

189185
except Exception as e:
190-
logger.error(
191-
f"message_listener: Failed to parse message '{message}': {e}"
192-
)
186+
logger.error(f"message_listener: Failed to parse message '{message}': {e}")
193187
continue # Skip to the next message
194188

195189
if "REQ" in message:
196190
logger.debug("Sending a CON")
197191
self.ota.send_ota_message(bue_id, f"CON:{self.ota.id}")
198192
self.bue_timeout_tracker[bue_id] = TIMEOUT
199193
if not bue_id in self.connected_bues:
200-
logger.bind(bue_id=bue_id).info(
201-
f"Received a request signal from {bue_id}"
202-
)
194+
logger.bind(bue_id=bue_id).info(f"Received a request signal from {bue_id}")
203195
self.connected_bues.append(bue_id)
204196
else:
205-
logger.error(
206-
f"Got a connection request from {bue_id} but it is already listed as connected"
207-
)
197+
logger.error(f"Got a connection request from {bue_id} but it is already listed as connected")
208198

209199
elif "ACK" in message:
210200
logger.bind(bue_id=bue_id).info(f"Received ACK from {bue_id}")
211201

212-
elif (
213-
"PING" in message
214-
): # Looks like <origin id>,<length>,PING,<lat>,<long>,-55,8
202+
elif "PING" in message: # Looks like <origin id>,<length>,PING,<lat>,<long>,-55,8
215203
if len(parts) >= 5:
216204
lat = parts[3]
217205
long = parts[4]
218206
self.ping_bue(bue_id, lat, long)
219207

220-
elif (
221-
"UPD" in message
222-
): # 40,55,UPD:LAT,LONG,STDOUT: [helloworld.py STDOUT] TyGoodTest,-42,8
208+
elif "UPD" in message: # 40,55,UPD:LAT,LONG,STDOUT: [helloworld.py STDOUT] TyGoodTest,-42,8
223209
if not bue_id in self.testing_bues:
224210
self.testing_bues.append(bue_id)
225211
lat = parts[3]
226212
long = parts[4]
227213
stdout = parts[5]
228214
# logger.info(f"Received UPD from {bue_id}. Currently at Latitude: {lat}, Longitude: {long}. Message: {stdout}")
229-
logger.bind(bue_id=bue_id).info(
230-
f"Received UPD from {bue_id}. Message: {stdout}"
231-
)
215+
logger.bind(bue_id=bue_id).info(f"Received UPD from {bue_id}. Message: {stdout}")
232216
if lat != "" and long != "":
233217
self.bue_coordinates[bue_id] = [lat, long]
234218
else:
@@ -280,33 +264,23 @@ def get_distance(self, bue_1, bue_2):
280264
lat1, lon1 = float(c1[0]), float(c1[1])
281265
lat2, lon2 = float(c2[0]), float(c2[1])
282266
except (ValueError, TypeError):
283-
logger.error(
284-
f"Non-numeric coordinates: bUE {bue_1}: {c1}, bUE {bue_2}: {c2}"
285-
)
267+
logger.error(f"Non-numeric coordinates: bUE {bue_1}: {c1}, bUE {bue_2}: {c2}")
286268
return None
287269

288270
# Check if coordinates are within valid ranges
289271
if not (-90 <= lat1 <= 90) or not (-180 <= lon1 <= 180):
290-
logger.error(
291-
f"Invalid latitude/longitude for bUE {bue_1}: lat={lat1}, lon={lon1}"
292-
)
272+
logger.error(f"Invalid latitude/longitude for bUE {bue_1}: lat={lat1}, lon={lon1}")
293273
return None
294274

295275
if not (-90 <= lat2 <= 90) or not (-180 <= lon2 <= 180):
296-
logger.error(
297-
f"Invalid latitude/longitude for bUE {bue_2}: lat={lat2}, lon={lon2}"
298-
)
276+
logger.error(f"Invalid latitude/longitude for bUE {bue_2}: lat={lat2}, lon={lon2}")
299277
return None
300278

301279
# Check if coordinates are not empty/zero (optional - depends on your use case)
302280
if (lat1 == 0 and lon1 == 0) or (lat2 == 0 and lon2 == 0):
303-
logger.warning(
304-
f"Zero coordinates detected: bUE {bue_1}: {c1}, bUE {bue_2}: {c2}"
305-
)
281+
logger.warning(f"Zero coordinates detected: bUE {bue_1}: {c1}, bUE {bue_2}: {c2}")
306282

307-
logger.info(
308-
f"Calculating distance between bUE {bue_1} at ({lat1}, {lon1}) and bUE {bue_2} at ({lat2}, {lon2})"
309-
)
283+
logger.info(f"Calculating distance between bUE {bue_1} at ({lat1}, {lon1}) and bUE {bue_2} at ({lat2}, {lon2})")
310284

311285
return distance.great_circle((lat1, lon1), (lat2, lon2)).meters
312286

bue_main.py

Lines changed: 20 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ def ota_task_queue_handler(self):
120120
# Send out REQs until a base station is found
121121
def ota_connect_req(self):
122122
if self.ota_connected:
123-
logger.warning(
124-
f"connect_ota_req: OTA device is already connected to base station {self.ota_base_station_id}"
125-
)
123+
logger.warning(f"connect_ota_req: OTA device is already connected to base station {self.ota_base_station_id}")
126124
return
127125

128126
# See if there are any new messages from the OTA device
@@ -144,14 +142,10 @@ def ota_connect_req(self):
144142
if parts[2].startswith(
145143
"CON:"
146144
): # TY This checks to see if the received message matches a base station connecting
147-
if (
148-
parts[0] == parts[2][4:]
149-
): # format. If it does we are now going to be in the connected state
145+
if parts[0] == parts[2][4:]: # format. If it does we are now going to be in the connected state
150146
self.ota_connected = True
151147
self.ota_base_station_id = int(parts[0])
152-
logger.info(
153-
f"ota_connect_req: OTA device connected to base station {self.ota_base_station_id}"
154-
)
148+
logger.info(f"ota_connect_req: OTA device connected to base station {self.ota_base_station_id}")
155149
self.ota_timeout = TIMEOUT
156150
self.ota.send_ota_message(self.ota_base_station_id, "ACK")
157151
return
@@ -164,15 +158,11 @@ def ota_connect_req(self):
164158
logger.error("ota_connect_req: Error parsing OTA message")
165159
continue
166160

167-
self.ota_base_station_id = (
168-
0 if self.ota_base_station_id is None else self.ota_base_station_id
169-
)
161+
self.ota_base_station_id = 0 if self.ota_base_station_id is None else self.ota_base_station_id
170162

171163
# Send a REQ (request) message through the OTA device
172164
# Next cycle we will hopefully have a CON (connected) response
173-
self.ota.send_ota_message(
174-
self.ota_base_station_id, "REQ"
175-
) # bUE sends a message back to the base station asking to
165+
self.ota.send_ota_message(self.ota_base_station_id, "REQ") # bUE sends a message back to the base station asking to
176166
# be connected as well
177167
print("Sending a REQ")
178168

@@ -187,9 +177,7 @@ def ota_idle_ping(self):
187177
print("Getting GPS Data")
188178
lat, long = self.gps_handler()
189179
print("trying to send a ping")
190-
self.ota.send_ota_message(
191-
self.ota_base_station_id, f"PING,{lat},{long}"
192-
) # test ping for now
180+
self.ota.send_ota_message(self.ota_base_station_id, f"PING,{lat},{long}") # test ping for now
193181

194182
# See if there are any new messages from the OTA device
195183
try:
@@ -215,9 +203,7 @@ def ota_idle_ping(self):
215203
self.ota_timeout = TIMEOUT
216204
got_pingr = True
217205

218-
elif (
219-
"TEST" in message
220-
): # Message should look like 1,34,TEST.<file>.<configuration>.<role>.<starttime>,-1,8
206+
elif "TEST" in message: # Message should look like 1,34,TEST.<file>.<configuration>.<role>.<starttime>,-1,8
221207
input = parts[2]
222208

223209
self.test_handler(input)
@@ -236,13 +222,9 @@ def ota_idle_ping(self):
236222
self.ota_timeout -= 1
237223

238224
if self.ota_timeout <= TIMEOUT / 2:
239-
logger.info(
240-
f"We haven't heard from {self.ota_base_station_id} in a while...."
241-
)
225+
logger.info(f"We haven't heard from {self.ota_base_station_id} in a while....")
242226
if self.ota_timeout <= 0:
243-
logger.info(
244-
f"We have not heard from {self.ota_base_station_id} in too long. Disconnecting..."
245-
)
227+
logger.info(f"We have not heard from {self.ota_base_station_id} in too long. Disconnecting...")
246228
self.ota_connected = False
247229

248230
"""
@@ -284,9 +266,7 @@ def ota_idle_ping(self):
284266
# logger.error(f"GPS error: {e}") # logger.debug("Could not find coordinates. Are they off?")
285267
# return "", ""
286268

287-
def gps_handler(
288-
self, max_attempts=50, min_fixes=3, hdop_threshold=2.0, max_runtime=10
289-
):
269+
def gps_handler(self, max_attempts=50, min_fixes=3, hdop_threshold=2.0, max_runtime=10):
290270
start_time = time.time()
291271
try:
292272
session = gps.gps(mode=gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)
@@ -310,9 +290,7 @@ def gps_handler(
310290
eph = getattr(report, "eph", None)
311291

312292
if lat is not None and lon is not None:
313-
logger.debug(
314-
f"Got GPS fix: lat={lat}, lon={lon}, HDOP={eph}"
315-
)
293+
logger.debug(f"Got GPS fix: lat={lat}, lon={lon}, HDOP={eph}")
316294
all_fixes.append((lat, lon))
317295
else:
318296
logger.debug("GPS fix missing lat/lon fields")
@@ -352,9 +330,7 @@ def test_handler(self, input): # Input Format: TEST-<file>-<wait_time>-<paramet
352330
current_time = int(time.time())
353331
if start_time > current_time:
354332
wait_duration = start_time - current_time
355-
logger.info(
356-
f"Waiting {wait_duration} seconds until start time {start_time}"
357-
)
333+
logger.info(f"Waiting {wait_duration} seconds until start time {start_time}")
358334

359335
# Wait in small increments to allow for cancellation
360336
while int(time.time()) < start_time and not self.cancel_test:
@@ -382,9 +358,7 @@ def test_handler(self, input): # Input Format: TEST-<file>-<wait_time>-<paramet
382358
text=True, # decode bytes to str
383359
)
384360

385-
logger.info(
386-
f"Started test script: {file}.py with parameters {parameters}"
387-
)
361+
logger.info(f"Started test script: {file}.py with parameters {parameters}")
388362

389363
def reader_thread(pipe, output_queue):
390364
for line in iter(pipe.readline, ""):
@@ -413,9 +387,7 @@ def reader_thread(pipe, output_queue):
413387
414388
# We also collect all the terminal outputs from the script so we can send them back to the base station
415389
"""
416-
while (
417-
process.poll() is None
418-
): # poll() returns None if process hasn't terminated
390+
while process.poll() is None: # poll() returns None if process hasn't terminated
419391
# Get all normal terminal outputs
420392
try:
421393
stdout_line = stdout_queue.get_nowait()
@@ -514,22 +486,14 @@ def ota_send_upd(self):
514486
with self.test_output_lock:
515487
if self.test_output_buffer:
516488
for line in self.test_output_buffer:
517-
self.ota.send_ota_message(
518-
self.ota_base_station_id, f"UPD:,{lat},{long},{line}"
519-
)
520-
logger.info(
521-
f"Sent UPD to {self.ota_base_station_id} with console output: {line}"
522-
)
489+
self.ota.send_ota_message(self.ota_base_station_id, f"UPD:,{lat},{long},{line}")
490+
logger.info(f"Sent UPD to {self.ota_base_station_id} with console output: {line}")
523491
time.sleep(0.4) # Sleep so UART does not get overwhelmed
524492
self.test_output_buffer.clear()
525493

526494
else: # If there is no message send it blank
527-
self.ota.send_ota_message(
528-
self.ota_base_station_id, f"UPD:,{lat},{long},"
529-
)
530-
logger.info(
531-
f"Sent UPD to {self.ota_base_station_id} with no console output"
532-
)
495+
self.ota.send_ota_message(self.ota_base_station_id, f"UPD:,{lat},{long},")
496+
logger.info(f"Sent UPD to {self.ota_base_station_id} with no console output")
533497

534498
"""
535499
# This function checks for incoming messages while in the system is the UTW_TEST state.
@@ -553,9 +517,7 @@ def check_for_cancel(self):
553517
logger.info(f"Received a RESTART message")
554518
self.restart_system()
555519
else:
556-
logger.error(
557-
f"Received unexpected message while in UTW_TEST state: {message}"
558-
)
520+
logger.error(f"Received unexpected message while in UTW_TEST state: {message}")
559521

560522
"""
561523
Restarts the service entirely
@@ -581,9 +543,7 @@ def restart_system(self):
581543

582544
def state_change_logger(self):
583545
if self.cur_st != self.prv_st:
584-
logger.info(
585-
f"state_change_logger: State changed from {self.prv_st.name} to {self.cur_st.name}"
586-
)
546+
logger.info(f"state_change_logger: State changed from {self.prv_st.name} to {self.cur_st.name}")
587547
self.prv_st = self.cur_st
588548

589549
def bue_tick(self, loop_dur=0.01):
File renamed without changes.
File renamed without changes.

gui_test_tkinter.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,11 @@ def send_test_to_bue(self, bue_id, test_script):
9191
"""Simulate sending a test to a bUE (like PREPR message)"""
9292
if bue_id in self.connected_bues and bue_id not in self.testing_bues:
9393
self.testing_bues.append(bue_id)
94-
self.stdout_history.append(
95-
f"[test_manager.py] PREPR sent to bUE {bue_id} for {test_script}"
96-
)
94+
self.stdout_history.append(f"[test_manager.py] PREPR sent to bUE {bue_id} for {test_script}")
9795

9896
# Simulate test completion after random time (5-15 seconds)
9997
completion_delay = random.uniform(5, 15)
100-
completion_timer = threading.Timer(
101-
completion_delay, self._complete_test, args=[bue_id]
102-
)
98+
completion_timer = threading.Timer(completion_delay, self._complete_test, args=[bue_id])
10399
completion_timer.daemon = True
104100
completion_timer.start()
105101

@@ -108,17 +104,13 @@ def _complete_test(self, bue_id):
108104
if bue_id in self.testing_bues:
109105
self.testing_bues.remove(bue_id)
110106
completion_type = random.choice(["DONE", "FAIL"])
111-
self.stdout_history.append(
112-
f"[test_manager.py] Test {completion_type} on bUE {bue_id}"
113-
)
107+
self.stdout_history.append(f"[test_manager.py] Test {completion_type} on bUE {bue_id}")
114108

115109
def cancel_test_on_bue(self, bue_id):
116110
"""Simulate canceling a test on a bUE (like CANCD message)"""
117111
if bue_id in self.testing_bues:
118112
self.testing_bues.remove(bue_id)
119-
self.stdout_history.append(
120-
f"[test_manager.py] CANCD sent to bUE {bue_id} - test cancelled"
121-
)
113+
self.stdout_history.append(f"[test_manager.py] CANCD sent to bUE {bue_id} - test cancelled")
122114

123115
def mock_updates(self):
124116
"""Simulate dynamic updates to the base station data"""
@@ -186,9 +178,7 @@ def get_distance(self, bue_1, bue_2):
186178

187179
# Convert to approximate meters (rough calculation)
188180
lat_meters = lat_diff * 111000 # 1 degree lat ≈ 111km
189-
lon_meters = (
190-
lon_diff * 111000 * 0.8
191-
) # Adjust for longitude at this latitude
181+
lon_meters = lon_diff * 111000 * 0.8 # Adjust for longitude at this latitude
192182

193183
distance = (lat_meters**2 + lon_meters**2) ** 0.5
194184
return distance

0 commit comments

Comments
 (0)