##// END OF EJS Templates
Add support to read abs module status
Juan C. Espinoza -
r326:f70d4e6cdcb2
parent child
Show More
@@ -1,7 +1,6
1 from django.db import models
1 from django.db import models
2 from apps.main.models import Configuration
2 from apps.main.models import Configuration, User
3 from django.core.urlresolvers import reverse
3 from django.core.urlresolvers import reverse
4 # Create your models here.
5 from celery.execute import send_task
4 from celery.execute import send_task
6 from datetime import datetime
5 from datetime import datetime
7 import ast
6 import ast
@@ -11,9 +10,6 import requests
11 import struct
10 import struct
12 import os, sys, time
11 import os, sys, time
13
12
14 import multiprocessing
15
16
17 antenna_default = json.dumps({
13 antenna_default = json.dumps({
18 "antenna_up": [[0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
14 "antenna_up": [[0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
19 [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
15 [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
@@ -210,7 +206,7 OPERATION_MODES = (
210
206
211 class ABSConfiguration(Configuration):
207 class ABSConfiguration(Configuration):
212 active_beam = models.PositiveSmallIntegerField(verbose_name='Active Beam', default=0)
208 active_beam = models.PositiveSmallIntegerField(verbose_name='Active Beam', default=0)
213 module_status = models.CharField(verbose_name='Module Status', max_length=10000, default=json.dumps(status_default))
209 module_status = models.CharField(verbose_name='Module Status', max_length=10000, default=status_default)
214 operation_mode = models.PositiveSmallIntegerField(verbose_name='Operation Mode', choices=OPERATION_MODES, default = 0)
210 operation_mode = models.PositiveSmallIntegerField(verbose_name='Operation Mode', choices=OPERATION_MODES, default = 0)
215 operation_value = models.FloatField(verbose_name='Periodic (seconds)', default="10", null=True, blank=True)
211 operation_value = models.FloatField(verbose_name='Periodic (seconds)', default="10", null=True, blank=True)
216 module_messages = models.CharField(verbose_name='Modules Messages', max_length=10000, default=json.dumps(default_messages))
212 module_messages = models.CharField(verbose_name='Modules Messages', max_length=10000, default=json.dumps(default_messages))
@@ -417,6 +413,9 class ABSConfiguration(Configuration):
417 self.device.status = 3
413 self.device.status = 3
418 self.module_status = ''.join(status)
414 self.module_status = ''.join(status)
419 self.save()
415 self.save()
416 for u in User.objects.all():
417 u.profile.abs_active = self
418 u.save()
420 return True
419 return True
421
420
422
421
@@ -494,11 +493,9 class ABSConfiguration(Configuration):
494 # Create the datagram socket
493 # Create the datagram socket
495 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
494 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
496 sock.settimeout(1)
495 sock.settimeout(1)
497 # sock.bind((local_ip, 10000))
498 local_ip = os.environ.get('LOCAL_IP', '127.0.0.1')
496 local_ip = os.environ.get('LOCAL_IP', '127.0.0.1')
499 local_ip = '192.168.1.128'
500 sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_IF, socket.inet_aton(local_ip))
497 sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_IF, socket.inet_aton(local_ip))
501 sent = sock.sendto(message, multicast_group)
498 sock.sendto(message, multicast_group)
502 print('Sending ' + message)
499 print('Sending ' + message)
503 return sock
500 return sock
504
501
@@ -517,13 +514,19 class ABSConfiguration(Configuration):
517 try:
514 try:
518 address = None
515 address = None
519 data, address = sock.recvfrom(1024)
516 data, address = sock.recvfrom(1024)
520 print address, data
517 x = int(address[0][10:])-1
521 if data == '1':
518 if data[0] == '1':
522 status[int(address[0][10:])-1] = '3'
519 remote = fromChar2Binary(data[1])
523 elif data == '0':
520 local = ABSBeam.objects.get(pk=self.active_beam).module_6bits(x)
524 status[int(address[0][10:])-1] = '1'
521 if local == remote:
522 status[x] = '3'
523 print('Module: {} connected...igual'.format(address))
524 else:
525 status[x] = '2'
526 print('Module: {} connected...diferente'.format(address))
527 elif data[0] == '0':
528 status[x] = '1'
525 n += 1
529 n += 1
526 print('Module: {} connected'.format(address))
527 except:
530 except:
528 print('Module: {} error'.format(address))
531 print('Module: {} error'.format(address))
529 pass
532 pass
@@ -34,6 +34,7
34 .legend td {
34 .legend td {
35 padding: 2px;
35 padding: 2px;
36 text-align: center;
36 text-align: center;
37 font-weight: bold;
37 }
38 }
38
39
39 </style>
40 </style>
@@ -282,26 +283,19
282 {% if beam.id == active_beam %}
283 {% if beam.id == active_beam %}
283 <table class="legend">
284 <table class="legend">
284 <tr>
285 <tr>
285 <th colspan="2">Legend</th>
286 <th>Legend</th>
286 </tr>
287 </tr>
287 <tr>
288 <tr>
288 <td class="text-danger">
289 <td class="text-warning">Connected</td>
289 <i>RED</i>
290 </td>
291 <td>Disconnected</td>
292 </tr>
290 </tr>
293 <tr>
291 <tr>
294 <td class="text-warning">
292 <td class="text-success">Running</td>
295 <i>ORANGE</i>
296 </td>
297 <td>Connected</td>
298 </tr>
293 </tr>
299 <tr>
294 <tr>
300 <td class="text-success">
295 <td class="text-info">Mismath</td>
301 <i>GREEN</i>
296 </tr>
302 </td>
297 <tr>
303 <td>Running
298 <td class="text-danger">Disconnected</td>
304 </td>
305 </tr>
299 </tr>
306 </table>
300 </table>
307 {% else %}
301 {% else %}
@@ -6,6 +6,7 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 from django.views.decorators.csrf import csrf_exempt
9 from django.utils.safestring import mark_safe
9
10
10 from datetime import datetime
11 from datetime import datetime
11 from time import sleep
12 from time import sleep
@@ -134,6 +135,9 def abs_conf(request, id_conf):
134 if status == '3': #Running background-color: #00cc00;
135 if status == '3': #Running background-color: #00cc00;
135 all_status['{}'.format(i+1)] = 2
136 all_status['{}'.format(i+1)] = 2
136 color_status['{}'.format(i+1)] = 'class=text-success'#'bgcolor=#00cc00'
137 color_status['{}'.format(i+1)] = 'class=text-success'#'bgcolor=#00cc00'
138 elif status == '2':
139 all_status['{}'.format(i+1)] = 1
140 color_status['{}'.format(i+1)] = 'class=text-info'
137 elif status == '1': #Connected background-color: #ee902c;
141 elif status == '1': #Connected background-color: #ee902c;
138 all_status['{}'.format(i+1)] = 1
142 all_status['{}'.format(i+1)] = 1
139 color_status['{}'.format(i+1)] = 'class=text-warning'#'bgcolor=#ee902c'
143 color_status['{}'.format(i+1)] = 'class=text-warning'#'bgcolor=#ee902c'
@@ -245,8 +249,22 def import_file(request, id_conf):
245 def send_beam(request, id_conf, id_beam):
249 def send_beam(request, id_conf, id_beam):
246
250
247 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
251 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
252
253 abs = request.user.profile.abs_active
254 if abs<>conf:
255 url = '#' if abs is None else abs.get_absolute_url()
256 label = 'None' if abs is None else abs.label
257 messages.warning(
258 request,
259 mark_safe('The current configuration has not been written in the modules, the active configuration is <a href="{}">{}</a>'.format(
260 url,
261 label
262 ))
263 )
264 return redirect(conf.get_absolute_url())
265
248 beam = get_object_or_404(ABSBeam, pk=id_beam)
266 beam = get_object_or_404(ABSBeam, pk=id_beam)
249 beams_list = ABSBeam.objects.filter(abs_conf=conf)
267 beams_list = ABSBeam.objects.filter(abs_conf=conf)
250 conf.active_beam = id_beam
268 conf.active_beam = id_beam
251
269
252 i = 0
270 i = 0
@@ -118,5 +118,13
118 },
118 },
119 "model": "auth.user",
119 "model": "auth.user",
120 "pk": 1
120 "pk": 1
121 },
122 {
123 "fields": {
124 "user": 1,
125 "theme": "spacelab"
126 },
127 "model": "main.profile",
128 "pk": 1
121 }
129 }
122 ] No newline at end of file
130 ]
@@ -88,7 +88,9 CONF_TYPES = (
88
88
89 class Profile(models.Model):
89 class Profile(models.Model):
90 user = models.OneToOneField(User, on_delete=models.CASCADE)
90 user = models.OneToOneField(User, on_delete=models.CASCADE)
91 theme = models.CharField(max_length=30, default='yeti')
91 theme = models.CharField(max_length=30, default='spacelab')
92 abs_active = models.ForeignKey('Configuration', null=True, blank=True, verbose_name='Current ABS')
93
92
94
93 @receiver(post_save, sender=User)
95 @receiver(post_save, sender=User)
94 def create_user_profile(sender, instance, created, **kwargs):
96 def create_user_profile(sender, instance, created, **kwargs):
@@ -1444,10 +1444,25 def dev_conf_stop(request, id_conf):
1444 return redirect(conf.get_absolute_url())
1444 return redirect(conf.get_absolute_url())
1445
1445
1446
1446
1447 @login_required
1447 def dev_conf_status(request, id_conf):
1448 def dev_conf_status(request, id_conf):
1448
1449
1449 conf = get_object_or_404(Configuration, pk=id_conf)
1450 conf = get_object_or_404(Configuration, pk=id_conf)
1450
1451
1452 if conf.device.device_type.name == 'abs':
1453 abs = request.user.profile.abs_active
1454 if abs<>conf:
1455 url = '#' if abs is None else abs.get_absolute_url()
1456 label = 'None' if abs is None else abs.label
1457 messages.warning(
1458 request,
1459 mark_safe('The current configuration has not been written in the modules, the active configuration is <a href="{}">{}</a>'.format(
1460 url,
1461 label
1462 ))
1463 )
1464 return redirect(conf.get_absolute_url())
1465
1451 if conf.status_device():
1466 if conf.status_device():
1452 messages.success(request, conf.message)
1467 messages.success(request, conf.message)
1453 else:
1468 else:
General Comments 0
You need to be logged in to leave comments. Login now