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