diff --git a/apps/abs/models.py b/apps/abs/models.py
index 2e0c1ec..f9d1a14 100644
--- a/apps/abs/models.py
+++ b/apps/abs/models.py
@@ -1,7 +1,6 @@
from django.db import models
-from apps.main.models import Configuration
+from apps.main.models import Configuration, User
from django.core.urlresolvers import reverse
-# Create your models here.
from celery.execute import send_task
from datetime import datetime
import ast
@@ -11,9 +10,6 @@ import requests
import struct
import os, sys, time
-import multiprocessing
-
-
antenna_default = json.dumps({
"antenna_up": [[0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
[0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
@@ -210,7 +206,7 @@ OPERATION_MODES = (
class ABSConfiguration(Configuration):
active_beam = models.PositiveSmallIntegerField(verbose_name='Active Beam', default=0)
- module_status = models.CharField(verbose_name='Module Status', max_length=10000, default=json.dumps(status_default))
+ module_status = models.CharField(verbose_name='Module Status', max_length=10000, default=status_default)
operation_mode = models.PositiveSmallIntegerField(verbose_name='Operation Mode', choices=OPERATION_MODES, default = 0)
operation_value = models.FloatField(verbose_name='Periodic (seconds)', default="10", null=True, blank=True)
module_messages = models.CharField(verbose_name='Modules Messages', max_length=10000, default=json.dumps(default_messages))
@@ -417,6 +413,9 @@ class ABSConfiguration(Configuration):
self.device.status = 3
self.module_status = ''.join(status)
self.save()
+ for u in User.objects.all():
+ u.profile.abs_active = self
+ u.save()
return True
@@ -494,11 +493,9 @@ class ABSConfiguration(Configuration):
# Create the datagram socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.settimeout(1)
- # sock.bind((local_ip, 10000))
local_ip = os.environ.get('LOCAL_IP', '127.0.0.1')
- local_ip = '192.168.1.128'
sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_IF, socket.inet_aton(local_ip))
- sent = sock.sendto(message, multicast_group)
+ sock.sendto(message, multicast_group)
print('Sending ' + message)
return sock
@@ -517,13 +514,19 @@ class ABSConfiguration(Configuration):
try:
address = None
data, address = sock.recvfrom(1024)
- print address, data
- if data == '1':
- status[int(address[0][10:])-1] = '3'
- elif data == '0':
- status[int(address[0][10:])-1] = '1'
+ x = int(address[0][10:])-1
+ if data[0] == '1':
+ remote = fromChar2Binary(data[1])
+ local = ABSBeam.objects.get(pk=self.active_beam).module_6bits(x)
+ if local == remote:
+ status[x] = '3'
+ print('Module: {} connected...igual'.format(address))
+ else:
+ status[x] = '2'
+ print('Module: {} connected...diferente'.format(address))
+ elif data[0] == '0':
+ status[x] = '1'
n += 1
- print('Module: {} connected'.format(address))
except:
print('Module: {} error'.format(address))
pass
diff --git a/apps/abs/templates/abs_conf.html b/apps/abs/templates/abs_conf.html
index 94d26f5..2362fce 100644
--- a/apps/abs/templates/abs_conf.html
+++ b/apps/abs/templates/abs_conf.html
@@ -34,6 +34,7 @@
.legend td {
padding: 2px;
text-align: center;
+ font-weight: bold;
}
@@ -282,26 +283,19 @@
{% if beam.id == active_beam %}
- Legend |
+ Legend |
-
- RED
- |
- Disconnected |
+ Connected |
-
- ORANGE
- |
- Connected |
+ Running |
-
- GREEN
- |
- Running
- |
+ Mismath |
+
+
+ Disconnected |
{% else %}
diff --git a/apps/abs/views.py b/apps/abs/views.py
index 5f5ca29..87bb72e 100644
--- a/apps/abs/views.py
+++ b/apps/abs/views.py
@@ -6,6 +6,7 @@ from django.conf import settings
from django.http import HttpResponse
from django.core.urlresolvers import reverse
from django.views.decorators.csrf import csrf_exempt
+from django.utils.safestring import mark_safe
from datetime import datetime
from time import sleep
@@ -134,6 +135,9 @@ def abs_conf(request, id_conf):
if status == '3': #Running background-color: #00cc00;
all_status['{}'.format(i+1)] = 2
color_status['{}'.format(i+1)] = 'class=text-success'#'bgcolor=#00cc00'
+ elif status == '2':
+ all_status['{}'.format(i+1)] = 1
+ color_status['{}'.format(i+1)] = 'class=text-info'
elif status == '1': #Connected background-color: #ee902c;
all_status['{}'.format(i+1)] = 1
color_status['{}'.format(i+1)] = 'class=text-warning'#'bgcolor=#ee902c'
@@ -245,8 +249,22 @@ def import_file(request, id_conf):
def send_beam(request, id_conf, id_beam):
conf = get_object_or_404(ABSConfiguration, pk=id_conf)
+
+ abs = request.user.profile.abs_active
+ if abs<>conf:
+ url = '#' if abs is None else abs.get_absolute_url()
+ label = 'None' if abs is None else abs.label
+ messages.warning(
+ request,
+ mark_safe('The current configuration has not been written in the modules, the active configuration is {}'.format(
+ url,
+ label
+ ))
+ )
+ return redirect(conf.get_absolute_url())
+
beam = get_object_or_404(ABSBeam, pk=id_beam)
- beams_list = ABSBeam.objects.filter(abs_conf=conf)
+ beams_list = ABSBeam.objects.filter(abs_conf=conf)
conf.active_beam = id_beam
i = 0
diff --git a/apps/main/fixtures/main_initial_data.json b/apps/main/fixtures/main_initial_data.json
index 547b61b..68021c1 100644
--- a/apps/main/fixtures/main_initial_data.json
+++ b/apps/main/fixtures/main_initial_data.json
@@ -118,5 +118,13 @@
},
"model": "auth.user",
"pk": 1
+ },
+ {
+ "fields": {
+ "user": 1,
+ "theme": "spacelab"
+ },
+ "model": "main.profile",
+ "pk": 1
}
]
\ No newline at end of file
diff --git a/apps/main/models.py b/apps/main/models.py
index 81e16e2..f13cbfd 100644
--- a/apps/main/models.py
+++ b/apps/main/models.py
@@ -88,7 +88,9 @@ CONF_TYPES = (
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
- theme = models.CharField(max_length=30, default='yeti')
+ theme = models.CharField(max_length=30, default='spacelab')
+ abs_active = models.ForeignKey('Configuration', null=True, blank=True, verbose_name='Current ABS')
+
@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
diff --git a/apps/main/views.py b/apps/main/views.py
index ea1395f..09bf64d 100644
--- a/apps/main/views.py
+++ b/apps/main/views.py
@@ -1444,10 +1444,25 @@ def dev_conf_stop(request, id_conf):
return redirect(conf.get_absolute_url())
+@login_required
def dev_conf_status(request, id_conf):
conf = get_object_or_404(Configuration, pk=id_conf)
+ if conf.device.device_type.name == 'abs':
+ abs = request.user.profile.abs_active
+ if abs<>conf:
+ url = '#' if abs is None else abs.get_absolute_url()
+ label = 'None' if abs is None else abs.label
+ messages.warning(
+ request,
+ mark_safe('The current configuration has not been written in the modules, the active configuration is {}'.format(
+ url,
+ label
+ ))
+ )
+ return redirect(conf.get_absolute_url())
+
if conf.status_device():
messages.success(request, conf.message)
else: