##// END OF EJS Templates
clean abs code
jespinoza -
r315:b3c54f0853ae
parent child
Show More
@@ -1,878 +1,876
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 from celery.execute import send_task
5 from celery.execute import send_task
6 from datetime import datetime
6 from datetime import datetime
7 import ast
7 import ast
8 import socket
8 import socket
9 import json
9 import json
10 import requests
10 import requests
11 import struct
11 import struct
12 import os, sys, time
12 import os, sys, time
13
13
14 import multiprocessing
14 import multiprocessing
15
15
16
16
17 antenna_default = json.dumps({
17 antenna_default = json.dumps({
18 "antenna_up": [[0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
18 "antenna_up": [[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.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
21 [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
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 [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0]
25 [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0]
26 ]
26 ]
27 ,
27 ,
28 "antenna_down": [[0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
28 "antenna_down": [[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.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
31 [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
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 [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0]],
35 [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0]],
36 })
36 })
37
37
38
38
39 tx_default = json.dumps({
39 tx_default = json.dumps({
40 "up": [[1,1,1,1,0,0,0,0],
40 "up": [[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 [1,1,1,1,0,0,0,0],
43 [1,1,1,1,0,0,0,0],
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 [0,0,0,0,1,1,1,1]],
47 [0,0,0,0,1,1,1,1]],
48
48
49 "down": [[1,1,1,1,0,0,0,0],
49 "down": [[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 [1,1,1,1,0,0,0,0],
52 [1,1,1,1,0,0,0,0],
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 [0,0,0,0,1,1,1,1]],
56 [0,0,0,0,1,1,1,1]],
57 })
57 })
58
58
59 rx_default = json.dumps({
59 rx_default = json.dumps({
60 "up": [[1,1,1,1,0,0,0,0],
60 "up": [[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 [1,1,1,1,0,0,0,0],
63 [1,1,1,1,0,0,0,0],
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 [0,0,0,0,1,1,1,1]],
67 [0,0,0,0,1,1,1,1]],
68
68
69 "down": [[1,1,1,1,0,0,0,0],
69 "down": [[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 [1,1,1,1,0,0,0,0],
72 [1,1,1,1,0,0,0,0],
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 [0,0,0,0,1,1,1,1]],
76 [0,0,0,0,1,1,1,1]],
77 })
77 })
78
78
79 status_default = '0000000000000000000000000000000000000000000000000000000000000000'
79 status_default = '0000000000000000000000000000000000000000000000000000000000000000'
80 default_messages = {}
80 default_messages = {}
81
81
82 for i in range(1,65):
82 for i in range(1,65):
83 default_messages[str(i)] = "Module "+str(i)
83 default_messages[str(i)] = "Module "+str(i)
84
84
85
85
86 ues_default = json.dumps({
86 ues_default = json.dumps({
87 "up": [0.533333,0.00000,1.06667,0.00000],
87 "up": [0.533333,0.00000,1.06667,0.00000],
88 "down": [0.533333,0.00000,1.06667,0.00000]
88 "down": [0.533333,0.00000,1.06667,0.00000]
89 })
89 })
90
90
91 onlyrx_default = json.dumps({
91 onlyrx_default = json.dumps({
92 "up": False,
92 "up": False,
93 "down": False
93 "down": False
94 })
94 })
95
95
96 def up_convertion(cadena):
96 def up_convertion(cadena):
97 valores = []
97 valores = []
98 for c in cadena:
98 for c in cadena:
99 if c == 1.0: valores=valores+['000']
99 if c == 1.0: valores=valores+['000']
100 if c == 2.0: valores=valores+['001']
100 if c == 2.0: valores=valores+['001']
101 if c == 3.0: valores=valores+['010']
101 if c == 3.0: valores=valores+['010']
102 if c == 0.0: valores=valores+['011']
102 if c == 0.0: valores=valores+['011']
103 if c == 0.5: valores=valores+['100']
103 if c == 0.5: valores=valores+['100']
104 if c == 1.5: valores=valores+['101']
104 if c == 1.5: valores=valores+['101']
105 if c == 2.5: valores=valores+['110']
105 if c == 2.5: valores=valores+['110']
106 if c == 3.5: valores=valores+['111']
106 if c == 3.5: valores=valores+['111']
107
107
108 return valores
108 return valores
109
109
110 def up_conv_bits(value):
110 def up_conv_bits(value):
111
111
112 if value == 1.0: bits="000"
112 if value == 1.0: bits="000"
113 if value == 2.0: bits="001"
113 if value == 2.0: bits="001"
114 if value == 3.0: bits="010"
114 if value == 3.0: bits="010"
115 if value == 0.0: bits="011"
115 if value == 0.0: bits="011"
116 if value == 0.5: bits="100"
116 if value == 0.5: bits="100"
117 if value == 1.5: bits="101"
117 if value == 1.5: bits="101"
118 if value == 2.5: bits="110"
118 if value == 2.5: bits="110"
119 if value == 3.5: bits="111"
119 if value == 3.5: bits="111"
120
120
121 return bits
121 return bits
122
122
123 def down_convertion(cadena):
123 def down_convertion(cadena):
124 valores = []
124 valores = []
125 for c in cadena:
125 for c in cadena:
126 if c == 1.0: valores=valores+['000']
126 if c == 1.0: valores=valores+['000']
127 if c == 2.0: valores=valores+['001']
127 if c == 2.0: valores=valores+['001']
128 if c == 3.0: valores=valores+['010']
128 if c == 3.0: valores=valores+['010']
129 if c == 0.0: valores=valores+['011']
129 if c == 0.0: valores=valores+['011']
130 if c == 0.5: valores=valores+['100']
130 if c == 0.5: valores=valores+['100']
131 if c == 1.5: valores=valores+['101']
131 if c == 1.5: valores=valores+['101']
132 if c == 2.5: valores=valores+['110']
132 if c == 2.5: valores=valores+['110']
133 if c == 3.5: valores=valores+['111']
133 if c == 3.5: valores=valores+['111']
134
134
135 return valores
135 return valores
136
136
137 def down_conv_bits(value):
137 def down_conv_bits(value):
138
138
139 if value == 1.0: bits="000"
139 if value == 1.0: bits="000"
140 if value == 2.0: bits="001"
140 if value == 2.0: bits="001"
141 if value == 3.0: bits="010"
141 if value == 3.0: bits="010"
142 if value == 0.0: bits="011"
142 if value == 0.0: bits="011"
143 if value == 0.5: bits="100"
143 if value == 0.5: bits="100"
144 if value == 1.5: bits="101"
144 if value == 1.5: bits="101"
145 if value == 2.5: bits="110"
145 if value == 2.5: bits="110"
146 if value == 3.5: bits="111"
146 if value == 3.5: bits="111"
147
147
148 return bits
148 return bits
149
149
150 def up_conv_value(bits):
150 def up_conv_value(bits):
151
151
152 if bits == "000": value=1.0
152 if bits == "000": value=1.0
153 if bits == "001": value=2.0
153 if bits == "001": value=2.0
154 if bits == "010": value=3.0
154 if bits == "010": value=3.0
155 if bits == "011": value=0.0
155 if bits == "011": value=0.0
156 if bits == "100": value=0.5
156 if bits == "100": value=0.5
157 if bits == "101": value=1.5
157 if bits == "101": value=1.5
158 if bits == "110": value=2.5
158 if bits == "110": value=2.5
159 if bits == "111": value=3.5
159 if bits == "111": value=3.5
160
160
161 return value
161 return value
162
162
163 def down_conv_value(bits):
163 def down_conv_value(bits):
164
164
165 if bits == "000": value=1.0
165 if bits == "000": value=1.0
166 if bits == "001": value=2.0
166 if bits == "001": value=2.0
167 if bits == "010": value=3.0
167 if bits == "010": value=3.0
168 if bits == "011": value=0.0
168 if bits == "011": value=0.0
169 if bits == "100": value=0.5
169 if bits == "100": value=0.5
170 if bits == "101": value=1.5
170 if bits == "101": value=1.5
171 if bits == "110": value=2.5
171 if bits == "110": value=2.5
172 if bits == "111": value=3.5
172 if bits == "111": value=3.5
173
173
174 return value
174 return value
175
175
176 def ip2position(module_number):
176 def ip2position(module_number):
177 j=0
177 j=0
178 i=0
178 i=0
179 for x in range(0,module_number-1):
179 for x in range(0,module_number-1):
180 j=j+1
180 j=j+1
181 if j==8:
181 if j==8:
182 i=i+1
182 i=i+1
183 j=0
183 j=0
184
184
185 pos = [i,j]
185 pos = [i,j]
186 return pos
186 return pos
187
187
188
188
189 def fromBinary2Char(binary_string):
189 def fromBinary2Char(binary_string):
190 number = int(binary_string, 2)
190 number = int(binary_string, 2)
191 #Plus 33 to avoid more than 1 characters values such as: '\x01'-'\x1f'
191 #Plus 33 to avoid more than 1 characters values such as: '\x01'-'\x1f'
192 number = number + 33
192 number = number + 33
193 char = chr(number)
193 char = chr(number)
194 return char
194 return char
195
195
196 def fromChar2Binary(char):
196 def fromChar2Binary(char):
197 number = ord(char) - 33
197 number = ord(char) - 33
198 #Minus 33 to get the real value
198 #Minus 33 to get the real value
199 bits = bin(number)[2:]
199 bits = bin(number)[2:]
200 #To ensure we have a string with 6bits
200 #To ensure we have a string with 6bits
201 if len(bits) < 6:
201 if len(bits) < 6:
202 bits = bits.zfill(6)
202 bits = bits.zfill(6)
203 return bits
203 return bits
204
204
205 OPERATION_MODES = (
205 OPERATION_MODES = (
206 (0, 'Manual'),
206 (0, 'Manual'),
207 (1, 'Automatic'),
207 (1, 'Automatic'),
208 )
208 )
209
209
210
210
211 class ABSConfiguration(Configuration):
211 class ABSConfiguration(Configuration):
212 active_beam = models.PositiveSmallIntegerField(verbose_name='Active Beam', default=0)
212 active_beam = models.PositiveSmallIntegerField(verbose_name='Active Beam', default=0)
213 module_status = models.CharField(verbose_name='Module Status', max_length=10000, default=json.dumps(status_default))
213 module_status = models.CharField(verbose_name='Module Status', max_length=10000, default=json.dumps(status_default))
214 operation_mode = models.PositiveSmallIntegerField(verbose_name='Operation Mode', choices=OPERATION_MODES, default = 0)
214 operation_mode = models.PositiveSmallIntegerField(verbose_name='Operation Mode', choices=OPERATION_MODES, default = 0)
215 operation_value = models.FloatField(verbose_name='Periodic (seconds)', default="10", null=True, blank=True)
215 operation_value = models.FloatField(verbose_name='Periodic (seconds)', default="10", null=True, blank=True)
216 module_messages = models.CharField(verbose_name='Modules Messages', max_length=10000, default=json.dumps(default_messages))
216 module_messages = models.CharField(verbose_name='Modules Messages', max_length=10000, default=json.dumps(default_messages))
217
217
218 class Meta:
218 class Meta:
219 db_table = 'abs_configurations'
219 db_table = 'abs_configurations'
220
220
221 def get_absolute_url_plot(self):
221 def get_absolute_url_plot(self):
222 return reverse('url_plot_abs_patterns', args=[str(self.id)])
222 return reverse('url_plot_abs_patterns', args=[str(self.id)])
223
223
224
224
225 def parms_to_dict(self):
225 def parms_to_dict(self):
226
226
227 parameters = {}
227 parameters = {}
228
228
229 parameters['device_id'] = self.device.id
229 parameters['device_id'] = self.device.id
230 parameters['name'] = self.name
230 parameters['name'] = self.name
231 parameters['device_type'] = self.device.device_type.name
231 parameters['device_type'] = self.device.device_type.name
232 parameters['beams'] = {}
232 parameters['beams'] = {}
233
233
234 beams = ABSBeam.objects.filter(abs_conf=self)
234 beams = ABSBeam.objects.filter(abs_conf=self)
235 b=1
235 b=1
236 for beam in beams:
236 for beam in beams:
237 #absbeam = ABSBeam.objects.get(pk=beams[beam])
237 #absbeam = ABSBeam.objects.get(pk=beams[beam])
238 parameters['beams']['beam'+str(b)] = beam.parms_to_dict()#absbeam.parms_to_dict()
238 parameters['beams']['beam'+str(b)] = beam.parms_to_dict()#absbeam.parms_to_dict()
239 b+=1
239 b+=1
240
240
241 return parameters
241 return parameters
242
242
243
243
244 def dict_to_parms(self, parameters):
244 def dict_to_parms(self, parameters):
245
245
246 self.name = parameters['name']
246 self.name = parameters['name']
247
247
248 absbeams = ABSBeam.objects.filter(abs_conf=self)
248 absbeams = ABSBeam.objects.filter(abs_conf=self)
249 beams = parameters['beams']
249 beams = parameters['beams']
250
250
251 if absbeams:
251 if absbeams:
252 beams_number = len(beams)
252 beams_number = len(beams)
253 absbeams_number = len(absbeams)
253 absbeams_number = len(absbeams)
254 if beams_number==absbeams_number:
254 if beams_number==absbeams_number:
255 i = 1
255 i = 1
256 for absbeam in absbeams:
256 for absbeam in absbeams:
257 absbeam.dict_to_parms(beams['beam'+str(i)])
257 absbeam.dict_to_parms(beams['beam'+str(i)])
258 i = i+1
258 i = i+1
259 elif beams_number > absbeams_number:
259 elif beams_number > absbeams_number:
260 i = 1
260 i = 1
261 for absbeam in absbeams:
261 for absbeam in absbeams:
262 absbeam.dict_to_parms(beams['beam'+str(i)])
262 absbeam.dict_to_parms(beams['beam'+str(i)])
263 i=i+1
263 i=i+1
264 for x in range(i,beams_number+1):
264 for x in range(i,beams_number+1):
265 new_beam = ABSBeam(
265 new_beam = ABSBeam(
266 name =beams['beam'+str(i)]['name'],
266 name =beams['beam'+str(i)]['name'],
267 antenna =json.dumps(beams['beam'+str(i)]['antenna']),
267 antenna =json.dumps(beams['beam'+str(i)]['antenna']),
268 abs_conf = self,
268 abs_conf = self,
269 tx =json.dumps(beams['beam'+str(i)]['tx']),
269 tx =json.dumps(beams['beam'+str(i)]['tx']),
270 rx =json.dumps(beams['beam'+str(i)]['rx']),
270 rx =json.dumps(beams['beam'+str(i)]['rx']),
271 ues =json.dumps(beams['beam'+str(i)]['ues']),
271 ues =json.dumps(beams['beam'+str(i)]['ues']),
272 only_rx =json.dumps(beams['beam'+str(i)]['only_rx'])
272 only_rx =json.dumps(beams['beam'+str(i)]['only_rx'])
273 )
273 )
274 new_beam.save()
274 new_beam.save()
275 i=i+1
275 i=i+1
276 else: #beams_number < absbeams_number:
276 else: #beams_number < absbeams_number:
277 i = 1
277 i = 1
278 for absbeam in absbeams:
278 for absbeam in absbeams:
279 if i <= beams_number:
279 if i <= beams_number:
280 absbeam.dict_to_parms(beams['beam'+str(i)])
280 absbeam.dict_to_parms(beams['beam'+str(i)])
281 i=i+1
281 i=i+1
282 else:
282 else:
283 absbeam.delete()
283 absbeam.delete()
284 else:
284 else:
285 for beam in beams:
285 for beam in beams:
286 new_beam = ABSBeam(
286 new_beam = ABSBeam(
287 name =beams[beam]['name'],
287 name =beams[beam]['name'],
288 antenna =json.dumps(beams[beam]['antenna']),
288 antenna =json.dumps(beams[beam]['antenna']),
289 abs_conf = self,
289 abs_conf = self,
290 tx =json.dumps(beams[beam]['tx']),
290 tx =json.dumps(beams[beam]['tx']),
291 rx =json.dumps(beams[beam]['rx']),
291 rx =json.dumps(beams[beam]['rx']),
292 ues =json.dumps(beams[beam]['ues']),
292 ues =json.dumps(beams[beam]['ues']),
293 only_rx =json.dumps(beams[beam]['only_rx'])
293 only_rx =json.dumps(beams[beam]['only_rx'])
294 )
294 )
295 new_beam.save()
295 new_beam.save()
296
296
297
297
298
298
299 def update_from_file(self, parameters):
299 def update_from_file(self, parameters):
300
300
301 self.dict_to_parms(parameters)
301 self.dict_to_parms(parameters)
302 self.save()
302 self.save()
303
303
304
304
305 def get_beams(self, **kwargs):
305 def get_beams(self, **kwargs):
306 '''
306 '''
307 This function returns ABS Configuration beams
307 This function returns ABS Configuration beams
308 '''
308 '''
309 return ABSBeam.objects.filter(abs_conf=self.pk, **kwargs)
309 return ABSBeam.objects.filter(abs_conf=self.pk, **kwargs)
310
310
311 def clone(self, **kwargs):
311 def clone(self, **kwargs):
312
312
313 beams = self.get_beams()
313 beams = self.get_beams()
314 self.pk = None
314 self.pk = None
315 self.id = None
315 self.id = None
316 for attr, value in kwargs.items():
316 for attr, value in kwargs.items():
317 setattr(self, attr, value)
317 setattr(self, attr, value)
318 self.save()
318 self.save()
319
319
320 for beam in beams:
320 for beam in beams:
321 beam.clone(abs_conf=self)
321 beam.clone(abs_conf=self)
322
322
323 #-----For Active Beam-----
323 #-----For Active Beam-----
324 new_beams = ABSBeam.objects.filter(abs_conf=self)
324 new_beams = ABSBeam.objects.filter(abs_conf=self)
325 self.active_beam = new_beams[0].id
325 self.active_beam = new_beams[0].id
326 self.save()
326 self.save()
327 #-----For Active Beam-----
327 #-----For Active Beam-----
328 #-----For Device Status---
328 #-----For Device Status---
329 self.device.status = 3
329 self.device.status = 3
330 self.device.save()
330 self.device.save()
331 #-----For Device Status---
331 #-----For Device Status---
332
332
333 return self
333 return self
334
334
335
335
336 def start_device(self):
336 def start_device(self):
337
337
338 if self.device.status == 3:
338 if self.device.status == 3:
339
339
340 try:
340 try:
341 #self.write_device()
341 #self.write_device()
342 send_task('task_change_beam', [self.id],)
342 send_task('task_change_beam', [self.id],)
343 self.message = 'ABS running'
343 self.message = 'ABS running'
344
344
345 except Exception as e:
345 except Exception as e:
346 self.message = str(e)
346 self.message = str(e)
347 return False
347 return False
348
348
349 return True
349 return True
350
350
351 else:
351 else:
352 self.message = 'Please, select Write ABS Device first.'
352 self.message = 'Please, select Write ABS Device first.'
353 return False
353 return False
354
354
355
355
356 def stop_device(self):
356 def stop_device(self):
357
357
358 self.device.status = 2
358 self.device.status = 2
359 self.device.save()
359 self.device.save()
360 self.message = 'ABS has been stopped.'
360 self.message = 'ABS has been stopped.'
361 self.save()
361 self.save()
362
362
363 return True
363 return True
364
364
365
365
366 def write_device(self):
366 def write_device(self):
367
367
368 """
368 """
369 This function sends the beams list to every abs module.
369 This function sends the beams list to every abs module.
370 It needs 'module_conf' function
370 It needs 'module_conf' function
371 """
371 """
372
372
373 beams = ABSBeam.objects.filter(abs_conf=self)
373 beams = ABSBeam.objects.filter(abs_conf=self)
374 nbeams = len(beams)
374 nbeams = len(beams)
375 if self.connected_modules() == 0 :
375 if self.connected_modules() == 0 :
376 self.message = "No ABS Module detected."
376 self.message = "No ABS Module detected."
377 return False
377 return False
378
378
379 #-------------Write each abs module-----------
379 #-------------Write each abs module-----------
380
380
381 if beams:
381 if beams:
382 block_id = 0
382 block_id = 0
383 message = 'SNDF{:03d}{:02d}{:02d}'.format(nbeams, nbeams, block_id)
383 message = 'SNDF{:03d}{:02d}{:02d}'.format(nbeams, nbeams, block_id)
384 for i, status in enumerate(self.module_status):
384 for i, status in enumerate(self.module_status):
385 message += ''.join([fromBinary2Char(beam.module_6bits(i)) for beam in beams])
385 message += ''.join([fromBinary2Char(beam.module_6bits(i)) for beam in beams])
386 status = ['0'] * 64
386 status = ['0'] * 64
387 n = 0
387 n = 0
388
388
389 sock = self.send_multicast(message)
389 sock = self.send_multicast(message)
390
390
391 for i in range(32):
391 for i in range(32):
392 try:
392 try:
393 data, address = sock.recvfrom(1024)
393 data, address = sock.recvfrom(1024)
394 print address, data
394 print address, data
395 if data == '1':
395 if data == '1':
396 status[int(address[0][10:])-1] = '3'
396 status[int(address[0][10:])-1] = '3'
397 elif data == '0':
397 elif data == '0':
398 status[int(address[0][10:])-1] = '1'
398 status[int(address[0][10:])-1] = '1'
399 except:
399 except Exception as e:
400 print 'Error {}'.format(e)
400 n += 1
401 n += 1
401 sock.close()
402 sock.close()
402 else:
403 else:
403 self.message = "ABS Configuration does not have beams"
404 self.message = "ABS Configuration does not have beams"
404 return False
405 return False
405
406
406 if n == 64:
407 if n == 64:
407 self.message = "Could not write ABS Modules"
408 self.message = "Could not write ABS Modules"
408 self.device.status = 0
409 self.device.status = 0
409 self.module_status = ''.join(status)
410 self.module_status = ''.join(status)
410 self.save()
411 self.save()
411 return False
412 return False
412 else:
413 else:
413 self.message = "ABS Beams List have been sent to ABS Modules"
414 self.message = "ABS Beams List have been sent to ABS Modules"
414 self.active_beam = beams[0].pk
415 self.active_beam = beams[0].pk
415
416
416 self.device.status = 3
417 self.device.status = 3
417 self.module_status = ''.join(status)
418 self.module_status = ''.join(status)
418 self.save()
419 self.save()
419 return True
420 return True
420
421
421
422
422 def read_module(self, module):
423 def read_module(self, module):
423
424
424 """
425 """
425 Read out-bits (up-down) of 1 abs module NOT for Configuration
426 Read out-bits (up-down) of 1 abs module NOT for Configuration
426 """
427 """
427
428
428 ip_address = self.device.ip_address
429 ip_address = self.device.ip_address
429 ip_address = ip_address.split('.')
430 ip_address = ip_address.split('.')
430 module_seq = (ip_address[0],ip_address[1],ip_address[2])
431 module_seq = (ip_address[0],ip_address[1],ip_address[2])
431 dot = '.'
432 dot = '.'
432 module_ip = dot.join(module_seq)+'.'+str(module)
433 module_ip = dot.join(module_seq)+'.'+str(module)
433 module_port = self.device.port_address
434 module_port = self.device.port_address
434 read_route = 'http://'+module_ip+':'+str(module_port)+'/read'
435 read_route = 'http://'+module_ip+':'+str(module_port)+'/read'
435
436
436 module_status = json.loads(self.module_status)
437 module_status = json.loads(self.module_status)
437 print(read_route)
438 print(read_route)
438
439
439 module_bits = ''
440 module_bits = ''
440
441
441 try:
442 try:
442 r_read = requests.get(read_route, timeout=0.5)
443 r_read = requests.get(read_route, timeout=0.5)
443 answer = r_read.json()
444 answer = r_read.json()
444 module_bits = answer['allbits']
445 module_bits = answer['allbits']
445 except:
446 except:
446 return {}
447 return {}
447
448
448 return module_bits
449 return module_bits
449
450
450 def read_device(self):
451 def read_device(self):
451
452
452 parms = {}
453 parms = {}
453 # Reads active modules.
454 # Reads active modules.
454 module_status = json.loads(self.module_status)
455 module_status = json.loads(self.module_status)
455 total = 0
456 total = 0
456 for status in module_status:
457 for status in module_status:
457 if module_status[status] != 0:
458 if module_status[status] != 0:
458 module_bits = self.read_module(int(status))
459 module_bits = self.read_module(int(status))
459 bits={}
460 bits={}
460 if module_bits:
461 if module_bits:
461 bits = (str(module_bits['um2']) + str(module_bits['um1']) + str(module_bits['um0']) +
462 bits = (str(module_bits['um2']) + str(module_bits['um1']) + str(module_bits['um0']) +
462 str(module_bits['dm2']) + str(module_bits['dm1']) + str(module_bits['dm0']) )
463 str(module_bits['dm2']) + str(module_bits['dm1']) + str(module_bits['dm0']) )
463 parms[str(status)] = bits
464 parms[str(status)] = bits
464
465
465 total +=1
466 total +=1
466
467
467 if total==0:
468 if total==0:
468 self.message = "No ABS Module detected. Please select 'Status'."
469 self.message = "No ABS Module detected. Please select 'Status'."
469 return False
470 return False
470
471
471
472
472
473
473 self.message = "ABS Modules have been read"
474 self.message = "ABS Modules have been read"
474 #monitoreo_tx = JROABSClnt_01CeCnMod000000MNTR10
475 #monitoreo_tx = JROABSClnt_01CeCnMod000000MNTR10
475 return parms
476 return parms
476
477
477
478
478 def connected_modules(self):
479 def connected_modules(self):
479 """
480 """
480 This function returns the number of connected abs-modules without updating.
481 This function returns the number of connected abs-modules without updating.
481 """
482 """
482 num = 0
483 num = 0
483 print(self.module_status)
484 print(self.module_status)
484 for i, status in enumerate(self.module_status):
485 for i, status in enumerate(self.module_status):
485 if status != '0':
486 if status != '0':
486 num += 1
487 num += 1
487 #print('status {}:{}'.format(i+1, status))
488 #print('status {}:{}'.format(i+1, status))
488 return num
489 return num
489
490
490 def send_multicast(self, message):
491 def send_multicast(self, message):
491
492
492 multicast_group = ('224.3.29.71', 10000)
493 multicast_group = ('224.3.29.71', 10000)
493 # Create the datagram socket
494 # Create the datagram socket
494 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
495 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
495 sock.settimeout(0.5)
496 sock.settimeout(1)
496 # sock.bind((local_ip, 10000))
497 # sock.bind((local_ip, 10000))
497 local_ip = os.environ.get('LOCAL_IP', '127.0.0.1')
498 local_ip = os.environ.get('LOCAL_IP', '127.0.0.1')
499 local_ip = '192.168.1.128'
498 sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_IF, socket.inet_aton(local_ip))
500 sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_IF, socket.inet_aton(local_ip))
499 sent = sock.sendto(message, multicast_group)
501 sent = sock.sendto(message, multicast_group)
500 print('Sending ' + message)
502 print('Sending ' + message)
501 return sock
503 return sock
502
504
503 def status_device(self):
505 def status_device(self):
504 """
506 """
505 This function returns the status of all abs-modules as one.
507 This function returns the status of all abs-modules as one.
506 If at least one module is connected, its answer is "1"
508 If at least one module is connected, its answer is "1"
507 """
509 """
508
510
509 sock = self.send_multicast('MNTR')
511 sock = self.send_multicast('MNTR')
510
512
511 n = 0
513 n = 0
512 status = ['0'] * 64
514 status = ['0'] * 64
513 for i in range(32):
515 for i in range(32):
514 #if True:
516 #if True:
515 try:
517 try:
518 address = None
516 data, address = sock.recvfrom(1024)
519 data, address = sock.recvfrom(1024)
517 print address, data
520 print address, data
518 if data == '1':
521 if data == '1':
519 status[int(address[0][10:])-1] = '3'
522 status[int(address[0][10:])-1] = '3'
520 elif data == '0':
523 elif data == '0':
521 status[int(address[0][10:])-1] = '1'
524 status[int(address[0][10:])-1] = '1'
522 n += 1
525 n += 1
523 print('Module: {} connected'.format(address))
526 print('Module: {} connected'.format(address))
524 except:
527 except:
525 print('Module: {} error'.format(address))
528 print('Module: {} error'.format(address))
526 pass
529 pass
527 sock.close()
530 sock.close()
528
531
529 if n > 0:
532 if n > 0:
530 self.message = 'ABS modules Status have been updated.'
533 self.message = 'ABS modules Status have been updated.'
531 self.device.status = 1
534 self.device.status = 1
532 else:
535 else:
533 self.device.status = 0
536 self.device.status = 0
534 self.message = 'No ABS module is connected.'
537 self.message = 'No ABS module is connected.'
535 self.module_status = ''.join(status)
538 self.module_status = ''.join(status)
536 self.save()
539 self.save()
537
540
538 return self.device.status
541 return self.device.status
539
542
540
543
541 def send_beam(self, beam_pos):
544 def send_beam(self, beam_pos):
542 """
545 """
543 This function connects to a multicast group and sends the beam number
546 This function connects to a multicast group and sends the beam number
544 to all abs modules.
547 to all abs modules.
545 """
548 """
546
549
547 # Se manda a cero RC para poder realizar cambio de beam
550 # Se manda a cero RC para poder realizar cambio de beam
548 if self.experiment is None:
551 if self.experiment is None:
549 confs = []
552 confs = []
550 else:
553 else:
551 confs = Configuration.objects.filter(experiment = self.experiment).filter(type=0)
554 confs = Configuration.objects.filter(experiment = self.experiment).filter(type=0)
552 confdds = ''
555 confdds = ''
553 confjars = ''
556 confjars = ''
554 confrc = ''
557 confrc = ''
555 print 'Starting...', self.experiment
556 #TO STOP DEVICES: DDS-JARS-RC
558 #TO STOP DEVICES: DDS-JARS-RC
557 for i in range(0,len(confs)):
559 for i in range(0,len(confs)):
558 print i
559 if i==0:
560 if i==0:
560 for conf in confs:
561 for conf in confs:
561 if conf.device.device_type.name == 'dds':
562 if conf.device.device_type.name == 'dds':
562 confdds = conf
563 confdds = conf
563 confdds.stop_device()
564 confdds.stop_device()
564 break
565 break
565 if i==1:
566 if i==1:
566 for conf in confs:
567 for conf in confs:
567 if conf.device.device_type.name == 'jars':
568 if conf.device.device_type.name == 'jars':
568 confjars = conf
569 confjars = conf
569 confjars.stop_device()
570 confjars.stop_device()
570 break
571 break
571 if i==2:
572 if i==2:
572 for conf in confs:
573 for conf in confs:
573 print conf
574 if conf.device.device_type.name == 'rc':
574 if conf.device.device_type.name == 'rc':
575 confrc = conf
575 confrc = conf
576 confrc.stop_device()
576 confrc.stop_device()
577 break
577 break
578 print 'Stop devices'
579 if beam_pos > 0:
578 if beam_pos > 0:
580 beam_pos = beam_pos - 1
579 beam_pos = beam_pos - 1
581 else:
580 else:
582 beam_pos = 0
581 beam_pos = 0
583
582
584 #El indice del apunte debe ser menor que el numero total de apuntes
583 #El indice del apunte debe ser menor que el numero total de apuntes
585 #El servidor tcp en el embebido comienza a contar desde 0
584 #El servidor tcp en el embebido comienza a contar desde 0
586 status = ['0'] * 64
585 status = ['0'] * 64
587 message = 'CHGB{}'.format(beam_pos)
586 message = 'CHGB{}'.format(beam_pos)
588 print 'Before send'
589 sock = self.send_multicast(message)
587 sock = self.send_multicast(message)
590 print 'Waiting'
591 for i in range(32):
588 for i in range(32):
592 try:
589 try:
593 data, address = sock.recvfrom(1024)
590 data, address = sock.recvfrom(1024)
594 print address, data
591 print address, data
595 if data == '1':
592 if data == '1':
596 status[int(address[0][10:])-1] = '3'
593 status[int(address[0][10:])-1] = '3'
597 elif data == '0':
594 elif data == '0':
598 status[int(address[0][10:])-1] = '1'
595 status[int(address[0][10:])-1] = '1'
599 except:
596 except Exception as e:
597 print 'Error {}'.format(e)
600 pass
598 pass
601
599
602 sock.close()
600 sock.close()
603
601
604 #Start DDS-RC-JARS
602 #Start DDS-RC-JARS
605 if confdds:
603 if confdds:
606 confdds.start_device()
604 confdds.start_device()
607 if confrc:
605 if confrc:
608 #print confrc
606 #print confrc
609 confrc.start_device()
607 confrc.start_device()
610 if confjars:
608 if confjars:
611 confjars.start_device()
609 confjars.start_device()
612
610
613 self.message = "ABS Beam has been changed"
611 self.message = "ABS Beam has been changed"
614 self.module_status = ''.join(status)
612 self.module_status = ''.join(status)
615 self.save()
613 self.save()
616 return True
614 return True
617
615
618
616
619 def get_absolute_url_import(self):
617 def get_absolute_url_import(self):
620 return reverse('url_import_abs_conf', args=[str(self.id)])
618 return reverse('url_import_abs_conf', args=[str(self.id)])
621
619
622
620
623 class ABSBeam(models.Model):
621 class ABSBeam(models.Model):
624
622
625 name = models.CharField(max_length=60, default='Beam')
623 name = models.CharField(max_length=60, default='Beam')
626 antenna = models.CharField(verbose_name='Antenna', max_length=1000, default=antenna_default)
624 antenna = models.CharField(verbose_name='Antenna', max_length=1000, default=antenna_default)
627 abs_conf = models.ForeignKey(ABSConfiguration, null=True, verbose_name='ABS Configuration')
625 abs_conf = models.ForeignKey(ABSConfiguration, null=True, verbose_name='ABS Configuration')
628 tx = models.CharField(verbose_name='Tx', max_length=1000, default=tx_default)
626 tx = models.CharField(verbose_name='Tx', max_length=1000, default=tx_default)
629 rx = models.CharField(verbose_name='Rx', max_length=1000, default=rx_default)
627 rx = models.CharField(verbose_name='Rx', max_length=1000, default=rx_default)
630 s_time = models.TimeField(verbose_name='Star Time', default='00:00:00')
628 s_time = models.TimeField(verbose_name='Star Time', default='00:00:00')
631 e_time = models.TimeField(verbose_name='End Time', default='23:59:59')
629 e_time = models.TimeField(verbose_name='End Time', default='23:59:59')
632 ues = models.CharField(verbose_name='Ues', max_length=100, default=ues_default)
630 ues = models.CharField(verbose_name='Ues', max_length=100, default=ues_default)
633 only_rx = models.CharField(verbose_name='Only RX', max_length=40, default=onlyrx_default)
631 only_rx = models.CharField(verbose_name='Only RX', max_length=40, default=onlyrx_default)
634
632
635 class Meta:
633 class Meta:
636 db_table = 'abs_beams'
634 db_table = 'abs_beams'
637
635
638 def __unicode__(self):
636 def __unicode__(self):
639 return u'%s' % (self.name)
637 return u'%s' % (self.name)
640
638
641 def parms_to_dict(self):
639 def parms_to_dict(self):
642
640
643 parameters = {}
641 parameters = {}
644 parameters['name'] = self.name
642 parameters['name'] = self.name
645 parameters['antenna'] = ast.literal_eval(self.antenna)
643 parameters['antenna'] = ast.literal_eval(self.antenna)
646 parameters['abs_conf'] = self.abs_conf.name
644 parameters['abs_conf'] = self.abs_conf.name
647 parameters['tx'] = ast.literal_eval(self.tx)
645 parameters['tx'] = ast.literal_eval(self.tx)
648 parameters['rx'] = ast.literal_eval(self.rx)
646 parameters['rx'] = ast.literal_eval(self.rx)
649 parameters['s_time'] = self.s_time.strftime("%H:%M:%S")
647 parameters['s_time'] = self.s_time.strftime("%H:%M:%S")
650 parameters['e_time'] = self.e_time.strftime("%H:%M:%S")
648 parameters['e_time'] = self.e_time.strftime("%H:%M:%S")
651 parameters['ues'] = ast.literal_eval(self.ues)
649 parameters['ues'] = ast.literal_eval(self.ues)
652 parameters['only_rx'] = json.loads(self.only_rx)
650 parameters['only_rx'] = json.loads(self.only_rx)
653
651
654 return parameters
652 return parameters
655
653
656 def dict_to_parms(self, parameters):
654 def dict_to_parms(self, parameters):
657
655
658 self.name = parameters['name']
656 self.name = parameters['name']
659 self.antenna = json.dumps(parameters['antenna'])
657 self.antenna = json.dumps(parameters['antenna'])
660 #self.abs_conf = parameters['abs_conf']
658 #self.abs_conf = parameters['abs_conf']
661 self.tx = json.dumps(parameters['tx'])
659 self.tx = json.dumps(parameters['tx'])
662 self.rx = json.dumps(parameters['rx'])
660 self.rx = json.dumps(parameters['rx'])
663 #self.s_time = parameters['s_time']
661 #self.s_time = parameters['s_time']
664 #self.e_time = parameters['e_time']
662 #self.e_time = parameters['e_time']
665 self.ues = json.dumps(parameters['ues'])
663 self.ues = json.dumps(parameters['ues'])
666 self.only_rx = json.dumps(parameters['only_rx'])
664 self.only_rx = json.dumps(parameters['only_rx'])
667 self.save()
665 self.save()
668
666
669
667
670 def clone(self, **kwargs):
668 def clone(self, **kwargs):
671
669
672 self.pk = None
670 self.pk = None
673 self.id = None
671 self.id = None
674 for attr, value in kwargs.items():
672 for attr, value in kwargs.items():
675 setattr(self, attr, value)
673 setattr(self, attr, value)
676
674
677 self.save()
675 self.save()
678
676
679 return self
677 return self
680
678
681
679
682 def module_6bits(self, module):
680 def module_6bits(self, module):
683 """
681 """
684 This function reads antenna pattern and choose 6bits (upbits-downbits) for one abs module
682 This function reads antenna pattern and choose 6bits (upbits-downbits) for one abs module
685 """
683 """
686 module += 1
684 module += 1
687 if module > 64:
685 if module > 64:
688 beam_bits = ""
686 beam_bits = ""
689 return beam_bits
687 return beam_bits
690
688
691 data = ast.literal_eval(self.antenna)
689 data = ast.literal_eval(self.antenna)
692 up_data = data['antenna_up']
690 up_data = data['antenna_up']
693 down_data = data['antenna_down']
691 down_data = data['antenna_down']
694
692
695 pos = ip2position(module)
693 pos = ip2position(module)
696 up_value = up_data[pos[0]][pos[1]]
694 up_value = up_data[pos[0]][pos[1]]
697 down_value = down_data[pos[0]][pos[1]]
695 down_value = down_data[pos[0]][pos[1]]
698
696
699 up_bits = up_conv_bits(up_value)
697 up_bits = up_conv_bits(up_value)
700 down_bits = down_conv_bits(down_value)
698 down_bits = down_conv_bits(down_value)
701 beam_bits = up_bits+down_bits
699 beam_bits = up_bits+down_bits
702
700
703 return beam_bits
701 return beam_bits
704
702
705
703
706 @property
704 @property
707 def get_upvalues(self):
705 def get_upvalues(self):
708 """
706 """
709 This function reads antenna pattern and show the up-value of one abs module
707 This function reads antenna pattern and show the up-value of one abs module
710 """
708 """
711
709
712 data = ast.literal_eval(self.antenna)
710 data = ast.literal_eval(self.antenna)
713 up_data = data['antenna_up']
711 up_data = data['antenna_up']
714
712
715 up_values = []
713 up_values = []
716 for data in up_data:
714 for data in up_data:
717 for i in range(0,8):
715 for i in range(0,8):
718 up_values.append(data[i])
716 up_values.append(data[i])
719
717
720 return up_values
718 return up_values
721
719
722 @property
720 @property
723 def antenna_upvalues(self):
721 def antenna_upvalues(self):
724 """
722 """
725 This function reads antenna pattern and show the up - values of one abs beam
723 This function reads antenna pattern and show the up - values of one abs beam
726 in a particular order
724 in a particular order
727 """
725 """
728 data = ast.literal_eval(self.antenna)
726 data = ast.literal_eval(self.antenna)
729 up_data = data['antenna_up']
727 up_data = data['antenna_up']
730
728
731 return up_data
729 return up_data
732
730
733 @property
731 @property
734 def antenna_downvalues(self):
732 def antenna_downvalues(self):
735 """
733 """
736 This function reads antenna pattern and show the down - values of one abs beam
734 This function reads antenna pattern and show the down - values of one abs beam
737 in a particular order
735 in a particular order
738 """
736 """
739 data = ast.literal_eval(self.antenna)
737 data = ast.literal_eval(self.antenna)
740 down_data = data['antenna_down']
738 down_data = data['antenna_down']
741
739
742 return down_data
740 return down_data
743
741
744 @property
742 @property
745 def get_downvalues(self):
743 def get_downvalues(self):
746 """
744 """
747 This function reads antenna pattern and show the down-value of one abs module
745 This function reads antenna pattern and show the down-value of one abs module
748 """
746 """
749
747
750 data = ast.literal_eval(self.antenna)
748 data = ast.literal_eval(self.antenna)
751 down_data = data['antenna_down']
749 down_data = data['antenna_down']
752
750
753 down_values = []
751 down_values = []
754 for data in down_data:
752 for data in down_data:
755 for i in range(0,8):
753 for i in range(0,8):
756 down_values.append(data[i])
754 down_values.append(data[i])
757
755
758 return down_values
756 return down_values
759
757
760 @property
758 @property
761 def get_up_ues(self):
759 def get_up_ues(self):
762 """
760 """
763 This function shows the up-ues-value of one beam
761 This function shows the up-ues-value of one beam
764 """
762 """
765 data = ast.literal_eval(self.ues)
763 data = ast.literal_eval(self.ues)
766 up_ues = data['up']
764 up_ues = data['up']
767
765
768 return up_ues
766 return up_ues
769
767
770 @property
768 @property
771 def get_down_ues(self):
769 def get_down_ues(self):
772 """
770 """
773 This function shows the down-ues-value of one beam
771 This function shows the down-ues-value of one beam
774 """
772 """
775 data = ast.literal_eval(self.ues)
773 data = ast.literal_eval(self.ues)
776 down_ues = data['down']
774 down_ues = data['down']
777
775
778 return down_ues
776 return down_ues
779
777
780 @property
778 @property
781 def get_up_onlyrx(self):
779 def get_up_onlyrx(self):
782 """
780 """
783 This function shows the up-onlyrx-value of one beam
781 This function shows the up-onlyrx-value of one beam
784 """
782 """
785 data = json.loads(self.only_rx)
783 data = json.loads(self.only_rx)
786 up_onlyrx = data['up']
784 up_onlyrx = data['up']
787
785
788 return up_onlyrx
786 return up_onlyrx
789
787
790 @property
788 @property
791 def get_down_onlyrx(self):
789 def get_down_onlyrx(self):
792 """
790 """
793 This function shows the down-onlyrx-value of one beam
791 This function shows the down-onlyrx-value of one beam
794 """
792 """
795 data = json.loads(self.only_rx)
793 data = json.loads(self.only_rx)
796 down_onlyrx = data['down']
794 down_onlyrx = data['down']
797
795
798 return down_onlyrx
796 return down_onlyrx
799
797
800 @property
798 @property
801 def get_tx(self):
799 def get_tx(self):
802 """
800 """
803 This function shows the tx-values of one beam
801 This function shows the tx-values of one beam
804 """
802 """
805 data = json.loads(self.tx)
803 data = json.loads(self.tx)
806
804
807 return data
805 return data
808
806
809 @property
807 @property
810 def get_uptx(self):
808 def get_uptx(self):
811 """
809 """
812 This function shows the up-tx-values of one beam
810 This function shows the up-tx-values of one beam
813 """
811 """
814 data = json.loads(self.tx)
812 data = json.loads(self.tx)
815 up_data = data['up']
813 up_data = data['up']
816
814
817 up_values = []
815 up_values = []
818 for data in up_data:
816 for data in up_data:
819 for i in range(0,8):
817 for i in range(0,8):
820 up_values.append(data[i])
818 up_values.append(data[i])
821
819
822 return up_values
820 return up_values
823
821
824 @property
822 @property
825 def get_downtx(self):
823 def get_downtx(self):
826 """
824 """
827 This function shows the down-tx-values of one beam
825 This function shows the down-tx-values of one beam
828 """
826 """
829 data = json.loads(self.tx)
827 data = json.loads(self.tx)
830 down_data = data['down']
828 down_data = data['down']
831
829
832 down_values = []
830 down_values = []
833 for data in down_data:
831 for data in down_data:
834 for i in range(0,8):
832 for i in range(0,8):
835 down_values.append(data[i])
833 down_values.append(data[i])
836
834
837 return down_values
835 return down_values
838
836
839
837
840
838
841 @property
839 @property
842 def get_rx(self):
840 def get_rx(self):
843 """
841 """
844 This function shows the rx-values of one beam
842 This function shows the rx-values of one beam
845 """
843 """
846 data = json.loads(self.rx)
844 data = json.loads(self.rx)
847
845
848 return data
846 return data
849
847
850 @property
848 @property
851 def get_uprx(self):
849 def get_uprx(self):
852 """
850 """
853 This function shows the up-rx-values of one beam
851 This function shows the up-rx-values of one beam
854 """
852 """
855 data = json.loads(self.rx)
853 data = json.loads(self.rx)
856 up_data = data['up']
854 up_data = data['up']
857
855
858 up_values = []
856 up_values = []
859 for data in up_data:
857 for data in up_data:
860 for i in range(0,8):
858 for i in range(0,8):
861 up_values.append(data[i])
859 up_values.append(data[i])
862
860
863 return up_values
861 return up_values
864
862
865 @property
863 @property
866 def get_downrx(self):
864 def get_downrx(self):
867 """
865 """
868 This function shows the down-rx-values of one beam
866 This function shows the down-rx-values of one beam
869 """
867 """
870 data = json.loads(self.rx)
868 data = json.loads(self.rx)
871 down_data = data['down']
869 down_data = data['down']
872
870
873 down_values = []
871 down_values = []
874 for data in down_data:
872 for data in down_data:
875 for i in range(0,8):
873 for i in range(0,8):
876 down_values.append(data[i])
874 down_values.append(data[i])
877
875
878 return down_values
876 return down_values
General Comments 0
You need to be logged in to leave comments. Login now