Skip to content

Commit

Permalink
Improve robustness of hwp_pcu (#797)
Browse files Browse the repository at this point in the history
* attempt to improve robustness

* fix

* add exception

* fix
  • Loading branch information
ykyohei authored Nov 25, 2024
1 parent 10b48d1 commit 843d942
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions socs/agents/hwp_pcu/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from dataclasses import dataclass
from queue import Queue

import serial
import txaio
from twisted.internet import defer, reactor, threads

Expand Down Expand Up @@ -116,20 +117,30 @@ def main(self, session, params):
self.log.info('Connected to PCU')
PCU.clear_buffer()
self.log.info('Cleared buffer')
except ConnectionRefusedError:
except (ConnectionRefusedError, serial.serialutil.SerialException):
self.log.error(
"Could not connect to PCU. "
"Retrying after 30 sec..."
)
time.sleep(30)
continue
now = time.time()
if now - last_daq > 5:
self._get_and_publish_data(PCU, session)
last_daq = now

self._process_actions(PCU)
time.sleep(0.1)
try:
now = time.time()
if now - last_daq > 5:
self._get_and_publish_data(PCU, session)
last_daq = now

self._process_actions(PCU)
session.degraded = False
time.sleep(0.1)
except serial.serialutil.SerialException:
self.log.error(
"Decive reports readiness to read but returned no data. "
"Reconnect to PCU."
)
PCU.close()
PCU = None
session.degraded = True

PCU.close()

Expand Down

0 comments on commit 843d942

Please sign in to comment.