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