Skip to content

Commit

Permalink
Fixes to pre-commit failures
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryce Bixler committed Nov 20, 2023
1 parent f7cc7e4 commit 0735a59
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
7 changes: 3 additions & 4 deletions socs/agents/hwp_pid/drivers/pid_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self, ip, port, verb=False):
self.set_direction('0')

@staticmethod
def _establish_connection(ip, port, timeout=5):
def _establish_connection(ip, port, timeout=2):
"""Connect to PID controller.
Args:
Expand All @@ -54,9 +54,8 @@ def _establish_connection(ip, port, timeout=5):
try:
conn.connect((ip, port))
break
except (ConnectionRefusedError, OSError) as e:
except (ConnectionRefusedError, OSError):
print(f"Failed to connect to device at {ip}:{port}")
time.sleep(5)
else:
raise RuntimeError('Could not connect to PID controller')
return conn
Expand Down Expand Up @@ -267,7 +266,7 @@ def send_message(self, msg):
time.sleep(0.5) # Don't send messages too quickly
data = self.conn.recv(4096).decode().strip()
return data
except (socket.timeout, OSError) as e:
except (socket.timeout, OSError):
print("Caught timeout waiting for response from PID controller. "
+ "Trying again...")
time.sleep(1)
Expand Down
7 changes: 3 additions & 4 deletions socs/agents/hwp_pmx/drivers/PMX_ethernet.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,16 @@ def __init__(self, ip, port):
self.buffer_size = 128
self.conn = self._establish_connection(self.ip, int(self.port))

def _establish_connection(self, ip, port, timeout=5):
def _establish_connection(self, ip, port, timeout=2):
conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
conn.settimeout(timeout)
attempts = 3
for attempt in range(attempts):
try:
conn.connect((ip, port))
break
except (ConnectionRefusedError, OSError) as e:
except (ConnectionRefusedError, OSError):
print(f"Failed to connect to device at {ip}:{port}")
time.sleep(5)
else:
raise RuntimeError('Could not connect to PID controller')
return conn
Expand All @@ -54,7 +53,7 @@ def send_message(self, msg, read=True):
data = self.conn.recv(self.buffer_size).decode('utf-8')
return data
return
except (socket.timeout, OSError) as e:
except (socket.timeout, OSError):
print("Caught timeout waiting for responce from PMX. Trying again...")
time.sleep(1)
if attempt == 1:
Expand Down

0 comments on commit 0735a59

Please sign in to comment.