##// END OF EJS Templates
operation mode field added...
Fiorella Quino -
r194:1bba8179301f
parent child
Show More
@@ -0,0 +1,19
1 $(document).ready(function() {
2 updateOperationMode()
3 });
4
5 $("#id_operation_mode").on('change', function() {
6 updateOperationMode()
7 });
8
9 function updateOperationMode(){
10 var operation_mode = $("#id_operation_mode").val();
11 if (operation_mode==0){
12 document.getElementById("id_operation_value").disabled=true;
13 $("#id_operation_value").hide();
14 }
15 else {
16 document.getElementById("id_operation_value").disabled=false;
17 $("#id_operation_value").show();
18 }
19 }
@@ -1,1038 +1,1038
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
5
6 import ast
6 import ast
7 import socket
7 import socket
8 import json
8 import json
9 import requests
9 import requests
10 import struct
10 import struct
11 import sys, time
11 import sys, time
12
12
13 import multiprocessing
13 import multiprocessing
14
14
15
15
16 antenna_default = json.dumps({
16 antenna_default = json.dumps({
17 "antenna_up": [[0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
17 "antenna_up": [[0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
18 [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
18 [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.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0],
21 [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0],
22 [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 ]
25 ]
26 ,
26 ,
27 "antenna_down": [[0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
27 "antenna_down": [[0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
28 [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5],
28 [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.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0],
31 [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0],
32 [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 })
35 })
36
36
37
37
38 tx_default = json.dumps({
38 tx_default = json.dumps({
39 "up": [[1,1,1,1,0,0,0,0],
39 "up": [[1,1,1,1,0,0,0,0],
40 [1,1,1,1,0,0,0,0],
40 [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 [0,0,0,0,1,1,1,1],
43 [0,0,0,0,1,1,1,1],
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
47
48 "down": [[1,1,1,1,0,0,0,0],
48 "down": [[1,1,1,1,0,0,0,0],
49 [1,1,1,1,0,0,0,0],
49 [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 [0,0,0,0,1,1,1,1],
52 [0,0,0,0,1,1,1,1],
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 })
56 })
57
57
58 rx_default = json.dumps({
58 rx_default = json.dumps({
59 "up": [[1,1,1,1,0,0,0,0],
59 "up": [[1,1,1,1,0,0,0,0],
60 [1,1,1,1,0,0,0,0],
60 [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 [0,0,0,0,1,1,1,1],
63 [0,0,0,0,1,1,1,1],
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
67
68 "down": [[1,1,1,1,0,0,0,0],
68 "down": [[1,1,1,1,0,0,0,0],
69 [1,1,1,1,0,0,0,0],
69 [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 [0,0,0,0,1,1,1,1],
72 [0,0,0,0,1,1,1,1],
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 })
76 })
77
77
78 conf_default = {}
78 conf_default = {}
79 status_default = {}
79 status_default = {}
80 for i in range(1,65):
80 for i in range(1,65):
81 conf_default[str(i)] = ""
81 conf_default[str(i)] = ""
82 status_default[str(i)] = 0
82 status_default[str(i)] = 0
83
83
84 ues_default = json.dumps({
84 ues_default = json.dumps({
85 "up": [0.533333,0.00000,1.06667,0.00000],
85 "up": [0.533333,0.00000,1.06667,0.00000],
86 "down": [0.533333,0.00000,1.06667,0.00000]
86 "down": [0.533333,0.00000,1.06667,0.00000]
87 })
87 })
88
88
89 onlyrx_default = json.dumps({
89 onlyrx_default = json.dumps({
90 "up": False,
90 "up": False,
91 "down": False
91 "down": False
92 })
92 })
93
93
94 def up_convertion(cadena):
94 def up_convertion(cadena):
95 valores = []
95 valores = []
96 for c in cadena:
96 for c in cadena:
97 if c == 1.0: valores=valores+['000']
97 if c == 1.0: valores=valores+['000']
98 if c == 2.0: valores=valores+['001']
98 if c == 2.0: valores=valores+['001']
99 if c == 3.0: valores=valores+['010']
99 if c == 3.0: valores=valores+['010']
100 if c == 0.0: valores=valores+['011']
100 if c == 0.0: valores=valores+['011']
101 if c == 0.5: valores=valores+['100']
101 if c == 0.5: valores=valores+['100']
102 if c == 1.5: valores=valores+['101']
102 if c == 1.5: valores=valores+['101']
103 if c == 2.5: valores=valores+['110']
103 if c == 2.5: valores=valores+['110']
104 if c == 3.5: valores=valores+['111']
104 if c == 3.5: valores=valores+['111']
105
105
106 return valores
106 return valores
107
107
108 def up_conv_bits(value):
108 def up_conv_bits(value):
109
109
110 if value == 1.0: bits="000"
110 if value == 1.0: bits="000"
111 if value == 2.0: bits="001"
111 if value == 2.0: bits="001"
112 if value == 3.0: bits="010"
112 if value == 3.0: bits="010"
113 if value == 0.0: bits="011"
113 if value == 0.0: bits="011"
114 if value == 0.5: bits="100"
114 if value == 0.5: bits="100"
115 if value == 1.5: bits="101"
115 if value == 1.5: bits="101"
116 if value == 2.5: bits="110"
116 if value == 2.5: bits="110"
117 if value == 3.5: bits="111"
117 if value == 3.5: bits="111"
118
118
119 return bits
119 return bits
120
120
121 def down_convertion(cadena):
121 def down_convertion(cadena):
122 valores = []
122 valores = []
123 for c in cadena:
123 for c in cadena:
124 if c == 1.0: valores=valores+['000']
124 if c == 1.0: valores=valores+['000']
125 if c == 2.0: valores=valores+['001']
125 if c == 2.0: valores=valores+['001']
126 if c == 3.0: valores=valores+['010']
126 if c == 3.0: valores=valores+['010']
127 if c == 0.0: valores=valores+['011']
127 if c == 0.0: valores=valores+['011']
128 if c == 0.5: valores=valores+['100']
128 if c == 0.5: valores=valores+['100']
129 if c == 1.5: valores=valores+['101']
129 if c == 1.5: valores=valores+['101']
130 if c == 2.5: valores=valores+['110']
130 if c == 2.5: valores=valores+['110']
131 if c == 3.5: valores=valores+['111']
131 if c == 3.5: valores=valores+['111']
132
132
133 return valores
133 return valores
134
134
135 def down_conv_bits(value):
135 def down_conv_bits(value):
136
136
137 if value == 1.0: bits="000"
137 if value == 1.0: bits="000"
138 if value == 2.0: bits="001"
138 if value == 2.0: bits="001"
139 if value == 3.0: bits="010"
139 if value == 3.0: bits="010"
140 if value == 0.0: bits="011"
140 if value == 0.0: bits="011"
141 if value == 0.5: bits="100"
141 if value == 0.5: bits="100"
142 if value == 1.5: bits="101"
142 if value == 1.5: bits="101"
143 if value == 2.5: bits="110"
143 if value == 2.5: bits="110"
144 if value == 3.5: bits="111"
144 if value == 3.5: bits="111"
145
145
146 return bits
146 return bits
147
147
148 def ip2position(module_number):
148 def ip2position(module_number):
149 j=0
149 j=0
150 i=0
150 i=0
151 for x in range(0,module_number-1):
151 for x in range(0,module_number-1):
152 j=j+1
152 j=j+1
153 if j==8:
153 if j==8:
154 i=i+1
154 i=i+1
155 j=0
155 j=0
156
156
157 pos = [i,j]
157 pos = [i,j]
158 return pos
158 return pos
159
159
160
160
161 def fromBinary2Char(binary_string):
161 def fromBinary2Char(binary_string):
162 number = int(binary_string, 2)
162 number = int(binary_string, 2)
163 #Plus 33 to avoid more than 1 characters values such as: '\x01'-'\x1f'
163 #Plus 33 to avoid more than 1 characters values such as: '\x01'-'\x1f'
164 number = number + 33
164 number = number + 33
165 char = chr(number)
165 char = chr(number)
166 return char
166 return char
167
167
168 def fromChar2Binary(char):
168 def fromChar2Binary(char):
169 number = ord(char) - 33
169 number = ord(char) - 33
170 #Minus 33 to get the real value
170 #Minus 33 to get the real value
171 bits = bin(number)[2:]
171 bits = bin(number)[2:]
172 #To ensure we have a string with 6bits
172 #To ensure we have a string with 6bits
173 if len(bits) < 6:
173 if len(bits) < 6:
174 bits = bits.zfill(6)
174 bits = bits.zfill(6)
175 return bits
175 return bits
176
176
177 OPERATION_MODES = (
177 OPERATION_MODES = (
178 (0, 'Manual'),
178 (0, 'Manual'),
179 (1, 'Automatic'),
179 (1, 'Automatic'),
180 )
180 )
181
181
182
182
183 class ABSConfiguration(Configuration):
183 class ABSConfiguration(Configuration):
184 active_beam = models.CharField(verbose_name='Active Beam', max_length=20000, default="{}")
184 active_beam = models.CharField(verbose_name='Active Beam', max_length=20000, default="{}")
185 module_status = models.CharField(verbose_name='Module Status', max_length=10000, default=json.dumps(status_default))
185 module_status = models.CharField(verbose_name='Module Status', max_length=10000, default=json.dumps(status_default))
186 operation_mode = models.CharField(verbose_name='Operation Mode', max_length = 20, choices=OPERATION_MODES, default = 0)
186 operation_mode = models.PositiveSmallIntegerField(verbose_name='Operation Mode', choices=OPERATION_MODES, default = 0)
187 operation_value = models.CharField(verbose_name='Periodic (seconds)', max_length=20000, default="10", null=True, blank=True)
187 operation_value = models.FloatField(verbose_name='Periodic (seconds)', default="10", null=True, blank=True)
188
188
189 class Meta:
189 class Meta:
190 db_table = 'abs_configurations'
190 db_table = 'abs_configurations'
191
191
192 def get_absolute_url_plot(self):
192 def get_absolute_url_plot(self):
193 return reverse('url_plot_abs_patterns', args=[str(self.id)])
193 return reverse('url_plot_abs_patterns', args=[str(self.id)])
194
194
195
195
196 def parms_to_dict(self):
196 def parms_to_dict(self):
197
197
198 parameters = {}
198 parameters = {}
199
199
200 parameters['device_id'] = self.device.id
200 parameters['device_id'] = self.device.id
201 parameters['name'] = self.name
201 parameters['name'] = self.name
202 parameters['beams'] = {}
202 parameters['beams'] = {}
203
203
204 beams = ABSBeam.objects.filter(abs_conf=self)
204 beams = ABSBeam.objects.filter(abs_conf=self)
205 b=1
205 b=1
206 for beam in beams:
206 for beam in beams:
207 #absbeam = ABSBeam.objects.get(pk=beams[beam])
207 #absbeam = ABSBeam.objects.get(pk=beams[beam])
208 parameters['beams']['beam'+str(b)] = beam.parms_to_dict()#absbeam.parms_to_dict()
208 parameters['beams']['beam'+str(b)] = beam.parms_to_dict()#absbeam.parms_to_dict()
209 b+=1
209 b+=1
210
210
211 return parameters
211 return parameters
212
212
213 def dict_to_parms(self, parameters):
213 def dict_to_parms(self, parameters):
214
214
215 self.name = parameters['name']
215 self.name = parameters['name']
216
216
217 absbeams = ABSBeam.objects.filter(abs_conf=self)
217 absbeams = ABSBeam.objects.filter(abs_conf=self)
218 beams = parameters['beams']
218 beams = parameters['beams']
219
219
220 if absbeams:
220 if absbeams:
221 beams_number = len(beams)
221 beams_number = len(beams)
222 absbeams_number = len(absbeams)
222 absbeams_number = len(absbeams)
223 if beams_number==absbeams_number:
223 if beams_number==absbeams_number:
224 i = 1
224 i = 1
225 for absbeam in absbeams:
225 for absbeam in absbeams:
226 absbeam.dict_to_parms(beams['beam'+str(i)])
226 absbeam.dict_to_parms(beams['beam'+str(i)])
227 i = i+1
227 i = i+1
228 elif beams_number > absbeams_number:
228 elif beams_number > absbeams_number:
229 i = 1
229 i = 1
230 for absbeam in absbeams:
230 for absbeam in absbeams:
231 absbeam.dict_to_parms(beams['beam'+str(i)])
231 absbeam.dict_to_parms(beams['beam'+str(i)])
232 i=i+1
232 i=i+1
233 for x in range(i,beams_number+1):
233 for x in range(i,beams_number+1):
234 new_beam = ABSBeam(
234 new_beam = ABSBeam(
235 name =beams['beam'+str(i)]['name'],
235 name =beams['beam'+str(i)]['name'],
236 antenna =json.dumps(beams['beam'+str(i)]['antenna']),
236 antenna =json.dumps(beams['beam'+str(i)]['antenna']),
237 abs_conf = self,
237 abs_conf = self,
238 tx =json.dumps(beams['beam'+str(i)]['tx']),
238 tx =json.dumps(beams['beam'+str(i)]['tx']),
239 rx =json.dumps(beams['beam'+str(i)]['rx']),
239 rx =json.dumps(beams['beam'+str(i)]['rx']),
240 ues =json.dumps(beams['beam'+str(i)]['ues']),
240 ues =json.dumps(beams['beam'+str(i)]['ues']),
241 only_rx =json.dumps(beams['beam'+str(i)]['only_rx'])
241 only_rx =json.dumps(beams['beam'+str(i)]['only_rx'])
242 )
242 )
243 new_beam.save()
243 new_beam.save()
244 i=i+1
244 i=i+1
245 else: #beams_number < absbeams_number:
245 else: #beams_number < absbeams_number:
246 i = 1
246 i = 1
247 for absbeam in absbeams:
247 for absbeam in absbeams:
248 if i <= beams_number:
248 if i <= beams_number:
249 absbeam.dict_to_parms(beams['beam'+str(i)])
249 absbeam.dict_to_parms(beams['beam'+str(i)])
250 i=i+1
250 i=i+1
251 else:
251 else:
252 absbeam.delete()
252 absbeam.delete()
253 else:
253 else:
254 for beam in beams:
254 for beam in beams:
255 new_beam = ABSBeam(
255 new_beam = ABSBeam(
256 name =beams[beam]['name'],
256 name =beams[beam]['name'],
257 antenna =json.dumps(beams[beam]['antenna']),
257 antenna =json.dumps(beams[beam]['antenna']),
258 abs_conf = self,
258 abs_conf = self,
259 tx =json.dumps(beams[beam]['tx']),
259 tx =json.dumps(beams[beam]['tx']),
260 rx =json.dumps(beams[beam]['rx']),
260 rx =json.dumps(beams[beam]['rx']),
261 ues =json.dumps(beams[beam]['ues']),
261 ues =json.dumps(beams[beam]['ues']),
262 only_rx =json.dumps(beams[beam]['only_rx'])
262 only_rx =json.dumps(beams[beam]['only_rx'])
263 )
263 )
264 new_beam.save()
264 new_beam.save()
265
265
266
266
267
267
268 def update_from_file(self, parameters):
268 def update_from_file(self, parameters):
269
269
270 self.dict_to_parms(parameters)
270 self.dict_to_parms(parameters)
271 self.save()
271 self.save()
272
272
273
273
274 def get_beams(self, **kwargs):
274 def get_beams(self, **kwargs):
275 '''
275 '''
276 This function returns ABS Configuration beams
276 This function returns ABS Configuration beams
277 '''
277 '''
278 return ABSBeam.objects.filter(abs_conf=self.pk, **kwargs)
278 return ABSBeam.objects.filter(abs_conf=self.pk, **kwargs)
279
279
280 def clone(self, **kwargs):
280 def clone(self, **kwargs):
281
281
282 beams = self.get_beams()
282 beams = self.get_beams()
283 self.pk = None
283 self.pk = None
284 self.id = None
284 self.id = None
285 for attr, value in kwargs.items():
285 for attr, value in kwargs.items():
286 setattr(self, attr, value)
286 setattr(self, attr, value)
287 self.save()
287 self.save()
288
288
289 for beam in beams:
289 for beam in beams:
290 beam.clone(abs_conf=self)
290 beam.clone(abs_conf=self)
291
291
292 return self
292 return self
293
293
294
294
295 def module_conf(self, module_num, beams):
295 def module_conf(self, module_num, beams):
296 """
296 """
297 This function creates beam configurations for one abs module.
297 This function creates beam configurations for one abs module.
298 """
298 """
299 ip_address = self.device.ip_address
299 ip_address = self.device.ip_address
300 ip_address = ip_address.split('.')
300 ip_address = ip_address.split('.')
301 module_seq = (ip_address[0],ip_address[1],ip_address[2])
301 module_seq = (ip_address[0],ip_address[1],ip_address[2])
302 dot = '.'
302 dot = '.'
303 module_ip = dot.join(module_seq)+'.'+str(module_num)
303 module_ip = dot.join(module_seq)+'.'+str(module_num)
304 module_port = self.device.port_address
304 module_port = self.device.port_address
305 write_route = 'http://'+module_ip+':'+str(module_port)+'/write'
305 write_route = 'http://'+module_ip+':'+str(module_port)+'/write'
306
306
307 header = 'JROABSCeCnModCnMod01000108SNDFexperimento1.ab1'
307 header = 'JROABSCeCnModCnMod01000108SNDFexperimento1.ab1'
308 module = 'ABS_'+str(module_num)
308 module = 'ABS_'+str(module_num)
309 bs = '' #{}
309 bs = '' #{}
310 i=1
310 i=1
311 #beams = {1: '001000', 2: '010001', 3: '010010', 4: '000011', 5: '101100', 6: '101101',
311 #beams = {1: '001000', 2: '010001', 3: '010010', 4: '000011', 5: '101100', 6: '101101',
312 # 7: '110110', 8: '111111', 9: '000000', 10: '001001', 11: '010010', 12: '011011'}
312 # 7: '110110', 8: '111111', 9: '000000', 10: '001001', 11: '010010', 12: '011011'}
313 for beam in beams:
313 for beam in beams:
314 #bs[i] = fromBinary2Char(beam.module_6bits(module_num))
314 #bs[i] = fromBinary2Char(beam.module_6bits(module_num))
315 bs = bs + fromBinary2Char(beam.module_6bits(module_num))
315 bs = bs + fromBinary2Char(beam.module_6bits(module_num))
316 i=i+1
316 i=i+1
317
317
318 beams = bs
318 beams = bs
319
319
320 parameters = {}
320 parameters = {}
321 parameters['header'] = header
321 parameters['header'] = header
322 parameters['module'] = module
322 parameters['module'] = module
323 parameters['beams'] = beams #json.dumps(beams)
323 parameters['beams'] = beams #json.dumps(beams)
324 print parameters['beams']
324 print parameters['beams']
325 answer = ''
325 answer = ''
326
326
327 try:
327 try:
328 r_write = requests.post(write_route, parameters, timeout=0.5)
328 r_write = requests.post(write_route, parameters, timeout=0.5)
329 answer = r_write.json()
329 answer = r_write.json()
330 self.message = answer['message']
330 self.message = answer['message']
331 except:
331 except:
332 self.message = "Could not write ABS parameters"
332 self.message = "Could not write ABS parameters"
333 return 0
333 return 0
334 return 1
334 return 1
335
335
336 def read_module(self, module):
336 def read_module(self, module):
337
337
338 """
338 """
339 Read out-bits (up-down) of 1 abs module NOT for Configuration
339 Read out-bits (up-down) of 1 abs module NOT for Configuration
340 """
340 """
341
341
342 parameters = {}
342 parameters = {}
343 ip_address = self.device.ip_address
343 ip_address = self.device.ip_address
344 ip_address = ip_address.split('.')
344 ip_address = ip_address.split('.')
345 module_seq = (ip_address[0],ip_address[1],ip_address[2])
345 module_seq = (ip_address[0],ip_address[1],ip_address[2])
346 dot = '.'
346 dot = '.'
347 module_ip = dot.join(module_seq)+'.'+str(module)
347 module_ip = dot.join(module_seq)+'.'+str(module)
348 module_port = self.device.port_address
348 module_port = self.device.port_address
349 read_route = 'http://'+module_ip+':'+str(module_port)+'/read'
349 read_route = 'http://'+module_ip+':'+str(module_port)+'/read'
350
350
351 print(read_route)
351 print(read_route)
352
352
353 answer = ''
353 answer = ''
354 module_bits = ''
354 module_bits = ''
355
355
356 try:
356 try:
357 r_write = requests.get(read_route, timeout=0.7)
357 r_write = requests.get(read_route, timeout=0.7)
358 answer = r_write.json()
358 answer = r_write.json()
359 self.message = answer['message']
359 self.message = answer['message']
360 module_bits = answer['allbits']
360 module_bits = answer['allbits']
361 except:
361 except:
362 #message = "Could not read ABS parameters"
362 #message = "Could not read ABS parameters"
363 return 0
363 return 0
364
364
365 return module_bits
365 return module_bits
366
366
367
367
368 def read_module(self, module):
368 def read_module(self, module):
369
369
370 return True
370 return True
371
371
372 def status_device(self):
372 def status_device(self):
373 """
373 """
374 This function gets the status of each abs module. It sends GET method to Web Application
374 This function gets the status of each abs module. It sends GET method to Web Application
375 in Python Bottle.
375 in Python Bottle.
376 """
376 """
377 ip_address = self.device.ip_address
377 ip_address = self.device.ip_address
378 ip_address = ip_address.split('.')
378 ip_address = ip_address.split('.')
379 module_seq = (ip_address[0],ip_address[1],ip_address[2])
379 module_seq = (ip_address[0],ip_address[1],ip_address[2])
380 dot = '.'
380 dot = '.'
381 module_port = self.device.port_address
381 module_port = self.device.port_address
382
382
383 modules_status = json.loads(self.module_status)
383 modules_status = json.loads(self.module_status)
384
384
385 for i in range(1,65):
385 for i in range(1,65):
386 module_ip = dot.join(module_seq)+'.'+str(i)
386 module_ip = dot.join(module_seq)+'.'+str(i)
387 print module_ip
387 print module_ip
388
388
389 route = 'http://'+module_ip+':'+str(module_port)+'/hello'
389 route = 'http://'+module_ip+':'+str(module_port)+'/hello'
390
390
391 try:
391 try:
392 r = requests.get(route, timeout=0.7)
392 r = requests.get(route, timeout=0.7)
393 modules_status[str(i)] = 1
393 modules_status[str(i)] = 1
394 except:
394 except:
395 modules_status[str(i)] = 0
395 modules_status[str(i)] = 0
396 pass
396 pass
397
397
398 self.message = 'ABS modules Status have been updated.'
398 self.message = 'ABS modules Status have been updated.'
399 self.module_status=json.dumps(modules_status)
399 self.module_status=json.dumps(modules_status)
400 self.save()
400 self.save()
401
401
402 return
402 return
403
403
404
404
405 def write_device(self):
405 def write_device(self):
406 """
406 """
407 This function sends the beams list to every abs module.
407 This function sends the beams list to every abs module.
408 It needs 'module_conf' function
408 It needs 'module_conf' function
409 """
409 """
410
410
411 beams = ABSBeam.objects.filter(abs_conf=self)
411 beams = ABSBeam.objects.filter(abs_conf=self)
412
412
413 #-------------Write each abs module-----------
413 #-------------Write each abs module-----------
414 if beams:
414 if beams:
415 beams_status = ast.literal_eval(self.module_status)
415 beams_status = ast.literal_eval(self.module_status)
416 for i in range(62,65): #(62,65)
416 for i in range(61,64): #(62,65)
417 try:
417 try:
418 answer = self.module_conf(i, beams)
418 answer = self.module_conf(i, beams)
419 beams_status[str(i)] = 1
419 beams_status[str(i)] = 1
420 self.module_status = json.dumps(beams_status)
420 self.module_status = json.dumps(beams_status)
421 self.save()
421 self.save()
422
422
423 except:
423 except:
424 beams_status[str(i)] = 0
424 beams_status[str(i)] = 0
425 self.module_status = json.dumps(beams_status)
425 self.module_status = json.dumps(beams_status)
426 self.save()
426 self.save()
427 answer = 0
427 answer = 0
428 return 0
428 return 0
429 else:
429 else:
430 self.message = "ABS Configuration does not have beams"
430 self.message = "ABS Configuration does not have beams"
431 return 0
431 return 0
432
432
433 #self.device.status = 1
433 #self.device.status = 1
434 ##
434 ##
435 if answer==1:
435 if answer==1:
436 self.message = "ABS Beams List have been sent to ABS Modules"
436 self.message = "ABS Beams List have been sent to ABS Modules"
437 beams[0].set_as_activebeam()
437 beams[0].set_as_activebeam()
438 else:
438 else:
439 self.message = "Could not read ABS parameters"
439 self.message = "Could not read ABS parameters"
440 ##
440 ##
441 self.save()
441 self.save()
442 return 1
442 return 1
443
443
444
444
445 def write_module(self, module):
445 def write_module(self, module):
446
446
447 """
447 """
448 Send configuration to one abs module
448 Send configuration to one abs module
449 """
449 """
450
450
451 parameters = {}
451 parameters = {}
452 ip_address = self.abs_conf.device.ip_address
452 ip_address = self.abs_conf.device.ip_address
453 ip_address = ip_address.split('.')
453 ip_address = ip_address.split('.')
454 module_seq = (ip_address[0],ip_address[1],ip_address[2])
454 module_seq = (ip_address[0],ip_address[1],ip_address[2])
455 dot = '.'
455 dot = '.'
456 module_ip = dot.join(module_seq)+'.'+str(module)
456 module_ip = dot.join(module_seq)+'.'+str(module)
457 module_port = self.abs_conf.device.port_address
457 module_port = self.abs_conf.device.port_address
458 write_route = 'http://'+module_ip+':'+str(module_port)+'/write'
458 write_route = 'http://'+module_ip+':'+str(module_port)+'/write'
459
459
460 #print write_route
460 #print write_route
461
461
462 header = 'JROABSCeCnModCnMod01000108SNDFexperimento1.ab1'
462 header = 'JROABSCeCnModCnMod01000108SNDFexperimento1.ab1'
463 module = 'ABS_'+str(module)
463 module = 'ABS_'+str(module)
464 beams = {1: '001000', 2: '010001', 3: '010010', 4: '000011', 5: '101100', 6: '101101',
464 beams = {1: '001000', 2: '010001', 3: '010010', 4: '000011', 5: '101100', 6: '101101',
465 7: '110110', 8: '111111', 9: '000000', 10: '001001', 11: '010010', 12: '011011'}
465 7: '110110', 8: '111111', 9: '000000', 10: '001001', 11: '010010', 12: '011011'}
466
466
467 parameters['header'] = header
467 parameters['header'] = header
468 parameters['module'] = module
468 parameters['module'] = module
469 parameters['beams'] = json.dumps(beams)
469 parameters['beams'] = json.dumps(beams)
470
470
471 answer = ''
471 answer = ''
472
472
473 try:
473 try:
474 r_write = requests.post(write_route, parameters, timeout=0.5)
474 r_write = requests.post(write_route, parameters, timeout=0.5)
475 answer = r_write.json()
475 answer = r_write.json()
476 self.message = answer['message']
476 self.message = answer['message']
477 except:
477 except:
478 self.message = "Could not write ABS parameters"
478 self.message = "Could not write ABS parameters"
479 return 0
479 return 0
480
480
481
481
482 #self.device.status = int(answer['status'])
482 #self.device.status = int(answer['status'])
483
483
484 return 1
484 return 1
485
485
486
486
487 def beam_selector(self, module, beam_pos):
487 def beam_selector(self, module, beam_pos):
488 """
488 """
489 This function selects the beam number for one absmodule.
489 This function selects the beam number for one absmodule.
490 """
490 """
491
491
492 if beam_pos > 0:
492 if beam_pos > 0:
493 beam_pos = beam_pos - 1
493 beam_pos = beam_pos - 1
494 else:
494 else:
495 beam_pos = 0
495 beam_pos = 0
496
496
497 #El indice del apunte debe ser menor que el numero total de apuntes
497 #El indice del apunte debe ser menor que el numero total de apuntes
498 #El servidor tcp en el embebido comienza a contar desde 0
498 #El servidor tcp en el embebido comienza a contar desde 0
499 beams_list = ABSBeam.objects.filter(abs_conf=self)
499 beams_list = ABSBeam.objects.filter(abs_conf=self)
500 if len(beams_list) < beam_pos:
500 if len(beams_list) < beam_pos:
501 return 0
501 return 0
502
502
503 flag = 1
503 flag = 1
504 if beam_pos>9:
504 if beam_pos>9:
505 flag = 2
505 flag = 2
506
506
507 module_address = ('192.168.1.'+str(module), 5500)
507 module_address = ('192.168.1.'+str(module), 5500)
508 header = 'JROABSCeCnModCnMod0100000'
508 header = 'JROABSCeCnModCnMod0100000'
509 numbers = len(str(beam_pos))
509 numbers = len(str(beam_pos))
510 function = 'CHGB'
510 function = 'CHGB'
511
511
512 message_tx = header+str(numbers)+function+str(beam_pos)+'0'
512 message_tx = header+str(numbers)+function+str(beam_pos)+'0'
513
513
514 # Create the datagram socket
514 # Create the datagram socket
515 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
515 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
516 #sock.connect(module_address)
516 #sock.connect(module_address)
517 try:
517 try:
518 sock.connect(module_address)
518 sock.connect(module_address)
519 sock.send(message_tx)
519 sock.send(message_tx)
520 sock.close()
520 sock.close()
521 print("Writing abs module:"+module_address[0]+"...")
521 print("Writing abs module:"+module_address[0]+"...")
522 except:
522 except:
523 sock = None
523 sock = None
524 print("Problem writing abs module:"+module_address[0])
524 print("Problem writing abs module:"+module_address[0])
525 return 0
525 return 0
526
526
527 return 1
527 return 1
528
528
529
529
530 def change_beam(self, beam_pos):
530 def change_beam(self, beam_pos):
531 """
531 """
532 This function selects the beam number for all absmodules.
532 This function selects the beam number for all absmodules.
533 """
533 """
534 for i in range(1,65):
534 for i in range(1,65):
535 try:
535 try:
536 self.beam_selector(i,beam_pos)
536 self.beam_selector(i,beam_pos)
537 except:
537 except:
538 print("Problem with module: 192.168.1."+str(i))
538 print("Problem with module: 192.168.1."+str(i))
539 self.message = "Problem with module: 192.168.1."+str(i)
539 self.message = "Problem with module: 192.168.1."+str(i)
540 #return 0
540 #return 0
541 return 1
541 return 1
542
542
543
543
544 def send_beam_num(self, beam_pos):
544 def send_beam_num(self, beam_pos):
545 """
545 """
546 This function connects to a multicast group and sends the beam number
546 This function connects to a multicast group and sends the beam number
547 to all abs modules.
547 to all abs modules.
548 """
548 """
549
549
550 if beam_pos > 0:
550 if beam_pos > 0:
551 beam_pos = beam_pos - 1
551 beam_pos = beam_pos - 1
552 else:
552 else:
553 beam_pos = 0
553 beam_pos = 0
554
554
555 #El indice del apunte debe ser menor que el numero total de apuntes
555 #El indice del apunte debe ser menor que el numero total de apuntes
556 #El servidor tcp en el embebido comienza a contar desde 0
556 #El servidor tcp en el embebido comienza a contar desde 0
557 beams_list = ABSBeam.objects.filter(abs_conf=self)
557 beams_list = ABSBeam.objects.filter(abs_conf=self)
558 if len(beams_list) < beam_pos:
558 if len(beams_list) < beam_pos:
559 return 0
559 return 0
560
560
561 flag = 1
561 flag = 1
562 if beam_pos>9:
562 if beam_pos>9:
563 flag = 2
563 flag = 2
564
564
565 header = 'JROABSCeCnModCnMod0100000'
565 header = 'JROABSCeCnModCnMod0100000'
566 flag = str(flag)
566 flag = str(flag)
567 function = 'CHGB'
567 function = 'CHGB'
568 message_tx = header+flag+function+str(beam_pos)+'0'
568 message_tx = header+flag+function+str(beam_pos)+'0'
569
569
570 multicast_group = '224.3.29.71'
570 multicast_group = '224.3.29.71'
571 server_address = ('',10000)
571 server_address = ('',10000)
572
572
573 # Create the socket
573 # Create the socket
574 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
574 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
575 # Bind to the server address
575 # Bind to the server address
576 sock.bind(server_address)
576 sock.bind(server_address)
577 # Telling the OS add the socket to the multicast on all interfaces
577 # Telling the OS add the socket to the multicast on all interfaces
578 group = socket.inet_aton(multicast_group)
578 group = socket.inet_aton(multicast_group)
579 mreq = struct.pack('4sL', group, socket.INADDR_ANY)
579 mreq = struct.pack('4sL', group, socket.INADDR_ANY)
580 sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
580 sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
581
581
582 #print 'sending acknowledgement to all: \n' + message_tx
582 #print 'sending acknowledgement to all: \n' + message_tx
583 sock.sendto(message_tx, (multicast_group, 10000))
583 sock.sendto(message_tx, (multicast_group, 10000))
584 sock.close()
584 sock.close()
585 sock = None
585 sock = None
586
586
587 return 1
587 return 1
588
588
589 def test1(self):
589 def test1(self):
590 t1 = time.time()
590 t1 = time.time()
591 t2 = 0
591 t2 = 0
592 while (t2-t1)<100:#300
592 while (t2-t1)<100:#300
593 t2 = time.time()
593 t2 = time.time()
594 self.send_beam_num(2)
594 self.send_beam_num(2)
595 time.sleep(0.04)
595 time.sleep(0.04)
596 self.send_beam_num(1)
596 self.send_beam_num(1)
597 time.sleep(0.04)
597 time.sleep(0.04)
598 return
598 return
599
599
600 def change_procs_test1(self, module):
600 def change_procs_test1(self, module):
601
601
602 for i in range (1,300):#300
602 for i in range (1,300):#300
603 beam_pos = 1
603 beam_pos = 1
604 module_address = ('192.168.1.'+str(module), 5500)
604 module_address = ('192.168.1.'+str(module), 5500)
605 header = 'JROABSCeCnModCnMod0100000'
605 header = 'JROABSCeCnModCnMod0100000'
606 numbers = len(str(beam_pos))
606 numbers = len(str(beam_pos))
607 function = 'CHGB'
607 function = 'CHGB'
608
608
609 message_tx = header+str(numbers)+function+str(beam_pos)+'0'
609 message_tx = header+str(numbers)+function+str(beam_pos)+'0'
610
610
611 # Create the datagram socket
611 # Create the datagram socket
612 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
612 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
613 sock.connect(module_address)
613 sock.connect(module_address)
614
614
615 sock.send(message_tx)
615 sock.send(message_tx)
616 #t = sock.recv(1024)
616 #t = sock.recv(1024)
617 sock.close()
617 sock.close()
618 sock = None
618 sock = None
619
619
620
620
621 time.sleep(0.04)
621 time.sleep(0.04)
622
622
623
623
624 beam_pos = 0
624 beam_pos = 0
625 numbers = len(str(beam_pos))
625 numbers = len(str(beam_pos))
626
626
627 message_tx = header+str(numbers)+function+str(beam_pos)+'0'
627 message_tx = header+str(numbers)+function+str(beam_pos)+'0'
628
628
629 # Create the datagram socket
629 # Create the datagram socket
630 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
630 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
631 sock.connect(module_address)
631 sock.connect(module_address)
632 sock.send(message_tx)
632 sock.send(message_tx)
633 sock.close()
633 sock.close()
634 sock = None
634 sock = None
635
635
636 time.sleep(0.04)
636 time.sleep(0.04)
637
637
638
638
639 def multi_procs_test1(self):
639 def multi_procs_test1(self):
640
640
641 """
641 """
642 This function sends the beam number to all abs modules using multiprocessing.
642 This function sends the beam number to all abs modules using multiprocessing.
643 """
643 """
644
644
645 #if __name__ == "__main__":
645 #if __name__ == "__main__":
646 size = 10000000 # Number of random numbers to add
646 size = 10000000 # Number of random numbers to add
647 procs = 65 # (Number-1) of processes to create (absmodule)
647 procs = 65 # (Number-1) of processes to create (absmodule)
648
648
649 # Create a list of jobs and then iterate through
649 # Create a list of jobs and then iterate through
650 # the number of processes appending each process to
650 # the number of processes appending each process to
651 # the job list
651 # the job list
652 jobs = []
652 jobs = []
653 for i in range(1, procs):
653 for i in range(1, procs):
654
654
655 process = multiprocessing.Process(target=self.change_procs_test1,args=(i,))
655 process = multiprocessing.Process(target=self.change_procs_test1,args=(i,))
656 jobs.append(process)
656 jobs.append(process)
657 #print jobs
657 #print jobs
658
658
659 # Start the processes (i.e. calculate the random number lists)
659 # Start the processes (i.e. calculate the random number lists)
660 for j in jobs:
660 for j in jobs:
661 #time.sleep(0.4)
661 #time.sleep(0.4)
662 #print j
662 #print j
663 j.start()
663 j.start()
664
664
665 # Ensure all of the processes have finished
665 # Ensure all of the processes have finished
666 for j in jobs:
666 for j in jobs:
667 j.join()
667 j.join()
668
668
669 print("List processing complete.")
669 print("List processing complete.")
670 return 1
670 return 1
671
671
672
672
673
673
674 def multi_procs_test2(self):
674 def multi_procs_test2(self):
675 """
675 """
676 This function use multiprocessing python library. Importing Pool we can select
676 This function use multiprocessing python library. Importing Pool we can select
677 the number of cores we want to use
677 the number of cores we want to use
678 After 'nproc' linux command, we know how many cores computer has.
678 After 'nproc' linux command, we know how many cores computer has.
679 NOT WORKING
679 NOT WORKING
680 """
680 """
681 import multiprocessing
681 import multiprocessing
682 pool = multiprocessing.Pool(3) # cores
682 pool = multiprocessing.Pool(3) # cores
683
683
684 tasks = []
684 tasks = []
685 procs = 65
685 procs = 65
686 for i in range(62, procs):
686 for i in range(62, procs):
687 tasks.append( (i,))
687 tasks.append( (i,))
688 #print tasks
688 #print tasks
689 #pool.apply_async(self.change_procs_test1, 62)
689 #pool.apply_async(self.change_procs_test1, 62)
690 results = [pool.apply( self.change_procs_test1, t ) for t in tasks]
690 results = [pool.apply( self.change_procs_test1, t ) for t in tasks]
691 #for result in results:
691 #for result in results:
692 #result.get()
692 #result.get()
693 #(plotNum, plotFilename) = result.get()
693 #(plotNum, plotFilename) = result.get()
694 #print("Result: plot %d written to %s" % (plotNum, plotFilename) )
694 #print("Result: plot %d written to %s" % (plotNum, plotFilename) )
695
695
696 return 1
696 return 1
697
697
698
698
699 def multi_procs_test3(self):
699 def multi_procs_test3(self):
700 """
700 """
701 This function use multiprocessing python library. Importing Pool we can select
701 This function use multiprocessing python library. Importing Pool we can select
702 the number of cores we want to use
702 the number of cores we want to use
703 After 'nproc' linux command, we know how many cores computer has.
703 After 'nproc' linux command, we know how many cores computer has.
704 """
704 """
705 from multiprocessing import Pool
705 from multiprocessing import Pool
706 import time
706 import time
707
707
708 def f(x):
708 def f(x):
709 return x*x
709 return x*x
710
710
711 tasks = []
711 tasks = []
712 procs = 65
712 procs = 65
713 pool = Pool(processes=4)
713 pool = Pool(processes=4)
714
714
715 #for i in range(62, procs):
715 #for i in range(62, procs):
716 #result = pool.map(f, range(62,65))
716 #result = pool.map(f, range(62,65))
717 it = pool.imap(self.change_procs_test1, range(62,65))
717 it = pool.imap(self.change_procs_test1, range(62,65))
718 #result.get(timeout=5)
718 #result.get(timeout=5)
719
719
720 return 1
720 return 1
721
721
722
722
723 def f(x):
723 def f(x):
724 print x
724 print x
725 return
725 return
726
726
727 def multi_procs_test4(self):
727 def multi_procs_test4(self):
728 import multiprocessing as mp
728 import multiprocessing as mp
729
729
730
730
731 num_workers = mp.cpu_count()
731 num_workers = mp.cpu_count()
732
732
733 pool = mp.Pool(num_workers)
733 pool = mp.Pool(num_workers)
734 procs = 65
734 procs = 65
735 for i in range(62, procs):
735 for i in range(62, procs):
736 #for task in tasks:
736 #for task in tasks:
737 pool.apply_async(self.f, args = (i,))
737 pool.apply_async(self.f, args = (i,))
738
738
739 pool.close()
739 pool.close()
740 pool.join()
740 pool.join()
741
741
742 return 1
742 return 1
743
743
744
744
745 def get_absolute_url_import(self):
745 def get_absolute_url_import(self):
746 return reverse('url_import_abs_conf', args=[str(self.id)])
746 return reverse('url_import_abs_conf', args=[str(self.id)])
747
747
748
748
749
749
750
750
751 class ABSBeam(models.Model):
751 class ABSBeam(models.Model):
752
752
753 name = models.CharField(max_length=60, default='Beam')
753 name = models.CharField(max_length=60, default='Beam')
754 antenna = models.CharField(verbose_name='Antenna', max_length=1000, default=antenna_default)
754 antenna = models.CharField(verbose_name='Antenna', max_length=1000, default=antenna_default)
755 abs_conf = models.ForeignKey(ABSConfiguration, null=True, verbose_name='ABS Configuration')
755 abs_conf = models.ForeignKey(ABSConfiguration, null=True, verbose_name='ABS Configuration')
756 tx = models.CharField(verbose_name='Tx', max_length=1000, default=tx_default)
756 tx = models.CharField(verbose_name='Tx', max_length=1000, default=tx_default)
757 rx = models.CharField(verbose_name='Rx', max_length=1000, default=rx_default)
757 rx = models.CharField(verbose_name='Rx', max_length=1000, default=rx_default)
758 s_time = models.TimeField(verbose_name='Star Time', default='00:00:00')
758 s_time = models.TimeField(verbose_name='Star Time', default='00:00:00')
759 e_time = models.TimeField(verbose_name='End Time', default='23:59:59')
759 e_time = models.TimeField(verbose_name='End Time', default='23:59:59')
760 modules_conf = models.CharField(verbose_name='Modules', max_length=2000, default=json.dumps(conf_default))
760 modules_conf = models.CharField(verbose_name='Modules', max_length=2000, default=json.dumps(conf_default))
761 ues = models.CharField(verbose_name='Ues', max_length=100, default=ues_default)
761 ues = models.CharField(verbose_name='Ues', max_length=100, default=ues_default)
762 only_rx = models.CharField(verbose_name='Only RX', max_length=40, default=onlyrx_default)
762 only_rx = models.CharField(verbose_name='Only RX', max_length=40, default=onlyrx_default)
763
763
764 class Meta:
764 class Meta:
765 db_table = 'abs_beams'
765 db_table = 'abs_beams'
766
766
767 def __unicode__(self):
767 def __unicode__(self):
768 return u'%s' % (self.name)
768 return u'%s' % (self.name)
769
769
770 def parms_to_dict(self):
770 def parms_to_dict(self):
771
771
772 #Update data
772 #Update data
773 self.modules_6bits()
773 self.modules_6bits()
774
774
775 parameters = {}
775 parameters = {}
776
776
777 parameters['name'] = self.name
777 parameters['name'] = self.name
778 parameters['antenna'] = ast.literal_eval(self.antenna)
778 parameters['antenna'] = ast.literal_eval(self.antenna)
779 parameters['abs_conf'] = self.abs_conf.name
779 parameters['abs_conf'] = self.abs_conf.name
780 parameters['tx'] = ast.literal_eval(self.tx)
780 parameters['tx'] = ast.literal_eval(self.tx)
781 parameters['rx'] = ast.literal_eval(self.rx)
781 parameters['rx'] = ast.literal_eval(self.rx)
782 parameters['s_time'] = self.s_time.strftime("%H:%M:%S")
782 parameters['s_time'] = self.s_time.strftime("%H:%M:%S")
783 parameters['e_time'] = self.e_time.strftime("%H:%M:%S")
783 parameters['e_time'] = self.e_time.strftime("%H:%M:%S")
784 parameters['configuration'] = ast.literal_eval(self.modules_conf)
784 parameters['configuration'] = ast.literal_eval(self.modules_conf)
785 parameters['ues'] = ast.literal_eval(self.ues)
785 parameters['ues'] = ast.literal_eval(self.ues)
786 parameters['only_rx'] = json.loads(self.only_rx)
786 parameters['only_rx'] = json.loads(self.only_rx)
787
787
788 return parameters
788 return parameters
789
789
790 def dict_to_parms(self, parameters):
790 def dict_to_parms(self, parameters):
791
791
792 self.name = parameters['name']
792 self.name = parameters['name']
793 self.antenna = json.dumps(parameters['antenna'])
793 self.antenna = json.dumps(parameters['antenna'])
794 #self.abs_conf = parameters['abs_conf']
794 #self.abs_conf = parameters['abs_conf']
795 self.tx = json.dumps(parameters['tx'])
795 self.tx = json.dumps(parameters['tx'])
796 self.rx = json.dumps(parameters['rx'])
796 self.rx = json.dumps(parameters['rx'])
797 #self.s_time = parameters['s_time']
797 #self.s_time = parameters['s_time']
798 #self.e_time = parameters['e_time']
798 #self.e_time = parameters['e_time']
799 self.ues = json.dumps(parameters['ues'])
799 self.ues = json.dumps(parameters['ues'])
800 self.only_rx = json.dumps(parameters['only_rx'])
800 self.only_rx = json.dumps(parameters['only_rx'])
801
801
802 self.modules_6bits()
802 self.modules_6bits()
803 self.save()
803 self.save()
804
804
805
805
806 def clone(self, **kwargs):
806 def clone(self, **kwargs):
807
807
808 self.pk = None
808 self.pk = None
809 self.id = None
809 self.id = None
810 for attr, value in kwargs.items():
810 for attr, value in kwargs.items():
811 setattr(self, attr, value)
811 setattr(self, attr, value)
812
812
813 self.save()
813 self.save()
814
814
815 return self
815 return self
816
816
817
817
818
818
819 def module_6bits(self, module):
819 def module_6bits(self, module):
820 """
820 """
821 This function reads antenna pattern and choose 6bits (upbits-downbits) for one abs module
821 This function reads antenna pattern and choose 6bits (upbits-downbits) for one abs module
822 """
822 """
823 if module > 64:
823 if module > 64:
824 beam_bits = ""
824 beam_bits = ""
825 return beam_bits
825 return beam_bits
826
826
827 data = ast.literal_eval(self.antenna)
827 data = ast.literal_eval(self.antenna)
828 up_data = data['antenna_up']
828 up_data = data['antenna_up']
829 down_data = data['antenna_down']
829 down_data = data['antenna_down']
830
830
831 pos = ip2position(module)
831 pos = ip2position(module)
832 up_value = up_data[pos[0]][pos[1]]
832 up_value = up_data[pos[0]][pos[1]]
833 down_value = down_data[pos[0]][pos[1]]
833 down_value = down_data[pos[0]][pos[1]]
834
834
835 up_bits = up_conv_bits(up_value)
835 up_bits = up_conv_bits(up_value)
836 down_bits = down_conv_bits(down_value)
836 down_bits = down_conv_bits(down_value)
837 beam_bits = up_bits+down_bits
837 beam_bits = up_bits+down_bits
838
838
839 return beam_bits
839 return beam_bits
840
840
841 def modules_6bits(self):
841 def modules_6bits(self):
842 """
842 """
843 This function returns 6bits from every abs module (1-64) in a dict
843 This function returns 6bits from every abs module (1-64) in a dict
844 """
844 """
845 modules_configuration = ast.literal_eval(self.modules_conf)
845 modules_configuration = ast.literal_eval(self.modules_conf)
846
846
847 for i in range(1,65):
847 for i in range(1,65):
848 modules_configuration[str(i)] = self.module_6bits(i)
848 modules_configuration[str(i)] = self.module_6bits(i)
849
849
850 self.modules_conf = json.dumps(modules_configuration)
850 self.modules_conf = json.dumps(modules_configuration)
851 self.save()
851 self.save()
852
852
853 return self.modules_conf
853 return self.modules_conf
854
854
855
855
856 def set_as_activebeam(self):
856 def set_as_activebeam(self):
857 """
857 """
858 This function set this beam as the active beam of its ABS Configuration.
858 This function set this beam as the active beam of its ABS Configuration.
859 """
859 """
860 self.abs_conf.active_beam = json.dumps({'active_beam': self.id})
860 self.abs_conf.active_beam = json.dumps({'active_beam': self.id})
861 self.abs_conf.save()
861 self.abs_conf.save()
862
862
863 return
863 return
864
864
865
865
866 @property
866 @property
867 def get_upvalues(self):
867 def get_upvalues(self):
868 """
868 """
869 This function reads antenna pattern and show the up-value of one abs module
869 This function reads antenna pattern and show the up-value of one abs module
870 """
870 """
871
871
872 data = ast.literal_eval(self.antenna)
872 data = ast.literal_eval(self.antenna)
873 up_data = data['antenna_up']
873 up_data = data['antenna_up']
874
874
875 up_values = []
875 up_values = []
876 for data in up_data:
876 for data in up_data:
877 for i in range(0,8):
877 for i in range(0,8):
878 up_values.append(data[i])
878 up_values.append(data[i])
879
879
880 return up_values
880 return up_values
881
881
882 @property
882 @property
883 def antenna_upvalues(self):
883 def antenna_upvalues(self):
884 """
884 """
885 This function reads antenna pattern and show the up - values of one abs beam
885 This function reads antenna pattern and show the up - values of one abs beam
886 in a particular order
886 in a particular order
887 """
887 """
888 data = ast.literal_eval(self.antenna)
888 data = ast.literal_eval(self.antenna)
889 up_data = data['antenna_up']
889 up_data = data['antenna_up']
890
890
891 return up_data
891 return up_data
892
892
893 @property
893 @property
894 def antenna_downvalues(self):
894 def antenna_downvalues(self):
895 """
895 """
896 This function reads antenna pattern and show the down - values of one abs beam
896 This function reads antenna pattern and show the down - values of one abs beam
897 in a particular order
897 in a particular order
898 """
898 """
899 data = ast.literal_eval(self.antenna)
899 data = ast.literal_eval(self.antenna)
900 down_data = data['antenna_down']
900 down_data = data['antenna_down']
901
901
902 return down_data
902 return down_data
903
903
904 @property
904 @property
905 def get_downvalues(self):
905 def get_downvalues(self):
906 """
906 """
907 This function reads antenna pattern and show the down-value of one abs module
907 This function reads antenna pattern and show the down-value of one abs module
908 """
908 """
909
909
910 data = ast.literal_eval(self.antenna)
910 data = ast.literal_eval(self.antenna)
911 down_data = data['antenna_down']
911 down_data = data['antenna_down']
912
912
913 down_values = []
913 down_values = []
914 for data in down_data:
914 for data in down_data:
915 for i in range(0,8):
915 for i in range(0,8):
916 down_values.append(data[i])
916 down_values.append(data[i])
917
917
918 return down_values
918 return down_values
919
919
920 @property
920 @property
921 def get_up_ues(self):
921 def get_up_ues(self):
922 """
922 """
923 This function shows the up-ues-value of one beam
923 This function shows the up-ues-value of one beam
924 """
924 """
925 data = ast.literal_eval(self.ues)
925 data = ast.literal_eval(self.ues)
926 up_ues = data['up']
926 up_ues = data['up']
927
927
928 return up_ues
928 return up_ues
929
929
930 @property
930 @property
931 def get_down_ues(self):
931 def get_down_ues(self):
932 """
932 """
933 This function shows the down-ues-value of one beam
933 This function shows the down-ues-value of one beam
934 """
934 """
935 data = ast.literal_eval(self.ues)
935 data = ast.literal_eval(self.ues)
936 down_ues = data['down']
936 down_ues = data['down']
937
937
938 return down_ues
938 return down_ues
939
939
940 @property
940 @property
941 def get_up_onlyrx(self):
941 def get_up_onlyrx(self):
942 """
942 """
943 This function shows the up-onlyrx-value of one beam
943 This function shows the up-onlyrx-value of one beam
944 """
944 """
945 data = json.loads(self.only_rx)
945 data = json.loads(self.only_rx)
946 up_onlyrx = data['up']
946 up_onlyrx = data['up']
947
947
948 return up_onlyrx
948 return up_onlyrx
949
949
950 @property
950 @property
951 def get_down_onlyrx(self):
951 def get_down_onlyrx(self):
952 """
952 """
953 This function shows the down-onlyrx-value of one beam
953 This function shows the down-onlyrx-value of one beam
954 """
954 """
955 data = json.loads(self.only_rx)
955 data = json.loads(self.only_rx)
956 down_onlyrx = data['down']
956 down_onlyrx = data['down']
957
957
958 return down_onlyrx
958 return down_onlyrx
959
959
960 @property
960 @property
961 def get_tx(self):
961 def get_tx(self):
962 """
962 """
963 This function shows the tx-values of one beam
963 This function shows the tx-values of one beam
964 """
964 """
965 data = json.loads(self.tx)
965 data = json.loads(self.tx)
966
966
967 return data
967 return data
968
968
969 @property
969 @property
970 def get_uptx(self):
970 def get_uptx(self):
971 """
971 """
972 This function shows the up-tx-values of one beam
972 This function shows the up-tx-values of one beam
973 """
973 """
974 data = json.loads(self.tx)
974 data = json.loads(self.tx)
975 up_data = data['up']
975 up_data = data['up']
976
976
977 up_values = []
977 up_values = []
978 for data in up_data:
978 for data in up_data:
979 for i in range(0,8):
979 for i in range(0,8):
980 up_values.append(data[i])
980 up_values.append(data[i])
981
981
982 return up_values
982 return up_values
983
983
984 @property
984 @property
985 def get_downtx(self):
985 def get_downtx(self):
986 """
986 """
987 This function shows the down-tx-values of one beam
987 This function shows the down-tx-values of one beam
988 """
988 """
989 data = json.loads(self.tx)
989 data = json.loads(self.tx)
990 down_data = data['down']
990 down_data = data['down']
991
991
992 down_values = []
992 down_values = []
993 for data in down_data:
993 for data in down_data:
994 for i in range(0,8):
994 for i in range(0,8):
995 down_values.append(data[i])
995 down_values.append(data[i])
996
996
997 return down_values
997 return down_values
998
998
999
999
1000
1000
1001 @property
1001 @property
1002 def get_rx(self):
1002 def get_rx(self):
1003 """
1003 """
1004 This function shows the rx-values of one beam
1004 This function shows the rx-values of one beam
1005 """
1005 """
1006 data = json.loads(self.rx)
1006 data = json.loads(self.rx)
1007
1007
1008 return data
1008 return data
1009
1009
1010 @property
1010 @property
1011 def get_uprx(self):
1011 def get_uprx(self):
1012 """
1012 """
1013 This function shows the up-rx-values of one beam
1013 This function shows the up-rx-values of one beam
1014 """
1014 """
1015 data = json.loads(self.rx)
1015 data = json.loads(self.rx)
1016 up_data = data['up']
1016 up_data = data['up']
1017
1017
1018 up_values = []
1018 up_values = []
1019 for data in up_data:
1019 for data in up_data:
1020 for i in range(0,8):
1020 for i in range(0,8):
1021 up_values.append(data[i])
1021 up_values.append(data[i])
1022
1022
1023 return up_values
1023 return up_values
1024
1024
1025 @property
1025 @property
1026 def get_downrx(self):
1026 def get_downrx(self):
1027 """
1027 """
1028 This function shows the down-rx-values of one beam
1028 This function shows the down-rx-values of one beam
1029 """
1029 """
1030 data = json.loads(self.rx)
1030 data = json.loads(self.rx)
1031 down_data = data['down']
1031 down_data = data['down']
1032
1032
1033 down_values = []
1033 down_values = []
1034 for data in down_data:
1034 for data in down_data:
1035 for i in range(0,8):
1035 for i in range(0,8):
1036 down_values.append(data[i])
1036 down_values.append(data[i])
1037
1037
1038 return down_values
1038 return down_values
@@ -1,46 +1,47
1 {% extends "dev_conf_edit.html" %}
1 {% extends "dev_conf_edit.html" %}
2 {% load bootstrap3 %}
2 {% load bootstrap3 %}
3 {% load static %}
3 {% load static %}
4
4
5 {% block extra-head %}
5 {% block extra-head %}
6 <style type="text/css">
6 <style type="text/css">
7 /* show the move cursor as the user moves the mouse over the panel header.*/
7 /* show the move cursor as the user moves the mouse over the panel header.*/
8 .panel-default { cursor: move; }
8 .panel-default { cursor: move; }
9 </style>
9 </style>
10 <script src="{% static 'js/jquery-ui.min.js' %}"></script>
10 <script src="{% static 'js/jquery-ui.min.js' %}"></script>
11
11
12 {% endblock %}
12 {% endblock %}
13
13
14 {% block content %}
14 {% block content %}
15 <form class="form" method="post">
15 <form class="form" method="post">
16 {% csrf_token %}
16 {% csrf_token %}
17 {% bootstrap_form form layout='horizontal' size='medium' %}
17 {% bootstrap_form form layout='horizontal' size='medium' %}
18 <div style="clear: both;"></div>
18 <div style="clear: both;"></div>
19 <h2>ABS Beams</h2><hr>
19 <h2>ABS Beams</h2><hr>
20 <div class="panel-group" id="div_beams" role="tablist" aria-multiselectable="true">
20 <div class="panel-group" id="div_beams" role="tablist" aria-multiselectable="true">
21 {% include "abs_beams_list.html" %}
21 {% include "abs_beams_list.html" %}
22 </div>
22 </div>
23 <div style="clear: both;"></div>
23 <div style="clear: both;"></div>
24 <br>
24 <br>
25 <div class="pull-right">
25 <div class="pull-right">
26 <button type="button" class="btn btn-primary" onclick="{% if previous %}window.location.replace('{{ previous }}');{% else %}history.go(-1);{% endif %}">Cancel</button>
26 <button type="button" class="btn btn-primary" onclick="{% if previous %}window.location.replace('{{ previous }}');{% else %}history.go(-1);{% endif %}">Cancel</button>
27 <button type="button" class="btn btn-primary" id="bt_add_beam">Add Beam</button>
27 <button type="button" class="btn btn-primary" id="bt_add_beam">Add Beam</button>
28 <button type="submit" class="btn btn-primary">{{button}}</button>
28 <button type="submit" class="btn btn-primary">{{button}}</button>
29 </div>
29 </div>
30 </form>
30 </form>
31 {% endblock %}
31 {% endblock %}
32
32
33
33
34 {% block extra-js%}
34 {% block extra-js%}
35 <script src="{% static 'js/abs.js' %}"></script>
35 <script type="text/javascript">
36 <script type="text/javascript">
36
37
37 $("#bt_toggle").click(function() {
38 $("#bt_toggle").click(function() {
38 $(".panel-collapse").collapse('toggle')
39 $(".panel-collapse").collapse('toggle')
39 });
40 });
40
41
41 $("#bt_add_beam").click(function() {
42 $("#bt_add_beam").click(function() {
42 document.location = "{% url 'url_add_abs_beam' id_conf %}";
43 document.location = "{% url 'url_add_abs_beam' id_conf %}";
43 });
44 });
44
45
45 </script>
46 </script>
46 {% endblock %}
47 {% endblock %}
@@ -1,424 +1,424
1 from django.shortcuts import render_to_response
1 from django.shortcuts import render_to_response
2 from django.template import RequestContext
2 from django.template import RequestContext
3 from django.shortcuts import redirect, render, get_object_or_404
3 from django.shortcuts import redirect, render, get_object_or_404
4 from django.contrib import messages
4 from django.contrib import messages
5 from django.conf import settings
5 from django.conf import settings
6 from django.http import HttpResponse
6 from django.http import HttpResponse
7 from django.core.urlresolvers import reverse
7 from django.core.urlresolvers import reverse
8
8
9 from datetime import datetime
9 from datetime import datetime
10 from time import sleep
10 from time import sleep
11 import os
11 import os
12
12
13 from apps.main.models import Device, Configuration
13 from apps.main.models import Device, Configuration
14 from apps.main.views import sidebar
14 from apps.main.views import sidebar
15
15
16 from .models import ABSConfiguration, ABSBeam
16 from .models import ABSConfiguration, ABSBeam
17 from .forms import ABSConfigurationForm, ABSBeamEditForm, ABSBeamAddForm, ABSImportForm
17 from .forms import ABSConfigurationForm, ABSBeamEditForm, ABSBeamAddForm, ABSImportForm
18
18
19 from .utils.overJroShow import overJroShow
19 from .utils.overJroShow import overJroShow
20 from .utils.OverJRO import OverJRO
20 from .utils.OverJRO import OverJRO
21 # Create your views here.
21 # Create your views here.
22 import json, ast
22 import json, ast
23
23
24
24
25 def get_values_from_form(form_data):
25 def get_values_from_form(form_data):
26
26
27 sublistup = []
27 sublistup = []
28 sublistdown = []
28 sublistdown = []
29 subtxlistup = []
29 subtxlistup = []
30 subtxlistdown = []
30 subtxlistdown = []
31 subrxlistup = []
31 subrxlistup = []
32 subrxlistdown = []
32 subrxlistdown = []
33
33
34 up_values_list = []
34 up_values_list = []
35 down_values_list = []
35 down_values_list = []
36 up_txvalues_list = []
36 up_txvalues_list = []
37 down_txvalues_list = []
37 down_txvalues_list = []
38 up_rxvalues_list = []
38 up_rxvalues_list = []
39 down_rxvalues_list = []
39 down_rxvalues_list = []
40
40
41 values_list = {}
41 values_list = {}
42 cont = 1
42 cont = 1
43
43
44 for i in range(1,65):
44 for i in range(1,65):
45 x = float(form_data['abs_up'+str(i)])
45 x = float(form_data['abs_up'+str(i)])
46 y = float(form_data['abs_down'+str(i)])
46 y = float(form_data['abs_down'+str(i)])
47 sublistup.append(x)
47 sublistup.append(x)
48 sublistdown.append(y)
48 sublistdown.append(y)
49
49
50 if str(i) in form_data.getlist('uptx_checks'):
50 if str(i) in form_data.getlist('uptx_checks'):
51 subtxlistup.append(1)
51 subtxlistup.append(1)
52 else:
52 else:
53 subtxlistup.append(0)
53 subtxlistup.append(0)
54 if str(i) in form_data.getlist('downtx_checks'):
54 if str(i) in form_data.getlist('downtx_checks'):
55 subtxlistdown.append(1)
55 subtxlistdown.append(1)
56 else:
56 else:
57 subtxlistdown.append(0)
57 subtxlistdown.append(0)
58
58
59 if str(i) in form_data.getlist('uprx_checks'):
59 if str(i) in form_data.getlist('uprx_checks'):
60 subrxlistup.append(1)
60 subrxlistup.append(1)
61 else:
61 else:
62 subrxlistup.append(0)
62 subrxlistup.append(0)
63 if str(i) in form_data.getlist('downrx_checks'):
63 if str(i) in form_data.getlist('downrx_checks'):
64 subrxlistdown.append(1)
64 subrxlistdown.append(1)
65 else:
65 else:
66 subrxlistdown.append(0)
66 subrxlistdown.append(0)
67
67
68 cont = cont+1
68 cont = cont+1
69
69
70 if cont == 9:
70 if cont == 9:
71 up_values_list.append(sublistup)
71 up_values_list.append(sublistup)
72 down_values_list.append(sublistdown)
72 down_values_list.append(sublistdown)
73 sublistup = []
73 sublistup = []
74 sublistdown = []
74 sublistdown = []
75
75
76 up_txvalues_list.append(subtxlistup)
76 up_txvalues_list.append(subtxlistup)
77 down_txvalues_list.append(subtxlistdown)
77 down_txvalues_list.append(subtxlistdown)
78 subtxlistup = []
78 subtxlistup = []
79 subtxlistdown = []
79 subtxlistdown = []
80 up_rxvalues_list.append(subrxlistup)
80 up_rxvalues_list.append(subrxlistup)
81 down_rxvalues_list.append(subrxlistdown)
81 down_rxvalues_list.append(subrxlistdown)
82 subrxlistup = []
82 subrxlistup = []
83 subrxlistdown = []
83 subrxlistdown = []
84 cont = 1
84 cont = 1
85
85
86
86
87 list_uesup = []
87 list_uesup = []
88 list_uesdown = []
88 list_uesdown = []
89 for i in range(1,5):
89 for i in range(1,5):
90 if form_data['ues_up'+str(i)] == '':
90 if form_data['ues_up'+str(i)] == '':
91 list_uesup.append(0.0)
91 list_uesup.append(0.0)
92 else:
92 else:
93 list_uesup.append(float(form_data['ues_up'+str(i)]))
93 list_uesup.append(float(form_data['ues_up'+str(i)]))
94
94
95 if form_data['ues_down'+str(i)] == '':
95 if form_data['ues_down'+str(i)] == '':
96 list_uesdown.append(0.0)
96 list_uesdown.append(0.0)
97 else:
97 else:
98 list_uesdown.append(float(form_data['ues_down'+str(i)]))
98 list_uesdown.append(float(form_data['ues_down'+str(i)]))
99
99
100 onlyrx_list = form_data.getlist('onlyrx')
100 onlyrx_list = form_data.getlist('onlyrx')
101 only_rx = {}
101 only_rx = {}
102 if '1' in onlyrx_list:
102 if '1' in onlyrx_list:
103 only_rx['up'] = True
103 only_rx['up'] = True
104 else:
104 else:
105 only_rx['up'] = False
105 only_rx['up'] = False
106 if '2' in onlyrx_list:
106 if '2' in onlyrx_list:
107 only_rx['down'] = True
107 only_rx['down'] = True
108 else:
108 else:
109 only_rx['down'] = False
109 only_rx['down'] = False
110
110
111 antenna = {'antenna_up': up_values_list, 'antenna_down': down_values_list}
111 antenna = {'antenna_up': up_values_list, 'antenna_down': down_values_list}
112 tx = {'up': up_txvalues_list, 'down': down_txvalues_list}
112 tx = {'up': up_txvalues_list, 'down': down_txvalues_list}
113 rx = {'up': up_rxvalues_list, 'down': down_rxvalues_list}
113 rx = {'up': up_rxvalues_list, 'down': down_rxvalues_list}
114 ues = {'up': list_uesup, 'down': list_uesdown}
114 ues = {'up': list_uesup, 'down': list_uesdown}
115 name = str(form_data['beam_name'])
115 name = str(form_data['beam_name'])
116
116
117 beam_data = {'name': name, 'antenna': antenna, 'tx': tx, 'rx': rx, 'ues': ues, 'only_rx': only_rx}
117 beam_data = {'name': name, 'antenna': antenna, 'tx': tx, 'rx': rx, 'ues': ues, 'only_rx': only_rx}
118
118
119 return beam_data
119 return beam_data
120
120
121
121
122
122
123 def abs_conf(request, id_conf):
123 def abs_conf(request, id_conf):
124
124
125 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
125 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
126 beams = ABSBeam.objects.filter(abs_conf=conf)
126 beams = ABSBeam.objects.filter(abs_conf=conf)
127 active_beam_id = json.loads(conf.active_beam)
127 active_beam_id = json.loads(conf.active_beam)
128
128
129 #------------Colors for Active Beam:-------------
129 #------------Colors for Active Beam:-------------
130 modules_status = json.loads(conf.module_status)
130 modules_status = json.loads(conf.module_status)
131
131
132 color_status = {}
132 color_status = {}
133 for status in modules_status:
133 for status in modules_status:
134 if modules_status[status] == 2: #Running background-color: #ff0000;
134 if modules_status[status] == 2: #Running background-color: #ff0000;
135 color_status[status] = 'bgcolor=#00cc00'
135 color_status[status] = 'bgcolor=#00cc00'
136 elif modules_status[status] == 1: #Connected background-color: #ee902c;
136 elif modules_status[status] == 1: #Connected background-color: #ee902c;
137 color_status[status] = 'bgcolor=#ee902c'
137 color_status[status] = 'bgcolor=#ee902c'
138 else: #Disconnected background-color: #00cc00;
138 else: #Disconnected background-color: #00cc00;
139 color_status[status] = 'bgcolor=#FF0000'
139 color_status[status] = 'bgcolor=#FF0000'
140 #------------------------------------------------
140 #------------------------------------------------
141
141
142 kwargs = {}
142 kwargs = {}
143 kwargs['status'] = conf.device.get_status_display()
143 kwargs['status'] = conf.device.get_status_display()
144
144
145
145
146 kwargs['dev_conf'] = conf
146 kwargs['dev_conf'] = conf
147 kwargs['dev_conf_keys'] = ['name',]
147 kwargs['dev_conf_keys'] = ['name',]
148
148
149 kwargs['title'] = 'ABS Configuration'
149 kwargs['title'] = 'ABS Configuration'
150 kwargs['suptitle'] = 'Details'
150 kwargs['suptitle'] = 'Details'
151 kwargs['no_play'] = True
151 kwargs['no_play'] = True
152
152
153 kwargs['button'] = 'Edit Configuration'
153 kwargs['button'] = 'Edit Configuration'
154 #------------------Active Beam-----------------------
154 #------------------Active Beam-----------------------
155 try:
155 try:
156 active_beam_id = active_beam_id['active_beam']
156 active_beam_id = active_beam_id['active_beam']
157 active_beam = ABSBeam.objects.get(pk=active_beam_id)
157 active_beam = ABSBeam.objects.get(pk=active_beam_id)
158 kwargs['active_beam'] = active_beam
158 kwargs['active_beam'] = active_beam
159 for beam in beams:
159 for beam in beams:
160 if beam.id == active_beam.id:
160 if beam.id == active_beam.id:
161 beam.color_status=color_status
161 beam.color_status=color_status
162 except:
162 except:
163 active_beam = ''
163 active_beam = ''
164 #----------------------------------------------------
164 #----------------------------------------------------
165 kwargs['beams'] = beams
165 kwargs['beams'] = beams
166 kwargs['modules_status'] = modules_status
166 kwargs['modules_status'] = modules_status
167 kwargs['color_status'] = color_status
167 kwargs['color_status'] = color_status
168
168
169 kwargs['only_stop'] = True
169 kwargs['only_stop'] = True
170
170
171 ###### SIDEBAR ######
171 ###### SIDEBAR ######
172 kwargs.update(sidebar(conf=conf))
172 kwargs.update(sidebar(conf=conf))
173
173
174 return render(request, 'abs_conf.html', kwargs)
174 return render(request, 'abs_conf.html', kwargs)
175
175
176 def abs_conf_edit(request, id_conf):
176 def abs_conf_edit(request, id_conf):
177
177
178 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
178 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
179
179
180 beams = ABSBeam.objects.filter(abs_conf=conf)
180 beams = ABSBeam.objects.filter(abs_conf=conf)
181 print beams
181 print beams
182
182
183 if request.method=='GET':
183 if request.method=='GET':
184 form = ABSConfigurationForm(instance=conf)
184 form = ABSConfigurationForm(instance=conf)
185
185
186 if request.method=='POST':
186 if request.method=='POST':
187 form = ABSConfigurationForm(request.POST, instance=conf)
187 form = ABSConfigurationForm(request.POST, instance=conf)
188
188
189 if form.is_valid():
189 if form.is_valid():
190 conf = form.save(commit=False)
190 conf = form.save(commit=False)
191 conf.save()
191 conf.save()
192 return redirect('url_abs_conf', id_conf=conf.id)
192 return redirect('url_abs_conf', id_conf=conf.id)
193
193
194 ###### SIDEBAR ######
194 ###### SIDEBAR ######
195 kwargs = {}
195 kwargs = {}
196
196
197 kwargs['dev_conf'] = conf
197 kwargs['dev_conf'] = conf
198 #kwargs['id_dev'] = conf.id
198 #kwargs['id_dev'] = conf.id
199 kwargs['id_conf'] = conf.id
199 kwargs['id_conf'] = conf.id
200 kwargs['form'] = form
200 kwargs['form'] = form
201 kwargs['abs_beams'] = beams
201 kwargs['abs_beams'] = beams
202 kwargs['title'] = 'Device Configuration'
202 kwargs['title'] = 'Device Configuration'
203 kwargs['suptitle'] = 'Edit'
203 kwargs['suptitle'] = 'Edit'
204 kwargs['button'] = 'Save'
204 kwargs['button'] = 'Save'
205
205
206 kwargs['edit'] = True
206 kwargs['edit'] = True
207
207
208 return render(request, 'abs_conf_edit.html', kwargs)
208 return render(request, 'abs_conf_edit.html', kwargs)
209
209
210
210
211 def import_file(request, id_conf):
211 def import_file(request, id_conf):
212
212
213 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
213 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
214 if request.method=='POST':
214 if request.method=='POST':
215 form = ABSImportForm(request.POST, request.FILES)
215 form = ABSImportForm(request.POST, request.FILES)
216 if form.is_valid():
216 if form.is_valid():
217 try:
217 try:
218 parms = conf.import_from_file(request.FILES['file_name'])
218 parms = conf.import_from_file(request.FILES['file_name'])
219
219
220 if parms:
220 if parms:
221 conf.update_from_file(parms)
221 conf.update_from_file(parms)
222 messages.success(request, 'Configuration "%s" loaded succesfully' % request.FILES['file_name'])
222 messages.success(request, 'Configuration "%s" loaded succesfully' % request.FILES['file_name'])
223 return redirect(conf.get_absolute_url_edit())
223 return redirect(conf.get_absolute_url_edit())
224
224
225 except Exception as e:
225 except Exception as e:
226 messages.error(request, 'Error parsing file: "%s" - %s' % (request.FILES['file_name'], e))
226 messages.error(request, 'Error parsing file: "%s" - %s' % (request.FILES['file_name'], e))
227
227
228 else:
228 else:
229 messages.warning(request, 'Your current configuration will be replaced')
229 messages.warning(request, 'Your current configuration will be replaced')
230 form = ABSImportForm()
230 form = ABSImportForm()
231
231
232 kwargs = {}
232 kwargs = {}
233 kwargs['form'] = form
233 kwargs['form'] = form
234 kwargs['title'] = 'ABS Configuration'
234 kwargs['title'] = 'ABS Configuration'
235 kwargs['suptitle'] = 'Import file'
235 kwargs['suptitle'] = 'Import file'
236 kwargs['button'] = 'Upload'
236 kwargs['button'] = 'Upload'
237 kwargs['previous'] = conf.get_absolute_url()
237 kwargs['previous'] = conf.get_absolute_url()
238
238
239 return render(request, 'abs_import.html', kwargs)
239 return render(request, 'abs_import.html', kwargs)
240
240
241
241
242 def send_beam(request, id_conf, id_beam):
242 def send_beam(request, id_conf, id_beam):
243
243
244 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
244 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
245 beam = get_object_or_404(ABSBeam, pk=id_beam)
245 beam = get_object_or_404(ABSBeam, pk=id_beam)
246 beams_list = ABSBeam.objects.filter(abs_conf=conf)
246 beams_list = ABSBeam.objects.filter(abs_conf=conf)
247 #To set this beam as an Active Beam
247 #To set this beam as an Active Beam
248 beam.set_activebeam()
248 beam.set_as_activebeam()
249 #To send beam position to abs-modules
249 #To send beam position to abs-modules
250 i = 0
250 i = 0
251 for b in beams_list:
251 for b in beams_list:
252 if b.id == int(id_beam):
252 if b.id == int(id_beam):
253 break
253 break
254 else:
254 else:
255 i += 1
255 i += 1
256 beam_pos = i + 1 #Estandarizar
256 beam_pos = i + 1 #Estandarizar
257 print 'Position: ',beam_pos
257 print 'Position: ',beam_pos
258 conf.send_beam_num(beam_pos)
258 conf.send_beam_num(beam_pos)
259
259
260 return redirect('url_abs_conf', conf.id)
260 return redirect('url_abs_conf', conf.id)
261
261
262
262
263 def add_beam(request, id_conf):
263 def add_beam(request, id_conf):
264
264
265 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
265 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
266 confs = Configuration.objects.all()
266 confs = Configuration.objects.all()
267
267
268 if request.method=='GET':
268 if request.method=='GET':
269 #form = ABSBeamEditForm()
269 #form = ABSBeamEditForm()
270 form = ABSBeamAddForm()
270 form = ABSBeamAddForm()
271
271
272 if request.method=='POST':
272 if request.method=='POST':
273 form = ABSBeamAddForm(request.POST)
273 form = ABSBeamAddForm(request.POST)
274
274
275 beam_data = get_values_from_form(request.POST)
275 beam_data = get_values_from_form(request.POST)
276
276
277 new_beam = ABSBeam(
277 new_beam = ABSBeam(
278 name =beam_data['name'],
278 name =beam_data['name'],
279 antenna =json.dumps(beam_data['antenna']),
279 antenna =json.dumps(beam_data['antenna']),
280 abs_conf=conf,
280 abs_conf=conf,
281 tx =json.dumps(beam_data['tx']),
281 tx =json.dumps(beam_data['tx']),
282 rx =json.dumps(beam_data['rx']),
282 rx =json.dumps(beam_data['rx']),
283 ues =json.dumps(beam_data['ues']),
283 ues =json.dumps(beam_data['ues']),
284 only_rx =json.dumps(beam_data['only_rx'])
284 only_rx =json.dumps(beam_data['only_rx'])
285 )
285 )
286 new_beam.save()
286 new_beam.save()
287 #---Update 6bits configuration and add beam to abs configuration beams list.
287 #---Update 6bits configuration and add beam to abs configuration beams list.
288 new_beam.modules_6bits()
288 new_beam.modules_6bits()
289 #new_beam.add_beam2list()
289 #new_beam.add_beam2list()
290 messages.success(request, 'Beam: "%s" has been added.' % new_beam.name)
290 messages.success(request, 'Beam: "%s" has been added.' % new_beam.name)
291
291
292 return redirect('url_edit_abs_conf', conf.id)
292 return redirect('url_edit_abs_conf', conf.id)
293
293
294 ###### SIDEBAR ######
294 ###### SIDEBAR ######
295 kwargs = {}
295 kwargs = {}
296
296
297 #kwargs['dev_conf'] = conf.device
297 #kwargs['dev_conf'] = conf.device
298 #kwargs['id_dev'] = conf.device
298 #kwargs['id_dev'] = conf.device
299 kwargs['id_conf'] = conf.id
299 kwargs['id_conf'] = conf.id
300 kwargs['form'] = form
300 kwargs['form'] = form
301 kwargs['title'] = 'ABS Beams'
301 kwargs['title'] = 'ABS Beams'
302 kwargs['suptitle'] = 'Add Beam'
302 kwargs['suptitle'] = 'Add Beam'
303 kwargs['button'] = 'Add'
303 kwargs['button'] = 'Add'
304 kwargs['no_sidebar'] = True
304 kwargs['no_sidebar'] = True
305
305
306 #kwargs['previous'] = conf.get_absolute_url_edit()
306 #kwargs['previous'] = conf.get_absolute_url_edit()
307 kwargs['edit'] = True
307 kwargs['edit'] = True
308
308
309 return render(request, 'abs_add_beam.html', kwargs)
309 return render(request, 'abs_add_beam.html', kwargs)
310
310
311
311
312 def edit_beam(request, id_conf, id_beam):
312 def edit_beam(request, id_conf, id_beam):
313
313
314 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
314 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
315 beam = get_object_or_404(ABSBeam, pk=id_beam)
315 beam = get_object_or_404(ABSBeam, pk=id_beam)
316
316
317 if request.method=='GET':
317 if request.method=='GET':
318 form = ABSBeamEditForm(initial={'beam': beam})
318 form = ABSBeamEditForm(initial={'beam': beam})
319
319
320 if request.method=='POST':
320 if request.method=='POST':
321 form = ABSBeamEditForm(request.POST)
321 form = ABSBeamEditForm(request.POST)
322
322
323 beam_data = get_values_from_form(request.POST)
323 beam_data = get_values_from_form(request.POST)
324
324
325 beam.dict_to_parms(beam_data)
325 beam.dict_to_parms(beam_data)
326 beam.save()
326 beam.save()
327
327
328 messages.success(request, 'Beam: "%s" has been updated.' % beam.name)
328 messages.success(request, 'Beam: "%s" has been updated.' % beam.name)
329
329
330 return redirect('url_edit_abs_conf', conf.id)
330 return redirect('url_edit_abs_conf', conf.id)
331
331
332 ###### SIDEBAR ######
332 ###### SIDEBAR ######
333 kwargs = {}
333 kwargs = {}
334
334
335 kwargs['id_conf'] = conf.id
335 kwargs['id_conf'] = conf.id
336 kwargs['form'] = form
336 kwargs['form'] = form
337 kwargs['title'] = 'ABS Beams'
337 kwargs['title'] = 'ABS Beams'
338 kwargs['suptitle'] = 'Edit Beam'
338 kwargs['suptitle'] = 'Edit Beam'
339 kwargs['button'] = 'Save'
339 kwargs['button'] = 'Save'
340 kwargs['no_sidebar'] = True
340 kwargs['no_sidebar'] = True
341
341
342 #kwargs['previous'] = conf.get_absolute_url_edit()
342 #kwargs['previous'] = conf.get_absolute_url_edit()
343 kwargs['edit'] = True
343 kwargs['edit'] = True
344
344
345 return render(request, 'abs_edit_beam.html', kwargs)
345 return render(request, 'abs_edit_beam.html', kwargs)
346
346
347
347
348
348
349 def remove_beam(request, id_conf, id_beam):
349 def remove_beam(request, id_conf, id_beam):
350
350
351 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
351 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
352 beam = get_object_or_404(ABSBeam, pk=id_beam)
352 beam = get_object_or_404(ABSBeam, pk=id_beam)
353
353
354 if request.method=='POST':
354 if request.method=='POST':
355 if beam:
355 if beam:
356 try:
356 try:
357 beam.remove_beamfromlist()
357 beam.remove_beamfromlist()
358 beam.delete()
358 beam.delete()
359 messages.success(request, 'Beam: "%s" has been deleted.' % beam)
359 messages.success(request, 'Beam: "%s" has been deleted.' % beam)
360 except:
360 except:
361 messages.error(request, 'Unable to delete beam: "%s".' % beam)
361 messages.error(request, 'Unable to delete beam: "%s".' % beam)
362
362
363 return redirect('url_edit_abs_conf', conf.id)
363 return redirect('url_edit_abs_conf', conf.id)
364
364
365 ###### SIDEBAR ######
365 ###### SIDEBAR ######
366 kwargs = {}
366 kwargs = {}
367
367
368 kwargs['object'] = beam
368 kwargs['object'] = beam
369 kwargs['delete'] = True
369 kwargs['delete'] = True
370 kwargs['title'] = 'Delete'
370 kwargs['title'] = 'Delete'
371 kwargs['suptitle'] = 'Beam'
371 kwargs['suptitle'] = 'Beam'
372 kwargs['previous'] = conf.get_absolute_url_edit()
372 kwargs['previous'] = conf.get_absolute_url_edit()
373 return render(request, 'confirm.html', kwargs)
373 return render(request, 'confirm.html', kwargs)
374
374
375
375
376
376
377 def plot_patterns(request, id_conf, id_beam=None):
377 def plot_patterns(request, id_conf, id_beam=None):
378
378
379 kwargs = {}
379 kwargs = {}
380 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
380 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
381 beams = ABSBeam.objects.filter(abs_conf=conf)
381 beams = ABSBeam.objects.filter(abs_conf=conf)
382
382
383 if id_beam:
383 if id_beam:
384 beam = get_object_or_404(ABSBeam, pk=id_beam)
384 beam = get_object_or_404(ABSBeam, pk=id_beam)
385 kwargs['beam'] = beam
385 kwargs['beam'] = beam
386
386
387
387
388 ###### SIDEBAR ######
388 ###### SIDEBAR ######
389
389
390 kwargs['dev_conf'] = conf.device
390 kwargs['dev_conf'] = conf.device
391 kwargs['id_dev'] = conf.device
391 kwargs['id_dev'] = conf.device
392 kwargs['id_conf'] = conf.id
392 kwargs['id_conf'] = conf.id
393 kwargs['abs_beams'] = beams
393 kwargs['abs_beams'] = beams
394 kwargs['title'] = 'ABS Patterns'
394 kwargs['title'] = 'ABS Patterns'
395 kwargs['suptitle'] = conf.name
395 kwargs['suptitle'] = conf.name
396 kwargs['no_sidebar'] = True
396 kwargs['no_sidebar'] = True
397
397
398 return render(request, 'abs_patterns.html', kwargs)
398 return render(request, 'abs_patterns.html', kwargs)
399
399
400
400
401 def plot_pattern(request, id_conf, id_beam, antenna):
401 def plot_pattern(request, id_conf, id_beam, antenna):
402
402
403 if antenna=='down':
403 if antenna=='down':
404 sleep(3)
404 sleep(3)
405
405
406 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
406 conf = get_object_or_404(ABSConfiguration, pk=id_conf)
407 beam = get_object_or_404(ABSBeam, pk=id_beam)
407 beam = get_object_or_404(ABSBeam, pk=id_beam)
408
408
409 name = conf.experiment.name
409 name = conf.experiment.name
410
410
411 just_rx = 1 if json.loads(beam.only_rx)[antenna] else 0
411 just_rx = 1 if json.loads(beam.only_rx)[antenna] else 0
412 phases = json.loads(beam.antenna)['antenna_{}'.format(antenna)]
412 phases = json.loads(beam.antenna)['antenna_{}'.format(antenna)]
413 gain_tx = json.loads(beam.tx)[antenna]
413 gain_tx = json.loads(beam.tx)[antenna]
414 gain_rx = json.loads(beam.rx)[antenna]
414 gain_rx = json.loads(beam.rx)[antenna]
415 ues = json.loads(beam.ues)[antenna]
415 ues = json.loads(beam.ues)[antenna]
416
416
417 newOverJro = overJroShow(name)
417 newOverJro = overJroShow(name)
418 fig = newOverJro.plotPattern2(datetime.today(), phases, gain_tx, gain_rx, ues, just_rx)
418 fig = newOverJro.plotPattern2(datetime.today(), phases, gain_tx, gain_rx, ues, just_rx)
419
419
420 response=HttpResponse(content_type='image/png')
420 response=HttpResponse(content_type='image/png')
421
421
422 fig.canvas.print_png(response)
422 fig.canvas.print_png(response)
423
423
424 return response
424 return response
General Comments 0
You need to be logged in to leave comments. Login now