##// END OF EJS Templates
Actualización de readme
Actualización de readme

File last commit:

r346:ba295fe54b17
r347:b4bde5f869b0
Show More
models.py
290 lines | 9.2 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
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 import numpy as np
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 = (
('AZI', 'azimuth'),
('ELE', 'elevation')
)
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',
max_length=3,
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,
null=False
)
Juan C. Espinoza
Updating base models and views ...
r6
class Meta:
Primer commit radarsys_met
r345 db_table = 'pedestal_configurations'
def __str__(self):
return 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:
self.device.status = 0
Fiorella Quino
RC files have been updated...
r264 payload = self.request('status')
if payload['status']=='enable':
Juan C. Espinoza
Update RC control methods, add change_ip for RC, fix win_reference for sub-baudio...
r236 self.device.status = 3
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
Limpieza de código y funcionalidades usrp
r346 self.message = 'Pedestal stop: {}'.format(str(e))
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):
Primer commit radarsys_met
r345 print("Entró al start")
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)
Primer commit radarsys_met
r345 pedestal_axis = pedestal.get_axis_display()
print(pedestal)
print(pedestal_axis)
table = pedestal.table
print(table)
Limpieza de código y funcionalidades usrp
r346 li = list(table.split(", "))
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)
coded_table = base64.urlsafe_b64encode(bytes(byte_table))
coded_table_ascii = coded_table.decode('ascii')
print(coded_table_ascii)
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]
if pedestal.axis=='azimuth':
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})
base64_table = base64.urlsafe_b64encode(json_data.encode('ascii'))
base64_az = base64.urlsafe_b64encode(json_az.encode('ascii'))
base64_el = base64.urlsafe_b64encode(json_el.encode('ascii'))
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
Limpieza de código y funcionalidades usrp
r346 self.message = 'Pedestal start: {}'.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
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):
Limpieza de código y funcionalidades usrp
r346 return reverse('url_import_pedestal_conf', args=[str(self.id)])