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