@@ -0,0 +1,6 | |||||
|
1 | from django.contrib import admin | |||
|
2 | from .models import ATRADConfiguration | |||
|
3 | ||||
|
4 | # Register your models here. | |||
|
5 | ||||
|
6 | admin.site.register(ATRADConfiguration) |
@@ -0,0 +1,6 | |||||
|
1 | #from django.apps import AppConfig | |||
|
2 | ||||
|
3 | ||||
|
4 | #class AtradConfig(AppConfig):# | |||
|
5 | # default_auto_field = 'django.db.models.BigAutoField' | |||
|
6 | # name = 'atrad' |
@@ -0,0 +1,19 | |||||
|
1 | import json | |||
|
2 | ||||
|
3 | def read_json_file(fp): | |||
|
4 | ||||
|
5 | kwargs = {} | |||
|
6 | ||||
|
7 | json_data = fp | |||
|
8 | data = json.load(json_data) | |||
|
9 | json_data.close() | |||
|
10 | ||||
|
11 | topic = data["topic"][0][1] | |||
|
12 | ||||
|
13 | kwargs['topic'] = topic | |||
|
14 | ||||
|
15 | return kwargs | |||
|
16 | ||||
|
17 | ||||
|
18 | def write_json_file(filename): | |||
|
19 | pass No newline at end of file |
@@ -0,0 +1,27 | |||||
|
1 | from django import forms | |||
|
2 | from apps.main.models import Device | |||
|
3 | from .models import ATRADConfiguration | |||
|
4 | ||||
|
5 | class ATRADConfigurationForm(forms.ModelForm): | |||
|
6 | ||||
|
7 | def __init__(self, *args, **kwargs): | |||
|
8 | super(ATRADConfigurationForm, self).__init__(*args, **kwargs) | |||
|
9 | instance = getattr(self, 'instance', None) | |||
|
10 | ||||
|
11 | if instance and instance.pk: | |||
|
12 | devices = Device.objects.filter(device_type__name='atrad') | |||
|
13 | if instance.experiment: | |||
|
14 | self.fields['experiment'].widget.attrs['disabled'] = 'disabled' | |||
|
15 | self.fields['device'].widget.choices = [(device.id, device) for device in devices] | |||
|
16 | ||||
|
17 | def clean(self): | |||
|
18 | return | |||
|
19 | ||||
|
20 | class Meta: | |||
|
21 | model = ATRADConfiguration | |||
|
22 | exclude = ('type', 'parameters', 'status', 'author', 'hash') | |||
|
23 | ||||
|
24 | ||||
|
25 | class UploadFileForm(forms.Form): | |||
|
26 | title = forms.CharField(label='Extension Type', widget=forms.TextInput(attrs={'readonly':'readonly'})) | |||
|
27 | file = forms.FileField() |
@@ -0,0 +1,175 | |||||
|
1 | from django.db import models | |||
|
2 | from apps.main.models import Configuration | |||
|
3 | from apps.main.utils import Params | |||
|
4 | from django.core.validators import MinValueValidator, MaxValueValidator | |||
|
5 | ||||
|
6 | from .files import read_json_file | |||
|
7 | import requests | |||
|
8 | # Create your models here. validators=[MinValueValidator(62.5e6), MaxValueValidator(450e6)] | |||
|
9 | ||||
|
10 | class ATRADConfiguration(Configuration): | |||
|
11 | ||||
|
12 | topic = models.PositiveIntegerField(verbose_name='Topic',validators=[MaxValueValidator(10)], default = 0) | |||
|
13 | ||||
|
14 | def verify_frequencies(self): | |||
|
15 | ||||
|
16 | return True | |||
|
17 | ||||
|
18 | ||||
|
19 | def status_device(self): | |||
|
20 | ||||
|
21 | ip=self.device.ip_address | |||
|
22 | port=self.device.port_address | |||
|
23 | ||||
|
24 | route = "http://" + str(ip) + ":" + str(port) + "/status/" | |||
|
25 | try: | |||
|
26 | r = requests.get(route, timeout=0.7) | |||
|
27 | except Exception as e: | |||
|
28 | self.device.status = 0 | |||
|
29 | self.device.save() | |||
|
30 | self.message = 'Could not read TX status: ' + str(e) | |||
|
31 | return False | |||
|
32 | ||||
|
33 | response = r.json() | |||
|
34 | self.device.status = response['status'] | |||
|
35 | self.message = response['message'] | |||
|
36 | self.device.save() | |||
|
37 | ||||
|
38 | if response['components_status']==0: | |||
|
39 | return False | |||
|
40 | ||||
|
41 | return True | |||
|
42 | ||||
|
43 | ||||
|
44 | def start_device(self): | |||
|
45 | ||||
|
46 | ip=self.device.ip_address | |||
|
47 | port=self.device.port_address | |||
|
48 | ||||
|
49 | #---Device must be configured | |||
|
50 | if not self.device.status == 2: | |||
|
51 | self.message = 'TX Device must be configured.' | |||
|
52 | return False | |||
|
53 | #---Frequencies from form | |||
|
54 | post_data = self.parms_to_dict() | |||
|
55 | route = "http://" + str(ip) + ":" + str(port) + "/write/" | |||
|
56 | ||||
|
57 | try: | |||
|
58 | r = requests.post(route, post_data, timeout=0.7) | |||
|
59 | except Exception as e: | |||
|
60 | self.message = "Could not start TX device. "+str(e) | |||
|
61 | return False | |||
|
62 | ||||
|
63 | response = r.json() | |||
|
64 | if response['status']==1: | |||
|
65 | self.device.status = 1 | |||
|
66 | self.device.save() | |||
|
67 | self.message = response['message'] | |||
|
68 | return False | |||
|
69 | ||||
|
70 | self.device.status = response['status'] | |||
|
71 | self.device.save() | |||
|
72 | self.message = response['message'] | |||
|
73 | ||||
|
74 | return True | |||
|
75 | ||||
|
76 | ||||
|
77 | def stop_device(self): | |||
|
78 | ||||
|
79 | ip=self.device.ip_address | |||
|
80 | port=self.device.port_address | |||
|
81 | ||||
|
82 | if self.device.status == 2: #Configured | |||
|
83 | self.message = 'TX device is already stopped.' | |||
|
84 | return False | |||
|
85 | ||||
|
86 | post_data = {"topic":0} | |||
|
87 | route = "http://" + str(ip) + ":" + str(port) + "/write/" | |||
|
88 | ||||
|
89 | try: | |||
|
90 | r = requests.post(route, post_data, timeout=0.7) | |||
|
91 | except Exception as e: | |||
|
92 | self.message = "Could not write TX parameters. "+str(e) | |||
|
93 | self.device.status = 0 | |||
|
94 | self.device.save() | |||
|
95 | return False | |||
|
96 | ||||
|
97 | response = r.json() | |||
|
98 | status = response['status'] | |||
|
99 | if status == 1: | |||
|
100 | self.device.status = status | |||
|
101 | self.device.save() | |||
|
102 | self.message = 'Could not stop TX device.' | |||
|
103 | return False | |||
|
104 | ||||
|
105 | self.message = 'TX device has been stopped successfully.' | |||
|
106 | self.device.status = 2 | |||
|
107 | self.device.save() | |||
|
108 | ||||
|
109 | return True | |||
|
110 | ||||
|
111 | ||||
|
112 | def read_device(self): | |||
|
113 | ||||
|
114 | ip=self.device.ip_address | |||
|
115 | port=self.device.port_address | |||
|
116 | ||||
|
117 | route = "http://" + str(ip) + ":" + str(port) + "/read/" | |||
|
118 | try: | |||
|
119 | frequencies = requests.get(route,timeout=0.7) | |||
|
120 | except: | |||
|
121 | self.message = "Could not read TX parameters from this device" | |||
|
122 | return None | |||
|
123 | ||||
|
124 | frequencies = frequencies.json() | |||
|
125 | if frequencies: | |||
|
126 | frequencies = frequencies.get("Frequencies") | |||
|
127 | topic = frequencies.get("topic") | |||
|
128 | ||||
|
129 | parms = {'topic': topic} | |||
|
130 | ||||
|
131 | self.message = "TX parameters have been successfully read" | |||
|
132 | return parms | |||
|
133 | else: | |||
|
134 | self.message = "Error reading TX parameters" | |||
|
135 | return None | |||
|
136 | ||||
|
137 | ||||
|
138 | def write_device(self): | |||
|
139 | ||||
|
140 | ip=self.device.ip_address | |||
|
141 | port=self.device.port_address | |||
|
142 | ||||
|
143 | #---Frequencies from form | |||
|
144 | parms = self.parms_to_dict()['configurations'] | |||
|
145 | for parm in parms['allIds']: | |||
|
146 | byid = parm | |||
|
147 | frequencies = parms['byId'][byid] | |||
|
148 | post_data = {} | |||
|
149 | for data in frequencies: | |||
|
150 | if data in ['topic']: | |||
|
151 | post_data[data] = frequencies[data] | |||
|
152 | ||||
|
153 | route = "http://" + str(ip) + ":" + str(port) + "/write/" | |||
|
154 | print (post_data) | |||
|
155 | try: | |||
|
156 | r = requests.post(route, post_data, timeout=0.7) | |||
|
157 | except: | |||
|
158 | self.message = "Could not write TX parameters" | |||
|
159 | self.device.status = 0 | |||
|
160 | self.device.save() | |||
|
161 | return False | |||
|
162 | ||||
|
163 | response = r.json() | |||
|
164 | self.message = response['message'] | |||
|
165 | self.device.status = response['status'] | |||
|
166 | self.device.save() | |||
|
167 | ||||
|
168 | if self.device.status==1: | |||
|
169 | return False | |||
|
170 | ||||
|
171 | return True | |||
|
172 | ||||
|
173 | ||||
|
174 | class Meta: | |||
|
175 | db_table = 'atrad_configurations' No newline at end of file |
@@ -0,0 +1,38 | |||||
|
1 | import paho.mqtt.client as mqtt | |||
|
2 | from radarsys import settings | |||
|
3 | from radarsys.socketconfig import sio as sio | |||
|
4 | import numpy as np | |||
|
5 | ||||
|
6 | def on_connect(mqtt_client, userdata, flags, rc): | |||
|
7 | if rc == 0: | |||
|
8 | print('Connected successfully') | |||
|
9 | mqtt_client.subscribe('atrad/test3') | |||
|
10 | else: | |||
|
11 | print('Bad connection. Code:', rc) | |||
|
12 | ||||
|
13 | def maxima_temp(trs): | |||
|
14 | np_array = [np.array(i) for i in trs] | |||
|
15 | temps = [max(i[i<40]) for i in np_array] | |||
|
16 | return max(temps) | |||
|
17 | ||||
|
18 | def on_message(mqtt_client, userdata, msg): | |||
|
19 | print(f'Received message on topic: {msg.topic} with payload: {msg.payload}', flush=True) | |||
|
20 | trsi = [[],[],[],[]] | |||
|
21 | mensaje = str(msg.payload) | |||
|
22 | datos = [i for i in mensaje[21:-1].split("*")] | |||
|
23 | status=''.join([datos[i][3] for i in [0,1,2,3]]) | |||
|
24 | for trs,i in zip(datos,[0,1,2,3]) : | |||
|
25 | trsi[i]= [int(i) for i in trs[1:-1].split(",")] | |||
|
26 | potencias = [trsi[0][34],trsi[0][36],trsi[2][32],trsi[2][34]] | |||
|
27 | tmax = maxima_temp(trsi) | |||
|
28 | sio.emit('test', data={'time':mensaje[2:21],'num':trsi[0][0],'pow':potencias,'tmax':str(tmax),'status':status}) | |||
|
29 | ||||
|
30 | client = mqtt.Client() | |||
|
31 | client.on_connect = on_connect | |||
|
32 | client.on_message = on_message | |||
|
33 | client.username_pw_set(settings.MQTT_USER, settings.MQTT_PASSWORD) | |||
|
34 | client.connect( | |||
|
35 | host=settings.MQTT_SERVER, | |||
|
36 | port=settings.MQTT_PORT, | |||
|
37 | keepalive=settings.MQTT_KEEPALIVE | |||
|
38 | ) No newline at end of file |
@@ -0,0 +1,288 | |||||
|
1 | {% extends "dev_conf.html" %} | |||
|
2 | {% block extra-head %} | |||
|
3 | <style> | |||
|
4 | .dot { | |||
|
5 | height: 25px; | |||
|
6 | width: 25px; | |||
|
7 | background-color: #b0b3af; | |||
|
8 | border-radius: 50%; | |||
|
9 | display: inline-block; | |||
|
10 | } | |||
|
11 | </style> | |||
|
12 | {% endblock %} | |||
|
13 | ||||
|
14 | {% block extra-content %} | |||
|
15 | <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script> | |||
|
16 | <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/4.4.1/socket.io.min.js"></script> | |||
|
17 | ||||
|
18 | <div class="container-fluid"> | |||
|
19 | <div class="row"> | |||
|
20 | <div class="col-xs-12"> | |||
|
21 | <h1>Atrad Monitor</h1> | |||
|
22 | </div> | |||
|
23 | </div> | |||
|
24 | ||||
|
25 | <div class="row "> | |||
|
26 | <!-- Potencia --> | |||
|
27 | <div class="col col-xs-12"> | |||
|
28 | <div class="row"> | |||
|
29 | <div class="panel panel-default" style="width:100%;"> | |||
|
30 | <div class="panel-heading"> | |||
|
31 | <h3 class="panel-title">Potencia</h3> | |||
|
32 | </div> | |||
|
33 | <div class="panel-body"> | |||
|
34 | <div class="col-xs-12"> | |||
|
35 | <div class="row"> | |||
|
36 | <div id="plot-pot"></div> | |||
|
37 | </div> | |||
|
38 | </div> | |||
|
39 | </div> | |||
|
40 | <div class="panel-footer"> | |||
|
41 | <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#Pot1">T1</button> | |||
|
42 | <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#Pot2">T2</button> | |||
|
43 | </div> | |||
|
44 | </div> | |||
|
45 | </div> | |||
|
46 | </div> | |||
|
47 | <div class="col col-xs-12"> | |||
|
48 | <div class="panel panel-default"> | |||
|
49 | <div class="panel-heading"> | |||
|
50 | <h3 class="panel-title">Status</h3> | |||
|
51 | </div> | |||
|
52 | <div class="panel-body"> | |||
|
53 | <table class="table table-borderless" style="max-width: 300px;"> | |||
|
54 | <tbody> | |||
|
55 | <tr> | |||
|
56 | <th scope="row">Tx1</th> | |||
|
57 | <td><span id="status1" class="dot"></span></td> | |||
|
58 | <td><p id="status-text1" class="font-weight-bold">Sin envio de datos</p></td> | |||
|
59 | </tr> | |||
|
60 | <tr> | |||
|
61 | <th scope="row">Tx2</th> | |||
|
62 | <td><span id="status2" class="dot"></span></td> | |||
|
63 | <td><p id="status-text2" class="font-weight-bold">Sin envio de datos</p></td> | |||
|
64 | </tr> | |||
|
65 | </tbody> | |||
|
66 | </table> | |||
|
67 | </div> | |||
|
68 | </div> | |||
|
69 | </div> | |||
|
70 | </div> | |||
|
71 | ||||
|
72 | <!-- Temperatura --> | |||
|
73 | <div class="row"> | |||
|
74 | <div class="col-xs-12"> | |||
|
75 | <div class="panel panel-default"> | |||
|
76 | <div class="panel-heading"> | |||
|
77 | <h3 class="panel-title">Temperatura</h3> | |||
|
78 | </div> | |||
|
79 | <div class="panel-body"> | |||
|
80 | <div class="col-xs-12"> | |||
|
81 | <div class="row"> | |||
|
82 | <div id="plot-temp"></div> | |||
|
83 | </div> | |||
|
84 | </div> | |||
|
85 | </div> | |||
|
86 | </div> | |||
|
87 | </div> | |||
|
88 | </div> | |||
|
89 | ||||
|
90 | <div class="row"> | |||
|
91 | <!-- Controles --> | |||
|
92 | <div class="col-xs-6"> | |||
|
93 | <div class="panel panel-default"> | |||
|
94 | <div class="panel-heading"> | |||
|
95 | <h3 class="panel-title">Control</h3> | |||
|
96 | </div> | |||
|
97 | <div class="panel-body"> | |||
|
98 | <div class="col-xs-12"> | |||
|
99 | <div class="form-row"> | |||
|
100 | <div class="form-group col-xs-6"> | |||
|
101 | <form id="controlON" method="POST" action=''> | |||
|
102 | <button type="summit" class="btn btn-secondary btn-lg">Prender</button> | |||
|
103 | </form> | |||
|
104 | </div> | |||
|
105 | <div class="form-group col-xs-6"> | |||
|
106 | <form id="controlOFF" method="POST" action=''> | |||
|
107 | <button type="summit" class="btn btn-secondary btn-lg">Apagar</button> | |||
|
108 | </form> | |||
|
109 | </div> | |||
|
110 | </div> | |||
|
111 | </div> | |||
|
112 | </div> | |||
|
113 | </div> | |||
|
114 | </div> | |||
|
115 | ||||
|
116 | <div class="col-xs-6"> | |||
|
117 | <div class="panel panel-default"> | |||
|
118 | <div class="panel-heading"> | |||
|
119 | </div> | |||
|
120 | </div> | |||
|
121 | </div> | |||
|
122 | </div> | |||
|
123 | </div> | |||
|
124 | ||||
|
125 | <!--Modales--> | |||
|
126 | <div class="modal fade" id="Pot1" role="dialog"> | |||
|
127 | <div class="modal-dialog modal-md" style="min-width:760px"> | |||
|
128 | <div class="modal-content"> | |||
|
129 | <div class="modal-header"> | |||
|
130 | <h4 class="modal-title">Potencia incidente - Transmisor 1</h4> | |||
|
131 | <button type="button" class="close" data-dismiss="modal">×</button> | |||
|
132 | </div> | |||
|
133 | <div class="modal-body"> | |||
|
134 | <div class="col-xs-12"> | |||
|
135 | <div id="plot-pot-t1"></div> | |||
|
136 | </div> | |||
|
137 | <div clas="col-xs-12"> | |||
|
138 | <table class="table table-borderless"> | |||
|
139 | <tbody> | |||
|
140 | <tr> | |||
|
141 | <th scope="row">P1</th> | |||
|
142 | <td>e</td> | |||
|
143 | <td>e</td> | |||
|
144 | </tr> | |||
|
145 | <tr> | |||
|
146 | <th scope="row">P2</th> | |||
|
147 | <td>e</td> | |||
|
148 | <td>e</td> | |||
|
149 | </tr> | |||
|
150 | <tr> | |||
|
151 | <th scope="row">P3</th> | |||
|
152 | <td>e</td> | |||
|
153 | <td>e</td> | |||
|
154 | </tr> | |||
|
155 | <tr> | |||
|
156 | <th scope="row">P4</th> | |||
|
157 | <td>e</td> | |||
|
158 | <td>e</td> | |||
|
159 | </tr> | |||
|
160 | </tbody> | |||
|
161 | </table> | |||
|
162 | </div> | |||
|
163 | </div> | |||
|
164 | </div> | |||
|
165 | </div> | |||
|
166 | </div> | |||
|
167 | ||||
|
168 | <div class="modal fade" id="Pot2" role="dialog"> | |||
|
169 | <div class="modal-dialog modal-md" style="min-width:760px"> | |||
|
170 | <div class="modal-content"> | |||
|
171 | <div class="modal-header"> | |||
|
172 | <h4 class="modal-title">Potencia incidente - Transmisor 2</h4> | |||
|
173 | <button type="button" class="close" data-dismiss="modal">×</button> | |||
|
174 | </div> | |||
|
175 | <div class="modal-body"> | |||
|
176 | <div class="col-xs-12"> | |||
|
177 | <div id="plot-pot-t2"></div> | |||
|
178 | </div> | |||
|
179 | </div> | |||
|
180 | </div> | |||
|
181 | </div> | |||
|
182 | </div> | |||
|
183 | ||||
|
184 | <script type="text/javascript" charset="utf-8"> | |||
|
185 | $(document).ready(function() { | |||
|
186 | var socket = io.connect('http://' + document.domain + ':' + location.port); | |||
|
187 | ||||
|
188 | socket.on('connect', function(data) { | |||
|
189 | console.log('Connecting... OK'); | |||
|
190 | makePlot("plot-temp",2,["T1","T2"],[14, 45]) | |||
|
191 | makePlot("plot-pot",2,["T1","T2"],[70,100]) | |||
|
192 | makePlot("plot-pot-t1",4,["P1","P2","P3","P4"],[0,26]) | |||
|
193 | makePlot("plot-pot-t2",4,["P1","P2","P3","P4"],[0,26]) | |||
|
194 | }) | |||
|
195 | ||||
|
196 | socket.on('test', function(data) { | |||
|
197 | let total = data.pow.reduce((a, b) => a + b, 0); | |||
|
198 | var id = (data.num/4)>>0; | |||
|
199 | streamPlot("plot-pot",data.time,total/1000.0,id,81); | |||
|
200 | streamPlot("plot-temp",data.time,data.tmax,id>>0,40); | |||
|
201 | if(id == 0){streamPlot2("plot-pot-t1",data.time,data.pow);ligthStatus('status1','status-text1',data.status);} | |||
|
202 | if(id == 1){streamPlot2("plot-pot-t2",data.time,data.pow);ligthStatus('status2','status-text2',data.status);} | |||
|
203 | }) | |||
|
204 | $('form#controlON').submit(function(event) { | |||
|
205 | socket.emit('control_event', {data: 1}); | |||
|
206 | return false; | |||
|
207 | }); | |||
|
208 | $('form#controlOFF').submit(function(event) { | |||
|
209 | socket.emit('control_event', {data: 0}); | |||
|
210 | return false; | |||
|
211 | }); | |||
|
212 | $("#btn1").click(function(){ | |||
|
213 | $("#box").animate({height: "300px"}); | |||
|
214 | }); | |||
|
215 | $("#btn2").click(function(){ | |||
|
216 | $("#box").animate({height: "100px"}); | |||
|
217 | }); | |||
|
218 | }); | |||
|
219 | ||||
|
220 | function makePlot(div, n=1, names=["", ""],ranges){ | |||
|
221 | var plotDiv = document.getElementById(div); | |||
|
222 | var traces = []; | |||
|
223 | for (let i = 0; i < n; i++) { | |||
|
224 | traces.push({x: [], y: [],mode: 'lines', name: names[i]}); | |||
|
225 | } | |||
|
226 | traces.push({x: [], y: [],mode: 'lines',line: {color:'rgb(219, 64, 82)',dash: 'dot',width: 2},name:"nominal",showlegend: false}); | |||
|
227 | var yrange = ranges; | |||
|
228 | var layout = { | |||
|
229 | height: 350, | |||
|
230 | font: {size: 12}, | |||
|
231 | margin: { t: 10, b:50}, | |||
|
232 | xaxis: { | |||
|
233 | type: 'date' | |||
|
234 | }, | |||
|
235 | yaxis: { | |||
|
236 | range: yrange, | |||
|
237 | }, | |||
|
238 | }; | |||
|
239 | ||||
|
240 | Plotly.plot(plotDiv, traces, layout); | |||
|
241 | }; | |||
|
242 | ||||
|
243 | function streamPlot(div,x,y,ind,val){ | |||
|
244 | var plotDiv = document.getElementById(div); | |||
|
245 | if (plotDiv.data[ind].x.length > 8){ | |||
|
246 | plotDiv.data[2].x = plotDiv.data[2].x.slice(-23) | |||
|
247 | plotDiv.data[2].y = plotDiv.data[2].y.slice(-23) | |||
|
248 | plotDiv.data[ind].x = plotDiv.data[ind].x.slice(-11) | |||
|
249 | plotDiv.data[ind].y = plotDiv.data[ind].y.slice(-11) | |||
|
250 | } | |||
|
251 | var tm = [x]; | |||
|
252 | var values = [y]; | |||
|
253 | var data_update = {x: [tm,tm], y: [values,[val]]} | |||
|
254 | Plotly.extendTraces(plotDiv, data_update,[ind,2]) | |||
|
255 | }; | |||
|
256 | function streamPlot2(div,x,y){ | |||
|
257 | var plotDiv = document.getElementById(div); | |||
|
258 | if (plotDiv.data[0].x.length > 8){ | |||
|
259 | for(let i=0;i<4;i++){ | |||
|
260 | plotDiv.data[i].x = plotDiv.data[i].x.slice(-11) | |||
|
261 | plotDiv.data[i].y = plotDiv.data[i].y.slice(-11) | |||
|
262 | } | |||
|
263 | } | |||
|
264 | var tm = [x]; | |||
|
265 | var values = []; | |||
|
266 | for(let i=0;i<4;i++){ | |||
|
267 | values[i]=[y[i]/1000.0]; | |||
|
268 | } | |||
|
269 | var data_update = {x: [tm,tm,tm,tm], y: values} | |||
|
270 | Plotly.extendTraces(plotDiv, data_update,[0,1,2,3]) | |||
|
271 | }; | |||
|
272 | function ligthStatus(div1,div2,status){ | |||
|
273 | if(status==='0000'){ | |||
|
274 | document.getElementById(div1).style.backgroundColor = "green"; | |||
|
275 | document.getElementById(div2).innerHTML = "Desabilitado"; | |||
|
276 | } | |||
|
277 | else if(status==='1111'){ | |||
|
278 | document.getElementById(div1).style.backgroundColor = "green"; | |||
|
279 | document.getElementById(div2).innerHTML = "Habilitado"; | |||
|
280 | } | |||
|
281 | else{ | |||
|
282 | document.getElementById(div1).style.backgroundColor = "yellow"; | |||
|
283 | document.getElementById(div2).innerHTML = "Incompleto"; | |||
|
284 | } | |||
|
285 | } | |||
|
286 | ||||
|
287 | </script> | |||
|
288 | {% endblock %} No newline at end of file |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 |
@@ -0,0 +1,7 | |||||
|
1 | {% extends "dev_conf_edit.html" %} | |||
|
2 | {% load django_bootstrap5 %} | |||
|
3 | {% load static %} | |||
|
4 | {% load main_tags %} | |||
|
5 | ||||
|
6 | {% block extra-js%} | |||
|
7 | {% endblock %} No newline at end of file |
@@ -0,0 +1,15 | |||||
|
1 | {% extends "base.html" %} | |||
|
2 | {% block mainactive %}active{% endblock %} | |||
|
3 | ||||
|
4 | {% block content-title %}TITLE{% endblock %} | |||
|
5 | {% block content-suptitle %}Suptitle{% endblock %} | |||
|
6 | ||||
|
7 | {% block content %} | |||
|
8 | <p class="text-justify"> | |||
|
9 | {% lorem %} | |||
|
10 | </p> | |||
|
11 | {% endblock %} | |||
|
12 | ||||
|
13 | {% block sidebar%} | |||
|
14 | ||||
|
15 | {% endblock %} |
@@ -0,0 +1,46 | |||||
|
1 | {% extends "base.html" %} | |||
|
2 | {% load django_bootstrap5 %} | |||
|
3 | {% block mainactive %}active{% endblock %} | |||
|
4 | ||||
|
5 | {% block content-title %}DEVICE CGS{% endblock %} | |||
|
6 | {% block content-suptitle %}CLOCK GENERATOR AND SYNCHRONIZER{% endblock %} | |||
|
7 | ||||
|
8 | {% block content %} | |||
|
9 | <p class="text-justify"> | |||
|
10 | Ingresar Frecuencias | |||
|
11 | </p> | |||
|
12 | ||||
|
13 | ||||
|
14 | ||||
|
15 | <!-- Agregado 30-11-2015 --> | |||
|
16 | {% if form.is_multipart %} | |||
|
17 | ||||
|
18 | <script type="text/javascript"> | |||
|
19 | ||||
|
20 | </script> | |||
|
21 | ||||
|
22 | <form id="{{ idform }}" enctype="multipart/form-data" method="{{ submit_method|default:'post' }}" action="" class="form"> | |||
|
23 | {% else %} | |||
|
24 | <form method="{{ submit_method|default:'post' }}" action="" class="form"> | |||
|
25 | {% endif %} | |||
|
26 | ||||
|
27 | {% if step_field %} | |||
|
28 | <input type="hidden" name="{{ step_field }}" value="{{ step0 }}" /> | |||
|
29 | {% endif %} | |||
|
30 | ||||
|
31 | {% if submit_method != 'GET' and submit_method != 'get' %} | |||
|
32 | {% csrf_token %} | |||
|
33 | {% endif %} | |||
|
34 | <!-- Agregado 30-11-2015 --> | |||
|
35 | ||||
|
36 | ||||
|
37 | ||||
|
38 | <div class='col-md-8'> | |||
|
39 | {% bootstrap_form form size='md' %} | |||
|
40 | <button type="submit" class="btn btn-primary pull-right">Submit</button> | |||
|
41 | </div> | |||
|
42 | {% endblock %} | |||
|
43 | ||||
|
44 | {% block sidebar%} | |||
|
45 | ||||
|
46 | {% endblock %} No newline at end of file |
@@ -0,0 +1,8 | |||||
|
1 | from django.urls import path | |||
|
2 | ||||
|
3 | from . import views | |||
|
4 | ||||
|
5 | urlpatterns = ( | |||
|
6 | path('<int:id_conf>/', views.atrad_conf, name='url_atrad_conf'), | |||
|
7 | path('<int:id_conf>/edit/', views.atrad_conf_edit, name='url_edit_atrad_conf'), | |||
|
8 | ) No newline at end of file |
@@ -0,0 +1,108 | |||||
|
1 | from django.shortcuts import redirect, render, get_object_or_404 | |||
|
2 | from django.contrib import messages | |||
|
3 | from django.http import HttpResponse | |||
|
4 | ||||
|
5 | from apps.main.models import Experiment | |||
|
6 | from .models import ATRADConfiguration | |||
|
7 | ||||
|
8 | from .forms import ATRADConfigurationForm, UploadFileForm | |||
|
9 | from apps.main.views import sidebar | |||
|
10 | ||||
|
11 | import requests | |||
|
12 | import json | |||
|
13 | ||||
|
14 | import os | |||
|
15 | from django.http import JsonResponse | |||
|
16 | from .mqtt import client as mqtt_client | |||
|
17 | from radarsys.socketconfig import sio as sio | |||
|
18 | ||||
|
19 | ||||
|
20 | def atrad_conf(request, id_conf): | |||
|
21 | ||||
|
22 | conf = get_object_or_404(ATRADConfiguration, pk=id_conf) | |||
|
23 | ||||
|
24 | ip=conf.device.ip_address | |||
|
25 | port=conf.device.port_address | |||
|
26 | ||||
|
27 | kwargs = {} | |||
|
28 | ||||
|
29 | kwargs['status'] = conf.device.get_status_display() | |||
|
30 | ||||
|
31 | kwargs['dev_conf'] = conf | |||
|
32 | kwargs['dev_conf_keys'] = ['label', | |||
|
33 | 'topic'] | |||
|
34 | ||||
|
35 | kwargs['title'] = 'ATRAD Configuration' | |||
|
36 | kwargs['suptitle'] = 'Details' | |||
|
37 | ||||
|
38 | kwargs['button'] = 'Edit Configuration' | |||
|
39 | ||||
|
40 | #kwargs['no_play'] = True | |||
|
41 | ||||
|
42 | ###### SIDEBAR ###### | |||
|
43 | kwargs.update(sidebar(conf=conf)) | |||
|
44 | ||||
|
45 | return render(request, 'atrad_conf.html', kwargs) | |||
|
46 | ||||
|
47 | def atrad_conf_edit(request, id_conf): | |||
|
48 | ||||
|
49 | conf = get_object_or_404(ATRADConfiguration, pk=id_conf) | |||
|
50 | ||||
|
51 | if request.method=='GET': | |||
|
52 | form = ATRADConfigurationForm(instance=conf) | |||
|
53 | ||||
|
54 | if request.method=='POST': | |||
|
55 | form = ATRADConfigurationForm(request.POST, instance=conf) | |||
|
56 | ||||
|
57 | if form.is_valid(): | |||
|
58 | if conf.topic == None: conf.topic = 0 | |||
|
59 | ||||
|
60 | conf = form.save(commit=False) | |||
|
61 | ||||
|
62 | if conf.verify_frequencies(): | |||
|
63 | conf.save() | |||
|
64 | return redirect('url_atrad_conf', id_conf=conf.id) | |||
|
65 | ||||
|
66 | kwargs = {} | |||
|
67 | kwargs['id_dev'] = conf.id | |||
|
68 | kwargs['form'] = form | |||
|
69 | kwargs['title'] = 'Device Configuration' | |||
|
70 | kwargs['suptitle'] = 'Edit' | |||
|
71 | kwargs['button'] = 'Save' | |||
|
72 | ||||
|
73 | return render(request, 'atrad_conf_edit.html', kwargs) | |||
|
74 | ||||
|
75 | import os | |||
|
76 | from django.http import HttpResponse# | |||
|
77 | ||||
|
78 | def publish_message(request): | |||
|
79 | rc, mid = mqtt_client.publish('test/data2',1) | |||
|
80 | return JsonResponse({'code1': 'HIKA', 'code2': 'LUCAS'}) | |||
|
81 | ||||
|
82 | def monitor(request): | |||
|
83 | kwargs = {'no_sidebar': True} | |||
|
84 | return render(request, 'monitor.html', kwargs) | |||
|
85 | ||||
|
86 | def prueba(request): | |||
|
87 | kwargs = {'no_sidebar': True} | |||
|
88 | return render(request, 'prueba.html', kwargs) | |||
|
89 | ||||
|
90 | @sio.on('connection-bind') | |||
|
91 | def connection_bind(sid, data): | |||
|
92 | print("sid:",sid,"data",data) | |||
|
93 | ||||
|
94 | @sio.on('disconnect') | |||
|
95 | def test_disconnect(sid): | |||
|
96 | print("Disconnected") | |||
|
97 | ||||
|
98 | @sio.event | |||
|
99 | def control_event(sid,message): | |||
|
100 | mqtt_client.publish('test/data2',message['data']) | |||
|
101 | ||||
|
102 | def hello(data): | |||
|
103 | try: | |||
|
104 | rc, mid = mqtt_client.publish('test/data2', 'Hello') | |||
|
105 | sio.emit('test', data={'topic':mid, 'status': 'Not Running'}) | |||
|
106 | except: | |||
|
107 | print('ERROR', flush=True) | |||
|
108 | return HttpResponse("Hello") No newline at end of file |
@@ -0,0 +1,6 | |||||
|
1 | import os | |||
|
2 | import socketio | |||
|
3 | async_mode = None | |||
|
4 | ||||
|
5 | basedir = os.path.dirname(os.path.realpath(__file__)) | |||
|
6 | sio = socketio.Server(async_mode='eventlet') No newline at end of file |
@@ -94,6 +94,14 | |||||
94 | }, |
|
94 | }, | |
95 | "model": "main.devicetype", |
|
95 | "model": "main.devicetype", | |
96 | "pk": 6 |
|
96 | "pk": 6 | |
|
97 | }, | |||
|
98 | { | |||
|
99 | "fields": { | |||
|
100 | "name": "atrad", | |||
|
101 | "description": "" | |||
|
102 | }, | |||
|
103 | "model": "main.devicetype", | |||
|
104 | "pk": 7 | |||
97 | }, |
|
105 | }, | |
98 | { |
|
106 | { | |
99 | "fields": { |
|
107 | "fields": { |
@@ -73,6 +73,7 DEV_TYPES = ( | |||||
73 | ('cgs', 'Clock Generator System'), |
|
73 | ('cgs', 'Clock Generator System'), | |
74 | ('abs', 'Automatic Beam Switching'), |
|
74 | ('abs', 'Automatic Beam Switching'), | |
75 | ('dds_rest', 'Direct Digital Synthesizer_REST'), |
|
75 | ('dds_rest', 'Direct Digital Synthesizer_REST'), | |
|
76 | ('atrad', 'Transmitter ATRAD'), | |||
76 | ) |
|
77 | ) | |
77 |
|
78 | |||
78 | EXP_STATES = ( |
|
79 | EXP_STATES = ( |
@@ -30,6 +30,7 from apps.cgs.forms import CGSConfigurationForm | |||||
30 | from apps.abs.forms import ABSConfigurationForm |
|
30 | from apps.abs.forms import ABSConfigurationForm | |
31 | from apps.usrp.forms import USRPConfigurationForm |
|
31 | from apps.usrp.forms import USRPConfigurationForm | |
32 | from apps.dds_rest.forms import DDSRestConfigurationForm |
|
32 | from apps.dds_rest.forms import DDSRestConfigurationForm | |
|
33 | from apps.atrad.forms import ATRADConfigurationForm | |||
33 | from .utils import Params |
|
34 | from .utils import Params | |
34 |
|
35 | |||
35 | from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment, DEV_STATES |
|
36 | from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment, DEV_STATES | |
@@ -40,6 +41,7 from apps.abs.models import ABSConfiguration | |||||
40 | from apps.rc.models import RCConfiguration, RCLine, RCLineType, RCClock |
|
41 | from apps.rc.models import RCConfiguration, RCLine, RCLineType, RCClock | |
41 | from apps.dds.models import DDSConfiguration |
|
42 | from apps.dds.models import DDSConfiguration | |
42 | from apps.dds_rest.models import DDSRestConfiguration |
|
43 | from apps.dds_rest.models import DDSRestConfiguration | |
|
44 | from apps.atrad.models import ATRADConfiguration | |||
43 |
|
45 | |||
44 | #from .tasks import task_start |
|
46 | #from .tasks import task_start | |
45 | from radarsys.celery import app |
|
47 | from radarsys.celery import app | |
@@ -53,6 +55,7 CONF_FORMS = { | |||||
53 | 'cgs': CGSConfigurationForm, |
|
55 | 'cgs': CGSConfigurationForm, | |
54 | 'abs': ABSConfigurationForm, |
|
56 | 'abs': ABSConfigurationForm, | |
55 | 'usrp': USRPConfigurationForm, |
|
57 | 'usrp': USRPConfigurationForm, | |
|
58 | 'atrad': ATRADConfigurationForm, | |||
56 | } |
|
59 | } | |
57 |
|
60 | |||
58 | CONF_MODELS = { |
|
61 | CONF_MODELS = { | |
@@ -63,6 +66,7 CONF_MODELS = { | |||||
63 | 'cgs': CGSConfiguration, |
|
66 | 'cgs': CGSConfiguration, | |
64 | 'abs': ABSConfiguration, |
|
67 | 'abs': ABSConfiguration, | |
65 | 'usrp': USRPConfiguration, |
|
68 | 'usrp': USRPConfiguration, | |
|
69 | 'atrad': ATRADConfiguration, | |||
66 | } |
|
70 | } | |
67 |
|
71 | |||
68 | MIX_MODES = { |
|
72 | MIX_MODES = { |
@@ -52,12 +52,12 services: | |||||
52 | env_file: .env |
|
52 | env_file: .env | |
53 |
|
53 | |||
54 | #Web Server |
|
54 | #Web Server | |
55 | nginx: |
|
55 | radarsys-nginx: | |
56 | container_name: 'radarsys-nginx' |
|
56 | container_name: 'radarsys-nginx' | |
57 | restart: always |
|
57 | restart: always | |
58 | build: ./nginx/ |
|
58 | build: ./nginx/ | |
59 | ports: |
|
59 | ports: | |
60 |
- ' |
|
60 | - '0.0.0.0:80:80' | |
61 | volumes_from: |
|
61 | volumes_from: | |
62 | - radarsys |
|
62 | - radarsys | |
63 | links: |
|
63 | links: |
@@ -8,5 +8,5 python3 manage.py collectstatic --no-input | |||||
8 |
|
8 | |||
9 | #DJANGO_SUPERUSER_PASSWORD=$SUPER_USER_PASSWORD python manage.py createsuperuser --username $SUPER_USER_NAME --email $SUPER_USER_EMAIL --noinput |
|
9 | #DJANGO_SUPERUSER_PASSWORD=$SUPER_USER_PASSWORD python manage.py createsuperuser --username $SUPER_USER_NAME --email $SUPER_USER_EMAIL --noinput | |
10 |
|
10 | |||
11 |
gunicorn radarsys.wsgi:application - |
|
11 | gunicorn -k eventlet radarsys.wsgi:application --bind 0.0.0.0:8000 | |
12 | No newline at end of file |
|
12 |
@@ -1,20 +1,28 | |||||
|
1 | upstream django { | |||
|
2 | server radarsys:8000; | |||
|
3 | } | |||
|
4 | ||||
1 | server { |
|
5 | server { | |
2 |
|
6 | |||
3 |
listen 80 |
|
7 | listen 80; | |
4 | server_name localhost; |
|
8 | server_name localhost; | |
5 |
|
9 | |||
6 | access_log /dev/stdout; |
|
10 | #access_log /dev/stdout; | |
7 | error_log /dev/stdout info; |
|
11 | #error_log /dev/stdout info; | |
8 |
|
12 | |||
9 | location /static { |
|
13 | location /static { | |
10 | alias /radarsys/static; |
|
14 | alias /radarsys/static; | |
11 | } |
|
15 | } | |
12 |
|
16 | |||
13 | location / { |
|
17 | location / { | |
14 | proxy_set_header Host "localhost"; |
|
18 | proxy_pass http://django; | |
15 | proxy_pass http://radarsys:8000; |
|
19 | proxy_set_header X-Real-IP $remote_addr; | |
16 | # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
|
20 | proxy_set_header Host $host; | |
17 |
|
21 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
|
22 | proxy_set_header X-Forwarded-Proto $scheme; | |||
|
23 | proxy_http_version 1.1; | |||
|
24 | proxy_set_header Upgrade $http_upgrade; | |||
|
25 | proxy_set_header Connection "upgrade"; | |||
18 | } |
|
26 | } | |
19 |
|
27 | |||
20 | } |
|
28 | } No newline at end of file |
@@ -52,9 +52,10 INSTALLED_APPS = [ | |||||
52 | 'apps.abs', |
|
52 | 'apps.abs', | |
53 | 'apps.cgs', |
|
53 | 'apps.cgs', | |
54 | 'apps.dds_rest', |
|
54 | 'apps.dds_rest', | |
|
55 | 'apps.atrad', | |||
55 | "django_bootstrap5", |
|
56 | "django_bootstrap5", | |
56 | 'polymorphic', |
|
57 | 'polymorphic', | |
57 |
' |
|
58 | 'radarsys', | |
58 | ] |
|
59 | ] | |
59 |
|
60 | |||
60 | MIDDLEWARE = [ |
|
61 | MIDDLEWARE = [ | |
@@ -168,3 +169,9 django.utils.encoding.force_text = force_str | |||||
168 |
|
169 | |||
169 | # choose of auto-created primary keys |
|
170 | # choose of auto-created primary keys | |
170 | DEFAULT_AUTO_FIELD='django.db.models.AutoField' |
|
171 | DEFAULT_AUTO_FIELD='django.db.models.AutoField' | |
|
172 | ||||
|
173 | MQTT_SERVER = '10.10.10.99' | |||
|
174 | MQTT_PORT = 1883 | |||
|
175 | MQTT_KEEPALIVE = 60 | |||
|
176 | MQTT_USER = '' | |||
|
177 | MQTT_PASSWORD = '' No newline at end of file |
@@ -14,7 +14,7 urlpatterns = [ | |||||
14 | path('abs/', include('apps.abs.urls')), |
|
14 | path('abs/', include('apps.abs.urls')), | |
15 | path('misc/',include('apps.misc.urls')), |
|
15 | path('misc/',include('apps.misc.urls')), | |
16 | path('dds_rest/', include('apps.dds_rest.urls')), |
|
16 | path('dds_rest/', include('apps.dds_rest.urls')), | |
17 |
|
17 | path('atrad/', include('apps.atrad.urls')), | ||
18 | ] |
|
18 | ] | |
19 |
|
19 | |||
20 | #urlpatterns += staticfiles_urlpatterns() |
|
20 | #urlpatterns += staticfiles_urlpatterns() |
@@ -10,7 +10,10 https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/ | |||||
10 | import os |
|
10 | import os | |
11 |
|
11 | |||
12 | from django.core.wsgi import get_wsgi_application |
|
12 | from django.core.wsgi import get_wsgi_application | |
|
13 | from .socketconfig import sio | |||
|
14 | import socketio | |||
13 |
|
15 | |||
14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "radarsys.settings") |
|
16 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "radarsys.settings") | |
15 |
|
17 | |||
16 | application = get_wsgi_application() |
|
18 | application = get_wsgi_application() | |
|
19 | application = socketio.WSGIApp(sio, application) |
@@ -10,5 +10,9 celery==5.2.7 | |||||
10 | gunicorn==20.1.0 |
|
10 | gunicorn==20.1.0 | |
11 | requests==2.28.2 |
|
11 | requests==2.28.2 | |
12 | redis==4.4.2 |
|
12 | redis==4.4.2 | |
13 | channels==4.0.0 |
|
13 | ||
14 | daphne==4.0.0 No newline at end of file |
|
14 | paho-mqtt==1.6.1 | |
|
15 | ||||
|
16 | eventlet==0.30.2 | |||
|
17 | python-engineio | |||
|
18 | python-socketio No newline at end of file |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now