Skip to content

Commit ed201a6

Browse files
committed
Added BAD message
1 parent 88a2d13 commit ed201a6

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

base_station_main.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
# The system will recommend disconnecting after missing TIMEOUT PINGs.
4848
# Exact timing depends on CHECK_FOR_TIMEOUTS_INTERVAL variable in base_station_tick()
4949
"""
50-
from constants import TIMEOUT
50+
from constants import TIMEOUT, bUEs
5151

5252

5353
# Internal imports
@@ -195,15 +195,15 @@ def message_listener(self):
195195
else:
196196
logger.error(f"Got a connection request from {bue_id} but it is already listed as connected")
197197

198-
if message_body.startswith("ACK"):
198+
elif message_body.startswith("ACK"):
199199
logger.bind(bue_id=bue_id).info(f"Received ACK from {bue_id}")
200200

201-
if message_body.startswith("PING"): # Looks like <origin id>,PING,<lat>,<long>
201+
elif message_body.startswith("PING"): # Looks like <origin id>,PING,<lat>,<long>
202202
header, lat, long = message_body.split(",")
203203
print(f"header: {header}, lat: {lat}, long: {long}", flush=True)
204204
self.ping_bue(bue_id, lat, long)
205205

206-
if message_body.startswith("UPD"): # 40,55,UPD:LAT,LONG,STDOUT: [helloworld.py STDOUT] TyGoodTest,-42,8
206+
elif message_body.startswith("UPD"): # 40,55,UPD:LAT,LONG,STDOUT: [helloworld.py STDOUT] TyGoodTest,-42,8
207207
if not bue_id in self.testing_bues:
208208
self.testing_bues.append(bue_id)
209209
header, lat, long, stdout = message_body.split(",")
@@ -219,21 +219,24 @@ def message_listener(self):
219219
if stdout != "":
220220
self.stdout_history.append(stdout)
221221

222-
if message_body.startswith("FAIL"):
222+
elif message_body.startswith("FAIL"):
223223
logger.bind(bue_id=bue_id).error(f"Received FAIL from {bue_id}")
224224
self.testing_bues.remove(bue_id)
225225

226-
if message_body.startswith("DONE"):
226+
elif message_body.startswith("DONE"):
227227
logger.bind(bue_id=bue_id).info(f"Received DONE from {bue_id}")
228228
self.testing_bues.remove(bue_id)
229229

230-
if message_body.startswith("PREPR"):
230+
elif message_body.startswith("PREPR"):
231231
logger.bind(bue_id=bue_id).info(f"Received PREPR from {bue_id}")
232232
self.testing_bues.append(bue_id)
233233

234-
if message_body.startswith("CANCD"):
234+
elif message_body.startswith("CANCD"):
235235
logger.bind(bue_id=bue_id).info(f"Received CANCD from {bue_id}")
236236
self.testing_bues.remove(bue_id)
237+
elif message_body.startswith("BAD"):
238+
logger.bind(bue_id=bue_id).info(f"Received BAD from {bue_id}")
239+
self.stdout_history.append(f"Received a BAD from {bUEs[str(bue_id)]}")
237240

238241
else:
239242
logger.info(f"Received undefined message {message}")

ota.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,13 @@ def read_from_port(self):
6969
# Extract components: +RCV=origin,length,message_with_crc,rssi,snr
7070
origin = parts[0][5:]
7171
message_with_crc_part = ",".join(parts[2:-2])
72-
# print(parts)
73-
# print(f"Message with CRC Part: {message_with_crc_part}")
7472

7573
valid_crc, original_message = self.verify_crc(message_with_crc_part)
7674

7775
if not valid_crc: # Bad checksum
76+
self.send_ota_message(origin, "BAD")
7877
continue
7978

80-
# print("!!!!!!!!!!!")
81-
8279
self.recv_msgs.put(f"{origin},{original_message}")
8380
except Exception as e:
8481
print(f"OTA encountered some error: {e}")

0 commit comments

Comments
 (0)