followup change: fix dummy webserver
the dummy server was no longer working after server rework
This commit is contained in:
@ -1,9 +1,32 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import argparse
|
||||||
import pathlib
|
import pathlib
|
||||||
sys.path.insert(0, str((pathlib.Path(__file__) / '..').resolve()))
|
sys.path.insert(0, str((pathlib.Path(__file__) / '..').resolve()))
|
||||||
import webserver
|
from webserver import server
|
||||||
from dummy import SecopDummyInstrument
|
from base import Client
|
||||||
|
from dummy import DummyGraph, DummyHistory
|
||||||
|
from secop import SecopInteractor
|
||||||
|
|
||||||
webserver.instrument = webserver.main(SecopDummyInstrument)
|
|
||||||
|
def parseArgv(argv):
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="start webserver with dummy history and SECoP interaction",
|
||||||
|
)
|
||||||
|
parser.add_argument("port",
|
||||||
|
type=str,
|
||||||
|
default='8888',
|
||||||
|
nargs='?',
|
||||||
|
help="port number to serve")
|
||||||
|
parser.add_argument('-u',
|
||||||
|
'--uri',
|
||||||
|
action='store',
|
||||||
|
help='SECoP uri',
|
||||||
|
default='localhost:5000')
|
||||||
|
return parser.parse_args(argv)
|
||||||
|
|
||||||
|
|
||||||
|
args = parseArgv(sys.argv[1:])
|
||||||
|
|
||||||
|
server.run(int(args.port), DummyHistory(args.uri), DummyGraph, Client, single_instrument='dummy', secop=SecopInteractor)
|
||||||
|
29
dummy.py
29
dummy.py
@ -2,12 +2,18 @@ import time
|
|||||||
import math
|
import math
|
||||||
import io
|
import io
|
||||||
from colors import assign_colors_to_curves
|
from colors import assign_colors_to_curves
|
||||||
from secop import SecopInstrument, SecopClient
|
from secop import SecopClient
|
||||||
from base import get_abs_time
|
from base import get_abs_time, HandlerBase
|
||||||
|
|
||||||
|
|
||||||
class DummyGraph:
|
class DummyGraph(HandlerBase):
|
||||||
def __init__(self):
|
def __init__(self, server, instrument, device, tags):
|
||||||
|
super().__init__() # put methods w_... to handlers
|
||||||
|
self.handlers['graphpoll'] = self.graphpoll
|
||||||
|
self.server = server
|
||||||
|
self.instrument = instrument
|
||||||
|
self.device = device
|
||||||
|
self.tags = tags
|
||||||
self.blocks = []
|
self.blocks = []
|
||||||
self.phase = {}
|
self.phase = {}
|
||||||
self.end_time = 0
|
self.end_time = 0
|
||||||
@ -158,11 +164,7 @@ class DummyGraph:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class SecopDummyClient(SecopClient, DummyGraph):
|
class SecopDummyClient(SecopClient):
|
||||||
def __init__(self, instrument):
|
|
||||||
SecopClient.__init__(self, instrument)
|
|
||||||
DummyGraph.__init__(self)
|
|
||||||
|
|
||||||
def poll(self):
|
def poll(self):
|
||||||
messages = super().poll()
|
messages = super().poll()
|
||||||
msg = self.graphpoll()
|
msg = self.graphpoll()
|
||||||
@ -171,8 +173,9 @@ class SecopDummyClient(SecopClient, DummyGraph):
|
|||||||
return messages
|
return messages
|
||||||
|
|
||||||
|
|
||||||
class SecopDummyInstrument(SecopInstrument):
|
class DummyHistory:
|
||||||
|
def __init__(self, stream):
|
||||||
def new_client(self):
|
self.stream = stream
|
||||||
return self.register(SecopDummyClient(self))
|
|
||||||
|
|
||||||
|
def get_streams(self, instrument=None, **kwds):
|
||||||
|
return {self.stream: {'device': 'dummy'}}
|
||||||
|
11
secop.py
11
secop.py
@ -29,18 +29,21 @@ class SecopInteractor(SecopClient):
|
|||||||
self.module_updates = set()
|
self.module_updates = set()
|
||||||
self.param_updates = set()
|
self.param_updates = set()
|
||||||
self.updates = {}
|
self.updates = {}
|
||||||
|
self.connect()
|
||||||
|
self.register_callback(None, updateItem=self.updateItem)
|
||||||
|
|
||||||
def add_main_components(self, components):
|
def add_main_components(self, components):
|
||||||
# todo: treat non Readable classes correctly
|
for name, desc in self.modules.items():
|
||||||
components.extend(dict(type='rdlink', name=name + ':value', title=name)
|
component = dict(type='rdlink', name=f'{name}:value', title=name)
|
||||||
for name in self.modules)
|
if 'status' in desc['parameters']:
|
||||||
|
component['statusname'] = f'{name}:status'
|
||||||
|
components.append(component)
|
||||||
self.param_updates.add('value')
|
self.param_updates.add('value')
|
||||||
self.param_updates.add('status')
|
self.param_updates.add('status')
|
||||||
|
|
||||||
def get_components(self, path):
|
def get_components(self, path):
|
||||||
module = self.modules[path]
|
module = self.modules[path]
|
||||||
self.module_updates.add(path) # TODO: remove others?
|
self.module_updates.add(path) # TODO: remove others?
|
||||||
# logging.info('MP %r', path)
|
|
||||||
parameters = dict(module["parameters"])
|
parameters = dict(module["parameters"])
|
||||||
components = []
|
components = []
|
||||||
for name in SecopInteractor.skip_par:
|
for name in SecopInteractor.skip_par:
|
||||||
|
Reference in New Issue
Block a user