custom device name for fake udp
This commit is contained in:
@ -56,8 +56,8 @@ class NicosStream(Stream):
|
||||
self.secnode_uri = {}
|
||||
super().__init__(uri, name)
|
||||
|
||||
def init(self):
|
||||
self.tags['device'] = 'nicos'
|
||||
def init(self, device=None, **kwds):
|
||||
self.tags['device'] = device or 'nicos'
|
||||
self.send(f'@nicos/*\n{END_MARKER}{OP_ASK}')
|
||||
self._init = True
|
||||
|
||||
|
17
secop.py
17
secop.py
@ -19,7 +19,7 @@ class EnumConvert(dict):
|
||||
class SecopStream(Stream):
|
||||
ping_time = 0
|
||||
|
||||
def init(self):
|
||||
def init(self, device=None, **kwds):
|
||||
self._buffer = []
|
||||
self.send('*IDN?')
|
||||
resend = True
|
||||
@ -41,7 +41,7 @@ class SecopStream(Stream):
|
||||
else:
|
||||
raise ValueError('missing describing message')
|
||||
self.descr = json.loads(match.group(1))
|
||||
self.device = self.descr['equipment_id']
|
||||
self.device = device or self.descr['equipment_id']
|
||||
if self.device.endswith('psi.ch'):
|
||||
self.device[-6:] = []
|
||||
self.tags['device'] = self.device
|
||||
@ -110,13 +110,18 @@ class UdpStream(Base):
|
||||
except socket.error: # pragma: no cover
|
||||
return None
|
||||
msg = json.loads(msg.decode('utf-8'))
|
||||
if msg['SECoP'] == 'for_other_node':
|
||||
uri = msg['uri']
|
||||
elif msg['SECoP'] == 'node':
|
||||
kind = msg.pop('SECoP', None)
|
||||
if not kind:
|
||||
continue
|
||||
if kind == 'for_other_node':
|
||||
uri = msg.pop('uri')
|
||||
kwargs = msg
|
||||
elif kind == 'node':
|
||||
uri = f"{addr[0]}:{msg['port']}"
|
||||
kwargs = {'name': msg['equipment_id']}
|
||||
else:
|
||||
continue
|
||||
yield SecopStream, uri, msg['equipment_id']
|
||||
yield SecopStream, uri, kwargs
|
||||
|
||||
|
||||
class ScanReply(UdpStream):
|
||||
|
10
streams.py
10
streams.py
@ -48,7 +48,7 @@ class Stream(Base):
|
||||
_deadline = INF
|
||||
_next_connect = 0
|
||||
|
||||
def __init__(self, uri, name=None, timeout=5, encoding='latin-1'):
|
||||
def __init__(self, uri, name=None, timeout=5, encoding='latin-1', **kwds):
|
||||
self.name = name or uri
|
||||
self.uri = uri
|
||||
self.tags = {}
|
||||
@ -63,7 +63,7 @@ class Stream(Base):
|
||||
self.generator = self.event_generator()
|
||||
try:
|
||||
self.connect()
|
||||
self.init()
|
||||
self.init(**kwds)
|
||||
except Exception as e:
|
||||
print(self.uri, repr(e))
|
||||
raise
|
||||
@ -261,10 +261,10 @@ class EventStream:
|
||||
while 1:
|
||||
for stream in self.wait_ready(1):
|
||||
if not isinstance(stream, Stream):
|
||||
for streamcls, uri, *args in stream.events():
|
||||
for streamcls, uri, kwargs in stream.events():
|
||||
if uri not in self.streams:
|
||||
print('add stream', uri, *args)
|
||||
self.streams[uri] = streamcls(uri, *args)
|
||||
print('add stream', uri, kwargs)
|
||||
self.streams[uri] = streamcls(uri, **kwargs)
|
||||
for name, stream in self.streams.items():
|
||||
try:
|
||||
if stream.get_events(events, maxevents):
|
||||
|
Reference in New Issue
Block a user