@@ -308,8 +308,7 class ABSConfiguration(Configuration): | |||
|
308 | 308 | module = 'ABS_'+str(module_num) |
|
309 | 309 | bs = '' #{} |
|
310 | 310 | i=1 |
|
311 | #beams = {1: '001000', 2: '010001', 3: '010010', 4: '000011', 5: '101100', 6: '101101', | |
|
312 | # 7: '110110', 8: '111111', 9: '000000', 10: '001001', 11: '010010', 12: '011011'} | |
|
311 | ||
|
313 | 312 | for beam in beams: |
|
314 | 313 | #bs[i] = fromBinary2Char(beam.module_6bits(module_num)) |
|
315 | 314 | bs = bs + fromBinary2Char(beam.module_6bits(module_num)) |
@@ -318,14 +317,17 class ABSConfiguration(Configuration): | |||
|
318 | 317 | beams = bs |
|
319 | 318 | |
|
320 | 319 | parameters = {} |
|
321 | parameters['header'] = header | |
|
322 | parameters['module'] = module | |
|
320 | #parameters['header'] = header | |
|
321 | #parameters['module'] = module | |
|
323 | 322 | parameters['beams'] = beams #json.dumps(beams) |
|
324 |
print |
|
|
323 | #print beams | |
|
324 | #print parameters['beams'] | |
|
325 | print parameters | |
|
325 | 326 | answer = '' |
|
326 | 327 | |
|
327 | 328 | try: |
|
328 | r_write = requests.post(write_route, parameters, timeout=0.5) | |
|
329 | #r_write = requests.post(write_route, parameters, timeout=0.5) | |
|
330 | r_write = requests.post(write_route, json = parameters, timeout=0.5) | |
|
329 | 331 | answer = r_write.json() |
|
330 | 332 | self.message = answer['message'] |
|
331 | 333 | except: |
@@ -333,6 +335,50 class ABSConfiguration(Configuration): | |||
|
333 | 335 | return 0 |
|
334 | 336 | return 1 |
|
335 | 337 | |
|
338 | ||
|
339 | ||
|
340 | def write_device(self): | |
|
341 | """ | |
|
342 | This function sends the beams list to every abs module. | |
|
343 | It needs 'module_conf' function | |
|
344 | """ | |
|
345 | ||
|
346 | beams = ABSBeam.objects.filter(abs_conf=self) | |
|
347 | ||
|
348 | #-------------Write each abs module----------- | |
|
349 | if beams: | |
|
350 | beams_status = ast.literal_eval(self.module_status) | |
|
351 | for i in range(61,64): #(62,65) | |
|
352 | try: | |
|
353 | answer = self.module_conf(i, beams) | |
|
354 | beams_status[str(i)] = 1 | |
|
355 | self.module_status = json.dumps(beams_status) | |
|
356 | self.save() | |
|
357 | ||
|
358 | except: | |
|
359 | beams_status[str(i)] = 0 | |
|
360 | self.module_status = json.dumps(beams_status) | |
|
361 | self.save() | |
|
362 | answer = 0 | |
|
363 | return 0 | |
|
364 | else: | |
|
365 | self.message = "ABS Configuration does not have beams" | |
|
366 | return 0 | |
|
367 | ||
|
368 | #self.device.status = 1 | |
|
369 | ## | |
|
370 | if answer==1: | |
|
371 | self.message = "ABS Beams List have been sent to ABS Modules" | |
|
372 | beams[0].set_as_activebeam() | |
|
373 | else: | |
|
374 | self.message = "Could not read ABS parameters" | |
|
375 | ## | |
|
376 | self.save() | |
|
377 | return 1 | |
|
378 | ||
|
379 | ||
|
380 | ||
|
381 | ||
|
336 | 382 | def read_module(self, module): |
|
337 | 383 | |
|
338 | 384 | """ |
@@ -360,19 +406,17 class ABSConfiguration(Configuration): | |||
|
360 | 406 | module_bits = answer['allbits'] |
|
361 | 407 | except: |
|
362 | 408 | #message = "Could not read ABS parameters" |
|
409 | answer = r_write.json() | |
|
363 | 410 | return 0 |
|
364 | 411 | |
|
365 | 412 | return module_bits |
|
366 | 413 | |
|
367 | 414 | |
|
368 |
def |
|
|
369 | ||
|
370 | return True | |
|
371 | ||
|
372 | def status_device(self): | |
|
415 | def absmodule_status(self): | |
|
373 | 416 | """ |
|
374 | 417 | This function gets the status of each abs module. It sends GET method to Web Application |
|
375 | 418 | in Python Bottle. |
|
419 | This function updates "module_status" field from ABSconfiguration. | |
|
376 | 420 | """ |
|
377 | 421 | ip_address = self.device.ip_address |
|
378 | 422 | ip_address = ip_address.split('.') |
@@ -395,51 +439,38 class ABSConfiguration(Configuration): | |||
|
395 | 439 | modules_status[str(i)] = 0 |
|
396 | 440 | pass |
|
397 | 441 | |
|
398 | self.message = 'ABS modules Status have been updated.' | |
|
442 | ||
|
399 | 443 | self.module_status=json.dumps(modules_status) |
|
400 | 444 | self.save() |
|
401 | 445 | |
|
402 | 446 | return |
|
403 | 447 | |
|
404 | 448 | |
|
405 |
def |
|
|
449 | def connected_modules(self): | |
|
406 | 450 | """ |
|
407 |
This function |
|
|
408 | It needs 'module_conf' function | |
|
451 | This function returns the number of connected abs-modules without updating. | |
|
409 | 452 | """ |
|
453 | modules_status = json.loads(self.module_status) | |
|
454 | num = 0 | |
|
455 | for status in modules_status: | |
|
456 | num = num +modules_status[status] | |
|
410 | 457 | |
|
411 | beams = ABSBeam.objects.filter(abs_conf=self) | |
|
458 | return num | |
|
412 | 459 | |
|
413 | #-------------Write each abs module----------- | |
|
414 | if beams: | |
|
415 | beams_status = ast.literal_eval(self.module_status) | |
|
416 | for i in range(61,64): #(62,65) | |
|
417 | try: | |
|
418 | answer = self.module_conf(i, beams) | |
|
419 | beams_status[str(i)] = 1 | |
|
420 | self.module_status = json.dumps(beams_status) | |
|
421 | self.save() | |
|
422 | 460 | |
|
423 | except: | |
|
424 | beams_status[str(i)] = 0 | |
|
425 | self.module_status = json.dumps(beams_status) | |
|
426 | self.save() | |
|
427 | answer = 0 | |
|
428 | return 0 | |
|
429 | else: | |
|
430 | self.message = "ABS Configuration does not have beams" | |
|
431 | return 0 | |
|
461 | def status_device(self): | |
|
462 | """ | |
|
463 | This function returns the status of all abs-modules as one. | |
|
464 | If at least one module is connected, its answer is "1" | |
|
465 | """ | |
|
466 | self.absmodule_status() | |
|
467 | connected_modules = self.connected_modules() | |
|
468 | if connected_modules>0: | |
|
469 | self.message = 'ABS modules Status have been updated.' | |
|
470 | return 1 | |
|
471 | self.message = 'No ABS module is connected.' | |
|
472 | return 0 | |
|
432 | 473 | |
|
433 | #self.device.status = 1 | |
|
434 | ## | |
|
435 | if answer==1: | |
|
436 | self.message = "ABS Beams List have been sent to ABS Modules" | |
|
437 | beams[0].set_as_activebeam() | |
|
438 | else: | |
|
439 | self.message = "Could not read ABS parameters" | |
|
440 | ## | |
|
441 | self.save() | |
|
442 | return 1 | |
|
443 | 474 | |
|
444 | 475 | |
|
445 | 476 | def write_module(self, module): |
@@ -51,7 +51,7 | |||
|
51 | 51 | } |
|
52 | 52 | .north tr{ |
|
53 | 53 | border: 1px solid #ffffff; |
|
54 | ||
|
54 | ||
|
55 | 55 | } |
|
56 | 56 | .north td{ |
|
57 | 57 | border: 2px solid #e2e2e7; |
@@ -177,12 +177,12 | |||
|
177 | 177 | {% endfor %} |
|
178 | 178 | </ul> |
|
179 | 179 | |
|
180 | ||
|
180 | ||
|
181 | 181 | <div class="tab-content"> |
|
182 | 182 | <div id="home" class="tab-pane fade in active"> |
|
183 | 183 | <!----> |
|
184 | 184 | {% if active_beam %} |
|
185 |
<h3>Active Beam: {{active_beam.name}}</h3> |
|
|
185 | <h3>Active Beam: {{active_beam.name}}</h3> | |
|
186 | 186 | |
|
187 | 187 | <table id="abs_pattern" class="abs"> |
|
188 | 188 | <tr> |
@@ -304,20 +304,19 | |||
|
304 | 304 | </table> |
|
305 | 305 | |
|
306 | 306 | |
|
307 | ||
|
307 | ||
|
308 | 308 | <table class="legend"> |
|
309 | 309 | <tr> |
|
310 | 310 | <th colspan="2">Legend</th> |
|
311 | 311 | </tr> |
|
312 | 312 | <tr> |
|
313 |
<td |
|
|
313 | <td class="text-danger"><i>RED</i></td><td>Disconnected</td> | |
|
314 | 314 | </tr> |
|
315 | 315 | <tr> |
|
316 |
<td |
|
|
316 | <td class="text-warning"><i>ORANGE</i></td><td>Connected</td> | |
|
317 | 317 | </tr> |
|
318 | 318 | <tr> |
|
319 |
<td |
|
|
320 | </td> | |
|
319 | <td class="text-success"><i>GREEN</i></td><td>Running </td> | |
|
321 | 320 | </tr> |
|
322 | 321 | <!-- |
|
323 | 322 | <tr> |
@@ -329,8 +328,8 | |||
|
329 | 328 | </tr> |
|
330 | 329 | --> |
|
331 | 330 | </table> |
|
332 | ||
|
333 | ||
|
331 | ||
|
332 | ||
|
334 | 333 | |
|
335 | 334 | |
|
336 | 335 | {% else %} |
@@ -341,8 +340,8 | |||
|
341 | 340 | |
|
342 | 341 | |
|
343 | 342 | </div> |
|
344 | ||
|
345 | ||
|
343 | ||
|
344 | ||
|
346 | 345 | |
|
347 | 346 | {% for beam in beams %} |
|
348 | 347 | <div id="menu{{forloop.counter}}" class="tab-pane fade"> |
@@ -474,9 +473,9 | |||
|
474 | 473 | Change Beam</button> |
|
475 | 474 | </div> |
|
476 | 475 | {% endif %} |
|
477 | ||
|
478 | 476 | |
|
479 | ||
|
477 | ||
|
478 | ||
|
480 | 479 | |
|
481 | 480 | {% if active_beam %} |
|
482 | 481 | {% if active_beam.id == beam.id %} |
@@ -485,27 +484,27 | |||
|
485 | 484 | <th colspan="2">Legend</th> |
|
486 | 485 | </tr> |
|
487 | 486 | <tr> |
|
488 |
<td |
|
|
487 | <td class="text-danger"><i>RED</i></td><td>Disconnected</td> | |
|
489 | 488 | </tr> |
|
490 | 489 | <tr> |
|
491 |
<td |
|
|
490 | <td class="text-warning"><i>ORANGE</i></td><td>Connected</td> | |
|
492 | 491 | </tr> |
|
493 | 492 | <tr> |
|
494 |
<td |
|
|
493 | <td class="text-success"><i>GREEN</i></td><td>Running | |
|
495 | 494 | </td> |
|
496 | 495 | </tr> |
|
497 | 496 | </table> |
|
498 | ||
|
497 | ||
|
499 | 498 | {% endif %} |
|
500 | 499 | {% endif %} |
|
501 | 500 | |
|
502 | ||
|
501 | ||
|
503 | 502 | </div> |
|
504 | 503 | |
|
505 | 504 | |
|
506 | 505 | {% endfor %} |
|
507 | 506 | |
|
508 | ||
|
507 | ||
|
509 | 508 | |
|
510 | 509 | </div> |
|
511 | 510 | </div> |
@@ -519,9 +518,9 $(document).ready(function() { | |||
|
519 | 518 | {% for beam in beams %} |
|
520 | 519 | $("#send_beam{{forloop.counter}}").click(function() { |
|
521 | 520 | document.location = "{% url 'url_send_beam' dev_conf.id beam.id %}"; |
|
522 |
}); |
|
|
521 | }); | |
|
523 | 522 | {%endfor%} |
|
524 | ||
|
523 | ||
|
525 | 524 | }); |
|
526 | 525 | </script> |
|
527 | 526 |
@@ -131,17 +131,17 def abs_conf(request, id_conf): | |||
|
131 | 131 | |
|
132 | 132 | color_status = {} |
|
133 | 133 | for status in modules_status: |
|
134 |
if modules_status[status] == 2: #Running background-color: # |
|
|
135 |
color_status[status] = ' |
|
|
134 | if modules_status[status] == 2: #Running background-color: #00cc00; | |
|
135 | color_status[status] = 'class=text-success'#'bgcolor=#00cc00' | |
|
136 | 136 | elif modules_status[status] == 1: #Connected background-color: #ee902c; |
|
137 |
color_status[status] = ' |
|
|
138 |
else: #Disconnected background-color: #00 |
|
|
139 |
color_status[status] = ' |
|
|
137 | color_status[status] = 'class=text-warning'#'bgcolor=#ee902c' | |
|
138 | else: #Disconnected background-color: #ff0000; | |
|
139 | color_status[status] = 'class=text-danger'#'bgcolor=#FF0000' | |
|
140 | 140 | #------------------------------------------------ |
|
141 | 141 | |
|
142 | 142 | kwargs = {} |
|
143 | kwargs['status'] = conf.device.get_status_display() | |
|
144 | ||
|
143 | #kwargs['status'] = conf.device.get_status_display() | |
|
144 | kwargs['connected_modules'] = str(conf.connected_modules())+'/64' | |
|
145 | 145 | |
|
146 | 146 | kwargs['dev_conf'] = conf |
|
147 | 147 | kwargs['dev_conf_keys'] = ['name',] |
General Comments 0
You need to be logged in to leave comments.
Login now