##// END OF EJS Templates
README superscript fix
README superscript fix

File last commit:

r360:46316742ce9f
r363:cbaf0ec08021
Show More
models.py
296 lines | 9.6 KiB | text/x-python | PythonLexer
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 import ast
Juan C. Espinoza
Updates to models, views & forms for CR...
r25 import json
Juan C. Espinoza
Improve RC pulses plot and Operation view...
r175 import requests
Primer commit radarsys_met
r345 import base64
Limpieza de código y funcionalidades usrp
r346 import struct
Juan C. Espinoza
Update RC model, RC api for testing...
r185 from struct import pack
Limpieza de código y funcionalidades usrp
r346 import time
from django.contrib import messages
Juan C. Espinoza
Proyecto base en Django (refs #259) ...
r0 from django.db import models
Nueva plantilla, prueba comunicacion y nuevos campos ddsrest
r335 from django.urls import reverse
Juan C. Espinoza
Add rc config mods...
r23 from django.core.validators import MinValueValidator, MaxValueValidator
Juan C. Espinoza
Updating base models and views ...
r6 from apps.main.models import Configuration
Juan C. Espinoza
- Update rc app...
r79
Primer commit radarsys_met
r345 AXIS_VALUE = (
New experiment views
r360 ('azimuth', 'PPI'),
('elevation', 'RHI')
Primer commit radarsys_met
r345 )
Juan C. Espinoza
Updating base models and views ...
r6
Limpieza de código y funcionalidades usrp
r346 class PedestalConfiguration(Configuration):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Primer commit radarsys_met
r345 axis = models.CharField(
verbose_name='Axis',
New experiment views
r360 max_length=10,
Primer commit radarsys_met
r345 choices=AXIS_VALUE,
null=False,
blank=False
)
speed = models.FloatField(
verbose_name='Speed',
validators=[MinValueValidator(-20), MaxValueValidator(20)],
blank=False,
null=False
)
table = models.CharField(
verbose_name="Table",
max_length=100,
default='',
blank=False,
Pedestal comma bug fixed, help text added and more
r352 null=False,
help_text="Please separate the values with commas"
Primer commit radarsys_met
r345 )
Juan C. Espinoza
Updating base models and views ...
r6
class Meta:
Primer commit radarsys_met
r345 db_table = 'pedestal_configurations'
def __str__(self):
Clean code and docker files
r349 return str(self.label)
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Juan C. Espinoza
- Update rc app...
r79 def get_absolute_url_plot(self):
Primer commit radarsys_met
r345 return reverse('url_plot_pedestal_pulses', args=[str(self.id)])
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Fiorella Quino
RC files have been updated...
r264 def request(self, cmd, method='get', **kwargs):
req = getattr(requests, method)(self.device.url(cmd), **kwargs)
payload = req.json()
return payload
Juan C. Espinoza
Improve RC pulses plot and Operation view...
r175 def status_device(self):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Juan C. Espinoza
Update RC API methods...
r222 try:
Generator parameter type fixed, devices status & warning messages
r350 #self.device.status = 0
#payload = self.request('status')
payload = requests.get(self.device.url())
print(payload)
if payload:
self.device.status = 1
Fiorella Quino
RC files have been updated...
r264 elif payload['status']=='disable':
Juan C. Espinoza
Update RC API methods...
r222 self.device.status = 2
Juan C. Espinoza
Update RC model, RC api for testing...
r185 else:
Fiorella Quino
import/export functions have been updated...
r243 self.device.status = 1
Juan C. Espinoza
Update RC API methods...
r222 self.device.save()
Limpieza de código y funcionalidades usrp
r346 self.message = 'Pedestal status: {}'.format(payload['status'])
Juan C. Espinoza
Update RC API methods...
r222 return False
Juan C. Espinoza
Update RC model, RC api for testing...
r185 except Exception as e:
Juan C. Espinoza
Update RC API methods...
r222 if 'No route to host' not in str(e):
self.device.status = 4
self.device.save()
Limpieza de código y funcionalidades usrp
r346 self.message = 'Pedestal status: {}'.format(str(e))
Juan C. Espinoza
Update RC model, RC api for testing...
r185 return False
Fiorella Quino
import/export functions have been updated...
r243
self.device.save()
return True
Juan C. Espinoza
Improve RC pulses plot and Operation view...
r175
def reset_device(self):
Fiorella Quino
import/export functions have been updated...
r243
Juan C. Espinoza
Update RC model, RC api for testing...
r185 try:
Fiorella Quino
RC files have been updated...
r264 payload = self.request('reset', 'post')
Juan C. Espinoza
Update RC API methods...
r222 if payload['reset']=='ok':
Limpieza de código y funcionalidades usrp
r346 self.message = 'Pedestal restarted OK'
Fiorella Quino
RC files have been updated...
r264 self.device.status = 2
self.device.save()
Juan C. Espinoza
Update RC model, RC api for testing...
r185 else:
Limpieza de código y funcionalidades usrp
r346 self.message = 'Pedestal restart fail'
Juan C. Espinoza
Update RC model, RC api for testing...
r185 self.device.status = 4
self.device.save()
except Exception as e:
Limpieza de código y funcionalidades usrp
r346 self.message = 'Pedestal reset: {}'.format(str(e))
Juan C. Espinoza
Update RC model, RC api for testing...
r185 return False
Fiorella Quino
import/export functions have been updated...
r243
Juan C. Espinoza
Update RC model, RC api for testing...
r185 return True
Fiorella Quino
import/export functions have been updated...
r243
Juan C. Espinoza
Improve RC pulses plot and Operation view...
r175 def stop_device(self):
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Juan C. Espinoza
Update RC model, RC api for testing...
r185 try:
Limpieza de código y funcionalidades usrp
r346 command = self.device.url() + "stop"
r = requests.get(command)
if r:
self.device.status = 4
Juan C. Espinoza
Update RC model, RC api for testing...
r185 self.device.save()
Limpieza de código y funcionalidades usrp
r346 self.message = 'Pedestal stopped'
Juan C. Espinoza
Update RC model, RC api for testing...
r185 else:
self.device.status = 4
self.device.save()
return False
except Exception as e:
Juan C. Espinoza
Update RC API methods...
r222 if 'No route to host' not in str(e):
self.device.status = 4
else:
self.device.status = 0
Generator parameter type fixed, devices status & warning messages
r350 #self.message = 'Pedestal stop: {}'.format(str(e))
self.message = "Pedestal can't start, please check network/device connection or IP address/port configuration"
Juan C. Espinoza
Update RC API methods...
r222 self.device.save()
Fiorella Quino
import/export functions have been updated...
r243 return False
Juan C. Espinoza
Update RC model, RC api for testing...
r185 return True
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Juan C. Espinoza
Update RC app (add support for mix configurations, bug plotting window line, )...
r107 def start_device(self):
Generator parameter type fixed, devices status & warning messages
r350
Juan C. Espinoza
Update RC model, RC api for testing...
r185 try:
Limpieza de código y funcionalidades usrp
r346 pedestal = PedestalConfiguration.objects.get(pk=self)
Pulse generator & USRP_Tx devices added
r348 print(pedestal)
New experiment views
r360 #pedestal_axis = pedestal.get_axis_display()
Primer commit radarsys_met
r345 print(pedestal)
New experiment views
r360 #print(pedestal_axis)
Primer commit radarsys_met
r345 table = pedestal.table
print(table)
Pedestal comma bug fixed, help text added and more
r352 li = list(table.split(","))
Limpieza de código y funcionalidades usrp
r346 print(li)
list_of_floats = []
for item in li:
list_of_floats.append(float(item))
print(list_of_floats)
byte_table = []
for x in list_of_floats:
temp = bytearray(struct.pack("f", x))
byte_table.append(temp[3])
byte_table.append(temp[2])
byte_table.append(temp[1])
byte_table.append(temp[0])
print(byte_table)
changed base64.urlsafe to base64.standard
r357 coded_table = base64.standard_b64encode(bytes(byte_table))
Limpieza de código y funcionalidades usrp
r346 coded_table_ascii = coded_table.decode('ascii')
print(coded_table_ascii)
New experiment views
r360 data = {'axis': pedestal.axis, 'speed': pedestal.speed, 'table': coded_table_ascii}
Primer commit radarsys_met
r345 print(data)
Limpieza de código y funcionalidades usrp
r346 json_data = json.dumps(data)
print(json_data)
first_position = table[0]
New experiment views
r360 if pedestal.axis=='PPI':
Limpieza de código y funcionalidades usrp
r346 json_az = json.dumps({"axis": 'azimuth', "position": 0.0})
json_el = json.dumps({"axis": 'elevation', "position": first_position})
else:
json_az = json.dumps({"axis": 'azimuth', "position": first_position})
json_el = json.dumps({"axis": 'elevation', "position": 0.0})
changed base64.urlsafe to base64.standard
r357 base64_table = base64.standard_b64encode(json_data.encode('ascii'))
base64_az = base64.standard_b64encode(json_az.encode('ascii'))
base64_el = base64.standard_b64encode(json_el.encode('ascii'))
Limpieza de código y funcionalidades usrp
r346
table_url = self.device.url() + "table?params="
az_url = self.device.url() + "position?params="
el_url = self.device.url() + "position?params="
complete_url = table_url + base64_table.decode('ascii')
az_url = az_url + base64_az.decode('ascii')
el_url = el_url + base64_el.decode('ascii')
print(complete_url)
print(az_url)
print(el_url)
r = requests.get(az_url)
r = requests.get(el_url)
#time.sleep(10)
r = requests.get(complete_url)
if r:
Juan C. Espinoza
Update RC model, RC api for testing...
r185 self.device.status = 3
self.device.save()
Limpieza de código y funcionalidades usrp
r346 self.message = 'Pedestal configured and started'
Juan C. Espinoza
Update RC model, RC api for testing...
r185 else:
return False
except Exception as e:
Juan C. Espinoza
Update RC API methods...
r222 if 'No route to host' not in str(e):
self.device.status = 4
else:
self.device.status = 0
Generator parameter type fixed, devices status & warning messages
r350 #self.message = 'Pedestal start: {}'.format(str(e))
self.message = "Pedestal can't start, please check network/device connection or IP address/port configuration"
Juan C. Espinoza
Update RC API methods...
r222 self.device.save()
Juan C. Espinoza
Update RC model, RC api for testing...
r185 return False
Fiorella Quino
import/export functions have been updated...
r243
Juan C. Espinoza
Update RC model, RC api for testing...
r185 return True
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Limpieza de código y funcionalidades usrp
r346 #def write_device(self, raw=False):
SIR with docker-compose working
r299
Juan C. Espinoza
Add compatibility with embed CGS in RC
r328 if not raw:
clock = RCClock.objects.get(rc_configuration=self)
Primer commit radarsys_met
r345 print(clock)
Juan C. Espinoza
Add compatibility with embed CGS in RC
r328 if clock.mode:
data = {'default': clock.frequency}
else:
data = {'manual': [clock.multiplier, clock.divisor, clock.reference]}
payload = self.request('setfreq', 'post', data=json.dumps(data))
Primer commit radarsys_met
r345 print(payload)
Nueva plantilla, prueba comunicacion y nuevos campos ddsrest
r335 if payload['command'] != 'ok':
Limpieza de código y funcionalidades usrp
r346 self.message = 'Pedestal write: {}'.format(payload['command'])
Juan C. Espinoza
Add compatibility with embed CGS in RC
r328 else:
self.message = payload['programming']
if payload['programming'] == 'fail':
Limpieza de código y funcionalidades usrp
r346 self.message = 'Pedestal write: error programming CGS chip'
Juan C. Espinoza
Add compatibility with embed CGS in RC
r328
SIR with docker-compose working
r299 values = []
for pulse, delay in zip(self.get_pulses(), self.get_delays()):
Fix extra delays in RC when delay is bigger than 65536 (16bits)
r302 while delay>65536:
SIR with docker-compose working
r299 values.append((pulse, 65535))
Fix extra delays in RC when delay is bigger than 65536 (16bits)
r302 delay -= 65536
SIR with docker-compose working
r299 values.append((pulse, delay-1))
Juan C. Espinoza
Update RC control methods, add change_ip for RC, fix win_reference for sub-baudio...
r236 data = bytearray()
Fiorella Quino
import/export functions have been updated...
r243 #reset
data.extend((128, 0))
#disable
Juan C. Espinoza
Update RC control methods, add change_ip for RC, fix win_reference for sub-baudio...
r236 data.extend((129, 0))
Add control_sw value in write_device RC
r304 #SW switch
if self.control_sw:
data.extend((130, 2))
else:
data.extend((130, 0))
Fiorella Quino
import/export functions have been updated...
r243 #divider
data.extend((131, self.clock_divider-1))
Juan C. Espinoza
Update RC control methods, add change_ip for RC, fix win_reference for sub-baudio...
r236 #enable writing
data.extend((139, 62))
Fiorella Quino
import/export functions have been updated...
r243
Juan C. Espinoza
Update RC control methods, add change_ip for RC, fix win_reference for sub-baudio...
r236 last = 0
Fiorella Quino
import/export functions have been updated...
r243 for tup in values:
vals = pack('<HH', last^tup[0], tup[1])
Juan C. Espinoza
Update RC control methods, add change_ip for RC, fix win_reference for sub-baudio...
r236 last = tup[0]
Fiorella Quino
import/export functions have been updated...
r243 data.extend((133, vals[1], 132, vals[0], 133, vals[3], 132, vals[2]))
Juan C. Espinoza
Update RC control methods, add change_ip for RC, fix win_reference for sub-baudio...
r236 #enable
data.extend((129, 1))
Fiorella Quino
import/export functions have been updated...
r243
Juan C. Espinoza
Update Views y several improvements
r316 if raw:
return b64encode(data)
Juan C. Espinoza
Update RC model, RC api for testing...
r185 try:
SIR with docker-compose working
r299 payload = self.request('stop', 'post')
payload = self.request('reset', 'post')
#payload = self.request('divider', 'post', data={'divider': self.clock_divider-1})
#payload = self.request('write', 'post', data=b64encode(bytearray((139, 62))), timeout=20)
n = len(data)
x = 0
#while x < n:
Fiorella Quino
RC files have been updated...
r264 payload = self.request('write', 'post', data=b64encode(data))
SIR with docker-compose working
r299 # x += 1024
Juan C. Espinoza
Update RC API methods...
r222 if payload['write']=='ok':
Fiorella Quino
RC files have been updated...
r264 self.device.status = 3
Juan C. Espinoza
Update RC model, RC api for testing...
r185 self.device.save()
Limpieza de código y funcionalidades usrp
r346 self.message = 'Pedestal configured and started'
Juan C. Espinoza
Update RC model, RC api for testing...
r185 else:
Juan C. Espinoza
Update RC control methods, add change_ip for RC, fix win_reference for sub-baudio...
r236 self.device.status = 1
Juan C. Espinoza
Update RC model, RC api for testing...
r185 self.device.save()
Limpieza de código y funcionalidades usrp
r346 self.message = 'Pedestal write: {}'.format(payload['write'])
Juan C. Espinoza
Update RC model, RC api for testing...
r185 return False
Fiorella Quino
import/export functions have been updated...
r243
SIR with docker-compose working
r299 #payload = self.request('start', 'post')
Juan C. Espinoza
Update RC model, RC api for testing...
r185 except Exception as e:
Juan C. Espinoza
Update RC API methods...
r222 if 'No route to host' not in str(e):
self.device.status = 4
else:
self.device.status = 0
Limpieza de código y funcionalidades usrp
r346 self.message = 'Pedestal write: {}'.format(str(e))
Juan C. Espinoza
Update RC API methods...
r222 self.device.save()
Juan C. Espinoza
Update RC model, RC api for testing...
r185 return False
Fiorella Quino
import/export functions have been updated...
r243
Juan C. Espinoza
Update RC model, RC api for testing...
r185 return True
Juan C. Espinoza
Update code for django 1.10, python 3 and latest third party packages, review operation view ...
r172
Juan C. Espinoza
Update RC app (add support for mix configurations, bug plotting window line, )...
r107
Fiorella Quino
RC files have been updated...
r264 def get_absolute_url_import(self):
Clean code and docker files
r349 return reverse('url_import_pedestal_conf', args=[str(self.id)])