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