@@ -1,1004 +1,1004 | |||
|
1 | 1 | from django.db import models |
|
2 | 2 | from apps.main.models import Configuration , User |
|
3 | 3 | from django.urls import reverse |
|
4 | 4 | from celery.execute import send_task |
|
5 | 5 | from datetime import datetime |
|
6 | 6 | import ast |
|
7 | 7 | import socket |
|
8 | 8 | import json |
|
9 | 9 | import requests |
|
10 | 10 | import struct |
|
11 | 11 | import os, sys, time |
|
12 | 12 | |
|
13 | 13 | antenna_default = json.dumps({ |
|
14 | 14 | "antenna_up": [[0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
15 | 15 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
16 | 16 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
17 | 17 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
18 | 18 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0], |
|
19 | 19 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0], |
|
20 | 20 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0], |
|
21 | 21 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0] |
|
22 | 22 | ] |
|
23 | 23 | , |
|
24 | 24 | "antenna_down": [[0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
25 | 25 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
26 | 26 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
27 | 27 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
28 | 28 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0], |
|
29 | 29 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0], |
|
30 | 30 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0], |
|
31 | 31 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0]], |
|
32 | 32 | }) |
|
33 | 33 | |
|
34 | 34 | |
|
35 | 35 | tx_default = json.dumps({ |
|
36 | 36 | "up": [[1,1,1,1,0,0,0,0], |
|
37 | 37 | [1,1,1,1,0,0,0,0], |
|
38 | 38 | [1,1,1,1,0,0,0,0], |
|
39 | 39 | [1,1,1,1,0,0,0,0], |
|
40 | 40 | [0,0,0,0,1,1,1,1], |
|
41 | 41 | [0,0,0,0,1,1,1,1], |
|
42 | 42 | [0,0,0,0,1,1,1,1], |
|
43 | 43 | [0,0,0,0,1,1,1,1]], |
|
44 | 44 | |
|
45 | 45 | "down": [[1,1,1,1,0,0,0,0], |
|
46 | 46 | [1,1,1,1,0,0,0,0], |
|
47 | 47 | [1,1,1,1,0,0,0,0], |
|
48 | 48 | [1,1,1,1,0,0,0,0], |
|
49 | 49 | [0,0,0,0,1,1,1,1], |
|
50 | 50 | [0,0,0,0,1,1,1,1], |
|
51 | 51 | [0,0,0,0,1,1,1,1], |
|
52 | 52 | [0,0,0,0,1,1,1,1]], |
|
53 | 53 | }) |
|
54 | 54 | |
|
55 | 55 | rx_default = json.dumps({ |
|
56 | 56 | "up": [[1,1,1,1,0,0,0,0], |
|
57 | 57 | [1,1,1,1,0,0,0,0], |
|
58 | 58 | [1,1,1,1,0,0,0,0], |
|
59 | 59 | [1,1,1,1,0,0,0,0], |
|
60 | 60 | [0,0,0,0,1,1,1,1], |
|
61 | 61 | [0,0,0,0,1,1,1,1], |
|
62 | 62 | [0,0,0,0,1,1,1,1], |
|
63 | 63 | [0,0,0,0,1,1,1,1]], |
|
64 | 64 | |
|
65 | 65 | "down": [[1,1,1,1,0,0,0,0], |
|
66 | 66 | [1,1,1,1,0,0,0,0], |
|
67 | 67 | [1,1,1,1,0,0,0,0], |
|
68 | 68 | [1,1,1,1,0,0,0,0], |
|
69 | 69 | [0,0,0,0,1,1,1,1], |
|
70 | 70 | [0,0,0,0,1,1,1,1], |
|
71 | 71 | [0,0,0,0,1,1,1,1], |
|
72 | 72 | [0,0,0,0,1,1,1,1]], |
|
73 | 73 | }) |
|
74 | 74 | |
|
75 | 75 | status_default = '0000000000000000000000000000000000000000000000000000000000000000' |
|
76 | 76 | default_messages = {} |
|
77 | 77 | |
|
78 | 78 | for i in range(1,65): |
|
79 | 79 | default_messages[str(i)] = "Module "+str(i) |
|
80 | 80 | |
|
81 | 81 | |
|
82 | 82 | ues_default = json.dumps({ |
|
83 | 83 | "up": [0.533333,0.00000,1.06667,0.00000], |
|
84 | 84 | "down": [0.533333,0.00000,1.06667,0.00000] |
|
85 | 85 | }) |
|
86 | 86 | |
|
87 | 87 | onlyrx_default = json.dumps({ |
|
88 | 88 | "up": False, |
|
89 | 89 | "down": False |
|
90 | 90 | }) |
|
91 | 91 | |
|
92 | 92 | def up_convertion(cadena): |
|
93 | 93 | valores = [] |
|
94 | 94 | for c in cadena: |
|
95 | 95 | if c == 1.0: valores=valores+['000'] |
|
96 | 96 | if c == 2.0: valores=valores+['001'] |
|
97 | 97 | if c == 3.0: valores=valores+['010'] |
|
98 | 98 | if c == 0.0: valores=valores+['011'] |
|
99 | 99 | if c == 0.5: valores=valores+['100'] |
|
100 | 100 | if c == 1.5: valores=valores+['101'] |
|
101 | 101 | if c == 2.5: valores=valores+['110'] |
|
102 | 102 | if c == 3.5: valores=valores+['111'] |
|
103 | 103 | |
|
104 | 104 | return valores |
|
105 | 105 | |
|
106 | 106 | def up_conv_bits(value): |
|
107 | 107 | |
|
108 | 108 | if value == 1.0: bits="000" |
|
109 | 109 | if value == 2.0: bits="001" |
|
110 | 110 | if value == 3.0: bits="010" |
|
111 | 111 | if value == 0.0: bits="011" |
|
112 | 112 | if value == 0.5: bits="100" |
|
113 | 113 | if value == 1.5: bits="101" |
|
114 | 114 | if value == 2.5: bits="110" |
|
115 | 115 | if value == 3.5: bits="111" |
|
116 | 116 | |
|
117 | 117 | return bits |
|
118 | 118 | |
|
119 | 119 | def down_convertion(cadena): |
|
120 | 120 | valores = [] |
|
121 | 121 | for c in cadena: |
|
122 | 122 | if c == 1.0: valores=valores+['000'] |
|
123 | 123 | if c == 2.0: valores=valores+['001'] |
|
124 | 124 | if c == 3.0: valores=valores+['010'] |
|
125 | 125 | if c == 0.0: valores=valores+['011'] |
|
126 | 126 | if c == 0.5: valores=valores+['100'] |
|
127 | 127 | if c == 1.5: valores=valores+['101'] |
|
128 | 128 | if c == 2.5: valores=valores+['110'] |
|
129 | 129 | if c == 3.5: valores=valores+['111'] |
|
130 | 130 | |
|
131 | 131 | return valores |
|
132 | 132 | |
|
133 | 133 | def down_conv_bits(value): |
|
134 | 134 | |
|
135 | 135 | if value == 1.0: bits="000" |
|
136 | 136 | if value == 2.0: bits="001" |
|
137 | 137 | if value == 3.0: bits="010" |
|
138 | 138 | if value == 0.0: bits="011" |
|
139 | 139 | if value == 0.5: bits="100" |
|
140 | 140 | if value == 1.5: bits="101" |
|
141 | 141 | if value == 2.5: bits="110" |
|
142 | 142 | if value == 3.5: bits="111" |
|
143 | 143 | |
|
144 | 144 | return bits |
|
145 | 145 | |
|
146 | 146 | def up_conv_value(bits): |
|
147 | 147 | |
|
148 | 148 | if bits == "000": value=1.0 |
|
149 | 149 | if bits == "001": value=2.0 |
|
150 | 150 | if bits == "010": value=3.0 |
|
151 | 151 | if bits == "011": value=0.0 |
|
152 | 152 | if bits == "100": value=0.5 |
|
153 | 153 | if bits == "101": value=1.5 |
|
154 | 154 | if bits == "110": value=2.5 |
|
155 | 155 | if bits == "111": value=3.5 |
|
156 | 156 | |
|
157 | 157 | return value |
|
158 | 158 | |
|
159 | 159 | def down_conv_value(bits): |
|
160 | 160 | |
|
161 | 161 | if bits == "000": value=1.0 |
|
162 | 162 | if bits == "001": value=2.0 |
|
163 | 163 | if bits == "010": value=3.0 |
|
164 | 164 | if bits == "011": value=0.0 |
|
165 | 165 | if bits == "100": value=0.5 |
|
166 | 166 | if bits == "101": value=1.5 |
|
167 | 167 | if bits == "110": value=2.5 |
|
168 | 168 | if bits == "111": value=3.5 |
|
169 | 169 | |
|
170 | 170 | return value |
|
171 | 171 | |
|
172 | 172 | def ip2position(module_number): |
|
173 | 173 | j=0 |
|
174 | 174 | i=0 |
|
175 | 175 | for x in range(0,module_number-1): |
|
176 | 176 | j=j+1 |
|
177 | 177 | if j==8: |
|
178 | 178 | i=i+1 |
|
179 | 179 | j=0 |
|
180 | 180 | |
|
181 | 181 | pos = [i,j] |
|
182 | 182 | return pos |
|
183 | 183 | |
|
184 | 184 | |
|
185 | 185 | def fromBinary2Char(binary_string): |
|
186 | 186 | number = int(binary_string, 2) |
|
187 | 187 | #Plus 33 to avoid more than 1 characters values such as: '\x01'-'\x1f' |
|
188 | 188 | number = number + 33 |
|
189 | 189 | char = chr(number) |
|
190 | 190 | return char |
|
191 | 191 | |
|
192 | 192 | def fromChar2Binary(char): |
|
193 | 193 | number = ord(char) - 33 |
|
194 | 194 | #Minus 33 to get the real value |
|
195 | 195 | bits = bin(number)[2:] |
|
196 | 196 | #To ensure we have a string with 6bits |
|
197 | 197 | if len(bits) < 6: |
|
198 | 198 | bits = bits.zfill(6) |
|
199 | 199 | return bits |
|
200 | 200 | |
|
201 | 201 | OPERATION_MODES = ( |
|
202 | 202 | (0, 'Manual'), |
|
203 | 203 | (1, 'Automatic'), |
|
204 | 204 | ) |
|
205 | 205 | |
|
206 | 206 | class ABSConfiguration(Configuration): |
|
207 | 207 | active_beam = models.PositiveSmallIntegerField(verbose_name='Active Beam', default=0) |
|
208 | 208 | module_status = models.CharField(verbose_name='Module Status', max_length=10000, default=status_default) |
|
209 | 209 | operation_mode = models.PositiveSmallIntegerField(verbose_name='Operation Mode', choices=OPERATION_MODES, default = 0) |
|
210 | 210 | operation_value = models.FloatField(verbose_name='Periodic (seconds)', default="10", null=True, blank=True) |
|
211 | 211 | module_messages = models.CharField(verbose_name='Modules Messages', max_length=10000, default=json.dumps(default_messages)) |
|
212 | 212 | |
|
213 | 213 | class Meta: |
|
214 | 214 | db_table = 'abs_configurations' |
|
215 | 215 | |
|
216 | 216 | def get_absolute_url_plot(self): |
|
217 | 217 | return reverse('url_plot_abs_patterns', args=[str(self.id)]) |
|
218 | 218 | |
|
219 | 219 | |
|
220 | 220 | def parms_to_dict(self): |
|
221 | 221 | |
|
222 | 222 | parameters = {} |
|
223 | 223 | |
|
224 | 224 | parameters['device_id'] = self.device.id |
|
225 | 225 | parameters['label'] = self.label |
|
226 | 226 | parameters['device_type'] = self.device.device_type.name |
|
227 | 227 | parameters['beams'] = {} |
|
228 | 228 | |
|
229 | 229 | beams = ABSBeam.objects.filter(abs_conf=self) |
|
230 | 230 | b=1 |
|
231 | 231 | for beam in beams: |
|
232 | 232 | #absbeam = ABSBeam.objects.get(pk=beams[beam]) |
|
233 | 233 | parameters['beams']['beam'+str(b)] = beam.parms_to_dict()#absbeam.parms_to_dict() |
|
234 | 234 | b+=1 |
|
235 | 235 | |
|
236 | 236 | return parameters |
|
237 | 237 | |
|
238 | 238 | |
|
239 | 239 | def dict_to_parms(self, parameters): |
|
240 | 240 | |
|
241 | 241 | self.label = parameters['label'] |
|
242 | 242 | |
|
243 | 243 | absbeams = ABSBeam.objects.filter(abs_conf=self) |
|
244 | 244 | beams = parameters['beams'] |
|
245 | 245 | |
|
246 | 246 | if absbeams: |
|
247 | 247 | beams_number = len(beams) |
|
248 | 248 | absbeams_number = len(absbeams) |
|
249 | 249 | if beams_number==absbeams_number: |
|
250 | 250 | i = 1 |
|
251 | 251 | for absbeam in absbeams: |
|
252 | 252 | absbeam.dict_to_parms(beams['beam'+str(i)]) |
|
253 | 253 | i = i+1 |
|
254 | 254 | elif beams_number > absbeams_number: |
|
255 | 255 | i = 1 |
|
256 | 256 | for absbeam in absbeams: |
|
257 | 257 | absbeam.dict_to_parms(beams['beam'+str(i)]) |
|
258 | 258 | i=i+1 |
|
259 | 259 | for x in range(i,beams_number+1): |
|
260 | 260 | new_beam = ABSBeam( |
|
261 | 261 | name =beams['beam'+str(i)]['name'], |
|
262 | 262 | antenna =json.dumps(beams['beam'+str(i)]['antenna']), |
|
263 | 263 | abs_conf = self, |
|
264 | 264 | tx =json.dumps(beams['beam'+str(i)]['tx']), |
|
265 | 265 | rx =json.dumps(beams['beam'+str(i)]['rx']), |
|
266 | 266 | ues =json.dumps(beams['beam'+str(i)]['ues']), |
|
267 | 267 | only_rx =json.dumps(beams['beam'+str(i)]['only_rx']) |
|
268 | 268 | ) |
|
269 | 269 | new_beam.save() |
|
270 | 270 | i=i+1 |
|
271 | 271 | else: #beams_number < absbeams_number: |
|
272 | 272 | i = 1 |
|
273 | 273 | for absbeam in absbeams: |
|
274 | 274 | if i <= beams_number: |
|
275 | 275 | absbeam.dict_to_parms(beams['beam'+str(i)]) |
|
276 | 276 | i=i+1 |
|
277 | 277 | else: |
|
278 | 278 | absbeam.delete() |
|
279 | 279 | else: |
|
280 | 280 | for beam in beams: |
|
281 | 281 | new_beam = ABSBeam( |
|
282 | 282 | name =beams[beam]['name'], |
|
283 | 283 | antenna =json.dumps(beams[beam]['antenna']), |
|
284 | 284 | abs_conf = self, |
|
285 | 285 | tx =json.dumps(beams[beam]['tx']), |
|
286 | 286 | rx =json.dumps(beams[beam]['rx']), |
|
287 | 287 | ues =json.dumps(beams[beam]['ues']), |
|
288 | 288 | only_rx =json.dumps(beams[beam]['only_rx']) |
|
289 | 289 | ) |
|
290 | 290 | new_beam.save() |
|
291 | 291 | |
|
292 | 292 | |
|
293 | 293 | |
|
294 | 294 | def update_from_file(self, parameters): |
|
295 | 295 | |
|
296 | 296 | self.dict_to_parms(parameters) |
|
297 | 297 | self.save() |
|
298 | 298 | |
|
299 | 299 | |
|
300 | 300 | def get_beams(self, **kwargs): |
|
301 | 301 | ''' |
|
302 | 302 | This function returns ABS Configuration beams |
|
303 | 303 | ''' |
|
304 | 304 | return ABSBeam.objects.filter(abs_conf=self.pk, **kwargs) |
|
305 | 305 | |
|
306 | 306 | def clone(self, **kwargs): |
|
307 | 307 | |
|
308 | 308 | beams = self.get_beams() |
|
309 | 309 | self.pk = None |
|
310 | 310 | self.id = None |
|
311 | 311 | for attr, value in kwargs.items(): |
|
312 | 312 | setattr(self, attr, value) |
|
313 | 313 | self.save() |
|
314 | 314 | |
|
315 | 315 | for beam in beams: |
|
316 | 316 | beam.clone(abs_conf=self) |
|
317 | 317 | |
|
318 | 318 | #-----For Active Beam----- |
|
319 | 319 | new_beams = ABSBeam.objects.filter(abs_conf=self) |
|
320 | 320 | self.active_beam = new_beams[0].id |
|
321 | 321 | self.save() |
|
322 | 322 | #-----For Active Beam----- |
|
323 | 323 | #-----For Device Status--- |
|
324 | 324 | self.device.status = 3 |
|
325 | 325 | self.device.save() |
|
326 | 326 | #-----For Device Status--- |
|
327 | 327 | |
|
328 | 328 | return self |
|
329 | 329 | |
|
330 | 330 | |
|
331 | 331 | def start_device(self, beam=0): |
|
332 | 332 | |
|
333 | 333 | if self.device.status == 3: |
|
334 | 334 | dds = Configuration.objects.filter(experiment=self.experiment, device__device_type__name='dds', type=0) |
|
335 | 335 | if dds: |
|
336 | 336 | dds[0].stop_device() |
|
337 | 337 | self.send_beam(beam) |
|
338 | 338 | time.sleep(1) |
|
339 | 339 | if dds: |
|
340 | 340 | dds[0].start_device() |
|
341 | 341 | else: |
|
342 | 342 | self.device.status = 2 |
|
343 | 343 | self.device.save() |
|
344 | 344 | self.message = 'Please, select Write ABS Device first.' |
|
345 | 345 | return False |
|
346 | 346 | |
|
347 | 347 | |
|
348 | 348 | def stop_device(self): |
|
349 | 349 | |
|
350 | 350 | self.device.status = 2 |
|
351 | 351 | self.device.save() |
|
352 | 352 | self.message = 'ABS has been stopped.' |
|
353 | 353 | self.save() |
|
354 | 354 | |
|
355 | 355 | return True |
|
356 | 356 | |
|
357 | 357 | |
|
358 | 358 | def write_device(self): |
|
359 | 359 | |
|
360 | 360 | """ |
|
361 | 361 | This function sends the beams list to every abs module. |
|
362 | 362 | It needs 'module_conf' function |
|
363 | 363 | """ |
|
364 | 364 | print("Write") |
|
365 | 365 | beams = ABSBeam.objects.filter(abs_conf=self) |
|
366 | 366 | nbeams = len(beams) |
|
367 | 367 | |
|
368 | 368 | # Se manda a cero RC para poder realizar cambio de beam |
|
369 | 369 | if self.experiment is None: |
|
370 | 370 | confs = [] |
|
371 | 371 | else: |
|
372 | 372 | confs = Configuration.objects.filter(experiment = self.experiment).filter(type=0) |
|
373 | 373 | confdds = '' |
|
374 | 374 | confjars = '' |
|
375 | 375 | confrc = '' |
|
376 | 376 | #TO STOP DEVICES: DDS-JARS-RC |
|
377 | 377 | # for i in range(0,len(confs)): |
|
378 | 378 | # if i==0: |
|
379 | 379 | # for conf in confs: |
|
380 | 380 | # if conf.device.device_type.name == 'dds': |
|
381 | 381 | # confdds = conf |
|
382 | 382 | # confdds.stop_device() |
|
383 | 383 | # break |
|
384 | 384 | # if i==1: |
|
385 | 385 | # for conf in confs: |
|
386 | 386 | # if conf.device.device_type.name == 'jars': |
|
387 | 387 | # confjars = conf |
|
388 | 388 | # confjars.stop_device() |
|
389 | 389 | # break |
|
390 | 390 | # if i==2: |
|
391 | 391 | # for conf in confs: |
|
392 | 392 | # if conf.device.device_type.name == 'rc': |
|
393 | 393 | # confrc = conf |
|
394 | 394 | # confrc.stop_device() |
|
395 | 395 | # break |
|
396 | 396 | |
|
397 | 397 | ''' |
|
398 | 398 | if self.connected_modules() == 0 : |
|
399 | 399 | print("No encuentra modulos") |
|
400 | 400 | self.message = "No ABS Module detected." |
|
401 | 401 | return False |
|
402 | 402 | ''' |
|
403 | 403 | #-------------Write each abs module----------- |
|
404 | 404 | |
|
405 | 405 | if beams: |
|
406 | 406 | block_id = 0 |
|
407 | 407 | message = 'SNDF{:03d}{:02d}{:02d}'.format(nbeams, nbeams, block_id) |
|
408 | 408 | for i, status in enumerate(self.module_status): |
|
409 | 409 | message += ''.join([fromBinary2Char(beam.module_6bits(i)) for beam in beams]) |
|
410 | 410 | status = ['0'] * 64 |
|
411 | 411 | n = 0 |
|
412 | 412 | print("Llega una antes entrar a multicast") |
|
413 | 413 | sock = self.send_multicast(message) |
|
414 | 414 | |
|
415 | 415 | while True: |
|
416 | 416 | #for i in range(32): |
|
417 | 417 | try: |
|
418 | 418 | data, address = sock.recvfrom(1024) |
|
419 | 419 | print (address, data) |
|
420 | 420 | data = data.decode("utf-8") |
|
421 | 421 | if data == '1': |
|
422 | 422 | status[int(address[0][10:])-1] = '3' |
|
423 | 423 | #print (int(address[0][10:])-1) |
|
424 | 424 | elif data == '0': |
|
425 | 425 | status[int(address[0][10:])-1] = '1' |
|
426 | 426 | except socket.timeout: |
|
427 | 427 | print('Timeout') |
|
428 | 428 | break |
|
429 | 429 | except Exception as e: |
|
430 | 430 | print ('Error {}'.format(e)) |
|
431 | 431 | n += 1 |
|
432 | 432 | sock.close() |
|
433 | 433 | else: |
|
434 | 434 | self.message = "ABS Configuration does not have beams" |
|
435 | 435 | print('No beams') |
|
436 | 436 | #Start DDS-RC-JARS |
|
437 | 437 | # if confdds: |
|
438 | 438 | # confdds.start_device() |
|
439 | 439 | # if confrc: |
|
440 | 440 | # #print confrc |
|
441 | 441 | # confrc.start_device() |
|
442 | 442 | # if confjars: |
|
443 | 443 | # confjars.start_device() |
|
444 | 444 | return False |
|
445 | 445 | |
|
446 | 446 | if n == 64: |
|
447 | 447 | self.message = "Could not write ABS Modules" |
|
448 | 448 | self.device.status = 0 |
|
449 | 449 | self.module_status = ''.join(status) |
|
450 | 450 | self.save() |
|
451 | 451 | print('Could not write ABS') |
|
452 | 452 | #Start DDS-RC-JARS |
|
453 | 453 | if confdds: |
|
454 | 454 | confdds.start_device() |
|
455 | 455 | if confrc: |
|
456 | 456 | #print confrc |
|
457 | 457 | confrc.start_device() |
|
458 | 458 | if confjars: |
|
459 | 459 | confjars.start_device() |
|
460 | 460 | return False |
|
461 | 461 | else: |
|
462 | 462 | self.message = "ABS Beams List have been sent to ABS Modules" |
|
463 | 463 | print('ABS beams list sent') |
|
464 | 464 | self.active_beam = beams[0].pk |
|
465 | 465 | |
|
466 | 466 | #Start DDS-RC-JARS |
|
467 | 467 | if confdds: |
|
468 | 468 | confdds.start_device() |
|
469 | 469 | if confrc: |
|
470 | 470 | #print confrc |
|
471 | 471 | confrc.start_device() |
|
472 | 472 | if confjars: |
|
473 | 473 | confjars.start_device() |
|
474 | 474 | |
|
475 | 475 | print('Inicia intento de salvar device.status') |
|
476 | 476 | self.device.status = 3 |
|
477 | 477 | self.module_status = ''.join(status) |
|
478 | 478 | #print(status) |
|
479 | 479 | self.save() |
|
480 | 480 | print('Estatus salvado') |
|
481 | 481 | conf_active, __ = ABSActive.objects.get_or_create(pk=1) |
|
482 | 482 | conf_active.conf = self |
|
483 | 483 | conf_active.save() |
|
484 | 484 | return True |
|
485 | 485 | |
|
486 | 486 | |
|
487 | 487 | def read_module(self, module): |
|
488 | 488 | |
|
489 | 489 | """ |
|
490 | 490 | Read out-bits (up-down) of 1 abs module NOT for Configuration |
|
491 | 491 | """ |
|
492 | 492 | |
|
493 | 493 | ip_address = self.device.ip_address |
|
494 | 494 | ip_address = ip_address.split('.') |
|
495 | 495 | module_seq = (ip_address[0],ip_address[1],ip_address[2]) |
|
496 | 496 | dot = '.' |
|
497 | 497 | module_ip = dot.join(module_seq)+'.'+str(module) |
|
498 | 498 | module_port = self.device.port_address |
|
499 | 499 | read_route = 'http://'+module_ip+':'+str(module_port)+'/read' |
|
500 | 500 | |
|
501 | 501 | module_status = json.loads(self.module_status) |
|
502 | 502 | print(read_route) |
|
503 | 503 | |
|
504 | 504 | module_bits = '' |
|
505 | 505 | |
|
506 | 506 | try: |
|
507 | 507 | r_read = requests.get(read_route, timeout=0.5) |
|
508 | 508 | answer = r_read.json() |
|
509 | 509 | module_bits = answer['allbits'] |
|
510 | 510 | except: |
|
511 | 511 | return {} |
|
512 | 512 | |
|
513 | 513 | return module_bits |
|
514 | 514 | |
|
515 | 515 | def read_device(self): |
|
516 | 516 | |
|
517 | 517 | parms = {} |
|
518 | 518 | # Reads active modules. |
|
519 | 519 | module_status = json.loads(self.module_status) |
|
520 | 520 | total = 0 |
|
521 | 521 | for status in module_status: |
|
522 | 522 | if module_status[status] != 0: |
|
523 | 523 | module_bits = self.read_module(int(status)) |
|
524 | 524 | bits={} |
|
525 | 525 | if module_bits: |
|
526 | 526 | bits = (str(module_bits['um2']) + str(module_bits['um1']) + str(module_bits['um0']) + |
|
527 | 527 | str(module_bits['dm2']) + str(module_bits['dm1']) + str(module_bits['dm0']) ) |
|
528 | 528 | parms[str(status)] = bits |
|
529 | 529 | |
|
530 | 530 | total +=1 |
|
531 | 531 | |
|
532 | 532 | if total==0: |
|
533 | 533 | self.message = "No ABS Module detected. Please select 'Status'." |
|
534 | 534 | return False |
|
535 | 535 | |
|
536 | 536 | |
|
537 | 537 | |
|
538 | 538 | self.message = "ABS Modules have been read" |
|
539 | 539 | #monitoreo_tx = JROABSClnt_01CeCnMod000000MNTR10 |
|
540 | 540 | return parms |
|
541 | 541 | |
|
542 | 542 | |
|
543 | 543 | def connected_modules(self): |
|
544 | 544 | """ |
|
545 | 545 | This function returns the number of connected abs-modules without updating. |
|
546 | 546 | """ |
|
547 | 547 | num = 0 |
|
548 | 548 | print(self.module_status) |
|
549 | 549 | for i, status in enumerate(self.module_status): |
|
550 | 550 | if status != '0': |
|
551 | 551 | num += 1 |
|
552 | 552 | #print('status {}:{}'.format(i+1, status)) |
|
553 | 553 | return num |
|
554 | 554 | |
|
555 | 555 | def send_multicast(self, message): |
|
556 | 556 | #print("Send multicast") |
|
557 | 557 | multicast_group = ('224.3.29.71', 10000) |
|
558 | 558 | # Create the datagram socket |
|
559 | 559 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
|
560 | 560 | sock.settimeout(1) |
|
561 | 561 | local_ip = os.environ.get('LOCAL_IP', '192.168.1.128') |
|
562 | 562 | sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_IF, socket.inet_aton(local_ip)) |
|
563 | 563 | sock.sendto(message.encode(), multicast_group) |
|
564 | 564 | print('Sending ' + message) |
|
565 | 565 | return sock |
|
566 | 566 | |
|
567 | 567 | def status_device(self): |
|
568 | 568 | """ |
|
569 | 569 | This function returns the status of all abs-modules as one. |
|
570 | 570 | If at least one module is connected, its answer is "1" |
|
571 | 571 | """ |
|
572 | 572 | print ('Status device') |
|
573 | 573 | print (self.active_beam) |
|
574 | 574 | beams = ABSBeam.objects.filter(abs_conf=self) |
|
575 | 575 | #print beams[self.active_beam-1].module_6bits(0) |
|
576 | 576 | active = ABSActive.objects.get(pk=1) |
|
577 | 577 | if active.conf != self: |
|
578 | 578 | self.message = 'La configuracion actual es la del siguiente enlace %s.' % active.conf.get_absolute_url() |
|
579 | 579 | self.message += "\n" |
|
580 | 580 | self.message += 'Se debe realizar un write en esta configuracion para luego obtener un status valido.' |
|
581 | 581 | |
|
582 | 582 | return False |
|
583 | 583 | |
|
584 | 584 | sock = self.send_multicast('MNTR') |
|
585 | 585 | |
|
586 | 586 | n = 0 |
|
587 | 587 | status = ['0'] * 64 |
|
588 | 588 | |
|
589 | 589 | while True: |
|
590 | 590 | #for i in range(32): |
|
591 | 591 | #if True: |
|
592 | 592 | try: |
|
593 | 593 | print("Recibiendo") |
|
594 | 594 | address = None |
|
595 | 595 | data, address = sock.recvfrom(2) |
|
596 | 596 | print (address, data) |
|
597 | 597 | print("!!!!") |
|
598 | 598 | data = data.decode() |
|
599 | 599 | aux_mon = "1" |
|
600 | 600 | aux_expected = aux_mon |
|
601 | 601 | if(len(data)==2): |
|
602 | 602 | print ("data[1]: ") |
|
603 | 603 | print (data[1]) |
|
604 | 604 | aux_mon = fromChar2Binary(data[1]) |
|
605 | 605 | print (aux_mon) |
|
606 | 606 | aux_i = (str(address[0]).split('.'))[3] |
|
607 | 607 | print (aux_i) |
|
608 | 608 | print ('Active beam') |
|
609 | 609 | beam_active = ABSBeam.objects.get(pk=self.active_beam) |
|
610 | 610 | print (beam_active) |
|
611 | 611 | aux_expected = beam_active.module_6bits(int(aux_i)-1) |
|
612 | 612 | print (aux_expected) |
|
613 | 613 | |
|
614 | 614 | print ("data[0]: ") |
|
615 | 615 | print (data[0]) |
|
616 | 616 | |
|
617 | 617 | if data[0] == '1': |
|
618 | 618 | status[int(address[0][10:])-1] = '3' |
|
619 | 619 | if aux_mon == aux_expected: |
|
620 | 620 | print ('Es igual') |
|
621 | 621 | else: |
|
622 | 622 | print ('Es diferente') |
|
623 | 623 | status[int(address[0][10:])-1] = '2' |
|
624 | 624 | |
|
625 | 625 | elif data[0] == '0': |
|
626 | 626 | status[int(address[0][10:])-1] = '1' |
|
627 | 627 | n += 1 |
|
628 | 628 | print('Module: {} connected'.format(address)) |
|
629 | 629 | except socket.timeout: |
|
630 | 630 | print('Timeout') |
|
631 | 631 | break |
|
632 | 632 | except: |
|
633 | 633 | print('Module: {} error'.format(address)) |
|
634 | 634 | pass |
|
635 | 635 | |
|
636 | 636 | sock.close() |
|
637 | 637 | |
|
638 | 638 | if n > 0: |
|
639 | 639 | self.message = 'ABS modules Status have been updated.' |
|
640 | 640 | self.device.status = 1 |
|
641 | 641 | else: |
|
642 | 642 | self.device.status = 0 |
|
643 | 643 | self.message = 'No ABS module is connected.' |
|
644 | 644 | self.module_status = ''.join(status) |
|
645 | 645 | self.save() |
|
646 | 646 | |
|
647 | 647 | return self.device.status |
|
648 | 648 | |
|
649 | 649 | |
|
650 | 650 | def send_beam(self, beam_pos): |
|
651 | 651 | """ |
|
652 | 652 | This function connects to a multicast group and sends the beam number |
|
653 | 653 | to all abs modules. |
|
654 | 654 | """ |
|
655 | 655 | print ('Send beam') |
|
656 | 656 | print (self.active_beam) |
|
657 | 657 | beams = ABSBeam.objects.filter(abs_conf=self) |
|
658 | #print beams[self.active_beam-1].module_6bits(0) | |
|
658 | ||
|
659 | 659 | active = ABSActive.objects.get(pk=1) |
|
660 | 660 | if active.conf != self: |
|
661 | 661 | self.message = 'La configuracion actual es la del siguiente enlace %s.' % active.conf.get_absolute_url() |
|
662 | 662 | self.message += "\n" |
|
663 | 663 | self.message += 'Se debe realizar un write en esta configuracion para luego obtener un status valido.' |
|
664 | 664 | |
|
665 | 665 | return False |
|
666 | 666 | |
|
667 | 667 | # Se manda a cero RC para poder realizar cambio de beam |
|
668 | 668 | if self.experiment is None: |
|
669 | 669 | confs = [] |
|
670 | 670 | else: |
|
671 | 671 | confs = Configuration.objects.filter(experiment = self.experiment).filter(type=0) |
|
672 | 672 | confdds = '' |
|
673 | 673 | confjars = '' |
|
674 | 674 | confrc = '' |
|
675 | 675 | #TO STOP DEVICES: DDS-JARS-RC |
|
676 | 676 | # for i in range(0,len(confs)): |
|
677 | 677 | # if i==0: |
|
678 | 678 | # for conf in confs: |
|
679 | 679 | # if conf.device.device_type.name == 'dds': |
|
680 | 680 | # confdds = conf |
|
681 | 681 | # confdds.stop_device() |
|
682 | 682 | # break |
|
683 | 683 | # if i==1: |
|
684 | 684 | # for conf in confs: |
|
685 | 685 | # if conf.device.device_type.name == 'jars': |
|
686 | 686 | # confjars = conf |
|
687 | 687 | # confjars.stop_device() |
|
688 | 688 | # break |
|
689 | 689 | # if i==2: |
|
690 | 690 | # for conf in confs: |
|
691 | 691 | # if conf.device.device_type.name == 'rc': |
|
692 | 692 | # confrc = conf |
|
693 | 693 | # confrc.stop_device() |
|
694 | 694 | # break |
|
695 | 695 | # if beam_pos > 0: |
|
696 | 696 | # beam_pos = beam_pos - 1 |
|
697 | 697 | # else: |
|
698 | 698 | # beam_pos = 0 |
|
699 | 699 | |
|
700 | 700 | #El indice del apunte debe ser menor que el numero total de apuntes |
|
701 | 701 | #El servidor tcp en el embebido comienza a contar desde 0 |
|
702 | 702 | status = ['0'] * 64 |
|
703 | 703 | message = 'CHGB{}'.format(beam_pos) |
|
704 | 704 | sock = self.send_multicast(message) |
|
705 | 705 | while True: |
|
706 | 706 | #for i in range(32): |
|
707 | 707 | try: |
|
708 | 708 | data, address = sock.recvfrom(1024) |
|
709 | 709 | print (address, data) |
|
710 | 710 | data = data.decode() |
|
711 | 711 | if data == '1': |
|
712 | 712 | status[int(address[0][10:])-1] = '3' |
|
713 | 713 | elif data == '0': |
|
714 | 714 | status[int(address[0][10:])-1] = '1' |
|
715 | 715 | except socket.timeout: |
|
716 | 716 | print('Timeout') |
|
717 | 717 | break |
|
718 | 718 | except Exception as e: |
|
719 | 719 | print ('Error {}'.format(e)) |
|
720 | 720 | pass |
|
721 | 721 | |
|
722 | 722 | sock.close() |
|
723 | 723 | |
|
724 | 724 | #Start DDS-RC-JARS |
|
725 | 725 | # if confdds: |
|
726 | 726 | # confdds.start_device() |
|
727 | 727 | # if confrc: |
|
728 | 728 | # #print confrc |
|
729 | 729 | # confrc.start_device() |
|
730 | 730 | # if confjars: |
|
731 | 731 | # confjars.start_device() |
|
732 | 732 | |
|
733 | 733 | self.message = "ABS Beam has been changed" |
|
734 | 734 | self.module_status = ''.join(status) |
|
735 | 735 | self.save() |
|
736 | 736 | return True |
|
737 | 737 | |
|
738 | 738 | |
|
739 | 739 | def get_absolute_url_import(self): |
|
740 | 740 | return reverse('url_import_abs_conf', args=[str(self.id)]) |
|
741 | 741 | |
|
742 | 742 | class ABSActive(models.Model): |
|
743 | 743 | conf = models.ForeignKey(ABSConfiguration, null=True, verbose_name='ABS Configuration', on_delete=models.CASCADE) |
|
744 | 744 | |
|
745 | 745 | class Meta: |
|
746 | 746 | db_table = 'abs_absactive' |
|
747 | 747 | |
|
748 | 748 | class ABSBeam(models.Model): |
|
749 | 749 | |
|
750 | 750 | name = models.CharField(max_length=60, default='Beam') |
|
751 | 751 | antenna = models.CharField(verbose_name='Antenna', max_length=1000, default=antenna_default) |
|
752 | 752 | abs_conf = models.ForeignKey('ABSConfiguration', null=True, |
|
753 | 753 | verbose_name='ABS Configuration', on_delete=models.CASCADE) |
|
754 | 754 | tx = models.CharField(verbose_name='Tx', max_length=1000, default=tx_default) |
|
755 | 755 | rx = models.CharField(verbose_name='Rx', max_length=1000, default=rx_default) |
|
756 | 756 | s_time = models.TimeField(verbose_name='Star Time', default='00:00:00') |
|
757 | 757 | e_time = models.TimeField(verbose_name='End Time', default='23:59:59') |
|
758 | 758 | ues = models.CharField(verbose_name='Ues', max_length=100, default=ues_default) |
|
759 | 759 | only_rx = models.CharField(verbose_name='Only RX', max_length=40, default=onlyrx_default) |
|
760 | 760 | |
|
761 | 761 | class Meta: |
|
762 | 762 | db_table = 'abs_beams' |
|
763 | 763 | |
|
764 | 764 | def __unicode__(self): |
|
765 | 765 | return u'%s' % (self.name) |
|
766 | 766 | |
|
767 | 767 | def parms_to_dict(self): |
|
768 | 768 | |
|
769 | 769 | parameters = {} |
|
770 | 770 | parameters['name'] = self.name |
|
771 | 771 | parameters['antenna'] = ast.literal_eval(self.antenna) |
|
772 | 772 | parameters['abs_conf'] = self.abs_conf.name |
|
773 | 773 | parameters['tx'] = ast.literal_eval(self.tx) |
|
774 | 774 | parameters['rx'] = ast.literal_eval(self.rx) |
|
775 | 775 | parameters['s_time'] = self.s_time.strftime("%H:%M:%S") |
|
776 | 776 | parameters['e_time'] = self.e_time.strftime("%H:%M:%S") |
|
777 | 777 | parameters['ues'] = ast.literal_eval(self.ues) |
|
778 | 778 | parameters['only_rx'] = json.loads(self.only_rx) |
|
779 | 779 | |
|
780 | 780 | return parameters |
|
781 | 781 | |
|
782 | 782 | def dict_to_parms(self, parameters): |
|
783 | 783 | |
|
784 | 784 | self.name = parameters['name'] |
|
785 | 785 | self.antenna = json.dumps(parameters['antenna']) |
|
786 | 786 | #self.abs_conf = parameters['abs_conf'] |
|
787 | 787 | self.tx = json.dumps(parameters['tx']) |
|
788 | 788 | self.rx = json.dumps(parameters['rx']) |
|
789 | 789 | #self.s_time = parameters['s_time'] |
|
790 | 790 | #self.e_time = parameters['e_time'] |
|
791 | 791 | self.ues = json.dumps(parameters['ues']) |
|
792 | 792 | self.only_rx = json.dumps(parameters['only_rx']) |
|
793 | 793 | self.save() |
|
794 | 794 | |
|
795 | 795 | |
|
796 | 796 | def clone(self, **kwargs): |
|
797 | 797 | |
|
798 | 798 | self.pk = None |
|
799 | 799 | self.id = None |
|
800 | 800 | for attr, value in kwargs.items(): |
|
801 | 801 | setattr(self, attr, value) |
|
802 | 802 | |
|
803 | 803 | self.save() |
|
804 | 804 | |
|
805 | 805 | return self |
|
806 | 806 | |
|
807 | 807 | |
|
808 | 808 | def module_6bits(self, module): |
|
809 | 809 | """ |
|
810 | 810 | This function reads antenna pattern and choose 6bits (upbits-downbits) for one abs module |
|
811 | 811 | """ |
|
812 | 812 | module += 1 |
|
813 | 813 | if module > 64: |
|
814 | 814 | beam_bits = "" |
|
815 | 815 | return beam_bits |
|
816 | 816 | |
|
817 | 817 | data = ast.literal_eval(self.antenna) |
|
818 | 818 | up_data = data['antenna_up'] |
|
819 | 819 | down_data = data['antenna_down'] |
|
820 | 820 | |
|
821 | 821 | pos = ip2position(module) |
|
822 | 822 | up_value = up_data[pos[0]][pos[1]] |
|
823 | 823 | down_value = down_data[pos[0]][pos[1]] |
|
824 | 824 | |
|
825 | 825 | up_bits = up_conv_bits(up_value) |
|
826 | 826 | down_bits = down_conv_bits(down_value) |
|
827 | 827 | beam_bits = up_bits+down_bits |
|
828 | 828 | |
|
829 | 829 | return beam_bits |
|
830 | 830 | |
|
831 | 831 | |
|
832 | 832 | @property |
|
833 | 833 | def get_upvalues(self): |
|
834 | 834 | """ |
|
835 | 835 | This function reads antenna pattern and show the up-value of one abs module |
|
836 | 836 | """ |
|
837 | 837 | |
|
838 | 838 | data = ast.literal_eval(self.antenna) |
|
839 | 839 | up_data = data['antenna_up'] |
|
840 | 840 | |
|
841 | 841 | up_values = [] |
|
842 | 842 | for data in up_data: |
|
843 | 843 | for i in range(0,8): |
|
844 | 844 | up_values.append(data[i]) |
|
845 | 845 | |
|
846 | 846 | return up_values |
|
847 | 847 | |
|
848 | 848 | @property |
|
849 | 849 | def antenna_upvalues(self): |
|
850 | 850 | """ |
|
851 | 851 | This function reads antenna pattern and show the up - values of one abs beam |
|
852 | 852 | in a particular order |
|
853 | 853 | """ |
|
854 | 854 | data = ast.literal_eval(self.antenna) |
|
855 | 855 | up_data = data['antenna_up'] |
|
856 | 856 | |
|
857 | 857 | return up_data |
|
858 | 858 | |
|
859 | 859 | @property |
|
860 | 860 | def antenna_downvalues(self): |
|
861 | 861 | """ |
|
862 | 862 | This function reads antenna pattern and show the down - values of one abs beam |
|
863 | 863 | in a particular order |
|
864 | 864 | """ |
|
865 | 865 | data = ast.literal_eval(self.antenna) |
|
866 | 866 | down_data = data['antenna_down'] |
|
867 | 867 | |
|
868 | 868 | return down_data |
|
869 | 869 | |
|
870 | 870 | @property |
|
871 | 871 | def get_downvalues(self): |
|
872 | 872 | """ |
|
873 | 873 | This function reads antenna pattern and show the down-value of one abs module |
|
874 | 874 | """ |
|
875 | 875 | |
|
876 | 876 | data = ast.literal_eval(self.antenna) |
|
877 | 877 | down_data = data['antenna_down'] |
|
878 | 878 | |
|
879 | 879 | down_values = [] |
|
880 | 880 | for data in down_data: |
|
881 | 881 | for i in range(0,8): |
|
882 | 882 | down_values.append(data[i]) |
|
883 | 883 | |
|
884 | 884 | return down_values |
|
885 | 885 | |
|
886 | 886 | @property |
|
887 | 887 | def get_up_ues(self): |
|
888 | 888 | """ |
|
889 | 889 | This function shows the up-ues-value of one beam |
|
890 | 890 | """ |
|
891 | 891 | data = ast.literal_eval(self.ues) |
|
892 | 892 | up_ues = data['up'] |
|
893 | 893 | |
|
894 | 894 | return up_ues |
|
895 | 895 | |
|
896 | 896 | @property |
|
897 | 897 | def get_down_ues(self): |
|
898 | 898 | """ |
|
899 | 899 | This function shows the down-ues-value of one beam |
|
900 | 900 | """ |
|
901 | 901 | data = ast.literal_eval(self.ues) |
|
902 | 902 | down_ues = data['down'] |
|
903 | 903 | |
|
904 | 904 | return down_ues |
|
905 | 905 | |
|
906 | 906 | @property |
|
907 | 907 | def get_up_onlyrx(self): |
|
908 | 908 | """ |
|
909 | 909 | This function shows the up-onlyrx-value of one beam |
|
910 | 910 | """ |
|
911 | 911 | data = json.loads(self.only_rx) |
|
912 | 912 | up_onlyrx = data['up'] |
|
913 | 913 | |
|
914 | 914 | return up_onlyrx |
|
915 | 915 | |
|
916 | 916 | @property |
|
917 | 917 | def get_down_onlyrx(self): |
|
918 | 918 | """ |
|
919 | 919 | This function shows the down-onlyrx-value of one beam |
|
920 | 920 | """ |
|
921 | 921 | data = json.loads(self.only_rx) |
|
922 | 922 | down_onlyrx = data['down'] |
|
923 | 923 | |
|
924 | 924 | return down_onlyrx |
|
925 | 925 | |
|
926 | 926 | @property |
|
927 | 927 | def get_tx(self): |
|
928 | 928 | """ |
|
929 | 929 | This function shows the tx-values of one beam |
|
930 | 930 | """ |
|
931 | 931 | data = json.loads(self.tx) |
|
932 | 932 | |
|
933 | 933 | return data |
|
934 | 934 | |
|
935 | 935 | @property |
|
936 | 936 | def get_uptx(self): |
|
937 | 937 | """ |
|
938 | 938 | This function shows the up-tx-values of one beam |
|
939 | 939 | """ |
|
940 | 940 | data = json.loads(self.tx) |
|
941 | 941 | up_data = data['up'] |
|
942 | 942 | |
|
943 | 943 | up_values = [] |
|
944 | 944 | for data in up_data: |
|
945 | 945 | for i in range(0,8): |
|
946 | 946 | up_values.append(data[i]) |
|
947 | 947 | |
|
948 | 948 | return up_values |
|
949 | 949 | |
|
950 | 950 | @property |
|
951 | 951 | def get_downtx(self): |
|
952 | 952 | """ |
|
953 | 953 | This function shows the down-tx-values of one beam |
|
954 | 954 | """ |
|
955 | 955 | data = json.loads(self.tx) |
|
956 | 956 | down_data = data['down'] |
|
957 | 957 | |
|
958 | 958 | down_values = [] |
|
959 | 959 | for data in down_data: |
|
960 | 960 | for i in range(0,8): |
|
961 | 961 | down_values.append(data[i]) |
|
962 | 962 | |
|
963 | 963 | return down_values |
|
964 | 964 | |
|
965 | 965 | |
|
966 | 966 | |
|
967 | 967 | @property |
|
968 | 968 | def get_rx(self): |
|
969 | 969 | """ |
|
970 | 970 | This function shows the rx-values of one beam |
|
971 | 971 | """ |
|
972 | 972 | data = json.loads(self.rx) |
|
973 | 973 | |
|
974 | 974 | return data |
|
975 | 975 | |
|
976 | 976 | @property |
|
977 | 977 | def get_uprx(self): |
|
978 | 978 | """ |
|
979 | 979 | This function shows the up-rx-values of one beam |
|
980 | 980 | """ |
|
981 | 981 | data = json.loads(self.rx) |
|
982 | 982 | up_data = data['up'] |
|
983 | 983 | |
|
984 | 984 | up_values = [] |
|
985 | 985 | for data in up_data: |
|
986 | 986 | for i in range(0,8): |
|
987 | 987 | up_values.append(data[i]) |
|
988 | 988 | |
|
989 | 989 | return up_values |
|
990 | 990 | |
|
991 | 991 | @property |
|
992 | 992 | def get_downrx(self): |
|
993 | 993 | """ |
|
994 | 994 | This function shows the down-rx-values of one beam |
|
995 | 995 | """ |
|
996 | 996 | data = json.loads(self.rx) |
|
997 | 997 | down_data = data['down'] |
|
998 | 998 | |
|
999 | 999 | down_values = [] |
|
1000 | 1000 | for data in down_data: |
|
1001 | 1001 | for i in range(0,8): |
|
1002 | 1002 | down_values.append(data[i]) |
|
1003 | 1003 | |
|
1004 | 1004 | return down_values |
@@ -1,458 +1,461 | |||
|
1 | 1 | from django.shortcuts import render_to_response |
|
2 | 2 | from django.template import RequestContext |
|
3 | 3 | from django.shortcuts import redirect, render, get_object_or_404 |
|
4 | 4 | from django.contrib import messages |
|
5 | 5 | from django.conf import settings |
|
6 | 6 | from django.http import HttpResponse |
|
7 | 7 | from django.urls import reverse |
|
8 | 8 | from django.views.decorators.csrf import csrf_exempt |
|
9 | 9 | from django.utils.safestring import mark_safe |
|
10 | 10 | |
|
11 | 11 | from datetime import datetime |
|
12 | 12 | from time import sleep |
|
13 | 13 | import os |
|
14 | 14 | import io |
|
15 | 15 | |
|
16 | 16 | from apps.main.models import Device, Configuration, Experiment |
|
17 | 17 | from apps.main.views import sidebar |
|
18 | 18 | |
|
19 | 19 | from .models import ABSConfiguration, ABSBeam |
|
20 | 20 | from .forms import ABSConfigurationForm, ABSBeamEditForm, ABSBeamAddForm, ABSImportForm |
|
21 | 21 | |
|
22 | 22 | from .utils.overJroShow import overJroShow |
|
23 | 23 | #from .utils.OverJRO import OverJRO |
|
24 | 24 | #Create your views here. |
|
25 | 25 | import json, ast |
|
26 | 26 | |
|
27 | 27 | |
|
28 | 28 | def get_values_from_form(form_data): |
|
29 | 29 | |
|
30 | 30 | sublistup = [] |
|
31 | 31 | sublistdown = [] |
|
32 | 32 | subtxlistup = [] |
|
33 | 33 | subtxlistdown = [] |
|
34 | 34 | subrxlistup = [] |
|
35 | 35 | subrxlistdown = [] |
|
36 | 36 | |
|
37 | 37 | up_values_list = [] |
|
38 | 38 | down_values_list = [] |
|
39 | 39 | up_txvalues_list = [] |
|
40 | 40 | down_txvalues_list = [] |
|
41 | 41 | up_rxvalues_list = [] |
|
42 | 42 | down_rxvalues_list = [] |
|
43 | 43 | |
|
44 | 44 | values_list = {} |
|
45 | 45 | cont = 1 |
|
46 | 46 | |
|
47 | 47 | for i in range(1,65): |
|
48 | 48 | x = float(form_data['abs_up'+str(i)]) |
|
49 | 49 | y = float(form_data['abs_down'+str(i)]) |
|
50 | 50 | sublistup.append(x) |
|
51 | 51 | sublistdown.append(y) |
|
52 | 52 | |
|
53 | 53 | if str(i) in form_data.getlist('uptx_checks'): |
|
54 | 54 | subtxlistup.append(1) |
|
55 | 55 | else: |
|
56 | 56 | subtxlistup.append(0) |
|
57 | 57 | if str(i) in form_data.getlist('downtx_checks'): |
|
58 | 58 | subtxlistdown.append(1) |
|
59 | 59 | else: |
|
60 | 60 | subtxlistdown.append(0) |
|
61 | 61 | |
|
62 | 62 | if str(i) in form_data.getlist('uprx_checks'): |
|
63 | 63 | subrxlistup.append(1) |
|
64 | 64 | else: |
|
65 | 65 | subrxlistup.append(0) |
|
66 | 66 | if str(i) in form_data.getlist('downrx_checks'): |
|
67 | 67 | subrxlistdown.append(1) |
|
68 | 68 | else: |
|
69 | 69 | subrxlistdown.append(0) |
|
70 | 70 | |
|
71 | 71 | cont = cont+1 |
|
72 | 72 | |
|
73 | 73 | if cont == 9: |
|
74 | 74 | up_values_list.append(sublistup) |
|
75 | 75 | down_values_list.append(sublistdown) |
|
76 | 76 | sublistup = [] |
|
77 | 77 | sublistdown = [] |
|
78 | 78 | |
|
79 | 79 | up_txvalues_list.append(subtxlistup) |
|
80 | 80 | down_txvalues_list.append(subtxlistdown) |
|
81 | 81 | subtxlistup = [] |
|
82 | 82 | subtxlistdown = [] |
|
83 | 83 | up_rxvalues_list.append(subrxlistup) |
|
84 | 84 | down_rxvalues_list.append(subrxlistdown) |
|
85 | 85 | subrxlistup = [] |
|
86 | 86 | subrxlistdown = [] |
|
87 | 87 | cont = 1 |
|
88 | 88 | |
|
89 | 89 | |
|
90 | 90 | list_uesup = [] |
|
91 | 91 | list_uesdown = [] |
|
92 | 92 | for i in range(1,5): |
|
93 | 93 | if form_data['ues_up'+str(i)] == '': |
|
94 | 94 | list_uesup.append(0.0) |
|
95 | 95 | else: |
|
96 | 96 | list_uesup.append(float(form_data['ues_up'+str(i)])) |
|
97 | 97 | |
|
98 | 98 | if form_data['ues_down'+str(i)] == '': |
|
99 | 99 | list_uesdown.append(0.0) |
|
100 | 100 | else: |
|
101 | 101 | list_uesdown.append(float(form_data['ues_down'+str(i)])) |
|
102 | 102 | |
|
103 | 103 | onlyrx_list = form_data.getlist('onlyrx') |
|
104 | 104 | only_rx = {} |
|
105 | 105 | if '1' in onlyrx_list: |
|
106 | 106 | only_rx['up'] = True |
|
107 | 107 | else: |
|
108 | 108 | only_rx['up'] = False |
|
109 | 109 | if '2' in onlyrx_list: |
|
110 | 110 | only_rx['down'] = True |
|
111 | 111 | else: |
|
112 | 112 | only_rx['down'] = False |
|
113 | 113 | |
|
114 | 114 | antenna = {'antenna_up': up_values_list, 'antenna_down': down_values_list} |
|
115 | 115 | tx = {'up': up_txvalues_list, 'down': down_txvalues_list} |
|
116 | 116 | rx = {'up': up_rxvalues_list, 'down': down_rxvalues_list} |
|
117 | 117 | ues = {'up': list_uesup, 'down': list_uesdown} |
|
118 | 118 | name = str(form_data['beam_name']) |
|
119 | 119 | |
|
120 | 120 | beam_data = {'name': name, 'antenna': antenna, 'tx': tx, 'rx': rx, 'ues': ues, 'only_rx': only_rx} |
|
121 | 121 | |
|
122 | 122 | return beam_data |
|
123 | 123 | |
|
124 | 124 | |
|
125 | 125 | def abs_conf(request, id_conf): |
|
126 | 126 | |
|
127 | 127 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
128 | 128 | beams = ABSBeam.objects.filter(abs_conf=conf) |
|
129 | 129 | #------------Colors for Active Beam:------------- |
|
130 | 130 | all_status = {} |
|
131 | 131 | module_messages = json.loads(conf.module_messages) |
|
132 | 132 | |
|
133 | 133 | color_status = {} |
|
134 | 134 | for i, status in enumerate(conf.module_status): |
|
135 | 135 | if status == '3': #Running background-color: #00cc00; |
|
136 | 136 | all_status['{}'.format(i+1)] = 2 |
|
137 | 137 | color_status['{}'.format(i+1)] = 'class=text-success'#'bgcolor=#00cc00' |
|
138 | 138 | elif status == '2': |
|
139 | 139 | all_status['{}'.format(i+1)] = 1 |
|
140 | 140 | color_status['{}'.format(i+1)] = 'class=text-info' |
|
141 | 141 | elif status == '1': #Connected background-color: #ee902c; |
|
142 | 142 | all_status['{}'.format(i+1)] = 1 |
|
143 | 143 | color_status['{}'.format(i+1)] = 'class=text-warning'#'bgcolor=#ee902c' |
|
144 | 144 | else: #Disconnected background-color: #ff0000; |
|
145 | 145 | all_status['{}'.format(i+1)] = 0 |
|
146 | 146 | color_status['{}'.format(i+1)] = 'class=text-danger'#'bgcolor=#FF0000' |
|
147 | 147 | #------------------------------------------------ |
|
148 | 148 | |
|
149 | 149 | kwargs = {} |
|
150 | 150 | kwargs['connected_modules'] = str(conf.connected_modules())+'/64' |
|
151 | 151 | kwargs['dev_conf'] = conf |
|
152 | 152 | |
|
153 | 153 | if conf.operation_mode == 0: |
|
154 | 154 | kwargs['dev_conf_keys'] = ['label', 'operation_mode'] |
|
155 | 155 | else: |
|
156 | 156 | kwargs['dev_conf_keys'] = ['label', 'operation_mode', 'operation_value'] |
|
157 | 157 | |
|
158 | 158 | kwargs['title'] = 'ABS Configuration' |
|
159 | 159 | kwargs['suptitle'] = 'Details' |
|
160 | 160 | kwargs['button'] = 'Edit Configuration' |
|
161 | 161 | |
|
162 | 162 | if conf.active_beam != 0: |
|
163 | 163 | kwargs['active_beam'] = int(conf.active_beam) |
|
164 | 164 | |
|
165 | 165 | kwargs['beams'] = beams |
|
166 | 166 | kwargs['modules_status'] = all_status |
|
167 | 167 | kwargs['color_status'] = color_status |
|
168 | 168 | kwargs['module_messages'] = module_messages |
|
169 | 169 | ###### SIDEBAR ###### |
|
170 | 170 | kwargs.update(sidebar(conf=conf)) |
|
171 | 171 | |
|
172 | 172 | return render(request, 'abs_conf.html', kwargs) |
|
173 | 173 | |
|
174 | 174 | |
|
175 | 175 | def abs_conf_edit(request, id_conf): |
|
176 | 176 | |
|
177 | 177 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
178 | 178 | |
|
179 | 179 | beams = ABSBeam.objects.filter(abs_conf=conf) |
|
180 | 180 | |
|
181 | 181 | if request.method=='GET': |
|
182 | 182 | form = ABSConfigurationForm(instance=conf) |
|
183 | 183 | |
|
184 | 184 | if request.method=='POST': |
|
185 | 185 | form = ABSConfigurationForm(request.POST, instance=conf) |
|
186 | 186 | |
|
187 | 187 | if form.is_valid(): |
|
188 | 188 | conf = form.save(commit=False) |
|
189 | 189 | conf.save() |
|
190 | 190 | return redirect('url_abs_conf', id_conf=conf.id) |
|
191 | 191 | |
|
192 | 192 | ###### SIDEBAR ###### |
|
193 | 193 | kwargs = {} |
|
194 | 194 | |
|
195 | 195 | kwargs['dev_conf'] = conf |
|
196 | 196 | #kwargs['id_dev'] = conf.id |
|
197 | 197 | kwargs['id_conf'] = conf.id |
|
198 | 198 | kwargs['form'] = form |
|
199 | 199 | kwargs['abs_beams'] = beams |
|
200 | 200 | kwargs['title'] = 'Device Configuration' |
|
201 | 201 | kwargs['suptitle'] = 'Edit' |
|
202 | 202 | kwargs['button'] = 'Save' |
|
203 | 203 | |
|
204 | 204 | kwargs['edit'] = True |
|
205 | 205 | |
|
206 | 206 | return render(request, 'abs_conf_edit.html', kwargs) |
|
207 | 207 | |
|
208 | 208 | @csrf_exempt |
|
209 | 209 | def abs_conf_alert(request): |
|
210 | 210 | |
|
211 | 211 | if request.method == 'POST': |
|
212 | 212 | print (request.POST) |
|
213 | 213 | return HttpResponse(json.dumps({'result':1}), content_type='application/json') |
|
214 | 214 | else: |
|
215 | 215 | return redirect('index') |
|
216 | 216 | |
|
217 | 217 | |
|
218 | 218 | def import_file(request, id_conf): |
|
219 | 219 | |
|
220 | 220 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
221 | 221 | if request.method=='POST': |
|
222 | 222 | form = ABSImportForm(request.POST, request.FILES) |
|
223 | 223 | if form.is_valid(): |
|
224 | 224 | try: |
|
225 | 225 | parms = conf.import_from_file(request.FILES['file_name']) |
|
226 | 226 | |
|
227 | 227 | if parms: |
|
228 | 228 | conf.update_from_file(parms) |
|
229 | 229 | messages.success(request, 'Configuration "%s" loaded succesfully' % request.FILES['file_name']) |
|
230 | 230 | return redirect(conf.get_absolute_url_edit()) |
|
231 | 231 | |
|
232 | 232 | except Exception as e: |
|
233 | 233 | messages.error(request, 'Error parsing file: "%s" - %s' % (request.FILES['file_name'], e)) |
|
234 | 234 | |
|
235 | 235 | else: |
|
236 | 236 | messages.warning(request, 'Your current configuration will be replaced') |
|
237 | 237 | form = ABSImportForm() |
|
238 | 238 | |
|
239 | 239 | kwargs = {} |
|
240 | 240 | kwargs['form'] = form |
|
241 | 241 | kwargs['title'] = 'ABS Configuration' |
|
242 | 242 | kwargs['suptitle'] = 'Import file' |
|
243 | 243 | kwargs['button'] = 'Upload' |
|
244 | 244 | kwargs['previous'] = conf.get_absolute_url() |
|
245 | 245 | |
|
246 | 246 | return render(request, 'abs_import.html', kwargs) |
|
247 | 247 | |
|
248 | 248 | |
|
249 | 249 | def start(request, id_conf, id_beam): |
|
250 | 250 | |
|
251 | 251 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
252 | conf.start_device(id_beam) | |
|
253 | 252 | beams_list = ABSBeam.objects.filter(abs_conf=conf) |
|
254 |
f |
|
|
253 | if id_beam>=len(beams_list): | |
|
254 | return HttpResponse(json.dumps({'result':0}), content_type='application/json') | |
|
255 | conf.start_device(id_beam) | |
|
256 | ||
|
257 | for i, beam in enumerate(beams_list): | |
|
255 | 258 | if i==int(id_beam): |
|
256 | 259 | conf.active_beam = beam.pk |
|
257 | 260 | break |
|
258 | 261 | |
|
259 | 262 | return HttpResponse(json.dumps({'result':1}), content_type='application/json') |
|
260 | 263 | |
|
261 | 264 | |
|
262 | 265 | def send_beam(request, id_conf, id_beam): |
|
263 | 266 | |
|
264 | 267 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
265 | 268 | |
|
266 | 269 | abs = Configuration.objects.filter(pk=conf.device.conf_active).first() |
|
267 | 270 | if abs!=conf: |
|
268 | 271 | url = '#' if abs is None else abs.get_absolute_url() |
|
269 | 272 | label = 'None' if abs is None else abs.label |
|
270 | 273 | messages.warning( |
|
271 | 274 | request, |
|
272 | 275 | mark_safe('The current configuration has not been written in the modules, the active configuration is <a href="{}">{}</a>'.format( |
|
273 | 276 | url, |
|
274 | 277 | label |
|
275 | 278 | )) |
|
276 | 279 | ) |
|
277 | 280 | return redirect(conf.get_absolute_url()) |
|
278 | 281 | |
|
279 | 282 | beam = get_object_or_404(ABSBeam, pk=id_beam) |
|
280 | 283 | |
|
281 | 284 | if request.method == 'POST': |
|
282 | 285 | |
|
283 | 286 | beams_list = ABSBeam.objects.filter(abs_conf=conf) |
|
284 | 287 | conf.active_beam = id_beam |
|
285 | 288 | |
|
286 | 289 | i = 0 |
|
287 | 290 | for b in beams_list: |
|
288 | 291 | if b.id == int(id_beam): |
|
289 | 292 | break |
|
290 | 293 | else: |
|
291 | 294 | i += 1 |
|
292 | 295 | beam_pos = i + 1 #Estandarizar |
|
293 | 296 | print ('%s Position: %s') % (beam.name, str(beam_pos)) |
|
294 | 297 | conf.send_beam(beam_pos) |
|
295 | 298 | |
|
296 | 299 | return redirect('url_abs_conf', conf.id) |
|
297 | 300 | |
|
298 | 301 | kwargs = { |
|
299 | 302 | 'title': 'ABS', |
|
300 | 303 | 'suptitle': conf.label, |
|
301 | 304 | 'message': 'Are you sure you want to change ABS Beam to: {}?'.format(beam.name), |
|
302 | 305 | 'delete': False |
|
303 | 306 | } |
|
304 | 307 | kwargs['menu_configurations'] = 'active' |
|
305 | 308 | |
|
306 | 309 | return render(request, 'confirm.html', kwargs) |
|
307 | 310 | |
|
308 | 311 | |
|
309 | 312 | def add_beam(request, id_conf): |
|
310 | 313 | |
|
311 | 314 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
312 | 315 | confs = Configuration.objects.all() |
|
313 | 316 | |
|
314 | 317 | if request.method=='GET': |
|
315 | 318 | form = ABSBeamAddForm() |
|
316 | 319 | |
|
317 | 320 | if request.method=='POST': |
|
318 | 321 | form = ABSBeamAddForm(request.POST) |
|
319 | 322 | |
|
320 | 323 | beam_data = get_values_from_form(request.POST) |
|
321 | 324 | |
|
322 | 325 | new_beam = ABSBeam( |
|
323 | 326 | name = beam_data['name'], |
|
324 | 327 | antenna = json.dumps(beam_data['antenna']), |
|
325 | 328 | abs_conf = conf, |
|
326 | 329 | tx = json.dumps(beam_data['tx']), |
|
327 | 330 | rx = json.dumps(beam_data['rx']), |
|
328 | 331 | ues = json.dumps(beam_data['ues']), |
|
329 | 332 | only_rx = json.dumps(beam_data['only_rx']) |
|
330 | 333 | ) |
|
331 | 334 | new_beam.save() |
|
332 | 335 | messages.success(request, 'Beam: "%s" has been added.' % new_beam.name) |
|
333 | 336 | |
|
334 | 337 | return redirect('url_edit_abs_conf', conf.id) |
|
335 | 338 | |
|
336 | 339 | ###### SIDEBAR ###### |
|
337 | 340 | kwargs = {} |
|
338 | 341 | |
|
339 | 342 | #kwargs['dev_conf'] = conf.device |
|
340 | 343 | #kwargs['id_dev'] = conf.device |
|
341 | 344 | #kwargs['previous'] = conf.get_absolute_url_edit() |
|
342 | 345 | kwargs['id_conf'] = conf.id |
|
343 | 346 | kwargs['form'] = form |
|
344 | 347 | kwargs['title'] = 'ABS Beams' |
|
345 | 348 | kwargs['suptitle'] = 'Add Beam' |
|
346 | 349 | kwargs['button'] = 'Add' |
|
347 | 350 | kwargs['no_sidebar'] = True |
|
348 | 351 | kwargs['edit'] = True |
|
349 | 352 | |
|
350 | 353 | return render(request, 'abs_add_beam.html', kwargs) |
|
351 | 354 | |
|
352 | 355 | |
|
353 | 356 | def edit_beam(request, id_conf, id_beam): |
|
354 | 357 | |
|
355 | 358 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
356 | 359 | beam = get_object_or_404(ABSBeam, pk=id_beam) |
|
357 | 360 | |
|
358 | 361 | if request.method=='GET': |
|
359 | 362 | form = ABSBeamEditForm(initial={'beam': beam}) |
|
360 | 363 | |
|
361 | 364 | if request.method=='POST': |
|
362 | 365 | form = ABSBeamEditForm(request.POST) |
|
363 | 366 | |
|
364 | 367 | beam_data = get_values_from_form(request.POST) |
|
365 | 368 | |
|
366 | 369 | beam.dict_to_parms(beam_data) |
|
367 | 370 | beam.save() |
|
368 | 371 | |
|
369 | 372 | messages.success(request, 'Beam: "%s" has been updated.' % beam.name) |
|
370 | 373 | |
|
371 | 374 | return redirect('url_edit_abs_conf', conf.id) |
|
372 | 375 | |
|
373 | 376 | ###### SIDEBAR ###### |
|
374 | 377 | kwargs = {} |
|
375 | 378 | |
|
376 | 379 | kwargs['id_conf'] = conf.id |
|
377 | 380 | kwargs['form'] = form |
|
378 | 381 | kwargs['title'] = 'ABS Beams' |
|
379 | 382 | kwargs['suptitle'] = 'Edit Beam' |
|
380 | 383 | kwargs['button'] = 'Save' |
|
381 | 384 | kwargs['no_sidebar'] = True |
|
382 | 385 | |
|
383 | 386 | #kwargs['previous'] = conf.get_absolute_url_edit() |
|
384 | 387 | kwargs['edit'] = True |
|
385 | 388 | |
|
386 | 389 | return render(request, 'abs_edit_beam.html', kwargs) |
|
387 | 390 | |
|
388 | 391 | |
|
389 | 392 | |
|
390 | 393 | def remove_beam(request, id_conf, id_beam): |
|
391 | 394 | |
|
392 | 395 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
393 | 396 | beam = get_object_or_404(ABSBeam, pk=id_beam) |
|
394 | 397 | |
|
395 | 398 | if request.method=='POST': |
|
396 | 399 | if beam: |
|
397 | 400 | try: |
|
398 | 401 | beam.delete() |
|
399 | 402 | messages.success(request, 'Beam: "%s" has been deleted.' % beam) |
|
400 | 403 | except: |
|
401 | 404 | messages.error(request, 'Unable to delete beam: "%s".' % beam) |
|
402 | 405 | |
|
403 | 406 | return redirect('url_edit_abs_conf', conf.id) |
|
404 | 407 | |
|
405 | 408 | ###### SIDEBAR ###### |
|
406 | 409 | kwargs = {} |
|
407 | 410 | |
|
408 | 411 | kwargs['object'] = beam |
|
409 | 412 | kwargs['delete'] = True |
|
410 | 413 | kwargs['title'] = 'Delete' |
|
411 | 414 | kwargs['suptitle'] = 'Beam' |
|
412 | 415 | kwargs['previous'] = conf.get_absolute_url_edit() |
|
413 | 416 | return render(request, 'confirm.html', kwargs) |
|
414 | 417 | |
|
415 | 418 | |
|
416 | 419 | |
|
417 | 420 | def plot_patterns(request, id_conf, id_beam=None): |
|
418 | 421 | |
|
419 | 422 | kwargs = {} |
|
420 | 423 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
421 | 424 | beams = ABSBeam.objects.filter(abs_conf=conf) |
|
422 | 425 | |
|
423 | 426 | if id_beam: |
|
424 | 427 | beam = get_object_or_404(ABSBeam, pk=id_beam) |
|
425 | 428 | kwargs['beam'] = beam |
|
426 | 429 | |
|
427 | 430 | ###### SIDEBAR ###### |
|
428 | 431 | |
|
429 | 432 | kwargs['dev_conf'] = conf.device |
|
430 | 433 | kwargs['id_dev'] = conf.device |
|
431 | 434 | kwargs['id_conf'] = conf.id |
|
432 | 435 | kwargs['abs_beams'] = beams |
|
433 | 436 | kwargs['title'] = 'ABS Patterns' |
|
434 | 437 | kwargs['suptitle'] = conf.name |
|
435 | 438 | kwargs['no_sidebar'] = True |
|
436 | 439 | |
|
437 | 440 | return render(request, 'abs_patterns.html', kwargs) |
|
438 | 441 | |
|
439 | 442 | |
|
440 | 443 | def plot_pattern(request, id_conf, id_beam, antenna): |
|
441 | 444 | |
|
442 | 445 | if antenna=='down': |
|
443 | 446 | sleep(3) |
|
444 | 447 | |
|
445 | 448 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
446 | 449 | beam = get_object_or_404(ABSBeam, pk=id_beam) |
|
447 | 450 | just_rx = 1 if json.loads(beam.only_rx)[antenna] else 0 |
|
448 | 451 | phases = json.loads(beam.antenna)['antenna_{}'.format(antenna)] |
|
449 | 452 | gain_tx = json.loads(beam.tx)[antenna] |
|
450 | 453 | gain_rx = json.loads(beam.rx)[antenna] |
|
451 | 454 | ues = json.loads(beam.ues)[antenna] |
|
452 | 455 | newOverJro = overJroShow(beam.name) |
|
453 | 456 | fig = newOverJro.plotPattern2(datetime.today(), phases, gain_tx, gain_rx, ues, just_rx) |
|
454 | 457 | buf = io.BytesIO() |
|
455 | 458 | fig.savefig(buf, format='png') |
|
456 | 459 | response = HttpResponse(buf.getvalue(), content_type='image/png') |
|
457 | 460 | return response |
|
458 | 461 |
General Comments 0
You need to be logged in to leave comments.
Login now