make secop work
This commit is contained in:
@ -74,7 +74,7 @@ new Settings()
|
|||||||
.treat("hostPort", "hp", 0, location.hostname + ":" + location.port)
|
.treat("hostPort", "hp", 0, location.hostname + ":" + location.port)
|
||||||
.treat("showMain", "sm", to_bool, true)
|
.treat("showMain", "sm", to_bool, true)
|
||||||
.treat("showConsole", "sc", to_bool, true)
|
.treat("showConsole", "sc", to_bool, true)
|
||||||
.treat("showOverview", "so", to_bool, true)
|
.treat("showOverview", "so", to_bool, false)
|
||||||
.treat("showGraphics", "sg", to_bool, true) // false)
|
.treat("showGraphics", "sg", to_bool, true) // false)
|
||||||
.treat("hideRightPart", "hr", to_bool, true) //used to completely disable the right part
|
.treat("hideRightPart", "hr", to_bool, true) //used to completely disable the right part
|
||||||
.treat("wideGraphs", "wg", to_bool, false) //used to toggle the size of the graphs part
|
.treat("wideGraphs", "wg", to_bool, false) //used to toggle the size of the graphs part
|
||||||
|
77
seaweb.py
77
seaweb.py
@ -145,6 +145,7 @@ def export():
|
|||||||
logging.error('%s', traceback.format_exc())
|
logging.error('%s', traceback.format_exc())
|
||||||
circularlog.log()
|
circularlog.log()
|
||||||
msg = dict(type='error', request=path[1:], error=repr(e))
|
msg = dict(type='error', request=path[1:], error=repr(e))
|
||||||
|
logging.error('MSG: %r', msg)
|
||||||
resp = flask.Response(json.dumps(msg), mimetype='application/json')
|
resp = flask.Response(json.dumps(msg), mimetype='application/json')
|
||||||
resp.headers['Access-Control-Allow-Origin'] = '*'
|
resp.headers['Access-Control-Allow-Origin'] = '*'
|
||||||
return resp
|
return resp
|
||||||
@ -542,6 +543,7 @@ class SeaInfluxInstrument(SeaInstrument):
|
|||||||
self.init()
|
self.init()
|
||||||
return self.register(SeaInfluxClient())
|
return self.register(SeaInfluxClient())
|
||||||
|
|
||||||
|
|
||||||
class InfluxInstrument(Instrument):
|
class InfluxInstrument(Instrument):
|
||||||
|
|
||||||
def __init__(self, instr_name):
|
def __init__(self, instr_name):
|
||||||
@ -770,6 +772,7 @@ class SeaInfluxClient(SeaParams, InfluxGraph):
|
|||||||
SeaParams.__init__(self)
|
SeaParams.__init__(self)
|
||||||
InfluxGraph.__init__(self, instrument.influx_data_getter, instrument.title)
|
InfluxGraph.__init__(self, instrument.influx_data_getter, instrument.title)
|
||||||
|
|
||||||
|
|
||||||
class InfluxClient(InfluxParams, InfluxGraph):
|
class InfluxClient(InfluxParams, InfluxGraph):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
InfluxParams.__init__(self)
|
InfluxParams.__init__(self)
|
||||||
@ -864,10 +867,11 @@ class DummyInstrument(Instrument):
|
|||||||
|
|
||||||
|
|
||||||
class SecopMsg:
|
class SecopMsg:
|
||||||
|
par = None
|
||||||
|
value = None
|
||||||
|
|
||||||
def __init__(self, line):
|
def __init__(self, line):
|
||||||
self.par = None
|
sl = line.split(' ', 2)
|
||||||
self.value = None
|
|
||||||
sl = line.split(' ')
|
|
||||||
if len(sl[0].split(',')) > 1:
|
if len(sl[0].split(',')) > 1:
|
||||||
self.type = 'idn'
|
self.type = 'idn'
|
||||||
self.value = line
|
self.value = line
|
||||||
@ -875,8 +879,8 @@ class SecopMsg:
|
|||||||
self.type = sl[0]
|
self.type = sl[0]
|
||||||
if len(sl) > 1:
|
if len(sl) > 1:
|
||||||
self.par = sl[1]
|
self.par = sl[1]
|
||||||
if len(sl) > 2:
|
if len(sl) > 2:
|
||||||
self.value = json.loads(' '.join(sl[2:]))
|
self.value = json.loads(sl[2])
|
||||||
self.asynch = self.type in ('update', 'error_update')
|
self.asynch = self.type in ('update', 'error_update')
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
@ -914,7 +918,7 @@ def convert_event(messages):
|
|||||||
messages = [messages]
|
messages = [messages]
|
||||||
updates = []
|
updates = []
|
||||||
for msg in messages:
|
for msg in messages:
|
||||||
if msg['type'] == 'update':
|
if msg.type == 'update':
|
||||||
updates.append(dict(name=msg.par, value=msg.value[0]))
|
updates.append(dict(name=msg.par, value=msg.value[0]))
|
||||||
# updates.append(dict(name=msg.par, value=str(msg.value[0])))
|
# updates.append(dict(name=msg.par, value=str(msg.value[0])))
|
||||||
return [dict(type='update', updates=updates)]
|
return [dict(type='update', updates=updates)]
|
||||||
@ -950,11 +954,12 @@ class SecopClient:
|
|||||||
break
|
break
|
||||||
line = self.linesocket.get_line()
|
line = self.linesocket.get_line()
|
||||||
if line != None:
|
if line != None:
|
||||||
self.consolequeue.append(dict(type='reply',line=line,origin='other'))
|
if not line.startswith('update'):
|
||||||
|
self.consolequeue.append(dict(type='reply',line=line,origin='other'))
|
||||||
if self.out: self.out.write("<"+line+"\n")
|
if self.out: self.out.write("<"+line+"\n")
|
||||||
msg = SecopMsg(line)
|
msg = SecopMsg(line)
|
||||||
#print '<', msg['type'], msg.par
|
#print '<', msg.type, msg.par
|
||||||
if msg.asynch and replytype != msg['type'] + "=" + msg.par:
|
if msg.asynch: # and replytype != msg['type'] + "=" + msg.par:
|
||||||
t = 0
|
t = 0
|
||||||
self.queue.append(msg)
|
self.queue.append(msg)
|
||||||
else:
|
else:
|
||||||
@ -962,11 +967,11 @@ class SecopClient:
|
|||||||
if t >= tmo:
|
if t >= tmo:
|
||||||
#print 'TIMEOUT'
|
#print 'TIMEOUT'
|
||||||
raise Exception("timeout")
|
raise Exception("timeout")
|
||||||
gevent.sleep(0.1)
|
gevent.sleep(0.001)
|
||||||
t += 0.1
|
t += 0.001
|
||||||
#print 'REPLY', msg['type'], msg.par, json.dumps(msg.value)[0:50]
|
#print 'REPLY', msg['type'], msg.par, json.dumps(msg.value)[0:50]
|
||||||
if not replytype.startswith(msg['type']):
|
if not replytype.startswith(msg.type):
|
||||||
logging.error('REPLY MISMATCH %s <> %s', replytype, '<>', repr(msg))
|
logging.error('REPLY MISMATCH %s <> %s', replytype, repr(msg))
|
||||||
self.replytype = ""
|
self.replytype = ""
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
@ -981,7 +986,8 @@ class SecopClient:
|
|||||||
return dict(type='draw', path='main', title='modules', components=components)
|
return dict(type='draw', path='main', title='modules', components=components)
|
||||||
else:
|
else:
|
||||||
module = self.description['modules'][path]
|
module = self.description['modules'][path]
|
||||||
parameters = module["parameters"]
|
logging.info('MP %r %r', path, module)
|
||||||
|
parameters = dict(module["accessibles"])
|
||||||
components = []
|
components = []
|
||||||
for name in SecopClient.skip_par:
|
for name in SecopClient.skip_par:
|
||||||
if name in parameters:
|
if name in parameters:
|
||||||
@ -999,15 +1005,20 @@ class SecopClient:
|
|||||||
return dict(type='draw', path=path, title=path, components=components)
|
return dict(type='draw', path=path, title=path, components=components)
|
||||||
|
|
||||||
def w_updateblock(self, path):
|
def w_updateblock(self, path):
|
||||||
self.cmd_reply("activate", "active")
|
if path == 'main':
|
||||||
|
path = ''
|
||||||
|
self.cmd_reply(f"activate {path}", "active")
|
||||||
return dict(type='accept-block')
|
return dict(type='accept-block')
|
||||||
|
|
||||||
def w_console(self):
|
def w_console(self):
|
||||||
return dict(type='accept-console')
|
return dict(type='accept-console')
|
||||||
|
|
||||||
def w_sendcommand(self, command):
|
def w_sendcommand(self, command):
|
||||||
#print 'COMMAND', command
|
logging.info('SENDCOMMAND %r', command)
|
||||||
cmd = "change " + command
|
if not command.strip():
|
||||||
|
return dict(type='accept-command')
|
||||||
|
# cmd = "change " + command
|
||||||
|
cmd = command
|
||||||
return self.cmd_reply(cmd, 'event ' + command.split(' ')[0])
|
return self.cmd_reply(cmd, 'event ' + command.split(' ')[0])
|
||||||
|
|
||||||
def poll(self):
|
def poll(self):
|
||||||
@ -1021,10 +1032,11 @@ class SecopClient:
|
|||||||
return messages
|
return messages
|
||||||
line = self.linesocket.get_line()
|
line = self.linesocket.get_line()
|
||||||
if line:
|
if line:
|
||||||
self.consolequeue.append(dict(type='reply',line=line,origin='other'))
|
if not line.startswith('update'):
|
||||||
|
self.consolequeue.append(dict(type='reply',line=line,origin='other'))
|
||||||
if self.out: self.out.write("<"+line+"\n")
|
if self.out: self.out.write("<"+line+"\n")
|
||||||
msg = SecopMsg(line)
|
msg = SecopMsg(line)
|
||||||
if msg.asynch and self.replytype != msg['type'] + "=" + msg.par:
|
if msg.asynch: # and self.replytype != msg['type'] + "=" + msg.par:
|
||||||
return convert_event(SecopMsg(line))
|
return convert_event(SecopMsg(line))
|
||||||
self.syncreply.append(msg)
|
self.syncreply.append(msg)
|
||||||
return []
|
return []
|
||||||
@ -1038,14 +1050,35 @@ class SecopInstrument(Instrument):
|
|||||||
self.instrument_config = instrument_config
|
self.instrument_config = instrument_config
|
||||||
self.host_port = hostport_split(instrument_config['hostport'])
|
self.host_port = hostport_split(instrument_config['hostport'])
|
||||||
self.logger_dir = instrument_config.get('logger_dir', '')
|
self.logger_dir = instrument_config.get('logger_dir', '')
|
||||||
test_day = instrument_config.get('test_day', None)
|
#test_day = instrument_config.get('test_day', None)
|
||||||
self.test_day = [int(x) for x in test_day.split('-')] if test_day else None
|
#self.test_day = [int(x) for x in test_day.split('-')] if test_day else None
|
||||||
self.title = inst_name
|
self.title = inst_name
|
||||||
self.clients = {}
|
self.clients = {}
|
||||||
|
|
||||||
def newClient(self):
|
def newClient(self):
|
||||||
return self.register(SecopClient(self.host_port))
|
return self.register(SecopClient(self.host_port))
|
||||||
|
|
||||||
|
|
||||||
|
class SecopInfluxClient(SecopClient, InfluxGraph):
|
||||||
|
def __init__(self):
|
||||||
|
SecopClient.__init__(self, instrument.host_port)
|
||||||
|
InfluxGraph.__init__(self, instrument.influx_data_getter, instrument.title)
|
||||||
|
|
||||||
|
|
||||||
|
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(datetime.now().timestamp()))
|
||||||
|
|
||||||
|
def newClient(self):
|
||||||
|
#if not self.seaspy.connected:
|
||||||
|
# self.init()
|
||||||
|
return self.register(SecopInfluxClient())
|
||||||
|
|
||||||
|
|
||||||
class Logger(object):
|
class Logger(object):
|
||||||
def __init__(self, logpath):
|
def __init__(self, logpath):
|
||||||
self.terminal = sys.stdout
|
self.terminal = sys.stdout
|
||||||
@ -1100,6 +1133,8 @@ if __name__ == '__main__':
|
|||||||
instrument = SeaInstrument(inst_name, instrument_config)
|
instrument = SeaInstrument(inst_name, instrument_config)
|
||||||
elif type == 'influxsea':
|
elif type == 'influxsea':
|
||||||
instrument = SeaInfluxInstrument(inst_name, instrument_config)
|
instrument = SeaInfluxInstrument(inst_name, instrument_config)
|
||||||
|
elif type == 'influxsecop':
|
||||||
|
instrument = SecopInfluxInstrument(inst_name, instrument_config)
|
||||||
elif type == 'influx':
|
elif type == 'influx':
|
||||||
instrument = InfluxInstrument(inst_name)
|
instrument = InfluxInstrument(inst_name)
|
||||||
elif type == 'dummy':
|
elif type == 'dummy':
|
||||||
|
Reference in New Issue
Block a user