Skip to content

Commit da69224

Browse files
committed
Make time out work
1 parent d4f5473 commit da69224

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

Backend/core/comms.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ def serial_read(self):
148148
while True:
149149
curr_device = serial_port['device']
150150
curr_baud = serial_port['baud']
151-
print('serial', curr_device)
152151
if(curr_device):
153152
# Establish a serial connection)
154153
ser = serial.Serial(curr_device, curr_baud)
155154
# if device has been updated then exit loop and connect to new device
156-
while curr_device == serial_port['device']:
157-
print('read serial')
155+
while curr_device == serial_port['device'] and curr_baud == serial_port['baud']:
156+
if time.time() - latest_tstamp > 5:
157+
solar_car_connection['serial'] = False
158158
# Read data from serial port
159159
try:
160160
data = b''
@@ -165,8 +165,6 @@ def serial_read(self):
165165
if not data:
166166
# No data received, continue listening
167167
continue
168-
print('read data')
169-
print('data:', data)
170168
packets = self.parse_packets(data, 'serial')
171169
for packet in packets:
172170
if len(packet) == byte_length:
@@ -179,9 +177,6 @@ def serial_read(self):
179177
print(traceback.format_exc())
180178
continue
181179
solar_car_connection['serial'] = True
182-
if time.time() - latest_tstamp / 1000 > 5:
183-
solar_car_connection['lte'] = False
184-
break
185180
except Exception:
186181
print(traceback.format_exc())
187182
solar_car_connection['serial'] = False
@@ -270,7 +265,7 @@ def parse_packets(self, new_data: bytes, tmp_source: str):
270265
# If the remaining data is longer than the expected packet length,
271266
# there might be an incomplete packet, so log a warning.
272267
if len(self.__tmp_data[tmp_source]) >= byte_length:
273-
print("Warning: Incomplete or malformed packet ------------------------------------")
268+
print(f"Source: {tmp_source}: Warning: Incomplete or malformed packet ------------------------------------")
274269
self.__tmp_data[tmp_source] = b''
275270

276271
return packets

0 commit comments

Comments
 (0)