Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OCSClient crossbar address override to wg kikusui agent #511

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/agents/wiregrid_kikusui.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ An example site-config-file block::
Communicating device is determined by the ethernet port number of the converter.)
- encoder-agent is an instance ID of the wiregrid encoder agent (wiregrid-encoder).
This is necessary to get the position recorded by the encoder for controlling the rotation.
- crossbar-http is available (but not shown here) and can be used to set the
crossbar address used for the OCSClient connection to the encoder agent.

Docker Compose
``````````````
Expand All @@ -54,6 +56,8 @@ An example docker-compose configuration::
network_mode: "host"
command:
- INSTANCE_ID=wgkikusui
- SITE_HUB=ws://127.0.0.1:8001/ws
- SITE_HTTP=http://127.0.0.1:8001/call
volumes:
- ${OCS_CONFIG_DIR}:/config:ro
- "<local directory to record log file>:/data/wg-data"
Expand Down
20 changes: 18 additions & 2 deletions socs/agents/wiregrid_kikusui/agent.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import os
import time

import numpy as np
Expand Down Expand Up @@ -26,11 +27,14 @@ class WiregridKikusuiAgent:
Communicating device is determined
by the ethernet port number of the converter.
encoder_agent (str): Instance ID of the wiregrid encoder agent
crossbar_http (str): Crossbar site-http address for encoder client
connection. `SITE_HTTP` env var used by default. This argument
overrides `SITE_HTTP`.
debug (bool): ON/OFF of writing a log file
"""

def __init__(self, agent, kikusui_ip, kikusui_port,
encoder_agent='wgencoder', debug=False):
encoder_agent='wgencoder', crossbar_http=None, debug=False):
self.agent = agent
self.log = agent.log
self.lock = TimeoutLock()
Expand All @@ -39,6 +43,7 @@ def __init__(self, agent, kikusui_ip, kikusui_port,
self.kikusui_ip = kikusui_ip
self.kikusui_port = int(kikusui_port)
self.encoder_agent = encoder_agent
self.crossbar_http = crossbar_http
self.debug = debug

self.position_path = '/data/wg-data/position.log'
Expand Down Expand Up @@ -134,7 +139,12 @@ def _reconnect(self):
return False, msg

def _connect_encoder(self):
self.encoder_client = OCSClient(self.encoder_agent)
site_http_env = os.environ.get("SITE_HTTP")
if site_http_env:
args = ['--site-http', site_http_env]
if self.crossbar_http is not None:
args = ['--site-http', self.crossbar_http]
self.encoder_client = OCSClient(self.encoder_agent, args=args)

def _rotate_alittle(self, operation_time):
if operation_time != 0.:
Expand Down Expand Up @@ -612,6 +622,11 @@ def make_parser(parser=None):
pgroup.add_argument('--encoder-agent', dest='encoder_agent',
default='wgencoder',
help='Instance id of the wiregrid encoder agent')
# Avoiding --site-http name in case of interaction with actual argument
pgroup.add_argument('--crossbar-http', default=None,
help='crossbar site-http address for encoder client '
+ 'connection. `SITE_HTTP` env var used by default. '
+ 'This argument overrides `SITE_HTTP`.')
pgroup.add_argument('--debug', dest='debug',
action='store_true', default=False,
help='Write a log file for debug')
Expand All @@ -628,6 +643,7 @@ def main(args=None):
kikusui_agent = WiregridKikusuiAgent(agent, kikusui_ip=args.kikusui_ip,
kikusui_port=args.kikusui_port,
encoder_agent=args.encoder_agent,
crossbar_http=args.crossbar_http,
debug=args.debug)
agent.register_process('IV_acq', kikusui_agent.IV_acq,
kikusui_agent.stop_IV_acq, startup=True)
Expand Down