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