@@ -1,1069 +1,1103 | |||
|
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 | 186 | operation_mode = models.PositiveSmallIntegerField(verbose_name='Operation Mode', choices=OPERATION_MODES, default = 0) |
|
187 | 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 | #-----For Active Beam----- | |
|
293 | active_beam = json.loads(self.active_beam) | |
|
294 | new_beams = ABSBeam.objects.filter(abs_conf=self) | |
|
295 | active_beam['active_beam'] = new_beams[0].id | |
|
296 | self.active_beam = json.dumps(active_beam) | |
|
297 | self.save() | |
|
298 | #-----For Active Beam----- | |
|
299 | ||
|
292 | 300 | return self |
|
293 | 301 | |
|
294 | 302 | |
|
295 | 303 | def module_conf(self, module_num, beams): |
|
296 | 304 | """ |
|
297 | 305 | This function creates beam configurations for one abs module. |
|
298 | 306 | """ |
|
299 | 307 | ip_address = self.device.ip_address |
|
300 | 308 | ip_address = ip_address.split('.') |
|
301 | 309 | module_seq = (ip_address[0],ip_address[1],ip_address[2]) |
|
302 | 310 | dot = '.' |
|
303 | 311 | module_ip = dot.join(module_seq)+'.'+str(module_num) |
|
304 | 312 | module_port = self.device.port_address |
|
305 | 313 | write_route = 'http://'+module_ip+':'+str(module_port)+'/write' |
|
306 | 314 | |
|
307 | header = 'JROABSCeCnModCnMod01000108SNDFexperimento1.ab1' | |
|
308 | module = 'ABS_'+str(module_num) | |
|
315 | #header = 'JROABSCeCnModCnMod01000108SNDFexperimento1.ab1' | |
|
316 | #module = 'ABS_'+str(module_num) | |
|
309 | 317 | bs = '' #{} |
|
310 | 318 | i=1 |
|
311 | 319 | |
|
312 | 320 | for beam in beams: |
|
313 | 321 | #bs[i] = fromBinary2Char(beam.module_6bits(module_num)) |
|
314 | 322 | bs = bs + fromBinary2Char(beam.module_6bits(module_num)) |
|
315 | 323 | i=i+1 |
|
316 | 324 | |
|
317 | 325 | beams = bs |
|
318 | 326 | |
|
319 | 327 | parameters = {} |
|
320 | #parameters['header'] = header | |
|
321 | #parameters['module'] = module | |
|
322 | 328 | parameters['beams'] = beams #json.dumps(beams) |
|
323 | #print beams | |
|
324 | #print parameters['beams'] | |
|
325 | 329 | print parameters |
|
326 | 330 | answer = '' |
|
327 | 331 | |
|
328 | 332 | try: |
|
329 | 333 | #r_write = requests.post(write_route, parameters, timeout=0.5) |
|
330 | 334 | r_write = requests.post(write_route, json = parameters, timeout=0.5) |
|
331 | 335 | answer = r_write.json() |
|
332 | self.message = answer['message'] | |
|
336 | #self.message = answer['message'] | |
|
333 | 337 | except: |
|
334 | self.message = "Could not write ABS parameters" | |
|
335 |
return |
|
|
336 | return 1 | |
|
338 | #self.message = "Could not write ABS parameters" | |
|
339 | return False | |
|
340 | ||
|
341 | return answer | |
|
337 | 342 | |
|
338 | 343 | |
|
339 | 344 | |
|
340 | 345 | def write_device(self): |
|
341 | 346 | """ |
|
342 | 347 | This function sends the beams list to every abs module. |
|
343 | 348 | It needs 'module_conf' function |
|
344 | 349 | """ |
|
345 | 350 | |
|
346 | 351 | beams = ABSBeam.objects.filter(abs_conf=self) |
|
347 | 352 | |
|
348 | 353 | #-------------Write each abs module----------- |
|
349 | 354 | if beams: |
|
350 | 355 | beams_status = ast.literal_eval(self.module_status) |
|
351 | for i in range(61,64): #(62,65) | |
|
356 | disconnected_modules = 0 | |
|
357 | for i in range(1,65): #(62,65) | |
|
358 | #--------------JUEVES------------- | |
|
359 | if beams_status[str(i)] != 0: | |
|
352 | 360 | try: |
|
353 | 361 |
answer = self.module_conf(i, |
|
354 | beams_status[str(i)] = 1 | |
|
355 | self.module_status = json.dumps(beams_status) | |
|
356 | self.save() | |
|
362 | if answer: | |
|
363 | if answer['status']: | |
|
364 | beams_status[str(i)] = 3 | |
|
357 | 365 | |
|
358 | 366 | except: |
|
359 |
beams_status[str(i)] = |
|
|
360 | self.module_status = json.dumps(beams_status) | |
|
361 |
s |
|
|
362 |
|
|
|
363 |
|
|
|
367 | beams_status[str(i)] = 1 | |
|
368 | ||
|
369 | pass | |
|
370 | else: | |
|
371 | disconnected_modules += 1 | |
|
372 | #--------------JUEVES------------- | |
|
373 | #try: | |
|
374 | # answer = self.module_conf(i, beams) | |
|
375 | # beams_status[str(i)] = 1 | |
|
376 | # self.module_status = json.dumps(beams_status) | |
|
377 | # self.save() | |
|
378 | ||
|
379 | #except: | |
|
380 | # beams_status[str(i)] = 0 | |
|
381 | # self.module_status = json.dumps(beams_status) | |
|
382 | # self.save() | |
|
383 | # answer = 0 | |
|
384 | # return 0 | |
|
364 | 385 | else: |
|
365 | 386 | self.message = "ABS Configuration does not have beams" |
|
366 |
return |
|
|
387 | return False | |
|
367 | 388 | |
|
368 | 389 | #self.device.status = 1 |
|
369 | 390 | ## |
|
370 | if answer==1: | |
|
391 | #-------------Jueves------------- | |
|
392 | if disconnected_modules == 64: | |
|
393 | self.message = "Could not write ABS Modules" | |
|
394 | return False | |
|
395 | else: | |
|
371 | 396 | self.message = "ABS Beams List have been sent to ABS Modules" |
|
372 | 397 | beams[0].set_as_activebeam() |
|
373 | else: | |
|
374 | self.message = "Could not read ABS parameters" | |
|
398 | ||
|
399 | self.module_status = json.dumps(beams_status) | |
|
400 | self.save() | |
|
401 | ||
|
402 | #-------------Jueves------------- | |
|
403 | #if answer==1: | |
|
404 | # self.message = "ABS Beams List have been sent to ABS Modules" | |
|
405 | # beams[0].set_as_activebeam() | |
|
406 | #else: | |
|
407 | # self.message = "Could not read ABS parameters" | |
|
375 | 408 | ## |
|
376 | 409 | self.save() |
|
377 |
return |
|
|
410 | return True | |
|
378 | 411 | |
|
379 | 412 | |
|
380 | 413 | |
|
381 | 414 | |
|
382 | 415 | def read_module(self, module): |
|
383 | 416 | |
|
384 | 417 | """ |
|
385 | 418 | Read out-bits (up-down) of 1 abs module NOT for Configuration |
|
386 | 419 | """ |
|
387 | 420 | |
|
388 | 421 | parameters = {} |
|
389 | 422 | ip_address = self.device.ip_address |
|
390 | 423 | ip_address = ip_address.split('.') |
|
391 | 424 | module_seq = (ip_address[0],ip_address[1],ip_address[2]) |
|
392 | 425 | dot = '.' |
|
393 | 426 | module_ip = dot.join(module_seq)+'.'+str(module) |
|
394 | 427 | module_port = self.device.port_address |
|
395 | 428 | read_route = 'http://'+module_ip+':'+str(module_port)+'/read' |
|
396 | 429 | |
|
397 | 430 | print(read_route) |
|
398 | 431 | |
|
399 | 432 | answer = '' |
|
400 | 433 | module_bits = '' |
|
401 | 434 | |
|
402 | 435 | try: |
|
403 | 436 | r_write = requests.get(read_route, timeout=0.7) |
|
404 | 437 | answer = r_write.json() |
|
405 | 438 | self.message = answer['message'] |
|
406 | 439 | module_bits = answer['allbits'] |
|
407 | 440 | except: |
|
408 | 441 | #message = "Could not read ABS parameters" |
|
409 | 442 | answer = r_write.json() |
|
410 | 443 | return 0 |
|
411 | 444 | |
|
412 | 445 | return module_bits |
|
413 | 446 | |
|
414 | 447 | |
|
415 | 448 | def absmodule_status(self): |
|
416 | 449 | """ |
|
417 | 450 | This function gets the status of each abs module. It sends GET method to Web Application |
|
418 | 451 | in Python Bottle. |
|
419 | 452 | This function updates "module_status" field from ABSconfiguration. |
|
420 | 453 | """ |
|
421 | 454 | ip_address = self.device.ip_address |
|
422 | 455 | ip_address = ip_address.split('.') |
|
423 | 456 | module_seq = (ip_address[0],ip_address[1],ip_address[2]) |
|
424 | 457 | dot = '.' |
|
425 | 458 | module_port = self.device.port_address |
|
426 | 459 | |
|
427 | 460 | modules_status = json.loads(self.module_status) |
|
428 | 461 | |
|
429 | 462 | for i in range(1,65): |
|
430 | 463 | module_ip = dot.join(module_seq)+'.'+str(i) |
|
431 | 464 | print module_ip |
|
432 | 465 | |
|
433 | 466 | route = 'http://'+module_ip+':'+str(module_port)+'/hello' |
|
434 | 467 | |
|
435 | 468 | try: |
|
436 | 469 | r = requests.get(route, timeout=0.7) |
|
437 | 470 | modules_status[str(i)] = 1 |
|
438 | 471 | except: |
|
439 | 472 | modules_status[str(i)] = 0 |
|
440 | 473 | pass |
|
441 | 474 | |
|
442 | 475 | |
|
443 | 476 | self.module_status=json.dumps(modules_status) |
|
444 | 477 | self.save() |
|
445 | 478 | |
|
446 | 479 | return |
|
447 | 480 | |
|
448 | 481 | |
|
449 | 482 | def connected_modules(self): |
|
450 | 483 | """ |
|
451 | 484 | This function returns the number of connected abs-modules without updating. |
|
452 | 485 | """ |
|
453 | 486 | modules_status = json.loads(self.module_status) |
|
454 | 487 | num = 0 |
|
455 | 488 | for status in modules_status: |
|
456 |
|
|
|
489 | if modules_status[status] != 0: | |
|
490 | num += 1 | |
|
457 | 491 | |
|
458 | 492 | return num |
|
459 | 493 | |
|
460 | 494 | |
|
461 | 495 | def status_device(self): |
|
462 | 496 | """ |
|
463 | 497 | This function returns the status of all abs-modules as one. |
|
464 | 498 | If at least one module is connected, its answer is "1" |
|
465 | 499 | """ |
|
466 | 500 | self.absmodule_status() |
|
467 | 501 | connected_modules = self.connected_modules() |
|
468 | 502 | if connected_modules>0: |
|
469 | 503 | self.message = 'ABS modules Status have been updated.' |
|
470 | 504 | return 1 |
|
471 | 505 | self.message = 'No ABS module is connected.' |
|
472 | 506 | return 0 |
|
473 | 507 | |
|
474 | 508 | |
|
475 | 509 | |
|
476 | 510 | def write_module(self, module): |
|
477 | 511 | |
|
478 | 512 | """ |
|
479 | 513 | Send configuration to one abs module |
|
480 | 514 | """ |
|
481 | 515 | |
|
482 | 516 | parameters = {} |
|
483 | 517 | ip_address = self.abs_conf.device.ip_address |
|
484 | 518 | ip_address = ip_address.split('.') |
|
485 | 519 | module_seq = (ip_address[0],ip_address[1],ip_address[2]) |
|
486 | 520 | dot = '.' |
|
487 | 521 | module_ip = dot.join(module_seq)+'.'+str(module) |
|
488 | 522 | module_port = self.abs_conf.device.port_address |
|
489 | 523 | write_route = 'http://'+module_ip+':'+str(module_port)+'/write' |
|
490 | 524 | |
|
491 | 525 | #print write_route |
|
492 | 526 | |
|
493 | 527 | header = 'JROABSCeCnModCnMod01000108SNDFexperimento1.ab1' |
|
494 | 528 | module = 'ABS_'+str(module) |
|
495 | 529 | beams = {1: '001000', 2: '010001', 3: '010010', 4: '000011', 5: '101100', 6: '101101', |
|
496 | 530 | 7: '110110', 8: '111111', 9: '000000', 10: '001001', 11: '010010', 12: '011011'} |
|
497 | 531 | |
|
498 | 532 | parameters['header'] = header |
|
499 | 533 | parameters['module'] = module |
|
500 | 534 | parameters['beams'] = json.dumps(beams) |
|
501 | 535 | |
|
502 | 536 | answer = '' |
|
503 | 537 | |
|
504 | 538 | try: |
|
505 | 539 | r_write = requests.post(write_route, parameters, timeout=0.5) |
|
506 | 540 | answer = r_write.json() |
|
507 | 541 | self.message = answer['message'] |
|
508 | 542 | except: |
|
509 | 543 | self.message = "Could not write ABS parameters" |
|
510 | 544 | return 0 |
|
511 | 545 | |
|
512 | 546 | |
|
513 | 547 | #self.device.status = int(answer['status']) |
|
514 | 548 | |
|
515 | 549 | return 1 |
|
516 | 550 | |
|
517 | 551 | |
|
518 | 552 | def beam_selector(self, module, beam_pos): |
|
519 | 553 | """ |
|
520 | 554 | This function selects the beam number for one absmodule. |
|
521 | 555 | """ |
|
522 | 556 | |
|
523 | 557 | if beam_pos > 0: |
|
524 | 558 | beam_pos = beam_pos - 1 |
|
525 | 559 | else: |
|
526 | 560 | beam_pos = 0 |
|
527 | 561 | |
|
528 | 562 | #El indice del apunte debe ser menor que el numero total de apuntes |
|
529 | 563 | #El servidor tcp en el embebido comienza a contar desde 0 |
|
530 | 564 | beams_list = ABSBeam.objects.filter(abs_conf=self) |
|
531 | 565 | if len(beams_list) < beam_pos: |
|
532 | 566 | return 0 |
|
533 | 567 | |
|
534 | 568 | flag = 1 |
|
535 | 569 | if beam_pos>9: |
|
536 | 570 | flag = 2 |
|
537 | 571 | |
|
538 | 572 | module_address = ('192.168.1.'+str(module), 5500) |
|
539 | 573 | header = 'JROABSCeCnModCnMod0100000' |
|
540 | 574 | numbers = len(str(beam_pos)) |
|
541 | 575 | function = 'CHGB' |
|
542 | 576 | |
|
543 | 577 | message_tx = header+str(numbers)+function+str(beam_pos)+'0' |
|
544 | 578 | |
|
545 | 579 | # Create the datagram socket |
|
546 | 580 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
547 | 581 | #sock.connect(module_address) |
|
548 | 582 | try: |
|
549 | 583 | sock.connect(module_address) |
|
550 | 584 | sock.send(message_tx) |
|
551 | 585 | sock.close() |
|
552 | 586 | print("Writing abs module:"+module_address[0]+"...") |
|
553 | 587 | except: |
|
554 | 588 | sock = None |
|
555 | 589 | print("Problem writing abs module:"+module_address[0]) |
|
556 | 590 | return 0 |
|
557 | 591 | |
|
558 | 592 | return 1 |
|
559 | 593 | |
|
560 | 594 | |
|
561 | 595 | def change_beam(self, beam_pos): |
|
562 | 596 | """ |
|
563 | 597 | This function selects the beam number for all absmodules. |
|
564 | 598 | """ |
|
565 | 599 | for i in range(1,65): |
|
566 | 600 | try: |
|
567 | 601 | self.beam_selector(i,beam_pos) |
|
568 | 602 | except: |
|
569 | 603 | print("Problem with module: 192.168.1."+str(i)) |
|
570 | 604 | self.message = "Problem with module: 192.168.1."+str(i) |
|
571 | 605 | #return 0 |
|
572 | 606 | return 1 |
|
573 | 607 | |
|
574 | 608 | |
|
575 | 609 | def send_beam_num(self, beam_pos): |
|
576 | 610 | """ |
|
577 | 611 | This function connects to a multicast group and sends the beam number |
|
578 | 612 | to all abs modules. |
|
579 | 613 | """ |
|
580 | 614 | |
|
581 | 615 | if beam_pos > 0: |
|
582 | 616 | beam_pos = beam_pos - 1 |
|
583 | 617 | else: |
|
584 | 618 | beam_pos = 0 |
|
585 | 619 | |
|
586 | 620 | #El indice del apunte debe ser menor que el numero total de apuntes |
|
587 | 621 | #El servidor tcp en el embebido comienza a contar desde 0 |
|
588 | 622 | beams_list = ABSBeam.objects.filter(abs_conf=self) |
|
589 | 623 | if len(beams_list) < beam_pos: |
|
590 | 624 | return 0 |
|
591 | 625 | |
|
592 | 626 | flag = 1 |
|
593 | 627 | if beam_pos>9: |
|
594 | 628 | flag = 2 |
|
595 | 629 | |
|
596 | 630 | header = 'JROABSCeCnModCnMod0100000' |
|
597 | 631 | flag = str(flag) |
|
598 | 632 | function = 'CHGB' |
|
599 | 633 | message_tx = header+flag+function+str(beam_pos)+'0' |
|
600 | 634 | |
|
601 | 635 | multicast_group = '224.3.29.71' |
|
602 | 636 | server_address = ('',10000) |
|
603 | 637 | |
|
604 | 638 | # Create the socket |
|
605 | 639 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
|
606 | 640 | # Bind to the server address |
|
607 | 641 | sock.bind(server_address) |
|
608 | 642 | # Telling the OS add the socket to the multicast on all interfaces |
|
609 | 643 | group = socket.inet_aton(multicast_group) |
|
610 | 644 | mreq = struct.pack('4sL', group, socket.INADDR_ANY) |
|
611 | 645 | sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq) |
|
612 | 646 | |
|
613 | 647 | #print 'sending acknowledgement to all: \n' + message_tx |
|
614 | 648 | sock.sendto(message_tx, (multicast_group, 10000)) |
|
615 | 649 | sock.close() |
|
616 | 650 | sock = None |
|
617 | 651 | |
|
618 | 652 | return 1 |
|
619 | 653 | |
|
620 | 654 | def test1(self): |
|
621 | 655 | t1 = time.time() |
|
622 | 656 | t2 = 0 |
|
623 | 657 | while (t2-t1)<100:#300 |
|
624 | 658 | t2 = time.time() |
|
625 | 659 | self.send_beam_num(2) |
|
626 | 660 | time.sleep(0.04) |
|
627 | 661 | self.send_beam_num(1) |
|
628 | 662 | time.sleep(0.04) |
|
629 | 663 | return |
|
630 | 664 | |
|
631 | 665 | def change_procs_test1(self, module): |
|
632 | 666 | |
|
633 | 667 | for i in range (1,300):#300 |
|
634 | 668 | beam_pos = 1 |
|
635 | 669 | module_address = ('192.168.1.'+str(module), 5500) |
|
636 | 670 | header = 'JROABSCeCnModCnMod0100000' |
|
637 | 671 | numbers = len(str(beam_pos)) |
|
638 | 672 | function = 'CHGB' |
|
639 | 673 | |
|
640 | 674 | message_tx = header+str(numbers)+function+str(beam_pos)+'0' |
|
641 | 675 | |
|
642 | 676 | # Create the datagram socket |
|
643 | 677 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
644 | 678 | sock.connect(module_address) |
|
645 | 679 | |
|
646 | 680 | sock.send(message_tx) |
|
647 | 681 | #t = sock.recv(1024) |
|
648 | 682 | sock.close() |
|
649 | 683 | sock = None |
|
650 | 684 | |
|
651 | 685 | |
|
652 | 686 | time.sleep(0.04) |
|
653 | 687 | |
|
654 | 688 | |
|
655 | 689 | beam_pos = 0 |
|
656 | 690 | numbers = len(str(beam_pos)) |
|
657 | 691 | |
|
658 | 692 | message_tx = header+str(numbers)+function+str(beam_pos)+'0' |
|
659 | 693 | |
|
660 | 694 | # Create the datagram socket |
|
661 | 695 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
662 | 696 | sock.connect(module_address) |
|
663 | 697 | sock.send(message_tx) |
|
664 | 698 | sock.close() |
|
665 | 699 | sock = None |
|
666 | 700 | |
|
667 | 701 | time.sleep(0.04) |
|
668 | 702 | |
|
669 | 703 | |
|
670 | 704 | def multi_procs_test1(self): |
|
671 | 705 | |
|
672 | 706 | """ |
|
673 | 707 | This function sends the beam number to all abs modules using multiprocessing. |
|
674 | 708 | """ |
|
675 | 709 | |
|
676 | 710 | #if __name__ == "__main__": |
|
677 | 711 | size = 10000000 # Number of random numbers to add |
|
678 | 712 | procs = 65 # (Number-1) of processes to create (absmodule) |
|
679 | 713 | |
|
680 | 714 | # Create a list of jobs and then iterate through |
|
681 | 715 | # the number of processes appending each process to |
|
682 | 716 | # the job list |
|
683 | 717 | jobs = [] |
|
684 | 718 | for i in range(1, procs): |
|
685 | 719 | |
|
686 | 720 | process = multiprocessing.Process(target=self.change_procs_test1,args=(i,)) |
|
687 | 721 | jobs.append(process) |
|
688 | 722 | #print jobs |
|
689 | 723 | |
|
690 | 724 | # Start the processes (i.e. calculate the random number lists) |
|
691 | 725 | for j in jobs: |
|
692 | 726 | #time.sleep(0.4) |
|
693 | 727 | #print j |
|
694 | 728 | j.start() |
|
695 | 729 | |
|
696 | 730 | # Ensure all of the processes have finished |
|
697 | 731 | for j in jobs: |
|
698 | 732 | j.join() |
|
699 | 733 | |
|
700 | 734 | print("List processing complete.") |
|
701 | 735 | return 1 |
|
702 | 736 | |
|
703 | 737 | |
|
704 | 738 | |
|
705 | 739 | def multi_procs_test2(self): |
|
706 | 740 | """ |
|
707 | 741 | This function use multiprocessing python library. Importing Pool we can select |
|
708 | 742 | the number of cores we want to use |
|
709 | 743 | After 'nproc' linux command, we know how many cores computer has. |
|
710 | 744 | NOT WORKING |
|
711 | 745 | """ |
|
712 | 746 | import multiprocessing |
|
713 | 747 | pool = multiprocessing.Pool(3) # cores |
|
714 | 748 | |
|
715 | 749 | tasks = [] |
|
716 | 750 | procs = 65 |
|
717 | 751 | for i in range(62, procs): |
|
718 | 752 | tasks.append( (i,)) |
|
719 | 753 | #print tasks |
|
720 | 754 | #pool.apply_async(self.change_procs_test1, 62) |
|
721 | 755 | results = [pool.apply( self.change_procs_test1, t ) for t in tasks] |
|
722 | 756 | #for result in results: |
|
723 | 757 | #result.get() |
|
724 | 758 | #(plotNum, plotFilename) = result.get() |
|
725 | 759 | #print("Result: plot %d written to %s" % (plotNum, plotFilename) ) |
|
726 | 760 | |
|
727 | 761 | return 1 |
|
728 | 762 | |
|
729 | 763 | |
|
730 | 764 | def multi_procs_test3(self): |
|
731 | 765 | """ |
|
732 | 766 | This function use multiprocessing python library. Importing Pool we can select |
|
733 | 767 | the number of cores we want to use |
|
734 | 768 | After 'nproc' linux command, we know how many cores computer has. |
|
735 | 769 | """ |
|
736 | 770 | from multiprocessing import Pool |
|
737 | 771 | import time |
|
738 | 772 | |
|
739 | 773 | def f(x): |
|
740 | 774 | return x*x |
|
741 | 775 | |
|
742 | 776 | tasks = [] |
|
743 | 777 | procs = 65 |
|
744 | 778 | pool = Pool(processes=4) |
|
745 | 779 | |
|
746 | 780 | #for i in range(62, procs): |
|
747 | 781 | #result = pool.map(f, range(62,65)) |
|
748 | 782 | it = pool.imap(self.change_procs_test1, range(62,65)) |
|
749 | 783 | #result.get(timeout=5) |
|
750 | 784 | |
|
751 | 785 | return 1 |
|
752 | 786 | |
|
753 | 787 | |
|
754 | 788 | def f(x): |
|
755 | 789 | print x |
|
756 | 790 | return |
|
757 | 791 | |
|
758 | 792 | def multi_procs_test4(self): |
|
759 | 793 | import multiprocessing as mp |
|
760 | 794 | |
|
761 | 795 | |
|
762 | 796 | num_workers = mp.cpu_count() |
|
763 | 797 | |
|
764 | 798 | pool = mp.Pool(num_workers) |
|
765 | 799 | procs = 65 |
|
766 | 800 | for i in range(62, procs): |
|
767 | 801 | #for task in tasks: |
|
768 | 802 | pool.apply_async(self.f, args = (i,)) |
|
769 | 803 | |
|
770 | 804 | pool.close() |
|
771 | 805 | pool.join() |
|
772 | 806 | |
|
773 | 807 | return 1 |
|
774 | 808 | |
|
775 | 809 | |
|
776 | 810 | def get_absolute_url_import(self): |
|
777 | 811 | return reverse('url_import_abs_conf', args=[str(self.id)]) |
|
778 | 812 | |
|
779 | 813 | |
|
780 | 814 | |
|
781 | 815 | |
|
782 | 816 | class ABSBeam(models.Model): |
|
783 | 817 | |
|
784 | 818 | name = models.CharField(max_length=60, default='Beam') |
|
785 | 819 | antenna = models.CharField(verbose_name='Antenna', max_length=1000, default=antenna_default) |
|
786 | 820 | abs_conf = models.ForeignKey(ABSConfiguration, null=True, verbose_name='ABS Configuration') |
|
787 | 821 | tx = models.CharField(verbose_name='Tx', max_length=1000, default=tx_default) |
|
788 | 822 | rx = models.CharField(verbose_name='Rx', max_length=1000, default=rx_default) |
|
789 | 823 | s_time = models.TimeField(verbose_name='Star Time', default='00:00:00') |
|
790 | 824 | e_time = models.TimeField(verbose_name='End Time', default='23:59:59') |
|
791 | 825 | modules_conf = models.CharField(verbose_name='Modules', max_length=2000, default=json.dumps(conf_default)) |
|
792 | 826 | ues = models.CharField(verbose_name='Ues', max_length=100, default=ues_default) |
|
793 | 827 | only_rx = models.CharField(verbose_name='Only RX', max_length=40, default=onlyrx_default) |
|
794 | 828 | |
|
795 | 829 | class Meta: |
|
796 | 830 | db_table = 'abs_beams' |
|
797 | 831 | |
|
798 | 832 | def __unicode__(self): |
|
799 | 833 | return u'%s' % (self.name) |
|
800 | 834 | |
|
801 | 835 | def parms_to_dict(self): |
|
802 | 836 | |
|
803 | 837 | #Update data |
|
804 | 838 | self.modules_6bits() |
|
805 | 839 | |
|
806 | 840 | parameters = {} |
|
807 | 841 | |
|
808 | 842 | parameters['name'] = self.name |
|
809 | 843 | parameters['antenna'] = ast.literal_eval(self.antenna) |
|
810 | 844 | parameters['abs_conf'] = self.abs_conf.name |
|
811 | 845 | parameters['tx'] = ast.literal_eval(self.tx) |
|
812 | 846 | parameters['rx'] = ast.literal_eval(self.rx) |
|
813 | 847 | parameters['s_time'] = self.s_time.strftime("%H:%M:%S") |
|
814 | 848 | parameters['e_time'] = self.e_time.strftime("%H:%M:%S") |
|
815 | 849 | parameters['configuration'] = ast.literal_eval(self.modules_conf) |
|
816 | 850 | parameters['ues'] = ast.literal_eval(self.ues) |
|
817 | 851 | parameters['only_rx'] = json.loads(self.only_rx) |
|
818 | 852 | |
|
819 | 853 | return parameters |
|
820 | 854 | |
|
821 | 855 | def dict_to_parms(self, parameters): |
|
822 | 856 | |
|
823 | 857 | self.name = parameters['name'] |
|
824 | 858 | self.antenna = json.dumps(parameters['antenna']) |
|
825 | 859 | #self.abs_conf = parameters['abs_conf'] |
|
826 | 860 | self.tx = json.dumps(parameters['tx']) |
|
827 | 861 | self.rx = json.dumps(parameters['rx']) |
|
828 | 862 | #self.s_time = parameters['s_time'] |
|
829 | 863 | #self.e_time = parameters['e_time'] |
|
830 | 864 | self.ues = json.dumps(parameters['ues']) |
|
831 | 865 | self.only_rx = json.dumps(parameters['only_rx']) |
|
832 | 866 | |
|
833 | 867 | self.modules_6bits() |
|
834 | 868 | self.save() |
|
835 | 869 | |
|
836 | 870 | |
|
837 | 871 | def clone(self, **kwargs): |
|
838 | 872 | |
|
839 | 873 | self.pk = None |
|
840 | 874 | self.id = None |
|
841 | 875 | for attr, value in kwargs.items(): |
|
842 | 876 | setattr(self, attr, value) |
|
843 | 877 | |
|
844 | 878 | self.save() |
|
845 | 879 | |
|
846 | 880 | return self |
|
847 | 881 | |
|
848 | 882 | |
|
849 | 883 | |
|
850 | 884 | def module_6bits(self, module): |
|
851 | 885 | """ |
|
852 | 886 | This function reads antenna pattern and choose 6bits (upbits-downbits) for one abs module |
|
853 | 887 | """ |
|
854 | 888 | if module > 64: |
|
855 | 889 | beam_bits = "" |
|
856 | 890 | return beam_bits |
|
857 | 891 | |
|
858 | 892 | data = ast.literal_eval(self.antenna) |
|
859 | 893 | up_data = data['antenna_up'] |
|
860 | 894 | down_data = data['antenna_down'] |
|
861 | 895 | |
|
862 | 896 | pos = ip2position(module) |
|
863 | 897 | up_value = up_data[pos[0]][pos[1]] |
|
864 | 898 | down_value = down_data[pos[0]][pos[1]] |
|
865 | 899 | |
|
866 | 900 | up_bits = up_conv_bits(up_value) |
|
867 | 901 | down_bits = down_conv_bits(down_value) |
|
868 | 902 | beam_bits = up_bits+down_bits |
|
869 | 903 | |
|
870 | 904 | return beam_bits |
|
871 | 905 | |
|
872 | 906 | def modules_6bits(self): |
|
873 | 907 | """ |
|
874 | 908 | This function returns 6bits from every abs module (1-64) in a dict |
|
875 | 909 | """ |
|
876 | 910 | modules_configuration = ast.literal_eval(self.modules_conf) |
|
877 | 911 | |
|
878 | 912 | for i in range(1,65): |
|
879 | 913 | modules_configuration[str(i)] = self.module_6bits(i) |
|
880 | 914 | |
|
881 | 915 | self.modules_conf = json.dumps(modules_configuration) |
|
882 | 916 | self.save() |
|
883 | 917 | |
|
884 | 918 | return self.modules_conf |
|
885 | 919 | |
|
886 | 920 | |
|
887 | 921 | def set_as_activebeam(self): |
|
888 | 922 | """ |
|
889 | 923 | This function set this beam as the active beam of its ABS Configuration. |
|
890 | 924 | """ |
|
891 | 925 | self.abs_conf.active_beam = json.dumps({'active_beam': self.id}) |
|
892 | 926 | self.abs_conf.save() |
|
893 | 927 | |
|
894 | 928 | return |
|
895 | 929 | |
|
896 | 930 | |
|
897 | 931 | @property |
|
898 | 932 | def get_upvalues(self): |
|
899 | 933 | """ |
|
900 | 934 | This function reads antenna pattern and show the up-value of one abs module |
|
901 | 935 | """ |
|
902 | 936 | |
|
903 | 937 | data = ast.literal_eval(self.antenna) |
|
904 | 938 | up_data = data['antenna_up'] |
|
905 | 939 | |
|
906 | 940 | up_values = [] |
|
907 | 941 | for data in up_data: |
|
908 | 942 | for i in range(0,8): |
|
909 | 943 | up_values.append(data[i]) |
|
910 | 944 | |
|
911 | 945 | return up_values |
|
912 | 946 | |
|
913 | 947 | @property |
|
914 | 948 | def antenna_upvalues(self): |
|
915 | 949 | """ |
|
916 | 950 | This function reads antenna pattern and show the up - values of one abs beam |
|
917 | 951 | in a particular order |
|
918 | 952 | """ |
|
919 | 953 | data = ast.literal_eval(self.antenna) |
|
920 | 954 | up_data = data['antenna_up'] |
|
921 | 955 | |
|
922 | 956 | return up_data |
|
923 | 957 | |
|
924 | 958 | @property |
|
925 | 959 | def antenna_downvalues(self): |
|
926 | 960 | """ |
|
927 | 961 | This function reads antenna pattern and show the down - values of one abs beam |
|
928 | 962 | in a particular order |
|
929 | 963 | """ |
|
930 | 964 | data = ast.literal_eval(self.antenna) |
|
931 | 965 | down_data = data['antenna_down'] |
|
932 | 966 | |
|
933 | 967 | return down_data |
|
934 | 968 | |
|
935 | 969 | @property |
|
936 | 970 | def get_downvalues(self): |
|
937 | 971 | """ |
|
938 | 972 | This function reads antenna pattern and show the down-value of one abs module |
|
939 | 973 | """ |
|
940 | 974 | |
|
941 | 975 | data = ast.literal_eval(self.antenna) |
|
942 | 976 | down_data = data['antenna_down'] |
|
943 | 977 | |
|
944 | 978 | down_values = [] |
|
945 | 979 | for data in down_data: |
|
946 | 980 | for i in range(0,8): |
|
947 | 981 | down_values.append(data[i]) |
|
948 | 982 | |
|
949 | 983 | return down_values |
|
950 | 984 | |
|
951 | 985 | @property |
|
952 | 986 | def get_up_ues(self): |
|
953 | 987 | """ |
|
954 | 988 | This function shows the up-ues-value of one beam |
|
955 | 989 | """ |
|
956 | 990 | data = ast.literal_eval(self.ues) |
|
957 | 991 | up_ues = data['up'] |
|
958 | 992 | |
|
959 | 993 | return up_ues |
|
960 | 994 | |
|
961 | 995 | @property |
|
962 | 996 | def get_down_ues(self): |
|
963 | 997 | """ |
|
964 | 998 | This function shows the down-ues-value of one beam |
|
965 | 999 | """ |
|
966 | 1000 | data = ast.literal_eval(self.ues) |
|
967 | 1001 | down_ues = data['down'] |
|
968 | 1002 | |
|
969 | 1003 | return down_ues |
|
970 | 1004 | |
|
971 | 1005 | @property |
|
972 | 1006 | def get_up_onlyrx(self): |
|
973 | 1007 | """ |
|
974 | 1008 | This function shows the up-onlyrx-value of one beam |
|
975 | 1009 | """ |
|
976 | 1010 | data = json.loads(self.only_rx) |
|
977 | 1011 | up_onlyrx = data['up'] |
|
978 | 1012 | |
|
979 | 1013 | return up_onlyrx |
|
980 | 1014 | |
|
981 | 1015 | @property |
|
982 | 1016 | def get_down_onlyrx(self): |
|
983 | 1017 | """ |
|
984 | 1018 | This function shows the down-onlyrx-value of one beam |
|
985 | 1019 | """ |
|
986 | 1020 | data = json.loads(self.only_rx) |
|
987 | 1021 | down_onlyrx = data['down'] |
|
988 | 1022 | |
|
989 | 1023 | return down_onlyrx |
|
990 | 1024 | |
|
991 | 1025 | @property |
|
992 | 1026 | def get_tx(self): |
|
993 | 1027 | """ |
|
994 | 1028 | This function shows the tx-values of one beam |
|
995 | 1029 | """ |
|
996 | 1030 | data = json.loads(self.tx) |
|
997 | 1031 | |
|
998 | 1032 | return data |
|
999 | 1033 | |
|
1000 | 1034 | @property |
|
1001 | 1035 | def get_uptx(self): |
|
1002 | 1036 | """ |
|
1003 | 1037 | This function shows the up-tx-values of one beam |
|
1004 | 1038 | """ |
|
1005 | 1039 | data = json.loads(self.tx) |
|
1006 | 1040 | up_data = data['up'] |
|
1007 | 1041 | |
|
1008 | 1042 | up_values = [] |
|
1009 | 1043 | for data in up_data: |
|
1010 | 1044 | for i in range(0,8): |
|
1011 | 1045 | up_values.append(data[i]) |
|
1012 | 1046 | |
|
1013 | 1047 | return up_values |
|
1014 | 1048 | |
|
1015 | 1049 | @property |
|
1016 | 1050 | def get_downtx(self): |
|
1017 | 1051 | """ |
|
1018 | 1052 | This function shows the down-tx-values of one beam |
|
1019 | 1053 | """ |
|
1020 | 1054 | data = json.loads(self.tx) |
|
1021 | 1055 | down_data = data['down'] |
|
1022 | 1056 | |
|
1023 | 1057 | down_values = [] |
|
1024 | 1058 | for data in down_data: |
|
1025 | 1059 | for i in range(0,8): |
|
1026 | 1060 | down_values.append(data[i]) |
|
1027 | 1061 | |
|
1028 | 1062 | return down_values |
|
1029 | 1063 | |
|
1030 | 1064 | |
|
1031 | 1065 | |
|
1032 | 1066 | @property |
|
1033 | 1067 | def get_rx(self): |
|
1034 | 1068 | """ |
|
1035 | 1069 | This function shows the rx-values of one beam |
|
1036 | 1070 | """ |
|
1037 | 1071 | data = json.loads(self.rx) |
|
1038 | 1072 | |
|
1039 | 1073 | return data |
|
1040 | 1074 | |
|
1041 | 1075 | @property |
|
1042 | 1076 | def get_uprx(self): |
|
1043 | 1077 | """ |
|
1044 | 1078 | This function shows the up-rx-values of one beam |
|
1045 | 1079 | """ |
|
1046 | 1080 | data = json.loads(self.rx) |
|
1047 | 1081 | up_data = data['up'] |
|
1048 | 1082 | |
|
1049 | 1083 | up_values = [] |
|
1050 | 1084 | for data in up_data: |
|
1051 | 1085 | for i in range(0,8): |
|
1052 | 1086 | up_values.append(data[i]) |
|
1053 | 1087 | |
|
1054 | 1088 | return up_values |
|
1055 | 1089 | |
|
1056 | 1090 | @property |
|
1057 | 1091 | def get_downrx(self): |
|
1058 | 1092 | """ |
|
1059 | 1093 | This function shows the down-rx-values of one beam |
|
1060 | 1094 | """ |
|
1061 | 1095 | data = json.loads(self.rx) |
|
1062 | 1096 | down_data = data['down'] |
|
1063 | 1097 | |
|
1064 | 1098 | down_values = [] |
|
1065 | 1099 | for data in down_data: |
|
1066 | 1100 | for i in range(0,8): |
|
1067 | 1101 | down_values.append(data[i]) |
|
1068 | 1102 | |
|
1069 | 1103 | return down_values |
@@ -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 |
if modules_status[status] == |
|
|
134 | if modules_status[status] == 3: #Running background-color: #00cc00; | |
|
135 | 135 | color_status[status] = 'class=text-success'#'bgcolor=#00cc00' |
|
136 | 136 | elif modules_status[status] == 1: #Connected background-color: #ee902c; |
|
137 | 137 | color_status[status] = 'class=text-warning'#'bgcolor=#ee902c' |
|
138 | 138 | else: #Disconnected background-color: #ff0000; |
|
139 | 139 | color_status[status] = 'class=text-danger'#'bgcolor=#FF0000' |
|
140 | 140 | #------------------------------------------------ |
|
141 | 141 | |
|
142 | 142 | kwargs = {} |
|
143 | 143 | #kwargs['status'] = conf.device.get_status_display() |
|
144 | 144 | kwargs['connected_modules'] = str(conf.connected_modules())+'/64' |
|
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 | 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