diff --git a/client/jsFiles/SEAWebClientMain.js b/client/jsFiles/SEAWebClientMain.js index 94f98d0..0a464d6 100644 --- a/client/jsFiles/SEAWebClientMain.js +++ b/client/jsFiles/SEAWebClientMain.js @@ -74,7 +74,7 @@ new Settings() .treat("hostPort", "hp", 0, location.hostname + ":" + location.port) .treat("showMain", "sm", 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("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 diff --git a/seaweb.py b/seaweb.py index b4b6396..9fd37cf 100755 --- a/seaweb.py +++ b/seaweb.py @@ -145,6 +145,7 @@ def export(): logging.error('%s', traceback.format_exc()) circularlog.log() 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.headers['Access-Control-Allow-Origin'] = '*' return resp @@ -542,6 +543,7 @@ class SeaInfluxInstrument(SeaInstrument): self.init() return self.register(SeaInfluxClient()) + class InfluxInstrument(Instrument): def __init__(self, instr_name): @@ -770,6 +772,7 @@ class SeaInfluxClient(SeaParams, InfluxGraph): SeaParams.__init__(self) InfluxGraph.__init__(self, instrument.influx_data_getter, instrument.title) + class InfluxClient(InfluxParams, InfluxGraph): def __init__(self): InfluxParams.__init__(self) @@ -864,10 +867,11 @@ class DummyInstrument(Instrument): class SecopMsg: + par = None + value = None + def __init__(self, line): - self.par = None - self.value = None - sl = line.split(' ') + sl = line.split(' ', 2) if len(sl[0].split(',')) > 1: self.type = 'idn' self.value = line @@ -875,8 +879,8 @@ class SecopMsg: self.type = sl[0] if len(sl) > 1: self.par = sl[1] - if len(sl) > 2: - self.value = json.loads(' '.join(sl[2:])) + if len(sl) > 2: + self.value = json.loads(sl[2]) self.asynch = self.type in ('update', 'error_update') def __repr__(self): @@ -914,7 +918,7 @@ def convert_event(messages): messages = [messages] updates = [] 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=str(msg.value[0]))) return [dict(type='update', updates=updates)] @@ -950,11 +954,12 @@ class SecopClient: break line = self.linesocket.get_line() 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") msg = SecopMsg(line) - #print '<', msg['type'], msg.par - if msg.asynch and replytype != msg['type'] + "=" + msg.par: + #print '<', msg.type, msg.par + if msg.asynch: # and replytype != msg['type'] + "=" + msg.par: t = 0 self.queue.append(msg) else: @@ -962,11 +967,11 @@ class SecopClient: if t >= tmo: #print 'TIMEOUT' raise Exception("timeout") - gevent.sleep(0.1) - t += 0.1 + gevent.sleep(0.001) + t += 0.001 #print 'REPLY', msg['type'], msg.par, json.dumps(msg.value)[0:50] - if not replytype.startswith(msg['type']): - logging.error('REPLY MISMATCH %s <> %s', replytype, '<>', repr(msg)) + if not replytype.startswith(msg.type): + logging.error('REPLY MISMATCH %s <> %s', replytype, repr(msg)) self.replytype = "" return msg @@ -981,7 +986,8 @@ class SecopClient: return dict(type='draw', path='main', title='modules', components=components) else: module = self.description['modules'][path] - parameters = module["parameters"] + logging.info('MP %r %r', path, module) + parameters = dict(module["accessibles"]) components = [] for name in SecopClient.skip_par: if name in parameters: @@ -999,15 +1005,20 @@ class SecopClient: return dict(type='draw', path=path, title=path, components=components) 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') def w_console(self): return dict(type='accept-console') def w_sendcommand(self, command): - #print 'COMMAND', command - cmd = "change " + command + logging.info('SENDCOMMAND %r', command) + if not command.strip(): + return dict(type='accept-command') + # cmd = "change " + command + cmd = command return self.cmd_reply(cmd, 'event ' + command.split(' ')[0]) def poll(self): @@ -1021,10 +1032,11 @@ class SecopClient: return messages line = self.linesocket.get_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") 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)) self.syncreply.append(msg) return [] @@ -1038,14 +1050,35 @@ class SecopInstrument(Instrument): self.instrument_config = instrument_config self.host_port = hostport_split(instrument_config['hostport']) self.logger_dir = instrument_config.get('logger_dir', '') - test_day = instrument_config.get('test_day', None) - self.test_day = [int(x) for x in test_day.split('-')] if test_day else 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.title = inst_name self.clients = {} def newClient(self): 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): def __init__(self, logpath): self.terminal = sys.stdout @@ -1100,6 +1133,8 @@ if __name__ == '__main__': instrument = SeaInstrument(inst_name, instrument_config) elif type == 'influxsea': instrument = SeaInfluxInstrument(inst_name, instrument_config) + elif type == 'influxsecop': + instrument = SecopInfluxInstrument(inst_name, instrument_config) elif type == 'influx': instrument = InfluxInstrument(inst_name) elif type == 'dummy':