@@ -377,8 +377,10 class ABSConfiguration(Configuration): | |||||
377 | return False |
|
377 | return False | |
378 |
|
378 | |||
379 | #-------------Write each abs module----------- |
|
379 | #-------------Write each abs module----------- | |
|
380 | ||||
380 | if beams: |
|
381 | if beams: | |
381 | message = 'SNDF{:02d}'.format(nbeams) |
|
382 | block_id = 0 | |
|
383 | message = 'SNDF{:03d}{:02d}{:02d}'.format(nbeams, nbeams, block_id) | |||
382 | for i, status in enumerate(self.module_status): |
|
384 | for i, status in enumerate(self.module_status): | |
383 | message += ''.join([fromBinary2Char(beam.module_6bits(i)) for beam in beams]) |
|
385 | message += ''.join([fromBinary2Char(beam.module_6bits(i)) for beam in beams]) | |
384 | status = ['0'] * 64 |
|
386 | status = ['0'] * 64 | |
@@ -386,14 +388,16 class ABSConfiguration(Configuration): | |||||
386 |
|
388 | |||
387 | sock = self.send_multicast(message) |
|
389 | sock = self.send_multicast(message) | |
388 |
|
390 | |||
389 |
for i in range( |
|
391 | for i in range(32): | |
390 | try: |
|
392 | try: | |
391 | data, address = sock.recvfrom(1024) |
|
393 | data, address = sock.recvfrom(1024) | |
|
394 | print address, data | |||
392 | if data == '1': |
|
395 | if data == '1': | |
393 | status[int(address[0][10:])-1] = '3' |
|
396 | status[int(address[0][10:])-1] = '3' | |
394 | elif data == '0': |
|
397 | elif data == '0': | |
395 | status[int(address[0][10:])-1] = '1' |
|
398 | status[int(address[0][10:])-1] = '1' | |
396 | except: |
|
399 | except Exception as e: | |
|
400 | print 'Error {}'.format(e) | |||
397 | n += 1 |
|
401 | n += 1 | |
398 | sock.close() |
|
402 | sock.close() | |
399 | else: |
|
403 | else: | |
@@ -481,7 +485,7 class ABSConfiguration(Configuration): | |||||
481 | for i, status in enumerate(self.module_status): |
|
485 | for i, status in enumerate(self.module_status): | |
482 | if status != '0': |
|
486 | if status != '0': | |
483 | num += 1 |
|
487 | num += 1 | |
484 | print('status {}:{}'.format(i+1, status)) |
|
488 | #print('status {}:{}'.format(i+1, status)) | |
485 | return num |
|
489 | return num | |
486 |
|
490 | |||
487 | def send_multicast(self, message): |
|
491 | def send_multicast(self, message): | |
@@ -489,8 +493,10 class ABSConfiguration(Configuration): | |||||
489 | multicast_group = ('224.3.29.71', 10000) |
|
493 | multicast_group = ('224.3.29.71', 10000) | |
490 | # Create the datagram socket |
|
494 | # Create the datagram socket | |
491 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
|
495 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
492 |
sock.settimeout( |
|
496 | sock.settimeout(1) | |
|
497 | # sock.bind((local_ip, 10000)) | |||
493 | local_ip = os.environ.get('LOCAL_IP', '127.0.0.1') |
|
498 | local_ip = os.environ.get('LOCAL_IP', '127.0.0.1') | |
|
499 | local_ip = '192.168.1.128' | |||
494 | sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_IF, socket.inet_aton(local_ip)) |
|
500 | sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_IF, socket.inet_aton(local_ip)) | |
495 | sent = sock.sendto(message, multicast_group) |
|
501 | sent = sock.sendto(message, multicast_group) | |
496 | print('Sending ' + message) |
|
502 | print('Sending ' + message) | |
@@ -506,9 +512,12 class ABSConfiguration(Configuration): | |||||
506 |
|
512 | |||
507 | n = 0 |
|
513 | n = 0 | |
508 | status = ['0'] * 64 |
|
514 | status = ['0'] * 64 | |
509 |
for i in range( |
|
515 | for i in range(32): | |
|
516 | #if True: | |||
510 | try: |
|
517 | try: | |
|
518 | address = None | |||
511 | data, address = sock.recvfrom(1024) |
|
519 | data, address = sock.recvfrom(1024) | |
|
520 | print address, data | |||
512 | if data == '1': |
|
521 | if data == '1': | |
513 | status[int(address[0][10:])-1] = '3' |
|
522 | status[int(address[0][10:])-1] = '3' | |
514 | elif data == '0': |
|
523 | elif data == '0': | |
@@ -516,6 +525,7 class ABSConfiguration(Configuration): | |||||
516 | n += 1 |
|
525 | n += 1 | |
517 | print('Module: {} connected'.format(address)) |
|
526 | print('Module: {} connected'.format(address)) | |
518 | except: |
|
527 | except: | |
|
528 | print('Module: {} error'.format(address)) | |||
519 | pass |
|
529 | pass | |
520 | sock.close() |
|
530 | sock.close() | |
521 |
|
531 | |||
@@ -538,11 +548,13 class ABSConfiguration(Configuration): | |||||
538 | """ |
|
548 | """ | |
539 |
|
549 | |||
540 | # Se manda a cero RC para poder realizar cambio de beam |
|
550 | # Se manda a cero RC para poder realizar cambio de beam | |
541 | confs = Configuration.objects.filter(experiment = self.experiment).filter(type=0) |
|
551 | if self.experiment is None: | |
|
552 | confs = [] | |||
|
553 | else: | |||
|
554 | confs = Configuration.objects.filter(experiment = self.experiment).filter(type=0) | |||
542 | confdds = '' |
|
555 | confdds = '' | |
543 | confjars = '' |
|
556 | confjars = '' | |
544 | confrc = '' |
|
557 | confrc = '' | |
545 |
|
||||
546 | #TO STOP DEVICES: DDS-JARS-RC |
|
558 | #TO STOP DEVICES: DDS-JARS-RC | |
547 | for i in range(0,len(confs)): |
|
559 | for i in range(0,len(confs)): | |
548 | if i==0: |
|
560 | if i==0: | |
@@ -563,7 +575,6 class ABSConfiguration(Configuration): | |||||
563 | confrc = conf |
|
575 | confrc = conf | |
564 | confrc.stop_device() |
|
576 | confrc.stop_device() | |
565 | break |
|
577 | break | |
566 |
|
||||
567 | if beam_pos > 0: |
|
578 | if beam_pos > 0: | |
568 | beam_pos = beam_pos - 1 |
|
579 | beam_pos = beam_pos - 1 | |
569 | else: |
|
580 | else: | |
@@ -574,8 +585,7 class ABSConfiguration(Configuration): | |||||
574 | status = ['0'] * 64 |
|
585 | status = ['0'] * 64 | |
575 | message = 'CHGB{}'.format(beam_pos) |
|
586 | message = 'CHGB{}'.format(beam_pos) | |
576 | sock = self.send_multicast(message) |
|
587 | sock = self.send_multicast(message) | |
577 |
|
588 | for i in range(32): | ||
578 | for i in range(64): |
|
|||
579 | try: |
|
589 | try: | |
580 | data, address = sock.recvfrom(1024) |
|
590 | data, address = sock.recvfrom(1024) | |
581 | print address, data |
|
591 | print address, data | |
@@ -583,7 +593,8 class ABSConfiguration(Configuration): | |||||
583 | status[int(address[0][10:])-1] = '3' |
|
593 | status[int(address[0][10:])-1] = '3' | |
584 | elif data == '0': |
|
594 | elif data == '0': | |
585 | status[int(address[0][10:])-1] = '1' |
|
595 | status[int(address[0][10:])-1] = '1' | |
586 | except: |
|
596 | except Exception as e: | |
|
597 | print 'Error {}'.format(e) | |||
587 | pass |
|
598 | pass | |
588 |
|
599 | |||
589 | sock.close() |
|
600 | sock.close() | |
@@ -670,6 +681,7 class ABSBeam(models.Model): | |||||
670 | """ |
|
681 | """ | |
671 | This function reads antenna pattern and choose 6bits (upbits-downbits) for one abs module |
|
682 | This function reads antenna pattern and choose 6bits (upbits-downbits) for one abs module | |
672 | """ |
|
683 | """ | |
|
684 | module += 1 | |||
673 | if module > 64: |
|
685 | if module > 64: | |
674 | beam_bits = "" |
|
686 | beam_bits = "" | |
675 | return beam_bits |
|
687 | return beam_bits |
@@ -5,6 +5,7 from apps.abs import views | |||||
5 | urlpatterns = ( |
|
5 | urlpatterns = ( | |
6 | url(r'^(?P<id_conf>-?\d+)/$', views.abs_conf, name='url_abs_conf'), |
|
6 | url(r'^(?P<id_conf>-?\d+)/$', views.abs_conf, name='url_abs_conf'), | |
7 | url(r'^(?P<id_conf>-?\d+)/edit/$', views.abs_conf_edit, name='url_edit_abs_conf'), |
|
7 | url(r'^(?P<id_conf>-?\d+)/edit/$', views.abs_conf_edit, name='url_edit_abs_conf'), | |
|
8 | url(r'^alert/$', views.abs_conf_alert, name='url_alert_abs_conf'), | |||
8 | url(r'^(?P<id_conf>-?\d+)/import/$', views.import_file, name='url_import_abs_conf'), |
|
9 | 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'), |
|
10 | #url(r'^(?P<id_conf>-?\d+)/status/', views.abs_conf, {'status_request':True},name='url_status_abs_conf'), | |
10 | url(r'^(?P<id_conf>-?\d+)/change_beam/(?P<id_beam>-?\d+)/$', views.send_beam, name='url_send_beam'), |
|
11 | url(r'^(?P<id_conf>-?\d+)/change_beam/(?P<id_beam>-?\d+)/$', views.send_beam, name='url_send_beam'), |
@@ -5,6 +5,7 from django.contrib import messages | |||||
5 | from django.conf import settings |
|
5 | from django.conf import settings | |
6 | from django.http import HttpResponse |
|
6 | from django.http import HttpResponse | |
7 | from django.core.urlresolvers import reverse |
|
7 | from django.core.urlresolvers import reverse | |
|
8 | from django.views.decorators.csrf import csrf_exempt | |||
8 |
|
9 | |||
9 | from datetime import datetime |
|
10 | from datetime import datetime | |
10 | from time import sleep |
|
11 | from time import sleep | |
@@ -200,6 +201,15 def abs_conf_edit(request, id_conf): | |||||
200 |
|
201 | |||
201 | return render(request, 'abs_conf_edit.html', kwargs) |
|
202 | return render(request, 'abs_conf_edit.html', kwargs) | |
202 |
|
203 | |||
|
204 | @csrf_exempt | |||
|
205 | def abs_conf_alert(request): | |||
|
206 | ||||
|
207 | if request.method == 'POST': | |||
|
208 | print request.POST | |||
|
209 | return HttpResponse(json.dumps({'result':1}), content_type='application/json') | |||
|
210 | else: | |||
|
211 | return redirect('index') | |||
|
212 | ||||
203 |
|
213 | |||
204 | def import_file(request, id_conf): |
|
214 | def import_file(request, id_conf): | |
205 |
|
215 | |||
@@ -342,7 +352,6 def remove_beam(request, id_conf, id_beam): | |||||
342 | if request.method=='POST': |
|
352 | if request.method=='POST': | |
343 | if beam: |
|
353 | if beam: | |
344 | try: |
|
354 | try: | |
345 | beam.remove_beamfromlist() |
|
|||
346 | beam.delete() |
|
355 | beam.delete() | |
347 | messages.success(request, 'Beam: "%s" has been deleted.' % beam) |
|
356 | messages.success(request, 'Beam: "%s" has been deleted.' % beam) | |
348 | except: |
|
357 | except: | |
@@ -403,4 +412,4 def plot_pattern(request, id_conf, id_beam, antenna): | |||||
403 | fig.savefig(buf, format='png') |
|
412 | fig.savefig(buf, format='png') | |
404 | response = HttpResponse(buf.getvalue(), content_type='image/png') |
|
413 | response = HttpResponse(buf.getvalue(), content_type='image/png') | |
405 | return response |
|
414 | return response | |
406 | No newline at end of file |
|
415 |
General Comments 0
You need to be logged in to leave comments.
Login now