##// END OF EJS Templates
agregado para realtime, sin funcionar
José Chávez -
r902:135486d9969b
parent child
Show More
@@ -1,383 +1,388
1 '''
1 '''
2 @author: Juan C. Espinoza
2 @author: Juan C. Espinoza
3 '''
3 '''
4
4
5 import time
5 import time
6 import json
6 import json
7 import numpy
7 import numpy
8 import paho.mqtt.client as mqtt
8 import paho.mqtt.client as mqtt
9 import zmq
9 import zmq
10 import cPickle as pickle
10 import cPickle as pickle
11 import datetime
11 import datetime
12 from zmq.utils.monitor import recv_monitor_message
12 from zmq.utils.monitor import recv_monitor_message
13 from functools import wraps
13 from functools import wraps
14 from threading import Thread
14 from threading import Thread
15 from multiprocessing import Process
15 from multiprocessing import Process
16
16
17 from schainpy.model.proc.jroproc_base import Operation, ProcessingUnit
17 from schainpy.model.proc.jroproc_base import Operation, ProcessingUnit
18
18
19 MAXNUMX = 100
19 MAXNUMX = 100
20 MAXNUMY = 100
20 MAXNUMY = 100
21
21
22 class PrettyFloat(float):
22 class PrettyFloat(float):
23 def __repr__(self):
23 def __repr__(self):
24 return '%.2f' % self
24 return '%.2f' % self
25
25
26 def roundFloats(obj):
26 def roundFloats(obj):
27 if isinstance(obj, list):
27 if isinstance(obj, list):
28 return map(roundFloats, obj)
28 return map(roundFloats, obj)
29 elif isinstance(obj, float):
29 elif isinstance(obj, float):
30 return round(obj, 2)
30 return round(obj, 2)
31
31
32
32
33 class throttle(object):
33 class throttle(object):
34 """Decorator that prevents a function from being called more than once every
34 """Decorator that prevents a function from being called more than once every
35 time period.
35 time period.
36 To create a function that cannot be called more than once a minute, but
36 To create a function that cannot be called more than once a minute, but
37 will sleep until it can be called:
37 will sleep until it can be called:
38 @throttle(minutes=1)
38 @throttle(minutes=1)
39 def foo():
39 def foo():
40 pass
40 pass
41
41
42 for i in range(10):
42 for i in range(10):
43 foo()
43 foo()
44 print "This function has run %s times." % i
44 print "This function has run %s times." % i
45 """
45 """
46
46
47 def __init__(self, seconds=0, minutes=0, hours=0):
47 def __init__(self, seconds=0, minutes=0, hours=0):
48 self.throttle_period = datetime.timedelta(
48 self.throttle_period = datetime.timedelta(
49 seconds=seconds, minutes=minutes, hours=hours
49 seconds=seconds, minutes=minutes, hours=hours
50 )
50 )
51
51
52 self.time_of_last_call = datetime.datetime.min
52 self.time_of_last_call = datetime.datetime.min
53
53
54 def __call__(self, fn):
54 def __call__(self, fn):
55 @wraps(fn)
55 @wraps(fn)
56 def wrapper(*args, **kwargs):
56 def wrapper(*args, **kwargs):
57 now = datetime.datetime.now()
57 now = datetime.datetime.now()
58 time_since_last_call = now - self.time_of_last_call
58 time_since_last_call = now - self.time_of_last_call
59 time_left = self.throttle_period - time_since_last_call
59 time_left = self.throttle_period - time_since_last_call
60
60
61 if time_left > datetime.timedelta(seconds=0):
61 if time_left > datetime.timedelta(seconds=0):
62 return
62 return
63
63
64 self.time_of_last_call = datetime.datetime.now()
64 self.time_of_last_call = datetime.datetime.now()
65 return fn(*args, **kwargs)
65 return fn(*args, **kwargs)
66
66
67 return wrapper
67 return wrapper
68
68
69
69
70 class PublishData(Operation):
70 class PublishData(Operation):
71 """Clase publish."""
71 """Clase publish."""
72
72
73 def __init__(self, **kwargs):
73 def __init__(self, **kwargs):
74 """Inicio."""
74 """Inicio."""
75 Operation.__init__(self, **kwargs)
75 Operation.__init__(self, **kwargs)
76 self.isConfig = False
76 self.isConfig = False
77 self.client = None
77 self.client = None
78 self.zeromq = None
78 self.zeromq = None
79 self.mqtt = None
79 self.mqtt = None
80
80
81 def on_disconnect(self, client, userdata, rc):
81 def on_disconnect(self, client, userdata, rc):
82 if rc != 0:
82 if rc != 0:
83 print("Unexpected disconnection.")
83 print("Unexpected disconnection.")
84 self.connect()
84 self.connect()
85
85
86 def connect(self):
86 def connect(self):
87 print 'trying to connect'
87 print 'trying to connect'
88 try:
88 try:
89 self.client.connect(
89 self.client.connect(
90 host=self.host,
90 host=self.host,
91 port=self.port,
91 port=self.port,
92 keepalive=60*10,
92 keepalive=60*10,
93 bind_address='')
93 bind_address='')
94 self.client.loop_start()
94 self.client.loop_start()
95 # self.client.publish(
95 # self.client.publish(
96 # self.topic + 'SETUP',
96 # self.topic + 'SETUP',
97 # json.dumps(setup),
97 # json.dumps(setup),
98 # retain=True
98 # retain=True
99 # )
99 # )
100 except:
100 except:
101 print "MQTT Conection error."
101 print "MQTT Conection error."
102 self.client = False
102 self.client = False
103
103
104 def setup(self, port=1883, username=None, password=None, clientId="user", zeromq=1, **kwargs):
104 def setup(self, port=1883, username=None, password=None, clientId="user", zeromq=1, **kwargs):
105 self.counter = 0
105 self.counter = 0
106 self.topic = kwargs.get('topic', 'schain')
106 self.topic = kwargs.get('topic', 'schain')
107 self.delay = kwargs.get('delay', 0)
107 self.delay = kwargs.get('delay', 0)
108 self.plottype = kwargs.get('plottype', 'spectra')
108 self.plottype = kwargs.get('plottype', 'spectra')
109 self.host = kwargs.get('host', "10.10.10.82")
109 self.host = kwargs.get('host', "10.10.10.82")
110 self.port = kwargs.get('port', 3000)
110 self.port = kwargs.get('port', 3000)
111 self.clientId = clientId
111 self.clientId = clientId
112 self.cnt = 0
112 self.cnt = 0
113 self.zeromq = zeromq
113 self.zeromq = zeromq
114 self.mqtt = kwargs.get('plottype', 0)
114 self.mqtt = kwargs.get('plottype', 0)
115 self.client = None
115 self.client = None
116 setup = []
116 setup = []
117 if mqtt is 1:
117 if mqtt is 1:
118 self.client = mqtt.Client(
118 self.client = mqtt.Client(
119 client_id=self.clientId + self.topic + 'SCHAIN',
119 client_id=self.clientId + self.topic + 'SCHAIN',
120 clean_session=True)
120 clean_session=True)
121 self.client.on_disconnect = self.on_disconnect
121 self.client.on_disconnect = self.on_disconnect
122 self.connect()
122 self.connect()
123 for plot in self.plottype:
123 for plot in self.plottype:
124 setup.append({
124 setup.append({
125 'plot': plot,
125 'plot': plot,
126 'topic': self.topic + plot,
126 'topic': self.topic + plot,
127 'title': getattr(self, plot + '_' + 'title', False),
127 'title': getattr(self, plot + '_' + 'title', False),
128 'xlabel': getattr(self, plot + '_' + 'xlabel', False),
128 'xlabel': getattr(self, plot + '_' + 'xlabel', False),
129 'ylabel': getattr(self, plot + '_' + 'ylabel', False),
129 'ylabel': getattr(self, plot + '_' + 'ylabel', False),
130 'xrange': getattr(self, plot + '_' + 'xrange', False),
130 'xrange': getattr(self, plot + '_' + 'xrange', False),
131 'yrange': getattr(self, plot + '_' + 'yrange', False),
131 'yrange': getattr(self, plot + '_' + 'yrange', False),
132 'zrange': getattr(self, plot + '_' + 'zrange', False),
132 'zrange': getattr(self, plot + '_' + 'zrange', False),
133 })
133 })
134 if zeromq is 1:
134 if zeromq is 1:
135 context = zmq.Context()
135 context = zmq.Context()
136 self.zmq_socket = context.socket(zmq.PUSH)
136 self.zmq_socket = context.socket(zmq.PUSH)
137 server = kwargs.get('server', 'zmq.pipe')
137 server = kwargs.get('server', 'zmq.pipe')
138
138
139 if 'tcp://' in server:
139 if 'tcp://' in server:
140 address = server
140 address = server
141 else:
141 else:
142 address = 'ipc:///tmp/%s' % server
142 address = 'ipc:///tmp/%s' % server
143
143
144 self.zmq_socket.connect(address)
144 self.zmq_socket.connect(address)
145 time.sleep(1)
145 time.sleep(1)
146
146
147
147
148
148
149 def publish_data(self):
149 def publish_data(self):
150 self.dataOut.finished = False
150 self.dataOut.finished = False
151 if self.mqtt is 1:
151 if self.mqtt is 1:
152 yData = self.dataOut.heightList[:2].tolist()
152 yData = self.dataOut.heightList[:2].tolist()
153 if self.plottype == 'spectra':
153 if self.plottype == 'spectra':
154 data = getattr(self.dataOut, 'data_spc')
154 data = getattr(self.dataOut, 'data_spc')
155 z = data/self.dataOut.normFactor
155 z = data/self.dataOut.normFactor
156 zdB = 10*numpy.log10(z)
156 zdB = 10*numpy.log10(z)
157 xlen, ylen = zdB[0].shape
157 xlen, ylen = zdB[0].shape
158 dx = int(xlen/MAXNUMX) + 1
158 dx = int(xlen/MAXNUMX) + 1
159 dy = int(ylen/MAXNUMY) + 1
159 dy = int(ylen/MAXNUMY) + 1
160 Z = [0 for i in self.dataOut.channelList]
160 Z = [0 for i in self.dataOut.channelList]
161 for i in self.dataOut.channelList:
161 for i in self.dataOut.channelList:
162 Z[i] = zdB[i][::dx, ::dy].tolist()
162 Z[i] = zdB[i][::dx, ::dy].tolist()
163 payload = {
163 payload = {
164 'timestamp': self.dataOut.utctime,
164 'timestamp': self.dataOut.utctime,
165 'data': roundFloats(Z),
165 'data': roundFloats(Z),
166 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList],
166 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList],
167 'interval': self.dataOut.getTimeInterval(),
167 'interval': self.dataOut.getTimeInterval(),
168 'type': self.plottype,
168 'type': self.plottype,
169 'yData': yData
169 'yData': yData
170 }
170 }
171 # print payload
171 # print payload
172
172
173 elif self.plottype in ('rti', 'power'):
173 elif self.plottype in ('rti', 'power'):
174 data = getattr(self.dataOut, 'data_spc')
174 data = getattr(self.dataOut, 'data_spc')
175 z = data/self.dataOut.normFactor
175 z = data/self.dataOut.normFactor
176 avg = numpy.average(z, axis=1)
176 avg = numpy.average(z, axis=1)
177 avgdB = 10*numpy.log10(avg)
177 avgdB = 10*numpy.log10(avg)
178 xlen, ylen = z[0].shape
178 xlen, ylen = z[0].shape
179 dy = numpy.floor(ylen/self.__MAXNUMY) + 1
179 dy = numpy.floor(ylen/self.__MAXNUMY) + 1
180 AVG = [0 for i in self.dataOut.channelList]
180 AVG = [0 for i in self.dataOut.channelList]
181 for i in self.dataOut.channelList:
181 for i in self.dataOut.channelList:
182 AVG[i] = avgdB[i][::dy].tolist()
182 AVG[i] = avgdB[i][::dy].tolist()
183 payload = {
183 payload = {
184 'timestamp': self.dataOut.utctime,
184 'timestamp': self.dataOut.utctime,
185 'data': roundFloats(AVG),
185 'data': roundFloats(AVG),
186 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList],
186 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList],
187 'interval': self.dataOut.getTimeInterval(),
187 'interval': self.dataOut.getTimeInterval(),
188 'type': self.plottype,
188 'type': self.plottype,
189 'yData': yData
189 'yData': yData
190 }
190 }
191 elif self.plottype == 'noise':
191 elif self.plottype == 'noise':
192 noise = self.dataOut.getNoise()/self.dataOut.normFactor
192 noise = self.dataOut.getNoise()/self.dataOut.normFactor
193 noisedB = 10*numpy.log10(noise)
193 noisedB = 10*numpy.log10(noise)
194 payload = {
194 payload = {
195 'timestamp': self.dataOut.utctime,
195 'timestamp': self.dataOut.utctime,
196 'data': roundFloats(noisedB.reshape(-1, 1).tolist()),
196 'data': roundFloats(noisedB.reshape(-1, 1).tolist()),
197 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList],
197 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList],
198 'interval': self.dataOut.getTimeInterval(),
198 'interval': self.dataOut.getTimeInterval(),
199 'type': self.plottype,
199 'type': self.plottype,
200 'yData': yData
200 'yData': yData
201 }
201 }
202 elif self.plottype == 'snr':
202 elif self.plottype == 'snr':
203 data = getattr(self.dataOut, 'data_SNR')
203 data = getattr(self.dataOut, 'data_SNR')
204 avgdB = 10*numpy.log10(data)
204 avgdB = 10*numpy.log10(data)
205
205
206 ylen = data[0].size
206 ylen = data[0].size
207 dy = numpy.floor(ylen/self.__MAXNUMY) + 1
207 dy = numpy.floor(ylen/self.__MAXNUMY) + 1
208 AVG = [0 for i in self.dataOut.channelList]
208 AVG = [0 for i in self.dataOut.channelList]
209 for i in self.dataOut.channelList:
209 for i in self.dataOut.channelList:
210 AVG[i] = avgdB[i][::dy].tolist()
210 AVG[i] = avgdB[i][::dy].tolist()
211 payload = {
211 payload = {
212 'timestamp': self.dataOut.utctime,
212 'timestamp': self.dataOut.utctime,
213 'data': roundFloats(AVG),
213 'data': roundFloats(AVG),
214 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList],
214 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList],
215 'type': self.plottype,
215 'type': self.plottype,
216 'yData': yData
216 'yData': yData
217 }
217 }
218 else:
218 else:
219 print "Tipo de grafico invalido"
219 print "Tipo de grafico invalido"
220 payload = {
220 payload = {
221 'data': 'None',
221 'data': 'None',
222 'timestamp': 'None',
222 'timestamp': 'None',
223 'type': None
223 'type': None
224 }
224 }
225 # print 'Publishing data to {}'.format(self.host)
225 # print 'Publishing data to {}'.format(self.host)
226 self.client.publish(self.topic + self.plottype, json.dumps(payload), qos=0)
226 self.client.publish(self.topic + self.plottype, json.dumps(payload), qos=0)
227
227
228 if self.zeromq is 1:
228 if self.zeromq is 1:
229 print '[Sending] {} - {}'.format(self.dataOut.type, self.dataOut.datatime)
229 print '[Sending] {} - {}'.format(self.dataOut.type, self.dataOut.datatime)
230 self.zmq_socket.send_pyobj(self.dataOut)
230 self.zmq_socket.send_pyobj(self.dataOut)
231
231
232 def run(self, dataOut, **kwargs):
232 def run(self, dataOut, **kwargs):
233 self.dataOut = dataOut
233 self.dataOut = dataOut
234 if not self.isConfig:
234 if not self.isConfig:
235 self.setup(**kwargs)
235 self.setup(**kwargs)
236 self.isConfig = True
236 self.isConfig = True
237
237
238 self.publish_data()
238 self.publish_data()
239 time.sleep(self.delay)
239 time.sleep(self.delay)
240
240
241 def close(self):
241 def close(self):
242 if self.zeromq is 1:
242 if self.zeromq is 1:
243 self.dataOut.finished = True
243 self.dataOut.finished = True
244 self.zmq_socket.send_pyobj(self.dataOut)
244 self.zmq_socket.send_pyobj(self.dataOut)
245
245
246 if self.client:
246 if self.client:
247 self.client.loop_stop()
247 self.client.loop_stop()
248 self.client.disconnect()
248 self.client.disconnect()
249
249
250
250
251 class ReceiverData(ProcessingUnit, Process):
251 class ReceiverData(ProcessingUnit, Process):
252
252
253 throttle_value = 5
253 throttle_value = 5
254
254
255 def __init__(self, **kwargs):
255 def __init__(self, **kwargs):
256
256
257 ProcessingUnit.__init__(self, **kwargs)
257 ProcessingUnit.__init__(self, **kwargs)
258 Process.__init__(self)
258 Process.__init__(self)
259 self.mp = False
259 self.mp = False
260 self.isConfig = False
260 self.isConfig = False
261 self.plottypes =[]
261 self.plottypes =[]
262 self.connections = 0
262 self.connections = 0
263 server = kwargs.get('server', 'zmq.pipe')
263 server = kwargs.get('server', 'zmq.pipe')
264 if 'tcp://' in server:
264 if 'tcp://' in server:
265 address = server
265 address = server
266 else:
266 else:
267 address = 'ipc:///tmp/%s' % server
267 address = 'ipc:///tmp/%s' % server
268
268
269 self.address = address
269 self.address = address
270 self.plottypes = [s.strip() for s in kwargs.get('plottypes', 'rti').split(',')]
270 self.plottypes = [s.strip() for s in kwargs.get('plottypes', 'rti').split(',')]
271 self.realtime = kwargs.get('realtime', False)
271 self.realtime = kwargs.get('realtime', False)
272 self.throttle_value = kwargs.get('throttle', 10)
272 self.throttle_value = kwargs.get('throttle', 10)
273 self.sendData = self.initThrottle(self.throttle_value)
273 self.sendData = self.initThrottle(self.throttle_value)
274 self.setup()
274 self.setup()
275
275
276 def setup(self):
276 def setup(self):
277
277
278 self.data = {}
278 self.data = {}
279 self.data['times'] = []
279 self.data['times'] = []
280 for plottype in self.plottypes:
280 for plottype in self.plottypes:
281 self.data[plottype] = {}
281 self.data[plottype] = {}
282 self.data['noise'] = {}
282 self.data['noise'] = {}
283 self.data['throttle'] = self.throttle_value
283 self.data['throttle'] = self.throttle_value
284 self.data['ENDED'] = False
284 self.data['ENDED'] = False
285 self.isConfig = True
285 self.isConfig = True
286 self.data_web = {}
286
287
287 def event_monitor(self, monitor):
288 def event_monitor(self, monitor):
288
289
289 events = {}
290 events = {}
290
291
291 for name in dir(zmq):
292 for name in dir(zmq):
292 if name.startswith('EVENT_'):
293 if name.startswith('EVENT_'):
293 value = getattr(zmq, name)
294 value = getattr(zmq, name)
294 events[value] = name
295 events[value] = name
295
296
296 while monitor.poll():
297 while monitor.poll():
297 evt = recv_monitor_message(monitor)
298 evt = recv_monitor_message(monitor)
298 if evt['event'] == 32:
299 if evt['event'] == 32:
299 self.connections += 1
300 self.connections += 1
300 if evt['event'] == 512:
301 if evt['event'] == 512:
301 pass
302 pass
302 if self.connections == 0 and self.started is True:
303 if self.connections == 0 and self.started is True:
303 self.ended = True
304 self.ended = True
304 # send('ENDED')
305 # send('ENDED')
305 evt.update({'description': events[evt['event']]})
306 evt.update({'description': events[evt['event']]})
306
307
307 if evt['event'] == zmq.EVENT_MONITOR_STOPPED:
308 if evt['event'] == zmq.EVENT_MONITOR_STOPPED:
308 break
309 break
309 monitor.close()
310 monitor.close()
310 print("event monitor thread done!")
311 print("event monitor thread done!")
311
312
312 def initThrottle(self, throttle_value):
313 def initThrottle(self, throttle_value):
313
314
314 @throttle(seconds=throttle_value)
315 @throttle(seconds=throttle_value)
315 def sendDataThrottled(fn_sender, data):
316 def sendDataThrottled(fn_sender, data):
316 fn_sender(data)
317 fn_sender(data)
317
318
318 return sendDataThrottled
319 return sendDataThrottled
319
320
320 def send(self, data):
321 def send(self, data):
321 print '[sending] data=%s size=%s' % (data.keys(), len(data['times']))
322 print '[sending] data=%s size=%s' % (data.keys(), len(data['times']))
322 self.sender.send_pyobj(data)
323 self.sender.send_pyobj(data)
323
324
324 def update(self):
325 def update(self):
325
326
326 t = self.dataOut.ltctime
327 t = self.dataOut.ltctime
327 self.data['times'].append(t)
328 self.data['times'].append(t)
328 self.data['dataOut'] = self.dataOut
329 self.data['dataOut'] = self.dataOut
329 for plottype in self.plottypes:
330 for plottype in self.plottypes:
330
331 if plottype == 'spc':
331 if plottype == 'spc':
332 z = self.dataOut.data_spc/self.dataOut.normFactor
332 z = self.dataOut.data_spc/self.dataOut.normFactor
333 self.data[plottype] = 10*numpy.log10(z)
333 self.data[plottype] = 10*numpy.log10(z)
334 self.data['noise'][t] = 10*numpy.log10(self.dataOut.getNoise()/self.dataOut.normFactor)
334 self.data['noise'][t] = 10*numpy.log10(self.dataOut.getNoise()/self.dataOut.normFactor)
335 if plottype == 'rti':
335 if plottype == 'rti':
336 self.data[plottype][t] = self.dataOut.getPower()
336 self.data[plottype][t] = self.dataOut.getPower()
337 if plottype == 'snr':
337 if plottype == 'snr':
338 self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_SNR)
338 self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_SNR)
339 if plottype == 'dop':
339 if plottype == 'dop':
340 self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_DOP)
340 self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_DOP)
341 if plottype == 'coh':
341 if plottype == 'coh':
342 self.data[plottype][t] = self.dataOut.getCoherence()
342 self.data[plottype][t] = self.dataOut.getCoherence()
343 if plottype == 'phase':
343 if plottype == 'phase':
344 self.data[plottype][t] = self.dataOut.getCoherence(phase=True)
344 self.data[plottype][t] = self.dataOut.getCoherence(phase=True)
345
345 if self.realtime:
346 self.data_web[plottype] = self.data[plottype][t]
347 self.data_web['time'] = t
346 def run(self):
348 def run(self):
347
349
348 print '[Starting] {} from {}'.format(self.name, self.address)
350 print '[Starting] {} from {}'.format(self.name, self.address)
349
351
350 self.context = zmq.Context()
352 self.context = zmq.Context()
351 self.receiver = self.context.socket(zmq.PULL)
353 self.receiver = self.context.socket(zmq.PULL)
352 self.receiver.bind(self.address)
354 self.receiver.bind(self.address)
353 monitor = self.receiver.get_monitor_socket()
355 monitor = self.receiver.get_monitor_socket()
354 self.sender = self.context.socket(zmq.PUB)
356 self.sender = self.context.socket(zmq.PUB)
355
357 if self.realtime:
358 self.sender_web = self.context.socket(zmq.PUB)
359 self.sender.bind("ipc:///tmp/zmq.web")
356 self.sender.bind("ipc:///tmp/zmq.plots")
360 self.sender.bind("ipc:///tmp/zmq.plots")
357
361
358 t = Thread(target=self.event_monitor, args=(monitor,))
362 t = Thread(target=self.event_monitor)
359 t.start()
363 t.start()
360
364
361 while True:
365 while True:
362 self.dataOut = self.receiver.recv_pyobj()
366 self.dataOut = self.receiver.recv_pyobj()
363 # print '[Receiving] {} - {}'.format(self.dataOut.type,
367 # print '[Receiving] {} - {}'.format(self.dataOut.type,
364 # self.dataOut.datatime.ctime())
368 # self.dataOut.datatime.ctime())
365
369
366 self.update()
370 self.update()
367
371
368 if self.dataOut.finished is True:
372 if self.dataOut.finished is True:
369 self.send(self.data)
373 self.send(self.data)
370 self.connections -= 1
374 self.connections -= 1
371 if self.connections == 0 and self.started:
375 if self.connections == 0 and self.started:
372 self.ended = True
376 self.ended = True
373 self.data['ENDED'] = True
377 self.data['ENDED'] = True
374 self.send(self.data)
378 self.send(self.data)
375 self.setup()
379 self.setup()
376 else:
380 else:
377 if self.realtime:
381 if self.realtime:
378 self.send(self.data)
382 self.send(self.data)
383 self.sender_web.send_json(json.dumps(self.data_web))
379 else:
384 else:
380 self.sendData(self.send, self.data)
385 self.sendData(self.send, self.data)
381 self.started = True
386 self.started = True
382
387
383 return
388 return
@@ -1,48 +1,50
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 '''
2 '''
3 Created on Jul 7, 2014
3 Created on Jul 7, 2014
4
4
5 @author: roj-idl71
5 @author: roj-idl71
6 '''
6 '''
7 import os, sys
7 import os, sys
8
8
9 from schainpy.controller import Project
9 from schainpy.controller import Project
10
10
11 if __name__ == '__main__':
11 if __name__ == '__main__':
12 desc = "Segundo Test"
12 desc = "Segundo Test"
13
13
14 controllerObj = Project()
14 controllerObj = Project()
15 controllerObj.setup(id='191', name='test01', description=desc)
15 controllerObj.setup(id='191', name='test01', description=desc)
16
16
17 proc1 = controllerObj.addProcUnit(name='ReceiverData')
17 proc1 = controllerObj.addProcUnit(name='ReceiverData')
18 proc1.addParameter(name='realtime', value='0', format='bool')
18 proc1.addParameter(name='realtime', value='1', format='bool')
19 proc1.addParameter(name='plottypes', value='rti,coh,phase', format='str')
20 proc1.addParameter(name='throttle', value='10', format='int')
21
19
22 op1 = proc1.addOperation(name='PlotRTIData', optype='other')
20 proc1.addParameter(name='plottypes', value='rti', format='str')
23 op1.addParameter(name='wintitle', value='Julia 150Km', format='str')
21 proc1.addParameter(name='throttle', value='10', format='int')
24 op1.addParameter(name='save', value='/home/nanosat/Pictures', format='str')
22 ## TODO Agregar direccion de server de publicacion a graficos como variable
25
23
26 op2 = proc1.addOperation(name='PlotCOHData', optype='other')
24 # op1 = proc1.addOperation(name='PlotRTIData', optype='other')
27 op2.addParameter(name='wintitle', value='Julia 150Km', format='str')
25 # op1.addParameter(name='wintitle', value='Julia 150Km', format='str')
28 op2.addParameter(name='save', value='/home/nanosat/Pictures', format='str')
26 # op1.addParameter(name='save', value='/home/nanosat/Pictures', format='str')
29 #
27 #
30 op6 = proc1.addOperation(name='PlotPHASEData', optype='other')
28 # op2 = proc1.addOperation(name='PlotCOHData', optype='other')
31 op6.addParameter(name='wintitle', value='Julia 150Km', format='str')
29 # op2.addParameter(name='wintitle', value='Julia 150Km', format='str')
32 op6.addParameter(name='save', value='/home/nanosat/Pictures', format='str')
30 # op2.addParameter(name='save', value='/home/nanosat/Pictures', format='str')
31 # #
32 # op6 = proc1.addOperation(name='PlotPHASEData', optype='other')
33 # op6.addParameter(name='wintitle', value='Julia 150Km', format='str')
34 # op6.addParameter(name='save', value='/home/nanosat/Pictures', format='str')
33 #
35 #
34 # proc2 = controllerObj.addProcUnit(name='ReceiverData')
36 # proc2 = controllerObj.addProcUnit(name='ReceiverData')
35 # proc2.addParameter(name='server', value='juanca', format='str')
37 # proc2.addParameter(name='server', value='juanca', format='str')
36 # proc2.addParameter(name='plottypes', value='snr,dop', format='str')
38 # proc2.addParameter(name='plottypes', value='snr,dop', format='str')
37 #
39 #
38 # op3 = proc2.addOperation(name='PlotSNRData', optype='other')
40 # op3 = proc2.addOperation(name='PlotSNRData', optype='other')
39 # op3.addParameter(name='wintitle', value='Julia 150Km', format='str')
41 # op3.addParameter(name='wintitle', value='Julia 150Km', format='str')
40 # op3.addParameter(name='save', value='/home/nanosat/Pictures', format='str')
42 # op3.addParameter(name='save', value='/home/nanosat/Pictures', format='str')
41 #
43 #
42 # op4 = proc2.addOperation(name='PlotDOPData', optype='other')
44 # op4 = proc2.addOperation(name='PlotDOPData', optype='other')
43 # op4.addParameter(name='wintitle', value='Julia 150Km', format='str')
45 # op4.addParameter(name='wintitle', value='Julia 150Km', format='str')
44 # op4.addParameter(name='save', value='/home/nanosat/Pictures', format='str')
46 # op4.addParameter(name='save', value='/home/nanosat/Pictures', format='str')
45
47
46
48
47
49
48 controllerObj.start()
50 controllerObj.start()
General Comments 0
You need to be logged in to leave comments. Login now