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