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