@@ -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,9 +388,10 class ABSConfiguration(Configuration): | |||
|
386 | 388 | |
|
387 | 389 | sock = self.send_multicast(message) |
|
388 | 390 | |
|
389 |
for i in range( |
|
|
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': |
@@ -408,7 +411,7 class ABSConfiguration(Configuration): | |||
|
408 | 411 | return False |
|
409 | 412 | else: |
|
410 | 413 | self.message = "ABS Beams List have been sent to ABS Modules" |
|
411 | beams[0].set_as_activebeam() | |
|
414 | self.active_beam = beams[0].pk | |
|
412 | 415 | |
|
413 | 416 | self.device.status = 3 |
|
414 | 417 | self.module_status = ''.join(status) |
@@ -481,7 +484,7 class ABSConfiguration(Configuration): | |||
|
481 | 484 | for i, status in enumerate(self.module_status): |
|
482 | 485 | if status != '0': |
|
483 | 486 | num += 1 |
|
484 | print('status {}:{}'.format(i+1, status)) | |
|
487 | #print('status {}:{}'.format(i+1, status)) | |
|
485 | 488 | return num |
|
486 | 489 | |
|
487 | 490 | def send_multicast(self, message): |
@@ -489,8 +492,9 class ABSConfiguration(Configuration): | |||
|
489 | 492 | multicast_group = ('224.3.29.71', 10000) |
|
490 | 493 | # Create the datagram socket |
|
491 | 494 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
|
492 |
sock.settimeout(0. |
|
|
493 |
local_ip = " |
|
|
495 | sock.settimeout(0.5) | |
|
496 | local_ip = "192.168.1.128" | |
|
497 | sock.bind((local_ip, 10000)) | |
|
494 | 498 | sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_IF, socket.inet_aton(local_ip)) |
|
495 | 499 | sent = sock.sendto(message, multicast_group) |
|
496 | 500 | print('Sending ' + message) |
@@ -506,9 +510,11 class ABSConfiguration(Configuration): | |||
|
506 | 510 | |
|
507 | 511 | n = 0 |
|
508 | 512 | status = ['0'] * 64 |
|
509 |
for i in range( |
|
|
513 | for i in range(32): | |
|
514 | #if True: | |
|
510 | 515 | try: |
|
511 | 516 | data, address = sock.recvfrom(1024) |
|
517 | print address, data | |
|
512 | 518 | if data == '1': |
|
513 | 519 | status[int(address[0][10:])-1] = '3' |
|
514 | 520 | elif data == '0': |
@@ -516,6 +522,7 class ABSConfiguration(Configuration): | |||
|
516 | 522 | n += 1 |
|
517 | 523 | print('Module: {} connected'.format(address)) |
|
518 | 524 | except: |
|
525 | print('Module: {} error'.format(address)) | |
|
519 | 526 | pass |
|
520 | 527 | sock.close() |
|
521 | 528 | |
@@ -538,13 +545,17 class ABSConfiguration(Configuration): | |||
|
538 | 545 | """ |
|
539 | 546 | |
|
540 | 547 | # Se manda a cero RC para poder realizar cambio de beam |
|
541 | confs = Configuration.objects.filter(experiment = self.experiment).filter(type=0) | |
|
548 | if self.experiment is None: | |
|
549 | confs = [] | |
|
550 | else: | |
|
551 | confs = Configuration.objects.filter(experiment = self.experiment).filter(type=0) | |
|
542 | 552 | confdds = '' |
|
543 | 553 | confjars = '' |
|
544 | 554 | confrc = '' |
|
545 | ||
|
555 | print 'Starting...', self.experiment | |
|
546 | 556 | #TO STOP DEVICES: DDS-JARS-RC |
|
547 | 557 | for i in range(0,len(confs)): |
|
558 | print i | |
|
548 | 559 | if i==0: |
|
549 | 560 | for conf in confs: |
|
550 | 561 | if conf.device.device_type.name == 'dds': |
@@ -559,11 +570,12 class ABSConfiguration(Configuration): | |||
|
559 | 570 | break |
|
560 | 571 | if i==2: |
|
561 | 572 | for conf in confs: |
|
573 | print conf | |
|
562 | 574 | if conf.device.device_type.name == 'rc': |
|
563 | 575 | confrc = conf |
|
564 | 576 | confrc.stop_device() |
|
565 | 577 | break |
|
566 | ||
|
578 | print 'Stop devices' | |
|
567 | 579 | if beam_pos > 0: |
|
568 | 580 | beam_pos = beam_pos - 1 |
|
569 | 581 | else: |
@@ -573,9 +585,10 class ABSConfiguration(Configuration): | |||
|
573 | 585 | #El servidor tcp en el embebido comienza a contar desde 0 |
|
574 | 586 | status = ['0'] * 64 |
|
575 | 587 | message = 'CHGB{}'.format(beam_pos) |
|
588 | print 'Before send' | |
|
576 | 589 | sock = self.send_multicast(message) |
|
577 | ||
|
578 |
for i in range( |
|
|
590 | print 'Waiting' | |
|
591 | for i in range(32): | |
|
579 | 592 | try: |
|
580 | 593 | data, address = sock.recvfrom(1024) |
|
581 | 594 | print address, data |
@@ -670,6 +683,7 class ABSBeam(models.Model): | |||
|
670 | 683 | """ |
|
671 | 684 | This function reads antenna pattern and choose 6bits (upbits-downbits) for one abs module |
|
672 | 685 | """ |
|
686 | module += 1 | |
|
673 | 687 | if module > 64: |
|
674 | 688 | beam_bits = "" |
|
675 | 689 | 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