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