@@ -18,8 +18,8 TZ=America/Lima | |||
|
18 | 18 | DOCKER_DATA=/data/dockers/radarsys/ |
|
19 | 19 | LOCAL_IP=192.168.1.128 |
|
20 | 20 | |
|
21 | MQTT_SERVER=10.10.10.200 | |
|
22 |
|
|
|
21 | # MQTT_SERVER=10.10.10.200 | |
|
22 | MQTT_SERVER = 192.168.100.5 | |
|
23 | 23 | MQTT_PORT = 1883 |
|
24 | 24 | MQTT_KEEPALIVE = 3660 |
|
25 | 25 |
@@ -355,6 +355,7 class ABSConfiguration(Configuration): | |||
|
355 | 355 | |
|
356 | 356 | def stop_device(self): |
|
357 | 357 | self.device.status = 2 |
|
358 | self.active_beam = 0 | |
|
358 | 359 | self.device.save() |
|
359 | 360 | self.message = 'ABS has been stopped.' |
|
360 | 361 | self.save() |
@@ -364,6 +365,9 class ABSConfiguration(Configuration): | |||
|
364 | 365 | def stop_device_mqtt(self): |
|
365 | 366 | |
|
366 | 367 | self.device.status = 2 |
|
368 | self.active_beam = 0 | |
|
369 | # conf_active = None | |
|
370 | # conf_active.save() | |
|
367 | 371 | self.device.save() |
|
368 | 372 | self.message = 'ABS has been stopped.' |
|
369 | 373 | self.save() |
@@ -426,7 +430,7 class ABSConfiguration(Configuration): | |||
|
426 | 430 | message += ''.join([fromBinary2Char(beam.module_6bits(i)) for beam in beams]) |
|
427 | 431 | status = ['0'] * 64 |
|
428 | 432 | n = 0 |
|
429 | ||
|
433 | print("Estoy en write_device normal",flush=True) | |
|
430 | 434 | sock = self.send_multicast(message) |
|
431 | 435 | |
|
432 | 436 | while True: |
@@ -500,6 +504,16 class ABSConfiguration(Configuration): | |||
|
500 | 504 | conf_active.save() |
|
501 | 505 | return True |
|
502 | 506 | |
|
507 | ||
|
508 | # DEV_STATES = ( | |
|
509 | # (0, 'No connected'), | |
|
510 | # (1, 'Connected'), | |
|
511 | # (2, 'Configured'), | |
|
512 | # (3, 'Running'), | |
|
513 | # (4, 'Unknown'), | |
|
514 | # (5, 'Busy') | |
|
515 | # ) | |
|
516 | ||
|
503 | 517 | def write_device_mqtt(self): |
|
504 | 518 | |
|
505 | 519 | if self.experiment is None: |
@@ -545,6 +559,8 class ABSConfiguration(Configuration): | |||
|
545 | 559 | apuntes_up_down=inicializacion+ apuntes_up_down+finalizacion |
|
546 | 560 | mqtt_client.publish(os.environ.get('TOPIC_ABS', 'abs/beams'),apuntes_up_down) |
|
547 | 561 | |
|
562 | self.active_beam = beams[0].pk | |
|
563 | ||
|
548 | 564 | #Start DDS-RC-JARS |
|
549 | 565 | if confdds: |
|
550 | 566 | confdds.start_device() |
@@ -554,6 +570,12 class ABSConfiguration(Configuration): | |||
|
554 | 570 | if confjars: |
|
555 | 571 | confjars.start_device() |
|
556 | 572 | |
|
573 | self.device.status = 3 | |
|
574 | self.save() | |
|
575 | ||
|
576 | conf_active, __ = ABSActive.objects.get_or_create(pk=1) | |
|
577 | conf_active.conf = self | |
|
578 | conf_active.save() | |
|
557 | 579 | return True |
|
558 | 580 | |
|
559 | 581 | def read_module(self, module): |
@@ -657,6 +679,7 class ABSConfiguration(Configuration): | |||
|
657 | 679 | return False |
|
658 | 680 | |
|
659 | 681 | sock = self.send_multicast('MNTR') |
|
682 | print("Estoy en status_deice",flush=True) | |
|
660 | 683 | |
|
661 | 684 | n = 0 |
|
662 | 685 | status = ['0'] * 64 |
@@ -777,6 +800,7 class ABSConfiguration(Configuration): | |||
|
777 | 800 | status = ['0'] * 64 |
|
778 | 801 | message = 'CHGB{}'.format(beam_pos) |
|
779 | 802 | sock = self.send_multicast(message) |
|
803 | print("Estoy en send_beam ",flush=True) | |
|
780 | 804 | while True: |
|
781 | 805 | #for i in range(32): |
|
782 | 806 | try: |
@@ -810,6 +834,93 class ABSConfiguration(Configuration): | |||
|
810 | 834 | self.save() |
|
811 | 835 | return True |
|
812 | 836 | |
|
837 | def change_beam_mqtt(self, beam_pos): | |
|
838 | """ | |
|
839 | This function connects to a multicast group and sends the beam number | |
|
840 | to all abs modules. | |
|
841 | """ | |
|
842 | print ('Send beam') | |
|
843 | print (self.active_beam) | |
|
844 | beams = ABSBeam.objects.filter(abs_conf=self) | |
|
845 | #print beams[self.active_beam-1].module_6bits(0) | |
|
846 | active = ABSActive.objects.get(pk=1) | |
|
847 | if active.conf != self: | |
|
848 | self.message = 'La configuracion actual es la del siguiente enlace %s.' % active.conf.get_absolute_url() | |
|
849 | self.message += "\n" | |
|
850 | self.message += 'Se debe realizar un write en esta configuracion para luego obtener un status valido.' | |
|
851 | ||
|
852 | return False | |
|
853 | ||
|
854 | # Se manda a cero RC para poder realizar cambio de beam | |
|
855 | if self.experiment is None: | |
|
856 | confs = [] | |
|
857 | else: | |
|
858 | confs = Configuration.objects.filter(experiment = self.experiment).filter(type=0) | |
|
859 | confdds = '' | |
|
860 | confjars = '' | |
|
861 | confrc = '' | |
|
862 | #TO STOP DEVICES: DDS-JARS-RC | |
|
863 | for i in range(0,len(confs)): | |
|
864 | if i==0: | |
|
865 | for conf in confs: | |
|
866 | if conf.device.device_type.name == 'dds': | |
|
867 | confdds = conf | |
|
868 | confdds.stop_device() | |
|
869 | break | |
|
870 | if i==1: | |
|
871 | for conf in confs: | |
|
872 | if conf.device.device_type.name == 'jars': | |
|
873 | confjars = conf | |
|
874 | confjars.stop_device() | |
|
875 | break | |
|
876 | if i==2: | |
|
877 | for conf in confs: | |
|
878 | if conf.device.device_type.name == 'rc': | |
|
879 | confrc = conf | |
|
880 | confrc.stop_device() | |
|
881 | break | |
|
882 | if beam_pos > 0: | |
|
883 | beam_pos = beam_pos - 1 | |
|
884 | else: | |
|
885 | beam_pos = 0 | |
|
886 | ||
|
887 | #El indice del apunte debe ser menor que el numero total de apuntes | |
|
888 | #El servidor tcp en el embebido comienza a contar desde 0 | |
|
889 | # status = ['0'] * 64 | |
|
890 | # message = 'CHGB{}'.format(beam_pos) | |
|
891 | # sock = self.send_multicast(message) | |
|
892 | # while True: | |
|
893 | # #for i in range(32): | |
|
894 | # try: | |
|
895 | # data, address = sock.recvfrom(1024) | |
|
896 | # print (address, data) | |
|
897 | # data = data.decode() | |
|
898 | # if data == '1': | |
|
899 | # status[int(address[0][10:])-1] = '3' | |
|
900 | # elif data == '0': | |
|
901 | # status[int(address[0][10:])-1] = '1' | |
|
902 | # except socket.timeout: | |
|
903 | # print('Timeout') | |
|
904 | # break | |
|
905 | # except Exception as e: | |
|
906 | # print ('Error {}'.format(e)) | |
|
907 | # pass | |
|
908 | ||
|
909 | # sock.close() | |
|
910 | ||
|
911 | #Start DDS-RC-JARS | |
|
912 | if confdds: | |
|
913 | confdds.start_device() | |
|
914 | if confrc: | |
|
915 | #print confrc | |
|
916 | confrc.start_device() | |
|
917 | if confjars: | |
|
918 | confjars.start_device() | |
|
919 | ||
|
920 | self.message = "ABS Beam has been changed" | |
|
921 | self.module_status = ''.join(status) | |
|
922 | self.save() | |
|
923 | return True | |
|
813 | 924 | |
|
814 | 925 | def get_absolute_url_import(self): |
|
815 | 926 | return reverse('url_import_abs_conf', args=[str(self.id)]) |
@@ -406,10 +406,11 | |||
|
406 | 406 | document.location = "{% url 'url_send_beam' dev_conf.id beam.id %}"; |
|
407 | 407 | }); |
|
408 | 408 | |
|
409 | a=$("#change_beam_mqtt{{forloop.counter}}") | |
|
410 | a.click(function () { | |
|
409 | change_beam_mqtt_btn=$("#change_beam_mqtt{{forloop.counter}}") | |
|
410 | change_beam_mqtt_btn.click(function () { | |
|
411 | 411 | info="change_beam_mqtt{{forloop.counter}}" |
|
412 | socket.emit('change_beam',{data:info}) | |
|
412 | socket.emit('change_beam',{data:info}); | |
|
413 | document.location = "{% url 'url_send_beam_mqtt' dev_conf.id beam.id %}"; | |
|
413 | 414 | }); |
|
414 | 415 | |
|
415 | 416 | {% endif %} |
@@ -9,6 +9,7 urlpatterns = ( | |||
|
9 | 9 | path('<int:id_conf>/import/', views.import_file, name='url_import_abs_conf'), |
|
10 | 10 | #url(r'^(?P<id_conf>-?\d+)/status/', views.abs_conf, {'status_request':True},name='url_status_abs_conf'), |
|
11 | 11 | path('<int:id_conf>/change_beam/<int:id_beam>/', views.send_beam, name='url_send_beam'), |
|
12 | path('<int:id_conf>/change_beam/<int:id_beam>/', views.change_beam_mqtt, name='url_send_beam_mqtt'), | |
|
12 | 13 | path('<int:id_conf>/plot/', views.plot_patterns, name='url_plot_abs_patterns'), |
|
13 | 14 | path('<int:id_conf>/plot/<int:id_beam>/', views.plot_patterns, name='url_plot_abs_patterns2'), |
|
14 | 15 | path('<int:id_conf>/plot/<int:id_beam>/<slug:antenna>/pattern.png/', views.plot_pattern, name='url_plot_beam'), |
@@ -287,7 +287,7 def send_beam(request, id_conf, id_beam): | |||
|
287 | 287 | else: |
|
288 | 288 | i += 1 |
|
289 | 289 | beam_pos = i + 1 #Estandarizar |
|
290 |
print |
|
|
290 | print('{} Position {}'.format(beam.name,str(beam_pos))) | |
|
291 | 291 | conf.send_beam(beam_pos) |
|
292 | 292 | |
|
293 | 293 | return redirect('url_abs_conf', conf.id) |
@@ -302,6 +302,81 def send_beam(request, id_conf, id_beam): | |||
|
302 | 302 | |
|
303 | 303 | return render(request, 'confirm.html', kwargs) |
|
304 | 304 | |
|
305 | def change_beam_mqtt(request, id_conf, id_beam): | |
|
306 | ||
|
307 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) | |
|
308 | ||
|
309 | abs = Configuration.objects.filter(pk=conf.device.conf_active).first() | |
|
310 | if abs!=conf: | |
|
311 | url = '#' if abs is None else abs.get_absolute_url() | |
|
312 | label = 'None' if abs is None else abs.label | |
|
313 | messages.warning( | |
|
314 | request, | |
|
315 | mark_safe('The current configuration has not been written in the modules, the active configuration is <a href="{}">{}</a>'.format( | |
|
316 | url, | |
|
317 | label | |
|
318 | )) | |
|
319 | ) | |
|
320 | return redirect(conf.get_absolute_url()) | |
|
321 | ||
|
322 | beams = ABSBeam.objects.filter(abs_conf=conf) | |
|
323 | beam = get_object_or_404(ABSBeam, pk=id_beam) | |
|
324 | ||
|
325 | if request.method == 'POST': | |
|
326 | ||
|
327 | beams_list = ABSBeam.objects.filter(abs_conf=conf) | |
|
328 | conf.active_beam = id_beam | |
|
329 | ||
|
330 | i = 0 | |
|
331 | for b in beams_list: | |
|
332 | if b.id == int(id_beam): | |
|
333 | break | |
|
334 | else: | |
|
335 | i += 1 | |
|
336 | beam_pos = i + 1 #Estandarizar | |
|
337 | ||
|
338 | print('{} Position {}'.format(beam.name,str(beam_pos))) | |
|
339 | conf.change_beam_mqtt(beam_pos) | |
|
340 | ||
|
341 | module_messages = json.loads(conf.module_messages) | |
|
342 | kwargs = {} | |
|
343 | kwargs['connected_modules'] = str(conf.connected_modules())+'/64' | |
|
344 | kwargs['dev_conf'] = conf | |
|
345 | ||
|
346 | if conf.operation_mode == 0: | |
|
347 | kwargs['dev_conf_keys'] = ['label', 'operation_mode'] | |
|
348 | else: | |
|
349 | kwargs['dev_conf_keys'] = ['label', 'operation_mode', 'operation_value'] | |
|
350 | ||
|
351 | kwargs['title'] = 'ABS Configuration' | |
|
352 | kwargs['suptitle'] = 'Details' | |
|
353 | kwargs['button'] = 'Edit Configuration' | |
|
354 | if conf.active_beam != 0: | |
|
355 | kwargs['active_beam'] = int(conf.active_beam) | |
|
356 | ||
|
357 | ||
|
358 | kwargs['beams'] = beams | |
|
359 | # kwargs['modules_status'] = all_status | |
|
360 | # kwargs['color_status'] = color_status | |
|
361 | ||
|
362 | ||
|
363 | kwargs['module_messages'] = module_messages | |
|
364 | ||
|
365 | ###### SIDEBAR ###### | |
|
366 | kwargs.update(sidebar(conf=conf)) | |
|
367 | ||
|
368 | # return redirect('url_abs_conf', conf.id) | |
|
369 | return render(request, 'abs_conf_mqtt.html',kwargs) | |
|
370 | ||
|
371 | kwargs = { | |
|
372 | 'title': 'ABS', | |
|
373 | 'suptitle': conf.label, | |
|
374 | 'message': 'Are you sure you want to change ABS Beam through MQTT to: {}?'.format(beam.name), | |
|
375 | 'delete': False | |
|
376 | } | |
|
377 | kwargs['menu_configurations'] = 'active' | |
|
378 | ||
|
379 | return render(request, 'confirm.html', kwargs) | |
|
305 | 380 | |
|
306 | 381 | def add_beam(request, id_conf): |
|
307 | 382 |
@@ -78,9 +78,8 def GetTemperatures(data): | |||
|
78 | 78 | |
|
79 | 79 | def on_connect(mqtt_client, userdata, flags, rc): |
|
80 | 80 | if rc == 0: |
|
81 | print('Connected successfullyasdss') | |
|
81 | # print('Connected successfullyasdss') | |
|
82 | 82 | mqtt_client.subscribe("atrad/test4") |
|
83 | print("Exito") | |
|
84 | 83 | else: |
|
85 | 84 | print('Bad connection. Code:', rc) |
|
86 | 85 |
@@ -442,6 +442,7 class Experiment(models.Model): | |||
|
442 | 442 | |
|
443 | 443 | |
|
444 | 444 | for conf in confs: |
|
445 | print("conf->",conf) | |
|
445 | 446 | print(conf.device) |
|
446 | 447 | print(conf.device.status) |
|
447 | 448 | print("--------------",flush=True) |
@@ -60,9 +60,9 | |||
|
60 | 60 | {% else %} |
|
61 | 61 | <div class="col-md-3 hidden-xs hidden-sm" role="complementary"> |
|
62 | 62 | <br><br> |
|
63 | <div id="sidebar"> | |
|
64 | {% block sidebar%} | |
|
65 | {% include "sidebar_devices.html" %} | |
|
63 | <div id="sidebar"> | |
|
64 | {% block sidebar%} | |
|
65 | {% include "sidebar_devices.html" %} | |
|
66 | 66 | {% endblock %} |
|
67 | 67 | </div> |
|
68 | 68 | </div> |
@@ -88,8 +88,10 | |||
|
88 | 88 | {% endfor %} |
|
89 | 89 | {% endif %} |
|
90 | 90 | {% endblock %} |
|
91 | {% block content %} | |
|
92 |
{% |
|
|
91 | ||
|
92 | {% block content %} | |
|
93 | {% endblock %} | |
|
94 | ||
|
93 | 95 | </div> |
|
94 | 96 | {% block content-graph %} |
|
95 | 97 | {% endblock %} |
@@ -40,8 +40,6 | |||
|
40 | 40 | {% endfor%} |
|
41 | 41 | </tr> |
|
42 | 42 | {% for object in objects %} |
|
43 | <p>{{ object }}</p> | |
|
44 | <p>{{ objects }}</p> | |
|
45 | 43 | <tr class="clickable-row" data-href="{{object.get_absolute_url}}"> |
|
46 | 44 | <td>{{ forloop.counter|add:offset }}</td> |
|
47 | 45 | {% for key in keys %} |
@@ -46,7 +46,7 | |||
|
46 | 46 | {% else %} |
|
47 | 47 | <td class="text-info"><strong> Connected </strong></td> |
|
48 | 48 | {% endif %} |
|
49 | </tr> | |
|
49 | </tr> | |
|
50 | 50 | |
|
51 | 51 | {% for key in dev_conf_keys %} |
|
52 | 52 | <tr> |
@@ -1579,6 +1579,7 def dev_conf_write_mqtt(request,id_conf): | |||
|
1579 | 1579 | kwargs['suptitle'] = 'Details' |
|
1580 | 1580 | kwargs['button'] = 'Edit Configuration' |
|
1581 | 1581 | |
|
1582 | print("conf.active_beam: {}".format(conf.active_beam)) | |
|
1582 | 1583 | if conf.active_beam != 0: |
|
1583 | 1584 | kwargs['active_beam'] = int(conf.active_beam) |
|
1584 | 1585 |
@@ -199,7 +199,7 class RCConfiguration(Configuration): | |||
|
199 | 199 | 'params': json.dumps(line_data['params']) |
|
200 | 200 | } |
|
201 | 201 | ) |
|
202 | print(line,flush=True) | |
|
202 | # print(line,flush=True) | |
|
203 | 203 | |
|
204 | 204 | for i, line in enumerate(self.get_lines()): |
|
205 | 205 | line_params = json.loads(line.params) |
@@ -563,10 +563,10 class RCConfiguration(Configuration): | |||
|
563 | 563 | else: |
|
564 | 564 | data = {'manual': [clock.multiplier, clock.divisor, clock.reference]} |
|
565 | 565 | payload = self.request('setfreq', 'post', data=json.dumps(data)) |
|
566 | print(payload) | |
|
566 | # print(payload) | |
|
567 | 567 | if payload['command'] != 'ok': |
|
568 | 568 | self.message = 'RC write: {}'.format(payload['command']) |
|
569 | print('RC write: {}'.format(payload['command'])) | |
|
569 | # print('RC write: {}'.format(payload['command'])) | |
|
570 | 570 | else: |
|
571 | 571 | self.message = payload['programming'] |
|
572 | 572 | if payload['programming'] == 'fail': |
@@ -620,12 +620,12 class RCConfiguration(Configuration): | |||
|
620 | 620 | self.device.status = 3 |
|
621 | 621 | self.device.save() |
|
622 | 622 | self.message = 'RC configured and started' |
|
623 | print('RC configured and started') | |
|
623 | # print('RC configured and started') | |
|
624 | 624 | else: |
|
625 | 625 | self.device.status = 1 |
|
626 | 626 | self.device.save() |
|
627 | 627 | self.message = 'RC write: {}'.format(payload['write']) |
|
628 | print('RC write: {}'.format(payload['write'])) | |
|
628 | # print('RC write: {}'.format(payload['write'])) | |
|
629 | 629 | return False |
|
630 | 630 | |
|
631 | 631 | #payload = self.request('start', 'post') |
@@ -688,11 +688,11 class RCLine(models.Model): | |||
|
688 | 688 | ordering = ['channel'] |
|
689 | 689 | |
|
690 | 690 | def __str__(self): |
|
691 | print("AAAA: ",self.rc_configuration,flush=True) | |
|
692 | ret = u'{}|{} - {}'.format(self.pk, self.get_name(),self.rc_configuration.name) | |
|
693 | return ret | |
|
694 |
|
|
|
695 |
|
|
|
691 | # print("AAAA: ",self.rc_configuration,flush=True) | |
|
692 | # ret = u'{}|{} - {}'.format(self.pk, self.get_name(),self.rc_configuration.name) | |
|
693 | # return ret | |
|
694 | if self.rc_configuration: | |
|
695 | return u'{}|{} - {}'.format(self.pk, self.get_name(), self.rc_configuration.name) | |
|
696 | 696 | |
|
697 | 697 | def jsonify(self): |
|
698 | 698 |
@@ -355,22 +355,22 def update_lines_position(request, conf_id): | |||
|
355 | 355 | |
|
356 | 356 | |
|
357 | 357 | def import_file(request, conf_id): |
|
358 | print("HOLA",flush=True) | |
|
358 | # print("HOLA",flush=True) | |
|
359 | 359 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
360 | print("HOLA2",flush=True) | |
|
360 | # print("HOLA2",flush=True) | |
|
361 | 361 | if request.method=='POST': |
|
362 | 362 | form = RCImportForm(request.POST, request.FILES) |
|
363 | print("HOLA3",flush=True) | |
|
363 | # print("HOLA3",flush=True) | |
|
364 | 364 | if form.is_valid(): |
|
365 | print("HOLA4",flush=True) | |
|
365 | #print("HOLA4",flush=True) | |
|
366 | 366 | # try: |
|
367 | print("HOLA5",flush=True) | |
|
367 | #print("HOLA5",flush=True) | |
|
368 | 368 | data = conf.import_from_file(request.FILES['file_name']) |
|
369 | print("HOLA6",flush=True) | |
|
369 | #print("HOLA6",flush=True) | |
|
370 | 370 | conf.dict_to_parms(data) |
|
371 | print("1",flush=True) | |
|
371 | #print("1",flush=True) | |
|
372 | 372 | conf.update_pulses() |
|
373 | print("2",flush=True) | |
|
373 | #print("2",flush=True) | |
|
374 | 374 | messages.success(request, 'Configuration "%s" loaded succesfully' % request.FILES['file_name']) |
|
375 | 375 | return redirect(conf.get_absolute_url_edit()) |
|
376 | 376 |
General Comments 0
You need to be logged in to leave comments.
Login now