move classes using influx from secop to influxgraph
+ fix parameter change command in secop
This commit is contained in:
43
secop.py
43
secop.py
@ -1,9 +1,6 @@
|
||||
import time
|
||||
import logging
|
||||
import uuid
|
||||
from base import Instrument, get_abs_time
|
||||
from influxdb import InfluxDB, InfluxDataGetter
|
||||
from influxgraph import InfluxGraph
|
||||
from frappy.client import SecopClient as SecNodeClient
|
||||
from frappy.lib.enum import EnumMember
|
||||
from frappy.datatypes import get_datatype
|
||||
@ -98,15 +95,17 @@ class SecopClient:
|
||||
logging.info('SENDCOMMAND %r', command)
|
||||
if not command.strip():
|
||||
return dict(type='accept-command')
|
||||
scmd = command.split(' ')
|
||||
if scmd[0] != 'change':
|
||||
scmd.insert(0, 'change')
|
||||
# return dict(type='accept-command', error=f'do not know how to do {command!r}')
|
||||
module, _, parameter = scmd[1].partition(':')
|
||||
if command.startswith('change '):
|
||||
command = command[7:]
|
||||
modpar, _, strvalue = command.partition(' ')
|
||||
module, _, parameter = modpar.partition(':')
|
||||
if not parameter:
|
||||
parameter = 'target'
|
||||
node = self.instrument.node_map[module]
|
||||
result = node.setParameterFromString(module, parameter, scmd[2])
|
||||
try:
|
||||
node.setParameterFromString(module, parameter, strvalue)
|
||||
except Exception as e:
|
||||
print(f"{e!r} converting {strvalue} to {node.modules[module]['parameters'][parameter]['datatype']}")
|
||||
return dict(type='accept-command')
|
||||
|
||||
def w_gettime(self, time):
|
||||
@ -138,7 +137,6 @@ class SecopInstrument(Instrument):
|
||||
# self.test_day = [int(x) for x in test_day.split('-')] if test_day else None
|
||||
self.title = inst_name
|
||||
self.device = 'UNDEFINED'
|
||||
self.clients = {}
|
||||
self.nodes = []
|
||||
self.node_map = {}
|
||||
for host_port in host_ports.split(','):
|
||||
@ -162,28 +160,3 @@ class SecopInstrument(Instrument):
|
||||
|
||||
def new_client(self):
|
||||
return self.register(SecopClient(self))
|
||||
|
||||
|
||||
class SecopInfluxClient(SecopClient, InfluxGraph):
|
||||
def __init__(self, instrument):
|
||||
SecopClient.__init__(self, instrument)
|
||||
InfluxGraph.__init__(self, instrument.influx_data_getter, instrument.title)
|
||||
|
||||
def poll(self):
|
||||
messages = super().poll()
|
||||
msg = self.graphpoll()
|
||||
if msg:
|
||||
messages.append(msg)
|
||||
return messages
|
||||
|
||||
|
||||
class SecopInfluxInstrument(SecopInstrument):
|
||||
|
||||
def __init__(self, inst_name, instrument_config):
|
||||
super().__init__(inst_name, instrument_config)
|
||||
self.db = InfluxDB()
|
||||
self.influx_data_getter = InfluxDataGetter(self.db, inst_name)
|
||||
self.device = self.influx_data_getter.get_device_name(int(time.time()))
|
||||
|
||||
def new_client(self):
|
||||
return self.register(SecopInfluxClient(self))
|
||||
|
Reference in New Issue
Block a user