@@ -2,7 +2,8 from django.db import models | |||||
2 | from apps.main.models import Configuration |
|
2 | from apps.main.models import Configuration | |
3 | from django.core.urlresolvers import reverse |
|
3 | from django.core.urlresolvers import reverse | |
4 | # Create your models here. |
|
4 | # Create your models here. | |
5 |
|
5 | from celery.execute import send_task | ||
|
6 | from datetime import datetime | |||
6 | import ast |
|
7 | import ast | |
7 | import socket |
|
8 | import socket | |
8 | import json |
|
9 | import json | |
@@ -189,7 +190,7 class ABSConfiguration(Configuration): | |||||
189 | operation_mode = models.PositiveSmallIntegerField(verbose_name='Operation Mode', choices=OPERATION_MODES, default = 0) |
|
190 | operation_mode = models.PositiveSmallIntegerField(verbose_name='Operation Mode', choices=OPERATION_MODES, default = 0) | |
190 | operation_value = models.FloatField(verbose_name='Periodic (seconds)', default="10", null=True, blank=True) |
|
191 | operation_value = models.FloatField(verbose_name='Periodic (seconds)', default="10", null=True, blank=True) | |
191 | module_messages = models.CharField(verbose_name='Modules Messages', max_length=10000, default=json.dumps(default_messages)) |
|
192 | module_messages = models.CharField(verbose_name='Modules Messages', max_length=10000, default=json.dumps(default_messages)) | |
192 |
|
193 | |||
193 | class Meta: |
|
194 | class Meta: | |
194 | db_table = 'abs_configurations' |
|
195 | db_table = 'abs_configurations' | |
195 |
|
196 | |||
@@ -297,13 +298,48 class ABSConfiguration(Configuration): | |||||
297 | active_beam = json.loads(self.active_beam) |
|
298 | active_beam = json.loads(self.active_beam) | |
298 | new_beams = ABSBeam.objects.filter(abs_conf=self) |
|
299 | new_beams = ABSBeam.objects.filter(abs_conf=self) | |
299 | active_beam['active_beam'] = new_beams[0].id |
|
300 | active_beam['active_beam'] = new_beams[0].id | |
|
301 | ||||
300 | self.active_beam = json.dumps(active_beam) |
|
302 | self.active_beam = json.dumps(active_beam) | |
301 | self.save() |
|
303 | self.save() | |
302 | #-----For Active Beam----- |
|
304 | #-----For Active Beam----- | |
|
305 | #-----For Device Status--- | |||
|
306 | self.device.status = 3 | |||
|
307 | self.device.save() | |||
|
308 | #-----For Device Status--- | |||
303 |
|
309 | |||
304 | return self |
|
310 | return self | |
305 |
|
311 | |||
306 |
|
312 | |||
|
313 | def start_device(self): | |||
|
314 | ||||
|
315 | if self.device.status == 3: | |||
|
316 | ||||
|
317 | try: | |||
|
318 | #self.write_device() | |||
|
319 | send_task('task_change_beam', [self.id],) | |||
|
320 | self.message = 'ABS running' | |||
|
321 | ||||
|
322 | except Exception as e: | |||
|
323 | self.message = str(e) | |||
|
324 | return False | |||
|
325 | ||||
|
326 | return True | |||
|
327 | ||||
|
328 | else: | |||
|
329 | self.message = 'Please, select Write ABS Device first.' | |||
|
330 | return False | |||
|
331 | ||||
|
332 | ||||
|
333 | def stop_device(self): | |||
|
334 | ||||
|
335 | self.device.status = 2 | |||
|
336 | self.device.save() | |||
|
337 | self.message = 'ABS has been stopped.' | |||
|
338 | self.save() | |||
|
339 | ||||
|
340 | return True | |||
|
341 | ||||
|
342 | ||||
307 | def module_conf(self, module_num, beams): |
|
343 | def module_conf(self, module_num, beams): | |
308 | """ |
|
344 | """ | |
309 | This function creates beam configurations for one abs module. |
|
345 | This function creates beam configurations for one abs module. | |
@@ -347,7 +383,7 class ABSConfiguration(Configuration): | |||||
347 |
|
383 | |||
348 |
|
384 | |||
349 | def write_device(self): |
|
385 | def write_device(self): | |
350 |
|
386 | |||
351 | """ |
|
387 | """ | |
352 | This function sends the beams list to every abs module. |
|
388 | This function sends the beams list to every abs module. | |
353 | It needs 'module_conf' function |
|
389 | It needs 'module_conf' function | |
@@ -356,7 +392,7 class ABSConfiguration(Configuration): | |||||
356 | beams = ABSBeam.objects.filter(abs_conf=self) |
|
392 | beams = ABSBeam.objects.filter(abs_conf=self) | |
357 | connected_modules = ast.literal_eval(self.module_status) |
|
393 | connected_modules = ast.literal_eval(self.module_status) | |
358 | suma_connected_modules = 0 |
|
394 | suma_connected_modules = 0 | |
359 |
|
395 | |||
360 | for c in connected_modules: |
|
396 | for c in connected_modules: | |
361 | suma_connected_modules = suma_connected_modules+connected_modules[c] |
|
397 | suma_connected_modules = suma_connected_modules+connected_modules[c] | |
362 | if not suma_connected_modules > 0 : |
|
398 | if not suma_connected_modules > 0 : | |
@@ -382,7 +418,7 class ABSConfiguration(Configuration): | |||||
382 | pass |
|
418 | pass | |
383 | else: |
|
419 | else: | |
384 | disconnected_modules += 1 |
|
420 | disconnected_modules += 1 | |
385 |
|
421 | |||
386 | else: |
|
422 | else: | |
387 | self.message = "ABS Configuration does not have beams" |
|
423 | self.message = "ABS Configuration does not have beams" | |
388 | return False |
|
424 | return False | |
@@ -392,15 +428,17 class ABSConfiguration(Configuration): | |||||
392 | #-------------Jueves------------- |
|
428 | #-------------Jueves------------- | |
393 | if disconnected_modules == 64: |
|
429 | if disconnected_modules == 64: | |
394 | self.message = "Could not write ABS Modules" |
|
430 | self.message = "Could not write ABS Modules" | |
|
431 | self.device.status = 0 | |||
395 | return False |
|
432 | return False | |
396 | else: |
|
433 | else: | |
397 | self.message = "ABS Beams List have been sent to ABS Modules" |
|
434 | self.message = "ABS Beams List have been sent to ABS Modules" | |
398 | beams[0].set_as_activebeam() |
|
435 | beams[0].set_as_activebeam() | |
399 |
|
436 | |||
|
437 | self.device.status = 3 | |||
400 | self.module_status = json.dumps(beams_status) |
|
438 | self.module_status = json.dumps(beams_status) | |
401 | self.save() |
|
|||
402 |
|
439 | |||
403 |
|
440 | |||
|
441 | ||||
404 | self.save() |
|
442 | self.save() | |
405 | return True |
|
443 | return True | |
406 |
|
444 |
@@ -6,19 +6,7 import json | |||||
6 | from datetime import timedelta, datetime |
|
6 | from datetime import timedelta, datetime | |
7 | from celery.task import task |
|
7 | from celery.task import task | |
8 |
|
8 | |||
9 | """ |
|
9 | @task(name='task_change_beam') | |
10 | @task |
|
|||
11 | def beam_task(id_conf): |
|
|||
12 |
|
||||
13 | abs_conf = Configuration.objects.get(pk=id_conf) |
|
|||
14 |
|
||||
15 | task_change_beam(abs_conf.pk) |
|
|||
16 |
|
||||
17 | return task_change_beam(abs_conf.pk) |
|
|||
18 |
|
||||
19 | """ |
|
|||
20 |
|
||||
21 | @task |
|
|||
22 | def task_change_beam(id_conf): |
|
10 | def task_change_beam(id_conf): | |
23 |
|
11 | |||
24 | abs_conf = Configuration.objects.get(pk=id_conf) |
|
12 | abs_conf = Configuration.objects.get(pk=id_conf) | |
@@ -29,6 +17,9 def task_change_beam(id_conf): | |||||
29 | now = datetime.utcnow() |
|
17 | now = datetime.utcnow() | |
30 | date = now + run_every |
|
18 | date = now + run_every | |
31 |
|
19 | |||
|
20 | if abs_conf.device.status != 3: | |||
|
21 | return abs_conf.device.status | |||
|
22 | ||||
32 | if abs_conf.operation_mode == 0: #Manual Mode |
|
23 | if abs_conf.operation_mode == 0: #Manual Mode | |
33 | return 1 |
|
24 | return 1 | |
34 |
|
25 | |||
@@ -51,7 +42,7 def task_change_beam(id_conf): | |||||
51 | abs_conf.send_beam_num(1) |
|
42 | abs_conf.send_beam_num(1) | |
52 | beams_list[0].set_as_activebeam() |
|
43 | beams_list[0].set_as_activebeam() | |
53 | task = task_change_beam.apply_async((abs_conf.pk,), eta=date) |
|
44 | task = task_change_beam.apply_async((abs_conf.pk,), eta=date) | |
54 |
print |
|
45 | print beams_list[0] | |
55 | i=0 |
|
46 | i=0 | |
56 |
|
47 | |||
57 | else: |
|
48 | else: |
@@ -10,7 +10,7 from datetime import datetime | |||||
10 | from time import sleep |
|
10 | from time import sleep | |
11 | import os |
|
11 | import os | |
12 |
|
12 | |||
13 | from apps.main.models import Device, Configuration |
|
13 | from apps.main.models import Device, Configuration, Experiment | |
14 | from apps.main.views import sidebar |
|
14 | from apps.main.views import sidebar | |
15 |
|
15 | |||
16 | from .models import ABSConfiguration, ABSBeam |
|
16 | from .models import ABSConfiguration, ABSBeam | |
@@ -149,7 +149,7 def abs_conf(request, id_conf): | |||||
149 |
|
149 | |||
150 | kwargs['title'] = 'ABS Configuration' |
|
150 | kwargs['title'] = 'ABS Configuration' | |
151 | kwargs['suptitle'] = 'Details' |
|
151 | kwargs['suptitle'] = 'Details' | |
152 | kwargs['no_play'] = True |
|
152 | #kwargs['no_play'] = True | |
153 |
|
153 | |||
154 | kwargs['button'] = 'Edit Configuration' |
|
154 | kwargs['button'] = 'Edit Configuration' | |
155 | #------------------Active Beam----------------------- |
|
155 | #------------------Active Beam----------------------- | |
@@ -169,7 +169,7 def abs_conf(request, id_conf): | |||||
169 | kwargs['color_status'] = color_status |
|
169 | kwargs['color_status'] = color_status | |
170 | kwargs['module_messages'] = module_messages |
|
170 | kwargs['module_messages'] = module_messages | |
171 |
|
171 | |||
172 | kwargs['only_stop'] = True |
|
172 | #kwargs['only_stop'] = True | |
173 |
|
173 | |||
174 | ###### SIDEBAR ###### |
|
174 | ###### SIDEBAR ###### | |
175 | kwargs.update(sidebar(conf=conf)) |
|
175 | kwargs.update(sidebar(conf=conf)) |
General Comments 0
You need to be logged in to leave comments.
Login now