##// END OF EJS Templates
standardize functions in cgs device, abs device does not have read_device function...
Fiorella Quino -
r207:2d204f6ad0f7
parent child
Show More
@@ -1,1140 +1,1189
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 from celery.execute import send_task
6 6 from datetime import datetime
7 7 import ast
8 8 import socket
9 9 import json
10 10 import requests
11 11 import struct
12 12 import sys, time
13 13
14 14 import multiprocessing
15 15
16 16
17 17 antenna_default = json.dumps({
18 18 "antenna_up": [[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.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
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 [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0]
26 26 ]
27 27 ,
28 28 "antenna_down": [[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.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
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 [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0]],
36 36 })
37 37
38 38
39 39 tx_default = json.dumps({
40 40 "up": [[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 [1,1,1,1,0,0,0,0],
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 [0,0,0,0,1,1,1,1]],
48 48
49 49 "down": [[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 [1,1,1,1,0,0,0,0],
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 [0,0,0,0,1,1,1,1]],
57 57 })
58 58
59 59 rx_default = json.dumps({
60 60 "up": [[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 [1,1,1,1,0,0,0,0],
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 [0,0,0,0,1,1,1,1]],
68 68
69 69 "down": [[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 [1,1,1,1,0,0,0,0],
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 [0,0,0,0,1,1,1,1]],
77 77 })
78 78
79 79 conf_default = {}
80 80 status_default = {}
81 81 default_messages = {}
82 82 for i in range(1,65):
83 83 conf_default[str(i)] = ""
84 84 status_default[str(i)] = 0
85 85 default_messages[str(i)] = "Module "+str(i)
86 86
87 87
88 88 ues_default = json.dumps({
89 89 "up": [0.533333,0.00000,1.06667,0.00000],
90 90 "down": [0.533333,0.00000,1.06667,0.00000]
91 91 })
92 92
93 93 onlyrx_default = json.dumps({
94 94 "up": False,
95 95 "down": False
96 96 })
97 97
98 98 def up_convertion(cadena):
99 99 valores = []
100 100 for c in cadena:
101 101 if c == 1.0: valores=valores+['000']
102 102 if c == 2.0: valores=valores+['001']
103 103 if c == 3.0: valores=valores+['010']
104 104 if c == 0.0: valores=valores+['011']
105 105 if c == 0.5: valores=valores+['100']
106 106 if c == 1.5: valores=valores+['101']
107 107 if c == 2.5: valores=valores+['110']
108 108 if c == 3.5: valores=valores+['111']
109 109
110 110 return valores
111 111
112 112 def up_conv_bits(value):
113 113
114 114 if value == 1.0: bits="000"
115 115 if value == 2.0: bits="001"
116 116 if value == 3.0: bits="010"
117 117 if value == 0.0: bits="011"
118 118 if value == 0.5: bits="100"
119 119 if value == 1.5: bits="101"
120 120 if value == 2.5: bits="110"
121 121 if value == 3.5: bits="111"
122 122
123 123 return bits
124 124
125 125 def down_convertion(cadena):
126 126 valores = []
127 127 for c in cadena:
128 128 if c == 1.0: valores=valores+['000']
129 129 if c == 2.0: valores=valores+['001']
130 130 if c == 3.0: valores=valores+['010']
131 131 if c == 0.0: valores=valores+['011']
132 132 if c == 0.5: valores=valores+['100']
133 133 if c == 1.5: valores=valores+['101']
134 134 if c == 2.5: valores=valores+['110']
135 135 if c == 3.5: valores=valores+['111']
136 136
137 137 return valores
138 138
139 139 def down_conv_bits(value):
140 140
141 141 if value == 1.0: bits="000"
142 142 if value == 2.0: bits="001"
143 143 if value == 3.0: bits="010"
144 144 if value == 0.0: bits="011"
145 145 if value == 0.5: bits="100"
146 146 if value == 1.5: bits="101"
147 147 if value == 2.5: bits="110"
148 148 if value == 3.5: bits="111"
149 149
150 150 return bits
151 151
152 def up_conv_value(bits):
153
154 if bits == "000": value=1.0
155 if bits == "001": value=2.0
156 if bits == "010": value=3.0
157 if bits == "011": value=0.0
158 if bits == "100": value=0.5
159 if bits == "101": value=1.5
160 if bits == "110": value=2.5
161 if bits == "111": value=3.5
162
163 return value
164
165 def down_conv_value(bits):
166
167 if bits == "000": value=1.0
168 if bits == "001": value=2.0
169 if bits == "010": value=3.0
170 if bits == "011": value=0.0
171 if bits == "100": value=0.5
172 if bits == "101": value=1.5
173 if bits == "110": value=2.5
174 if bits == "111": value=3.5
175
176 return value
177
152 178 def ip2position(module_number):
153 179 j=0
154 180 i=0
155 181 for x in range(0,module_number-1):
156 182 j=j+1
157 183 if j==8:
158 184 i=i+1
159 185 j=0
160 186
161 187 pos = [i,j]
162 188 return pos
163 189
164 190
165 191 def fromBinary2Char(binary_string):
166 192 number = int(binary_string, 2)
167 193 #Plus 33 to avoid more than 1 characters values such as: '\x01'-'\x1f'
168 194 number = number + 33
169 195 char = chr(number)
170 196 return char
171 197
172 198 def fromChar2Binary(char):
173 199 number = ord(char) - 33
174 200 #Minus 33 to get the real value
175 201 bits = bin(number)[2:]
176 202 #To ensure we have a string with 6bits
177 203 if len(bits) < 6:
178 204 bits = bits.zfill(6)
179 205 return bits
180 206
181 207 OPERATION_MODES = (
182 208 (0, 'Manual'),
183 209 (1, 'Automatic'),
184 210 )
185 211
186 212
187 213 class ABSConfiguration(Configuration):
188 214 active_beam = models.CharField(verbose_name='Active Beam', max_length=20000, default="{}")
189 215 module_status = models.CharField(verbose_name='Module Status', max_length=10000, default=json.dumps(status_default))
190 216 operation_mode = models.PositiveSmallIntegerField(verbose_name='Operation Mode', choices=OPERATION_MODES, default = 0)
191 217 operation_value = models.FloatField(verbose_name='Periodic (seconds)', default="10", null=True, blank=True)
192 218 module_messages = models.CharField(verbose_name='Modules Messages', max_length=10000, default=json.dumps(default_messages))
193 219
194 220 class Meta:
195 221 db_table = 'abs_configurations'
196 222
197 223 def get_absolute_url_plot(self):
198 224 return reverse('url_plot_abs_patterns', args=[str(self.id)])
199 225
200 226
201 227 def parms_to_dict(self):
202 228
203 229 parameters = {}
204 230
205 231 parameters['device_id'] = self.device.id
206 232 parameters['name'] = self.name
207 233 parameters['beams'] = {}
208 234
209 235 beams = ABSBeam.objects.filter(abs_conf=self)
210 236 b=1
211 237 for beam in beams:
212 238 #absbeam = ABSBeam.objects.get(pk=beams[beam])
213 239 parameters['beams']['beam'+str(b)] = beam.parms_to_dict()#absbeam.parms_to_dict()
214 240 b+=1
215 241
216 242 return parameters
217 243
218 244 def dict_to_parms(self, parameters):
219 245
220 246 self.name = parameters['name']
221 247
222 248 absbeams = ABSBeam.objects.filter(abs_conf=self)
223 249 beams = parameters['beams']
224 250
225 251 if absbeams:
226 252 beams_number = len(beams)
227 253 absbeams_number = len(absbeams)
228 254 if beams_number==absbeams_number:
229 255 i = 1
230 256 for absbeam in absbeams:
231 257 absbeam.dict_to_parms(beams['beam'+str(i)])
232 258 i = i+1
233 259 elif beams_number > absbeams_number:
234 260 i = 1
235 261 for absbeam in absbeams:
236 262 absbeam.dict_to_parms(beams['beam'+str(i)])
237 263 i=i+1
238 264 for x in range(i,beams_number+1):
239 265 new_beam = ABSBeam(
240 266 name =beams['beam'+str(i)]['name'],
241 267 antenna =json.dumps(beams['beam'+str(i)]['antenna']),
242 268 abs_conf = self,
243 269 tx =json.dumps(beams['beam'+str(i)]['tx']),
244 270 rx =json.dumps(beams['beam'+str(i)]['rx']),
245 271 ues =json.dumps(beams['beam'+str(i)]['ues']),
246 272 only_rx =json.dumps(beams['beam'+str(i)]['only_rx'])
247 273 )
248 274 new_beam.save()
249 275 i=i+1
250 276 else: #beams_number < absbeams_number:
251 277 i = 1
252 278 for absbeam in absbeams:
253 279 if i <= beams_number:
254 280 absbeam.dict_to_parms(beams['beam'+str(i)])
255 281 i=i+1
256 282 else:
257 283 absbeam.delete()
258 284 else:
259 285 for beam in beams:
260 286 new_beam = ABSBeam(
261 287 name =beams[beam]['name'],
262 288 antenna =json.dumps(beams[beam]['antenna']),
263 289 abs_conf = self,
264 290 tx =json.dumps(beams[beam]['tx']),
265 291 rx =json.dumps(beams[beam]['rx']),
266 292 ues =json.dumps(beams[beam]['ues']),
267 293 only_rx =json.dumps(beams[beam]['only_rx'])
268 294 )
269 295 new_beam.save()
270 296
271 297
272 298
273 299 def update_from_file(self, parameters):
274 300
275 301 self.dict_to_parms(parameters)
276 302 self.save()
277 303
278 304
279 305 def get_beams(self, **kwargs):
280 306 '''
281 307 This function returns ABS Configuration beams
282 308 '''
283 309 return ABSBeam.objects.filter(abs_conf=self.pk, **kwargs)
284 310
285 311 def clone(self, **kwargs):
286 312
287 313 beams = self.get_beams()
288 314 self.pk = None
289 315 self.id = None
290 316 for attr, value in kwargs.items():
291 317 setattr(self, attr, value)
292 318 self.save()
293 319
294 320 for beam in beams:
295 321 beam.clone(abs_conf=self)
296 322
297 323 #-----For Active Beam-----
298 324 active_beam = json.loads(self.active_beam)
299 325 new_beams = ABSBeam.objects.filter(abs_conf=self)
300 326 active_beam['active_beam'] = new_beams[0].id
301 327
302 328 self.active_beam = json.dumps(active_beam)
303 329 self.save()
304 330 #-----For Active Beam-----
305 331 #-----For Device Status---
306 332 self.device.status = 3
307 333 self.device.save()
308 334 #-----For Device Status---
309 335
310 336 return self
311 337
312 338
313 339 def start_device(self):
314 340
315 341 if self.device.status == 3:
316 342
317 343 try:
318 344 #self.write_device()
319 345 send_task('task_change_beam', [self.id],)
320 346 self.message = 'ABS running'
321 347
322 348 except Exception as e:
323 349 self.message = str(e)
324 350 return False
325 351
326 352 return True
327 353
328 354 else:
329 355 self.message = 'Please, select Write ABS Device first.'
330 356 return False
331 357
332 358
333 359 def stop_device(self):
334 360
335 361 self.device.status = 2
336 362 self.device.save()
337 363 self.message = 'ABS has been stopped.'
338 364 self.save()
339 365
340 366 return True
341 367
342 368
343 369 def module_conf(self, module_num, beams):
344 370 """
345 371 This function creates beam configurations for one abs module.
346 372 """
347 373 ip_address = self.device.ip_address
348 374 ip_address = ip_address.split('.')
349 375 module_seq = (ip_address[0],ip_address[1],ip_address[2])
350 376 dot = '.'
351 377 module_ip = dot.join(module_seq)+'.'+str(module_num)
352 378 module_port = self.device.port_address
353 379 write_route = 'http://'+module_ip+':'+str(module_port)+'/write'
354 380
355 381 #header = 'JROABSCeCnModCnMod01000108SNDFexperimento1.ab1'
356 382 #module = 'ABS_'+str(module_num)
357 383 bs = '' #{}
358 384 i=1
359 385
360 386 for beam in beams:
361 387 #bs[i] = fromBinary2Char(beam.module_6bits(module_num))
362 388 bs = bs + fromBinary2Char(beam.module_6bits(module_num))
363 389 i=i+1
364 390
365 391 beams = bs
366 392
367 393 parameters = {}
368 394 parameters['beams'] = beams #json.dumps(beams)
369 395 print parameters
370 396 answer = ''
371 397
372 398 try:
373 399 #r_write = requests.post(write_route, parameters, timeout=0.5)
374 400 r_write = requests.post(write_route, json = parameters, timeout=0.5)
375 401 answer = r_write.json()
376 402 #self.message = answer['message']
377 403 except:
378 404 #self.message = "Could not write ABS parameters"
379 405 return False
380 406
381 407 return answer
382 408
383 409
384 410
385 411 def write_device(self):
386 412
387 413 """
388 414 This function sends the beams list to every abs module.
389 415 It needs 'module_conf' function
390 416 """
391 417
392 418 beams = ABSBeam.objects.filter(abs_conf=self)
393 419 connected_modules = ast.literal_eval(self.module_status)
394 420 suma_connected_modules = 0
395 421
396 422 for c in connected_modules:
397 423 suma_connected_modules = suma_connected_modules+connected_modules[c]
398 424 if not suma_connected_modules > 0 :
399 425 self.message = "No ABS Module detected."
400 426 return False
401 427
402 428 #-------------Write each abs module-----------
403 429 if beams:
404 430 beams_status = ast.literal_eval(self.module_status)
405 431 disconnected_modules = 0
406 432 for i in range(1,65): #(62,65)
407 433 #--------------JUEVES-------------
408 434 if beams_status[str(i)] != 0:
409 435 try:
410 436 answer = self.module_conf(i,beams)
411 437 if answer:
412 438 if answer['status']:
413 439 beams_status[str(i)] = 3
414 440
415 441 except:
416 442 beams_status[str(i)] = 1
417 443
418 444 pass
419 445 else:
420 446 disconnected_modules += 1
421 447
422 448 else:
423 449 self.message = "ABS Configuration does not have beams"
424 450 return False
425 451
426 452 #self.device.status = 1
427 453 ##
428 454 #-------------Jueves-------------
429 455 if disconnected_modules == 64:
430 456 self.message = "Could not write ABS Modules"
431 457 self.device.status = 0
432 458 return False
433 459 else:
434 460 self.message = "ABS Beams List have been sent to ABS Modules"
435 461 beams[0].set_as_activebeam()
436 462
437 463 self.device.status = 3
438 464 self.module_status = json.dumps(beams_status)
439 465
440 466
441 467
442 468 self.save()
443 469 return True
444 470
445 471
446 472
447 473
448 474 def read_module(self, module):
449 475
450 476 """
451 477 Read out-bits (up-down) of 1 abs module NOT for Configuration
452 478 """
453 479
454 parameters = {}
455 480 ip_address = self.device.ip_address
456 481 ip_address = ip_address.split('.')
457 482 module_seq = (ip_address[0],ip_address[1],ip_address[2])
458 483 dot = '.'
459 484 module_ip = dot.join(module_seq)+'.'+str(module)
460 485 module_port = self.device.port_address
461 486 read_route = 'http://'+module_ip+':'+str(module_port)+'/read'
462 487
488 module_status = json.loads(self.module_status)
463 489 print(read_route)
464 490
465 answer = ''
466 491 module_bits = ''
467 492
468 493 try:
469 r_write = requests.get(read_route, timeout=0.7)
470 answer = r_write.json()
471 self.message = answer['message']
472 module_bits = answer['allbits']
494 r_read = requests.get(read_route, timeout=0.5)
495 answer = r_read.json()
496 module_bits = answer['allbits']
473 497 except:
474 #message = "Could not read ABS parameters"
475 answer = r_write.json()
476 return 0
498 return {}
477 499
478 500 return module_bits
479 501
502 def read_device(self):
503
504 parms = {}
505 # Reads active modules.
506 module_status = json.loads(self.module_status)
507 total = 0
508 for status in module_status:
509 if module_status[status] != 0:
510 module_bits = self.read_module(int(status))
511 bits={}
512 if module_bits:
513 bits = (str(module_bits['um2']) + str(module_bits['um1']) + str(module_bits['um0']) +
514 str(module_bits['dm2']) + str(module_bits['dm1']) + str(module_bits['dm0']) )
515 parms[str(status)] = bits
516
517 total +=1
518
519 if total==0:
520 self.message = "No ABS Module detected. Please select 'Status'."
521 return False
522
523
524
525 self.message = "ABS Modules have been read"
526 #monitoreo_tx = JROABSClnt_01CeCnMod000000MNTR10
527 return parms
528
480 529
481 530 def absmodule_status(self):
482 531 """
483 532 This function gets the status of each abs module. It sends GET method to Web Application
484 533 in Python Bottle.
485 534 This function updates "module_status" field from ABSconfiguration.
486 535 """
487 536 ip_address = self.device.ip_address
488 537 ip_address = ip_address.split('.')
489 538 module_seq = (ip_address[0],ip_address[1],ip_address[2])
490 539 dot = '.'
491 540 module_port = self.device.port_address
492 541
493 542 modules_status = json.loads(self.module_status)
494 543 module_messages = json.loads(self.module_messages)
495 544
496 545 for i in range(1,65):
497 546 module_ip = dot.join(module_seq)+'.'+str(i)
498 547 print module_ip
499 548
500 549 route = 'http://'+module_ip+':'+str(module_port)+'/status'
501 550
502 551 try:
503 552 r = requests.get(route, timeout=0.5)#, timeout=0.7)
504 553 answer = r.json()
505 554 modules_status[str(i)] = answer['status']
506 555 module_messages[str(i)] = answer['message']
507 556 except:
508 557 modules_status[str(i)] = 0
509 558 pass
510 559
511 560
512 561 self.module_status = json.dumps(modules_status)
513 562 self.module_messages = json.dumps(module_messages)
514 563 self.save()
515 564
516 565 return
517 566
518 567
519 568 def connected_modules(self):
520 569 """
521 570 This function returns the number of connected abs-modules without updating.
522 571 """
523 572 modules_status = json.loads(self.module_status)
524 573 num = 0
525 574 for status in modules_status:
526 575 if modules_status[status] != 0:
527 576 num += 1
528 577
529 578 return num
530 579
531 580
532 581 def status_device(self):
533 582 """
534 583 This function returns the status of all abs-modules as one.
535 584 If at least one module is connected, its answer is "1"
536 585 """
537 586 self.absmodule_status()
538 587 connected_modules = self.connected_modules()
539 588 if connected_modules>0:
540 589 self.message = 'ABS modules Status have been updated.'
541 590 return 1
542 591 self.message = 'No ABS module is connected.'
543 592 return 0
544 593
545 594
546 595
547 596 def write_module(self, module):
548 597
549 598 """
550 599 Send configuration to one abs module
551 600 """
552 601
553 602 parameters = {}
554 603 ip_address = self.abs_conf.device.ip_address
555 604 ip_address = ip_address.split('.')
556 605 module_seq = (ip_address[0],ip_address[1],ip_address[2])
557 606 dot = '.'
558 607 module_ip = dot.join(module_seq)+'.'+str(module)
559 608 module_port = self.abs_conf.device.port_address
560 609 write_route = 'http://'+module_ip+':'+str(module_port)+'/write'
561 610
562 611 #print write_route
563 612
564 613 #header = 'JROABSCeCnModCnMod01000108SNDFexperimento1.ab1'
565 614 #module = 'ABS_'+str(module)
566 615 beams = '!`*3<ENW'#{1: '001000', 2: '010001', 3: '010010', 4: '000011', 5: '101100', 6: '101101',
567 616 # 7: '110110', 8: '111111', 9: '000000', 10: '001001', 11: '010010', 12: '011011'}
568 617
569 618 #parameters['header'] = header
570 619 parameters['module'] = module
571 620 parameters['beams'] = json.dumps(beams)
572 621
573 622 answer = ''
574 623
575 624 try:
576 625 r_write = requests.post(write_route, parameters, timeout=0.5)
577 626 answer = r_write.json()
578 627 self.message = answer['message']
579 628 except:
580 629 self.message = "Could not write ABS parameters"
581 630 return 0
582 631
583 632
584 633 #self.device.status = int(answer['status'])
585 634
586 635 return 1
587 636
588 637
589 638 def beam_selector(self, module, beam_pos):
590 639 """
591 640 This function selects the beam number for one absmodule.
592 641 """
593 642
594 643 if beam_pos > 0:
595 644 beam_pos = beam_pos - 1
596 645 else:
597 646 beam_pos = 0
598 647
599 648 #El indice del apunte debe ser menor que el numero total de apuntes
600 649 #El servidor tcp en el embebido comienza a contar desde 0
601 650 beams_list = ABSBeam.objects.filter(abs_conf=self)
602 651 if len(beams_list) < beam_pos:
603 652 return 0
604 653
605 654 flag = 1
606 655 if beam_pos>9:
607 656 flag = 2
608 657
609 658 module_address = ('192.168.1.'+str(module), 5500)
610 659 header = 'JROABSCeCnModCnMod0100000'
611 660 numbers = len(str(beam_pos))
612 661 function = 'CHGB'
613 662
614 663 message_tx = header+str(numbers)+function+str(beam_pos)+'0'
615 664
616 665 # Create the datagram socket
617 666 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
618 667 #sock.connect(module_address)
619 668 try:
620 669 sock.connect(module_address)
621 670 sock.send(message_tx)
622 671 sock.close()
623 672 print("Writing abs module:"+module_address[0]+"...")
624 673 except:
625 674 sock = None
626 675 print("Problem writing abs module:"+module_address[0])
627 676 return 0
628 677
629 678 return 1
630 679
631 680
632 681 def change_beam(self, beam_pos):
633 682 """
634 683 This function selects the beam number for all absmodules.
635 684 """
636 685 for i in range(1,65):
637 686 try:
638 687 self.beam_selector(i,beam_pos)
639 688 except:
640 689 print("Problem with module: 192.168.1."+str(i))
641 690 self.message = "Problem with module: 192.168.1."+str(i)
642 691 #return 0
643 692 return 1
644 693
645 694
646 695 def send_beam_num(self, beam_pos):
647 696 """
648 697 This function connects to a multicast group and sends the beam number
649 698 to all abs modules.
650 699 """
651 700
652 701 if beam_pos > 0:
653 702 beam_pos = beam_pos - 1
654 703 else:
655 704 beam_pos = 0
656 705
657 706 #El indice del apunte debe ser menor que el numero total de apuntes
658 707 #El servidor tcp en el embebido comienza a contar desde 0
659 708 beams_list = ABSBeam.objects.filter(abs_conf=self)
660 709 if len(beams_list) < beam_pos:
661 710 return 0
662 711
663 712 flag = 1
664 713 if beam_pos>9:
665 714 flag = 2
666 715
667 716 header = 'JROABSCeCnModCnMod0100000'
668 717 flag = str(flag)
669 718 function = 'CHGB'
670 719 message_tx = header+flag+function+str(beam_pos)+'0'
671 720
672 721 multicast_group = '224.3.29.71'
673 722 server_address = ('',10000)
674 723
675 724 # Create the socket
676 725 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
677 726 # Bind to the server address
678 727 sock.bind(server_address)
679 728 # Telling the OS add the socket to the multicast on all interfaces
680 729 group = socket.inet_aton(multicast_group)
681 730 mreq = struct.pack('4sL', group, socket.INADDR_ANY)
682 731 sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
683 732
684 733 #print 'sending acknowledgement to all: \n' + message_tx
685 734 sock.sendto(message_tx, (multicast_group, 10000))
686 735 sock.close()
687 736 sock = None
688 737
689 738 return 1
690 739
691 740 def test1(self):
692 741 t1 = time.time()
693 742 t2 = 0
694 743 while (t2-t1)<100:#300
695 744 t2 = time.time()
696 745 self.send_beam_num(2)
697 746 time.sleep(0.04)
698 747 self.send_beam_num(1)
699 748 time.sleep(0.04)
700 749 return
701 750
702 751 def change_procs_test1(self, module):
703 752
704 753 for i in range (1,300):#300
705 754 beam_pos = 1
706 755 module_address = ('192.168.1.'+str(module), 5500)
707 756 header = 'JROABSCeCnModCnMod0100000'
708 757 numbers = len(str(beam_pos))
709 758 function = 'CHGB'
710 759
711 760 message_tx = header+str(numbers)+function+str(beam_pos)+'0'
712 761
713 762 # Create the datagram socket
714 763 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
715 764 sock.connect(module_address)
716 765
717 766 sock.send(message_tx)
718 767 #t = sock.recv(1024)
719 768 sock.close()
720 769 sock = None
721 770
722 771
723 772 time.sleep(0.04)
724 773
725 774
726 775 beam_pos = 0
727 776 numbers = len(str(beam_pos))
728 777
729 778 message_tx = header+str(numbers)+function+str(beam_pos)+'0'
730 779
731 780 # Create the datagram socket
732 781 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
733 782 sock.connect(module_address)
734 783 sock.send(message_tx)
735 784 sock.close()
736 785 sock = None
737 786
738 787 time.sleep(0.04)
739 788
740 789
741 790 def multi_procs_test1(self):
742 791
743 792 """
744 793 This function sends the beam number to all abs modules using multiprocessing.
745 794 """
746 795
747 796 #if __name__ == "__main__":
748 797 size = 10000000 # Number of random numbers to add
749 798 procs = 65 # (Number-1) of processes to create (absmodule)
750 799
751 800 # Create a list of jobs and then iterate through
752 801 # the number of processes appending each process to
753 802 # the job list
754 803 jobs = []
755 804 for i in range(1, procs):
756 805
757 806 process = multiprocessing.Process(target=self.change_procs_test1,args=(i,))
758 807 jobs.append(process)
759 808 #print jobs
760 809
761 810 # Start the processes (i.e. calculate the random number lists)
762 811 for j in jobs:
763 812 #time.sleep(0.4)
764 813 #print j
765 814 j.start()
766 815
767 816 # Ensure all of the processes have finished
768 817 for j in jobs:
769 818 j.join()
770 819
771 820 print("List processing complete.")
772 821 return 1
773 822
774 823
775 824
776 825 def multi_procs_test2(self):
777 826 """
778 827 This function use multiprocessing python library. Importing Pool we can select
779 828 the number of cores we want to use
780 829 After 'nproc' linux command, we know how many cores computer has.
781 830 NOT WORKING
782 831 """
783 832 import multiprocessing
784 833 pool = multiprocessing.Pool(3) # cores
785 834
786 835 tasks = []
787 836 procs = 65
788 837 for i in range(62, procs):
789 838 tasks.append( (i,))
790 839 #print tasks
791 840 #pool.apply_async(self.change_procs_test1, 62)
792 841 results = [pool.apply( self.change_procs_test1, t ) for t in tasks]
793 842 #for result in results:
794 843 #result.get()
795 844 #(plotNum, plotFilename) = result.get()
796 845 #print("Result: plot %d written to %s" % (plotNum, plotFilename) )
797 846
798 847 return 1
799 848
800 849
801 850 def multi_procs_test3(self):
802 851 """
803 852 This function use multiprocessing python library. Importing Pool we can select
804 853 the number of cores we want to use
805 854 After 'nproc' linux command, we know how many cores computer has.
806 855 """
807 856 from multiprocessing import Pool
808 857 import time
809 858
810 859 def f(x):
811 860 return x*x
812 861
813 862 tasks = []
814 863 procs = 65
815 864 pool = Pool(processes=4)
816 865
817 866 #for i in range(62, procs):
818 867 #result = pool.map(f, range(62,65))
819 868 it = pool.imap(self.change_procs_test1, range(62,65))
820 869 #result.get(timeout=5)
821 870
822 871 return 1
823 872
824 873
825 874 def f(x):
826 875 print x
827 876 return
828 877
829 878 def multi_procs_test4(self):
830 879 import multiprocessing as mp
831 880
832 881
833 882 num_workers = mp.cpu_count()
834 883
835 884 pool = mp.Pool(num_workers)
836 885 procs = 65
837 886 for i in range(62, procs):
838 887 #for task in tasks:
839 888 pool.apply_async(self.f, args = (i,))
840 889
841 890 pool.close()
842 891 pool.join()
843 892
844 893 return 1
845 894
846 895
847 896 def get_absolute_url_import(self):
848 897 return reverse('url_import_abs_conf', args=[str(self.id)])
849 898
850 899
851 900
852 901
853 902 class ABSBeam(models.Model):
854 903
855 904 name = models.CharField(max_length=60, default='Beam')
856 905 antenna = models.CharField(verbose_name='Antenna', max_length=1000, default=antenna_default)
857 906 abs_conf = models.ForeignKey(ABSConfiguration, null=True, verbose_name='ABS Configuration')
858 907 tx = models.CharField(verbose_name='Tx', max_length=1000, default=tx_default)
859 908 rx = models.CharField(verbose_name='Rx', max_length=1000, default=rx_default)
860 909 s_time = models.TimeField(verbose_name='Star Time', default='00:00:00')
861 910 e_time = models.TimeField(verbose_name='End Time', default='23:59:59')
862 911 modules_conf = models.CharField(verbose_name='Modules', max_length=2000, default=json.dumps(conf_default))
863 912 ues = models.CharField(verbose_name='Ues', max_length=100, default=ues_default)
864 913 only_rx = models.CharField(verbose_name='Only RX', max_length=40, default=onlyrx_default)
865 914
866 915 class Meta:
867 916 db_table = 'abs_beams'
868 917
869 918 def __unicode__(self):
870 919 return u'%s' % (self.name)
871 920
872 921 def parms_to_dict(self):
873 922
874 923 #Update data
875 924 self.modules_6bits()
876 925
877 926 parameters = {}
878 927
879 928 parameters['name'] = self.name
880 929 parameters['antenna'] = ast.literal_eval(self.antenna)
881 930 parameters['abs_conf'] = self.abs_conf.name
882 931 parameters['tx'] = ast.literal_eval(self.tx)
883 932 parameters['rx'] = ast.literal_eval(self.rx)
884 933 parameters['s_time'] = self.s_time.strftime("%H:%M:%S")
885 934 parameters['e_time'] = self.e_time.strftime("%H:%M:%S")
886 935 parameters['configuration'] = ast.literal_eval(self.modules_conf)
887 936 parameters['ues'] = ast.literal_eval(self.ues)
888 937 parameters['only_rx'] = json.loads(self.only_rx)
889 938
890 939 return parameters
891 940
892 941 def dict_to_parms(self, parameters):
893 942
894 943 self.name = parameters['name']
895 944 self.antenna = json.dumps(parameters['antenna'])
896 945 #self.abs_conf = parameters['abs_conf']
897 946 self.tx = json.dumps(parameters['tx'])
898 947 self.rx = json.dumps(parameters['rx'])
899 948 #self.s_time = parameters['s_time']
900 949 #self.e_time = parameters['e_time']
901 950 self.ues = json.dumps(parameters['ues'])
902 951 self.only_rx = json.dumps(parameters['only_rx'])
903 952
904 953 self.modules_6bits()
905 954 self.save()
906 955
907 956
908 957 def clone(self, **kwargs):
909 958
910 959 self.pk = None
911 960 self.id = None
912 961 for attr, value in kwargs.items():
913 962 setattr(self, attr, value)
914 963
915 964 self.save()
916 965
917 966 return self
918 967
919 968
920 969
921 970 def module_6bits(self, module):
922 971 """
923 972 This function reads antenna pattern and choose 6bits (upbits-downbits) for one abs module
924 973 """
925 974 if module > 64:
926 975 beam_bits = ""
927 976 return beam_bits
928 977
929 978 data = ast.literal_eval(self.antenna)
930 979 up_data = data['antenna_up']
931 980 down_data = data['antenna_down']
932 981
933 982 pos = ip2position(module)
934 983 up_value = up_data[pos[0]][pos[1]]
935 984 down_value = down_data[pos[0]][pos[1]]
936 985
937 986 up_bits = up_conv_bits(up_value)
938 987 down_bits = down_conv_bits(down_value)
939 988 beam_bits = up_bits+down_bits
940 989
941 990 return beam_bits
942 991
943 992 def modules_6bits(self):
944 993 """
945 994 This function returns 6bits from every abs module (1-64) in a dict
946 995 """
947 996 modules_configuration = ast.literal_eval(self.modules_conf)
948 997
949 998 for i in range(1,65):
950 999 modules_configuration[str(i)] = self.module_6bits(i)
951 1000
952 1001 self.modules_conf = json.dumps(modules_configuration)
953 1002 self.save()
954 1003
955 1004 return self.modules_conf
956 1005
957 1006
958 1007 def set_as_activebeam(self):
959 1008 """
960 1009 This function set this beam as the active beam of its ABS Configuration.
961 1010 """
962 1011 self.abs_conf.active_beam = json.dumps({'active_beam': self.id})
963 1012 self.abs_conf.save()
964 1013
965 1014 return
966 1015
967 1016
968 1017 @property
969 1018 def get_upvalues(self):
970 1019 """
971 1020 This function reads antenna pattern and show the up-value of one abs module
972 1021 """
973 1022
974 1023 data = ast.literal_eval(self.antenna)
975 1024 up_data = data['antenna_up']
976 1025
977 1026 up_values = []
978 1027 for data in up_data:
979 1028 for i in range(0,8):
980 1029 up_values.append(data[i])
981 1030
982 1031 return up_values
983 1032
984 1033 @property
985 1034 def antenna_upvalues(self):
986 1035 """
987 1036 This function reads antenna pattern and show the up - values of one abs beam
988 1037 in a particular order
989 1038 """
990 1039 data = ast.literal_eval(self.antenna)
991 1040 up_data = data['antenna_up']
992 1041
993 1042 return up_data
994 1043
995 1044 @property
996 1045 def antenna_downvalues(self):
997 1046 """
998 1047 This function reads antenna pattern and show the down - values of one abs beam
999 1048 in a particular order
1000 1049 """
1001 1050 data = ast.literal_eval(self.antenna)
1002 1051 down_data = data['antenna_down']
1003 1052
1004 1053 return down_data
1005 1054
1006 1055 @property
1007 1056 def get_downvalues(self):
1008 1057 """
1009 1058 This function reads antenna pattern and show the down-value of one abs module
1010 1059 """
1011 1060
1012 1061 data = ast.literal_eval(self.antenna)
1013 1062 down_data = data['antenna_down']
1014 1063
1015 1064 down_values = []
1016 1065 for data in down_data:
1017 1066 for i in range(0,8):
1018 1067 down_values.append(data[i])
1019 1068
1020 1069 return down_values
1021 1070
1022 1071 @property
1023 1072 def get_up_ues(self):
1024 1073 """
1025 1074 This function shows the up-ues-value of one beam
1026 1075 """
1027 1076 data = ast.literal_eval(self.ues)
1028 1077 up_ues = data['up']
1029 1078
1030 1079 return up_ues
1031 1080
1032 1081 @property
1033 1082 def get_down_ues(self):
1034 1083 """
1035 1084 This function shows the down-ues-value of one beam
1036 1085 """
1037 1086 data = ast.literal_eval(self.ues)
1038 1087 down_ues = data['down']
1039 1088
1040 1089 return down_ues
1041 1090
1042 1091 @property
1043 1092 def get_up_onlyrx(self):
1044 1093 """
1045 1094 This function shows the up-onlyrx-value of one beam
1046 1095 """
1047 1096 data = json.loads(self.only_rx)
1048 1097 up_onlyrx = data['up']
1049 1098
1050 1099 return up_onlyrx
1051 1100
1052 1101 @property
1053 1102 def get_down_onlyrx(self):
1054 1103 """
1055 1104 This function shows the down-onlyrx-value of one beam
1056 1105 """
1057 1106 data = json.loads(self.only_rx)
1058 1107 down_onlyrx = data['down']
1059 1108
1060 1109 return down_onlyrx
1061 1110
1062 1111 @property
1063 1112 def get_tx(self):
1064 1113 """
1065 1114 This function shows the tx-values of one beam
1066 1115 """
1067 1116 data = json.loads(self.tx)
1068 1117
1069 1118 return data
1070 1119
1071 1120 @property
1072 1121 def get_uptx(self):
1073 1122 """
1074 1123 This function shows the up-tx-values of one beam
1075 1124 """
1076 1125 data = json.loads(self.tx)
1077 1126 up_data = data['up']
1078 1127
1079 1128 up_values = []
1080 1129 for data in up_data:
1081 1130 for i in range(0,8):
1082 1131 up_values.append(data[i])
1083 1132
1084 1133 return up_values
1085 1134
1086 1135 @property
1087 1136 def get_downtx(self):
1088 1137 """
1089 1138 This function shows the down-tx-values of one beam
1090 1139 """
1091 1140 data = json.loads(self.tx)
1092 1141 down_data = data['down']
1093 1142
1094 1143 down_values = []
1095 1144 for data in down_data:
1096 1145 for i in range(0,8):
1097 1146 down_values.append(data[i])
1098 1147
1099 1148 return down_values
1100 1149
1101 1150
1102 1151
1103 1152 @property
1104 1153 def get_rx(self):
1105 1154 """
1106 1155 This function shows the rx-values of one beam
1107 1156 """
1108 1157 data = json.loads(self.rx)
1109 1158
1110 1159 return data
1111 1160
1112 1161 @property
1113 1162 def get_uprx(self):
1114 1163 """
1115 1164 This function shows the up-rx-values of one beam
1116 1165 """
1117 1166 data = json.loads(self.rx)
1118 1167 up_data = data['up']
1119 1168
1120 1169 up_values = []
1121 1170 for data in up_data:
1122 1171 for i in range(0,8):
1123 1172 up_values.append(data[i])
1124 1173
1125 1174 return up_values
1126 1175
1127 1176 @property
1128 1177 def get_downrx(self):
1129 1178 """
1130 1179 This function shows the down-rx-values of one beam
1131 1180 """
1132 1181 data = json.loads(self.rx)
1133 1182 down_data = data['down']
1134 1183
1135 1184 down_values = []
1136 1185 for data in down_data:
1137 1186 for i in range(0,8):
1138 1187 down_values.append(data[i])
1139 1188
1140 1189 return down_values
@@ -1,179 +1,184
1 1 from django.db import models
2 2 from apps.main.models import Configuration
3 3 from django.core.validators import MinValueValidator, MaxValueValidator
4 4
5 5 from .files import read_json_file
6 6 # Create your models here. validators=[MinValueValidator(62.5e6), MaxValueValidator(450e6)]
7 7
8 8 class CGSConfiguration(Configuration):
9 9
10 10 freq0 = models.PositiveIntegerField(verbose_name='Frequency 0',validators=[MaxValueValidator(450e6)], default = 60)
11 11 freq1 = models.PositiveIntegerField(verbose_name='Frequency 1',validators=[MaxValueValidator(450e6)], default = 60)
12 12 freq2 = models.PositiveIntegerField(verbose_name='Frequency 2',validators=[MaxValueValidator(450e6)], default = 60)
13 13 freq3 = models.PositiveIntegerField(verbose_name='Frequency 3',validators=[MaxValueValidator(450e6)], default = 60)
14 14
15 15 def verify_frequencies(self):
16 16
17 17 return True
18 18
19 19
20 20 def update_from_file(self, fp):
21 21
22 22 kwargs = read_json_file(fp)
23 23
24 24 if not kwargs:
25 25 return False
26 26
27 27 self.freq0 = kwargs['freq0']
28 28 self.freq1 = kwargs['freq1']
29 29 self.freq2 = kwargs['freq2']
30 30 self.freq3 = kwargs['freq3']
31 31
32 32 return True
33 33
34 34 def parms_to_dict(self):
35 35
36 36 parameters = {}
37 37
38 38 parameters['device_id'] = self.device.id
39 39
40 40 if self.freq0 == None or self.freq0 == '':
41 41 parameters['freq0'] = 0
42 42 else:
43 43 parameters['freq0'] = self.freq0
44 44
45 45 if self.freq1 == None or self.freq1 == '':
46 46 parameters['freq1'] = 0
47 47 else:
48 48 parameters['freq1'] = self.freq1
49 49
50 50 if self.freq2 == None or self.freq2 == '':
51 51 parameters['freq2'] = 0
52 52 else:
53 53 parameters['freq2'] = self.freq2
54 54
55 55 if self.freq3 == None or self.freq3 == '':
56 56 parameters['freq3'] = 0
57 57 else:
58 58 parameters['freq3'] = self.freq3
59 59
60 60 return parameters
61 61
62 62
63 63 def dict_to_parms(self, parameters):
64 64
65 65 self.freq0 = parameters['freq0']
66 66 self.freq1 = parameters['freq1']
67 67 self.freq2 = parameters['freq2']
68 68 self.freq3 = parameters['freq3']
69 69
70 70
71 71 def status_device(self):
72 72
73 73 import requests
74 74
75 75 ip=self.device.ip_address
76 76 port=self.device.port_address
77 77
78 78 route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548"
79 79 try:
80 80 r = requests.get(route,timeout=0.5)
81 81 except:
82 82 self.device.status = 0
83 83 self.device.save()
84 return self.device.status
84 self.message = 'Could not read CGS status'
85 return False
85 86
86 87 response = str(r.text)
87 88 response = response.split(";")
88 89 icon = response[0]
89 90 status = response[-1]
90 91
91 92 #print(icon, status)
92 93 #"icon" could be: "alert" or "okay"
93 94 if "alert" in icon:
94 95 if "Starting Up" in status: #No Esta conectado
95 96 self.device.status = 0
96 97 else:
97 98 self.device.status = 1
98 99 elif "okay" in icon:
99 100 self.device.status = 3
100 101 else:
101 102 self.device.status = 1
102 103
103 104 self.message = status
104 105 self.device.save()
105 106
106 107
107 return self.device.status
108 return True
108 109
109 110
110 111 def read_device(self):
111 112
112 113 import requests
113 114
114 115 ip=self.device.ip_address
115 116 port=self.device.port_address
116 117
117 118 route = "http://" + str(ip) + ":" + str(port) + "/frequencies/"
118 119 try:
119 120 frequencies = requests.get(route,timeout=0.5)
120 121
121 122 except:
122 123 self.message = "Could not read CGS parameters from this device"
123 124 return None
124 125
125 126 frequencies = frequencies.json()
126 127 frequencies = frequencies.get("Frecuencias")
127 128 f0 = frequencies.get("f0")
128 129 f1 = frequencies.get("f1")
129 130 f2 = frequencies.get("f2")
130 131 f3 = frequencies.get("f3")
131 132
132 133 parms = {'freq0': f0,
133 134 'freq1': f1,
134 135 'freq2': f2,
135 136 'freq3': f3}
136 137
137 138 self.message = ""
138 139 return parms
139 140
140 141
141 142 def write_device(self):
142 143
143 144 import requests
144 145
145 146 ip=self.device.ip_address
146 147 port=self.device.port_address
147 148
148 149 #---Frequencies from form
149 150 f0 = self.freq0
150 151 f1 = self.freq1
151 152 f2 = self.freq2
152 153 f3 = self.freq3
153 154 post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3}
154 155 route = "http://" + str(ip) + ":" + str(port) + "/frequencies/"
155 156
156 157 try:
157 158 r = requests.post(route, post_data, timeout=0.5)
158 159 except:
159 160 self.message = "Could not write CGS parameters"
160 return None
161 return False
161 162
162 163 text = r.text
163 164 text = text.split(',')
164 165
165 166 if len(text)>1:
166 167 title = text[0]
167 168 status = text[1]
168 169 if title == "okay":
169 170 self.message = status
170 return 3
171 self.device.status = 3
172 self.device.save()
173 return True
171 174 else:
172 175 self.message = title + ", " + status
173 return 1
176 self.device.status = 1
177 self.device.save()
178 return False
174 179
175 return 1
180 return False
176 181
177 182
178 183 class Meta:
179 184 db_table = 'cgs_configurations'
@@ -1,82 +1,84
1 1 {% extends "base.html" %}
2 2 {% load bootstrap3 %}
3 3 {% load static %}
4 4 {% load main_tags %}
5 5
6 6 {% block search-active %}active{% endblock %}
7 7
8 8 {% block content-title %}{{title}}{% endblock %}
9 9 {% block content-suptitle %}{{suptitle}}{% endblock %}
10 10
11 11 {% block content %}
12 12
13 13 {% block menu-actions %}
14 14 <span class=" dropdown pull-right">
15 15 <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-menu-hamburger gi-2x" aria-hidden="true"></span></a>
16 16 <ul class="dropdown-menu" role="menu">
17 17 <li><a href="{{ dev_conf.get_absolute_url_edit }}"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a></li>
18 18 <li><a href="{% url 'url_delete_dev_conf' dev_conf.id %}"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Delete</a></li>
19 19 <li><a href="{{ dev_conf.get_absolute_url_import }}"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import </a></li>
20 20 <li><a href="{{ dev_conf.get_absolute_url_export }}"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> Export </a></li>
21 21 {% block extra-menu-actions %}
22 22 {% endblock %}
23 23 <li><a>----------------</a></li>
24 24 <li><a href="{{ dev_conf.get_absolute_url_status }}"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Status</a></li>
25 25 {% if not no_play %}
26 26 {% if not only_stop %}
27 27 <li><a href="{{ dev_conf.get_absolute_url_start}}"><span class="glyphicon glyphicon-play" aria-hidden="true"></span> Start</a></li>
28 28 {% endif %}
29 29 <li><a href="{{ dev_conf.get_absolute_url_stop }}"><span class="glyphicon glyphicon-stop" aria-hidden="true"></span> Stop</a></li>
30 30 {% endif %}
31 31 <li><a href="{{ dev_conf.get_absolute_url_write }}"><span class="glyphicon glyphicon-download" aria-hidden="true"></span> Write</a></li>
32 {% if dev_conf.device.device_type.name != 'abs' %}
32 33 <li><a href="{{ dev_conf.get_absolute_url_read }}"><span class="glyphicon glyphicon-upload" aria-hidden="true"></span> Read</a></li>
34 {% endif %}
33 35 </ul>
34 36 </span>
35 37 {% endblock %}
36 38
37 39 <table class="table table-bordered">
38 40 <tr>
39 41 <th>Status</th>
40 42 <td class="text-{{dev_conf.device.status_color}}"> {% if dev_conf.device.device_type.name == 'abs' %} {{connected_modules}} {% else %} {{dev_conf.device.get_status_display}}{% endif %} </td>
41 43 </tr>
42 44
43 45 {% for key in dev_conf_keys %}
44 46 <tr>
45 47 <th>{% get_verbose_field_name dev_conf key %}</th>
46 48 <td>{{dev_conf|attr:key}}</td>
47 49 </tr>
48 50 {% endfor %}
49 51 </table>
50 52
51 53 {% block extra-content %}
52 54 {% endblock %}
53 55
54 56 {% endblock %}
55 57
56 58
57 59
58 60 {% block extra-js%}
59 61 <script type="text/javascript">
60 62
61 63 $("#bt_edit").click(function() {
62 64 document.location = "{{ dev_conf.get_absolute_url_edit }}";
63 65 });
64 66
65 67 $("#bt_read").click(function() {
66 68 document.location = "{{ dev_conf.get_absolute_url_read }}";
67 69 });
68 70
69 71 $("#bt_write").click(function() {
70 72 document.location = "{{ dev_conf.get_absolute_url_write }}";
71 73 });
72 74
73 75 $("#bt_import").click(function() {
74 76 document.location = "{{ dev_conf.get_absolute_url_import }}";
75 77 });
76 78
77 79 $("#bt_export").click(function() {
78 80 document.location = "{{ dev_conf.get_absolute_url_export }}";
79 81 });
80 82
81 83 </script>
82 84 {% endblock %}
General Comments 0
You need to be logged in to leave comments. Login now