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