Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ianohara committed Jan 21, 2025
1 parent 837e776 commit 2604a71
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions software/control/microcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,11 @@ def is_open(self) -> bool:
def reconnect(self, attempts: int) -> bool:
self._log.debug(f"Attempting reconnect to {self._serial.port}. With max of {attempts} attempts.")
for i in range(attempts):
this_interval = MicrocontrollerSerial.exponential_backoff_time(i, MicrocontrollerSerial.INITIAL_RECONNECT_INTERVAL)
this_interval = MicrocontrollerSerial.exponential_backoff_time(
i, MicrocontrollerSerial.INITIAL_RECONNECT_INTERVAL
)
if not self.is_open():
time.sleep(
this_interval
)
time.sleep(this_interval)
try:
try:
self._serial.close()
Expand All @@ -335,12 +335,13 @@ def reconnect(self, attempts: int) -> bool:
if i + 1 == attempts:
self._log.error(
f"Reconnect to {self._serial.port} failed after {attempts} attempts. Last reconnect interval was {this_interval} [s]",
exc_info=se
exc_info=se,
)
# This is the last time around the loop, so it'll exit and return self.is_open() as false after this.
else:
self._log.warning(
f"Couldn't reconnect serial={self._serial.port} @ baud={self._serial.baudrate}. Attempt {i + 1}/{attempts}.")
f"Couldn't reconnect serial={self._serial.port} @ baud={self._serial.baudrate}. Attempt {i + 1}/{attempts}."
)
else:
break

Expand Down Expand Up @@ -967,7 +968,9 @@ def read_received_packet(self):

if not self._serial.is_open():
if not self._serial.reconnect(attempts=Microcontroller.MAX_RECONNECT_COUNT):
self.log.error("In read loop, serial device failed to reconnect. Microcontroller is defunct!")
self.log.error(
"In read loop, serial device failed to reconnect. Microcontroller is defunct!"
)

continue

Expand Down Expand Up @@ -1064,7 +1067,6 @@ def read_received_packet(self):
except Exception as e:
self.log.error("Read loop failed, continuing to loop to see if anything can recover.", exc_info=e)


def get_pos(self):
return self.x_pos, self.y_pos, self.z_pos, self.theta_pos

Expand Down

0 comments on commit 2604a71

Please sign in to comment.