@@ -0,0 +1,19 | |||
|
1 | $(document).ready(function() { | |
|
2 | updateOperationMode() | |
|
3 | }); | |
|
4 | ||
|
5 | $("#id_operation_mode").on('change', function() { | |
|
6 | updateOperationMode() | |
|
7 | }); | |
|
8 | ||
|
9 | function updateOperationMode(){ | |
|
10 | var operation_mode = $("#id_operation_mode").val(); | |
|
11 | if (operation_mode==0){ | |
|
12 | document.getElementById("id_operation_value").disabled=true; | |
|
13 | $("#id_operation_value").hide(); | |
|
14 | } | |
|
15 | else { | |
|
16 | document.getElementById("id_operation_value").disabled=false; | |
|
17 | $("#id_operation_value").show(); | |
|
18 | } | |
|
19 | } |
@@ -1,1038 +1,1038 | |||
|
1 | 1 | from django.db import models |
|
2 | 2 | from apps.main.models import Configuration |
|
3 | 3 | from django.core.urlresolvers import reverse |
|
4 | 4 | # Create your models here. |
|
5 | 5 | |
|
6 | 6 | import ast |
|
7 | 7 | import socket |
|
8 | 8 | import json |
|
9 | 9 | import requests |
|
10 | 10 | import struct |
|
11 | 11 | import sys, time |
|
12 | 12 | |
|
13 | 13 | import multiprocessing |
|
14 | 14 | |
|
15 | 15 | |
|
16 | 16 | antenna_default = json.dumps({ |
|
17 | 17 | "antenna_up": [[0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
18 | 18 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
19 | 19 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
20 | 20 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
21 | 21 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0], |
|
22 | 22 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0], |
|
23 | 23 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0], |
|
24 | 24 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0] |
|
25 | 25 | ] |
|
26 | 26 | , |
|
27 | 27 | "antenna_down": [[0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
28 | 28 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
29 | 29 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
30 | 30 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
31 | 31 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0], |
|
32 | 32 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0], |
|
33 | 33 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0], |
|
34 | 34 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0]], |
|
35 | 35 | }) |
|
36 | 36 | |
|
37 | 37 | |
|
38 | 38 | tx_default = json.dumps({ |
|
39 | 39 | "up": [[1,1,1,1,0,0,0,0], |
|
40 | 40 | [1,1,1,1,0,0,0,0], |
|
41 | 41 | [1,1,1,1,0,0,0,0], |
|
42 | 42 | [1,1,1,1,0,0,0,0], |
|
43 | 43 | [0,0,0,0,1,1,1,1], |
|
44 | 44 | [0,0,0,0,1,1,1,1], |
|
45 | 45 | [0,0,0,0,1,1,1,1], |
|
46 | 46 | [0,0,0,0,1,1,1,1]], |
|
47 | 47 | |
|
48 | 48 | "down": [[1,1,1,1,0,0,0,0], |
|
49 | 49 | [1,1,1,1,0,0,0,0], |
|
50 | 50 | [1,1,1,1,0,0,0,0], |
|
51 | 51 | [1,1,1,1,0,0,0,0], |
|
52 | 52 | [0,0,0,0,1,1,1,1], |
|
53 | 53 | [0,0,0,0,1,1,1,1], |
|
54 | 54 | [0,0,0,0,1,1,1,1], |
|
55 | 55 | [0,0,0,0,1,1,1,1]], |
|
56 | 56 | }) |
|
57 | 57 | |
|
58 | 58 | rx_default = json.dumps({ |
|
59 | 59 | "up": [[1,1,1,1,0,0,0,0], |
|
60 | 60 | [1,1,1,1,0,0,0,0], |
|
61 | 61 | [1,1,1,1,0,0,0,0], |
|
62 | 62 | [1,1,1,1,0,0,0,0], |
|
63 | 63 | [0,0,0,0,1,1,1,1], |
|
64 | 64 | [0,0,0,0,1,1,1,1], |
|
65 | 65 | [0,0,0,0,1,1,1,1], |
|
66 | 66 | [0,0,0,0,1,1,1,1]], |
|
67 | 67 | |
|
68 | 68 | "down": [[1,1,1,1,0,0,0,0], |
|
69 | 69 | [1,1,1,1,0,0,0,0], |
|
70 | 70 | [1,1,1,1,0,0,0,0], |
|
71 | 71 | [1,1,1,1,0,0,0,0], |
|
72 | 72 | [0,0,0,0,1,1,1,1], |
|
73 | 73 | [0,0,0,0,1,1,1,1], |
|
74 | 74 | [0,0,0,0,1,1,1,1], |
|
75 | 75 | [0,0,0,0,1,1,1,1]], |
|
76 | 76 | }) |
|
77 | 77 | |
|
78 | 78 | conf_default = {} |
|
79 | 79 | status_default = {} |
|
80 | 80 | for i in range(1,65): |
|
81 | 81 | conf_default[str(i)] = "" |
|
82 | 82 | status_default[str(i)] = 0 |
|
83 | 83 | |
|
84 | 84 | ues_default = json.dumps({ |
|
85 | 85 | "up": [0.533333,0.00000,1.06667,0.00000], |
|
86 | 86 | "down": [0.533333,0.00000,1.06667,0.00000] |
|
87 | 87 | }) |
|
88 | 88 | |
|
89 | 89 | onlyrx_default = json.dumps({ |
|
90 | 90 | "up": False, |
|
91 | 91 | "down": False |
|
92 | 92 | }) |
|
93 | 93 | |
|
94 | 94 | def up_convertion(cadena): |
|
95 | 95 | valores = [] |
|
96 | 96 | for c in cadena: |
|
97 | 97 | if c == 1.0: valores=valores+['000'] |
|
98 | 98 | if c == 2.0: valores=valores+['001'] |
|
99 | 99 | if c == 3.0: valores=valores+['010'] |
|
100 | 100 | if c == 0.0: valores=valores+['011'] |
|
101 | 101 | if c == 0.5: valores=valores+['100'] |
|
102 | 102 | if c == 1.5: valores=valores+['101'] |
|
103 | 103 | if c == 2.5: valores=valores+['110'] |
|
104 | 104 | if c == 3.5: valores=valores+['111'] |
|
105 | 105 | |
|
106 | 106 | return valores |
|
107 | 107 | |
|
108 | 108 | def up_conv_bits(value): |
|
109 | 109 | |
|
110 | 110 | if value == 1.0: bits="000" |
|
111 | 111 | if value == 2.0: bits="001" |
|
112 | 112 | if value == 3.0: bits="010" |
|
113 | 113 | if value == 0.0: bits="011" |
|
114 | 114 | if value == 0.5: bits="100" |
|
115 | 115 | if value == 1.5: bits="101" |
|
116 | 116 | if value == 2.5: bits="110" |
|
117 | 117 | if value == 3.5: bits="111" |
|
118 | 118 | |
|
119 | 119 | return bits |
|
120 | 120 | |
|
121 | 121 | def down_convertion(cadena): |
|
122 | 122 | valores = [] |
|
123 | 123 | for c in cadena: |
|
124 | 124 | if c == 1.0: valores=valores+['000'] |
|
125 | 125 | if c == 2.0: valores=valores+['001'] |
|
126 | 126 | if c == 3.0: valores=valores+['010'] |
|
127 | 127 | if c == 0.0: valores=valores+['011'] |
|
128 | 128 | if c == 0.5: valores=valores+['100'] |
|
129 | 129 | if c == 1.5: valores=valores+['101'] |
|
130 | 130 | if c == 2.5: valores=valores+['110'] |
|
131 | 131 | if c == 3.5: valores=valores+['111'] |
|
132 | 132 | |
|
133 | 133 | return valores |
|
134 | 134 | |
|
135 | 135 | def down_conv_bits(value): |
|
136 | 136 | |
|
137 | 137 | if value == 1.0: bits="000" |
|
138 | 138 | if value == 2.0: bits="001" |
|
139 | 139 | if value == 3.0: bits="010" |
|
140 | 140 | if value == 0.0: bits="011" |
|
141 | 141 | if value == 0.5: bits="100" |
|
142 | 142 | if value == 1.5: bits="101" |
|
143 | 143 | if value == 2.5: bits="110" |
|
144 | 144 | if value == 3.5: bits="111" |
|
145 | 145 | |
|
146 | 146 | return bits |
|
147 | 147 | |
|
148 | 148 | def ip2position(module_number): |
|
149 | 149 | j=0 |
|
150 | 150 | i=0 |
|
151 | 151 | for x in range(0,module_number-1): |
|
152 | 152 | j=j+1 |
|
153 | 153 | if j==8: |
|
154 | 154 | i=i+1 |
|
155 | 155 | j=0 |
|
156 | 156 | |
|
157 | 157 | pos = [i,j] |
|
158 | 158 | return pos |
|
159 | 159 | |
|
160 | 160 | |
|
161 | 161 | def fromBinary2Char(binary_string): |
|
162 | 162 | number = int(binary_string, 2) |
|
163 | 163 | #Plus 33 to avoid more than 1 characters values such as: '\x01'-'\x1f' |
|
164 | 164 | number = number + 33 |
|
165 | 165 | char = chr(number) |
|
166 | 166 | return char |
|
167 | 167 | |
|
168 | 168 | def fromChar2Binary(char): |
|
169 | 169 | number = ord(char) - 33 |
|
170 | 170 | #Minus 33 to get the real value |
|
171 | 171 | bits = bin(number)[2:] |
|
172 | 172 | #To ensure we have a string with 6bits |
|
173 | 173 | if len(bits) < 6: |
|
174 | 174 | bits = bits.zfill(6) |
|
175 | 175 | return bits |
|
176 | 176 | |
|
177 | 177 | OPERATION_MODES = ( |
|
178 | 178 | (0, 'Manual'), |
|
179 | 179 | (1, 'Automatic'), |
|
180 | 180 | ) |
|
181 | 181 | |
|
182 | 182 | |
|
183 | 183 | class ABSConfiguration(Configuration): |
|
184 | 184 | active_beam = models.CharField(verbose_name='Active Beam', max_length=20000, default="{}") |
|
185 | 185 | module_status = models.CharField(verbose_name='Module Status', max_length=10000, default=json.dumps(status_default)) |
|
186 |
operation_mode = models. |
|
|
187 |
operation_value = models. |
|
|
186 | operation_mode = models.PositiveSmallIntegerField(verbose_name='Operation Mode', choices=OPERATION_MODES, default = 0) | |
|
187 | operation_value = models.FloatField(verbose_name='Periodic (seconds)', default="10", null=True, blank=True) | |
|
188 | 188 | |
|
189 | 189 | class Meta: |
|
190 | 190 | db_table = 'abs_configurations' |
|
191 | 191 | |
|
192 | 192 | def get_absolute_url_plot(self): |
|
193 | 193 | return reverse('url_plot_abs_patterns', args=[str(self.id)]) |
|
194 | 194 | |
|
195 | 195 | |
|
196 | 196 | def parms_to_dict(self): |
|
197 | 197 | |
|
198 | 198 | parameters = {} |
|
199 | 199 | |
|
200 | 200 | parameters['device_id'] = self.device.id |
|
201 | 201 | parameters['name'] = self.name |
|
202 | 202 | parameters['beams'] = {} |
|
203 | 203 | |
|
204 | 204 | beams = ABSBeam.objects.filter(abs_conf=self) |
|
205 | 205 | b=1 |
|
206 | 206 | for beam in beams: |
|
207 | 207 | #absbeam = ABSBeam.objects.get(pk=beams[beam]) |
|
208 | 208 | parameters['beams']['beam'+str(b)] = beam.parms_to_dict()#absbeam.parms_to_dict() |
|
209 | 209 | b+=1 |
|
210 | 210 | |
|
211 | 211 | return parameters |
|
212 | 212 | |
|
213 | 213 | def dict_to_parms(self, parameters): |
|
214 | 214 | |
|
215 | 215 | self.name = parameters['name'] |
|
216 | 216 | |
|
217 | 217 | absbeams = ABSBeam.objects.filter(abs_conf=self) |
|
218 | 218 | beams = parameters['beams'] |
|
219 | 219 | |
|
220 | 220 | if absbeams: |
|
221 | 221 | beams_number = len(beams) |
|
222 | 222 | absbeams_number = len(absbeams) |
|
223 | 223 | if beams_number==absbeams_number: |
|
224 | 224 | i = 1 |
|
225 | 225 | for absbeam in absbeams: |
|
226 | 226 | absbeam.dict_to_parms(beams['beam'+str(i)]) |
|
227 | 227 | i = i+1 |
|
228 | 228 | elif beams_number > absbeams_number: |
|
229 | 229 | i = 1 |
|
230 | 230 | for absbeam in absbeams: |
|
231 | 231 | absbeam.dict_to_parms(beams['beam'+str(i)]) |
|
232 | 232 | i=i+1 |
|
233 | 233 | for x in range(i,beams_number+1): |
|
234 | 234 | new_beam = ABSBeam( |
|
235 | 235 | name =beams['beam'+str(i)]['name'], |
|
236 | 236 | antenna =json.dumps(beams['beam'+str(i)]['antenna']), |
|
237 | 237 | abs_conf = self, |
|
238 | 238 | tx =json.dumps(beams['beam'+str(i)]['tx']), |
|
239 | 239 | rx =json.dumps(beams['beam'+str(i)]['rx']), |
|
240 | 240 | ues =json.dumps(beams['beam'+str(i)]['ues']), |
|
241 | 241 | only_rx =json.dumps(beams['beam'+str(i)]['only_rx']) |
|
242 | 242 | ) |
|
243 | 243 | new_beam.save() |
|
244 | 244 | i=i+1 |
|
245 | 245 | else: #beams_number < absbeams_number: |
|
246 | 246 | i = 1 |
|
247 | 247 | for absbeam in absbeams: |
|
248 | 248 | if i <= beams_number: |
|
249 | 249 | absbeam.dict_to_parms(beams['beam'+str(i)]) |
|
250 | 250 | i=i+1 |
|
251 | 251 | else: |
|
252 | 252 | absbeam.delete() |
|
253 | 253 | else: |
|
254 | 254 | for beam in beams: |
|
255 | 255 | new_beam = ABSBeam( |
|
256 | 256 | name =beams[beam]['name'], |
|
257 | 257 | antenna =json.dumps(beams[beam]['antenna']), |
|
258 | 258 | abs_conf = self, |
|
259 | 259 | tx =json.dumps(beams[beam]['tx']), |
|
260 | 260 | rx =json.dumps(beams[beam]['rx']), |
|
261 | 261 | ues =json.dumps(beams[beam]['ues']), |
|
262 | 262 | only_rx =json.dumps(beams[beam]['only_rx']) |
|
263 | 263 | ) |
|
264 | 264 | new_beam.save() |
|
265 | 265 | |
|
266 | 266 | |
|
267 | 267 | |
|
268 | 268 | def update_from_file(self, parameters): |
|
269 | 269 | |
|
270 | 270 | self.dict_to_parms(parameters) |
|
271 | 271 | self.save() |
|
272 | 272 | |
|
273 | 273 | |
|
274 | 274 | def get_beams(self, **kwargs): |
|
275 | 275 | ''' |
|
276 | 276 | This function returns ABS Configuration beams |
|
277 | 277 | ''' |
|
278 | 278 | return ABSBeam.objects.filter(abs_conf=self.pk, **kwargs) |
|
279 | 279 | |
|
280 | 280 | def clone(self, **kwargs): |
|
281 | 281 | |
|
282 | 282 | beams = self.get_beams() |
|
283 | 283 | self.pk = None |
|
284 | 284 | self.id = None |
|
285 | 285 | for attr, value in kwargs.items(): |
|
286 | 286 | setattr(self, attr, value) |
|
287 | 287 | self.save() |
|
288 | 288 | |
|
289 | 289 | for beam in beams: |
|
290 | 290 | beam.clone(abs_conf=self) |
|
291 | 291 | |
|
292 | 292 | return self |
|
293 | 293 | |
|
294 | 294 | |
|
295 | 295 | def module_conf(self, module_num, beams): |
|
296 | 296 | """ |
|
297 | 297 | This function creates beam configurations for one abs module. |
|
298 | 298 | """ |
|
299 | 299 | ip_address = self.device.ip_address |
|
300 | 300 | ip_address = ip_address.split('.') |
|
301 | 301 | module_seq = (ip_address[0],ip_address[1],ip_address[2]) |
|
302 | 302 | dot = '.' |
|
303 | 303 | module_ip = dot.join(module_seq)+'.'+str(module_num) |
|
304 | 304 | module_port = self.device.port_address |
|
305 | 305 | write_route = 'http://'+module_ip+':'+str(module_port)+'/write' |
|
306 | 306 | |
|
307 | 307 | header = 'JROABSCeCnModCnMod01000108SNDFexperimento1.ab1' |
|
308 | 308 | module = 'ABS_'+str(module_num) |
|
309 | 309 | bs = '' #{} |
|
310 | 310 | i=1 |
|
311 | 311 | #beams = {1: '001000', 2: '010001', 3: '010010', 4: '000011', 5: '101100', 6: '101101', |
|
312 | 312 | # 7: '110110', 8: '111111', 9: '000000', 10: '001001', 11: '010010', 12: '011011'} |
|
313 | 313 | for beam in beams: |
|
314 | 314 | #bs[i] = fromBinary2Char(beam.module_6bits(module_num)) |
|
315 | 315 | bs = bs + fromBinary2Char(beam.module_6bits(module_num)) |
|
316 | 316 | i=i+1 |
|
317 | 317 | |
|
318 | 318 | beams = bs |
|
319 | 319 | |
|
320 | 320 | parameters = {} |
|
321 | 321 | parameters['header'] = header |
|
322 | 322 | parameters['module'] = module |
|
323 | 323 | parameters['beams'] = beams #json.dumps(beams) |
|
324 | 324 | print parameters['beams'] |
|
325 | 325 | answer = '' |
|
326 | 326 | |
|
327 | 327 | try: |
|
328 | 328 | r_write = requests.post(write_route, parameters, timeout=0.5) |
|
329 | 329 | answer = r_write.json() |
|
330 | 330 | self.message = answer['message'] |
|
331 | 331 | except: |
|
332 | 332 | self.message = "Could not write ABS parameters" |
|
333 | 333 | return 0 |
|
334 | 334 | return 1 |
|
335 | 335 | |
|
336 | 336 | def read_module(self, module): |
|
337 | 337 | |
|
338 | 338 | """ |
|
339 | 339 | Read out-bits (up-down) of 1 abs module NOT for Configuration |
|
340 | 340 | """ |
|
341 | 341 | |
|
342 | 342 | parameters = {} |
|
343 | 343 | ip_address = self.device.ip_address |
|
344 | 344 | ip_address = ip_address.split('.') |
|
345 | 345 | module_seq = (ip_address[0],ip_address[1],ip_address[2]) |
|
346 | 346 | dot = '.' |
|
347 | 347 | module_ip = dot.join(module_seq)+'.'+str(module) |
|
348 | 348 | module_port = self.device.port_address |
|
349 | 349 | read_route = 'http://'+module_ip+':'+str(module_port)+'/read' |
|
350 | 350 | |
|
351 | 351 | print(read_route) |
|
352 | 352 | |
|
353 | 353 | answer = '' |
|
354 | 354 | module_bits = '' |
|
355 | 355 | |
|
356 | 356 | try: |
|
357 | 357 | r_write = requests.get(read_route, timeout=0.7) |
|
358 | 358 | answer = r_write.json() |
|
359 | 359 | self.message = answer['message'] |
|
360 | 360 | module_bits = answer['allbits'] |
|
361 | 361 | except: |
|
362 | 362 | #message = "Could not read ABS parameters" |
|
363 | 363 | return 0 |
|
364 | 364 | |
|
365 | 365 | return module_bits |
|
366 | 366 | |
|
367 | 367 | |
|
368 | 368 | def read_module(self, module): |
|
369 | 369 | |
|
370 | 370 | return True |
|
371 | 371 | |
|
372 | 372 | def status_device(self): |
|
373 | 373 | """ |
|
374 | 374 | This function gets the status of each abs module. It sends GET method to Web Application |
|
375 | 375 | in Python Bottle. |
|
376 | 376 | """ |
|
377 | 377 | ip_address = self.device.ip_address |
|
378 | 378 | ip_address = ip_address.split('.') |
|
379 | 379 | module_seq = (ip_address[0],ip_address[1],ip_address[2]) |
|
380 | 380 | dot = '.' |
|
381 | 381 | module_port = self.device.port_address |
|
382 | 382 | |
|
383 | 383 | modules_status = json.loads(self.module_status) |
|
384 | 384 | |
|
385 | 385 | for i in range(1,65): |
|
386 | 386 | module_ip = dot.join(module_seq)+'.'+str(i) |
|
387 | 387 | print module_ip |
|
388 | 388 | |
|
389 | 389 | route = 'http://'+module_ip+':'+str(module_port)+'/hello' |
|
390 | 390 | |
|
391 | 391 | try: |
|
392 | 392 | r = requests.get(route, timeout=0.7) |
|
393 | 393 | modules_status[str(i)] = 1 |
|
394 | 394 | except: |
|
395 | 395 | modules_status[str(i)] = 0 |
|
396 | 396 | pass |
|
397 | 397 | |
|
398 | 398 | self.message = 'ABS modules Status have been updated.' |
|
399 | 399 | self.module_status=json.dumps(modules_status) |
|
400 | 400 | self.save() |
|
401 | 401 | |
|
402 | 402 | return |
|
403 | 403 | |
|
404 | 404 | |
|
405 | 405 | def write_device(self): |
|
406 | 406 | """ |
|
407 | 407 | This function sends the beams list to every abs module. |
|
408 | 408 | It needs 'module_conf' function |
|
409 | 409 | """ |
|
410 | 410 | |
|
411 | 411 | beams = ABSBeam.objects.filter(abs_conf=self) |
|
412 | 412 | |
|
413 | 413 | #-------------Write each abs module----------- |
|
414 | 414 | if beams: |
|
415 | 415 | beams_status = ast.literal_eval(self.module_status) |
|
416 |
for i in range(6 |
|
|
416 | for i in range(61,64): #(62,65) | |
|
417 | 417 | try: |
|
418 | 418 | answer = self.module_conf(i, beams) |
|
419 | 419 | beams_status[str(i)] = 1 |
|
420 | 420 | self.module_status = json.dumps(beams_status) |
|
421 | 421 | self.save() |
|
422 | 422 | |
|
423 | 423 | except: |
|
424 | 424 | beams_status[str(i)] = 0 |
|
425 | 425 | self.module_status = json.dumps(beams_status) |
|
426 | 426 | self.save() |
|
427 | 427 | answer = 0 |
|
428 | 428 | return 0 |
|
429 | 429 | else: |
|
430 | 430 | self.message = "ABS Configuration does not have beams" |
|
431 | 431 | return 0 |
|
432 | 432 | |
|
433 | 433 | #self.device.status = 1 |
|
434 | 434 | ## |
|
435 | 435 | if answer==1: |
|
436 | 436 | self.message = "ABS Beams List have been sent to ABS Modules" |
|
437 | 437 | beams[0].set_as_activebeam() |
|
438 | 438 | else: |
|
439 | 439 | self.message = "Could not read ABS parameters" |
|
440 | 440 | ## |
|
441 | 441 | self.save() |
|
442 | 442 | return 1 |
|
443 | 443 | |
|
444 | 444 | |
|
445 | 445 | def write_module(self, module): |
|
446 | 446 | |
|
447 | 447 | """ |
|
448 | 448 | Send configuration to one abs module |
|
449 | 449 | """ |
|
450 | 450 | |
|
451 | 451 | parameters = {} |
|
452 | 452 | ip_address = self.abs_conf.device.ip_address |
|
453 | 453 | ip_address = ip_address.split('.') |
|
454 | 454 | module_seq = (ip_address[0],ip_address[1],ip_address[2]) |
|
455 | 455 | dot = '.' |
|
456 | 456 | module_ip = dot.join(module_seq)+'.'+str(module) |
|
457 | 457 | module_port = self.abs_conf.device.port_address |
|
458 | 458 | write_route = 'http://'+module_ip+':'+str(module_port)+'/write' |
|
459 | 459 | |
|
460 | 460 | #print write_route |
|
461 | 461 | |
|
462 | 462 | header = 'JROABSCeCnModCnMod01000108SNDFexperimento1.ab1' |
|
463 | 463 | module = 'ABS_'+str(module) |
|
464 | 464 | beams = {1: '001000', 2: '010001', 3: '010010', 4: '000011', 5: '101100', 6: '101101', |
|
465 | 465 | 7: '110110', 8: '111111', 9: '000000', 10: '001001', 11: '010010', 12: '011011'} |
|
466 | 466 | |
|
467 | 467 | parameters['header'] = header |
|
468 | 468 | parameters['module'] = module |
|
469 | 469 | parameters['beams'] = json.dumps(beams) |
|
470 | 470 | |
|
471 | 471 | answer = '' |
|
472 | 472 | |
|
473 | 473 | try: |
|
474 | 474 | r_write = requests.post(write_route, parameters, timeout=0.5) |
|
475 | 475 | answer = r_write.json() |
|
476 | 476 | self.message = answer['message'] |
|
477 | 477 | except: |
|
478 | 478 | self.message = "Could not write ABS parameters" |
|
479 | 479 | return 0 |
|
480 | 480 | |
|
481 | 481 | |
|
482 | 482 | #self.device.status = int(answer['status']) |
|
483 | 483 | |
|
484 | 484 | return 1 |
|
485 | 485 | |
|
486 | 486 | |
|
487 | 487 | def beam_selector(self, module, beam_pos): |
|
488 | 488 | """ |
|
489 | 489 | This function selects the beam number for one absmodule. |
|
490 | 490 | """ |
|
491 | 491 | |
|
492 | 492 | if beam_pos > 0: |
|
493 | 493 | beam_pos = beam_pos - 1 |
|
494 | 494 | else: |
|
495 | 495 | beam_pos = 0 |
|
496 | 496 | |
|
497 | 497 | #El indice del apunte debe ser menor que el numero total de apuntes |
|
498 | 498 | #El servidor tcp en el embebido comienza a contar desde 0 |
|
499 | 499 | beams_list = ABSBeam.objects.filter(abs_conf=self) |
|
500 | 500 | if len(beams_list) < beam_pos: |
|
501 | 501 | return 0 |
|
502 | 502 | |
|
503 | 503 | flag = 1 |
|
504 | 504 | if beam_pos>9: |
|
505 | 505 | flag = 2 |
|
506 | 506 | |
|
507 | 507 | module_address = ('192.168.1.'+str(module), 5500) |
|
508 | 508 | header = 'JROABSCeCnModCnMod0100000' |
|
509 | 509 | numbers = len(str(beam_pos)) |
|
510 | 510 | function = 'CHGB' |
|
511 | 511 | |
|
512 | 512 | message_tx = header+str(numbers)+function+str(beam_pos)+'0' |
|
513 | 513 | |
|
514 | 514 | # Create the datagram socket |
|
515 | 515 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
516 | 516 | #sock.connect(module_address) |
|
517 | 517 | try: |
|
518 | 518 | sock.connect(module_address) |
|
519 | 519 | sock.send(message_tx) |
|
520 | 520 | sock.close() |
|
521 | 521 | print("Writing abs module:"+module_address[0]+"...") |
|
522 | 522 | except: |
|
523 | 523 | sock = None |
|
524 | 524 | print("Problem writing abs module:"+module_address[0]) |
|
525 | 525 | return 0 |
|
526 | 526 | |
|
527 | 527 | return 1 |
|
528 | 528 | |
|
529 | 529 | |
|
530 | 530 | def change_beam(self, beam_pos): |
|
531 | 531 | """ |
|
532 | 532 | This function selects the beam number for all absmodules. |
|
533 | 533 | """ |
|
534 | 534 | for i in range(1,65): |
|
535 | 535 | try: |
|
536 | 536 | self.beam_selector(i,beam_pos) |
|
537 | 537 | except: |
|
538 | 538 | print("Problem with module: 192.168.1."+str(i)) |
|
539 | 539 | self.message = "Problem with module: 192.168.1."+str(i) |
|
540 | 540 | #return 0 |
|
541 | 541 | return 1 |
|
542 | 542 | |
|
543 | 543 | |
|
544 | 544 | def send_beam_num(self, beam_pos): |
|
545 | 545 | """ |
|
546 | 546 | This function connects to a multicast group and sends the beam number |
|
547 | 547 | to all abs modules. |
|
548 | 548 | """ |
|
549 | 549 | |
|
550 | 550 | if beam_pos > 0: |
|
551 | 551 | beam_pos = beam_pos - 1 |
|
552 | 552 | else: |
|
553 | 553 | beam_pos = 0 |
|
554 | 554 | |
|
555 | 555 | #El indice del apunte debe ser menor que el numero total de apuntes |
|
556 | 556 | #El servidor tcp en el embebido comienza a contar desde 0 |
|
557 | 557 | beams_list = ABSBeam.objects.filter(abs_conf=self) |
|
558 | 558 | if len(beams_list) < beam_pos: |
|
559 | 559 | return 0 |
|
560 | 560 | |
|
561 | 561 | flag = 1 |
|
562 | 562 | if beam_pos>9: |
|
563 | 563 | flag = 2 |
|
564 | 564 | |
|
565 | 565 | header = 'JROABSCeCnModCnMod0100000' |
|
566 | 566 | flag = str(flag) |
|
567 | 567 | function = 'CHGB' |
|
568 | 568 | message_tx = header+flag+function+str(beam_pos)+'0' |
|
569 | 569 | |
|
570 | 570 | multicast_group = '224.3.29.71' |
|
571 | 571 | server_address = ('',10000) |
|
572 | 572 | |
|
573 | 573 | # Create the socket |
|
574 | 574 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
|
575 | 575 | # Bind to the server address |
|
576 | 576 | sock.bind(server_address) |
|
577 | 577 | # Telling the OS add the socket to the multicast on all interfaces |
|
578 | 578 | group = socket.inet_aton(multicast_group) |
|
579 | 579 | mreq = struct.pack('4sL', group, socket.INADDR_ANY) |
|
580 | 580 | sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq) |
|
581 | 581 | |
|
582 | 582 | #print 'sending acknowledgement to all: \n' + message_tx |
|
583 | 583 | sock.sendto(message_tx, (multicast_group, 10000)) |
|
584 | 584 | sock.close() |
|
585 | 585 | sock = None |
|
586 | 586 | |
|
587 | 587 | return 1 |
|
588 | 588 | |
|
589 | 589 | def test1(self): |
|
590 | 590 | t1 = time.time() |
|
591 | 591 | t2 = 0 |
|
592 | 592 | while (t2-t1)<100:#300 |
|
593 | 593 | t2 = time.time() |
|
594 | 594 | self.send_beam_num(2) |
|
595 | 595 | time.sleep(0.04) |
|
596 | 596 | self.send_beam_num(1) |
|
597 | 597 | time.sleep(0.04) |
|
598 | 598 | return |
|
599 | 599 | |
|
600 | 600 | def change_procs_test1(self, module): |
|
601 | 601 | |
|
602 | 602 | for i in range (1,300):#300 |
|
603 | 603 | beam_pos = 1 |
|
604 | 604 | module_address = ('192.168.1.'+str(module), 5500) |
|
605 | 605 | header = 'JROABSCeCnModCnMod0100000' |
|
606 | 606 | numbers = len(str(beam_pos)) |
|
607 | 607 | function = 'CHGB' |
|
608 | 608 | |
|
609 | 609 | message_tx = header+str(numbers)+function+str(beam_pos)+'0' |
|
610 | 610 | |
|
611 | 611 | # Create the datagram socket |
|
612 | 612 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
613 | 613 | sock.connect(module_address) |
|
614 | 614 | |
|
615 | 615 | sock.send(message_tx) |
|
616 | 616 | #t = sock.recv(1024) |
|
617 | 617 | sock.close() |
|
618 | 618 | sock = None |
|
619 | 619 | |
|
620 | 620 | |
|
621 | 621 | time.sleep(0.04) |
|
622 | 622 | |
|
623 | 623 | |
|
624 | 624 | beam_pos = 0 |
|
625 | 625 | numbers = len(str(beam_pos)) |
|
626 | 626 | |
|
627 | 627 | message_tx = header+str(numbers)+function+str(beam_pos)+'0' |
|
628 | 628 | |
|
629 | 629 | # Create the datagram socket |
|
630 | 630 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
631 | 631 | sock.connect(module_address) |
|
632 | 632 | sock.send(message_tx) |
|
633 | 633 | sock.close() |
|
634 | 634 | sock = None |
|
635 | 635 | |
|
636 | 636 | time.sleep(0.04) |
|
637 | 637 | |
|
638 | 638 | |
|
639 | 639 | def multi_procs_test1(self): |
|
640 | 640 | |
|
641 | 641 | """ |
|
642 | 642 | This function sends the beam number to all abs modules using multiprocessing. |
|
643 | 643 | """ |
|
644 | 644 | |
|
645 | 645 | #if __name__ == "__main__": |
|
646 | 646 | size = 10000000 # Number of random numbers to add |
|
647 | 647 | procs = 65 # (Number-1) of processes to create (absmodule) |
|
648 | 648 | |
|
649 | 649 | # Create a list of jobs and then iterate through |
|
650 | 650 | # the number of processes appending each process to |
|
651 | 651 | # the job list |
|
652 | 652 | jobs = [] |
|
653 | 653 | for i in range(1, procs): |
|
654 | 654 | |
|
655 | 655 | process = multiprocessing.Process(target=self.change_procs_test1,args=(i,)) |
|
656 | 656 | jobs.append(process) |
|
657 | 657 | #print jobs |
|
658 | 658 | |
|
659 | 659 | # Start the processes (i.e. calculate the random number lists) |
|
660 | 660 | for j in jobs: |
|
661 | 661 | #time.sleep(0.4) |
|
662 | 662 | #print j |
|
663 | 663 | j.start() |
|
664 | 664 | |
|
665 | 665 | # Ensure all of the processes have finished |
|
666 | 666 | for j in jobs: |
|
667 | 667 | j.join() |
|
668 | 668 | |
|
669 | 669 | print("List processing complete.") |
|
670 | 670 | return 1 |
|
671 | 671 | |
|
672 | 672 | |
|
673 | 673 | |
|
674 | 674 | def multi_procs_test2(self): |
|
675 | 675 | """ |
|
676 | 676 | This function use multiprocessing python library. Importing Pool we can select |
|
677 | 677 | the number of cores we want to use |
|
678 | 678 | After 'nproc' linux command, we know how many cores computer has. |
|
679 | 679 | NOT WORKING |
|
680 | 680 | """ |
|
681 | 681 | import multiprocessing |
|
682 | 682 | pool = multiprocessing.Pool(3) # cores |
|
683 | 683 | |
|
684 | 684 | tasks = [] |
|
685 | 685 | procs = 65 |
|
686 | 686 | for i in range(62, procs): |
|
687 | 687 | tasks.append( (i,)) |
|
688 | 688 | #print tasks |
|
689 | 689 | #pool.apply_async(self.change_procs_test1, 62) |
|
690 | 690 | results = [pool.apply( self.change_procs_test1, t ) for t in tasks] |
|
691 | 691 | #for result in results: |
|
692 | 692 | #result.get() |
|
693 | 693 | #(plotNum, plotFilename) = result.get() |
|
694 | 694 | #print("Result: plot %d written to %s" % (plotNum, plotFilename) ) |
|
695 | 695 | |
|
696 | 696 | return 1 |
|
697 | 697 | |
|
698 | 698 | |
|
699 | 699 | def multi_procs_test3(self): |
|
700 | 700 | """ |
|
701 | 701 | This function use multiprocessing python library. Importing Pool we can select |
|
702 | 702 | the number of cores we want to use |
|
703 | 703 | After 'nproc' linux command, we know how many cores computer has. |
|
704 | 704 | """ |
|
705 | 705 | from multiprocessing import Pool |
|
706 | 706 | import time |
|
707 | 707 | |
|
708 | 708 | def f(x): |
|
709 | 709 | return x*x |
|
710 | 710 | |
|
711 | 711 | tasks = [] |
|
712 | 712 | procs = 65 |
|
713 | 713 | pool = Pool(processes=4) |
|
714 | 714 | |
|
715 | 715 | #for i in range(62, procs): |
|
716 | 716 | #result = pool.map(f, range(62,65)) |
|
717 | 717 | it = pool.imap(self.change_procs_test1, range(62,65)) |
|
718 | 718 | #result.get(timeout=5) |
|
719 | 719 | |
|
720 | 720 | return 1 |
|
721 | 721 | |
|
722 | 722 | |
|
723 | 723 | def f(x): |
|
724 | 724 | print x |
|
725 | 725 | return |
|
726 | 726 | |
|
727 | 727 | def multi_procs_test4(self): |
|
728 | 728 | import multiprocessing as mp |
|
729 | 729 | |
|
730 | 730 | |
|
731 | 731 | num_workers = mp.cpu_count() |
|
732 | 732 | |
|
733 | 733 | pool = mp.Pool(num_workers) |
|
734 | 734 | procs = 65 |
|
735 | 735 | for i in range(62, procs): |
|
736 | 736 | #for task in tasks: |
|
737 | 737 | pool.apply_async(self.f, args = (i,)) |
|
738 | 738 | |
|
739 | 739 | pool.close() |
|
740 | 740 | pool.join() |
|
741 | 741 | |
|
742 | 742 | return 1 |
|
743 | 743 | |
|
744 | 744 | |
|
745 | 745 | def get_absolute_url_import(self): |
|
746 | 746 | return reverse('url_import_abs_conf', args=[str(self.id)]) |
|
747 | 747 | |
|
748 | 748 | |
|
749 | 749 | |
|
750 | 750 | |
|
751 | 751 | class ABSBeam(models.Model): |
|
752 | 752 | |
|
753 | 753 | name = models.CharField(max_length=60, default='Beam') |
|
754 | 754 | antenna = models.CharField(verbose_name='Antenna', max_length=1000, default=antenna_default) |
|
755 | 755 | abs_conf = models.ForeignKey(ABSConfiguration, null=True, verbose_name='ABS Configuration') |
|
756 | 756 | tx = models.CharField(verbose_name='Tx', max_length=1000, default=tx_default) |
|
757 | 757 | rx = models.CharField(verbose_name='Rx', max_length=1000, default=rx_default) |
|
758 | 758 | s_time = models.TimeField(verbose_name='Star Time', default='00:00:00') |
|
759 | 759 | e_time = models.TimeField(verbose_name='End Time', default='23:59:59') |
|
760 | 760 | modules_conf = models.CharField(verbose_name='Modules', max_length=2000, default=json.dumps(conf_default)) |
|
761 | 761 | ues = models.CharField(verbose_name='Ues', max_length=100, default=ues_default) |
|
762 | 762 | only_rx = models.CharField(verbose_name='Only RX', max_length=40, default=onlyrx_default) |
|
763 | 763 | |
|
764 | 764 | class Meta: |
|
765 | 765 | db_table = 'abs_beams' |
|
766 | 766 | |
|
767 | 767 | def __unicode__(self): |
|
768 | 768 | return u'%s' % (self.name) |
|
769 | 769 | |
|
770 | 770 | def parms_to_dict(self): |
|
771 | 771 | |
|
772 | 772 | #Update data |
|
773 | 773 | self.modules_6bits() |
|
774 | 774 | |
|
775 | 775 | parameters = {} |
|
776 | 776 | |
|
777 | 777 | parameters['name'] = self.name |
|
778 | 778 | parameters['antenna'] = ast.literal_eval(self.antenna) |
|
779 | 779 | parameters['abs_conf'] = self.abs_conf.name |
|
780 | 780 | parameters['tx'] = ast.literal_eval(self.tx) |
|
781 | 781 | parameters['rx'] = ast.literal_eval(self.rx) |
|
782 | 782 | parameters['s_time'] = self.s_time.strftime("%H:%M:%S") |
|
783 | 783 | parameters['e_time'] = self.e_time.strftime("%H:%M:%S") |
|
784 | 784 | parameters['configuration'] = ast.literal_eval(self.modules_conf) |
|
785 | 785 | parameters['ues'] = ast.literal_eval(self.ues) |
|
786 | 786 | parameters['only_rx'] = json.loads(self.only_rx) |
|
787 | 787 | |
|
788 | 788 | return parameters |
|
789 | 789 | |
|
790 | 790 | def dict_to_parms(self, parameters): |
|
791 | 791 | |
|
792 | 792 | self.name = parameters['name'] |
|
793 | 793 | self.antenna = json.dumps(parameters['antenna']) |
|
794 | 794 | #self.abs_conf = parameters['abs_conf'] |
|
795 | 795 | self.tx = json.dumps(parameters['tx']) |
|
796 | 796 | self.rx = json.dumps(parameters['rx']) |
|
797 | 797 | #self.s_time = parameters['s_time'] |
|
798 | 798 | #self.e_time = parameters['e_time'] |
|
799 | 799 | self.ues = json.dumps(parameters['ues']) |
|
800 | 800 | self.only_rx = json.dumps(parameters['only_rx']) |
|
801 | 801 | |
|
802 | 802 | self.modules_6bits() |
|
803 | 803 | self.save() |
|
804 | 804 | |
|
805 | 805 | |
|
806 | 806 | def clone(self, **kwargs): |
|
807 | 807 | |
|
808 | 808 | self.pk = None |
|
809 | 809 | self.id = None |
|
810 | 810 | for attr, value in kwargs.items(): |
|
811 | 811 | setattr(self, attr, value) |
|
812 | 812 | |
|
813 | 813 | self.save() |
|
814 | 814 | |
|
815 | 815 | return self |
|
816 | 816 | |
|
817 | 817 | |
|
818 | 818 | |
|
819 | 819 | def module_6bits(self, module): |
|
820 | 820 | """ |
|
821 | 821 | This function reads antenna pattern and choose 6bits (upbits-downbits) for one abs module |
|
822 | 822 | """ |
|
823 | 823 | if module > 64: |
|
824 | 824 | beam_bits = "" |
|
825 | 825 | return beam_bits |
|
826 | 826 | |
|
827 | 827 | data = ast.literal_eval(self.antenna) |
|
828 | 828 | up_data = data['antenna_up'] |
|
829 | 829 | down_data = data['antenna_down'] |
|
830 | 830 | |
|
831 | 831 | pos = ip2position(module) |
|
832 | 832 | up_value = up_data[pos[0]][pos[1]] |
|
833 | 833 | down_value = down_data[pos[0]][pos[1]] |
|
834 | 834 | |
|
835 | 835 | up_bits = up_conv_bits(up_value) |
|
836 | 836 | down_bits = down_conv_bits(down_value) |
|
837 | 837 | beam_bits = up_bits+down_bits |
|
838 | 838 | |
|
839 | 839 | return beam_bits |
|
840 | 840 | |
|
841 | 841 | def modules_6bits(self): |
|
842 | 842 | """ |
|
843 | 843 | This function returns 6bits from every abs module (1-64) in a dict |
|
844 | 844 | """ |
|
845 | 845 | modules_configuration = ast.literal_eval(self.modules_conf) |
|
846 | 846 | |
|
847 | 847 | for i in range(1,65): |
|
848 | 848 | modules_configuration[str(i)] = self.module_6bits(i) |
|
849 | 849 | |
|
850 | 850 | self.modules_conf = json.dumps(modules_configuration) |
|
851 | 851 | self.save() |
|
852 | 852 | |
|
853 | 853 | return self.modules_conf |
|
854 | 854 | |
|
855 | 855 | |
|
856 | 856 | def set_as_activebeam(self): |
|
857 | 857 | """ |
|
858 | 858 | This function set this beam as the active beam of its ABS Configuration. |
|
859 | 859 | """ |
|
860 | 860 | self.abs_conf.active_beam = json.dumps({'active_beam': self.id}) |
|
861 | 861 | self.abs_conf.save() |
|
862 | 862 | |
|
863 | 863 | return |
|
864 | 864 | |
|
865 | 865 | |
|
866 | 866 | @property |
|
867 | 867 | def get_upvalues(self): |
|
868 | 868 | """ |
|
869 | 869 | This function reads antenna pattern and show the up-value of one abs module |
|
870 | 870 | """ |
|
871 | 871 | |
|
872 | 872 | data = ast.literal_eval(self.antenna) |
|
873 | 873 | up_data = data['antenna_up'] |
|
874 | 874 | |
|
875 | 875 | up_values = [] |
|
876 | 876 | for data in up_data: |
|
877 | 877 | for i in range(0,8): |
|
878 | 878 | up_values.append(data[i]) |
|
879 | 879 | |
|
880 | 880 | return up_values |
|
881 | 881 | |
|
882 | 882 | @property |
|
883 | 883 | def antenna_upvalues(self): |
|
884 | 884 | """ |
|
885 | 885 | This function reads antenna pattern and show the up - values of one abs beam |
|
886 | 886 | in a particular order |
|
887 | 887 | """ |
|
888 | 888 | data = ast.literal_eval(self.antenna) |
|
889 | 889 | up_data = data['antenna_up'] |
|
890 | 890 | |
|
891 | 891 | return up_data |
|
892 | 892 | |
|
893 | 893 | @property |
|
894 | 894 | def antenna_downvalues(self): |
|
895 | 895 | """ |
|
896 | 896 | This function reads antenna pattern and show the down - values of one abs beam |
|
897 | 897 | in a particular order |
|
898 | 898 | """ |
|
899 | 899 | data = ast.literal_eval(self.antenna) |
|
900 | 900 | down_data = data['antenna_down'] |
|
901 | 901 | |
|
902 | 902 | return down_data |
|
903 | 903 | |
|
904 | 904 | @property |
|
905 | 905 | def get_downvalues(self): |
|
906 | 906 | """ |
|
907 | 907 | This function reads antenna pattern and show the down-value of one abs module |
|
908 | 908 | """ |
|
909 | 909 | |
|
910 | 910 | data = ast.literal_eval(self.antenna) |
|
911 | 911 | down_data = data['antenna_down'] |
|
912 | 912 | |
|
913 | 913 | down_values = [] |
|
914 | 914 | for data in down_data: |
|
915 | 915 | for i in range(0,8): |
|
916 | 916 | down_values.append(data[i]) |
|
917 | 917 | |
|
918 | 918 | return down_values |
|
919 | 919 | |
|
920 | 920 | @property |
|
921 | 921 | def get_up_ues(self): |
|
922 | 922 | """ |
|
923 | 923 | This function shows the up-ues-value of one beam |
|
924 | 924 | """ |
|
925 | 925 | data = ast.literal_eval(self.ues) |
|
926 | 926 | up_ues = data['up'] |
|
927 | 927 | |
|
928 | 928 | return up_ues |
|
929 | 929 | |
|
930 | 930 | @property |
|
931 | 931 | def get_down_ues(self): |
|
932 | 932 | """ |
|
933 | 933 | This function shows the down-ues-value of one beam |
|
934 | 934 | """ |
|
935 | 935 | data = ast.literal_eval(self.ues) |
|
936 | 936 | down_ues = data['down'] |
|
937 | 937 | |
|
938 | 938 | return down_ues |
|
939 | 939 | |
|
940 | 940 | @property |
|
941 | 941 | def get_up_onlyrx(self): |
|
942 | 942 | """ |
|
943 | 943 | This function shows the up-onlyrx-value of one beam |
|
944 | 944 | """ |
|
945 | 945 | data = json.loads(self.only_rx) |
|
946 | 946 | up_onlyrx = data['up'] |
|
947 | 947 | |
|
948 | 948 | return up_onlyrx |
|
949 | 949 | |
|
950 | 950 | @property |
|
951 | 951 | def get_down_onlyrx(self): |
|
952 | 952 | """ |
|
953 | 953 | This function shows the down-onlyrx-value of one beam |
|
954 | 954 | """ |
|
955 | 955 | data = json.loads(self.only_rx) |
|
956 | 956 | down_onlyrx = data['down'] |
|
957 | 957 | |
|
958 | 958 | return down_onlyrx |
|
959 | 959 | |
|
960 | 960 | @property |
|
961 | 961 | def get_tx(self): |
|
962 | 962 | """ |
|
963 | 963 | This function shows the tx-values of one beam |
|
964 | 964 | """ |
|
965 | 965 | data = json.loads(self.tx) |
|
966 | 966 | |
|
967 | 967 | return data |
|
968 | 968 | |
|
969 | 969 | @property |
|
970 | 970 | def get_uptx(self): |
|
971 | 971 | """ |
|
972 | 972 | This function shows the up-tx-values of one beam |
|
973 | 973 | """ |
|
974 | 974 | data = json.loads(self.tx) |
|
975 | 975 | up_data = data['up'] |
|
976 | 976 | |
|
977 | 977 | up_values = [] |
|
978 | 978 | for data in up_data: |
|
979 | 979 | for i in range(0,8): |
|
980 | 980 | up_values.append(data[i]) |
|
981 | 981 | |
|
982 | 982 | return up_values |
|
983 | 983 | |
|
984 | 984 | @property |
|
985 | 985 | def get_downtx(self): |
|
986 | 986 | """ |
|
987 | 987 | This function shows the down-tx-values of one beam |
|
988 | 988 | """ |
|
989 | 989 | data = json.loads(self.tx) |
|
990 | 990 | down_data = data['down'] |
|
991 | 991 | |
|
992 | 992 | down_values = [] |
|
993 | 993 | for data in down_data: |
|
994 | 994 | for i in range(0,8): |
|
995 | 995 | down_values.append(data[i]) |
|
996 | 996 | |
|
997 | 997 | return down_values |
|
998 | 998 | |
|
999 | 999 | |
|
1000 | 1000 | |
|
1001 | 1001 | @property |
|
1002 | 1002 | def get_rx(self): |
|
1003 | 1003 | """ |
|
1004 | 1004 | This function shows the rx-values of one beam |
|
1005 | 1005 | """ |
|
1006 | 1006 | data = json.loads(self.rx) |
|
1007 | 1007 | |
|
1008 | 1008 | return data |
|
1009 | 1009 | |
|
1010 | 1010 | @property |
|
1011 | 1011 | def get_uprx(self): |
|
1012 | 1012 | """ |
|
1013 | 1013 | This function shows the up-rx-values of one beam |
|
1014 | 1014 | """ |
|
1015 | 1015 | data = json.loads(self.rx) |
|
1016 | 1016 | up_data = data['up'] |
|
1017 | 1017 | |
|
1018 | 1018 | up_values = [] |
|
1019 | 1019 | for data in up_data: |
|
1020 | 1020 | for i in range(0,8): |
|
1021 | 1021 | up_values.append(data[i]) |
|
1022 | 1022 | |
|
1023 | 1023 | return up_values |
|
1024 | 1024 | |
|
1025 | 1025 | @property |
|
1026 | 1026 | def get_downrx(self): |
|
1027 | 1027 | """ |
|
1028 | 1028 | This function shows the down-rx-values of one beam |
|
1029 | 1029 | """ |
|
1030 | 1030 | data = json.loads(self.rx) |
|
1031 | 1031 | down_data = data['down'] |
|
1032 | 1032 | |
|
1033 | 1033 | down_values = [] |
|
1034 | 1034 | for data in down_data: |
|
1035 | 1035 | for i in range(0,8): |
|
1036 | 1036 | down_values.append(data[i]) |
|
1037 | 1037 | |
|
1038 | 1038 | return down_values |
@@ -1,46 +1,47 | |||
|
1 | 1 | {% extends "dev_conf_edit.html" %} |
|
2 | 2 | {% load bootstrap3 %} |
|
3 | 3 | {% load static %} |
|
4 | 4 | |
|
5 | 5 | {% block extra-head %} |
|
6 | 6 | <style type="text/css"> |
|
7 | 7 | /* show the move cursor as the user moves the mouse over the panel header.*/ |
|
8 | 8 | .panel-default { cursor: move; } |
|
9 | 9 | </style> |
|
10 | 10 | <script src="{% static 'js/jquery-ui.min.js' %}"></script> |
|
11 | 11 | |
|
12 | 12 | {% endblock %} |
|
13 | 13 | |
|
14 | 14 | {% block content %} |
|
15 | 15 | <form class="form" method="post"> |
|
16 | 16 | {% csrf_token %} |
|
17 | 17 | {% bootstrap_form form layout='horizontal' size='medium' %} |
|
18 | 18 | <div style="clear: both;"></div> |
|
19 | 19 | <h2>ABS Beams</h2><hr> |
|
20 | 20 | <div class="panel-group" id="div_beams" role="tablist" aria-multiselectable="true"> |
|
21 | 21 | {% include "abs_beams_list.html" %} |
|
22 | 22 | </div> |
|
23 | 23 | <div style="clear: both;"></div> |
|
24 | 24 | <br> |
|
25 | 25 | <div class="pull-right"> |
|
26 | 26 | <button type="button" class="btn btn-primary" onclick="{% if previous %}window.location.replace('{{ previous }}');{% else %}history.go(-1);{% endif %}">Cancel</button> |
|
27 | 27 | <button type="button" class="btn btn-primary" id="bt_add_beam">Add Beam</button> |
|
28 | 28 | <button type="submit" class="btn btn-primary">{{button}}</button> |
|
29 | 29 | </div> |
|
30 | 30 | </form> |
|
31 | 31 | {% endblock %} |
|
32 | 32 | |
|
33 | 33 | |
|
34 | 34 | {% block extra-js%} |
|
35 | <script src="{% static 'js/abs.js' %}"></script> | |
|
35 | 36 | <script type="text/javascript"> |
|
36 | 37 | |
|
37 | 38 | $("#bt_toggle").click(function() { |
|
38 | 39 | $(".panel-collapse").collapse('toggle') |
|
39 | 40 | }); |
|
40 | 41 | |
|
41 | 42 | $("#bt_add_beam").click(function() { |
|
42 | 43 | document.location = "{% url 'url_add_abs_beam' id_conf %}"; |
|
43 | 44 | }); |
|
44 | 45 | |
|
45 | 46 | </script> |
|
46 | 47 | {% endblock %} |
@@ -1,424 +1,424 | |||
|
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.core.urlresolvers import reverse |
|
8 | 8 | |
|
9 | 9 | from datetime import datetime |
|
10 | 10 | from time import sleep |
|
11 | 11 | import os |
|
12 | 12 | |
|
13 | 13 | from apps.main.models import Device, Configuration |
|
14 | 14 | from apps.main.views import sidebar |
|
15 | 15 | |
|
16 | 16 | from .models import ABSConfiguration, ABSBeam |
|
17 | 17 | from .forms import ABSConfigurationForm, ABSBeamEditForm, ABSBeamAddForm, ABSImportForm |
|
18 | 18 | |
|
19 | 19 | from .utils.overJroShow import overJroShow |
|
20 | 20 | from .utils.OverJRO import OverJRO |
|
21 | 21 | # Create your views here. |
|
22 | 22 | import json, ast |
|
23 | 23 | |
|
24 | 24 | |
|
25 | 25 | def get_values_from_form(form_data): |
|
26 | 26 | |
|
27 | 27 | sublistup = [] |
|
28 | 28 | sublistdown = [] |
|
29 | 29 | subtxlistup = [] |
|
30 | 30 | subtxlistdown = [] |
|
31 | 31 | subrxlistup = [] |
|
32 | 32 | subrxlistdown = [] |
|
33 | 33 | |
|
34 | 34 | up_values_list = [] |
|
35 | 35 | down_values_list = [] |
|
36 | 36 | up_txvalues_list = [] |
|
37 | 37 | down_txvalues_list = [] |
|
38 | 38 | up_rxvalues_list = [] |
|
39 | 39 | down_rxvalues_list = [] |
|
40 | 40 | |
|
41 | 41 | values_list = {} |
|
42 | 42 | cont = 1 |
|
43 | 43 | |
|
44 | 44 | for i in range(1,65): |
|
45 | 45 | x = float(form_data['abs_up'+str(i)]) |
|
46 | 46 | y = float(form_data['abs_down'+str(i)]) |
|
47 | 47 | sublistup.append(x) |
|
48 | 48 | sublistdown.append(y) |
|
49 | 49 | |
|
50 | 50 | if str(i) in form_data.getlist('uptx_checks'): |
|
51 | 51 | subtxlistup.append(1) |
|
52 | 52 | else: |
|
53 | 53 | subtxlistup.append(0) |
|
54 | 54 | if str(i) in form_data.getlist('downtx_checks'): |
|
55 | 55 | subtxlistdown.append(1) |
|
56 | 56 | else: |
|
57 | 57 | subtxlistdown.append(0) |
|
58 | 58 | |
|
59 | 59 | if str(i) in form_data.getlist('uprx_checks'): |
|
60 | 60 | subrxlistup.append(1) |
|
61 | 61 | else: |
|
62 | 62 | subrxlistup.append(0) |
|
63 | 63 | if str(i) in form_data.getlist('downrx_checks'): |
|
64 | 64 | subrxlistdown.append(1) |
|
65 | 65 | else: |
|
66 | 66 | subrxlistdown.append(0) |
|
67 | 67 | |
|
68 | 68 | cont = cont+1 |
|
69 | 69 | |
|
70 | 70 | if cont == 9: |
|
71 | 71 | up_values_list.append(sublistup) |
|
72 | 72 | down_values_list.append(sublistdown) |
|
73 | 73 | sublistup = [] |
|
74 | 74 | sublistdown = [] |
|
75 | 75 | |
|
76 | 76 | up_txvalues_list.append(subtxlistup) |
|
77 | 77 | down_txvalues_list.append(subtxlistdown) |
|
78 | 78 | subtxlistup = [] |
|
79 | 79 | subtxlistdown = [] |
|
80 | 80 | up_rxvalues_list.append(subrxlistup) |
|
81 | 81 | down_rxvalues_list.append(subrxlistdown) |
|
82 | 82 | subrxlistup = [] |
|
83 | 83 | subrxlistdown = [] |
|
84 | 84 | cont = 1 |
|
85 | 85 | |
|
86 | 86 | |
|
87 | 87 | list_uesup = [] |
|
88 | 88 | list_uesdown = [] |
|
89 | 89 | for i in range(1,5): |
|
90 | 90 | if form_data['ues_up'+str(i)] == '': |
|
91 | 91 | list_uesup.append(0.0) |
|
92 | 92 | else: |
|
93 | 93 | list_uesup.append(float(form_data['ues_up'+str(i)])) |
|
94 | 94 | |
|
95 | 95 | if form_data['ues_down'+str(i)] == '': |
|
96 | 96 | list_uesdown.append(0.0) |
|
97 | 97 | else: |
|
98 | 98 | list_uesdown.append(float(form_data['ues_down'+str(i)])) |
|
99 | 99 | |
|
100 | 100 | onlyrx_list = form_data.getlist('onlyrx') |
|
101 | 101 | only_rx = {} |
|
102 | 102 | if '1' in onlyrx_list: |
|
103 | 103 | only_rx['up'] = True |
|
104 | 104 | else: |
|
105 | 105 | only_rx['up'] = False |
|
106 | 106 | if '2' in onlyrx_list: |
|
107 | 107 | only_rx['down'] = True |
|
108 | 108 | else: |
|
109 | 109 | only_rx['down'] = False |
|
110 | 110 | |
|
111 | 111 | antenna = {'antenna_up': up_values_list, 'antenna_down': down_values_list} |
|
112 | 112 | tx = {'up': up_txvalues_list, 'down': down_txvalues_list} |
|
113 | 113 | rx = {'up': up_rxvalues_list, 'down': down_rxvalues_list} |
|
114 | 114 | ues = {'up': list_uesup, 'down': list_uesdown} |
|
115 | 115 | name = str(form_data['beam_name']) |
|
116 | 116 | |
|
117 | 117 | beam_data = {'name': name, 'antenna': antenna, 'tx': tx, 'rx': rx, 'ues': ues, 'only_rx': only_rx} |
|
118 | 118 | |
|
119 | 119 | return beam_data |
|
120 | 120 | |
|
121 | 121 | |
|
122 | 122 | |
|
123 | 123 | def abs_conf(request, id_conf): |
|
124 | 124 | |
|
125 | 125 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
126 | 126 | beams = ABSBeam.objects.filter(abs_conf=conf) |
|
127 | 127 | active_beam_id = json.loads(conf.active_beam) |
|
128 | 128 | |
|
129 | 129 | #------------Colors for Active Beam:------------- |
|
130 | 130 | modules_status = json.loads(conf.module_status) |
|
131 | 131 | |
|
132 | 132 | color_status = {} |
|
133 | 133 | for status in modules_status: |
|
134 | 134 | if modules_status[status] == 2: #Running background-color: #ff0000; |
|
135 | 135 | color_status[status] = 'bgcolor=#00cc00' |
|
136 | 136 | elif modules_status[status] == 1: #Connected background-color: #ee902c; |
|
137 | 137 | color_status[status] = 'bgcolor=#ee902c' |
|
138 | 138 | else: #Disconnected background-color: #00cc00; |
|
139 | 139 | color_status[status] = 'bgcolor=#FF0000' |
|
140 | 140 | #------------------------------------------------ |
|
141 | 141 | |
|
142 | 142 | kwargs = {} |
|
143 | 143 | kwargs['status'] = conf.device.get_status_display() |
|
144 | 144 | |
|
145 | 145 | |
|
146 | 146 | kwargs['dev_conf'] = conf |
|
147 | 147 | kwargs['dev_conf_keys'] = ['name',] |
|
148 | 148 | |
|
149 | 149 | kwargs['title'] = 'ABS Configuration' |
|
150 | 150 | kwargs['suptitle'] = 'Details' |
|
151 | 151 | kwargs['no_play'] = True |
|
152 | 152 | |
|
153 | 153 | kwargs['button'] = 'Edit Configuration' |
|
154 | 154 | #------------------Active Beam----------------------- |
|
155 | 155 | try: |
|
156 | 156 | active_beam_id = active_beam_id['active_beam'] |
|
157 | 157 | active_beam = ABSBeam.objects.get(pk=active_beam_id) |
|
158 | 158 | kwargs['active_beam'] = active_beam |
|
159 | 159 | for beam in beams: |
|
160 | 160 | if beam.id == active_beam.id: |
|
161 | 161 | beam.color_status=color_status |
|
162 | 162 | except: |
|
163 | 163 | active_beam = '' |
|
164 | 164 | #---------------------------------------------------- |
|
165 | 165 | kwargs['beams'] = beams |
|
166 | 166 | kwargs['modules_status'] = modules_status |
|
167 | 167 | kwargs['color_status'] = color_status |
|
168 | 168 | |
|
169 | 169 | kwargs['only_stop'] = True |
|
170 | 170 | |
|
171 | 171 | ###### SIDEBAR ###### |
|
172 | 172 | kwargs.update(sidebar(conf=conf)) |
|
173 | 173 | |
|
174 | 174 | return render(request, 'abs_conf.html', kwargs) |
|
175 | 175 | |
|
176 | 176 | def abs_conf_edit(request, id_conf): |
|
177 | 177 | |
|
178 | 178 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
179 | 179 | |
|
180 | 180 | beams = ABSBeam.objects.filter(abs_conf=conf) |
|
181 | 181 | print beams |
|
182 | 182 | |
|
183 | 183 | if request.method=='GET': |
|
184 | 184 | form = ABSConfigurationForm(instance=conf) |
|
185 | 185 | |
|
186 | 186 | if request.method=='POST': |
|
187 | 187 | form = ABSConfigurationForm(request.POST, instance=conf) |
|
188 | 188 | |
|
189 | 189 | if form.is_valid(): |
|
190 | 190 | conf = form.save(commit=False) |
|
191 | 191 | conf.save() |
|
192 | 192 | return redirect('url_abs_conf', id_conf=conf.id) |
|
193 | 193 | |
|
194 | 194 | ###### SIDEBAR ###### |
|
195 | 195 | kwargs = {} |
|
196 | 196 | |
|
197 | 197 | kwargs['dev_conf'] = conf |
|
198 | 198 | #kwargs['id_dev'] = conf.id |
|
199 | 199 | kwargs['id_conf'] = conf.id |
|
200 | 200 | kwargs['form'] = form |
|
201 | 201 | kwargs['abs_beams'] = beams |
|
202 | 202 | kwargs['title'] = 'Device Configuration' |
|
203 | 203 | kwargs['suptitle'] = 'Edit' |
|
204 | 204 | kwargs['button'] = 'Save' |
|
205 | 205 | |
|
206 | 206 | kwargs['edit'] = True |
|
207 | 207 | |
|
208 | 208 | return render(request, 'abs_conf_edit.html', kwargs) |
|
209 | 209 | |
|
210 | 210 | |
|
211 | 211 | def import_file(request, id_conf): |
|
212 | 212 | |
|
213 | 213 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
214 | 214 | if request.method=='POST': |
|
215 | 215 | form = ABSImportForm(request.POST, request.FILES) |
|
216 | 216 | if form.is_valid(): |
|
217 | 217 | try: |
|
218 | 218 | parms = conf.import_from_file(request.FILES['file_name']) |
|
219 | 219 | |
|
220 | 220 | if parms: |
|
221 | 221 | conf.update_from_file(parms) |
|
222 | 222 | messages.success(request, 'Configuration "%s" loaded succesfully' % request.FILES['file_name']) |
|
223 | 223 | return redirect(conf.get_absolute_url_edit()) |
|
224 | 224 | |
|
225 | 225 | except Exception as e: |
|
226 | 226 | messages.error(request, 'Error parsing file: "%s" - %s' % (request.FILES['file_name'], e)) |
|
227 | 227 | |
|
228 | 228 | else: |
|
229 | 229 | messages.warning(request, 'Your current configuration will be replaced') |
|
230 | 230 | form = ABSImportForm() |
|
231 | 231 | |
|
232 | 232 | kwargs = {} |
|
233 | 233 | kwargs['form'] = form |
|
234 | 234 | kwargs['title'] = 'ABS Configuration' |
|
235 | 235 | kwargs['suptitle'] = 'Import file' |
|
236 | 236 | kwargs['button'] = 'Upload' |
|
237 | 237 | kwargs['previous'] = conf.get_absolute_url() |
|
238 | 238 | |
|
239 | 239 | return render(request, 'abs_import.html', kwargs) |
|
240 | 240 | |
|
241 | 241 | |
|
242 | 242 | def send_beam(request, id_conf, id_beam): |
|
243 | 243 | |
|
244 | 244 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
245 | 245 | beam = get_object_or_404(ABSBeam, pk=id_beam) |
|
246 | 246 | beams_list = ABSBeam.objects.filter(abs_conf=conf) |
|
247 | 247 | #To set this beam as an Active Beam |
|
248 | beam.set_activebeam() | |
|
248 | beam.set_as_activebeam() | |
|
249 | 249 | #To send beam position to abs-modules |
|
250 | 250 | i = 0 |
|
251 | 251 | for b in beams_list: |
|
252 | 252 | if b.id == int(id_beam): |
|
253 | 253 | break |
|
254 | 254 | else: |
|
255 | 255 | i += 1 |
|
256 | 256 | beam_pos = i + 1 #Estandarizar |
|
257 | 257 | print 'Position: ',beam_pos |
|
258 | 258 | conf.send_beam_num(beam_pos) |
|
259 | 259 | |
|
260 | 260 | return redirect('url_abs_conf', conf.id) |
|
261 | 261 | |
|
262 | 262 | |
|
263 | 263 | def add_beam(request, id_conf): |
|
264 | 264 | |
|
265 | 265 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
266 | 266 | confs = Configuration.objects.all() |
|
267 | 267 | |
|
268 | 268 | if request.method=='GET': |
|
269 | 269 | #form = ABSBeamEditForm() |
|
270 | 270 | form = ABSBeamAddForm() |
|
271 | 271 | |
|
272 | 272 | if request.method=='POST': |
|
273 | 273 | form = ABSBeamAddForm(request.POST) |
|
274 | 274 | |
|
275 | 275 | beam_data = get_values_from_form(request.POST) |
|
276 | 276 | |
|
277 | 277 | new_beam = ABSBeam( |
|
278 | 278 | name =beam_data['name'], |
|
279 | 279 | antenna =json.dumps(beam_data['antenna']), |
|
280 | 280 | abs_conf=conf, |
|
281 | 281 | tx =json.dumps(beam_data['tx']), |
|
282 | 282 | rx =json.dumps(beam_data['rx']), |
|
283 | 283 | ues =json.dumps(beam_data['ues']), |
|
284 | 284 | only_rx =json.dumps(beam_data['only_rx']) |
|
285 | 285 | ) |
|
286 | 286 | new_beam.save() |
|
287 | 287 | #---Update 6bits configuration and add beam to abs configuration beams list. |
|
288 | 288 | new_beam.modules_6bits() |
|
289 | 289 | #new_beam.add_beam2list() |
|
290 | 290 | messages.success(request, 'Beam: "%s" has been added.' % new_beam.name) |
|
291 | 291 | |
|
292 | 292 | return redirect('url_edit_abs_conf', conf.id) |
|
293 | 293 | |
|
294 | 294 | ###### SIDEBAR ###### |
|
295 | 295 | kwargs = {} |
|
296 | 296 | |
|
297 | 297 | #kwargs['dev_conf'] = conf.device |
|
298 | 298 | #kwargs['id_dev'] = conf.device |
|
299 | 299 | kwargs['id_conf'] = conf.id |
|
300 | 300 | kwargs['form'] = form |
|
301 | 301 | kwargs['title'] = 'ABS Beams' |
|
302 | 302 | kwargs['suptitle'] = 'Add Beam' |
|
303 | 303 | kwargs['button'] = 'Add' |
|
304 | 304 | kwargs['no_sidebar'] = True |
|
305 | 305 | |
|
306 | 306 | #kwargs['previous'] = conf.get_absolute_url_edit() |
|
307 | 307 | kwargs['edit'] = True |
|
308 | 308 | |
|
309 | 309 | return render(request, 'abs_add_beam.html', kwargs) |
|
310 | 310 | |
|
311 | 311 | |
|
312 | 312 | def edit_beam(request, id_conf, id_beam): |
|
313 | 313 | |
|
314 | 314 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
315 | 315 | beam = get_object_or_404(ABSBeam, pk=id_beam) |
|
316 | 316 | |
|
317 | 317 | if request.method=='GET': |
|
318 | 318 | form = ABSBeamEditForm(initial={'beam': beam}) |
|
319 | 319 | |
|
320 | 320 | if request.method=='POST': |
|
321 | 321 | form = ABSBeamEditForm(request.POST) |
|
322 | 322 | |
|
323 | 323 | beam_data = get_values_from_form(request.POST) |
|
324 | 324 | |
|
325 | 325 | beam.dict_to_parms(beam_data) |
|
326 | 326 | beam.save() |
|
327 | 327 | |
|
328 | 328 | messages.success(request, 'Beam: "%s" has been updated.' % beam.name) |
|
329 | 329 | |
|
330 | 330 | return redirect('url_edit_abs_conf', conf.id) |
|
331 | 331 | |
|
332 | 332 | ###### SIDEBAR ###### |
|
333 | 333 | kwargs = {} |
|
334 | 334 | |
|
335 | 335 | kwargs['id_conf'] = conf.id |
|
336 | 336 | kwargs['form'] = form |
|
337 | 337 | kwargs['title'] = 'ABS Beams' |
|
338 | 338 | kwargs['suptitle'] = 'Edit Beam' |
|
339 | 339 | kwargs['button'] = 'Save' |
|
340 | 340 | kwargs['no_sidebar'] = True |
|
341 | 341 | |
|
342 | 342 | #kwargs['previous'] = conf.get_absolute_url_edit() |
|
343 | 343 | kwargs['edit'] = True |
|
344 | 344 | |
|
345 | 345 | return render(request, 'abs_edit_beam.html', kwargs) |
|
346 | 346 | |
|
347 | 347 | |
|
348 | 348 | |
|
349 | 349 | def remove_beam(request, id_conf, id_beam): |
|
350 | 350 | |
|
351 | 351 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
352 | 352 | beam = get_object_or_404(ABSBeam, pk=id_beam) |
|
353 | 353 | |
|
354 | 354 | if request.method=='POST': |
|
355 | 355 | if beam: |
|
356 | 356 | try: |
|
357 | 357 | beam.remove_beamfromlist() |
|
358 | 358 | beam.delete() |
|
359 | 359 | messages.success(request, 'Beam: "%s" has been deleted.' % beam) |
|
360 | 360 | except: |
|
361 | 361 | messages.error(request, 'Unable to delete beam: "%s".' % beam) |
|
362 | 362 | |
|
363 | 363 | return redirect('url_edit_abs_conf', conf.id) |
|
364 | 364 | |
|
365 | 365 | ###### SIDEBAR ###### |
|
366 | 366 | kwargs = {} |
|
367 | 367 | |
|
368 | 368 | kwargs['object'] = beam |
|
369 | 369 | kwargs['delete'] = True |
|
370 | 370 | kwargs['title'] = 'Delete' |
|
371 | 371 | kwargs['suptitle'] = 'Beam' |
|
372 | 372 | kwargs['previous'] = conf.get_absolute_url_edit() |
|
373 | 373 | return render(request, 'confirm.html', kwargs) |
|
374 | 374 | |
|
375 | 375 | |
|
376 | 376 | |
|
377 | 377 | def plot_patterns(request, id_conf, id_beam=None): |
|
378 | 378 | |
|
379 | 379 | kwargs = {} |
|
380 | 380 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
381 | 381 | beams = ABSBeam.objects.filter(abs_conf=conf) |
|
382 | 382 | |
|
383 | 383 | if id_beam: |
|
384 | 384 | beam = get_object_or_404(ABSBeam, pk=id_beam) |
|
385 | 385 | kwargs['beam'] = beam |
|
386 | 386 | |
|
387 | 387 | |
|
388 | 388 | ###### SIDEBAR ###### |
|
389 | 389 | |
|
390 | 390 | kwargs['dev_conf'] = conf.device |
|
391 | 391 | kwargs['id_dev'] = conf.device |
|
392 | 392 | kwargs['id_conf'] = conf.id |
|
393 | 393 | kwargs['abs_beams'] = beams |
|
394 | 394 | kwargs['title'] = 'ABS Patterns' |
|
395 | 395 | kwargs['suptitle'] = conf.name |
|
396 | 396 | kwargs['no_sidebar'] = True |
|
397 | 397 | |
|
398 | 398 | return render(request, 'abs_patterns.html', kwargs) |
|
399 | 399 | |
|
400 | 400 | |
|
401 | 401 | def plot_pattern(request, id_conf, id_beam, antenna): |
|
402 | 402 | |
|
403 | 403 | if antenna=='down': |
|
404 | 404 | sleep(3) |
|
405 | 405 | |
|
406 | 406 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
407 | 407 | beam = get_object_or_404(ABSBeam, pk=id_beam) |
|
408 | 408 | |
|
409 | 409 | name = conf.experiment.name |
|
410 | 410 | |
|
411 | 411 | just_rx = 1 if json.loads(beam.only_rx)[antenna] else 0 |
|
412 | 412 | phases = json.loads(beam.antenna)['antenna_{}'.format(antenna)] |
|
413 | 413 | gain_tx = json.loads(beam.tx)[antenna] |
|
414 | 414 | gain_rx = json.loads(beam.rx)[antenna] |
|
415 | 415 | ues = json.loads(beam.ues)[antenna] |
|
416 | 416 | |
|
417 | 417 | newOverJro = overJroShow(name) |
|
418 | 418 | fig = newOverJro.plotPattern2(datetime.today(), phases, gain_tx, gain_rx, ues, just_rx) |
|
419 | 419 | |
|
420 | 420 | response=HttpResponse(content_type='image/png') |
|
421 | 421 | |
|
422 | 422 | fig.canvas.print_png(response) |
|
423 | 423 | |
|
424 | 424 | return response |
General Comments 0
You need to be logged in to leave comments.
Login now