Skip to content

Commit

Permalink
Added restart task to hwp-encoder agent
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryce Bixler committed Aug 27, 2024
1 parent 99854a7 commit 51471e0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/agents/hwp_encoder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ using all of the available arguments::
'instance-id': 'HBA0',
'arguments': [
['--port', '8080'],
['--ip', '192.168.11.113'],
]}
{'agent-class': 'HWPBBBAgent',
'instance-id': 'HBA1',
'arguments': [
['--port', '8081'],
['--ip', '192.168.11.114'],
]}

This is an example to run two agents because we usually have a couple of
Expand Down
37 changes: 35 additions & 2 deletions socs/agents/hwp_encoder/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,12 +488,13 @@ class HWPBBBAgent:
"""

def __init__(self, agent_obj, port=8080):
def __init__(self, agent_obj, port=8080, ip='None'):
self.active = True
self.agent = agent_obj
self.log = agent_obj.log
self.lock = TimeoutLock()
self.port = port
self.ip = ip
self.take_data = False
self.initialized = False
# For clock count to time conversion
Expand All @@ -511,6 +512,36 @@ def __init__(self, agent_obj, port=8080):
agg_params=agg_params)
self.parser = EncoderParser(beaglebone_port=self.port)

def restart(self, session, params):
"""restart()
**Task** - Restarts the beaglebone process
Notes:
The most recent data collected is stored in the session data in the
structure:
>>> response.session['response']
{'result': True,
'log': ["Restart command response: Success"]}
"""
if self.ip == 'None':
return False, "Could not restart process because beaglebone ip is not defined"

_restart_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
_restart_socket.connect((self.ip, 5656))
_restart_socket.sendall(('reset\n').encode())
time.sleep(0.5)

resp = _restart_socket.recv(4096).decode().strip()
log = f'Restart command response: {resp}'
result = True if resp == "Success" else False
_restart_socket.close()
time.sleep(10)

session.data['response'] = {'result': result, 'log': log}
return result, f'Success: {result}'

def acq(self, session, params):
"""acq()
Expand Down Expand Up @@ -695,6 +726,7 @@ def make_parser(parser=None):
# Add options specific to this agent.
pgroup = parser.add_argument_group('Agent Options')
pgroup.add_argument('--port', type=int, default=8080)
pgroup.add_argument('--ip', type=str, default='None')

return parser

Expand All @@ -709,8 +741,9 @@ def main(args=None):
parser=parser,
args=args)
agent, runner = ocs_agent.init_site_agent(args)
hwp_bbb_agent = HWPBBBAgent(agent, port=args.port)
hwp_bbb_agent = HWPBBBAgent(agent, port=args.port, ip=args.ip)
agent.register_process('acq', hwp_bbb_agent.acq, hwp_bbb_agent._stop_acq, startup=True)
agent.register_task('restart', hwp_bbb_agent.restart)

runner.run(agent, auto_reconnect=True)

Expand Down

0 comments on commit 51471e0

Please sign in to comment.