##// END OF EJS Templates
Task #961: Actualizar status de modulos ABS con subproceso...
Fiorella Quino -
r258:0e34c33380c6
parent child
Show More
@@ -1,1331 +1,1342
1 1 from django.db import models
2 2 from apps.main.models import Configuration
3 3 from django.core.urlresolvers import reverse
4 4 # Create your models here.
5 5 from celery.execute import send_task
6 6 from datetime import datetime
7 7 import ast
8 8 import socket
9 9 import json
10 10 import requests
11 11 import struct
12 12 import sys, time
13 13
14 14 import multiprocessing
15 15
16 16
17 17 antenna_default = json.dumps({
18 18 "antenna_up": [[0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
19 19 [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
20 20 [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
21 21 [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
22 22 [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0],
23 23 [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0],
24 24 [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0],
25 25 [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0]
26 26 ]
27 27 ,
28 28 "antenna_down": [[0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
29 29 [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
30 30 [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
31 31 [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
32 32 [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0],
33 33 [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0],
34 34 [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0],
35 35 [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0]],
36 36 })
37 37
38 38
39 39 tx_default = json.dumps({
40 40 "up": [[1,1,1,1,0,0,0,0],
41 41 [1,1,1,1,0,0,0,0],
42 42 [1,1,1,1,0,0,0,0],
43 43 [1,1,1,1,0,0,0,0],
44 44 [0,0,0,0,1,1,1,1],
45 45 [0,0,0,0,1,1,1,1],
46 46 [0,0,0,0,1,1,1,1],
47 47 [0,0,0,0,1,1,1,1]],
48 48
49 49 "down": [[1,1,1,1,0,0,0,0],
50 50 [1,1,1,1,0,0,0,0],
51 51 [1,1,1,1,0,0,0,0],
52 52 [1,1,1,1,0,0,0,0],
53 53 [0,0,0,0,1,1,1,1],
54 54 [0,0,0,0,1,1,1,1],
55 55 [0,0,0,0,1,1,1,1],
56 56 [0,0,0,0,1,1,1,1]],
57 57 })
58 58
59 59 rx_default = json.dumps({
60 60 "up": [[1,1,1,1,0,0,0,0],
61 61 [1,1,1,1,0,0,0,0],
62 62 [1,1,1,1,0,0,0,0],
63 63 [1,1,1,1,0,0,0,0],
64 64 [0,0,0,0,1,1,1,1],
65 65 [0,0,0,0,1,1,1,1],
66 66 [0,0,0,0,1,1,1,1],
67 67 [0,0,0,0,1,1,1,1]],
68 68
69 69 "down": [[1,1,1,1,0,0,0,0],
70 70 [1,1,1,1,0,0,0,0],
71 71 [1,1,1,1,0,0,0,0],
72 72 [1,1,1,1,0,0,0,0],
73 73 [0,0,0,0,1,1,1,1],
74 74 [0,0,0,0,1,1,1,1],
75 75 [0,0,0,0,1,1,1,1],
76 76 [0,0,0,0,1,1,1,1]],
77 77 })
78 78
79 79 conf_default = {}
80 80 status_default = {}
81 81 default_messages = {}
82 82 default_modulemode = {"1": 0, "2": 0, "3": 0, "4": 0, "5": 0, "6": 0, "7": 0, "8": 0, "9": 0, "10": 0,
83 83 "11": 0, "12": 0, "13": 0, "14": 0, "15": 0, "16": 0, "17": 0, "18": 0, "19": 0, "20": 0,
84 84 "21": 0, "22": 0, "23": 0, "24": 0, "25": 0, "26": 0, "27": 0, "28": 0, "29": 0, "30": 0,
85 85 "31": 0, "32": 0, "33": 0, "34": 0, "35": 0, "36": 0, "37": 0, "38": 0, "39": 0, "40": 0,
86 86 "41": 0, "42": 0, "43": 0, "44": 0, "45": 0, "46": 0, "47": 0, "48": 0, "49": 0, "50": 0,
87 87 "51": 0, "52": 0, "53": 0, "54": 0, "55": 0, "56": 0, "57": 0, "58": 0, "59": 0, "60": 0,
88 88 "61": 0, "62": 0, "63": 0, "64": 0} # 0 : Socket // 1: API Rest
89 89
90 90 for i in range(1,65):
91 91 conf_default[str(i)] = ""
92 92 status_default[str(i)] = 0
93 93 default_messages[str(i)] = "Module "+str(i)
94 94
95 95
96 96 ues_default = json.dumps({
97 97 "up": [0.533333,0.00000,1.06667,0.00000],
98 98 "down": [0.533333,0.00000,1.06667,0.00000]
99 99 })
100 100
101 101 onlyrx_default = json.dumps({
102 102 "up": False,
103 103 "down": False
104 104 })
105 105
106 106 def up_convertion(cadena):
107 107 valores = []
108 108 for c in cadena:
109 109 if c == 1.0: valores=valores+['000']
110 110 if c == 2.0: valores=valores+['001']
111 111 if c == 3.0: valores=valores+['010']
112 112 if c == 0.0: valores=valores+['011']
113 113 if c == 0.5: valores=valores+['100']
114 114 if c == 1.5: valores=valores+['101']
115 115 if c == 2.5: valores=valores+['110']
116 116 if c == 3.5: valores=valores+['111']
117 117
118 118 return valores
119 119
120 120 def up_conv_bits(value):
121 121
122 122 if value == 1.0: bits="000"
123 123 if value == 2.0: bits="001"
124 124 if value == 3.0: bits="010"
125 125 if value == 0.0: bits="011"
126 126 if value == 0.5: bits="100"
127 127 if value == 1.5: bits="101"
128 128 if value == 2.5: bits="110"
129 129 if value == 3.5: bits="111"
130 130
131 131 return bits
132 132
133 133 def down_convertion(cadena):
134 134 valores = []
135 135 for c in cadena:
136 136 if c == 1.0: valores=valores+['000']
137 137 if c == 2.0: valores=valores+['001']
138 138 if c == 3.0: valores=valores+['010']
139 139 if c == 0.0: valores=valores+['011']
140 140 if c == 0.5: valores=valores+['100']
141 141 if c == 1.5: valores=valores+['101']
142 142 if c == 2.5: valores=valores+['110']
143 143 if c == 3.5: valores=valores+['111']
144 144
145 145 return valores
146 146
147 147 def down_conv_bits(value):
148 148
149 149 if value == 1.0: bits="000"
150 150 if value == 2.0: bits="001"
151 151 if value == 3.0: bits="010"
152 152 if value == 0.0: bits="011"
153 153 if value == 0.5: bits="100"
154 154 if value == 1.5: bits="101"
155 155 if value == 2.5: bits="110"
156 156 if value == 3.5: bits="111"
157 157
158 158 return bits
159 159
160 160 def up_conv_value(bits):
161 161
162 162 if bits == "000": value=1.0
163 163 if bits == "001": value=2.0
164 164 if bits == "010": value=3.0
165 165 if bits == "011": value=0.0
166 166 if bits == "100": value=0.5
167 167 if bits == "101": value=1.5
168 168 if bits == "110": value=2.5
169 169 if bits == "111": value=3.5
170 170
171 171 return value
172 172
173 173 def down_conv_value(bits):
174 174
175 175 if bits == "000": value=1.0
176 176 if bits == "001": value=2.0
177 177 if bits == "010": value=3.0
178 178 if bits == "011": value=0.0
179 179 if bits == "100": value=0.5
180 180 if bits == "101": value=1.5
181 181 if bits == "110": value=2.5
182 182 if bits == "111": value=3.5
183 183
184 184 return value
185 185
186 186 def ip2position(module_number):
187 187 j=0
188 188 i=0
189 189 for x in range(0,module_number-1):
190 190 j=j+1
191 191 if j==8:
192 192 i=i+1
193 193 j=0
194 194
195 195 pos = [i,j]
196 196 return pos
197 197
198 198
199 199 def fromBinary2Char(binary_string):
200 200 number = int(binary_string, 2)
201 201 #Plus 33 to avoid more than 1 characters values such as: '\x01'-'\x1f'
202 202 number = number + 33
203 203 char = chr(number)
204 204 return char
205 205
206 206 def fromChar2Binary(char):
207 207 number = ord(char) - 33
208 208 #Minus 33 to get the real value
209 209 bits = bin(number)[2:]
210 210 #To ensure we have a string with 6bits
211 211 if len(bits) < 6:
212 212 bits = bits.zfill(6)
213 213 return bits
214 214
215 215 OPERATION_MODES = (
216 216 (0, 'Manual'),
217 217 (1, 'Automatic'),
218 218 )
219 219
220 220
221 221 class ABSConfiguration(Configuration):
222 222 active_beam = models.CharField(verbose_name='Active Beam', max_length=20000, default="{}")
223 223 module_status = models.CharField(verbose_name='Module Status', max_length=10000, default=json.dumps(status_default))
224 224 operation_mode = models.PositiveSmallIntegerField(verbose_name='Operation Mode', choices=OPERATION_MODES, default = 0)
225 225 operation_value = models.FloatField(verbose_name='Periodic (seconds)', default="10", null=True, blank=True)
226 226 module_messages = models.CharField(verbose_name='Modules Messages', max_length=10000, default=json.dumps(default_messages))
227 227 module_mode = models.CharField(verbose_name='Modules Mode', max_length=10000, default=json.dumps(default_modulemode))
228 228
229 229 class Meta:
230 230 db_table = 'abs_configurations'
231 231
232 232 def get_absolute_url_plot(self):
233 233 return reverse('url_plot_abs_patterns', args=[str(self.id)])
234 234
235 235
236 236 def parms_to_dict(self):
237 237
238 238 parameters = {}
239 239
240 240 parameters['device_id'] = self.device.id
241 241 parameters['name'] = self.name
242 242 parameters['device_type'] = self.device.device_type.name
243 243 parameters['beams'] = {}
244 244
245 245 beams = ABSBeam.objects.filter(abs_conf=self)
246 246 b=1
247 247 for beam in beams:
248 248 #absbeam = ABSBeam.objects.get(pk=beams[beam])
249 249 parameters['beams']['beam'+str(b)] = beam.parms_to_dict()#absbeam.parms_to_dict()
250 250 b+=1
251 251
252 252 return parameters
253 253
254
254 255 def dict_to_parms(self, parameters):
255 256
256 257 self.name = parameters['name']
257 258
258 259 absbeams = ABSBeam.objects.filter(abs_conf=self)
259 260 beams = parameters['beams']
260 261
261 262 if absbeams:
262 263 beams_number = len(beams)
263 264 absbeams_number = len(absbeams)
264 265 if beams_number==absbeams_number:
265 266 i = 1
266 267 for absbeam in absbeams:
267 268 absbeam.dict_to_parms(beams['beam'+str(i)])
268 269 i = i+1
269 270 elif beams_number > absbeams_number:
270 271 i = 1
271 272 for absbeam in absbeams:
272 273 absbeam.dict_to_parms(beams['beam'+str(i)])
273 274 i=i+1
274 275 for x in range(i,beams_number+1):
275 276 new_beam = ABSBeam(
276 277 name =beams['beam'+str(i)]['name'],
277 278 antenna =json.dumps(beams['beam'+str(i)]['antenna']),
278 279 abs_conf = self,
279 280 tx =json.dumps(beams['beam'+str(i)]['tx']),
280 281 rx =json.dumps(beams['beam'+str(i)]['rx']),
281 282 ues =json.dumps(beams['beam'+str(i)]['ues']),
282 283 only_rx =json.dumps(beams['beam'+str(i)]['only_rx'])
283 284 )
284 285 new_beam.save()
285 286 i=i+1
286 287 else: #beams_number < absbeams_number:
287 288 i = 1
288 289 for absbeam in absbeams:
289 290 if i <= beams_number:
290 291 absbeam.dict_to_parms(beams['beam'+str(i)])
291 292 i=i+1
292 293 else:
293 294 absbeam.delete()
294 295 else:
295 296 for beam in beams:
296 297 new_beam = ABSBeam(
297 298 name =beams[beam]['name'],
298 299 antenna =json.dumps(beams[beam]['antenna']),
299 300 abs_conf = self,
300 301 tx =json.dumps(beams[beam]['tx']),
301 302 rx =json.dumps(beams[beam]['rx']),
302 303 ues =json.dumps(beams[beam]['ues']),
303 304 only_rx =json.dumps(beams[beam]['only_rx'])
304 305 )
305 306 new_beam.save()
306 307
307 308
308 309
309 310 def update_from_file(self, parameters):
310 311
311 312 self.dict_to_parms(parameters)
312 313 self.save()
313 314
314 315
315 316 def get_beams(self, **kwargs):
316 317 '''
317 318 This function returns ABS Configuration beams
318 319 '''
319 320 return ABSBeam.objects.filter(abs_conf=self.pk, **kwargs)
320 321
321 322 def clone(self, **kwargs):
322 323
323 324 beams = self.get_beams()
324 325 self.pk = None
325 326 self.id = None
326 327 for attr, value in kwargs.items():
327 328 setattr(self, attr, value)
328 329 self.save()
329 330
330 331 for beam in beams:
331 332 beam.clone(abs_conf=self)
332 333
333 334 #-----For Active Beam-----
334 335 active_beam = json.loads(self.active_beam)
335 336 new_beams = ABSBeam.objects.filter(abs_conf=self)
336 337 active_beam['active_beam'] = new_beams[0].id
337 338
338 339 self.active_beam = json.dumps(active_beam)
339 340 self.save()
340 341 #-----For Active Beam-----
341 342 #-----For Device Status---
342 343 self.device.status = 3
343 344 self.device.save()
344 345 #-----For Device Status---
345 346
346 347 return self
347 348
348 349
349 350 def start_device(self):
350 351
351 352 if self.device.status == 3:
352 353
353 354 try:
354 355 #self.write_device()
355 356 send_task('task_change_beam', [self.id],)
356 357 self.message = 'ABS running'
357 358
358 359 except Exception as e:
359 360 self.message = str(e)
360 361 return False
361 362
362 363 return True
363 364
364 365 else:
365 366 self.message = 'Please, select Write ABS Device first.'
366 367 return False
367 368
368 369
369 370 def stop_device(self):
370 371
371 372 self.device.status = 2
372 373 self.device.save()
373 374 self.message = 'ABS has been stopped.'
374 375 self.save()
375 376
376 377 return True
377 378
378 379 def monitoring_device(self):
379 380
380 381 monitoreo_tx = 'JROABSClnt_01CeCnMod000000MNTR10'
381 382 beam_tx = 'JROABSCeCnModCnMod01000001CHGB10'
382 383
383 384 beam_pos = 1
384 385 module_address = ('192.168.1.63', 5500)
385 386
386 387 message_tx = monitoreo_tx
387 388 # Create the datagram socket
388 389 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
389 390 sock.connect(module_address)
390 391
391 392 sock.send(message_tx)
392 393 t = sock.recv(1024)
393 394 print 'Respuesta: \n',t
394 395 sock.close()
395 396 sock = None
396 397
397 398 return True
398 399
399 400
400 401 def module_conf(self, module_num, beams):
401 402 """
402 403 This function creates beam configurations for one abs module.
403 404 """
404 405 ip_address = self.device.ip_address
405 406 ip_address = ip_address.split('.')
406 407 module_seq = (ip_address[0],ip_address[1],ip_address[2])
407 408 dot = '.'
408 409 module_ip = dot.join(module_seq)+'.'+str(module_num)
409 410 module_port = self.device.port_address
410 411 write_route = 'http://'+module_ip+':'+str(module_port)+'/write'
411 412
412 413 #header = 'JROABSCeCnModCnMod01000108SNDFexperimento1.ab1'
413 414 #module = 'ABS_'+str(module_num)
414 415 bs = '' #{}
415 416 i=1
416 417
417 418 for beam in beams:
418 419 #bs[i] = fromBinary2Char(beam.module_6bits(module_num))
419 420 bs = bs + fromBinary2Char(beam.module_6bits(module_num))
420 421 i=i+1
421 422
422 423 beams = bs
423 424
424 425 parameters = {}
425 426 parameters['beams'] = beams #json.dumps(beams)
426 427 print parameters
427 428 answer = ''
428 429
429 430 try:
430 431 #r_write = requests.post(write_route, parameters, timeout=0.5)
431 432 r_write = requests.post(write_route, json = parameters, timeout=0.5)
432 433 answer = r_write.json()
433 434 #self.message = answer['message']
434 435 except:
435 436 #self.message = "Could not write ABS parameters"
436 437 return False
437 438
438 439 return answer
439 440
440 441
441 442
442 443 def write_device(self):
443 444
444 445 """
445 446 This function sends the beams list to every abs module.
446 447 It needs 'module_conf' function
447 448 """
448 449
449 450 beams = ABSBeam.objects.filter(abs_conf=self)
450 451 connected_modules = ast.literal_eval(self.module_status)
451 452 suma_connected_modules = 0
452 453
453 454 for c in connected_modules:
454 455 suma_connected_modules = suma_connected_modules+connected_modules[c]
455 456 if not suma_connected_modules > 0 :
456 457 self.message = "No ABS Module detected."
457 458 return False
458 459
459 460 #-------------Write each abs module-----------
460 461 if beams:
461 462 beams_status = ast.literal_eval(self.module_status)
462 463 disconnected_modules = 0
463 464 for i in range(1,65): #(62,65)
464 465 #--------------JUEVES-------------
465 466 if beams_status[str(i)] != 0:
466 467 try:
467 468 answer = self.module_conf(i,beams)
468 469 if answer:
469 470 if answer['status']:
470 471 beams_status[str(i)] = 3
471 472 print snswer
472 473
473 474 except:
474 475 beams_status[str(i)] = 1
475 476
476 477 pass
477 478 else:
478 479 disconnected_modules += 1
479 480
480 481 else:
481 482 self.message = "ABS Configuration does not have beams"
482 483 return False
483 484
484 485 #self.device.status = 1
485 486 ##
486 487 #-------------Jueves-------------
487 488 if disconnected_modules == 64:
488 489 self.message = "Could not write ABS Modules"
489 490 self.device.status = 0
490 491 return False
491 492 else:
492 493 self.message = "ABS Beams List have been sent to ABS Modules"
493 494 beams[0].set_as_activebeam()
494 495
495 496 self.device.status = 3
496 497 self.module_status = json.dumps(beams_status)
497 498
498 499
499 500
500 501 self.save()
501 502 return True
502 503
503 504
504 505
505 506
506 507 def read_module(self, module):
507 508
508 509 """
509 510 Read out-bits (up-down) of 1 abs module NOT for Configuration
510 511 """
511 512
512 513 ip_address = self.device.ip_address
513 514 ip_address = ip_address.split('.')
514 515 module_seq = (ip_address[0],ip_address[1],ip_address[2])
515 516 dot = '.'
516 517 module_ip = dot.join(module_seq)+'.'+str(module)
517 518 module_port = self.device.port_address
518 519 read_route = 'http://'+module_ip+':'+str(module_port)+'/read'
519 520
520 521 module_status = json.loads(self.module_status)
521 522 print(read_route)
522 523
523 524 module_bits = ''
524 525
525 526 try:
526 527 r_read = requests.get(read_route, timeout=0.5)
527 528 answer = r_read.json()
528 529 module_bits = answer['allbits']
529 530 except:
530 531 return {}
531 532
532 533 return module_bits
533 534
534 535 def read_device(self):
535 536
536 537 parms = {}
537 538 # Reads active modules.
538 539 module_status = json.loads(self.module_status)
539 540 total = 0
540 541 for status in module_status:
541 542 if module_status[status] != 0:
542 543 module_bits = self.read_module(int(status))
543 544 bits={}
544 545 if module_bits:
545 546 bits = (str(module_bits['um2']) + str(module_bits['um1']) + str(module_bits['um0']) +
546 547 str(module_bits['dm2']) + str(module_bits['dm1']) + str(module_bits['dm0']) )
547 548 parms[str(status)] = bits
548 549
549 550 total +=1
550 551
551 552 if total==0:
552 553 self.message = "No ABS Module detected. Please select 'Status'."
553 554 return False
554 555
555 556
556 557
557 558 self.message = "ABS Modules have been read"
558 559 #monitoreo_tx = JROABSClnt_01CeCnMod000000MNTR10
559 560 return parms
560 561
561 562
562 563 def absmodule_status(self):
563 564 """
564 565 This function gets the status of each abs module. It sends GET method to Web Application
565 566 in Python Bottle.
566 567 This function updates "module_status" field from ABSconfiguration.
567 568 """
568 569 ip_address = self.device.ip_address
569 570 ip_address = ip_address.split('.')
570 571 module_seq = (ip_address[0],ip_address[1],ip_address[2])
571 572 dot = '.'
572 573 module_port = self.device.port_address
573 574
574 575 modules_status = json.loads(self.module_status)
575 576 module_messages = json.loads(self.module_messages)
576 577
577 578 for i in range(1,65):
578 579 module_ip = dot.join(module_seq)+'.'+str(i)
579 580 print module_ip
580 581
581 582 route = 'http://'+module_ip+':'+str(module_port)+'/status'
582 583
583 584 try:
584 585 r = requests.get(route, timeout=0.8)#, timeout=0.7)
585 586 answer = r.json()
586 587 modules_status[str(i)] = answer['status']
587 588 module_messages[str(i)] = answer['message']
588 589 except:
589 590 modules_status[str(i)] = 0
590 591 pass
591 592
592 593
593 594 self.module_status = json.dumps(modules_status)
594 595 self.module_messages = json.dumps(module_messages)
595 596 self.save()
596 597
598 print 'Termino (='
599
597 600 return
598 601
599 602
600 603 def connected_modules(self):
601 604 """
602 605 This function returns the number of connected abs-modules without updating.
603 606 """
604 607 modules_status = json.loads(self.module_status)
605 608 num = 0
606 609 for status in modules_status:
607 610 if modules_status[status] != 0:
608 611 num += 1
609 612
610 613 return num
611 614
612 615
613 616 def status_device(self):
614 617 """
615 618 This function returns the status of all abs-modules as one.
616 619 If at least one module is connected, its answer is "1"
617 620 """
618 self.absmodule_status()
621 #self.absmodule_status()
622 send_task('status_absdevice', [self.id],)
619 623 connected_modules = self.connected_modules()
620 624 if connected_modules>0:
621 625 self.message = 'ABS modules Status have been updated.'
622 626 return 1
627 else:
628 self.device.status=0
629
623 630 self.message = 'No ABS module is connected.'
631 self.save()
624 632 return 0
625 633
626 634
627 635
628 636 def write_module(self, module):
629 637
630 638 """
631 639 Send configuration to one abs module
632 640 """
633 641
634 642 parameters = {}
635 643 ip_address = self.device.ip_address
636 644 ip_address = ip_address.split('.')
637 645 module_seq = (ip_address[0],ip_address[1],ip_address[2])
638 646 dot = '.'
639 647 module_ip = dot.join(module_seq)+'.'+str(module)
640 648 module_port = self.device.port_address
641 649 write_route = 'http://'+module_ip+':'+str(module_port)+'/write'
642 650
643 651 #print write_route
644 652
645 653 #header = 'JROABSCeCnModCnMod01000108SNDFexperimento1.ab1'
646 654 #module = 'ABS_'+str(module)
647 655 beams = '!`*3<ENW'#{1: '001000', 2: '010001', 3: '010010', 4: '000011', 5: '101100', 6: '101101',
648 656 # 7: '110110', 8: '111111', 9: '000000', 10: '001001', 11: '010010', 12: '011011'}
649 657
650 658 #parameters['header'] = header
651 659 parameters['module'] = module
652 660 parameters['beams'] = json.dumps(beams)
653 661
654 662 answer = ''
655 663
656 664 try:
657 665 r_write = requests.post(write_route, parameters, timeout=0.5)
658 666 answer = r_write.json()
659 667 self.message = answer['message']
660 668 except:
661 669 self.message = "Could not write ABS parameters"
662 670 return 0
663 671
664 672
665 673 #self.device.status = int(answer['status'])
666 674
667 675 return 1
668 676
669 677
670 678 def write_module_socket(self, module):
671 679 """
672 680 This function sends beams list to one abs-module to TCP_Control_Module using sockets
673 681 """
674 682
675 683 ip_address = self.device.ip_address
676 684 ip_address = ip_address.split('.')
677 685 module_seq = (ip_address[0],ip_address[1],ip_address[2])
678 686 dot = '.'
679 687 module_ip = dot.join(module_seq)+'.'+str(module)
680 688 module_port = self.device.port_address
681 689
682 690 header = 'JROABSCeCnModCnMod01000108SNDFexperimento1.ab1'
683 691 abs_module = 'ABS_'+str(module)
684 692
685 693 beams = self.get_beams()
686 694 beams_text = ''
687 695 for beam in beams:
688 696 modules_conf=json.loads(beam.modules_conf)
689 697 beams_text = beams_text + modules_conf[str(module)] + '\n'
690 698
691 699 message_tx = header + '\n' + abs_module + '\n' + beams_text + '0'
692 700 print "Send: ", message_tx
693 701
694 702 # Create the datagram socket
695 703 module_address = (module_ip, 5500)
696 704 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
697 705 try:
698 706 sock.connect(module_address)
699 707 sock.send(message_tx)
700 708 t = sock.recv(1024)
701 709 print 'Respuesta: \n',t
702 710
703 711 except Exception as e:
704 712 print str(e)
705 713 sock.close()
706 714 sock = None
707 715 return False
708 716
709 717 sock.close()
710 718 sock = None
711 719
712 720 return True
713 721
714 722 def write_device_socket(self):
715 723 """
716 724 This function sends beams list to every connected abs-module to TCP_Control_Module using sockets
717 725 """
718 726 module_mode = json.loads(self.module_mode)
719 727 module_status = json.loads(self.module_status)
720 728
721 729 for i in range(1,65):
722 730 if module_mode[str(i)] == 0 and module_status[str(i)] == 1: # 0: Sockets + Cserver & 1: Connected
723 731 try:
724 732 self.write_module_socket(i)
725 733 except Exception as e:
726 734 print 'Error ABS '+str(i)+': '+str(e)
727 735
728 736 return True
729 737
730 738
731 739 def beam_selector(self, module, beam_pos):
732 740 """
733 741 This function selects the beam number for one absmodule.
734 742 """
735 743
736 744 if beam_pos > 0:
737 745 beam_pos = beam_pos - 1
738 746 else:
739 747 beam_pos = 0
740 748
741 749 #El indice del apunte debe ser menor que el numero total de apuntes
742 750 #El servidor tcp en el embebido comienza a contar desde 0
743 751 beams_list = ABSBeam.objects.filter(abs_conf=self)
744 752 if len(beams_list) < beam_pos:
745 753 return 0
746 754
747 755 flag = 1
748 756 if beam_pos>9:
749 757 flag = 2
750 758
751 759 module_address = ('192.168.1.'+str(module), 5500)
752 760 header = 'JROABSCeCnModCnMod0100000'
753 761 numbers = len(str(beam_pos))
754 762 function = 'CHGB'
755 763
756 764 message_tx = header+str(numbers)+function+str(beam_pos)+'0'
757 765
758 766 # Create the datagram socket
759 767 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
760 768 #sock.connect(module_address)
761 769 try:
762 770 sock.connect(module_address)
763 771 sock.send(message_tx)
764 772 sock.close()
765 773 print("Writing abs module:"+module_address[0]+"...")
766 774 except:
767 775 sock = None
768 776 print("Problem writing abs module:"+module_address[0])
769 777 return 0
770 778
771 779 return 1
772 780
773 781
774 782 def change_beam(self, beam_pos):
775 783 """
776 784 This function selects the beam number for all absmodules.
777 785 """
778 786 for i in range(1,65):
779 787 try:
780 788 self.beam_selector(i,beam_pos)
781 789 except:
782 790 print("Problem with module: 192.168.1."+str(i))
783 791 self.message = "Problem with module: 192.168.1."+str(i)
784 792 #return 0
785 793 return 1
786 794
787 795
788 796 def send_beam_num(self, beam_pos):
789 797 """
790 798 This function connects to a multicast group and sends the beam number
791 799 to all abs modules.
792 800 """
793 801
794 802 # Se manda a cero RC para poder realizar cambio de beam
795 803 confs = Configuration.objects.filter(experiment = self.experiment)
796 804 confdds = ''
797 805 confjars = ''
798 806 confrc = ''
799 807
800 808 #TO STOP DEVICES: DDS-JARS-RC
801 809 for i in range(0,len(confs)):
802 810 if i==0:
803 811 for conf in confs:
804 812 if conf.device.device_type.name == 'dds':
805 813 confdds = conf
806 814 confdds.stop_device()
807 815 break
808 816 if i==1:
809 817 for conf in confs:
810 818 if conf.device.device_type.name == 'jars':
811 819 confjars = conf
812 820 confjars.stop_device()
813 821 break
814 822 if i==2:
815 823 for conf in confs:
816 824 if conf.device.device_type.name == 'rc':
817 825 confrc = conf
818 826 confrc.stop_device()
819 827 break
820 828
821 829 if beam_pos > 0:
822 830 beam_pos = beam_pos - 1
823 831 else:
824 832 beam_pos = 0
825 833
826 834 #El indice del apunte debe ser menor que el numero total de apuntes
827 835 #El servidor tcp en el embebido comienza a contar desde 0
828 836 beams_list = ABSBeam.objects.filter(abs_conf=self)
829 837 if len(beams_list) < beam_pos:
830 838 return 0
831 839
832 840 flag = 1
833 841 if beam_pos>9:
834 842 flag = 2
835 843
836 844 header = 'JROABSCeCnModCnMod0100000'
837 845 flag = str(flag)
838 846 function = 'CHGB'
839 847 message_tx = header+flag+function+str(beam_pos)+'0'
840 848
841 849 multicast_group = '224.3.29.71'
842 850 server_address = ('',10000)
843 851
844 852 # Create the socket
845 853 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
846 854 # Bind to the server address
847 855 sock.bind(server_address)
848 856 # Telling the OS add the socket to the multicast on all interfaces
849 857 group = socket.inet_aton(multicast_group)
850 858 mreq = struct.pack('4sL', group, socket.INADDR_ANY)
851 859
852 860 try:
853 861 sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
854 862 except Exception as e:
855 863 self.message = str(e)
856 864 print str(e)
857 865 sock.close()
858 866 sock = None
859 867 return False
860 868
861 869 #print 'sending acknowledgement to all: \n' + message_tx
862 870 try:
863 871 sock.sendto(message_tx, (multicast_group, 10000))
864 872 except Exception as e:
865 873 self.message = str(e)
866 874 print str(e)
867 875 sock.close()
868 876 sock = None
869 877 return False
870 878 sock.close()
871 879 sock = None
872 880
873 881 #Start DDS-RC-JARS
874 882 if confdds:
875 883 confdds.start_device()
876 884 if confrc:
877 885 #print confrc
878 886 confrc.start_device()
879 887 if confjars:
880 888 confjars.start_device()
881 889
882 890 self.message = "ABS Beam has been changed"
883 891
884 892 return True
885 893
886 894 def test1(self):
887 895 t1 = time.time()
888 896 t2 = 0
889 897 while (t2-t1)<100:#300
890 898 t2 = time.time()
891 899 self.send_beam_num(2)
892 900 time.sleep(0.04)
893 901 self.send_beam_num(1)
894 902 time.sleep(0.04)
895 903 return
896 904
897 905 def change_procs_test1(self, module):
898 906
899 907 for i in range (1,300):#300
900 908 beam_pos = 1
901 909 module_address = ('192.168.1.'+str(module), 5500)
902 910 header = 'JROABSCeCnModCnMod0100000'
903 911 numbers = len(str(beam_pos))
904 912 function = 'CHGB'
905 913
906 914 message_tx = header+str(numbers)+function+str(beam_pos)+'0'
907 915
908 916 # Create the datagram socket
909 917 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
910 918 sock.connect(module_address)
911 919
912 920 sock.send(message_tx)
913 921 #t = sock.recv(1024)
914 922 sock.close()
915 923 sock = None
916 924
917 925
918 926 time.sleep(0.04)
919 927
920 928
921 929 beam_pos = 0
922 930 numbers = len(str(beam_pos))
923 931
924 932 message_tx = header+str(numbers)+function+str(beam_pos)+'0'
925 933
926 934 # Create the datagram socket
927 935 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
928 936 sock.connect(module_address)
929 937 sock.send(message_tx)
930 938 sock.close()
931 939 sock = None
932 940
933 941 time.sleep(0.04)
934 942
935 943
936 944 def multi_procs_test1(self):
937 945
938 946 """
939 947 This function sends the beam number to all abs modules using multiprocessing.
940 948 """
941 949
942 950 #if __name__ == "__main__":
943 951 size = 10000000 # Number of random numbers to add
944 952 procs = 65 # (Number-1) of processes to create (absmodule)
945 953
946 954 # Create a list of jobs and then iterate through
947 955 # the number of processes appending each process to
948 956 # the job list
949 957 jobs = []
950 958 for i in range(1, procs):
951 959
952 960 process = multiprocessing.Process(target=self.change_procs_test1,args=(i,))
953 961 jobs.append(process)
954 962 #print jobs
955 963
956 964 # Start the processes (i.e. calculate the random number lists)
957 965 for j in jobs:
958 966 #time.sleep(0.4)
959 967 #print j
960 968 j.start()
961 969
962 970 # Ensure all of the processes have finished
963 971 for j in jobs:
964 972 j.join()
965 973
966 974 print("List processing complete.")
967 975 return 1
968 976
969 977
970 978
971 979 def multi_procs_test2(self):
972 980 """
973 981 This function use multiprocessing python library. Importing Pool we can select
974 982 the number of cores we want to use
975 983 After 'nproc' linux command, we know how many cores computer has.
976 984 NOT WORKING
977 985 """
978 986 import multiprocessing
979 987 pool = multiprocessing.Pool(3) # cores
980 988
981 989 tasks = []
982 990 procs = 65
983 991 for i in range(62, procs):
984 992 tasks.append( (i,))
985 993 #print tasks
986 994 #pool.apply_async(self.change_procs_test1, 62)
987 995 results = [pool.apply( self.change_procs_test1, t ) for t in tasks]
988 996 #for result in results:
989 997 #result.get()
990 998 #(plotNum, plotFilename) = result.get()
991 999 #print("Result: plot %d written to %s" % (plotNum, plotFilename) )
992 1000
993 1001 return 1
994 1002
995 1003
996 1004 def multi_procs_test3(self):
997 1005 """
998 1006 This function use multiprocessing python library. Importing Pool we can select
999 1007 the number of cores we want to use
1000 1008 After 'nproc' linux command, we know how many cores computer has.
1001 1009 """
1002 1010 from multiprocessing import Pool
1003 1011 import time
1004 1012
1005 1013 def f(x):
1006 1014 return x*x
1007 1015
1008 1016 tasks = []
1009 1017 procs = 65
1010 1018 pool = Pool(processes=4)
1011 1019
1012 1020 #for i in range(62, procs):
1013 1021 #result = pool.map(f, range(62,65))
1014 1022 it = pool.imap(self.change_procs_test1, range(62,65))
1015 1023 #result.get(timeout=5)
1016 1024
1017 1025 return 1
1018 1026
1019 1027
1020 1028 def multi_procs_test4(self):
1021 1029 import multiprocessing as mp
1022 1030
1023 1031
1024 1032 num_workers = mp.cpu_count()
1025 1033
1026 1034 pool = mp.Pool(num_workers)
1027 1035 procs = 65
1028 1036 for i in range(62, procs):
1029 1037 #for task in tasks:
1030 1038 pool.apply_async(self.f, args = (i,))
1031 1039
1032 1040 pool.close()
1033 1041 pool.join()
1034 1042
1035 1043 return 1
1036 1044
1037 1045
1038 1046 def get_absolute_url_import(self):
1039 1047 return reverse('url_import_abs_conf', args=[str(self.id)])
1040 1048
1041 1049
1050 def get_absolute_url_status(self):
1051 return reverse('url_status_abs_conf', args=[str(self.id)])
1052
1042 1053
1043 1054
1044 1055 class ABSBeam(models.Model):
1045 1056
1046 1057 name = models.CharField(max_length=60, default='Beam')
1047 1058 antenna = models.CharField(verbose_name='Antenna', max_length=1000, default=antenna_default)
1048 1059 abs_conf = models.ForeignKey(ABSConfiguration, null=True, verbose_name='ABS Configuration')
1049 1060 tx = models.CharField(verbose_name='Tx', max_length=1000, default=tx_default)
1050 1061 rx = models.CharField(verbose_name='Rx', max_length=1000, default=rx_default)
1051 1062 s_time = models.TimeField(verbose_name='Star Time', default='00:00:00')
1052 1063 e_time = models.TimeField(verbose_name='End Time', default='23:59:59')
1053 1064 modules_conf = models.CharField(verbose_name='Modules', max_length=2000, default=json.dumps(conf_default))
1054 1065 ues = models.CharField(verbose_name='Ues', max_length=100, default=ues_default)
1055 1066 only_rx = models.CharField(verbose_name='Only RX', max_length=40, default=onlyrx_default)
1056 1067
1057 1068 class Meta:
1058 1069 db_table = 'abs_beams'
1059 1070
1060 1071 def __unicode__(self):
1061 1072 return u'%s' % (self.name)
1062 1073
1063 1074 def parms_to_dict(self):
1064 1075
1065 1076 #Update data
1066 1077 self.modules_6bits()
1067 1078
1068 1079 parameters = {}
1069 1080
1070 1081 parameters['name'] = self.name
1071 1082 parameters['antenna'] = ast.literal_eval(self.antenna)
1072 1083 parameters['abs_conf'] = self.abs_conf.name
1073 1084 parameters['tx'] = ast.literal_eval(self.tx)
1074 1085 parameters['rx'] = ast.literal_eval(self.rx)
1075 1086 parameters['s_time'] = self.s_time.strftime("%H:%M:%S")
1076 1087 parameters['e_time'] = self.e_time.strftime("%H:%M:%S")
1077 1088 parameters['configuration'] = ast.literal_eval(self.modules_conf)
1078 1089 parameters['ues'] = ast.literal_eval(self.ues)
1079 1090 parameters['only_rx'] = json.loads(self.only_rx)
1080 1091
1081 1092 return parameters
1082 1093
1083 1094 def dict_to_parms(self, parameters):
1084 1095
1085 1096 self.name = parameters['name']
1086 1097 self.antenna = json.dumps(parameters['antenna'])
1087 1098 #self.abs_conf = parameters['abs_conf']
1088 1099 self.tx = json.dumps(parameters['tx'])
1089 1100 self.rx = json.dumps(parameters['rx'])
1090 1101 #self.s_time = parameters['s_time']
1091 1102 #self.e_time = parameters['e_time']
1092 1103 self.ues = json.dumps(parameters['ues'])
1093 1104 self.only_rx = json.dumps(parameters['only_rx'])
1094 1105
1095 1106 self.modules_6bits()
1096 1107 self.save()
1097 1108
1098 1109
1099 1110 def clone(self, **kwargs):
1100 1111
1101 1112 self.pk = None
1102 1113 self.id = None
1103 1114 for attr, value in kwargs.items():
1104 1115 setattr(self, attr, value)
1105 1116
1106 1117 self.save()
1107 1118
1108 1119 return self
1109 1120
1110 1121
1111 1122
1112 1123 def module_6bits(self, module):
1113 1124 """
1114 1125 This function reads antenna pattern and choose 6bits (upbits-downbits) for one abs module
1115 1126 """
1116 1127 if module > 64:
1117 1128 beam_bits = ""
1118 1129 return beam_bits
1119 1130
1120 1131 data = ast.literal_eval(self.antenna)
1121 1132 up_data = data['antenna_up']
1122 1133 down_data = data['antenna_down']
1123 1134
1124 1135 pos = ip2position(module)
1125 1136 up_value = up_data[pos[0]][pos[1]]
1126 1137 down_value = down_data[pos[0]][pos[1]]
1127 1138
1128 1139 up_bits = up_conv_bits(up_value)
1129 1140 down_bits = down_conv_bits(down_value)
1130 1141 beam_bits = up_bits+down_bits
1131 1142
1132 1143 return beam_bits
1133 1144
1134 1145 def modules_6bits(self):
1135 1146 """
1136 1147 This function returns 6bits from every abs module (1-64) in a dict
1137 1148 """
1138 1149 modules_configuration = ast.literal_eval(self.modules_conf)
1139 1150
1140 1151 for i in range(1,65):
1141 1152 modules_configuration[str(i)] = self.module_6bits(i)
1142 1153
1143 1154 self.modules_conf = json.dumps(modules_configuration)
1144 1155 self.save()
1145 1156
1146 1157 return self.modules_conf
1147 1158
1148 1159
1149 1160 def set_as_activebeam(self):
1150 1161 """
1151 1162 This function set this beam as the active beam of its ABS Configuration.
1152 1163 """
1153 1164 self.abs_conf.active_beam = json.dumps({'active_beam': self.id})
1154 1165 self.abs_conf.save()
1155 1166
1156 1167 return
1157 1168
1158 1169
1159 1170 @property
1160 1171 def get_upvalues(self):
1161 1172 """
1162 1173 This function reads antenna pattern and show the up-value of one abs module
1163 1174 """
1164 1175
1165 1176 data = ast.literal_eval(self.antenna)
1166 1177 up_data = data['antenna_up']
1167 1178
1168 1179 up_values = []
1169 1180 for data in up_data:
1170 1181 for i in range(0,8):
1171 1182 up_values.append(data[i])
1172 1183
1173 1184 return up_values
1174 1185
1175 1186 @property
1176 1187 def antenna_upvalues(self):
1177 1188 """
1178 1189 This function reads antenna pattern and show the up - values of one abs beam
1179 1190 in a particular order
1180 1191 """
1181 1192 data = ast.literal_eval(self.antenna)
1182 1193 up_data = data['antenna_up']
1183 1194
1184 1195 return up_data
1185 1196
1186 1197 @property
1187 1198 def antenna_downvalues(self):
1188 1199 """
1189 1200 This function reads antenna pattern and show the down - values of one abs beam
1190 1201 in a particular order
1191 1202 """
1192 1203 data = ast.literal_eval(self.antenna)
1193 1204 down_data = data['antenna_down']
1194 1205
1195 1206 return down_data
1196 1207
1197 1208 @property
1198 1209 def get_downvalues(self):
1199 1210 """
1200 1211 This function reads antenna pattern and show the down-value of one abs module
1201 1212 """
1202 1213
1203 1214 data = ast.literal_eval(self.antenna)
1204 1215 down_data = data['antenna_down']
1205 1216
1206 1217 down_values = []
1207 1218 for data in down_data:
1208 1219 for i in range(0,8):
1209 1220 down_values.append(data[i])
1210 1221
1211 1222 return down_values
1212 1223
1213 1224 @property
1214 1225 def get_up_ues(self):
1215 1226 """
1216 1227 This function shows the up-ues-value of one beam
1217 1228 """
1218 1229 data = ast.literal_eval(self.ues)
1219 1230 up_ues = data['up']
1220 1231
1221 1232 return up_ues
1222 1233
1223 1234 @property
1224 1235 def get_down_ues(self):
1225 1236 """
1226 1237 This function shows the down-ues-value of one beam
1227 1238 """
1228 1239 data = ast.literal_eval(self.ues)
1229 1240 down_ues = data['down']
1230 1241
1231 1242 return down_ues
1232 1243
1233 1244 @property
1234 1245 def get_up_onlyrx(self):
1235 1246 """
1236 1247 This function shows the up-onlyrx-value of one beam
1237 1248 """
1238 1249 data = json.loads(self.only_rx)
1239 1250 up_onlyrx = data['up']
1240 1251
1241 1252 return up_onlyrx
1242 1253
1243 1254 @property
1244 1255 def get_down_onlyrx(self):
1245 1256 """
1246 1257 This function shows the down-onlyrx-value of one beam
1247 1258 """
1248 1259 data = json.loads(self.only_rx)
1249 1260 down_onlyrx = data['down']
1250 1261
1251 1262 return down_onlyrx
1252 1263
1253 1264 @property
1254 1265 def get_tx(self):
1255 1266 """
1256 1267 This function shows the tx-values of one beam
1257 1268 """
1258 1269 data = json.loads(self.tx)
1259 1270
1260 1271 return data
1261 1272
1262 1273 @property
1263 1274 def get_uptx(self):
1264 1275 """
1265 1276 This function shows the up-tx-values of one beam
1266 1277 """
1267 1278 data = json.loads(self.tx)
1268 1279 up_data = data['up']
1269 1280
1270 1281 up_values = []
1271 1282 for data in up_data:
1272 1283 for i in range(0,8):
1273 1284 up_values.append(data[i])
1274 1285
1275 1286 return up_values
1276 1287
1277 1288 @property
1278 1289 def get_downtx(self):
1279 1290 """
1280 1291 This function shows the down-tx-values of one beam
1281 1292 """
1282 1293 data = json.loads(self.tx)
1283 1294 down_data = data['down']
1284 1295
1285 1296 down_values = []
1286 1297 for data in down_data:
1287 1298 for i in range(0,8):
1288 1299 down_values.append(data[i])
1289 1300
1290 1301 return down_values
1291 1302
1292 1303
1293 1304
1294 1305 @property
1295 1306 def get_rx(self):
1296 1307 """
1297 1308 This function shows the rx-values of one beam
1298 1309 """
1299 1310 data = json.loads(self.rx)
1300 1311
1301 1312 return data
1302 1313
1303 1314 @property
1304 1315 def get_uprx(self):
1305 1316 """
1306 1317 This function shows the up-rx-values of one beam
1307 1318 """
1308 1319 data = json.loads(self.rx)
1309 1320 up_data = data['up']
1310 1321
1311 1322 up_values = []
1312 1323 for data in up_data:
1313 1324 for i in range(0,8):
1314 1325 up_values.append(data[i])
1315 1326
1316 1327 return up_values
1317 1328
1318 1329 @property
1319 1330 def get_downrx(self):
1320 1331 """
1321 1332 This function shows the down-rx-values of one beam
1322 1333 """
1323 1334 data = json.loads(self.rx)
1324 1335 down_data = data['down']
1325 1336
1326 1337 down_values = []
1327 1338 for data in down_data:
1328 1339 for i in range(0,8):
1329 1340 down_values.append(data[i])
1330 1341
1331 1342 return down_values
@@ -1,54 +1,63
1 1 from __future__ import absolute_import
2 2
3 3 from apps.main.models import Configuration
4 4 from .models import ABSBeam
5 5 import json
6 6 from datetime import timedelta, datetime
7 7 from celery.task import task
8 8
9 9 @task(name='task_change_beam')
10 10 def task_change_beam(id_conf):
11 11
12 12 abs_conf = Configuration.objects.get(pk=id_conf)
13 13 beams_list = ABSBeam.objects.filter(abs_conf=abs_conf)
14 14 active_beam = json.loads(abs_conf.active_beam)
15 15
16 16 run_every = timedelta(seconds=abs_conf.operation_value)
17 17 now = datetime.utcnow()
18 18 date = now + run_every
19 19
20 20 if abs_conf.device.status != 3:
21 21 return abs_conf.device.status
22 22
23 23 if abs_conf.operation_mode == 0: #Manual Mode
24 24 return 1
25 25
26 26 if active_beam:
27 27 current_beam = ABSBeam.objects.get(pk=active_beam['active_beam'])
28 28 i=0
29 29 for beam in beams_list:
30 30 if beam == current_beam:
31 31 i+=1
32 32 break
33 33 i+=1
34 34
35 35 if i < len(beams_list):
36 36 next_beam = beams_list[i]
37 37 abs_conf.send_beam_num(i+1)
38 38 next_beam.set_as_activebeam()
39 39 task = task_change_beam.apply_async((abs_conf.pk,), eta=date)
40 40 print next_beam
41 41 else:
42 42 abs_conf.send_beam_num(1)
43 43 beams_list[0].set_as_activebeam()
44 44 task = task_change_beam.apply_async((abs_conf.pk,), eta=date)
45 45 print beams_list[0]
46 46 i=0
47 47
48 48 else:
49 49 abs_conf.send_beam_num(1)
50 50 beams_list[0].set_as_activebeam()
51 51 task = task_change_beam.apply_async((abs_conf.pk,), eta=date)
52 52
53 53
54 54 return 2
55
56
57 @task(name='status_absdevice')
58 def status_absdevice(id_conf):
59
60 abs_conf = Configuration.objects.get(pk=id_conf)
61 abs_conf.absmodule_status()
62
63 return
@@ -1,542 +1,550
1 1 {% extends "dev_conf.html" %}
2 2
3 3 {% load static %}
4 4 {% load bootstrap3 %}
5 5 {% load main_tags %}
6 6
7 7 {% block extra-menu-actions %}
8 8 <li><a href="{{ dev_conf.get_absolute_url_plot }}" target="_blank"><span class="glyphicon glyphicon-picture" aria-hidden="true"></span> View Patterns </a></li>
9 9 {% endblock %}
10 10
11 11 {% block extra-content %}
12 12 <style>
13 13
14 14 .abs {
15 15 border: 2px solid #00334d;
16 16 vertical-align: center;
17 17 display: inline-block;
18 18 }
19 19 .abs tr:nth-child(1){
20 20 border-bottom: 1px dashed #00334d;
21 21 }
22 22 .abs tr{
23 23 border-bottom: 0px solid #00334d;
24 24 }
25 25 .abs td {
26 26 border-right: 1px dashed #00334d;
27 27 text-align: center;
28 28 padding: 5px;
29 29 }
30 30
31 31
32 32 .legend {
33 33 margin-left: 15px;
34 34 display: inline-block;
35 35 border: 2px solid #00334d;
36 36 vertical-align: top;
37 37 }
38 38 .legend th{
39 39 border-bottom: 1px dashed #00334d;
40 40 font-weight: bold;
41 41 vertical-align: center;
42 42 text-align: center;
43 43 }
44 44 .legend td {
45 45 padding: 2px;
46 46 text-align: center;
47 47 }
48 48
49 49
50 50 .north {
51 51 border: 2px solid #00334d;
52 52 vertical-align: center;
53 53 font-weight: bold;
54 54 }
55 55 .north tr{
56 56 border: 1px solid #ffffff;
57 57
58 58 }
59 59 .north td{
60 60 border: 2px solid #e2e2e7;
61 61 text-align: center;
62 62 padding: 1px 15px 1px 15px;
63 63 }
64 64 .north tr:nth-child(even) td:nth-child(n){
65 65 border-bottom: 12px solid #e2e2e7;
66 66 }
67 67 .north td:nth-child(n) {
68 68 border-right: 12px solid #e2e2e7;
69 69 }
70 70 .north td:nth-last-child(4n+1) {
71 71 border-right: 2px solid #e2e2e7;
72 72 }
73 73 .north tr:nth-last-child(1) td:nth-child(n){
74 74 border-bottom: 3px solid #e2e2e7;
75 75 }
76 76
77 77
78 78
79 79 .east {
80 80 border: 2px solid #00334d;
81 81 vertical-align: center;
82 82 font-weight: bold;
83 83 }
84 84 .east tr{
85 85 border: 1px solid #ffffff;
86 86 }
87 87 .east td{
88 88 border: 2px solid #e2e2e7;
89 89 text-align: center;
90 90 padding: 1px 15px 1px 15px;
91 91 }
92 92 .east tr:nth-child(even) td:nth-child(n){
93 93 border-bottom: 12px solid #e2e2e7;
94 94 }
95 95 .east td:nth-child(n) {
96 96 border-right: 12px solid #e2e2e7;
97 97 }
98 98 .east td:nth-last-child(4n+1) {
99 99 border-right: 2px solid #e2e2e7;
100 100 }
101 101 .east tr:nth-last-child(1) td:nth-child(n){
102 102 border-bottom: 3px solid #e2e2e7;
103 103 }
104 104
105 105
106 106
107 107
108 108 .west {
109 109 border: 2px solid #00334d;
110 110 vertical-align: center;
111 111 font-weight: bold;
112 112 }
113 113 .west tr{
114 114 border: 1px solid #ffffff;
115 115 }
116 116 .west td{
117 117 border: 2px solid #e2e2e7;
118 118 text-align: center;
119 119 padding: 1px 15px 1px 15px;
120 120 }
121 121 .west tr:nth-child(even) td:nth-child(n){
122 122 border-bottom: 12px solid #e2e2e7;
123 123 }
124 124 .west td:nth-child(n) {
125 125 border-right: 12px solid #e2e2e7;
126 126 }
127 127 .west td:nth-last-child(4n+1) {
128 128 border-right: 2px solid #e2e2e7;
129 129 }
130 130 .west tr:nth-last-child(1) td:nth-child(n){
131 131 border-bottom: 3px solid #e2e2e7;
132 132 }
133 133
134 134
135 135
136 136
137 137 .south {
138 138 border: 2px solid #00334d;
139 139 vertical-align: center;
140 140 font-weight: bold;
141 141 }
142 142 .south tr{
143 143 border: 1px solid #ffffff;
144 144 }
145 145 .south td{
146 146 border: 2px solid #e2e2e7;
147 147 text-align: center;
148 148 padding: 1px 15px 1px 15px;
149 149 }
150 150 .south tr:nth-child(even) td:nth-child(n){
151 151 border-bottom: 12px solid #e2e2e7;
152 152 }
153 153 .south td:nth-child(n) {
154 154 border-right: 12px solid #e2e2e7;
155 155 }
156 156 .south td:nth-last-child(4n+1) {
157 157 border-right: 2px solid #e2e2e7;
158 158 }
159 159 .south tr:nth-last-child(1) td:nth-child(n){
160 160 border-bottom: 3px solid #e2e2e7;
161 161 }
162 162
163 163
164 164
165 165
166 166 </style>
167 167
168 {% if status_request %}
169 <img id="loading" src="{% static 'images/loader.gif' %}">
170 {% endif %}
171
168 172
169 173 {% if beams %}
170 174
171 175
172 176
173 177 <h4>Beams:</h4>
174 178 <div class="container">
175 179 <ul class="nav nav-pills">
176 180 {% for beam in beams %}
177 181 <li {% if active_beam.id == beam.id %} class="active" {% endif %} >
178 182 <a data-toggle="pill" href="#menu{{forloop.counter}}">{{forloop.counter}}</a>
179 183 </li>
180 184 {% endfor %}
181 185 </ul>
182 186
183 187
184 188 <div class="tab-content">
185 189 <div id="home" class="tab-pane fade in active">
186 190 <!---->
187 191 {% if active_beam %}
188 192 <h3>Active Beam: {{active_beam.name}}</h3>
189 193
190 194 <table id="abs_pattern" class="abs">
191 195 <tr>
192 196 <td> <b>North Quarter</b>
193 197 <table class="north ">
194 198 <tr>
195 199 <td {{color_status.1}} title='{{module_messages.1}}'>{{active_beam.get_upvalues.0}}</td> <td {{color_status.2}} title='{{module_messages.2}}'>{{active_beam.get_upvalues.1}}</td> <td {{color_status.3}} title='{{module_messages.3}}'>{{active_beam.get_upvalues.2}}</td> <td {{color_status.4}} title='{{module_messages.4}}'>{{active_beam.get_upvalues.3}}</td>
196 200 </tr>
197 201 <tr>
198 202 <td {{color_status.1}} title='{{module_messages.1}}'>{{active_beam.get_downvalues.0}}</td> <td {{color_status.2}} title='{{module_messages.2}}'>{{active_beam.get_downvalues.1}}</td> <td {{color_status.3}} title='{{module_messages.3}}'>{{active_beam.get_downvalues.2}}</td> <td {{color_status.4}} title='{{module_messages.4}}'>{{active_beam.get_downvalues.3}}</td>
199 203 </tr>
200 204 <tr>
201 205 <td {{color_status.9}} title='{{module_messages.9}}'>{{active_beam.get_upvalues.8}}</td> <td {{color_status.10}} title='{{module_messages.10}}'>{{active_beam.get_upvalues.9}}</td> <td {{color_status.11}} title='{{module_messages.11}}'>{{active_beam.get_upvalues.10}}</td> <td {{color_status.12}} title='{{module_messages.12}}'>{{active_beam.get_upvalues.11}}</td>
202 206 </tr>
203 207 <tr>
204 208 <td {{color_status.9}} title='{{module_messages.9}}'>{{active_beam.get_downvalues.8}}</td> <td {{color_status.10}} title='{{module_messages.10}}'>{{active_beam.get_downvalues.9}}</td> <td {{color_status.11}} title='{{module_messages.11}}'>{{active_beam.get_downvalues.10}}</td> <td {{color_status.12}} title='{{module_messages.12}}'>{{active_beam.get_downvalues.11}}</td>
205 209 </tr>
206 210 <tr>
207 211 <td {{color_status.17}} title='{{module_messages.17}}'>{{active_beam.get_upvalues.16}}</td> <td {{color_status.18}} title='{{module_messages.18}}'>{{active_beam.get_upvalues.17}}</td> <td {{color_status.19}} title='{{module_messages.19}}'>{{active_beam.get_upvalues.18}}</td> <td {{color_status.20}} title='{{module_messages.20}}'>{{active_beam.get_upvalues.19}}</td>
208 212 </tr>
209 213 <tr>
210 214 <td {{color_status.17}} title='{{module_messages.17}}'>{{active_beam.get_downvalues.16}}</td> <td {{color_status.18}} title='{{module_messages.18}}'>{{active_beam.get_downvalues.17}}</td> <td {{color_status.19}} title='{{module_messages.19}}'>{{active_beam.get_downvalues.18}}</td> <td {{color_status.20}} title='{{module_messages.20}}'>{{active_beam.get_downvalues.19}}</td>
211 215 </tr>
212 216 <tr>
213 217 <td {{color_status.25}} title='{{module_messages.25}}'>{{active_beam.get_upvalues.24}}</td> <td {{color_status.26}} title='{{module_messages.26}}'>{{active_beam.get_upvalues.25}}</td> <td {{color_status.27}} title='{{module_messages.27}}'>{{active_beam.get_upvalues.26}}</td> <td {{color_status.28}} title='{{module_messages.28}}'>{{active_beam.get_upvalues.27}}</td>
214 218 </tr>
215 219 <tr>
216 220 <td {{color_status.25}} title='{{module_messages.25}}'>{{active_beam.get_downvalues.24}}</td> <td {{color_status.26}} title='{{module_messages.26}}'>{{active_beam.get_downvalues.25}}</td> <td {{color_status.27}} title='{{module_messages.27}}'>{{active_beam.get_downvalues.26}}</td> <td {{color_status.28}} title='{{module_messages.28}}'>{{active_beam.get_downvalues.27}}</td>
217 221 </tr>
218 222 </table>
219 223 </td>
220 224 <td> <b>East Quarter</b>
221 225 <table class="east ">
222 226 <tr>
223 227 <td {{color_status.5}} title='{{module_messages.5}}'>{{active_beam.get_upvalues.4}}</td> <td {{color_status.6}} title='{{module_messages.6}}'>{{active_beam.get_upvalues.5}}</td> <td {{color_status.7}} title='{{module_messages.7}}'>{{active_beam.get_upvalues.6}}</td> <td {{color_status.8}} title='{{module_messages.8}}'>{{active_beam.get_upvalues.7}}</td>
224 228 </tr>
225 229 <tr>
226 230 <td {{color_status.5}} title='{{module_messages.5}}'>{{active_beam.get_downvalues.4}}</td> <td {{color_status.6}} title='{{module_messages.6}}'>{{active_beam.get_downvalues.5}}</td> <td {{color_status.7}} title='{{module_messages.7}}'>{{active_beam.get_downvalues.6}}</td> <td {{color_status.8}} title='{{module_messages.8}}'>{{active_beam.get_downvalues.7}}</td>
227 231 </tr>
228 232 <tr>
229 233 <td {{color_status.13}} title='{{module_messages.13}}'>{{active_beam.get_upvalues.12}}</td> <td {{color_status.14}} title='{{module_messages.14}}'>{{active_beam.get_upvalues.13}}</td> <td {{color_status.15}} title='{{module_messages.15}}'>{{active_beam.get_upvalues.14}}</td> <td {{color_status.16}} title='{{module_messages.16}}'>{{active_beam.get_upvalues.15}}</td>
230 234 </tr>
231 235 <tr>
232 236 <td {{color_status.13}} title='{{module_messages.13}}'>{{active_beam.get_downvalues.12}}</td> <td {{color_status.14}} title='{{module_messages.14}}'>{{active_beam.get_downvalues.13}}</td> <td {{color_status.15}} title='{{module_messages.15}}'>{{active_beam.get_downvalues.14}}</td> <td {{color_status.16}} title='{{module_messages.16}}'>{{active_beam.get_downvalues.15}}</td>
233 237 </tr>
234 238 <tr>
235 239 <td {{color_status.21}} title='{{module_messages.21}}'>{{active_beam.get_upvalues.20}}</td> <td {{color_status.22}} title='{{module_messages.22}}'>{{active_beam.get_upvalues.21}}</td> <td {{color_status.23}} title='{{module_messages.23}}'>{{active_beam.get_upvalues.22}}</td> <td {{color_status.24}} title='{{module_messages.24}}'>{{active_beam.get_upvalues.23}}</td>
236 240 </tr>
237 241 <tr>
238 242 <td {{color_status.21}} title='{{module_messages.21}}'>{{active_beam.get_downvalues.20}}</td> <td {{color_status.22}} title='{{module_messages.22}}'>{{active_beam.get_downvalues.21}}</td> <td {{color_status.23}} title='{{module_messages.23}}'>{{active_beam.get_downvalues.22}}</td> <td {{color_status.24}} title='{{module_messages.24}}'>{{active_beam.get_downvalues.23}}</td>
239 243 </tr>
240 244 <tr>
241 245 <td {{color_status.29}} title='{{module_messages.29}}'>{{active_beam.get_upvalues.28}}</td> <td {{color_status.30}} title='{{module_messages.30}}'>{{active_beam.get_upvalues.29}}</td> <td {{color_status.31}} title='{{module_messages.31}}'>{{active_beam.get_upvalues.30}}</td> <td {{color_status.32}} title='{{module_messages.32}}'>{{active_beam.get_upvalues.31}}</td>
242 246 </tr>
243 247 <tr>
244 248 <td {{color_status.29}} title='{{module_messages.29}}'>{{active_beam.get_downvalues.28}}</td> <td {{color_status.30}} title='{{module_messages.30}}'>{{active_beam.get_downvalues.29}}</td> <td {{color_status.31}} title='{{module_messages.31}}'>{{active_beam.get_downvalues.30}}</td> <td {{color_status.32}} title='{{module_messages.32}}'>{{active_beam.get_downvalues.31}}</td>
245 249 </tr>
246 250 </table>
247 251 </td>
248 252 </tr>
249 253 <tr>
250 254 <td> <b>West Quarter</b>
251 255 <table class="west ">
252 256 <tr>
253 257 <td {{color_status.33}} title='{{module_messages.33}}'>{{active_beam.get_upvalues.32}}</td> <td {{color_status.34}} title='{{module_messages.34}}'>{{active_beam.get_upvalues.33}}</td> <td {{color_status.35}} title='{{module_messages.35}}'>{{active_beam.get_upvalues.34}}</td> <td {{color_status.36}} title='{{module_messages.36}}'>{{active_beam.get_upvalues.35}}</td>
254 258 </tr>
255 259 <tr>
256 260 <td {{color_status.33}} title='{{module_messages.33}}'>{{active_beam.get_downvalues.32}}</td> <td {{color_status.34}} title='{{module_messages.34}}'>{{active_beam.get_downvalues.33}}</td> <td {{color_status.35}} title='{{module_messages.35}}'>{{active_beam.get_downvalues.34}}</td> <td {{color_status.36}} title='{{module_messages.36}}'>{{active_beam.get_downvalues.35}}</td>
257 261 </tr>
258 262 <tr>
259 263 <td {{color_status.41}} title='{{module_messages.41}}'>{{active_beam.get_upvalues.40}}</td> <td {{color_status.42}} title='{{module_messages.42}}'>{{active_beam.get_upvalues.41}}</td> <td {{color_status.43}} title='{{module_messages.43}}'>{{active_beam.get_upvalues.42}}</td> <td {{color_status.44}} title='{{module_messages.44}}'>{{active_beam.get_upvalues.43}}</td>
260 264 </tr>
261 265 <tr>
262 266 <td {{color_status.41}} title='{{module_messages.41}}'>{{active_beam.get_downvalues.40}}</td> <td {{color_status.42}} title='{{module_messages.42}}'>{{active_beam.get_downvalues.41}}</td> <td {{color_status.43}} title='{{module_messages.43}}'>{{active_beam.get_downvalues.42}}</td> <td {{color_status.44}} title='{{module_messages.44}}'>{{active_beam.get_downvalues.43}}</td>
263 267 </tr>
264 268 <tr>
265 269 <td {{color_status.49}} title='{{module_messages.49}}'>{{active_beam.get_upvalues.48}}</td> <td {{color_status.50}} title='{{module_messages.50}}'>{{active_beam.get_upvalues.49}}</td> <td {{color_status.51}} title='{{module_messages.51}}'>{{active_beam.get_upvalues.50}}</td> <td {{color_status.52}} title='{{module_messages.52}}'>{{active_beam.get_upvalues.51}}</td>
266 270 </tr>
267 271 <tr>
268 272 <td {{color_status.49}} title='{{module_messages.49}}'>{{active_beam.get_downvalues.48}}</td> <td {{color_status.50}} title='{{module_messages.50}}'>{{active_beam.get_downvalues.49}}</td> <td {{color_status.51}} title='{{module_messages.51}}'>{{active_beam.get_downvalues.50}}</td> <td {{color_status.52}} title='{{module_messages.52}}'>{{active_beam.get_downvalues.51}}</td>
269 273 </tr>
270 274 <tr>
271 275 <td {{color_status.57}} title='{{module_messages.57}}'>{{active_beam.get_upvalues.56}}</td> <td {{color_status.58}} title='{{module_messages.58}}'>{{active_beam.get_upvalues.57}}</td> <td {{color_status.59}} title='{{module_messages.59}}'>{{active_beam.get_upvalues.58}}</td> <td {{color_status.60}} title='{{module_messages.60}}'>{{active_beam.get_upvalues.59}}</td>
272 276 </tr>
273 277 <tr>
274 278 <td {{color_status.57}} title='{{module_messages.57}}'>{{active_beam.get_downvalues.56}}</td> <td {{color_status.58}} title='{{module_messages.58}}'>{{active_beam.get_downvalues.57}}</td> <td {{color_status.59}} title='{{module_messages.59}}'>{{active_beam.get_downvalues.58}}</td> <td {{color_status.60}} title='{{module_messages.60}}'>{{active_beam.get_downvalues.59}}</td>
275 279 </tr>
276 280 </table>
277 281 </td>
278 282 <td> <b>South Quarter</b>
279 283 <table class="south ">
280 284 <tr>
281 285 <td {{color_status.37}} title='{{module_messages.37}}'>{{active_beam.get_upvalues.36}}</td> <td {{color_status.38}} title='{{module_messages.38}}'>{{active_beam.get_upvalues.37}}</td> <td {{color_status.39}} title='{{module_messages.39}}'>{{active_beam.get_upvalues.38}}</td> <td {{color_status.40}} title='{{module_messages.40}}'>{{active_beam.get_upvalues.39}}</td>
282 286 </tr>
283 287 <tr>
284 288 <td {{color_status.37}} title='{{module_messages.37}}'>{{active_beam.get_downvalues.36}}</td> <td {{color_status.38}} title='{{module_messages.38}}'>{{active_beam.get_downvalues.37}}</td> <td {{color_status.39}} title='{{module_messages.39}}'>{{active_beam.get_downvalues.38}}</td> <td {{color_status.40}} title='{{module_messages.40}}'>{{active_beam.get_downvalues.39}}</td>
285 289 </tr>
286 290 <tr>
287 291 <td {{color_status.45}} title='{{module_messages.45}}'>{{active_beam.get_upvalues.44}}</td> <td {{color_status.46}} title='{{module_messages.46}}'>{{active_beam.get_upvalues.45}}</td> <td {{color_status.47}} title='{{module_messages.47}}'>{{active_beam.get_upvalues.46}}</td> <td {{color_status.48}} title='{{module_messages.48}}'>{{active_beam.get_upvalues.47}}</td>
288 292 </tr>
289 293 <tr>
290 294 <td {{color_status.45}} title='{{module_messages.45}}'>{{active_beam.get_downvalues.44}}</td> <td {{color_status.46}} title='{{module_messages.46}}'>{{active_beam.get_downvalues.45}}</td> <td {{color_status.47}} title='{{module_messages.47}}'>{{active_beam.get_downvalues.46}}</td> <td {{color_status.48}} title='{{module_messages.48}}'>{{active_beam.get_downvalues.47}}</td>
291 295 </tr>
292 296 <tr>
293 297 <td {{color_status.53}} title='{{module_messages.53}}'>{{active_beam.get_upvalues.52}}</td> <td {{color_status.54}} title='{{module_messages.54}}'>{{active_beam.get_upvalues.53}}</td> <td {{color_status.55}} title='{{module_messages.55}}'>{{active_beam.get_upvalues.54}}</td> <td {{color_status.56}} title='{{module_messages.56}}'>{{active_beam.get_upvalues.55}}</td>
294 298 </tr>
295 299 <tr>
296 300 <td {{color_status.53}} title='{{module_messages.53}}'>{{active_beam.get_downvalues.52}}</td> <td {{color_status.54}} title='{{module_messages.54}}'>{{active_beam.get_downvalues.53}}</td> <td {{color_status.55}} title='{{module_messages.55}}'>{{active_beam.get_downvalues.54}}</td> <td {{color_status.56}} title='{{module_messages.56}}'>{{active_beam.get_downvalues.55}}</td>
297 301 </tr>
298 302 <tr>
299 303 <td {{color_status.61}} title='{{module_messages.61}}'>{{active_beam.get_upvalues.60}}</td> <td {{color_status.62}} title='{{module_messages.62}}'>{{active_beam.get_upvalues.61}}</td> <td {{color_status.63}} title='{{module_messages.63}}'>{{active_beam.get_upvalues.62}}</td> <td {{color_status.64}} title='{{module_messages.64}}'>{{active_beam.get_upvalues.63}}</td>
300 304 </tr>
301 305 <tr>
302 306 <td {{color_status.61}} title='{{module_messages.61}}'>{{active_beam.get_downvalues.60}}</td> <td {{color_status.62}} title='{{module_messages.62}}'>{{active_beam.get_downvalues.61}}</td> <td {{color_status.63}} title='{{module_messages.63}}'>{{active_beam.get_downvalues.62}}</td> <td {{color_status.64}} title='{{module_messages.64}}'>{{active_beam.get_downvalues.63}}</td>
303 307 </tr>
304 308 </table>
305 309 </td>
306 310 </tr>
307 311 </table>
308 312
309 313
310 314
311 315 <table class="legend">
312 316 <tr>
313 317 <th colspan="2">Legend</th>
314 318 </tr>
315 319 <tr>
316 320 <td class="text-danger"><i>RED</i></td><td>Disconnected</td>
317 321 </tr>
318 322 <tr>
319 323 <td class="text-warning"><i>ORANGE</i></td><td>Connected</td>
320 324 </tr>
321 325 <tr>
322 326 <td class="text-success"><i>GREEN</i></td><td>Running </td>
323 327 </tr>
324 328 <!--
325 329 <tr>
326 330 <td colspan="2">
327 331 <button style="margin: 10px;" id="sendbeam" type="button" class="btn btn-default">
328 332 <span class="glyphicon glyphicon-export" aria-hidden="true"></span>
329 333 Change Beam</button>
330 334 </td>
331 335 </tr>
332 336 -->
333 337 </table>
334 338
335 339
336 340
337 341
338 342 {% else %}
339 343 <p><i>This ABS Configuration does not have a current active ABS Beam...<br>
340 344 Please send Beam List to ABS modules. </i></p>
341 345
342 346 {% endif %}
343 347
344 348
345 349 </div>
346 350
347 351
348 352
349 353 {% for beam in beams %}
350 354 <div id="menu{{forloop.counter}}" class="tab-pane fade">
351 355 <h3>{%if active_beam.id == beam.id%}Active Beam: {%endif%}{{beam.name}}</h3>
352 356 <!--<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>-->
353 357 <table id="abs_pattern{{forloop.counter}}" class="abs">
354 358 <tr>
355 359 <td> <b>North Quarter</b>
356 360 <table class="north ">
357 361 <tr>
358 362 <td {{beam.color_status.1}} title='{{beam.module_messages.1}}'>{{beam.get_upvalues.0}}</td> <td {{beam.color_status.2}} title='{{beam.module_messages.2}}'>{{beam.get_upvalues.1}}</td> <td {{beam.color_status.3}} title='{{beam.module_messages.3}}'>{{beam.get_upvalues.2}}</td> <td {{beam.color_status.4}} title='{{beam.module_messages.4}}'>{{beam.get_upvalues.3}}</td>
359 363 </tr>
360 364 <tr>
361 365 <td {{beam.color_status.1}} title='{{beam.module_messages.1}}'>{{beam.get_downvalues.0}}</td> <td {{beam.color_status.2}} title='{{beam.module_messages.2}}'>{{beam.get_downvalues.1}}</td> <td {{beam.color_status.3}} title='{{beam.module_messages.3}}'>{{beam.get_downvalues.2}}</td> <td {{beam.color_status.4}} title='{{beam.module_messages.4}}'>{{beam.get_downvalues.3}}</td>
362 366 </tr>
363 367 <tr>
364 368 <td {{beam.color_status.9}} title='{{beam.module_messages.9}}'>{{beam.get_upvalues.8}}</td> <td {{beam.color_status.10}} title='{{beam.module_messages.10}}'>{{beam.get_upvalues.9}}</td> <td {{beam.color_status.11}} title='{{beam.module_messages.11}}'>{{beam.get_upvalues.10}}</td> <td {{beam.color_status.12}} title='{{beam.module_messages.12}}'>{{beam.get_upvalues.11}}</td>
365 369 </tr>
366 370 <tr>
367 371 <td {{beam.color_status.9}} title='{{beam.module_messages.9}}'>{{beam.get_downvalues.8}}</td> <td {{beam.color_status.10}} title='{{beam.module_messages.10}}'>{{beam.get_downvalues.9}}</td> <td {{beam.color_status.11}} title='{{beam.module_messages.11}}'>{{beam.get_downvalues.10}}</td> <td {{beam.color_status.12}} title='{{beam.module_messages.12}}'>{{beam.get_downvalues.11}}</td>
368 372 </tr>
369 373 <tr>
370 374 <td {{beam.color_status.17}} title='{{beam.module_messages.17}}'>{{beam.get_upvalues.16}}</td> <td {{beam.color_status.18}} title='{{beam.module_messages.18}}'>{{beam.get_upvalues.17}}</td> <td {{beam.color_status.19}} title='{{beam.module_messages.19}}'>{{beam.get_upvalues.18}}</td> <td {{beam.color_status.20}} title='{{beam.module_messages.20}}'>{{beam.get_upvalues.19}}</td>
371 375 </tr>
372 376 <tr>
373 377 <td {{beam.color_status.17}} title='{{beam.module_messages.17}}'>{{beam.get_downvalues.16}}</td> <td {{beam.color_status.18}} title='{{beam.module_messages.18}}'>{{beam.get_downvalues.17}}</td> <td {{beam.color_status.19}} title='{{beam.module_messages.19}}'>{{beam.get_downvalues.18}}</td> <td {{beam.color_status.20}} title='{{beam.module_messages.20}}'>{{beam.get_downvalues.19}}</td>
374 378 </tr>
375 379 <tr>
376 380 <td {{beam.color_status.25}} title='{{beam.module_messages.25}}'>{{beam.get_upvalues.24}}</td> <td {{beam.color_status.26}} title='{{beam.module_messages.26}}'>{{beam.get_upvalues.25}}</td> <td {{beam.color_status.27}} title='{{beam.module_messages.27}}'>{{beam.get_upvalues.26}}</td> <td {{beam.color_status.28}} title='{{beam.module_messages.28}}'>{{beam.get_upvalues.27}}</td>
377 381 </tr>
378 382 <tr>
379 383 <td {{beam.color_status.25}} title='{{beam.module_messages.25}}'>{{beam.get_downvalues.24}}</td> <td {{beam.color_status.26}} title='{{beam.module_messages.26}}'>{{beam.get_downvalues.25}}</td> <td {{beam.color_status.27}} title='{{beam.module_messages.27}}'>{{beam.get_downvalues.26}}</td> <td {{beam.color_status.28}} title='{{beam.module_messages.28}}'>{{beam.get_downvalues.27}}</td>
380 384 </tr>
381 385 </table>
382 386 </td>
383 387 <td> <b>East Quarter</b>
384 388 <table class="east ">
385 389 <tr>
386 390 <td {{beam.color_status.5}} title='{{beam.module_messages.5}}'>{{beam.get_upvalues.4}}</td> <td {{beam.color_status.6}} title='{{beam.module_messages.6}}'>{{beam.get_upvalues.5}}</td> <td {{beam.color_status.7}} title='{{beam.module_messages.7}}'>{{beam.get_upvalues.6}}</td> <td {{beam.color_status.8}} title='{{beam.module_messages.8}}'>{{beam.get_upvalues.7}}</td>
387 391 </tr>
388 392 <tr>
389 393 <td {{beam.color_status.5}} title='{{beam.module_messages.5}}'>{{beam.get_downvalues.4}}</td> <td {{beam.color_status.6}} title='{{beam.module_messages.6}}'>{{beam.get_downvalues.5}}</td> <td {{beam.color_status.7}} title='{{beam.module_messages.7}}'>{{beam.get_downvalues.6}}</td> <td {{beam.color_status.8}} title='{{beam.module_messages.8}}'>{{beam.get_downvalues.7}}</td>
390 394 </tr>
391 395 <tr>
392 396 <td {{beam.color_status.13}} title='{{beam.module_messages.13}}'>{{beam.get_upvalues.12}}</td> <td {{beam.color_status.14}} title='{{beam.module_messages.14}}'>{{beam.get_upvalues.13}}</td> <td {{beam.color_status.15}} title='{{beam.module_messages.15}}'>{{beam.get_upvalues.14}}</td> <td {{beam.color_status.16}} title='{{beam.module_messages.16}}'>{{beam.get_upvalues.15}}</td>
393 397 </tr>
394 398 <tr>
395 399 <td {{beam.color_status.13}} title='{{beam.module_messages.13}}'>{{beam.get_downvalues.12}}</td> <td {{beam.color_status.14}} title='{{beam.module_messages.14}}'>{{beam.get_downvalues.13}}</td> <td {{beam.color_status.15}} title='{{beam.module_messages.15}}'>{{beam.get_downvalues.14}}</td> <td {{beam.color_status.16}} title='{{beam.module_messages.16}}'>{{beam.get_downvalues.15}}</td>
396 400 </tr>
397 401 <tr>
398 402 <td {{beam.color_status.21}} title='{{beam.module_messages.21}}'>{{beam.get_upvalues.20}}</td> <td {{beam.color_status.22}} title='{{beam.module_messages.22}}'>{{beam.get_upvalues.21}}</td> <td {{beam.color_status.23}} title='{{beam.module_messages.23}}'>{{beam.get_upvalues.22}}</td> <td {{beam.color_status.24}} title='{{beam.module_messages.24}}'>{{beam.get_upvalues.23}}</td>
399 403 </tr>
400 404 <tr>
401 405 <td {{beam.color_status.21}} title='{{beam.module_messages.21}}'>{{beam.get_downvalues.20}}</td> <td {{beam.color_status.22}} title='{{beam.module_messages.22}}'>{{beam.get_downvalues.21}}</td> <td {{beam.color_status.23}} title='{{beam.module_messages.23}}'>{{beam.get_downvalues.22}}</td> <td {{beam.color_status.24}} title='{{beam.module_messages.24}}'>{{beam.get_downvalues.23}}</td>
402 406 </tr>
403 407 <tr>
404 408 <td {{beam.color_status.29}} title='{{beam.module_messages.29}}'>{{beam.get_upvalues.28}}</td> <td {{beam.color_status.30}} title='{{beam.module_messages.30}}'>{{beam.get_upvalues.29}}</td> <td {{beam.color_status.31}} title='{{beam.module_messages.31}}'>{{beam.get_upvalues.30}}</td> <td {{beam.color_status.32}} title='{{beam.module_messages.32}}'>{{beam.get_upvalues.31}}</td>
405 409 </tr>
406 410 <tr>
407 411 <td {{beam.color_status.29}} title='{{beam.module_messages.29}}'>{{beam.get_downvalues.28}}</td> <td {{beam.color_status.30}} title='{{beam.module_messages.30}}'>{{beam.get_downvalues.29}}</td> <td {{beam.color_status.31}} title='{{beam.module_messages.31}}'>{{beam.get_downvalues.30}}</td> <td {{beam.color_status.32}} title='{{beam.module_messages.32}}'>{{beam.get_downvalues.31}}</td>
408 412 </tr>
409 413 </table>
410 414 </td>
411 415 </tr>
412 416 <tr>
413 417 <td> <b>West Quarter</b>
414 418 <table class="west ">
415 419 <tr>
416 420 <td {{beam.color_status.33}} title='{{beam.module_messages.33}}'>{{beam.get_upvalues.32}}</td> <td {{beam.color_status.34}} title='{{beam.module_messages.34}}'>{{beam.get_upvalues.33}}</td> <td {{beam.color_status.35}} title='{{beam.module_messages.35}}'>{{beam.get_upvalues.34}}</td> <td {{beam.color_status.36}} title='{{beam.module_messages.36}}'>{{beam.get_upvalues.35}}</td>
417 421 </tr>
418 422 <tr>
419 423 <td {{beam.color_status.33}} title='{{beam.module_messages.33}}'>{{beam.get_downvalues.32}}</td> <td {{beam.color_status.34}} title='{{beam.module_messages.34}}'>{{beam.get_downvalues.33}}</td> <td {{beam.color_status.35}} title='{{beam.module_messages.35}}'>{{beam.get_downvalues.34}}</td> <td {{beam.color_status.36}} title='{{beam.module_messages.36}}'>{{beam.get_downvalues.35}}</td>
420 424 </tr>
421 425 <tr>
422 426 <td {{beam.color_status.41}} title='{{beam.module_messages.41}}'>{{beam.get_upvalues.40}}</td> <td {{beam.color_status.42}} title='{{beam.module_messages.42}}'>{{beam.get_upvalues.41}}</td> <td {{beam.color_status.43}} title='{{beam.module_messages.43}}'>{{beam.get_upvalues.42}}</td> <td {{beam.color_status.44}} title='{{beam.module_messages.44}}'>{{beam.get_upvalues.43}}</td>
423 427 </tr>
424 428 <tr>
425 429 <td {{beam.color_status.41}} title='{{beam.module_messages.41}}'>{{beam.get_downvalues.40}}</td> <td {{beam.color_status.42}} title='{{beam.module_messages.42}}'>{{beam.get_downvalues.41}}</td> <td {{beam.color_status.43}} title='{{beam.module_messages.43}}'>{{beam.get_downvalues.42}}</td> <td {{beam.color_status.44}} title='{{beam.module_messages.44}}'>{{beam.get_downvalues.43}}</td>
426 430 </tr>
427 431 <tr>
428 432 <td {{beam.color_status.49}} title='{{beam.module_messages.49}}'>{{beam.get_upvalues.48}}</td> <td {{beam.color_status.50}} title='{{beam.module_messages.50}}'>{{beam.get_upvalues.49}}</td> <td {{beam.color_status.51}} title='{{beam.module_messages.51}}'>{{beam.get_upvalues.50}}</td> <td {{beam.color_status.52}} title='{{beam.module_messages.52}}'>{{beam.get_upvalues.51}}</td>
429 433 </tr>
430 434 <tr>
431 435 <td {{beam.color_status.49}} title='{{beam.module_messages.49}}'>{{beam.get_downvalues.48}}</td> <td {{beam.color_status.50}} title='{{beam.module_messages.50}}'>{{beam.get_downvalues.49}}</td> <td {{beam.color_status.51}} title='{{beam.module_messages.51}}'>{{beam.get_downvalues.50}}</td> <td {{beam.color_status.52}} title='{{beam.module_messages.52}}'>{{beam.get_downvalues.51}}</td>
432 436 </tr>
433 437 <tr>
434 438 <td {{beam.color_status.57}} title='{{beam.module_messages.57}}'>{{beam.get_upvalues.56}}</td> <td {{beam.color_status.58}} title='{{beam.module_messages.58}}'>{{beam.get_upvalues.57}}</td> <td {{beam.color_status.59}} title='{{beam.module_messages.59}}'>{{beam.get_upvalues.58}}</td> <td {{beam.color_status.60}} title='{{beam.module_messages.60}}'>{{beam.get_upvalues.59}}</td>
435 439 </tr>
436 440 <tr>
437 441 <td {{beam.color_status.57}} title='{{beam.module_messages.57}}'>{{beam.get_downvalues.56}}</td> <td {{beam.color_status.58}} title='{{beam.module_messages.58}}'>{{beam.get_downvalues.57}}</td> <td {{beam.color_status.59}} title='{{beam.module_messages.59}}'>{{beam.get_downvalues.58}}</td> <td {{beam.color_status.60}} title='{{beam.module_messages.60}}'>{{beam.get_downvalues.59}}</td>
438 442 </tr>
439 443 </table>
440 444 </td>
441 445 <td> <b>South Quarter</b>
442 446 <table class="south ">
443 447 <tr>
444 448 <td {{beam.color_status.37}} title='{{beam.module_messages.37}}'>{{beam.get_upvalues.36}}</td> <td {{beam.color_status.38}} title='{{beam.module_messages.38}}'>{{beam.get_upvalues.37}}</td> <td {{beam.color_status.39}} title='{{beam.module_messages.39}}'>{{beam.get_upvalues.38}}</td> <td {{beam.color_status.40}} title='{{beam.module_messages.40}}'>{{beam.get_upvalues.39}}</td>
445 449 </tr>
446 450 <tr>
447 451 <td {{beam.color_status.37}} title='{{beam.module_messages.37}}'>{{beam.get_downvalues.36}}</td> <td {{beam.color_status.38}} title='{{beam.module_messages.38}}'>{{beam.get_downvalues.37}}</td> <td {{beam.color_status.39}} title='{{beam.module_messages.39}}'>{{beam.get_downvalues.38}}</td> <td {{beam.color_status.40}} title='{{beam.module_messages.40}}'>{{beam.get_downvalues.39}}</td>
448 452 </tr>
449 453 <tr>
450 454 <td {{beam.color_status.45}} title='{{beam.module_messages.45}}'>{{beam.get_upvalues.44}}</td> <td {{beam.color_status.46}} title='{{beam.module_messages.46}}'>{{beam.get_upvalues.45}}</td> <td {{beam.color_status.47}} title='{{beam.module_messages.47}}'>{{beam.get_upvalues.46}}</td> <td {{beam.color_status.48}} title='{{beam.module_messages.48}}'>{{beam.get_upvalues.47}}</td>
451 455 </tr>
452 456 <tr>
453 457 <td {{beam.color_status.45}} title='{{beam.module_messages.45}}'>{{beam.get_downvalues.44}}</td> <td {{beam.color_status.46}} title='{{beam.module_messages.46}}'>{{beam.get_downvalues.45}}</td> <td {{beam.color_status.47}} title='{{beam.module_messages.47}}'>{{beam.get_downvalues.46}}</td> <td {{beam.color_status.48}} title='{{beam.module_messages.48}}'>{{beam.get_downvalues.47}}</td>
454 458 </tr>
455 459 <tr>
456 460 <td {{beam.color_status.53}} title='{{beam.module_messages.53}}'>{{beam.get_upvalues.52}}</td> <td {{beam.color_status.54}} title='{{beam.module_messages.54}}'>{{beam.get_upvalues.53}}</td> <td {{beam.color_status.55}} title='{{beam.module_messages.55}}'>{{beam.get_upvalues.54}}</td> <td {{beam.color_status.56}} title='{{beam.module_messages.56}}'>{{beam.get_upvalues.55}}</td>
457 461 </tr>
458 462 <tr>
459 463 <td {{beam.color_status.53}} title='{{beam.module_messages.53}}'>{{beam.get_downvalues.52}}</td> <td {{beam.color_status.54}} title='{{beam.module_messages.54}}'>{{beam.get_downvalues.53}}</td> <td {{beam.color_status.55}} title='{{beam.module_messages.55}}'>{{beam.get_downvalues.54}}</td> <td {{beam.color_status.56}} title='{{beam.module_messages.56}}'>{{beam.get_downvalues.55}}</td>
460 464 </tr>
461 465 <tr>
462 466 <td {{beam.color_status.61}} title='{{beam.module_messages.61}}'>{{beam.get_upvalues.60}}</td> <td {{beam.color_status.62}} title='{{beam.module_messages.62}}'>{{beam.get_upvalues.61}}</td> <td {{beam.color_status.63}} title='{{beam.module_messages.63}}'>{{beam.get_upvalues.62}}</td> <td {{beam.color_status.64}} title='{{beam.module_messages.64}}'>{{beam.get_upvalues.63}}</td>
463 467 </tr>
464 468 <tr>
465 469 <td {{beam.color_status.61}} title='{{beam.module_messages.61}}'>{{beam.get_downvalues.60}}</td> <td {{beam.color_status.62}} title='{{beam.module_messages.62}}'>{{beam.get_downvalues.61}}</td> <td {{beam.color_status.63}} title='{{beam.module_messages.63}}'>{{beam.get_downvalues.62}}</td> <td {{beam.color_status.64}} title='{{beam.module_messages.64}}'>{{beam.get_downvalues.63}}</td>
466 470 </tr>
467 471 </table>
468 472 </td>
469 473 </tr>
470 474 </table>
471 475
472 476 {% if active_beam.id != beam.id %}
473 477 <div style="vertical-align: top; display:inline-block;">
474 478 <button style="" id="send_beam{{forloop.counter}}" type="button" class="btn btn-default">
475 479 <span class="glyphicon glyphicon-export" aria-hidden="true"></span>
476 480 Change Beam</button>
477 481 </div>
478 482 {% endif %}
479 483
480 484
481 485
482 486
483 487 {% if active_beam %}
484 488 {% if active_beam.id == beam.id %}
485 489 <table class="legend">
486 490 <tr>
487 491 <th colspan="2">Legend</th>
488 492 </tr>
489 493 <tr>
490 494 <td class="text-danger"><i>RED</i></td><td>Disconnected</td>
491 495 </tr>
492 496 <tr>
493 497 <td class="text-warning"><i>ORANGE</i></td><td>Connected</td>
494 498 </tr>
495 499 <tr>
496 500 <td class="text-success"><i>GREEN</i></td><td>Running
497 501 </td>
498 502 </tr>
499 503 </table>
500 504
501 505 {% endif %}
502 506 {% endif %}
503 507
504 508
505 509 </div>
506 510
507 511
508 512 {% endfor %}
509 513
510 514
511 515
512 516 </div>
513 517 </div>
514 518
515 519
516 520 {% else %}
517 521 <p style="color:#b4bcc2; margin-left: 5%;"><i>No Beams...</i></p>
518 522 {% endif %}
519 523
520 524 {% endblock extra-content %}
521 525
522 526
523 527
524 528 {% block extra-js%}
525 529 <script>
526 530 $(document).ready(function() {
527 531
528 532 {% for beam in beams %}
529 533
530 534 {% if dev_conf.operation_mode == 1 %}
531 535 $("#send_beam{{forloop.counter}}").prop('disabled', true)
532 536 {% else %}
533 537 $("#send_beam{{forloop.counter}}").click(function() {
534 538 document.location = "{% url 'url_send_beam' dev_conf.id beam.id %}";
535 539 });
536 540 {% endif %}
537 541
538 542 {% endfor %}
539 543
544 {% if status_request %}
545 setTimeout("location.href = '{% url 'url_abs_conf' dev_conf.id %}'",53000);
546 {% endif %}
547
540 548 });
541 549 </script>
542 550 {% endblock %}
@@ -1,16 +1,17
1 1 from django.conf.urls import url
2 2
3 3 from apps.abs import views
4 4
5 5 urlpatterns = (
6 6 url(r'^(?P<id_conf>-?\d+)/$', views.abs_conf, name='url_abs_conf'),
7 7 url(r'^(?P<id_conf>-?\d+)/edit/$', views.abs_conf_edit, name='url_edit_abs_conf'),
8 8 url(r'^(?P<id_conf>-?\d+)/import/$', views.import_file, name='url_import_abs_conf'),
9 url(r'^(?P<id_conf>-?\d+)/status/', views.abs_conf, {'status_request':True},name='url_status_abs_conf'),
9 10 url(r'^(?P<id_conf>-?\d+)/change_beam/(?P<id_beam>-?\d+)/$', views.send_beam, name='url_send_beam'),
10 11 url(r'^(?P<id_conf>-?\d+)/plot/$', views.plot_patterns, name='url_plot_abs_patterns'),
11 12 url(r'^(?P<id_conf>-?\d+)/plot/(?P<id_beam>-?\d+)/$', views.plot_patterns, name='url_plot_abs_patterns'),
12 13 url(r'^(?P<id_conf>-?\d+)/plot/(?P<id_beam>-?\d+)/(?P<antenna>[\w\-]+)/pattern.png$', views.plot_pattern, name='url_plot_beam'),
13 14 url(r'^(?P<id_conf>-?\d+)/add_beam/$', views.add_beam, name='url_add_abs_beam'),
14 15 url(r'^(?P<id_conf>-?\d+)/beam/(?P<id_beam>-?\d+)/delete/$', views.remove_beam, name='url_remove_abs_beam'),
15 16 url(r'^(?P<id_conf>-?\d+)/beam/(?P<id_beam>-?\d+)/edit/$', views.edit_beam, name='url_edit_abs_beam'),
16 17 )
@@ -1,430 +1,440
1 1 from django.shortcuts import render_to_response
2 2 from django.template import RequestContext
3 3 from django.shortcuts import redirect, render, get_object_or_404
4 4 from django.contrib import messages
5 5 from django.conf import settings
6 6 from django.http import HttpResponse
7 7 from django.core.urlresolvers import reverse
8 8
9 9 from datetime import datetime
10 10 from time import sleep
11 11 import os
12 12
13 13 from apps.main.models import Device, Configuration, Experiment
14 14 from apps.main.views import sidebar
15 15
16 16 from .models import ABSConfiguration, ABSBeam
17 17 from .forms import ABSConfigurationForm, ABSBeamEditForm, ABSBeamAddForm, ABSImportForm
18 18
19 19 from .utils.overJroShow import overJroShow
20 20 from .utils.OverJRO import OverJRO
21 21 # Create your views here.
22 22 import json, ast
23 23
24 24
25 25 def get_values_from_form(form_data):
26 26
27 27 sublistup = []
28 28 sublistdown = []
29 29 subtxlistup = []
30 30 subtxlistdown = []
31 31 subrxlistup = []
32 32 subrxlistdown = []
33 33
34 34 up_values_list = []
35 35 down_values_list = []
36 36 up_txvalues_list = []
37 37 down_txvalues_list = []
38 38 up_rxvalues_list = []
39 39 down_rxvalues_list = []
40 40
41 41 values_list = {}
42 42 cont = 1
43 43
44 44 for i in range(1,65):
45 45 x = float(form_data['abs_up'+str(i)])
46 46 y = float(form_data['abs_down'+str(i)])
47 47 sublistup.append(x)
48 48 sublistdown.append(y)
49 49
50 50 if str(i) in form_data.getlist('uptx_checks'):
51 51 subtxlistup.append(1)
52 52 else:
53 53 subtxlistup.append(0)
54 54 if str(i) in form_data.getlist('downtx_checks'):
55 55 subtxlistdown.append(1)
56 56 else:
57 57 subtxlistdown.append(0)
58 58
59 59 if str(i) in form_data.getlist('uprx_checks'):
60 60 subrxlistup.append(1)
61 61 else:
62 62 subrxlistup.append(0)
63 63 if str(i) in form_data.getlist('downrx_checks'):
64 64 subrxlistdown.append(1)
65 65 else:
66 66 subrxlistdown.append(0)
67 67
68 68 cont = cont+1
69 69
70 70 if cont == 9:
71 71 up_values_list.append(sublistup)
72 72 down_values_list.append(sublistdown)
73 73 sublistup = []
74 74 sublistdown = []
75 75
76 76 up_txvalues_list.append(subtxlistup)
77 77 down_txvalues_list.append(subtxlistdown)
78 78 subtxlistup = []
79 79 subtxlistdown = []
80 80 up_rxvalues_list.append(subrxlistup)
81 81 down_rxvalues_list.append(subrxlistdown)
82 82 subrxlistup = []
83 83 subrxlistdown = []
84 84 cont = 1
85 85
86 86
87 87 list_uesup = []
88 88 list_uesdown = []
89 89 for i in range(1,5):
90 90 if form_data['ues_up'+str(i)] == '':
91 91 list_uesup.append(0.0)
92 92 else:
93 93 list_uesup.append(float(form_data['ues_up'+str(i)]))
94 94
95 95 if form_data['ues_down'+str(i)] == '':
96 96 list_uesdown.append(0.0)
97 97 else:
98 98 list_uesdown.append(float(form_data['ues_down'+str(i)]))
99 99
100 100 onlyrx_list = form_data.getlist('onlyrx')
101 101 only_rx = {}
102 102 if '1' in onlyrx_list:
103 103 only_rx['up'] = True
104 104 else:
105 105 only_rx['up'] = False
106 106 if '2' in onlyrx_list:
107 107 only_rx['down'] = True
108 108 else:
109 109 only_rx['down'] = False
110 110
111 111 antenna = {'antenna_up': up_values_list, 'antenna_down': down_values_list}
112 112 tx = {'up': up_txvalues_list, 'down': down_txvalues_list}
113 113 rx = {'up': up_rxvalues_list, 'down': down_rxvalues_list}
114 114 ues = {'up': list_uesup, 'down': list_uesdown}
115 115 name = str(form_data['beam_name'])
116 116
117 117 beam_data = {'name': name, 'antenna': antenna, 'tx': tx, 'rx': rx, 'ues': ues, 'only_rx': only_rx}
118 118
119 119 return beam_data
120 120
121 121
122 122
123 def abs_conf(request, id_conf):
123 def abs_conf(request, id_conf, status_request=None):
124 124
125 125 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
126 126 beams = ABSBeam.objects.filter(abs_conf=conf)
127 127 active_beam_id = json.loads(conf.active_beam)
128 128
129 129 #------------Colors for Active Beam:-------------
130 130 modules_status = json.loads(conf.module_status)
131 131 module_messages = json.loads(conf.module_messages)
132 132
133 133 color_status = {}
134 134 for status in modules_status:
135 135 if modules_status[status] == 3: #Running background-color: #00cc00;
136 136 color_status[status] = 'class=text-success'#'bgcolor=#00cc00'
137 137 elif modules_status[status] == 1: #Connected background-color: #ee902c;
138 138 color_status[status] = 'class=text-warning'#'bgcolor=#ee902c'
139 139 else: #Disconnected background-color: #ff0000;
140 140 color_status[status] = 'class=text-danger'#'bgcolor=#FF0000'
141 141 #------------------------------------------------
142 142
143 143 kwargs = {}
144 144 #kwargs['status'] = conf.device.get_status_display()
145 145 kwargs['connected_modules'] = str(conf.connected_modules())+'/64'
146 146
147 147 kwargs['dev_conf'] = conf
148 148 if conf.operation_mode == 0:
149 149 kwargs['dev_conf_keys'] = ['name', 'operation_mode']
150 150 else:
151 151 kwargs['dev_conf_keys'] = ['name', 'operation_mode', 'operation_value']
152 152
153 153 kwargs['title'] = 'ABS Configuration'
154 154 kwargs['suptitle'] = 'Details'
155 155 #kwargs['no_play'] = True
156 156
157 157 kwargs['button'] = 'Edit Configuration'
158 158 #------------------Active Beam-----------------------
159 159 try:
160 160 active_beam_id = active_beam_id['active_beam']
161 161 active_beam = ABSBeam.objects.get(pk=active_beam_id)
162 162 kwargs['active_beam'] = active_beam
163 163 for beam in beams:
164 164 if beam.id == active_beam.id:
165 165 beam.color_status = color_status
166 166 beam.module_messages = module_messages
167 167 except:
168 168 active_beam = ''
169 169 #----------------------------------------------------
170 170 kwargs['beams'] = beams
171 171 kwargs['modules_status'] = modules_status
172 172 kwargs['color_status'] = color_status
173 173 kwargs['module_messages'] = module_messages
174 174
175 #kwargs['only_stop'] = True
175 #if conf.device.status in [0,1]:
176 if conf.connected_modules() == 0:
177 messages.error(request, 'No ABS module is connected.')#conf.message)
178 else:
179 messages.success(request, 'ABS modules are connected.')#conf.message)
176 180
177 181 ###### SIDEBAR ######
178 182 kwargs.update(sidebar(conf=conf))
179 183
184 if status_request:
185 conf.status_device()
186 kwargs['status_request'] = True
187 return render(request, 'abs_conf.html', kwargs)
188
180 189 return render(request, 'abs_conf.html', kwargs)
181 190
191
182 192 def abs_conf_edit(request, id_conf):
183 193
184 194 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
185 195
186 196 beams = ABSBeam.objects.filter(abs_conf=conf)
187 197 print beams
188 198
189 199 if request.method=='GET':
190 200 form = ABSConfigurationForm(instance=conf)
191 201
192 202 if request.method=='POST':
193 203 form = ABSConfigurationForm(request.POST, instance=conf)
194 204
195 205 if form.is_valid():
196 206 conf = form.save(commit=False)
197 207 conf.save()
198 208 return redirect('url_abs_conf', id_conf=conf.id)
199 209
200 210 ###### SIDEBAR ######
201 211 kwargs = {}
202 212
203 213 kwargs['dev_conf'] = conf
204 214 #kwargs['id_dev'] = conf.id
205 215 kwargs['id_conf'] = conf.id
206 216 kwargs['form'] = form
207 217 kwargs['abs_beams'] = beams
208 218 kwargs['title'] = 'Device Configuration'
209 219 kwargs['suptitle'] = 'Edit'
210 220 kwargs['button'] = 'Save'
211 221
212 222 kwargs['edit'] = True
213 223
214 224 return render(request, 'abs_conf_edit.html', kwargs)
215 225
216 226
217 227 def import_file(request, id_conf):
218 228
219 229 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
220 230 if request.method=='POST':
221 231 form = ABSImportForm(request.POST, request.FILES)
222 232 if form.is_valid():
223 233 try:
224 234 parms = conf.import_from_file(request.FILES['file_name'])
225 235
226 236 if parms:
227 237 conf.update_from_file(parms)
228 238 messages.success(request, 'Configuration "%s" loaded succesfully' % request.FILES['file_name'])
229 239 return redirect(conf.get_absolute_url_edit())
230 240
231 241 except Exception as e:
232 242 messages.error(request, 'Error parsing file: "%s" - %s' % (request.FILES['file_name'], e))
233 243
234 244 else:
235 245 messages.warning(request, 'Your current configuration will be replaced')
236 246 form = ABSImportForm()
237 247
238 248 kwargs = {}
239 249 kwargs['form'] = form
240 250 kwargs['title'] = 'ABS Configuration'
241 251 kwargs['suptitle'] = 'Import file'
242 252 kwargs['button'] = 'Upload'
243 253 kwargs['previous'] = conf.get_absolute_url()
244 254
245 255 return render(request, 'abs_import.html', kwargs)
246 256
247 257
248 258 def send_beam(request, id_conf, id_beam):
249 259
250 260 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
251 261 beam = get_object_or_404(ABSBeam, pk=id_beam)
252 262 beams_list = ABSBeam.objects.filter(abs_conf=conf)
253 263 #To set this beam as an Active Beam
254 264 beam.set_as_activebeam()
255 265 #To send beam position to abs-modules
256 266 i = 0
257 267 for b in beams_list:
258 268 if b.id == int(id_beam):
259 269 break
260 270 else:
261 271 i += 1
262 272 beam_pos = i + 1 #Estandarizar
263 273 print 'Position: ',beam_pos
264 274 conf.send_beam_num(beam_pos)
265 275
266 276 return redirect('url_abs_conf', conf.id)
267 277
268 278
269 279 def add_beam(request, id_conf):
270 280
271 281 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
272 282 confs = Configuration.objects.all()
273 283
274 284 if request.method=='GET':
275 285 #form = ABSBeamEditForm()
276 286 form = ABSBeamAddForm()
277 287
278 288 if request.method=='POST':
279 289 form = ABSBeamAddForm(request.POST)
280 290
281 291 beam_data = get_values_from_form(request.POST)
282 292
283 293 new_beam = ABSBeam(
284 294 name =beam_data['name'],
285 295 antenna =json.dumps(beam_data['antenna']),
286 296 abs_conf=conf,
287 297 tx =json.dumps(beam_data['tx']),
288 298 rx =json.dumps(beam_data['rx']),
289 299 ues =json.dumps(beam_data['ues']),
290 300 only_rx =json.dumps(beam_data['only_rx'])
291 301 )
292 302 new_beam.save()
293 303 #---Update 6bits configuration and add beam to abs configuration beams list.
294 304 new_beam.modules_6bits()
295 305 #new_beam.add_beam2list()
296 306 messages.success(request, 'Beam: "%s" has been added.' % new_beam.name)
297 307
298 308 return redirect('url_edit_abs_conf', conf.id)
299 309
300 310 ###### SIDEBAR ######
301 311 kwargs = {}
302 312
303 313 #kwargs['dev_conf'] = conf.device
304 314 #kwargs['id_dev'] = conf.device
305 315 kwargs['id_conf'] = conf.id
306 316 kwargs['form'] = form
307 317 kwargs['title'] = 'ABS Beams'
308 318 kwargs['suptitle'] = 'Add Beam'
309 319 kwargs['button'] = 'Add'
310 320 kwargs['no_sidebar'] = True
311 321
312 322 #kwargs['previous'] = conf.get_absolute_url_edit()
313 323 kwargs['edit'] = True
314 324
315 325 return render(request, 'abs_add_beam.html', kwargs)
316 326
317 327
318 328 def edit_beam(request, id_conf, id_beam):
319 329
320 330 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
321 331 beam = get_object_or_404(ABSBeam, pk=id_beam)
322 332
323 333 if request.method=='GET':
324 334 form = ABSBeamEditForm(initial={'beam': beam})
325 335
326 336 if request.method=='POST':
327 337 form = ABSBeamEditForm(request.POST)
328 338
329 339 beam_data = get_values_from_form(request.POST)
330 340
331 341 beam.dict_to_parms(beam_data)
332 342 beam.save()
333 343
334 344 messages.success(request, 'Beam: "%s" has been updated.' % beam.name)
335 345
336 346 return redirect('url_edit_abs_conf', conf.id)
337 347
338 348 ###### SIDEBAR ######
339 349 kwargs = {}
340 350
341 351 kwargs['id_conf'] = conf.id
342 352 kwargs['form'] = form
343 353 kwargs['title'] = 'ABS Beams'
344 354 kwargs['suptitle'] = 'Edit Beam'
345 355 kwargs['button'] = 'Save'
346 356 kwargs['no_sidebar'] = True
347 357
348 358 #kwargs['previous'] = conf.get_absolute_url_edit()
349 359 kwargs['edit'] = True
350 360
351 361 return render(request, 'abs_edit_beam.html', kwargs)
352 362
353 363
354 364
355 365 def remove_beam(request, id_conf, id_beam):
356 366
357 367 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
358 368 beam = get_object_or_404(ABSBeam, pk=id_beam)
359 369
360 370 if request.method=='POST':
361 371 if beam:
362 372 try:
363 373 beam.remove_beamfromlist()
364 374 beam.delete()
365 375 messages.success(request, 'Beam: "%s" has been deleted.' % beam)
366 376 except:
367 377 messages.error(request, 'Unable to delete beam: "%s".' % beam)
368 378
369 379 return redirect('url_edit_abs_conf', conf.id)
370 380
371 381 ###### SIDEBAR ######
372 382 kwargs = {}
373 383
374 384 kwargs['object'] = beam
375 385 kwargs['delete'] = True
376 386 kwargs['title'] = 'Delete'
377 387 kwargs['suptitle'] = 'Beam'
378 388 kwargs['previous'] = conf.get_absolute_url_edit()
379 389 return render(request, 'confirm.html', kwargs)
380 390
381 391
382 392
383 393 def plot_patterns(request, id_conf, id_beam=None):
384 394
385 395 kwargs = {}
386 396 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
387 397 beams = ABSBeam.objects.filter(abs_conf=conf)
388 398
389 399 if id_beam:
390 400 beam = get_object_or_404(ABSBeam, pk=id_beam)
391 401 kwargs['beam'] = beam
392 402
393 403
394 404 ###### SIDEBAR ######
395 405
396 406 kwargs['dev_conf'] = conf.device
397 407 kwargs['id_dev'] = conf.device
398 408 kwargs['id_conf'] = conf.id
399 409 kwargs['abs_beams'] = beams
400 410 kwargs['title'] = 'ABS Patterns'
401 411 kwargs['suptitle'] = conf.name
402 412 kwargs['no_sidebar'] = True
403 413
404 414 return render(request, 'abs_patterns.html', kwargs)
405 415
406 416
407 417 def plot_pattern(request, id_conf, id_beam, antenna):
408 418
409 419 if antenna=='down':
410 420 sleep(3)
411 421
412 422 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
413 423 beam = get_object_or_404(ABSBeam, pk=id_beam)
414 424
415 425 name = conf.experiment.name
416 426
417 427 just_rx = 1 if json.loads(beam.only_rx)[antenna] else 0
418 428 phases = json.loads(beam.antenna)['antenna_{}'.format(antenna)]
419 429 gain_tx = json.loads(beam.tx)[antenna]
420 430 gain_rx = json.loads(beam.rx)[antenna]
421 431 ues = json.loads(beam.ues)[antenna]
422 432
423 433 newOverJro = overJroShow(name)
424 434 fig = newOverJro.plotPattern2(datetime.today(), phases, gain_tx, gain_rx, ues, just_rx)
425 435
426 436 response=HttpResponse(content_type='image/png')
427 437
428 438 fig.canvas.print_png(response)
429 439
430 440 return response
General Comments 0
You need to be logged in to leave comments. Login now