##// END OF EJS Templates
Avance de feedback ABS
Renato Huallpa -
r385:f880fec30c88
parent child
Show More
@@ -18,8 +18,8 TZ=America/Lima
18 DOCKER_DATA=/data/dockers/radarsys/
18 DOCKER_DATA=/data/dockers/radarsys/
19 LOCAL_IP=192.168.1.128
19 LOCAL_IP=192.168.1.128
20
20
21 MQTT_SERVER=10.10.10.200
21 # MQTT_SERVER=10.10.10.200
22 #MQTT_SERVER = 0.0.0.0
22 MQTT_SERVER = 192.168.100.5
23 MQTT_PORT = 1883
23 MQTT_PORT = 1883
24 MQTT_KEEPALIVE = 3660
24 MQTT_KEEPALIVE = 3660
25
25
@@ -361,6 +361,16 class ABSConfiguration(Configuration):
361
361
362 return True
362 return True
363
363
364 def stop_device_mqtt(self):
365
366 self.device.status = 2
367 self.device.save()
368 self.message = 'ABS has been stopped.'
369 self.save()
370
371 mqtt_client.publish(os.environ.get('TOPIC_ABS', 'abs/beams'),"STOP")
372
373 return True
364
374
365 def write_device(self):
375 def write_device(self):
366
376
@@ -494,6 +504,35 class ABSConfiguration(Configuration):
494 return True
504 return True
495
505
496 def write_device_mqtt(self):
506 def write_device_mqtt(self):
507
508 if self.experiment is None:
509 confs = []
510 else:
511 confs = Configuration.objects.filter(experiment = self.experiment).filter(type=0)
512 confdds = ''
513 confjars = ''
514 confrc = ''
515 #TO STOP DEVICES: DDS-JARS-RC
516 for i in range(0,len(confs)):
517 if i==0:
518 for conf in confs:
519 if conf.device.device_type.name == 'dds':
520 confdds = conf
521 confdds.stop_device()
522 break
523 if i==1:
524 for conf in confs:
525 if conf.device.device_type.name == 'jars':
526 confjars = conf
527 confjars.stop_device()
528 break
529 if i==2:
530 for conf in confs:
531 if conf.device.device_type.name == 'rc':
532 confrc = conf
533 confrc.stop_device()
534 break
535
497 apuntes_up_down=''
536 apuntes_up_down=''
498 beams = ABSBeam.objects.filter(abs_conf=self)
537 beams = ABSBeam.objects.filter(abs_conf=self)
499
538
@@ -506,13 +545,18 class ABSConfiguration(Configuration):
506 apuntes_up_down=apuntes_up_down+info
545 apuntes_up_down=apuntes_up_down+info
507
546
508 apuntes_up_down=apuntes_up_down[:len(apuntes_up_down)-1]
547 apuntes_up_down=apuntes_up_down[:len(apuntes_up_down)-1]
509
510 apuntes_up_down=inicializacion+ apuntes_up_down+finalizacion
548 apuntes_up_down=inicializacion+ apuntes_up_down+finalizacion
511
512 #print(apuntes_up_down,flush=True)
513
514 mqtt_client.publish(os.environ.get('TOPIC_ABS', 'abs/beams'),apuntes_up_down)
549 mqtt_client.publish(os.environ.get('TOPIC_ABS', 'abs/beams'),apuntes_up_down)
515
550
551 #Start DDS-RC-JARS
552 if confdds:
553 confdds.start_device()
554 if confrc:
555 #print confrc
556 confrc.start_device()
557 if confjars:
558 confjars.start_device()
559
516 return True
560 return True
517
561
518 def read_module(self, module):
562 def read_module(self, module):
@@ -174,6 +174,14 def abs_conf(request, id_conf):
174 return render(request, 'abs_conf.html', kwargs)
174 return render(request, 'abs_conf.html', kwargs)
175
175
176
176
177 # def abs_conf_mqtt(request, id_conf):
178 # # socket.on('beams_ack',function(data){
179 # ack=data;
180 # console.log("ack")
181 # console.log(ack)
182 # })
183
184
177 def abs_conf_edit(request, id_conf):
185 def abs_conf_edit(request, id_conf):
178
186
179 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
187 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
@@ -248,41 +256,6 def import_file(request, id_conf):
248 return render(request, 'abs_import.html', kwargs)
256 return render(request, 'abs_import.html', kwargs)
249
257
250
258
251 # def send_mqtt(request,id_conf):
252
253 # # conf = get_object_or_404(ABSConfiguration, pk=id_conf)
254
255 # # abs_mqtt = Configuration.objects.filter(pk=conf.device.conf_active).first()
256 # # if abs_mqtt!=conf:
257 # # url_mqtt = '#' if abs is None else abs.get_absolute_url()
258 # # label_mqtt = 'None' if abs is None else abs.label
259 # # messages.warning(
260 # # request,
261 # # mark_safe('The current configuration has not been written in the modules, the active configuration is <a href="{}">{}</a>'.format(
262 # # url_mqtt,
263 # # label_mqtt
264 # # ))
265 # # )
266 # # return redirect(conf.get_absolute_url())
267
268 # # beam = get_object_or_404(ABSBeam, pk=id_beam)
269
270 # conf = get_object_or_404(ABSConfiguration, pk=id_conf)
271
272 # mqtt_client.publish('abs/beams_up', 'Hola up')
273 # mqtt_client.publish('abs/beams_down', 'Hola down')
274
275 # kwargs = {
276 # 'title': 'ABS',
277 # 'suptitle': conf.label,
278 # 'message': 'Are you sure you want to write ABS Beam?',
279 # 'delete': False
280 # }
281 # kwargs['menu_configurations'] = 'active'
282
283 # return render(request, 'confirm.html', kwargs)
284
285
286 def send_beam(request, id_conf, id_beam):
259 def send_beam(request, id_conf, id_beam):
287
260
288 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
261 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
@@ -781,6 +781,10 class Configuration(PolymorphicModel):
781 self.message = 'Function not implemented'
781 self.message = 'Function not implemented'
782 return False
782 return False
783
783
784 def write_device_mqtt(self, parms):
785
786 self.message = 'Function not implemented'
787 return False
784
788
785 def read_device(self):
789 def read_device(self):
786
790
@@ -817,6 +821,9 class Configuration(PolymorphicModel):
817
821
818 def get_absolute_url_stop(self):
822 def get_absolute_url_stop(self):
819 return reverse('url_stop_dev_conf', args=[str(self.id)])
823 return reverse('url_stop_dev_conf', args=[str(self.id)])
824
825 def get_absolute_url_stop_mqtt(self):
826 return reverse('url_stop_mqtt_dev_conf', args=[str(self.id)])
820
827
821 def get_absolute_url_status(self):
828 def get_absolute_url_status(self):
822 return reverse('url_status_dev_conf', args=[str(self.id)])
829 return reverse('url_status_dev_conf', args=[str(self.id)])
@@ -5,12 +5,8 from radarsys.socketconfig import sio as sio
5
5
6
6
7 lista_ack=[
7 lista_ack=[
8 chr( 33 ), chr( 34 ), chr( 35 ), chr( 36 ), chr( 37 ), chr( 38 ), chr( 39 ), chr( 40 ), chr( 41 ), chr( 42 ), chr( 43 ), chr( 44 ), chr( 45 ), chr( 46 ), chr( 47 ), chr( 48 ), chr( 49 ), chr( 50 ), chr( 51 ), chr( 52 ), chr( 53 ), chr( 54 ), chr( 55 ), chr( 56 ), chr( 57 ), chr( 58 ), chr( 59 ), chr( 60 ), chr( 61 ), chr( 62 ), chr( 63 ), chr( 64 ), chr( 65 ), chr( 66 ), chr( 67 ), chr( 68 ), chr( 69 ), chr( 70 ), chr( 71 ), chr( 72 ), chr( 73 ), chr( 74 ), chr( 75 ), chr( 76 ), chr( 77 ), chr( 78 ), chr( 79 ), chr( 80 ), chr( 81 ), chr( 82 ), chr( 83 ), chr( 84 ), chr( 85 ), chr( 86 ), chr( 87 ), chr( 88 ), chr( 89 ), chr( 90 ), chr( 91 ), chr( 92 ), chr( 93 ), chr( 94 ), chr( 95 ), chr( 96 )
8 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128
9 ]
9 ]
10
11 lista_ack_dismatching=[
12 chr( 97 ), chr( 98 ), chr( 99 ), chr( 100 ), chr( 101 ), chr( 102 ), chr( 103 ), chr( 104 ), chr( 105 ), chr( 106 ), chr( 107 ), chr( 108 ), chr( 109 ), chr( 110 ), chr( 111 ), chr( 112 ), chr( 113 ), chr( 114 ), chr( 115 ), chr( 116 ), chr( 117 ), chr( 118 ), chr( 119 ), chr( 120 ), chr( 121 ), chr( 122 ), chr( 123 ), chr( 124 ), chr( 125 ), chr( 126 ), chr( 127 ), chr( 128 ), chr( 129 ), chr( 130 ), chr( 131 ), chr( 132 ), chr( 133 ), chr( 134 ), chr( 135 ), chr( 136 ), chr( 137 ), chr( 138 ), chr( 139 ), chr( 140 ), chr( 141 ), chr( 142 ), chr( 143 ), chr( 144 ), chr( 145 ), chr( 146 ), chr( 147 ), chr( 148 ), chr( 149 ), chr( 150 ), chr( 151 ), chr( 152 ), chr( 153 ), chr( 154 ), chr( 155 ), chr( 156 ), chr( 157 ), chr( 158 ), chr( 159 ), chr(160)
13 ]
14
10
15
11
16
12
@@ -25,11 +21,33 def on_message(mqtt_client, userdata, msg):
25 # print(f'Received message on topic: {msg.topic} with payload: {msg.payload}', flush=True)
21 # print(f'Received message on topic: {msg.topic} with payload: {msg.payload}', flush=True)
26 # message= str(msg.payload)
22 # message= str(msg.payload)
27 # sio.emit('abs_ws',data={'msg':message})
23 # sio.emit('abs_ws',data={'msg':message})
28 print("HOLA",flush=True)
24 #print("HOLA",flush=True)
29 # message=msg.payload[1]
25 # message=msg.payload[1]
30 # print("HOLAAA ",message,flush=True)
26 # print("HOLAAA ",message,flush=True)
31 # #lista_ack.remove(msg.payload)
27 # #lista_ack.remove(msg.payload)
32 # print("LISTA ",lista_ack)
28 # print("LISTA ",lista_ack)
29 global lista_ack
30 global lista_ack_dismatching
31 message= str(msg.payload)
32 message=message[2:len(message)-1]
33 if(message=="UPDATE"):
34 print("UUPDATE")
35 sio.emit('beams_ack',data={'msg':lista_ack})
36 print(lista_ack,flush=True)
37 lista_ack=[
38 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128
39 ]
40 else:
41 message=int(message)
42 if(message<=64):
43 # print(message,"\t MATCH",flush=True)
44 lista_ack.remove(message+64)
45
46 elif(message>64):
47 # print(message,"\t DISMATCH",flush=True)
48 lista_ack.remove(message-64)
49 else:
50 print(len(message))
33
51
34
52
35
53
@@ -28,6 +28,7
28 <li><a href="{{ dev_conf.get_absolute_url_write }}"><span class="fas fa-arrow-circle-down" aria-hidden="true"></span> Write</a></li>
28 <li><a href="{{ dev_conf.get_absolute_url_write }}"><span class="fas fa-arrow-circle-down" aria-hidden="true"></span> Write</a></li>
29 {% if dev_conf.device.device_type.name == 'abs' %}
29 {% if dev_conf.device.device_type.name == 'abs' %}
30 <li><a href="{{ dev_conf.get_absolute_url_write_mqtt }}"><span class="fas fa-arrow-circle-down" aria-hidden="true"></span> Write MQTT</a></li>
30 <li><a href="{{ dev_conf.get_absolute_url_write_mqtt }}"><span class="fas fa-arrow-circle-down" aria-hidden="true"></span> Write MQTT</a></li>
31 <li><a href="{{ dev_conf.get_absolute_url_stop_mqtt }}"><span class="fas fa-stop" aria-hidden="true"></span> Stop MQTT</a></li>
31 {% endif %}
32 {% endif %}
32 {% if dev_conf.device.device_type.name != 'abs' %}
33 {% if dev_conf.device.device_type.name != 'abs' %}
33 <li><a href="{{ dev_conf.get_absolute_url_read }}"><span class="fas fa-arrow-circle-up" aria-hidden="true"></span> Read</a></li>
34 <li><a href="{{ dev_conf.get_absolute_url_read }}"><span class="fas fa-arrow-circle-up" aria-hidden="true"></span> Read</a></li>
@@ -59,6 +59,7 urlpatterns = (
59 path('dev_conf/<int:id_conf>/export/', views.dev_conf_export, name='url_export_dev_conf'),
59 path('dev_conf/<int:id_conf>/export/', views.dev_conf_export, name='url_export_dev_conf'),
60 path('dev_conf/<int:id_conf>/start/', views.dev_conf_start, name='url_start_dev_conf'),
60 path('dev_conf/<int:id_conf>/start/', views.dev_conf_start, name='url_start_dev_conf'),
61 path('dev_conf/<int:id_conf>/stop/', views.dev_conf_stop, name='url_stop_dev_conf'),
61 path('dev_conf/<int:id_conf>/stop/', views.dev_conf_stop, name='url_stop_dev_conf'),
62 path('dev_conf/<int:id_conf>/stop_mqtt/', views.dev_conf_stop_mqtt, name='url_stop_mqtt_dev_conf'),
62 path('dev_conf/<int:id_conf>/status/', views.dev_conf_status, name='url_status_dev_conf'),
63 path('dev_conf/<int:id_conf>/status/', views.dev_conf_status, name='url_status_dev_conf'),
63
64
64 path('operation/', views.operation, name='url_operation'),
65 path('operation/', views.operation, name='url_operation'),
@@ -1465,6 +1465,19 def dev_conf_stop(request, id_conf):
1465
1465
1466 return redirect(conf.get_absolute_url())
1466 return redirect(conf.get_absolute_url())
1467
1467
1468 @login_required
1469 def dev_conf_stop_mqtt(request, id_conf):
1470
1471 conf = get_object_or_404(Configuration, pk=id_conf)
1472
1473 if conf.stop_device_mqtt():
1474 messages.success(request, conf.message)
1475 else:
1476 messages.error(request, conf.message)
1477
1478 #conf.status_device()
1479
1480 return redirect(conf.get_absolute_url())
1468
1481
1469 @login_required
1482 @login_required
1470 def dev_conf_status(request, id_conf):
1483 def dev_conf_status(request, id_conf):
@@ -1513,7 +1526,6 def dev_conf_write(request, id_conf):
1513
1526
1514 if request.method == 'POST':
1527 if request.method == 'POST':
1515 if conf.write_device():
1528 if conf.write_device():
1516 mqtt_client.publish('abs/beams_up', 'Write normal')
1517 conf.device.conf_active = conf.pk
1529 conf.device.conf_active = conf.pk
1518 conf.device.save()
1530 conf.device.save()
1519 messages.success(request, conf.message)
1531 messages.success(request, conf.message)
@@ -1542,9 +1554,6 def dev_conf_write_mqtt(request,id_conf):
1542
1554
1543 if request.method == 'POST':
1555 if request.method == 'POST':
1544 if conf.write_device_mqtt():
1556 if conf.write_device_mqtt():
1545 mqtt_client.publish('abs/beams_up', 'Mqtt')
1546 #mqtt_client.publish('abs/beams_down', 'Hola down')
1547
1548 conf.device.conf_active = conf.pk
1557 conf.device.conf_active = conf.pk
1549 conf.device.save()
1558 conf.device.save()
1550 messages.success(request, conf.message)
1559 messages.success(request, conf.message)
@@ -1552,7 +1561,7 def dev_conf_write_mqtt(request,id_conf):
1552 conf.clone(type=1, template=False)
1561 conf.clone(type=1, template=False)
1553 else:
1562 else:
1554 messages.error(request, conf.message)
1563 messages.error(request, conf.message)
1555
1564 print("return",flush=True)
1556 return redirect(get_object_or_404(Configuration, pk=id_conf).get_absolute_url())
1565 return redirect(get_object_or_404(Configuration, pk=id_conf).get_absolute_url())
1557
1566
1558 kwargs = {
1567 kwargs = {
@@ -1562,7 +1571,7 def dev_conf_write_mqtt(request,id_conf):
1562 'delete': False
1571 'delete': False
1563 }
1572 }
1564 kwargs['menu_configurations'] = 'active'
1573 kwargs['menu_configurations'] = 'active'
1565
1574 print("Confirm",flush=True)
1566 return render(request, 'confirm.html', kwargs)
1575 return render(request, 'confirm.html', kwargs)
1567
1576
1568
1577
General Comments 0
You need to be logged in to leave comments. Login now