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