@@ -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: | |
|
469 | self.message = 'ABS modules Status have been updated.' | |||
|
470 | return 1 | |||
|
471 | self.message = 'No ABS module is connected.' | |||
431 |
|
|
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): |
@@ -310,14 +310,13 | |||||
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> | |
@@ -485,13 +484,13 | |||||
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> |
@@ -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