##// END OF EJS Templates
Task #714: Modulo Web ABS...
Task #714: Modulo Web ABS git-svn-id: http://jro-dev.igp.gob.pe/svn/jro_hard/radarsys/trunk/webapp@205 aa17d016-51d5-4e8b-934c-7b2bbb1bbe71

File last commit:

r172:a641bec15a9b
r182:7e17a44bea6b
Show More
models.py
229 lines | 7.5 KiB | text/x-python | PythonLexer
Juan C. Espinoza
Proyecto base en Django (refs #259) ...
r0 from django.db import models
Juan C. Espinoza
Updating base models and views ...
r6 from apps.main.models import Configuration
Juan C. Espinoza
Proyecto base en Django (refs #259) ...
r0 # Create your models here.
Juan C. Espinoza
Updating base models and views ...
r6
Miguel Urco
DDS model added...
r12 from django.core.validators import MinValueValidator, MaxValueValidator
Miguel Urco
git-svn-id: http://jro-dev.igp.gob.pe/svn/jro_hard/radarsys/trunk/webapp@44 aa17d016-51d5-4e8b-934c-7b2bbb1bbe71
r26 from django.core.exceptions import ValidationError
Miguel Urco
DDS model added...
r12
Miguel Urco
DDS commands working...
r57 from devices.dds import api, data
Miguel Urco
DDS app updated...
r32
Miguel Urco
DDS model updated...
r55 ENABLE_TYPE = (
(False, 'Disabled'),
(True, 'Enabled'),
)
Miguel Urco
Campaign has been added to RadarSys Model...
r13 MOD_TYPES = (
Miguel Urco
DDS model updated...
r55 (0, 'Single Tone'),
(1, 'FSK'),
(2, 'Ramped FSK'),
(3, 'Chirp'),
(4, 'BPSK'),
)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Juan C. Espinoza
Updating base models and views ...
r6 class DDSConfiguration(Configuration):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
git-svn-id: http://jro-dev.igp.gob.pe/svn/jro_hard/radarsys/trunk/webapp@44 aa17d016-51d5-4e8b-934c-7b2bbb1bbe71
r26 DDS_NBITS = 48
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
git-svn-id: http://jro-dev.igp.gob.pe/svn/jro_hard/radarsys/trunk/webapp@166 aa17d016-51d5-4e8b-934c-7b2bbb1bbe71
r145 clock = models.FloatField(verbose_name='Clock In (MHz)',validators=[MinValueValidator(5), MaxValueValidator(75)], null=True, default=60)
Miguel Urco
Campaign has been added to RadarSys Model...
r13 multiplier = models.PositiveIntegerField(verbose_name='Multiplier',validators=[MinValueValidator(1), MaxValueValidator(20)], default=4)
Miguel Urco
git-svn-id: http://jro-dev.igp.gob.pe/svn/jro_hard/radarsys/trunk/webapp@44 aa17d016-51d5-4e8b-934c-7b2bbb1bbe71
r26
Fiorella Quino
DDS models: default values...
r97 frequencyA_Mhz = models.DecimalField(verbose_name='Frequency A (MHz)', validators=[MinValueValidator(0), MaxValueValidator(150)], max_digits=19, decimal_places=16, null=True, default=49.9200)
frequencyA = models.BigIntegerField(verbose_name='Frequency A (Decimal)',validators=[MinValueValidator(0), MaxValueValidator(2**DDS_NBITS-1)], blank=True, null=True)
Miguel Urco
DDS model updated...
r55
frequencyB_Mhz = models.DecimalField(verbose_name='Frequency B (MHz)', validators=[MinValueValidator(0), MaxValueValidator(150)], max_digits=19, decimal_places=16, blank=True, null=True)
frequencyB = models.BigIntegerField(verbose_name='Frequency B (Decimal)',validators=[MinValueValidator(0), MaxValueValidator(2**DDS_NBITS-1)], blank=True, null=True)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 phaseA_degrees = models.FloatField(verbose_name='Phase A (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)], default=0)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS commands working...
r57 phaseB_degrees = models.FloatField(verbose_name='Phase B (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)], blank=True, null=True)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
Buttons "Import", "Export, "Read" and "Write" added to Configuration View...
r30 modulation = models.PositiveIntegerField(verbose_name='Modulation Type', choices = MOD_TYPES, default = 0)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 amplitude_enabled = models.BooleanField(verbose_name='Amplitude Control', choices=ENABLE_TYPE, default=False)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 amplitudeI = models.PositiveIntegerField(verbose_name='Amplitude CH1',validators=[MinValueValidator(0), MaxValueValidator(2**12-1)], blank=True, null=True)
amplitudeQ = models.PositiveIntegerField(verbose_name='Amplitude CH2',validators=[MinValueValidator(0), MaxValueValidator(2**12-1)], blank=True, null=True)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
git-svn-id: http://jro-dev.igp.gob.pe/svn/jro_hard/radarsys/trunk/webapp@44 aa17d016-51d5-4e8b-934c-7b2bbb1bbe71
r26 def get_nbits(self):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
git-svn-id: http://jro-dev.igp.gob.pe/svn/jro_hard/radarsys/trunk/webapp@44 aa17d016-51d5-4e8b-934c-7b2bbb1bbe71
r26 return self.DDS_NBITS
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
git-svn-id: http://jro-dev.igp.gob.pe/svn/jro_hard/radarsys/trunk/webapp@44 aa17d016-51d5-4e8b-934c-7b2bbb1bbe71
r26 def clean(self):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
git-svn-id: http://jro-dev.igp.gob.pe/svn/jro_hard/radarsys/trunk/webapp@44 aa17d016-51d5-4e8b-934c-7b2bbb1bbe71
r26 if self.modulation in [1,2,3]:
Miguel Urco
DDS model updated...
r55 if self.frequencyB is None or self.frequencyB_Mhz is None:
Miguel Urco
git-svn-id: http://jro-dev.igp.gob.pe/svn/jro_hard/radarsys/trunk/webapp@44 aa17d016-51d5-4e8b-934c-7b2bbb1bbe71
r26 raise ValidationError({
Miguel Urco
DDS model updated...
r55 'frequencyB': 'Frequency modulation has to be defined when FSK or Chirp modulation is selected'
Miguel Urco
git-svn-id: http://jro-dev.igp.gob.pe/svn/jro_hard/radarsys/trunk/webapp@44 aa17d016-51d5-4e8b-934c-7b2bbb1bbe71
r26 })
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
git-svn-id: http://jro-dev.igp.gob.pe/svn/jro_hard/radarsys/trunk/webapp@44 aa17d016-51d5-4e8b-934c-7b2bbb1bbe71
r26 if self.modulation in [4,]:
Miguel Urco
DDS model updated...
r55 if self.phaseB_degrees is None:
Miguel Urco
git-svn-id: http://jro-dev.igp.gob.pe/svn/jro_hard/radarsys/trunk/webapp@44 aa17d016-51d5-4e8b-934c-7b2bbb1bbe71
r26 raise ValidationError({
Miguel Urco
DDS model updated...
r55 'phaseB': 'Phase modulation has to be defined when BPSK modulation is selected'
Miguel Urco
git-svn-id: http://jro-dev.igp.gob.pe/svn/jro_hard/radarsys/trunk/webapp@44 aa17d016-51d5-4e8b-934c-7b2bbb1bbe71
r26 })
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS commands working...
r57 self.frequencyA_Mhz = data.binary_to_freq(self.frequencyA, self.clock*self.multiplier)
self.frequencyB_Mhz = data.binary_to_freq(self.frequencyB, self.clock*self.multiplier)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
git-svn-id: http://jro-dev.igp.gob.pe/svn/jro_hard/radarsys/trunk/webapp@44 aa17d016-51d5-4e8b-934c-7b2bbb1bbe71
r26 def verify_frequencies(self):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
git-svn-id: http://jro-dev.igp.gob.pe/svn/jro_hard/radarsys/trunk/webapp@44 aa17d016-51d5-4e8b-934c-7b2bbb1bbe71
r26 return True
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 def parms_to_dict(self):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 parameters = {}
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
Import Experiment Function...
r108 parameters['device_id'] = self.device.id
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 parameters['clock'] = float(self.clock)
parameters['multiplier'] = int(self.multiplier)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 parameters['frequencyA'] = int(self.frequencyA)
Miguel Urco
DDS commands working...
r57 parameters['frequencyA_Mhz'] = float(self.frequencyA_Mhz)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 parameters['phaseA'] = data.phase_to_binary(self.phaseA_degrees)
parameters['phaseA_degrees'] = float(self.phaseA_degrees)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 parameters['modulation'] = int(self.modulation)
Miguel Urco
DDS commands working...
r57 parameters['amplitude_enabled'] = bool(self.amplitude_enabled)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS commands working...
r57 if self.frequencyB:
parameters['frequencyB'] = int(self.frequencyB)
parameters['frequencyB_Mhz'] = float(self.frequencyB_Mhz)
else:
parameters['frequencyB'] = 0
parameters['frequencyB_Mhz'] = 0
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS commands working...
r57 if self.phaseB_degrees:
parameters['phaseB_degrees'] = float(self.phaseB_degrees)
parameters['phaseB'] = data.phase_to_binary(self.phaseB_degrees)
else:
parameters['phaseB_degrees'] = 0
parameters['phaseB'] = 0
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 if self.amplitudeI:
parameters['amplitudeI'] = int(self.amplitudeI)
else:
parameters['amplitudeI'] = 0
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 if self.amplitudeQ:
parameters['amplitudeQ'] = int(self.amplitudeQ)
else:
parameters['amplitudeQ'] = 0
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 return parameters
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS commands working...
r57 def parms_to_text(self):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS commands working...
r57 my_dict = self.parms_to_dict()
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS commands working...
r57 text = data.dict_to_text(my_dict)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS commands working...
r57 return text
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 def dict_to_parms(self, parameters):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 self.clock = parameters['clock']
self.multiplier = parameters['multiplier']
self.frequencyA = parameters['frequencyA']
self.frequencyB = parameters['frequencyB']
self.frequencyA_Mhz = parameters['frequencyA_Mhz']
self.frequencyB_Mhz = parameters['frequencyB_Mhz']
self.phaseA_degrees = parameters['phaseA_degrees']
self.phaseB_degrees = parameters['phaseB_degrees']
self.modulation = parameters['modulation']
self.amplitude_enabled = parameters['amplitude_enabled']
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 def import_from_file(self, fp):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS commands working...
r57 import os, json
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 parms = {}
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS commands working...
r57 path, ext = os.path.splitext(fp.name)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 if ext == '.json':
Miguel Urco
DDS commands working...
r57 parms = json.load(fp)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 if ext == '.dds':
Miguel Urco
DDS commands working...
r57 lines = fp.readlines()
parms = data.text_to_dict(lines)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 return parms
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 def status_device(self):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 answer = api.status(ip = self.device.ip_address,
port = self.device.port_address)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 self.device.status = int(answer[0])
self.message = answer[2:]
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 self.device.save()
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 return self.device.status
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 def reset_device(self):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 answer = api.reset(ip = self.device.ip_address,
port = self.device.port_address)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 if answer[0] != "1":
self.message = answer[0:]
return 0
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 self.message = answer[2:]
return 1
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 def stop_device(self):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 answer = api.disable_rf(ip = self.device.ip_address,
port = self.device.port_address)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 if answer[0] != "1":
self.message = answer[0:]
return 0
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 self.message = answer[2:]
return 1
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 def start_device(self):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 answer = api.enable_rf(ip = self.device.ip_address,
port = self.device.port_address)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 if answer[0] != "1":
self.message = answer[0:]
return 0
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 self.message = answer[2:]
return 1
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 def read_device(self):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 parms = api.read_config(ip = self.device.ip_address,
port = self.device.port_address)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 if not parms:
self.message = "Could not read DDS parameters from this device"
return parms
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 self.message = ""
return parms
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 def write_device(self):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 answer = api.write_config(ip = self.device.ip_address,
port = self.device.port_address,
parms = self.parms_to_dict())
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 if answer[0] != "1":
self.message = answer[0:]
return 0
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Miguel Urco
DDS model updated...
r55 self.message = answer[2:]
return 1
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Juan C. Espinoza
Updating base models and views ...
r6 class Meta:
db_table = 'dds_configurations'