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