@@ -0,0 +1,39 | |||
|
1 | import os | |
|
2 | import paho.mqtt.client as mqtt | |
|
3 | from radarsys import settings | |
|
4 | from radarsys.socketconfig import sio as sio | |
|
5 | ||
|
6 | lista_ack=[ | |
|
7 | chr( 33 ), chr( 34 ), chr( 35 ), chr( 36 ), chr( 37 ), chr( 38 ), chr( 39 ), chr( 40 ), chr( 41 ), chr( 42 ), chr( 43 ), chr( 44 ), chr( 45 ), chr( 46 ), chr( 47 ), chr( 48 ), chr( 49 ), chr( 50 ), chr( 51 ), chr( 52 ), chr( 53 ), chr( 54 ), chr( 55 ), chr( 56 ), chr( 57 ), chr( 58 ), chr( 59 ), chr( 60 ), chr( 61 ), chr( 62 ), chr( 63 ), chr( 64 ), chr( 65 ), chr( 66 ), chr( 67 ), chr( 68 ), chr( 69 ), chr( 70 ), chr( 71 ), chr( 72 ), chr( 73 ), chr( 74 ), chr( 75 ), chr( 76 ), chr( 77 ), chr( 78 ), chr( 79 ), chr( 80 ), chr( 81 ), chr( 82 ), chr( 83 ), chr( 84 ), chr( 85 ), chr( 86 ), chr( 87 ), chr( 88 ), chr( 89 ), chr( 90 ), chr( 91 ), chr( 92 ), chr( 93 ), chr( 94 ), chr( 95 ), chr( 96 ) | |
|
8 | ] | |
|
9 | ||
|
10 | lista_ack_dismatching=[ | |
|
11 | chr( 97 ), chr( 98 ), chr( 99 ), chr( 100 ), chr( 101 ), chr( 102 ), chr( 103 ), chr( 104 ), chr( 105 ), chr( 106 ), chr( 107 ), chr( 108 ), chr( 109 ), chr( 110 ), chr( 111 ), chr( 112 ), chr( 113 ), chr( 114 ), chr( 115 ), chr( 116 ), chr( 117 ), chr( 118 ), chr( 119 ), chr( 120 ), chr( 121 ), chr( 122 ), chr( 123 ), chr( 124 ), chr( 125 ), chr( 126 ), chr( 127 ), chr( 128 ), chr( 129 ), chr( 130 ), chr( 131 ), chr( 132 ), chr( 133 ), chr( 134 ), chr( 135 ), chr( 136 ), chr( 137 ), chr( 138 ), chr( 139 ), chr( 140 ), chr( 141 ), chr( 142 ), chr( 143 ), chr( 144 ), chr( 145 ), chr( 146 ), chr( 147 ), chr( 148 ), chr( 149 ), chr( 150 ), chr( 151 ), chr( 152 ), chr( 153 ), chr( 154 ), chr( 155 ), chr( 156 ), chr( 157 ), chr( 158 ), chr( 159 ), chr(160) | |
|
12 | ] | |
|
13 | ||
|
14 | def on_connect(mqtt_client, userdata, flags, rc): | |
|
15 | if rc == 0: | |
|
16 | print('Connected successfully') | |
|
17 | mqtt_client.subscribe(os.environ.get('TOPIC_ABS_ACK','abs/beams_ack')) | |
|
18 | else: | |
|
19 | print('Bad connection. Code:', rc) | |
|
20 | ||
|
21 | def on_message(mqtt_client, userdata, msg): | |
|
22 | # print(f'Received message on topic: {msg.topic} with payload: {msg.payload}', flush=True) | |
|
23 | # message= str(msg.payload) | |
|
24 | # sio.emit('abs_ws',data={'msg':message}) | |
|
25 | #message=str(msg.payload) | |
|
26 | #lista_ack.pop(message) | |
|
27 | print("Mientras" ,flush=True) | |
|
28 | ||
|
29 | ||
|
30 | ||
|
31 | client = mqtt.Client() | |
|
32 | client.on_connect = on_connect | |
|
33 | client.on_message = on_message | |
|
34 | client.username_pw_set(os.environ.get('MQTT_USER', 'abs'), os.environ.get('MQTT_PASSWORD', 'abs')) | |
|
35 | client.connect( | |
|
36 | host=os.environ.get('MQTT_SERVER', '10.10.10.200'), | |
|
37 | port=int(settings.os.environ.get('MQTT_PORT', 1883)), | |
|
38 | keepalive=int(os.environ.get('MQTT_KEEPALIVE', 36000)) | |
|
39 | ) No newline at end of file |
@@ -1,19 +1,32 | |||
|
1 | 1 | |
|
2 | 2 | REDIS_HOST=radarsys-redis |
|
3 | 3 | REDIS_PORT=6300 |
|
4 | 4 | POSTGRES_PORT_5432_TCP_ADDR=radarsys-postgres |
|
5 | 5 | POSTGRES_PORT_5432_TCP_PORT=5432 |
|
6 | 6 | #POSTGRES_HOST=postgres |
|
7 | 7 | POSTGRES_HOST=localhost |
|
8 | 8 | POSTGRES_USER=docker |
|
9 | 9 | POSTGRES_PASSWORD=docker |
|
10 | 10 | POSTGRES_DB=radarsys |
|
11 | 11 | |
|
12 | 12 | # DB_NAME=radarsys |
|
13 | 13 | # DB_USER=docker |
|
14 | 14 | # DB_PASSWORD=docker |
|
15 | 15 | PGDATA=/var/lib/postgresql/data |
|
16 | 16 | LC_ALL=C.UTF-8 |
|
17 | 17 | TZ=America/Lima |
|
18 | 18 | DOCKER_DATA=/data/dockers/radarsys/ |
|
19 | 19 | LOCAL_IP=192.168.1.128 |
|
20 | ||
|
21 | MQTT_SERVER=10.10.10.102 | |
|
22 | #MQTT_SERVER = 0.0.0.0 | |
|
23 | MQTT_PORT = 1883 | |
|
24 | MQTT_KEEPALIVE = 3660 | |
|
25 | ||
|
26 | MQTT_USER_ATRAD=atrad | |
|
27 | MQTT_PASSWORD_ATRAD = atrad | |
|
28 | MQTT_USER = abs | |
|
29 | MQTT_PASSWORD = abs | |
|
30 | MQTT_CLIENT_ID= abs_id | |
|
31 | TOPIC_ABS=abs/beams | |
|
32 | TOPIC_ABS_ACK=abs/beams_ack |
@@ -1,1013 +1,1038 | |||
|
1 | 1 | from django.db import models |
|
2 | 2 | from apps.main.models import Configuration , User |
|
3 | 3 | from django.urls import reverse |
|
4 | 4 | from celery.execute import send_task |
|
5 | 5 | from datetime import datetime |
|
6 | 6 | import ast |
|
7 | 7 | import socket |
|
8 | 8 | import json |
|
9 | 9 | import requests |
|
10 | 10 | import struct |
|
11 | 11 | import os, sys, time |
|
12 | 12 | |
|
13 | from .mqtt import client as mqtt_client | |
|
14 | from radarsys.socketconfig import sio as sio | |
|
15 | import json | |
|
16 | ||
|
13 | 17 | antenna_default = json.dumps({ |
|
14 | 18 | "antenna_up": [[0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
15 | 19 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
16 | 20 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
17 | 21 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
18 | 22 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0], |
|
19 | 23 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0], |
|
20 | 24 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0], |
|
21 | 25 | [0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0] |
|
22 | 26 | ] |
|
23 | 27 | , |
|
24 | 28 | "antenna_down": [[0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
25 | 29 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
26 | 30 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
27 | 31 | [0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5], |
|
28 | 32 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0], |
|
29 | 33 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0], |
|
30 | 34 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0], |
|
31 | 35 | [0.5,0.5,0.5,0.5,3.0,3.0,3.0,3.0]], |
|
32 | 36 | }) |
|
33 | 37 | |
|
34 | 38 | |
|
35 | 39 | tx_default = json.dumps({ |
|
36 | 40 | "up": [[1,1,1,1,0,0,0,0], |
|
37 | 41 | [1,1,1,1,0,0,0,0], |
|
38 | 42 | [1,1,1,1,0,0,0,0], |
|
39 | 43 | [1,1,1,1,0,0,0,0], |
|
40 | 44 | [0,0,0,0,1,1,1,1], |
|
41 | 45 | [0,0,0,0,1,1,1,1], |
|
42 | 46 | [0,0,0,0,1,1,1,1], |
|
43 | 47 | [0,0,0,0,1,1,1,1]], |
|
44 | 48 | |
|
45 | 49 | "down": [[1,1,1,1,0,0,0,0], |
|
46 | 50 | [1,1,1,1,0,0,0,0], |
|
47 | 51 | [1,1,1,1,0,0,0,0], |
|
48 | 52 | [1,1,1,1,0,0,0,0], |
|
49 | 53 | [0,0,0,0,1,1,1,1], |
|
50 | 54 | [0,0,0,0,1,1,1,1], |
|
51 | 55 | [0,0,0,0,1,1,1,1], |
|
52 | 56 | [0,0,0,0,1,1,1,1]], |
|
53 | 57 | }) |
|
54 | 58 | |
|
55 | 59 | rx_default = json.dumps({ |
|
56 | 60 | "up": [[1,1,1,1,0,0,0,0], |
|
57 | 61 | [1,1,1,1,0,0,0,0], |
|
58 | 62 | [1,1,1,1,0,0,0,0], |
|
59 | 63 | [1,1,1,1,0,0,0,0], |
|
60 | 64 | [0,0,0,0,1,1,1,1], |
|
61 | 65 | [0,0,0,0,1,1,1,1], |
|
62 | 66 | [0,0,0,0,1,1,1,1], |
|
63 | 67 | [0,0,0,0,1,1,1,1]], |
|
64 | 68 | |
|
65 | 69 | "down": [[1,1,1,1,0,0,0,0], |
|
66 | 70 | [1,1,1,1,0,0,0,0], |
|
67 | 71 | [1,1,1,1,0,0,0,0], |
|
68 | 72 | [1,1,1,1,0,0,0,0], |
|
69 | 73 | [0,0,0,0,1,1,1,1], |
|
70 | 74 | [0,0,0,0,1,1,1,1], |
|
71 | 75 | [0,0,0,0,1,1,1,1], |
|
72 | 76 | [0,0,0,0,1,1,1,1]], |
|
73 | 77 | }) |
|
74 | 78 | |
|
75 | 79 | status_default = '0000000000000000000000000000000000000000000000000000000000000000' |
|
76 | 80 | default_messages = {} |
|
77 | 81 | |
|
78 | 82 | for i in range(1,65): |
|
79 | 83 | default_messages[str(i)] = "Module "+str(i) |
|
80 | 84 | |
|
81 | 85 | |
|
82 | 86 | ues_default = json.dumps({ |
|
83 | 87 | "up": [0.533333,0.00000,1.06667,0.00000], |
|
84 | 88 | "down": [0.533333,0.00000,1.06667,0.00000] |
|
85 | 89 | }) |
|
86 | 90 | |
|
87 | 91 | onlyrx_default = json.dumps({ |
|
88 | 92 | "up": False, |
|
89 | 93 | "down": False |
|
90 | 94 | }) |
|
91 | 95 | |
|
92 | 96 | def up_convertion(cadena): |
|
93 | 97 | valores = [] |
|
94 | 98 | for c in cadena: |
|
95 | 99 | if c == 1.0: valores=valores+['000'] |
|
96 | 100 | if c == 2.0: valores=valores+['001'] |
|
97 | 101 | if c == 3.0: valores=valores+['010'] |
|
98 | 102 | if c == 0.0: valores=valores+['011'] |
|
99 | 103 | if c == 0.5: valores=valores+['100'] |
|
100 | 104 | if c == 1.5: valores=valores+['101'] |
|
101 | 105 | if c == 2.5: valores=valores+['110'] |
|
102 | 106 | if c == 3.5: valores=valores+['111'] |
|
103 | 107 | |
|
104 | 108 | return valores |
|
105 | 109 | |
|
106 | 110 | def up_conv_bits(value): |
|
107 | 111 | |
|
108 | 112 | if value == 1.0: bits="000" |
|
109 | 113 | if value == 2.0: bits="001" |
|
110 | 114 | if value == 3.0: bits="010" |
|
111 | 115 | if value == 0.0: bits="011" |
|
112 | 116 | if value == 0.5: bits="100" |
|
113 | 117 | if value == 1.5: bits="101" |
|
114 | 118 | if value == 2.5: bits="110" |
|
115 | 119 | if value == 3.5: bits="111" |
|
116 | 120 | |
|
117 | 121 | return bits |
|
118 | 122 | |
|
119 | 123 | def down_convertion(cadena): |
|
120 | 124 | valores = [] |
|
121 | 125 | for c in cadena: |
|
122 | 126 | if c == 1.0: valores=valores+['000'] |
|
123 | 127 | if c == 2.0: valores=valores+['001'] |
|
124 | 128 | if c == 3.0: valores=valores+['010'] |
|
125 | 129 | if c == 0.0: valores=valores+['011'] |
|
126 | 130 | if c == 0.5: valores=valores+['100'] |
|
127 | 131 | if c == 1.5: valores=valores+['101'] |
|
128 | 132 | if c == 2.5: valores=valores+['110'] |
|
129 | 133 | if c == 3.5: valores=valores+['111'] |
|
130 | 134 | |
|
131 | 135 | return valores |
|
132 | 136 | |
|
133 | 137 | def down_conv_bits(value): |
|
134 | 138 | |
|
135 | 139 | if value == 1.0: bits="000" |
|
136 | 140 | if value == 2.0: bits="001" |
|
137 | 141 | if value == 3.0: bits="010" |
|
138 | 142 | if value == 0.0: bits="011" |
|
139 | 143 | if value == 0.5: bits="100" |
|
140 | 144 | if value == 1.5: bits="101" |
|
141 | 145 | if value == 2.5: bits="110" |
|
142 | 146 | if value == 3.5: bits="111" |
|
143 | 147 | |
|
144 | 148 | return bits |
|
145 | 149 | |
|
146 | 150 | def up_conv_value(bits): |
|
147 | 151 | |
|
148 | 152 | if bits == "000": value=1.0 |
|
149 | 153 | if bits == "001": value=2.0 |
|
150 | 154 | if bits == "010": value=3.0 |
|
151 | 155 | if bits == "011": value=0.0 |
|
152 | 156 | if bits == "100": value=0.5 |
|
153 | 157 | if bits == "101": value=1.5 |
|
154 | 158 | if bits == "110": value=2.5 |
|
155 | 159 | if bits == "111": value=3.5 |
|
156 | 160 | |
|
157 | 161 | return value |
|
158 | 162 | |
|
159 | 163 | def down_conv_value(bits): |
|
160 | 164 | |
|
161 | 165 | if bits == "000": value=1.0 |
|
162 | 166 | if bits == "001": value=2.0 |
|
163 | 167 | if bits == "010": value=3.0 |
|
164 | 168 | if bits == "011": value=0.0 |
|
165 | 169 | if bits == "100": value=0.5 |
|
166 | 170 | if bits == "101": value=1.5 |
|
167 | 171 | if bits == "110": value=2.5 |
|
168 | 172 | if bits == "111": value=3.5 |
|
169 | 173 | |
|
170 | 174 | return value |
|
171 | 175 | |
|
172 | 176 | def ip2position(module_number): |
|
173 | 177 | j=0 |
|
174 | 178 | i=0 |
|
175 | 179 | for x in range(0,module_number-1): |
|
176 | 180 | j=j+1 |
|
177 | 181 | if j==8: |
|
178 | 182 | i=i+1 |
|
179 | 183 | j=0 |
|
180 | 184 | |
|
181 | 185 | pos = [i,j] |
|
182 | 186 | return pos |
|
183 | 187 | |
|
184 | 188 | |
|
185 | 189 | def fromBinary2Char(binary_string): |
|
186 | 190 | number = int(binary_string, 2) |
|
187 | 191 | #Plus 33 to avoid more than 1 characters values such as: '\x01'-'\x1f' |
|
188 | 192 | number = number + 33 |
|
189 | 193 | char = chr(number) |
|
190 | 194 | return char |
|
191 | 195 | |
|
192 | 196 | def fromChar2Binary(char): |
|
193 | 197 | number = ord(char) - 33 |
|
194 | 198 | #Minus 33 to get the real value |
|
195 | 199 | bits = bin(number)[2:] |
|
196 | 200 | #To ensure we have a string with 6bits |
|
197 | 201 | if len(bits) < 6: |
|
198 | 202 | bits = bits.zfill(6) |
|
199 | 203 | return bits |
|
200 | 204 | |
|
201 | 205 | OPERATION_MODES = ( |
|
202 | 206 | (0, 'Manual'), |
|
203 | 207 | (1, 'Automatic'), |
|
204 | 208 | ) |
|
205 | 209 | |
|
206 | 210 | class ABSConfiguration(Configuration): |
|
207 | 211 | active_beam = models.PositiveSmallIntegerField(verbose_name='Active Beam', default=0) |
|
208 | 212 | module_status = models.CharField(verbose_name='Module Status', max_length=10000, default=status_default) |
|
209 | 213 | operation_mode = models.PositiveSmallIntegerField(verbose_name='Operation Mode', choices=OPERATION_MODES, default = 0) |
|
210 | 214 | operation_value = models.FloatField(verbose_name='Periodic (seconds)', default="10", null=True, blank=True) |
|
211 | 215 | module_messages = models.CharField(verbose_name='Modules Messages', max_length=10000, default=json.dumps(default_messages)) |
|
212 | 216 | |
|
213 | 217 | class Meta: |
|
214 | 218 | db_table = 'abs_configurations' |
|
215 | 219 | |
|
216 | 220 | def get_absolute_url_plot(self): |
|
217 | 221 | return reverse('url_plot_abs_patterns', args=[str(self.id)]) |
|
218 | 222 | |
|
219 | 223 | |
|
220 | 224 | def parms_to_dict(self): |
|
221 | 225 | |
|
222 | 226 | parameters = {} |
|
223 | 227 | |
|
224 | 228 | parameters['device_id'] = self.device.id |
|
225 | 229 | parameters['label'] = self.label |
|
226 | 230 | parameters['device_type'] = self.device.device_type.name |
|
227 | 231 | parameters['beams'] = {} |
|
228 | 232 | |
|
229 | 233 | beams = ABSBeam.objects.filter(abs_conf=self) |
|
230 | 234 | b=1 |
|
231 | 235 | for beam in beams: |
|
232 | 236 | #absbeam = ABSBeam.objects.get(pk=beams[beam]) |
|
233 | 237 | parameters['beams']['beam'+str(b)] = beam.parms_to_dict()#absbeam.parms_to_dict() |
|
234 | 238 | b+=1 |
|
235 | 239 | |
|
236 | 240 | return parameters |
|
237 | 241 | |
|
238 | 242 | |
|
239 | 243 | def dict_to_parms(self, parameters): |
|
240 | 244 | |
|
241 | 245 | self.label = parameters['label'] |
|
242 | 246 | |
|
243 | 247 | absbeams = ABSBeam.objects.filter(abs_conf=self) |
|
244 | 248 | beams = parameters['beams'] |
|
245 | 249 | |
|
246 | 250 | if absbeams: |
|
247 | 251 | beams_number = len(beams) |
|
248 | 252 | absbeams_number = len(absbeams) |
|
249 | 253 | if beams_number==absbeams_number: |
|
250 | 254 | i = 1 |
|
251 | 255 | for absbeam in absbeams: |
|
252 | 256 | absbeam.dict_to_parms(beams['beam'+str(i)]) |
|
253 | 257 | i = i+1 |
|
254 | 258 | elif beams_number > absbeams_number: |
|
255 | 259 | i = 1 |
|
256 | 260 | for absbeam in absbeams: |
|
257 | 261 | absbeam.dict_to_parms(beams['beam'+str(i)]) |
|
258 | 262 | i=i+1 |
|
259 | 263 | for x in range(i,beams_number+1): |
|
260 | 264 | new_beam = ABSBeam( |
|
261 | 265 | name =beams['beam'+str(i)]['name'], |
|
262 | 266 | antenna =json.dumps(beams['beam'+str(i)]['antenna']), |
|
263 | 267 | abs_conf = self, |
|
264 | 268 | tx =json.dumps(beams['beam'+str(i)]['tx']), |
|
265 | 269 | rx =json.dumps(beams['beam'+str(i)]['rx']), |
|
266 | 270 | ues =json.dumps(beams['beam'+str(i)]['ues']), |
|
267 | 271 | only_rx =json.dumps(beams['beam'+str(i)]['only_rx']) |
|
268 | 272 | ) |
|
269 | 273 | new_beam.save() |
|
270 | 274 | i=i+1 |
|
271 | 275 | else: #beams_number < absbeams_number: |
|
272 | 276 | i = 1 |
|
273 | 277 | for absbeam in absbeams: |
|
274 | 278 | if i <= beams_number: |
|
275 | 279 | absbeam.dict_to_parms(beams['beam'+str(i)]) |
|
276 | 280 | i=i+1 |
|
277 | 281 | else: |
|
278 | 282 | absbeam.delete() |
|
279 | 283 | else: |
|
280 | 284 | for beam in beams: |
|
281 | 285 | new_beam = ABSBeam( |
|
282 | 286 | name =beams[beam]['name'], |
|
283 | 287 | antenna =json.dumps(beams[beam]['antenna']), |
|
284 | 288 | abs_conf = self, |
|
285 | 289 | tx =json.dumps(beams[beam]['tx']), |
|
286 | 290 | rx =json.dumps(beams[beam]['rx']), |
|
287 | 291 | ues =json.dumps(beams[beam]['ues']), |
|
288 | 292 | only_rx =json.dumps(beams[beam]['only_rx']) |
|
289 | 293 | ) |
|
290 | 294 | new_beam.save() |
|
291 | 295 | |
|
292 | 296 | |
|
293 | 297 | |
|
294 | 298 | def update_from_file(self, parameters): |
|
295 | 299 | |
|
296 | 300 | self.dict_to_parms(parameters) |
|
297 | 301 | self.save() |
|
298 | 302 | |
|
299 | 303 | |
|
300 | 304 | def get_beams(self, **kwargs): |
|
301 | 305 | ''' |
|
302 | 306 | This function returns ABS Configuration beams |
|
303 | 307 | ''' |
|
304 | 308 | return ABSBeam.objects.filter(abs_conf=self.pk, **kwargs) |
|
305 | 309 | |
|
306 | 310 | def clone(self, **kwargs): |
|
307 | 311 | |
|
308 | 312 | beams = self.get_beams() |
|
309 | 313 | self.pk = None |
|
310 | 314 | self.id = None |
|
311 | 315 | for attr, value in kwargs.items(): |
|
312 | 316 | setattr(self, attr, value) |
|
313 | 317 | self.save() |
|
314 | 318 | |
|
315 | 319 | for beam in beams: |
|
316 | 320 | beam.clone(abs_conf=self) |
|
317 | 321 | |
|
318 | 322 | #-----For Active Beam----- |
|
319 | 323 | new_beams = ABSBeam.objects.filter(abs_conf=self) |
|
320 | 324 | self.active_beam = new_beams[0].id |
|
321 | 325 | self.save() |
|
322 | 326 | #-----For Active Beam----- |
|
323 | 327 | #-----For Device Status--- |
|
324 | 328 | self.device.status = 3 |
|
325 | 329 | self.device.save() |
|
326 | 330 | #-----For Device Status--- |
|
327 | 331 | |
|
328 | 332 | return self |
|
329 | 333 | |
|
330 | 334 | |
|
331 | 335 | def start_device(self): |
|
332 | 336 | |
|
333 | 337 | if self.device.status == 3: |
|
334 | 338 | |
|
335 | 339 | try: |
|
336 | 340 | #self.write_device() |
|
337 | 341 | send_task('task_change_beam', [self.id],) |
|
338 | 342 | self.message = 'ABS running' |
|
339 | 343 | |
|
340 | 344 | except Exception as e: |
|
341 | 345 | self.message = str(e) |
|
342 | 346 | return False |
|
343 | 347 | |
|
344 | 348 | return True |
|
345 | 349 | |
|
346 | 350 | else: |
|
347 | 351 | self.message = 'Please, select Write ABS Device first.' |
|
348 | 352 | return False |
|
349 | 353 | |
|
350 | 354 | |
|
351 | 355 | def stop_device(self): |
|
352 | 356 | |
|
353 | 357 | self.device.status = 2 |
|
354 | 358 | self.device.save() |
|
355 | 359 | self.message = 'ABS has been stopped.' |
|
356 | 360 | self.save() |
|
357 | 361 | |
|
358 | 362 | return True |
|
359 | 363 | |
|
360 | 364 | |
|
361 | 365 | def write_device(self): |
|
362 | 366 | |
|
363 | 367 | """ |
|
364 | 368 | This function sends the beams list to every abs module. |
|
365 | 369 | It needs 'module_conf' function |
|
366 | 370 | """ |
|
367 | 371 | print("Write 3") |
|
368 | 372 | |
|
369 | 373 | beams = ABSBeam.objects.filter(abs_conf=self) |
|
370 | 374 | nbeams = len(beams) |
|
371 | 375 | |
|
372 | 376 | # Se manda a cero RC para poder realizar cambio de beam |
|
373 | 377 | if self.experiment is None: |
|
374 | 378 | confs = [] |
|
375 | 379 | else: |
|
376 | 380 | confs = Configuration.objects.filter(experiment = self.experiment).filter(type=0) |
|
377 | 381 | confdds = '' |
|
378 | 382 | confjars = '' |
|
379 | 383 | confrc = '' |
|
380 | 384 | #TO STOP DEVICES: DDS-JARS-RC |
|
381 | 385 | for i in range(0,len(confs)): |
|
382 | 386 | if i==0: |
|
383 | 387 | for conf in confs: |
|
384 | 388 | if conf.device.device_type.name == 'dds': |
|
385 | 389 | confdds = conf |
|
386 | 390 | confdds.stop_device() |
|
387 | 391 | break |
|
388 | 392 | if i==1: |
|
389 | 393 | for conf in confs: |
|
390 | 394 | if conf.device.device_type.name == 'jars': |
|
391 | 395 | confjars = conf |
|
392 | 396 | confjars.stop_device() |
|
393 | 397 | break |
|
394 | 398 | if i==2: |
|
395 | 399 | for conf in confs: |
|
396 | 400 | if conf.device.device_type.name == 'rc': |
|
397 | 401 | confrc = conf |
|
398 | 402 | confrc.stop_device() |
|
399 | 403 | break |
|
400 | 404 | |
|
401 | 405 | ''' |
|
402 | 406 | if self.connected_modules() == 0 : |
|
403 | 407 | print("No encuentra modulos") |
|
404 | 408 | self.message = "No ABS Module detected." |
|
405 | 409 | return False |
|
406 | 410 | ''' |
|
407 | 411 | #-------------Write each abs module----------- |
|
408 | 412 | |
|
409 | 413 | if beams: |
|
410 | 414 | block_id = 0 |
|
411 | 415 | message = 'SNDF{:03d}{:02d}{:02d}'.format(nbeams, nbeams, block_id) |
|
412 | 416 | for i, status in enumerate(self.module_status): |
|
413 | 417 | message += ''.join([fromBinary2Char(beam.module_6bits(i)) for beam in beams]) |
|
414 | 418 | status = ['0'] * 64 |
|
415 | 419 | n = 0 |
|
416 | 420 | |
|
417 | 421 | print("Llega una antes entrar a multicast4") |
|
418 | 422 | |
|
419 | 423 | sock = self.send_multicast(message) |
|
420 | 424 | |
|
421 | 425 | while True: |
|
422 | 426 | #for i in range(32): |
|
423 | 427 | try: |
|
424 | 428 | data, address = sock.recvfrom(1024) |
|
425 | 429 | print (address, data) |
|
426 | 430 | data = data.decode("utf-8") |
|
427 | 431 | if data == '1': |
|
428 | 432 | status[int(address[0][10:])-1] = '3' |
|
429 | 433 | #print (int(address[0][10:])-1) |
|
430 | 434 | elif data == '0': |
|
431 | 435 | status[int(address[0][10:])-1] = '1' |
|
432 | 436 | except socket.timeout: |
|
433 | 437 | print('Timeout') |
|
434 | 438 | break |
|
435 | 439 | except Exception as e: |
|
436 | 440 | print ('Error {}'.format(e)) |
|
437 | 441 | n += 1 |
|
438 | 442 | sock.close() |
|
439 | 443 | else: |
|
440 | 444 | self.message = "ABS Configuration does not have beams" |
|
441 | 445 | print('No beams') |
|
442 | 446 | #Start DDS-RC-JARS |
|
443 | 447 | if confdds: |
|
444 | 448 | confdds.start_device() |
|
445 | 449 | if confrc: |
|
446 | 450 | #print confrc |
|
447 | 451 | confrc.start_device() |
|
448 | 452 | if confjars: |
|
449 | 453 | confjars.start_device() |
|
450 | 454 | return False |
|
451 | 455 | |
|
452 | 456 | if n == 64: |
|
453 | 457 | self.message = "Could not write ABS Modules" |
|
454 | 458 | self.device.status = 0 |
|
455 | 459 | self.module_status = ''.join(status) |
|
456 | 460 | self.save() |
|
457 | 461 | print('Could not write ABS') |
|
458 | 462 | #Start DDS-RC-JARS |
|
459 | 463 | if confdds: |
|
460 | 464 | confdds.start_device() |
|
461 | 465 | if confrc: |
|
462 | 466 | #print confrc |
|
463 | 467 | confrc.start_device() |
|
464 | 468 | if confjars: |
|
465 | 469 | confjars.start_device() |
|
466 | 470 | return False |
|
467 | 471 | else: |
|
468 | 472 | self.message = "ABS Beams List have been sent to ABS Modules" |
|
469 | 473 | print('ABS beams list sent') |
|
470 | 474 | self.active_beam = beams[0].pk |
|
471 | 475 | |
|
472 | 476 | #Start DDS-RC-JARS |
|
473 | 477 | if confdds: |
|
474 | 478 | confdds.start_device() |
|
475 | 479 | if confrc: |
|
476 | 480 | #print confrc |
|
477 | 481 | confrc.start_device() |
|
478 | 482 | if confjars: |
|
479 | 483 | confjars.start_device() |
|
480 | 484 | |
|
481 | 485 | print('Inicia intento de salvar device.status') |
|
482 | 486 | self.device.status = 3 |
|
483 | 487 | self.module_status = ''.join(status) |
|
484 | 488 | #print(status) |
|
485 | 489 | self.save() |
|
486 | 490 | print('Estatus salvado') |
|
487 | 491 | conf_active, __ = ABSActive.objects.get_or_create(pk=1) |
|
488 | 492 | conf_active.conf = self |
|
489 | 493 | conf_active.save() |
|
490 | 494 | return True |
|
491 | 495 | |
|
496 | def write_device_mqtt(self): | |
|
497 | apuntes_up_down='' | |
|
498 | beams = ABSBeam.objects.filter(abs_conf=self) | |
|
499 | ||
|
500 | inicializacion="{\"beams\":[" | |
|
501 | finalizacion="]}" | |
|
502 | ||
|
503 | for beam in beams: | |
|
504 | beam.antenna=beam.antenna[1:] | |
|
505 | info="{\"id\":"+str(beam.id)+","+beam.antenna + "," | |
|
506 | apuntes_up_down=apuntes_up_down+info | |
|
507 | ||
|
508 | apuntes_up_down=apuntes_up_down[:len(apuntes_up_down)-1] | |
|
509 | ||
|
510 | apuntes_up_down=inicializacion+ apuntes_up_down+finalizacion | |
|
511 | ||
|
512 | #print(apuntes_up_down,flush=True) | |
|
513 | ||
|
514 | mqtt_client.publish(os.environ.get('TOPIC_ABS', 'abs/beams'),apuntes_up_down) | |
|
515 | ||
|
516 | return True | |
|
492 | 517 | |
|
493 | 518 | def read_module(self, module): |
|
494 | 519 | |
|
495 | 520 | """ |
|
496 | 521 | Read out-bits (up-down) of 1 abs module NOT for Configuration |
|
497 | 522 | """ |
|
498 | 523 | |
|
499 | 524 | ip_address = self.device.ip_address |
|
500 | 525 | ip_address = ip_address.split('.') |
|
501 | 526 | module_seq = (ip_address[0],ip_address[1],ip_address[2]) |
|
502 | 527 | dot = '.' |
|
503 | 528 | module_ip = dot.join(module_seq)+'.'+str(module) |
|
504 | 529 | module_port = self.device.port_address |
|
505 | 530 | read_route = 'http://'+module_ip+':'+str(module_port)+'/read' |
|
506 | 531 | |
|
507 | 532 | module_status = json.loads(self.module_status) |
|
508 | 533 | print(read_route) |
|
509 | 534 | |
|
510 | 535 | module_bits = '' |
|
511 | 536 | |
|
512 | 537 | try: |
|
513 | 538 | r_read = requests.get(read_route, timeout=0.5) |
|
514 | 539 | answer = r_read.json() |
|
515 | 540 | module_bits = answer['allbits'] |
|
516 | 541 | except: |
|
517 | 542 | return {} |
|
518 | 543 | |
|
519 | 544 | return module_bits |
|
520 | 545 | |
|
521 | 546 | def read_device(self): |
|
522 | 547 | |
|
523 | 548 | parms = {} |
|
524 | 549 | # Reads active modules. |
|
525 | 550 | module_status = json.loads(self.module_status) |
|
526 | 551 | total = 0 |
|
527 | 552 | for status in module_status: |
|
528 | 553 | if module_status[status] != 0: |
|
529 | 554 | module_bits = self.read_module(int(status)) |
|
530 | 555 | bits={} |
|
531 | 556 | if module_bits: |
|
532 | 557 | bits = (str(module_bits['um2']) + str(module_bits['um1']) + str(module_bits['um0']) + |
|
533 | 558 | str(module_bits['dm2']) + str(module_bits['dm1']) + str(module_bits['dm0']) ) |
|
534 | 559 | parms[str(status)] = bits |
|
535 | 560 | |
|
536 | 561 | total +=1 |
|
537 | 562 | |
|
538 | 563 | if total==0: |
|
539 | 564 | self.message = "No ABS Module detected. Please select 'Status'." |
|
540 | 565 | return False |
|
541 | 566 | |
|
542 | 567 | |
|
543 | 568 | |
|
544 | 569 | self.message = "ABS Modules have been read" |
|
545 | 570 | #monitoreo_tx = JROABSClnt_01CeCnMod000000MNTR10 |
|
546 | 571 | return parms |
|
547 | 572 | |
|
548 | 573 | |
|
549 | 574 | def connected_modules(self): |
|
550 | 575 | """ |
|
551 | 576 | This function returns the number of connected abs-modules without updating. |
|
552 | 577 | """ |
|
553 | 578 | num = 0 |
|
554 | 579 | print(self.module_status) |
|
555 | 580 | for i, status in enumerate(self.module_status): |
|
556 | 581 | if status != '0': |
|
557 | 582 | num += 1 |
|
558 | 583 | #print('status {}:{}'.format(i+1, status)) |
|
559 | 584 | return num |
|
560 | 585 | |
|
561 | 586 | def send_multicast(self, message): |
|
562 | 587 | #print("Send multicast") |
|
563 | 588 | multicast_group = ('224.3.29.71', 10000) |
|
564 | 589 | # Create the datagram socket |
|
565 | 590 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
|
566 | 591 | sock.settimeout(1) |
|
567 | 592 | local_ip = os.environ.get('LOCAL_IP', '0.0.0.0') |
|
568 | 593 | local_ip = '0.0.0.0' |
|
569 | 594 | print("He llegado a IP local") |
|
570 | 595 | |
|
571 | 596 | sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_IF, socket.inet_aton(local_ip)) |
|
572 | 597 | sock.sendto(message.encode(), multicast_group) |
|
573 | 598 | print('Sending ' + message) |
|
574 | 599 | return sock |
|
575 | 600 | |
|
576 | 601 | def status_device(self): |
|
577 | 602 | """ |
|
578 | 603 | This function returns the status of all abs-modules as one. |
|
579 | 604 | If at least one module is connected, its answer is "1" |
|
580 | 605 | """ |
|
581 | 606 | print ('Status device') |
|
582 | 607 | print (self.active_beam) |
|
583 | 608 | beams = ABSBeam.objects.filter(abs_conf=self) |
|
584 | 609 | #print beams[self.active_beam-1].module_6bits(0) |
|
585 | 610 | active = ABSActive.objects.get(pk=1) |
|
586 | 611 | if active.conf != self: |
|
587 | 612 | self.message = 'La configuracion actual es la del siguiente enlace %s.' % active.conf.get_absolute_url() |
|
588 | 613 | self.message += "\n" |
|
589 | 614 | self.message += 'Se debe realizar un write en esta configuracion para luego obtener un status valido.' |
|
590 | 615 | |
|
591 | 616 | return False |
|
592 | 617 | |
|
593 | 618 | sock = self.send_multicast('MNTR') |
|
594 | 619 | |
|
595 | 620 | n = 0 |
|
596 | 621 | status = ['0'] * 64 |
|
597 | 622 | |
|
598 | 623 | while True: |
|
599 | 624 | #for i in range(32): |
|
600 | 625 | #if True: |
|
601 | 626 | try: |
|
602 | 627 | print("Recibiendo") |
|
603 | 628 | address = None |
|
604 | 629 | data, address = sock.recvfrom(2) |
|
605 | 630 | print (address, data) |
|
606 | 631 | print("!!!!") |
|
607 | 632 | data = data.decode() |
|
608 | 633 | aux_mon = "1" |
|
609 | 634 | aux_expected = aux_mon |
|
610 | 635 | if(len(data)==2): |
|
611 | 636 | print ("data[1]: ") |
|
612 | 637 | print (data[1]) |
|
613 | 638 | aux_mon = fromChar2Binary(data[1]) |
|
614 | 639 | print (aux_mon) |
|
615 | 640 | aux_i = (str(address[0]).split('.'))[3] |
|
616 | 641 | print (aux_i) |
|
617 | 642 | print ('Active beam') |
|
618 | 643 | beam_active = ABSBeam.objects.get(pk=self.active_beam) |
|
619 | 644 | print (beam_active) |
|
620 | 645 | aux_expected = beam_active.module_6bits(int(aux_i)-1) |
|
621 | 646 | print (aux_expected) |
|
622 | 647 | |
|
623 | 648 | print ("data[0]: ") |
|
624 | 649 | print (data[0]) |
|
625 | 650 | |
|
626 | 651 | if data[0] == '1': |
|
627 | 652 | status[int(address[0][10:])-1] = '3' |
|
628 | 653 | if aux_mon == aux_expected: |
|
629 | 654 | print ('Es igual') |
|
630 | 655 | else: |
|
631 | 656 | print ('Es diferente') |
|
632 | 657 | status[int(address[0][10:])-1] = '2' |
|
633 | 658 | |
|
634 | 659 | elif data[0] == '0': |
|
635 | 660 | status[int(address[0][10:])-1] = '1' |
|
636 | 661 | n += 1 |
|
637 | 662 | print('Module: {} connected'.format(address)) |
|
638 | 663 | except socket.timeout: |
|
639 | 664 | print('Timeout') |
|
640 | 665 | break |
|
641 | 666 | except: |
|
642 | 667 | print('Module: {} error'.format(address)) |
|
643 | 668 | pass |
|
644 | 669 | |
|
645 | 670 | sock.close() |
|
646 | 671 | |
|
647 | 672 | if n > 0: |
|
648 | 673 | self.message = 'ABS modules Status have been updated.' |
|
649 | 674 | self.device.status = 1 |
|
650 | 675 | else: |
|
651 | 676 | self.device.status = 0 |
|
652 | 677 | self.message = 'No ABS module is connected.' |
|
653 | 678 | self.module_status = ''.join(status) |
|
654 | 679 | self.save() |
|
655 | 680 | |
|
656 | 681 | return self.device.status |
|
657 | 682 | |
|
658 | 683 | |
|
659 | 684 | def send_beam(self, beam_pos): |
|
660 | 685 | """ |
|
661 | 686 | This function connects to a multicast group and sends the beam number |
|
662 | 687 | to all abs modules. |
|
663 | 688 | """ |
|
664 | 689 | print ('Send beam') |
|
665 | 690 | print (self.active_beam) |
|
666 | 691 | beams = ABSBeam.objects.filter(abs_conf=self) |
|
667 | 692 | #print beams[self.active_beam-1].module_6bits(0) |
|
668 | 693 | active = ABSActive.objects.get(pk=1) |
|
669 | 694 | if active.conf != self: |
|
670 | 695 | self.message = 'La configuracion actual es la del siguiente enlace %s.' % active.conf.get_absolute_url() |
|
671 | 696 | self.message += "\n" |
|
672 | 697 | self.message += 'Se debe realizar un write en esta configuracion para luego obtener un status valido.' |
|
673 | 698 | |
|
674 | 699 | return False |
|
675 | 700 | |
|
676 | 701 | # Se manda a cero RC para poder realizar cambio de beam |
|
677 | 702 | if self.experiment is None: |
|
678 | 703 | confs = [] |
|
679 | 704 | else: |
|
680 | 705 | confs = Configuration.objects.filter(experiment = self.experiment).filter(type=0) |
|
681 | 706 | confdds = '' |
|
682 | 707 | confjars = '' |
|
683 | 708 | confrc = '' |
|
684 | 709 | #TO STOP DEVICES: DDS-JARS-RC |
|
685 | 710 | for i in range(0,len(confs)): |
|
686 | 711 | if i==0: |
|
687 | 712 | for conf in confs: |
|
688 | 713 | if conf.device.device_type.name == 'dds': |
|
689 | 714 | confdds = conf |
|
690 | 715 | confdds.stop_device() |
|
691 | 716 | break |
|
692 | 717 | if i==1: |
|
693 | 718 | for conf in confs: |
|
694 | 719 | if conf.device.device_type.name == 'jars': |
|
695 | 720 | confjars = conf |
|
696 | 721 | confjars.stop_device() |
|
697 | 722 | break |
|
698 | 723 | if i==2: |
|
699 | 724 | for conf in confs: |
|
700 | 725 | if conf.device.device_type.name == 'rc': |
|
701 | 726 | confrc = conf |
|
702 | 727 | confrc.stop_device() |
|
703 | 728 | break |
|
704 | 729 | if beam_pos > 0: |
|
705 | 730 | beam_pos = beam_pos - 1 |
|
706 | 731 | else: |
|
707 | 732 | beam_pos = 0 |
|
708 | 733 | |
|
709 | 734 | #El indice del apunte debe ser menor que el numero total de apuntes |
|
710 | 735 | #El servidor tcp en el embebido comienza a contar desde 0 |
|
711 | 736 | status = ['0'] * 64 |
|
712 | 737 | message = 'CHGB{}'.format(beam_pos) |
|
713 | 738 | sock = self.send_multicast(message) |
|
714 | 739 | while True: |
|
715 | 740 | #for i in range(32): |
|
716 | 741 | try: |
|
717 | 742 | data, address = sock.recvfrom(1024) |
|
718 | 743 | print (address, data) |
|
719 | 744 | data = data.decode() |
|
720 | 745 | if data == '1': |
|
721 | 746 | status[int(address[0][10:])-1] = '3' |
|
722 | 747 | elif data == '0': |
|
723 | 748 | status[int(address[0][10:])-1] = '1' |
|
724 | 749 | except socket.timeout: |
|
725 | 750 | print('Timeout') |
|
726 | 751 | break |
|
727 | 752 | except Exception as e: |
|
728 | 753 | print ('Error {}'.format(e)) |
|
729 | 754 | pass |
|
730 | 755 | |
|
731 | 756 | sock.close() |
|
732 | 757 | |
|
733 | 758 | #Start DDS-RC-JARS |
|
734 | 759 | if confdds: |
|
735 | 760 | confdds.start_device() |
|
736 | 761 | if confrc: |
|
737 | 762 | #print confrc |
|
738 | 763 | confrc.start_device() |
|
739 | 764 | if confjars: |
|
740 | 765 | confjars.start_device() |
|
741 | 766 | |
|
742 | 767 | self.message = "ABS Beam has been changed" |
|
743 | 768 | self.module_status = ''.join(status) |
|
744 | 769 | self.save() |
|
745 | 770 | return True |
|
746 | 771 | |
|
747 | 772 | |
|
748 | 773 | def get_absolute_url_import(self): |
|
749 | 774 | return reverse('url_import_abs_conf', args=[str(self.id)]) |
|
750 | 775 | |
|
751 | 776 | class ABSActive(models.Model): |
|
752 | 777 | conf = models.ForeignKey(ABSConfiguration, null=True, verbose_name='ABS Configuration', on_delete=models.CASCADE) |
|
753 | 778 | |
|
754 | 779 | class Meta: |
|
755 | 780 | db_table = 'abs_absactive' |
|
756 | 781 | |
|
757 | 782 | class ABSBeam(models.Model): |
|
758 | 783 | |
|
759 | 784 | name = models.CharField(max_length=60, default='Beam') |
|
760 | 785 | antenna = models.CharField(verbose_name='Antenna', max_length=1000, default=antenna_default) |
|
761 | 786 | abs_conf = models.ForeignKey('ABSConfiguration', null=True, |
|
762 | 787 | verbose_name='ABS Configuration', on_delete=models.CASCADE) |
|
763 | 788 | tx = models.CharField(verbose_name='Tx', max_length=1000, default=tx_default) |
|
764 | 789 | rx = models.CharField(verbose_name='Rx', max_length=1000, default=rx_default) |
|
765 | 790 | s_time = models.TimeField(verbose_name='Star Time', default='00:00:00') |
|
766 | 791 | e_time = models.TimeField(verbose_name='End Time', default='23:59:59') |
|
767 | 792 | ues = models.CharField(verbose_name='Ues', max_length=100, default=ues_default) |
|
768 | 793 | only_rx = models.CharField(verbose_name='Only RX', max_length=40, default=onlyrx_default) |
|
769 | 794 | |
|
770 | 795 | class Meta: |
|
771 | 796 | db_table = 'abs_beams' |
|
772 | 797 | |
|
773 | 798 | def __unicode__(self): |
|
774 | 799 | return u'%s' % (self.name) |
|
775 | 800 | |
|
776 | 801 | def parms_to_dict(self): |
|
777 | 802 | |
|
778 | 803 | parameters = {} |
|
779 | 804 | parameters['name'] = self.name |
|
780 | 805 | parameters['antenna'] = ast.literal_eval(self.antenna) |
|
781 | 806 | parameters['abs_conf'] = self.abs_conf.name |
|
782 | 807 | parameters['tx'] = ast.literal_eval(self.tx) |
|
783 | 808 | parameters['rx'] = ast.literal_eval(self.rx) |
|
784 | 809 | parameters['s_time'] = self.s_time.strftime("%H:%M:%S") |
|
785 | 810 | parameters['e_time'] = self.e_time.strftime("%H:%M:%S") |
|
786 | 811 | parameters['ues'] = ast.literal_eval(self.ues) |
|
787 | 812 | parameters['only_rx'] = json.loads(self.only_rx) |
|
788 | 813 | |
|
789 | 814 | return parameters |
|
790 | 815 | |
|
791 | 816 | def dict_to_parms(self, parameters): |
|
792 | 817 | |
|
793 | 818 | self.name = parameters['name'] |
|
794 | 819 | self.antenna = json.dumps(parameters['antenna']) |
|
795 | 820 | #self.abs_conf = parameters['abs_conf'] |
|
796 | 821 | self.tx = json.dumps(parameters['tx']) |
|
797 | 822 | self.rx = json.dumps(parameters['rx']) |
|
798 | 823 | #self.s_time = parameters['s_time'] |
|
799 | 824 | #self.e_time = parameters['e_time'] |
|
800 | 825 | self.ues = json.dumps(parameters['ues']) |
|
801 | 826 | self.only_rx = json.dumps(parameters['only_rx']) |
|
802 | 827 | self.save() |
|
803 | 828 | |
|
804 | 829 | |
|
805 | 830 | def clone(self, **kwargs): |
|
806 | 831 | |
|
807 | 832 | self.pk = None |
|
808 | 833 | self.id = None |
|
809 | 834 | for attr, value in kwargs.items(): |
|
810 | 835 | setattr(self, attr, value) |
|
811 | 836 | |
|
812 | 837 | self.save() |
|
813 | 838 | |
|
814 | 839 | return self |
|
815 | 840 | |
|
816 | 841 | |
|
817 | 842 | def module_6bits(self, module): |
|
818 | 843 | """ |
|
819 | 844 | This function reads antenna pattern and choose 6bits (upbits-downbits) for one abs module |
|
820 | 845 | """ |
|
821 | 846 | module += 1 |
|
822 | 847 | if module > 64: |
|
823 | 848 | beam_bits = "" |
|
824 | 849 | return beam_bits |
|
825 | 850 | |
|
826 | 851 | data = ast.literal_eval(self.antenna) |
|
827 | 852 | up_data = data['antenna_up'] |
|
828 | 853 | down_data = data['antenna_down'] |
|
829 | 854 | |
|
830 | 855 | pos = ip2position(module) |
|
831 | 856 | up_value = up_data[pos[0]][pos[1]] |
|
832 | 857 | down_value = down_data[pos[0]][pos[1]] |
|
833 | 858 | |
|
834 | 859 | up_bits = up_conv_bits(up_value) |
|
835 | 860 | down_bits = down_conv_bits(down_value) |
|
836 | 861 | beam_bits = up_bits+down_bits |
|
837 | 862 | |
|
838 | 863 | return beam_bits |
|
839 | 864 | |
|
840 | 865 | |
|
841 | 866 | @property |
|
842 | 867 | def get_upvalues(self): |
|
843 | 868 | """ |
|
844 | 869 | This function reads antenna pattern and show the up-value of one abs module |
|
845 | 870 | """ |
|
846 | 871 | |
|
847 | 872 | data = ast.literal_eval(self.antenna) |
|
848 | 873 | up_data = data['antenna_up'] |
|
849 | 874 | |
|
850 | 875 | up_values = [] |
|
851 | 876 | for data in up_data: |
|
852 | 877 | for i in range(0,8): |
|
853 | 878 | up_values.append(data[i]) |
|
854 | 879 | |
|
855 | 880 | return up_values |
|
856 | 881 | |
|
857 | 882 | @property |
|
858 | 883 | def antenna_upvalues(self): |
|
859 | 884 | """ |
|
860 | 885 | This function reads antenna pattern and show the up - values of one abs beam |
|
861 | 886 | in a particular order |
|
862 | 887 | """ |
|
863 | 888 | data = ast.literal_eval(self.antenna) |
|
864 | 889 | up_data = data['antenna_up'] |
|
865 | 890 | |
|
866 | 891 | return up_data |
|
867 | 892 | |
|
868 | 893 | @property |
|
869 | 894 | def antenna_downvalues(self): |
|
870 | 895 | """ |
|
871 | 896 | This function reads antenna pattern and show the down - values of one abs beam |
|
872 | 897 | in a particular order |
|
873 | 898 | """ |
|
874 | 899 | data = ast.literal_eval(self.antenna) |
|
875 | 900 | down_data = data['antenna_down'] |
|
876 | 901 | |
|
877 | 902 | return down_data |
|
878 | 903 | |
|
879 | 904 | @property |
|
880 | 905 | def get_downvalues(self): |
|
881 | 906 | """ |
|
882 | 907 | This function reads antenna pattern and show the down-value of one abs module |
|
883 | 908 | """ |
|
884 | 909 | |
|
885 | 910 | data = ast.literal_eval(self.antenna) |
|
886 | 911 | down_data = data['antenna_down'] |
|
887 | 912 | |
|
888 | 913 | down_values = [] |
|
889 | 914 | for data in down_data: |
|
890 | 915 | for i in range(0,8): |
|
891 | 916 | down_values.append(data[i]) |
|
892 | 917 | |
|
893 | 918 | return down_values |
|
894 | 919 | |
|
895 | 920 | @property |
|
896 | 921 | def get_up_ues(self): |
|
897 | 922 | """ |
|
898 | 923 | This function shows the up-ues-value of one beam |
|
899 | 924 | """ |
|
900 | 925 | data = ast.literal_eval(self.ues) |
|
901 | 926 | up_ues = data['up'] |
|
902 | 927 | |
|
903 | 928 | return up_ues |
|
904 | 929 | |
|
905 | 930 | @property |
|
906 | 931 | def get_down_ues(self): |
|
907 | 932 | """ |
|
908 | 933 | This function shows the down-ues-value of one beam |
|
909 | 934 | """ |
|
910 | 935 | data = ast.literal_eval(self.ues) |
|
911 | 936 | down_ues = data['down'] |
|
912 | 937 | |
|
913 | 938 | return down_ues |
|
914 | 939 | |
|
915 | 940 | @property |
|
916 | 941 | def get_up_onlyrx(self): |
|
917 | 942 | """ |
|
918 | 943 | This function shows the up-onlyrx-value of one beam |
|
919 | 944 | """ |
|
920 | 945 | data = json.loads(self.only_rx) |
|
921 | 946 | up_onlyrx = data['up'] |
|
922 | 947 | |
|
923 | 948 | return up_onlyrx |
|
924 | 949 | |
|
925 | 950 | @property |
|
926 | 951 | def get_down_onlyrx(self): |
|
927 | 952 | """ |
|
928 | 953 | This function shows the down-onlyrx-value of one beam |
|
929 | 954 | """ |
|
930 | 955 | data = json.loads(self.only_rx) |
|
931 | 956 | down_onlyrx = data['down'] |
|
932 | 957 | |
|
933 | 958 | return down_onlyrx |
|
934 | 959 | |
|
935 | 960 | @property |
|
936 | 961 | def get_tx(self): |
|
937 | 962 | """ |
|
938 | 963 | This function shows the tx-values of one beam |
|
939 | 964 | """ |
|
940 | 965 | data = json.loads(self.tx) |
|
941 | 966 | |
|
942 | 967 | return data |
|
943 | 968 | |
|
944 | 969 | @property |
|
945 | 970 | def get_uptx(self): |
|
946 | 971 | """ |
|
947 | 972 | This function shows the up-tx-values of one beam |
|
948 | 973 | """ |
|
949 | 974 | data = json.loads(self.tx) |
|
950 | 975 | up_data = data['up'] |
|
951 | 976 | |
|
952 | 977 | up_values = [] |
|
953 | 978 | for data in up_data: |
|
954 | 979 | for i in range(0,8): |
|
955 | 980 | up_values.append(data[i]) |
|
956 | 981 | |
|
957 | 982 | return up_values |
|
958 | 983 | |
|
959 | 984 | @property |
|
960 | 985 | def get_downtx(self): |
|
961 | 986 | """ |
|
962 | 987 | This function shows the down-tx-values of one beam |
|
963 | 988 | """ |
|
964 | 989 | data = json.loads(self.tx) |
|
965 | 990 | down_data = data['down'] |
|
966 | 991 | |
|
967 | 992 | down_values = [] |
|
968 | 993 | for data in down_data: |
|
969 | 994 | for i in range(0,8): |
|
970 | 995 | down_values.append(data[i]) |
|
971 | 996 | |
|
972 | 997 | return down_values |
|
973 | 998 | |
|
974 | 999 | |
|
975 | 1000 | |
|
976 | 1001 | @property |
|
977 | 1002 | def get_rx(self): |
|
978 | 1003 | """ |
|
979 | 1004 | This function shows the rx-values of one beam |
|
980 | 1005 | """ |
|
981 | 1006 | data = json.loads(self.rx) |
|
982 | 1007 | |
|
983 | 1008 | return data |
|
984 | 1009 | |
|
985 | 1010 | @property |
|
986 | 1011 | def get_uprx(self): |
|
987 | 1012 | """ |
|
988 | 1013 | This function shows the up-rx-values of one beam |
|
989 | 1014 | """ |
|
990 | 1015 | data = json.loads(self.rx) |
|
991 | 1016 | up_data = data['up'] |
|
992 | 1017 | |
|
993 | 1018 | up_values = [] |
|
994 | 1019 | for data in up_data: |
|
995 | 1020 | for i in range(0,8): |
|
996 | 1021 | up_values.append(data[i]) |
|
997 | 1022 | |
|
998 | 1023 | return up_values |
|
999 | 1024 | |
|
1000 | 1025 | @property |
|
1001 | 1026 | def get_downrx(self): |
|
1002 | 1027 | """ |
|
1003 | 1028 | This function shows the down-rx-values of one beam |
|
1004 | 1029 | """ |
|
1005 | 1030 | data = json.loads(self.rx) |
|
1006 | 1031 | down_data = data['down'] |
|
1007 | 1032 | |
|
1008 | 1033 | down_values = [] |
|
1009 | 1034 | for data in down_data: |
|
1010 | 1035 | for i in range(0,8): |
|
1011 | 1036 | down_values.append(data[i]) |
|
1012 | 1037 | |
|
1013 | 1038 | return down_values |
@@ -1,339 +1,384 | |||
|
1 | 1 | {% extends "dev_conf.html" %} {% load static %} {% load django_bootstrap5 %} {% load main_tags %} |
|
2 | 2 | {% block extra-head %} |
|
3 | 3 | <style> |
|
4 | 4 | .abs { |
|
5 | 5 | width: auto; |
|
6 | 6 | display: inline-block; |
|
7 | 7 | text-align: center; |
|
8 | 8 | } |
|
9 | 9 | |
|
10 | 10 | .abs td { |
|
11 | 11 | padding: 4px; |
|
12 | 12 | } |
|
13 | 13 | |
|
14 | 14 | .module td { |
|
15 | 15 | padding: 4px 15px 4px 15px; |
|
16 | 16 | font-weight: bold; |
|
17 | 17 | border: 1px solid |
|
18 | 18 | } |
|
19 | 19 | |
|
20 | 20 | .legend { |
|
21 | 21 | margin-left: 15px; |
|
22 | 22 | display: inline-block; |
|
23 | 23 | border: 2px solid; |
|
24 | 24 | vertical-align: top; |
|
25 | 25 | } |
|
26 | 26 | |
|
27 | 27 | .legend th { |
|
28 | 28 | border-bottom: 1px dashed; |
|
29 | 29 | font-weight: bold; |
|
30 | 30 | vertical-align: center; |
|
31 | 31 | text-align: center; |
|
32 | 32 | } |
|
33 | 33 | |
|
34 | 34 | .legend td { |
|
35 | 35 | padding: 2px; |
|
36 | 36 | text-align: center; |
|
37 | 37 | font-weight: bold; |
|
38 | 38 | } |
|
39 | 39 | |
|
40 | 40 | </style> |
|
41 | 41 | {% endblock %} |
|
42 | ||
|
43 | ||
|
42 | 44 | {% block extra-menu-actions %} |
|
43 | 45 | <li> |
|
44 | 46 | <a href="{{ dev_conf.get_absolute_url_plot }}" target="_blank"> |
|
45 | 47 | <span class="far fa-image" aria-hidden="true"></span> View Patterns </a> |
|
46 | 48 | </li> |
|
47 | 49 | {% endblock %} |
|
50 | ||
|
51 | ||
|
48 | 52 | {% block extra-content %} |
|
53 | <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script> | |
|
54 | <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/4.4.1/socket.io.min.js"> | |
|
55 | </script> | |
|
56 | ||
|
57 | ||
|
49 | 58 | {% if beams %} |
|
50 | 59 | <h4>Beams:</h4> |
|
51 | 60 | <div class="container"> |
|
52 | 61 | <ul class="nav nav-pills"> |
|
53 | 62 | {% for beam in beams %} |
|
54 | 63 | <li class="nav-item"> |
|
55 | 64 | <a {%if beam.pk == active_beam %} class="nav-link active" {% else %} class="nav-link" {% endif %} data-toggle="pill" href="#menu{{forloop.counter}}">{{forloop.counter}}</a> |
|
56 | 65 | </li> |
|
57 | 66 | {% endfor %} |
|
58 | 67 | </ul> |
|
59 | 68 | |
|
60 | 69 | <div class="tab-content"> |
|
61 | 70 | {% for beam in beams %} |
|
62 | 71 | <div id="menu{{forloop.counter}}" class="tab-pane fade {%if beam.pk == active_beam %}in active show{% endif %}"> |
|
63 | 72 | <h3>{%if beam.pk == active_beam %}Active Beam: {%endif%}{{beam.name}}</h3> |
|
64 | 73 | <table id="abs_pattern{{forloop.counter}}" class="abs"> |
|
65 | 74 | <tr> |
|
66 | 75 | <td> |
|
67 | 76 | <b>North Quarter</b> |
|
68 | 77 | <table class="module"> |
|
69 | 78 | <tr> |
|
70 | 79 | <td title='{{module_messages.1}}'><span {%if beam.pk == active_beam %} {{color_status.1}} {%endif%}>{{beam.get_upvalues.0}}</span></td> |
|
71 | 80 | <td title='{{module_messages.2}}'><span {%if beam.pk == active_beam %} {{color_status.2}} {%endif%}>{{beam.get_upvalues.1}}</span></td> |
|
72 | 81 | <td title='{{module_messages.3}}'><span {%if beam.pk == active_beam %} {{color_status.3}} {%endif%}>{{beam.get_upvalues.2}}</span></td> |
|
73 | 82 | <td title='{{module_messages.4}}'><span {%if beam.pk == active_beam %} {{color_status.4}} {%endif%}>{{beam.get_upvalues.3}}</span></td> |
|
74 | 83 | </tr> |
|
75 | 84 | <tr> |
|
76 | 85 | <td title='{{module_messages.1}}'><span {%if beam.pk == active_beam %} {{color_status.1}} {%endif%}>{{beam.get_downvalues.0}}</span></td> |
|
77 | 86 | <td title='{{module_messages.2}}'><span {%if beam.pk == active_beam %} {{color_status.2}} {%endif%}>{{beam.get_downvalues.1}}</span></td> |
|
78 | 87 | <td title='{{module_messages.3}}'> <span {%if beam.pk == active_beam %} {{color_status.3}} {%endif%}>{{beam.get_downvalues.2}}</span></td> |
|
79 | 88 | <td title='{{module_messages.4}}'> <span {%if beam.pk == active_beam %} {{color_status.4}} {%endif%}>{{beam.get_downvalues.3}}</span></td> |
|
80 | 89 | </tr> |
|
81 | 90 | <tr> |
|
82 | 91 | <td title='{{module_messages.9}}'> <span {%if beam.pk == active_beam %} {{color_status.9}} {%endif%}>{{beam.get_upvalues.8}}</span></td> |
|
83 | 92 | <td title='{{module_messages.10}}'><span {%if beam.pk == active_beam %} {{color_status.10}} {%endif%}>{{beam.get_upvalues.9}}</span></td> |
|
84 | 93 | <td title='{{module_messages.11}}'><span {%if beam.pk == active_beam %} {{color_status.11}} {%endif%}>{{beam.get_upvalues.10}}</span></td> |
|
85 | 94 | <td title='{{module_messages.12}}'><span {%if beam.pk == active_beam %} {{color_status.12}} {%endif%}>{{beam.get_upvalues.11}}</span></td> |
|
86 | 95 | </tr> |
|
87 | 96 | <tr> |
|
88 | 97 | <td title='{{module_messages.9}}'> <span {%if beam.pk == active_beam %} {{color_status.9}} {%endif%}>{{beam.get_downvalues.8}}</span></td> |
|
89 | 98 | <td title='{{module_messages.10}}'><span {%if beam.pk == active_beam %} {{color_status.10}} {%endif%}>{{beam.get_downvalues.9}}</span></td> |
|
90 | 99 | <td title='{{module_messages.11}}'><span {%if beam.pk == active_beam %} {{color_status.11}} {%endif%}>{{beam.get_downvalues.10}}</span></td> |
|
91 | 100 | <td title='{{module_messages.12}}'><span {%if beam.pk == active_beam %} {{color_status.12}} {%endif%}>{{beam.get_downvalues.11}}</span></td> |
|
92 | 101 | </tr> |
|
93 | 102 | <tr> |
|
94 | 103 | <td title='{{module_messages.17}}'><span {%if beam.pk == active_beam %} {{color_status.17}} {%endif%}>{{beam.get_upvalues.16}}</span></td> |
|
95 | 104 | <td title='{{module_messages.18}}'><span {%if beam.pk == active_beam %} {{color_status.18}} {%endif%}>{{beam.get_upvalues.17}}</span></td> |
|
96 | 105 | <td title='{{module_messages.19}}'><span {%if beam.pk == active_beam %} {{color_status.19}} {%endif%}>{{beam.get_upvalues.18}}</span></td> |
|
97 | 106 | <td title='{{module_messages.20}}'><span {%if beam.pk == active_beam %} {{color_status.20}} {%endif%}>{{beam.get_upvalues.19}}</span></td> |
|
98 | 107 | </tr> |
|
99 | 108 | <tr> |
|
100 | 109 | <td title='{{module_messages.17}}'><span {%if beam.pk == active_beam %} {{color_status.17}} {%endif%}>{{beam.get_downvalues.16}}</span></td> |
|
101 | 110 | <td title='{{module_messages.18}}'><span {%if beam.pk == active_beam %} {{color_status.18}} {%endif%}>{{beam.get_downvalues.17}}</span></td> |
|
102 | 111 | <td title='{{module_messages.19}}'><span {%if beam.pk == active_beam %} {{color_status.19}} {%endif%}>{{beam.get_downvalues.18}}</span></td> |
|
103 | 112 | <td title='{{module_messages.20}}'><span {%if beam.pk == active_beam %} {{color_status.20}} {%endif%}>{{beam.get_downvalues.19}}</span></td> |
|
104 | 113 | </tr> |
|
105 | 114 | <tr> |
|
106 | 115 | <td title='{{module_messages.25}}'><span {%if beam.pk == active_beam %} {{color_status.25}} {%endif%}>{{beam.get_upvalues.24}}</span></td> |
|
107 | 116 | <td title='{{module_messages.26}}'><span {%if beam.pk == active_beam %} {{color_status.26}} {%endif%}>{{beam.get_upvalues.25}}</span></td> |
|
108 | 117 | <td title='{{module_messages.27}}'><span {%if beam.pk == active_beam %} {{color_status.27}} {%endif%}>{{beam.get_upvalues.26}}</span></td> |
|
109 | 118 | <td title='{{module_messages.28}}'><span {%if beam.pk == active_beam %} {{color_status.28}} {%endif%}>{{beam.get_upvalues.27}}</span></td> |
|
110 | 119 | </tr> |
|
111 | 120 | <tr> |
|
112 | 121 | <td title='{{module_messages.25}}'><span {%if beam.pk == active_beam %} {{color_status.25}} {%endif%}>{{beam.get_downvalues.24}}</span></td> |
|
113 | 122 | <td title='{{module_messages.26}}'><span {%if beam.pk == active_beam %} {{color_status.26}} {%endif%}>{{beam.get_downvalues.25}}</span></td> |
|
114 | 123 | <td title='{{module_messages.27}}'><span {%if beam.pk == active_beam %} {{color_status.27}} {%endif%}>{{beam.get_downvalues.26}}</span></td> |
|
115 | 124 | <td title='{{module_messages.28}}'><span {%if beam.pk == active_beam %} {{color_status.28}} {%endif%}>{{beam.get_downvalues.27}}</span></td> |
|
116 | 125 | </tr> |
|
117 | 126 | </table> |
|
118 | 127 | </td> |
|
119 | 128 | <td> |
|
120 | 129 | <b>East Quarter</b> |
|
121 | 130 | <table class="module"> |
|
122 | 131 | <tr> |
|
123 | 132 | <td title='{{module_messages.5}}'> <span {%if beam.pk == active_beam %} {{color_status.5}} {%endif%}>{{beam.get_upvalues.4}}</span></td> |
|
124 | 133 | <td title='{{module_messages.6}}'> <span {%if beam.pk == active_beam %} {{color_status.6}} {%endif%}>{{beam.get_upvalues.5}}</span></td> |
|
125 | 134 | <td title='{{module_messages.7}}'> <span {%if beam.pk == active_beam %} {{color_status.7}} {%endif%}>{{beam.get_upvalues.6}}</span></td> |
|
126 | 135 | <td title='{{module_messages.8}}'> <span {%if beam.pk == active_beam %} {{color_status.8}} {%endif%}>{{beam.get_upvalues.7}}</span></td> |
|
127 | 136 | </tr> |
|
128 | 137 | <tr> |
|
129 | 138 | <td title='{{module_messages.5}}'> <span {%if beam.pk == active_beam %} {{color_status.5}} {%endif%}>{{beam.get_downvalues.4}}</span></td> |
|
130 | 139 | <td title='{{module_messages.6}}'> <span {%if beam.pk == active_beam %} {{color_status.6}} {%endif%}>{{beam.get_downvalues.5}}</span></td> |
|
131 | 140 | <td title='{{module_messages.7}}'> <span {%if beam.pk == active_beam %} {{color_status.7}} {%endif%}>{{beam.get_downvalues.6}}</span></td> |
|
132 | 141 | <td title='{{module_messages.8}}'> <span {%if beam.pk == active_beam %} {{color_status.8}} {%endif%}>{{beam.get_downvalues.7}}</span></td> |
|
133 | 142 | </tr> |
|
134 | 143 | <tr> |
|
135 | 144 | <td title='{{module_messages.13}}'><span {%if beam.pk == active_beam %} {{color_status.13}} {%endif%}>{{beam.get_upvalues.12}}</span></td> |
|
136 | 145 | <td title='{{module_messages.14}}'><span {%if beam.pk == active_beam %} {{color_status.14}} {%endif%}>{{beam.get_upvalues.13}}</span></td> |
|
137 | 146 | <td title='{{module_messages.15}}'><span {%if beam.pk == active_beam %} {{color_status.15}} {%endif%}>{{beam.get_upvalues.14}}</span></td> |
|
138 | 147 | <td title='{{module_messages.16}}'><span {%if beam.pk == active_beam %} {{color_status.16}} {%endif%}>{{beam.get_upvalues.15}}</span></td> |
|
139 | 148 | </tr> |
|
140 | 149 | <tr> |
|
141 | 150 | <td title='{{module_messages.13}}'><span {%if beam.pk == active_beam %} {{color_status.13}} {%endif%}>{{beam.get_downvalues.12}}</span></td> |
|
142 | 151 | <td title='{{module_messages.14}}'><span {%if beam.pk == active_beam %} {{color_status.14}} {%endif%}>{{beam.get_downvalues.13}}</span></td> |
|
143 | 152 | <td title='{{module_messages.15}}'><span {%if beam.pk == active_beam %} {{color_status.15}} {%endif%}>{{beam.get_downvalues.14}}</span></td> |
|
144 | 153 | <td title='{{module_messages.16}}'><span {%if beam.pk == active_beam %} {{color_status.16}} {%endif%}>{{beam.get_downvalues.15}}</span></td> |
|
145 | 154 | </tr> |
|
146 | 155 | <tr> |
|
147 | 156 | <td title='{{module_messages.21}}'><span {%if beam.pk == active_beam %} {{color_status.21}} {%endif%}>{{beam.get_upvalues.20}}</span></td> |
|
148 | 157 | <td title='{{module_messages.22}}'><span {%if beam.pk == active_beam %} {{color_status.22}} {%endif%}>{{beam.get_upvalues.21}}</span></td> |
|
149 | 158 | <td title='{{module_messages.23}}'><span {%if beam.pk == active_beam %} {{color_status.23}} {%endif%}>{{beam.get_upvalues.22}}</span></td> |
|
150 | 159 | <td title='{{module_messages.24}}'><span {%if beam.pk == active_beam %} {{color_status.24}} {%endif%}>{{beam.get_upvalues.23}}</span></td> |
|
151 | 160 | </tr> |
|
152 | 161 | <tr> |
|
153 | 162 | <td title='{{module_messages.21}}'><span {%if beam.pk == active_beam %} {{color_status.21}} {%endif%}>{{beam.get_downvalues.20}}</span></td> |
|
154 | 163 | <td title='{{module_messages.22}}'><span {%if beam.pk == active_beam %} {{color_status.22}} {%endif%}>{{beam.get_downvalues.21}}</span></td> |
|
155 | 164 | <td title='{{module_messages.23}}'><span {%if beam.pk == active_beam %} {{color_status.23}} {%endif%}>{{beam.get_downvalues.22}}</span></td> |
|
156 | 165 | <td title='{{module_messages.24}}'><span {%if beam.pk == active_beam %} {{color_status.24}} {%endif%}>{{beam.get_downvalues.23}}</span></td> |
|
157 | 166 | </tr> |
|
158 | 167 | <tr> |
|
159 | 168 | <td title='{{module_messages.29}}'><span {%if beam.pk == active_beam %} {{color_status.29}} {%endif%}>{{beam.get_upvalues.28}}</span></td> |
|
160 | 169 | <td title='{{module_messages.30}}'><span {%if beam.pk == active_beam %} {{color_status.30}} {%endif%}>{{beam.get_upvalues.29}}</span></td> |
|
161 | 170 | <td title='{{module_messages.31}}'><span {%if beam.pk == active_beam %} {{color_status.31}} {%endif%}>{{beam.get_upvalues.30}}</span></td> |
|
162 | 171 | <td title='{{module_messages.32}}'><span {%if beam.pk == active_beam %} {{color_status.32}} {%endif%}>{{beam.get_upvalues.31}}</span></td> |
|
163 | 172 | </tr> |
|
164 | 173 | <tr> |
|
165 | 174 | <td title='{{module_messages.29}}'><span {%if beam.pk == active_beam %} {{color_status.29}} {%endif%}>{{beam.get_downvalues.28}}</span></td> |
|
166 | 175 | <td title='{{module_messages.30}}'><span {%if beam.pk == active_beam %} {{color_status.30}} {%endif%}>{{beam.get_downvalues.29}}</span></td> |
|
167 | 176 | <td title='{{module_messages.31}}'><span {%if beam.pk == active_beam %} {{color_status.31}} {%endif%}>{{beam.get_downvalues.30}}</span></td> |
|
168 | 177 | <td title='{{module_messages.32}}'><span {%if beam.pk == active_beam %} {{color_status.32}} {%endif%}>{{beam.get_downvalues.31}}</span></td> |
|
169 | 178 | </tr> |
|
170 | 179 | </table> |
|
171 | 180 | </td> |
|
172 | 181 | </tr> |
|
173 | 182 | <tr> |
|
174 | 183 | <td> |
|
175 | 184 | <b>West Quarter</b> |
|
176 | 185 | <table class="module"> |
|
177 | 186 | <tr> |
|
178 | 187 | <td title='{{module_messages.33}}'><span {%if beam.pk == active_beam %} {{color_status.33}} {%endif%}>{{beam.get_upvalues.32}}</span></td> |
|
179 | 188 | <td title='{{module_messages.34}}'><span {%if beam.pk == active_beam %} {{color_status.34}} {%endif%}>{{beam.get_upvalues.33}}</span></td> |
|
180 | 189 | <td title='{{module_messages.35}}'><span {%if beam.pk == active_beam %} {{color_status.35}} {%endif%}>{{beam.get_upvalues.34}}</span></td> |
|
181 | 190 | <td title='{{module_messages.36}}'><span {%if beam.pk == active_beam %} {{color_status.36}} {%endif%}>{{beam.get_upvalues.35}}</span></td> |
|
182 | 191 | </tr> |
|
183 | 192 | <tr> |
|
184 | 193 | <td title='{{module_messages.33}}'><span {%if beam.pk == active_beam %} {{color_status.33}} {%endif%}>{{beam.get_downvalues.32}}</span></td> |
|
185 | 194 | <td title='{{module_messages.34}}'><span {%if beam.pk == active_beam %} {{color_status.34}} {%endif%}>{{beam.get_downvalues.33}}</span></td> |
|
186 | 195 | <td title='{{module_messages.35}}'><span {%if beam.pk == active_beam %} {{color_status.35}} {%endif%}>{{beam.get_downvalues.34}}</span></td> |
|
187 | 196 | <td title='{{module_messages.36}}'><span {%if beam.pk == active_beam %} {{color_status.36}} {%endif%}>{{beam.get_downvalues.35}}</span></td> |
|
188 | 197 | </tr> |
|
189 | 198 | <tr> |
|
190 | 199 | <td title='{{module_messages.41}}'><span {%if beam.pk == active_beam %} {{color_status.41}} {%endif%}>{{beam.get_upvalues.40}}</span></td> |
|
191 | 200 | <td title='{{module_messages.42}}'><span {%if beam.pk == active_beam %} {{color_status.42}} {%endif%}>{{beam.get_upvalues.41}}</span></td> |
|
192 | 201 | <td title='{{module_messages.43}}'><span {%if beam.pk == active_beam %} {{color_status.43}} {%endif%}>{{beam.get_upvalues.42}}</span></td> |
|
193 | 202 | <td title='{{module_messages.44}}'><span {%if beam.pk == active_beam %} {{color_status.44}} {%endif%}>{{beam.get_upvalues.43}}</span></td> |
|
194 | 203 | </tr> |
|
195 | 204 | <tr> |
|
196 | 205 | <td title='{{module_messages.41}}'><span {%if beam.pk == active_beam %} {{color_status.41}} {%endif%}>{{beam.get_downvalues.40}}</span></td> |
|
197 | 206 | <td title='{{module_messages.42}}'><span {%if beam.pk == active_beam %} {{color_status.42}} {%endif%}>{{beam.get_downvalues.41}}</span></td> |
|
198 | 207 | <td title='{{module_messages.43}}'><span {%if beam.pk == active_beam %} {{color_status.43}} {%endif%}>{{beam.get_downvalues.42}}</span></td> |
|
199 | 208 | <td title='{{module_messages.44}}'><span {%if beam.pk == active_beam %} {{color_status.44}} {%endif%}>{{beam.get_downvalues.43}}</span></td> |
|
200 | 209 | </tr> |
|
201 | 210 | <tr> |
|
202 | 211 | <td title='{{module_messages.49}}'><span {%if beam.pk == active_beam %} {{color_status.49}} {%endif%}>{{beam.get_upvalues.48}}</span></td> |
|
203 | 212 | <td title='{{module_messages.51}}'><span {%if beam.pk == active_beam %} {{color_status.50}} {%endif%}>{{beam.get_upvalues.49}}</span></td> |
|
204 | 213 | <td title='{{module_messages.52}}'><span {%if beam.pk == active_beam %} {{color_status.51}} {%endif%}>{{beam.get_upvalues.50}}</span></td> |
|
205 | 214 | <td title='{{module_messages.53}}'><span {%if beam.pk == active_beam %} {{color_status.52}} {%endif%}>{{beam.get_upvalues.51}}</span></td> |
|
206 | 215 | </tr> |
|
207 | 216 | <tr> |
|
208 | 217 | <td title='{{module_messages.49}}'><span {%if beam.pk == active_beam %} {{color_status.49}} {%endif%}>{{beam.get_downvalues.48}}</span></td> |
|
209 | 218 | <td title='{{module_messages.50}}'><span {%if beam.pk == active_beam %} {{color_status.50}} {%endif%}>{{beam.get_downvalues.49}}</span></td> |
|
210 | 219 | <td title='{{module_messages.51}}'><span {%if beam.pk == active_beam %} {{color_status.51}} {%endif%}>{{beam.get_downvalues.50}}</span></td> |
|
211 | 220 | <td title='{{module_messages.52}}'><span {%if beam.pk == active_beam %} {{color_status.52}} {%endif%}>{{beam.get_downvalues.51}}</span></td> |
|
212 | 221 | </tr> |
|
213 | 222 | <tr> |
|
214 | 223 | <td title='{{module_messages.57}}'><span {%if beam.pk == active_beam %} {{color_status.57}} {%endif%}>{{beam.get_upvalues.56}}</span></td> |
|
215 | 224 | <td title='{{module_messages.58}}'><span {%if beam.pk == active_beam %} {{color_status.58}} {%endif%}>{{beam.get_upvalues.57}}</span></td> |
|
216 | 225 | <td title='{{module_messages.59}}'><span {%if beam.pk == active_beam %} {{color_status.59}} {%endif%}>{{beam.get_upvalues.58}}</span></td> |
|
217 | 226 | <td title='{{module_messages.60}}'><span {%if beam.pk == active_beam %} {{color_status.60}} {%endif%}>{{beam.get_upvalues.59}}</span></td> |
|
218 | 227 | </tr> |
|
219 | 228 | <tr> |
|
220 | 229 | <td title='{{module_messages.57}}'><span {%if beam.pk == active_beam %} {{color_status.57}} {%endif%}>{{beam.get_downvalues.56}}</span></td> |
|
221 | 230 | <td title='{{module_messages.58}}'><span {%if beam.pk == active_beam %} {{color_status.58}} {%endif%}>{{beam.get_downvalues.57}}</span></td> |
|
222 | 231 | <td title='{{module_messages.59}}'><span {%if beam.pk == active_beam %} {{color_status.59}} {%endif%}>{{beam.get_downvalues.58}}</span></td> |
|
223 | 232 | <td title='{{module_messages.60}}'><span {%if beam.pk == active_beam %} {{color_status.60}} {%endif%}>{{beam.get_downvalues.59}}</span></td> |
|
224 | 233 | </tr> |
|
225 | 234 | </table> |
|
226 | 235 | </td> |
|
227 | 236 | <td> |
|
228 | 237 | <b>South Quarter</b> |
|
229 | 238 | <table class="module"> |
|
230 | 239 | <tr> |
|
231 | 240 | <td title='{{module_messages.37}}'><span {%if beam.pk == active_beam %} {{color_status.37}} {%endif%}>{{beam.get_upvalues.36}}</span></td> |
|
232 | 241 | <td title='{{module_messages.38}}'><span {%if beam.pk == active_beam %} {{color_status.38}} {%endif%}>{{beam.get_upvalues.37}}</span></td> |
|
233 | 242 | <td title='{{module_messages.39}}'><span {%if beam.pk == active_beam %} {{color_status.39}} {%endif%}>{{beam.get_upvalues.38}}</span></td> |
|
234 | 243 | <td title='{{module_messages.40}}'><span {%if beam.pk == active_beam %} {{color_status.40}} {%endif%}>{{beam.get_upvalues.39}}</span></td> |
|
235 | 244 | </tr> |
|
236 | 245 | <tr> |
|
237 | 246 | <td title='{{module_messages.37}}'><span {%if beam.pk == active_beam %} {{color_status.37}} {%endif%}>{{beam.get_downvalues.36}}</span></td> |
|
238 | 247 | <td title='{{module_messages.38}}'><span {%if beam.pk == active_beam %} {{color_status.38}} {%endif%}>{{beam.get_downvalues.37}}</span></td> |
|
239 | 248 | <td title='{{module_messages.39}}'><span {%if beam.pk == active_beam %} {{color_status.39}} {%endif%}>{{beam.get_downvalues.38}}</span></td> |
|
240 | 249 | <td title='{{module_messages.40}}'><span {%if beam.pk == active_beam %} {{color_status.40}} {%endif%}>{{beam.get_downvalues.39}}</span></td> |
|
241 | 250 | </tr> |
|
242 | 251 | <tr> |
|
243 | 252 | <td title='{{module_messages.45}}'><span {%if beam.pk == active_beam %} {{color_status.45}} {%endif%}>{{beam.get_upvalues.44}}</span></td> |
|
244 | 253 | <td title='{{module_messages.46}}'><span {%if beam.pk == active_beam %} {{color_status.46}} {%endif%}>{{beam.get_upvalues.45}}</span></td> |
|
245 | 254 | <td title='{{module_messages.47}}'><span {%if beam.pk == active_beam %} {{color_status.47}} {%endif%}>{{beam.get_upvalues.46}}</span></td> |
|
246 | 255 | <td title='{{module_messages.48}}'><span {%if beam.pk == active_beam %} {{color_status.48}} {%endif%}>{{beam.get_upvalues.47}}</span></td> |
|
247 | 256 | </tr> |
|
248 | 257 | <tr> |
|
249 | 258 | <td title='{{module_messages.45}}'><span {%if beam.pk == active_beam %} {{color_status.45}} {%endif%}>{{beam.get_downvalues.44}}</span></td> |
|
250 | 259 | <td title='{{module_messages.46}}'><span {%if beam.pk == active_beam %} {{color_status.46}} {%endif%}>{{beam.get_downvalues.45}}</span></td> |
|
251 | 260 | <td title='{{module_messages.47}}'><span {%if beam.pk == active_beam %} {{color_status.47}} {%endif%}>{{beam.get_downvalues.46}}</span></td> |
|
252 | 261 | <td title='{{module_messages.48}}'><span {%if beam.pk == active_beam %} {{color_status.48}} {%endif%}>{{beam.get_downvalues.47}}</span></td> |
|
253 | 262 | </tr> |
|
254 | 263 | <tr> |
|
255 | 264 | <td title='{{module_messages.53}}'><span {%if beam.pk == active_beam %} {{color_status.53}} {%endif%}>{{beam.get_upvalues.52}}</span></td> |
|
256 | 265 | <td title='{{module_messages.54}}'><span {%if beam.pk == active_beam %} {{color_status.54}} {%endif%}>{{beam.get_upvalues.53}}</span></td> |
|
257 | 266 | <td title='{{module_messages.55}}'><span {%if beam.pk == active_beam %} {{color_status.55}} {%endif%}>{{beam.get_upvalues.54}}</span></td> |
|
258 | 267 | <td title='{{module_messages.56}}'><span {%if beam.pk == active_beam %} {{color_status.56}} {%endif%}>{{beam.get_upvalues.55}}</span></td> |
|
259 | 268 | </tr> |
|
260 | 269 | <tr> |
|
261 | 270 | <td title='{{module_messages.53}}'><span {%if beam.pk == active_beam %} {{color_status.53}} {%endif%}>{{beam.get_downvalues.52}}</span></td> |
|
262 | 271 | <td title='{{module_messages.54}}'><span {%if beam.pk == active_beam %} {{color_status.54}} {%endif%}>{{beam.get_downvalues.53}}</span></td> |
|
263 | 272 | <td title='{{module_messages.55}}'><span {%if beam.pk == active_beam %} {{color_status.55}} {%endif%}>{{beam.get_downvalues.54}}</span></td> |
|
264 | 273 | <td title='{{module_messages.56}}'><span {%if beam.pk == active_beam %} {{color_status.56}} {%endif%}>{{beam.get_downvalues.55}}</span></td> |
|
265 | 274 | </tr> |
|
266 | 275 | <tr> |
|
267 | 276 | <td title='{{module_messages.61}}'><span {%if beam.pk == active_beam %} {{color_status.61}} {%endif%}>{{beam.get_upvalues.60}}</span></td> |
|
268 | 277 | <td title='{{module_messages.62}}'><span {%if beam.pk == active_beam %} {{color_status.62}} {%endif%}>{{beam.get_upvalues.61}}</span></td> |
|
269 | 278 | <td title='{{module_messages.63}}'><span {%if beam.pk == active_beam %} {{color_status.63}} {%endif%}>{{beam.get_upvalues.62}}</span></td> |
|
270 | 279 | <td title='{{module_messages.64}}'><span {%if beam.pk == active_beam %} {{color_status.64}} {%endif%}>{{beam.get_upvalues.63}}</span></td> |
|
271 | 280 | </tr> |
|
272 | 281 | <tr> |
|
273 | 282 | <td title='{{module_messages.61}}'><span {%if beam.pk == active_beam %} {{color_status.61}} {%endif%}>{{beam.get_downvalues.60}}</span></td> |
|
274 | 283 | <td title='{{module_messages.62}}'><span {%if beam.pk == active_beam %} {{color_status.62}} {%endif%}>{{beam.get_downvalues.61}}</span></td> |
|
275 | 284 | <td title='{{module_messages.63}}'><span {%if beam.pk == active_beam %} {{color_status.63}} {%endif%}>{{beam.get_downvalues.62}}</span></td> |
|
276 | 285 | <td title='{{module_messages.64}}'><span {%if beam.pk == active_beam %} {{color_status.64}} {%endif%}>{{beam.get_downvalues.63}}</span></td> |
|
277 | 286 | </tr> |
|
278 | 287 | </table> |
|
279 | 288 | </td> |
|
280 | 289 | </tr> |
|
281 | 290 | </table> |
|
282 | 291 | |
|
292 | <!-- <meta id="configuraciones_down" data-playlist="{{ beam.get_downvalues }}"> | |
|
293 | <meta id="configuraciones_up" data-playlist="{{ beam.get_upvalues }}"> | |
|
294 | <meta id="sda" data-toggle="" --> | |
|
295 | ||
|
283 | 296 | {% if beam.id == active_beam %} |
|
284 | 297 | <table class="legend"> |
|
285 | 298 | <tr> |
|
286 | 299 | <th>Legend</th> |
|
287 | 300 | </tr> |
|
288 | 301 | <tr> |
|
289 | 302 | <td class="text-warning">Connected</td> |
|
290 | 303 | </tr> |
|
291 | 304 | <tr> |
|
292 | 305 | <td class="text-success">Running</td> |
|
293 | 306 | </tr> |
|
294 | 307 | <tr> |
|
295 | 308 | <td class="text-info">Mismath</td> |
|
296 | 309 | </tr> |
|
297 | 310 | <tr> |
|
298 | 311 | <td class="text-danger">Disconnected</td> |
|
299 | 312 | </tr> |
|
300 | 313 | </table> |
|
301 | 314 | {% else %} |
|
302 | 315 | <div style="vertical-align: top; display:inline-block;"> |
|
303 | 316 | <button id="send_beam{{forloop.counter}}" type="button" class="btn btn-default"> |
|
304 | 317 |
|
|
305 | 318 |
|
|
319 | <br><br><br> | |
|
320 | <button id="change_beam_mqtt{{forloop.counter}}" type="button" class="btn btn-default"> | |
|
321 | <span class="fas fa-external-link-square-alt" aria-hidden="true"></span> | |
|
322 | Change Beam MQTT</button> | |
|
306 | 323 | </div> |
|
307 | 324 | {% endif %} |
|
308 | 325 | </div> |
|
309 | 326 | {% endfor %} |
|
310 | 327 | </div> |
|
311 | 328 | </div> |
|
312 | 329 | |
|
313 | 330 | |
|
314 | 331 | {% else %} |
|
315 | 332 | <p style="color:#b4bcc2; margin-left: 5%;"> |
|
316 | 333 | <i>No Beams...</i> |
|
317 | 334 | </p> |
|
318 | 335 | {% endif %} |
|
319 | 336 | {% endblock extra-content %} |
|
337 | ||
|
320 | 338 | {% block extra-js%} |
|
321 | 339 | <script> |
|
322 | 340 | $(document).ready(function () { |
|
323 | 341 | |
|
342 | var socket = io.connect('http://' + document.domain + ':' + location.port); | |
|
343 | ||
|
344 | socket.on('connect', function(data) { | |
|
345 | console.log('Connecting... OK'); | |
|
346 | }) | |
|
347 | ||
|
348 | socket.on('abs_ws', function(data) { | |
|
349 | console.log('ingresamos'); | |
|
350 | console.log(data.msg); | |
|
351 | var text = data['msg']; | |
|
352 | // $('#chatLog').val(text); | |
|
353 | ||
|
354 | if(data.msg=="b\'Hola\'"){console.log('Hola_amigo')}; | |
|
355 | }) | |
|
356 | ||
|
357 | ||
|
324 | 358 |
|
|
325 | 359 | |
|
326 | 360 |
|
|
327 | 361 |
|
|
362 | $("#change_beam_mqtt{{forloop.counter}}").prop('disabled', true) | |
|
328 | 363 |
|
|
329 | 364 |
|
|
330 | 365 |
|
|
331 | 366 |
|
|
367 | ||
|
368 | a=$("#change_beam_mqtt{{forloop.counter}}") | |
|
369 | a.click(function () { | |
|
370 | info="change_beam_mqtt{{forloop.counter}}" | |
|
371 | socket.emit('change_beam',{data:info}) | |
|
372 | }); | |
|
373 | ||
|
332 | 374 |
|
|
333 | 375 | |
|
334 | 376 |
|
|
335 | 377 | |
|
336 | 378 | |
|
337 | 379 |
|
|
380 | ||
|
338 | 381 | </script> |
|
382 | ||
|
383 | ||
|
339 | 384 | {% endblock %} |
@@ -1,445 +1,512 | |||
|
1 | 1 | from django.shortcuts import render |
|
2 | 2 | from django.template import RequestContext |
|
3 | 3 | from django.shortcuts import redirect, render, get_object_or_404 |
|
4 | 4 | from django.contrib import messages |
|
5 | 5 | from django.conf import settings |
|
6 | 6 | from django.http import HttpResponse |
|
7 | 7 | from django.urls import reverse |
|
8 | 8 | from django.views.decorators.csrf import csrf_exempt |
|
9 | 9 | from django.utils.safestring import mark_safe |
|
10 | 10 | |
|
11 | 11 | from datetime import datetime |
|
12 | 12 | from time import sleep |
|
13 | 13 | import os |
|
14 | 14 | import io |
|
15 | 15 | |
|
16 | 16 | from apps.main.models import Device, Configuration, Experiment |
|
17 | 17 | from apps.main.views import sidebar |
|
18 | 18 | |
|
19 | 19 | from .models import ABSConfiguration, ABSBeam |
|
20 | 20 | from .forms import ABSConfigurationForm, ABSBeamEditForm, ABSBeamAddForm, ABSImportForm |
|
21 | 21 | |
|
22 | 22 | from .utils.overJroShow import overJroShow |
|
23 | 23 | #from .utils.OverJRO import OverJRO |
|
24 | 24 | #Create your views here. |
|
25 | 25 | import json, ast |
|
26 | 26 | |
|
27 | from .mqtt import client as mqtt_client | |
|
28 | from radarsys.socketconfig import sio as sio | |
|
27 | 29 | |
|
28 | 30 | def get_values_from_form(form_data): |
|
29 | 31 | |
|
30 | 32 | sublistup = [] |
|
31 | 33 | sublistdown = [] |
|
32 | 34 | subtxlistup = [] |
|
33 | 35 | subtxlistdown = [] |
|
34 | 36 | subrxlistup = [] |
|
35 | 37 | subrxlistdown = [] |
|
36 | 38 | |
|
37 | 39 | up_values_list = [] |
|
38 | 40 | down_values_list = [] |
|
39 | 41 | up_txvalues_list = [] |
|
40 | 42 | down_txvalues_list = [] |
|
41 | 43 | up_rxvalues_list = [] |
|
42 | 44 | down_rxvalues_list = [] |
|
43 | 45 | |
|
44 | 46 | values_list = {} |
|
45 | 47 | cont = 1 |
|
46 | 48 | |
|
47 | 49 | for i in range(1,65): |
|
48 | 50 | x = float(form_data['abs_up'+str(i)]) |
|
49 | 51 | y = float(form_data['abs_down'+str(i)]) |
|
50 | 52 | sublistup.append(x) |
|
51 | 53 | sublistdown.append(y) |
|
52 | 54 | |
|
53 | 55 | if str(i) in form_data.getlist('uptx_checks'): |
|
54 | 56 | subtxlistup.append(1) |
|
55 | 57 | else: |
|
56 | 58 | subtxlistup.append(0) |
|
57 | 59 | if str(i) in form_data.getlist('downtx_checks'): |
|
58 | 60 | subtxlistdown.append(1) |
|
59 | 61 | else: |
|
60 | 62 | subtxlistdown.append(0) |
|
61 | 63 | |
|
62 | 64 | if str(i) in form_data.getlist('uprx_checks'): |
|
63 | 65 | subrxlistup.append(1) |
|
64 | 66 | else: |
|
65 | 67 | subrxlistup.append(0) |
|
66 | 68 | if str(i) in form_data.getlist('downrx_checks'): |
|
67 | 69 | subrxlistdown.append(1) |
|
68 | 70 | else: |
|
69 | 71 | subrxlistdown.append(0) |
|
70 | 72 | |
|
71 | 73 | cont = cont+1 |
|
72 | 74 | |
|
73 | 75 | if cont == 9: |
|
74 | 76 | up_values_list.append(sublistup) |
|
75 | 77 | down_values_list.append(sublistdown) |
|
76 | 78 | sublistup = [] |
|
77 | 79 | sublistdown = [] |
|
78 | 80 | |
|
79 | 81 | up_txvalues_list.append(subtxlistup) |
|
80 | 82 | down_txvalues_list.append(subtxlistdown) |
|
81 | 83 | subtxlistup = [] |
|
82 | 84 | subtxlistdown = [] |
|
83 | 85 | up_rxvalues_list.append(subrxlistup) |
|
84 | 86 | down_rxvalues_list.append(subrxlistdown) |
|
85 | 87 | subrxlistup = [] |
|
86 | 88 | subrxlistdown = [] |
|
87 | 89 | cont = 1 |
|
88 | 90 | |
|
89 | 91 | |
|
90 | 92 | list_uesup = [] |
|
91 | 93 | list_uesdown = [] |
|
92 | 94 | for i in range(1,5): |
|
93 | 95 | if form_data['ues_up'+str(i)] == '': |
|
94 | 96 | list_uesup.append(0.0) |
|
95 | 97 | else: |
|
96 | 98 | list_uesup.append(float(form_data['ues_up'+str(i)])) |
|
97 | 99 | |
|
98 | 100 | if form_data['ues_down'+str(i)] == '': |
|
99 | 101 | list_uesdown.append(0.0) |
|
100 | 102 | else: |
|
101 | 103 | list_uesdown.append(float(form_data['ues_down'+str(i)])) |
|
102 | 104 | |
|
103 | 105 | onlyrx_list = form_data.getlist('onlyrx') |
|
104 | 106 | only_rx = {} |
|
105 | 107 | if '1' in onlyrx_list: |
|
106 | 108 | only_rx['up'] = True |
|
107 | 109 | else: |
|
108 | 110 | only_rx['up'] = False |
|
109 | 111 | if '2' in onlyrx_list: |
|
110 | 112 | only_rx['down'] = True |
|
111 | 113 | else: |
|
112 | 114 | only_rx['down'] = False |
|
113 | 115 | |
|
114 | 116 | antenna = {'antenna_up': up_values_list, 'antenna_down': down_values_list} |
|
115 | 117 | tx = {'up': up_txvalues_list, 'down': down_txvalues_list} |
|
116 | 118 | rx = {'up': up_rxvalues_list, 'down': down_rxvalues_list} |
|
117 | 119 | ues = {'up': list_uesup, 'down': list_uesdown} |
|
118 | 120 | name = str(form_data['beam_name']) |
|
119 | 121 | |
|
120 | 122 | beam_data = {'name': name, 'antenna': antenna, 'tx': tx, 'rx': rx, 'ues': ues, 'only_rx': only_rx} |
|
121 | 123 | |
|
122 | 124 | return beam_data |
|
123 | 125 | |
|
124 | 126 | |
|
125 | 127 | def abs_conf(request, id_conf): |
|
126 | 128 | |
|
127 | 129 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
128 | 130 | beams = ABSBeam.objects.filter(abs_conf=conf) |
|
129 | 131 | #------------Colors for Active Beam:------------- |
|
130 | 132 | all_status = {} |
|
131 | 133 | module_messages = json.loads(conf.module_messages) |
|
132 | 134 | |
|
133 | 135 | color_status = {} |
|
134 | 136 | for i, status in enumerate(conf.module_status): |
|
135 | 137 | if status == '3': #Running background-color: #00cc00; |
|
136 | 138 | all_status['{}'.format(i+1)] = 2 |
|
137 | 139 | color_status['{}'.format(i+1)] = 'class=text-success'#'bgcolor=#00cc00' |
|
138 | 140 | elif status == '2': |
|
139 | 141 | all_status['{}'.format(i+1)] = 1 |
|
140 | 142 | color_status['{}'.format(i+1)] = 'class=text-info' |
|
141 | 143 | elif status == '1': #Connected background-color: #ee902c; |
|
142 | 144 | all_status['{}'.format(i+1)] = 1 |
|
143 | 145 | color_status['{}'.format(i+1)] = 'class=text-warning'#'bgcolor=#ee902c' |
|
144 | 146 | else: #Disconnected background-color: #ff0000; |
|
145 | 147 | all_status['{}'.format(i+1)] = 0 |
|
146 | 148 | color_status['{}'.format(i+1)] = 'class=text-danger'#'bgcolor=#FF0000' |
|
147 | 149 | #------------------------------------------------ |
|
148 | 150 | |
|
149 | 151 | kwargs = {} |
|
150 | 152 | kwargs['connected_modules'] = str(conf.connected_modules())+'/64' |
|
151 | 153 | kwargs['dev_conf'] = conf |
|
152 | 154 | |
|
153 | 155 | if conf.operation_mode == 0: |
|
154 | 156 | kwargs['dev_conf_keys'] = ['label', 'operation_mode'] |
|
155 | 157 | else: |
|
156 | 158 | kwargs['dev_conf_keys'] = ['label', 'operation_mode', 'operation_value'] |
|
157 | 159 | |
|
158 | 160 | kwargs['title'] = 'ABS Configuration' |
|
159 | 161 | kwargs['suptitle'] = 'Details' |
|
160 | 162 | kwargs['button'] = 'Edit Configuration' |
|
161 | 163 | |
|
162 | 164 | if conf.active_beam != 0: |
|
163 | 165 | kwargs['active_beam'] = int(conf.active_beam) |
|
164 | 166 | |
|
165 | 167 | kwargs['beams'] = beams |
|
166 | 168 | kwargs['modules_status'] = all_status |
|
167 | 169 | kwargs['color_status'] = color_status |
|
168 | 170 | kwargs['module_messages'] = module_messages |
|
169 | 171 | ###### SIDEBAR ###### |
|
170 | 172 | kwargs.update(sidebar(conf=conf)) |
|
171 | 173 | |
|
172 | 174 | return render(request, 'abs_conf.html', kwargs) |
|
173 | 175 | |
|
174 | 176 | |
|
175 | 177 | def abs_conf_edit(request, id_conf): |
|
176 | 178 | |
|
177 | 179 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
178 | 180 | |
|
179 | 181 | beams = ABSBeam.objects.filter(abs_conf=conf) |
|
180 | 182 | |
|
181 | 183 | if request.method=='GET': |
|
182 | 184 | form = ABSConfigurationForm(instance=conf) |
|
183 | 185 | |
|
184 | 186 | if request.method=='POST': |
|
185 | 187 | form = ABSConfigurationForm(request.POST, instance=conf) |
|
186 | 188 | |
|
187 | 189 | if form.is_valid(): |
|
188 | 190 | conf = form.save(commit=False) |
|
189 | 191 | conf.save() |
|
190 | 192 | return redirect('url_abs_conf', id_conf=conf.id) |
|
191 | 193 | |
|
192 | 194 | ###### SIDEBAR ###### |
|
193 | 195 | kwargs = {} |
|
194 | 196 | |
|
195 | 197 | kwargs['dev_conf'] = conf |
|
196 | 198 | #kwargs['id_dev'] = conf.id |
|
197 | 199 | kwargs['id_conf'] = conf.id |
|
198 | 200 | kwargs['form'] = form |
|
199 | 201 | kwargs['abs_beams'] = beams |
|
200 | 202 | kwargs['title'] = 'Device Configuration' |
|
201 | 203 | kwargs['suptitle'] = 'Edit' |
|
202 | 204 | kwargs['button'] = 'Save' |
|
203 | 205 | |
|
204 | 206 | kwargs['edit'] = True |
|
205 | 207 | |
|
206 | 208 | return render(request, 'abs_conf_edit.html', kwargs) |
|
207 | 209 | |
|
208 | 210 | @csrf_exempt |
|
209 | 211 | def abs_conf_alert(request): |
|
210 | 212 | |
|
211 | 213 | if request.method == 'POST': |
|
212 | 214 | print (request.POST) |
|
213 | 215 | return HttpResponse(json.dumps({'result':1}), content_type='application/json') |
|
214 | 216 | else: |
|
215 | 217 | return redirect('index') |
|
216 | 218 | |
|
217 | 219 | |
|
218 | 220 | def import_file(request, id_conf): |
|
219 | 221 | |
|
220 | 222 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
221 | 223 | if request.method=='POST': |
|
222 | 224 | form = ABSImportForm(request.POST, request.FILES) |
|
223 | 225 | if form.is_valid(): |
|
224 | 226 | try: |
|
225 | 227 | parms = conf.import_from_file(request.FILES['file_name']) |
|
226 | 228 | |
|
227 | 229 | if parms: |
|
228 | 230 | conf.update_from_file(parms) |
|
229 | 231 | messages.success(request, 'Configuration "%s" loaded succesfully' % request.FILES['file_name']) |
|
230 | 232 | return redirect(conf.get_absolute_url_edit()) |
|
231 | 233 | |
|
232 | 234 | except Exception as e: |
|
233 | 235 | messages.error(request, 'Error parsing file: "%s" - %s' % (request.FILES['file_name'], e)) |
|
234 | 236 | |
|
235 | 237 | else: |
|
236 | 238 | messages.warning(request, 'Your current configuration will be replaced') |
|
237 | 239 | form = ABSImportForm() |
|
238 | 240 | |
|
239 | 241 | kwargs = {} |
|
240 | 242 | kwargs['form'] = form |
|
241 | 243 | kwargs['title'] = 'ABS Configuration' |
|
242 | 244 | kwargs['suptitle'] = 'Import file' |
|
243 | 245 | kwargs['button'] = 'Upload' |
|
244 | 246 | kwargs['previous'] = conf.get_absolute_url() |
|
245 | 247 | |
|
246 | 248 | return render(request, 'abs_import.html', kwargs) |
|
247 | 249 | |
|
248 | 250 | |
|
251 | # def send_mqtt(request,id_conf): | |
|
252 | ||
|
253 | # # conf = get_object_or_404(ABSConfiguration, pk=id_conf) | |
|
254 | ||
|
255 | # # abs_mqtt = Configuration.objects.filter(pk=conf.device.conf_active).first() | |
|
256 | # # if abs_mqtt!=conf: | |
|
257 | # # url_mqtt = '#' if abs is None else abs.get_absolute_url() | |
|
258 | # # label_mqtt = 'None' if abs is None else abs.label | |
|
259 | # # messages.warning( | |
|
260 | # # request, | |
|
261 | # # mark_safe('The current configuration has not been written in the modules, the active configuration is <a href="{}">{}</a>'.format( | |
|
262 | # # url_mqtt, | |
|
263 | # # label_mqtt | |
|
264 | # # )) | |
|
265 | # # ) | |
|
266 | # # return redirect(conf.get_absolute_url()) | |
|
267 | ||
|
268 | # # beam = get_object_or_404(ABSBeam, pk=id_beam) | |
|
269 | ||
|
270 | # conf = get_object_or_404(ABSConfiguration, pk=id_conf) | |
|
271 | ||
|
272 | # mqtt_client.publish('abs/beams_up', 'Hola up') | |
|
273 | # mqtt_client.publish('abs/beams_down', 'Hola down') | |
|
274 | ||
|
275 | # kwargs = { | |
|
276 | # 'title': 'ABS', | |
|
277 | # 'suptitle': conf.label, | |
|
278 | # 'message': 'Are you sure you want to write ABS Beam?', | |
|
279 | # 'delete': False | |
|
280 | # } | |
|
281 | # kwargs['menu_configurations'] = 'active' | |
|
282 | ||
|
283 | # return render(request, 'confirm.html', kwargs) | |
|
284 | ||
|
285 | ||
|
249 | 286 | def send_beam(request, id_conf, id_beam): |
|
250 | 287 | |
|
251 | 288 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
252 | 289 | |
|
253 | 290 | abs = Configuration.objects.filter(pk=conf.device.conf_active).first() |
|
254 | 291 | if abs!=conf: |
|
255 | 292 | url = '#' if abs is None else abs.get_absolute_url() |
|
256 | 293 | label = 'None' if abs is None else abs.label |
|
257 | 294 | messages.warning( |
|
258 | 295 | request, |
|
259 | 296 | mark_safe('The current configuration has not been written in the modules, the active configuration is <a href="{}">{}</a>'.format( |
|
260 | 297 | url, |
|
261 | 298 | label |
|
262 | 299 | )) |
|
263 | 300 | ) |
|
264 | 301 | return redirect(conf.get_absolute_url()) |
|
265 | 302 | |
|
266 | 303 | beam = get_object_or_404(ABSBeam, pk=id_beam) |
|
267 | 304 | |
|
268 | 305 | if request.method == 'POST': |
|
269 | 306 | |
|
270 | 307 | beams_list = ABSBeam.objects.filter(abs_conf=conf) |
|
271 | 308 | conf.active_beam = id_beam |
|
272 | 309 | |
|
273 | 310 | i = 0 |
|
274 | 311 | for b in beams_list: |
|
275 | 312 | if b.id == int(id_beam): |
|
276 | 313 | break |
|
277 | 314 | else: |
|
278 | 315 | i += 1 |
|
279 | 316 | beam_pos = i + 1 #Estandarizar |
|
280 | 317 | print ('%s Position: %s') % (beam.name, str(beam_pos)) |
|
281 | 318 | conf.send_beam(beam_pos) |
|
282 | 319 | |
|
283 | 320 | return redirect('url_abs_conf', conf.id) |
|
284 | 321 | |
|
285 | 322 | kwargs = { |
|
286 | 323 | 'title': 'ABS', |
|
287 | 324 | 'suptitle': conf.label, |
|
288 | 325 | 'message': 'Are you sure you want to change ABS Beam to: {}?'.format(beam.name), |
|
289 | 326 | 'delete': False |
|
290 | 327 | } |
|
291 | 328 | kwargs['menu_configurations'] = 'active' |
|
292 | 329 | |
|
293 | 330 | return render(request, 'confirm.html', kwargs) |
|
294 | 331 | |
|
295 | 332 | |
|
296 | 333 | def add_beam(request, id_conf): |
|
297 | 334 | |
|
298 | 335 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
299 | 336 | confs = Configuration.objects.all() |
|
300 | 337 | |
|
301 | 338 | if request.method=='GET': |
|
302 | 339 | form = ABSBeamAddForm() |
|
303 | 340 | |
|
304 | 341 | if request.method=='POST': |
|
305 | 342 | form = ABSBeamAddForm(request.POST) |
|
306 | 343 | |
|
307 | 344 | beam_data = get_values_from_form(request.POST) |
|
308 | 345 | |
|
309 | 346 | new_beam = ABSBeam( |
|
310 | 347 | name = beam_data['name'], |
|
311 | 348 | antenna = json.dumps(beam_data['antenna']), |
|
312 | 349 | abs_conf = conf, |
|
313 | 350 | tx = json.dumps(beam_data['tx']), |
|
314 | 351 | rx = json.dumps(beam_data['rx']), |
|
315 | 352 | ues = json.dumps(beam_data['ues']), |
|
316 | 353 | only_rx = json.dumps(beam_data['only_rx']) |
|
317 | 354 | ) |
|
318 | 355 | new_beam.save() |
|
319 | 356 | messages.success(request, 'Beam: "%s" has been added.' % new_beam.name) |
|
320 | 357 | |
|
321 | 358 | return redirect('url_edit_abs_conf', conf.id) |
|
322 | 359 | |
|
323 | 360 | ###### SIDEBAR ###### |
|
324 | 361 | kwargs = {} |
|
325 | 362 | |
|
326 | 363 | #kwargs['dev_conf'] = conf.device |
|
327 | 364 | #kwargs['id_dev'] = conf.device |
|
328 | 365 | #kwargs['previous'] = conf.get_absolute_url_edit() |
|
329 | 366 | kwargs['id_conf'] = conf.id |
|
330 | 367 | kwargs['form'] = form |
|
331 | 368 | kwargs['title'] = 'ABS Beams' |
|
332 | 369 | kwargs['suptitle'] = 'Add Beam' |
|
333 | 370 | kwargs['button'] = 'Add' |
|
334 | 371 | kwargs['no_sidebar'] = True |
|
335 | 372 | kwargs['edit'] = True |
|
336 | 373 | |
|
337 | 374 | return render(request, 'abs_add_beam.html', kwargs) |
|
338 | 375 | |
|
339 | 376 | |
|
340 | 377 | def edit_beam(request, id_conf, id_beam): |
|
341 | 378 | |
|
342 | 379 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
343 | 380 | beam = get_object_or_404(ABSBeam, pk=id_beam) |
|
344 | 381 | |
|
345 | 382 | if request.method=='GET': |
|
346 | 383 | form = ABSBeamEditForm(initial={'beam': beam}) |
|
347 | 384 | |
|
348 | 385 | if request.method=='POST': |
|
349 | 386 | form = ABSBeamEditForm(request.POST) |
|
350 | 387 | |
|
351 | 388 | beam_data = get_values_from_form(request.POST) |
|
352 | 389 | |
|
353 | 390 | beam.dict_to_parms(beam_data) |
|
354 | 391 | beam.save() |
|
355 | 392 | |
|
356 | 393 | messages.success(request, 'Beam: "%s" has been updated.' % beam.name) |
|
357 | 394 | |
|
358 | 395 | return redirect('url_edit_abs_conf', conf.id) |
|
359 | 396 | |
|
360 | 397 | ###### SIDEBAR ###### |
|
361 | 398 | kwargs = {} |
|
362 | 399 | |
|
363 | 400 | kwargs['id_conf'] = conf.id |
|
364 | 401 | kwargs['form'] = form |
|
365 | 402 | kwargs['title'] = 'ABS Beams' |
|
366 | 403 | kwargs['suptitle'] = 'Edit Beam' |
|
367 | 404 | kwargs['button'] = 'Save' |
|
368 | 405 | kwargs['no_sidebar'] = True |
|
369 | 406 | |
|
370 | 407 | #kwargs['previous'] = conf.get_absolute_url_edit() |
|
371 | 408 | kwargs['edit'] = True |
|
372 | 409 | |
|
373 | 410 | return render(request, 'abs_edit_beam.html', kwargs) |
|
374 | 411 | |
|
375 | 412 | |
|
376 | 413 | |
|
377 | 414 | def remove_beam(request, id_conf, id_beam): |
|
378 | 415 | |
|
379 | 416 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
380 | 417 | beam = get_object_or_404(ABSBeam, pk=id_beam) |
|
381 | 418 | |
|
382 | 419 | if request.method=='POST': |
|
383 | 420 | if beam: |
|
384 | 421 | try: |
|
385 | 422 | beam.delete() |
|
386 | 423 | messages.success(request, 'Beam: "%s" has been deleted.' % beam) |
|
387 | 424 | except: |
|
388 | 425 | messages.error(request, 'Unable to delete beam: "%s".' % beam) |
|
389 | 426 | |
|
390 | 427 | return redirect('url_edit_abs_conf', conf.id) |
|
391 | 428 | |
|
392 | 429 | ###### SIDEBAR ###### |
|
393 | 430 | kwargs = {} |
|
394 | 431 | |
|
395 | 432 | kwargs['object'] = beam |
|
396 | 433 | kwargs['delete'] = True |
|
397 | 434 | kwargs['title'] = 'Delete' |
|
398 | 435 | kwargs['suptitle'] = 'Beam' |
|
399 | 436 | kwargs['previous'] = conf.get_absolute_url_edit() |
|
400 | 437 | return render(request, 'confirm.html', kwargs) |
|
401 | 438 | |
|
402 | 439 | |
|
403 | 440 | |
|
404 | 441 | def plot_patterns(request, id_conf, id_beam=None): |
|
405 | 442 | |
|
406 | 443 | kwargs = {} |
|
407 | 444 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
408 | 445 | beams = ABSBeam.objects.filter(abs_conf=conf) |
|
409 | 446 | |
|
410 | 447 | if id_beam: |
|
411 | 448 | beam = get_object_or_404(ABSBeam, pk=id_beam) |
|
412 | 449 | kwargs['beam'] = beam |
|
413 | 450 | |
|
414 | 451 | ###### SIDEBAR ###### |
|
415 | 452 | |
|
416 | 453 | kwargs['dev_conf'] = conf.device |
|
417 | 454 | kwargs['id_dev'] = conf.device |
|
418 | 455 | kwargs['id_conf'] = conf.id |
|
419 | 456 | kwargs['abs_beams'] = beams |
|
420 | 457 | kwargs['title'] = 'ABS Patterns' |
|
421 | 458 | kwargs['suptitle'] = conf.name |
|
422 | 459 | kwargs['no_sidebar'] = True |
|
423 | 460 | |
|
424 | 461 | return render(request, 'abs_patterns.html', kwargs) |
|
425 | 462 | |
|
426 | 463 | |
|
427 | 464 | def plot_pattern(request, id_conf, id_beam, antenna): |
|
428 | 465 | |
|
429 | 466 | if antenna=='down': |
|
430 | 467 | sleep(3) |
|
431 | 468 | |
|
432 | 469 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
433 | 470 | beam = get_object_or_404(ABSBeam, pk=id_beam) |
|
434 | 471 | just_rx = 1 if json.loads(beam.only_rx)[antenna] else 0 |
|
435 | 472 | phases = json.loads(beam.antenna)['antenna_{}'.format(antenna)] |
|
436 | 473 | gain_tx = json.loads(beam.tx)[antenna] |
|
437 | 474 | gain_rx = json.loads(beam.rx)[antenna] |
|
438 | 475 | ues = json.loads(beam.ues)[antenna] |
|
439 | 476 | newOverJro = overJroShow(beam.name) |
|
440 | 477 | fig = newOverJro.plotPattern2(datetime.today(), phases, gain_tx, gain_rx, ues, just_rx) |
|
441 | 478 | buf = io.BytesIO() |
|
442 | 479 | fig.savefig(buf, format='png') |
|
443 | 480 | response = HttpResponse(buf.getvalue(), content_type='image/png') |
|
444 | 481 | return response |
|
445 | 482 | |
|
483 | import os | |
|
484 | from django.http import HttpResponse | |
|
485 | ||
|
486 | @sio.on('connection-bind') | |
|
487 | def abs_connection_bind(sid, data): | |
|
488 | print("sid:",sid,"data",data) | |
|
489 | ||
|
490 | @sio.on('disconnect') | |
|
491 | def abs_test_disconnect(sid): | |
|
492 | print("Disconnected") | |
|
493 | ||
|
494 | @sio.event | |
|
495 | def abs_send_beam_up(sid, message): | |
|
496 | mqtt_client.publish('abs/beams_up', message['data']) | |
|
497 | ||
|
498 | @sio.event | |
|
499 | def abs_send_beam_down(sid, message): | |
|
500 | mqtt_client.publish('abs/beams_down', message['data']) | |
|
501 | ||
|
502 | @sio.event | |
|
503 | def change_beam(sid,message): | |
|
504 | data=str(message['data']) | |
|
505 | data=data[16] | |
|
506 | mqtt_client.publish('abs/change_beam',data) | |
|
507 | ||
|
508 | ||
|
509 | ||
|
510 | ||
|
511 | ||
|
512 |
@@ -1,38 +1,39 | |||
|
1 | import os | |
|
1 | 2 | import paho.mqtt.client as mqtt |
|
2 | 3 | from radarsys import settings |
|
3 | 4 | from radarsys.socketconfig import sio as sio |
|
4 | 5 | import numpy as np |
|
5 | 6 | |
|
6 | 7 | def on_connect(mqtt_client, userdata, flags, rc): |
|
7 | 8 | if rc == 0: |
|
8 | 9 | print('Connected successfully') |
|
9 | 10 | mqtt_client.subscribe('atrad/test3') |
|
10 | 11 | else: |
|
11 | 12 | print('Bad connection. Code:', rc) |
|
12 | 13 | |
|
13 | 14 | def maxima_temp(trs): |
|
14 | 15 | np_array = [np.array(i) for i in trs] |
|
15 | 16 | temps = [max(i[i<40]) for i in np_array] |
|
16 | 17 | return max(temps) |
|
17 | 18 | |
|
18 | 19 | def on_message(mqtt_client, userdata, msg): |
|
19 | print(f'Received message on topic: {msg.topic} with payload: {msg.payload}', flush=True) | |
|
20 | # print(f'Received message on topic: {msg.topic} with payload: {msg.payload}', flush=True) | |
|
20 | 21 | trsi = [[],[],[],[]] |
|
21 | 22 | mensaje = str(msg.payload) |
|
22 | 23 | datos = [i for i in mensaje[21:-1].split("*")] |
|
23 |
status=''.join([datos[i][3] for i in |
|
|
24 | status=''.join([datos[i][3] for i in range(3)]) | |
|
24 | 25 | for trs,i in zip(datos,[0,1,2,3]) : |
|
25 | 26 | trsi[i]= [int(i) for i in trs[1:-1].split(",")] |
|
26 | 27 | potencias = [trsi[0][34],trsi[0][36],trsi[2][32],trsi[2][34]] |
|
27 | 28 | tmax = maxima_temp(trsi) |
|
28 | 29 | sio.emit('test', data={'time':mensaje[2:21],'num':trsi[0][0],'pow':potencias,'tmax':str(tmax),'status':status}) |
|
29 | 30 | |
|
30 | 31 | client = mqtt.Client() |
|
31 | 32 | client.on_connect = on_connect |
|
32 | 33 | client.on_message = on_message |
|
33 |
client.username_pw_set( |
|
|
34 | client.username_pw_set(os.environ.get('MQTT_USER_ATRAD', 'atrad'), os.environ.get('MQTT_PASSWORD_ATRAD', 'atrad')) | |
|
34 | 35 | client.connect( |
|
35 |
host= |
|
|
36 | port=settings.MQTT_PORT, | |
|
37 |
keepalive= |
|
|
36 | host=os.environ.get('MQTT_SERVER', '0.0.0.0'), | |
|
37 | port=int(settings.os.environ.get('MQTT_PORT', 1883)), | |
|
38 | keepalive=int(os.environ.get('MQTT_KEEPALIVE', 36000)) | |
|
38 | 39 | ) No newline at end of file |
@@ -1,177 +1,177 | |||
|
1 | 1 | """ |
|
2 | 2 | Django settings for radarsys project. |
|
3 | 3 | |
|
4 | 4 | Generated by 'django-admin startproject' using Django 1.8.6. |
|
5 | 5 | |
|
6 | 6 | For more information on this file, see |
|
7 | 7 | https://docs.djangoproject.com/en/1.8/topics/settings/ |
|
8 | 8 | |
|
9 | 9 | For the full list of settings and their values, see |
|
10 | 10 | https://docs.djangoproject.com/en/1.8/ref/settings/ |
|
11 | 11 | """ |
|
12 | 12 | |
|
13 | 13 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) |
|
14 | 14 | import os |
|
15 | 15 | |
|
16 | 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
|
17 | 17 | |
|
18 | 18 | # Quick-start development settings - unsuitable for production |
|
19 | 19 | # See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ |
|
20 | 20 | |
|
21 | 21 | # SECURITY WARNING: keep the secret key used in production secret! |
|
22 | 22 | SECRET_KEY = 'xshb$k5fc-+j16)cvyffj&9u__0q3$l!hieh#+tbzqg)*f^km0' |
|
23 | 23 | |
|
24 | 24 | # SECURITY WARNING: don't run with debug turned on in production! |
|
25 | 25 | DEBUG = True |
|
26 | 26 | |
|
27 | 27 | ALLOWED_HOSTS = ['*'] |
|
28 | 28 | |
|
29 | 29 | CSRF_TRUSTED_ORIGINS=[ |
|
30 | 30 | "http://*.localhost:8030", |
|
31 | 31 | "http://localhost:8030", |
|
32 | 32 | "http://127.0.0.1:8030" |
|
33 | 33 | ] |
|
34 | 34 | #Si se requiere que la aplicación salga de este entorno, para otros usuarios es necesario hacer una API request https://fractalideas.com/blog/making-react-and-django-play-well-together-single-page-app-model/ |
|
35 | 35 | |
|
36 | 36 | # Application definition |
|
37 | 37 | |
|
38 | 38 | INSTALLED_APPS = [ |
|
39 | 39 | 'django.contrib.admin', |
|
40 | 40 | 'django.contrib.auth', |
|
41 | 41 | 'django.contrib.contenttypes', |
|
42 | 42 | 'django.contrib.sessions', |
|
43 | 43 | 'django.contrib.messages', |
|
44 | 44 | 'django.contrib.staticfiles', |
|
45 | 45 | 'apps.accounts', |
|
46 | 46 | 'apps.main', |
|
47 | 47 | 'apps.misc', |
|
48 | 48 | 'apps.rc', |
|
49 | 49 | 'apps.dds', |
|
50 | 50 | 'apps.jars', |
|
51 | 51 | 'apps.usrp', |
|
52 | 52 | 'apps.abs', |
|
53 | 53 | 'apps.cgs', |
|
54 | 54 | 'apps.dds_rest', |
|
55 | 55 | 'apps.atrad', |
|
56 | 56 | "django_bootstrap5", |
|
57 | 57 | 'polymorphic', |
|
58 | 58 | 'radarsys', |
|
59 | 59 | ] |
|
60 | 60 | |
|
61 | 61 | MIDDLEWARE = [ |
|
62 | 62 | 'django.middleware.security.SecurityMiddleware', |
|
63 | 63 | 'django.contrib.sessions.middleware.SessionMiddleware', |
|
64 | 64 | 'django.middleware.common.CommonMiddleware', |
|
65 | 65 | 'django.middleware.csrf.CsrfViewMiddleware', |
|
66 | 66 | 'django.contrib.auth.middleware.AuthenticationMiddleware', |
|
67 | 67 | 'django.contrib.messages.middleware.MessageMiddleware', |
|
68 | 68 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', |
|
69 | 69 | |
|
70 | 70 | ] |
|
71 | 71 | |
|
72 | 72 | ROOT_URLCONF = 'radarsys.urls' |
|
73 | 73 | |
|
74 | 74 | TEMPLATES = [ |
|
75 | 75 | { |
|
76 | 76 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', |
|
77 | 77 | 'DIRS': [os.path.join(BASE_DIR, "templates")], |
|
78 | 78 | 'APP_DIRS': True, |
|
79 | 79 | 'OPTIONS': { |
|
80 | 80 | 'context_processors': [ |
|
81 | 81 | 'django.template.context_processors.debug', |
|
82 | 82 | 'django.template.context_processors.request', |
|
83 | 83 | 'django.contrib.auth.context_processors.auth', |
|
84 | 84 | 'django.contrib.messages.context_processors.messages', |
|
85 | 85 | 'apps.main.processors.radarsys_globals', |
|
86 | 86 | ], |
|
87 | 87 | }, |
|
88 | 88 | }, |
|
89 | 89 | ] |
|
90 | 90 | |
|
91 | 91 | WSGI_APPLICATION = 'radarsys.wsgi.application' |
|
92 | 92 | ASGI_APPLICATION = 'radarsys.asgi.application' |
|
93 | 93 | |
|
94 | 94 | # Database |
|
95 | 95 | # https://docs.djangoproject.com/en/1.8/ref/settings/#databases |
|
96 | 96 | |
|
97 | 97 | DATABASES = { |
|
98 | 98 | # 'default': { |
|
99 | 99 | # 'ENGINE': 'django.db.backends.sqlite3', |
|
100 | 100 | # 'NAME': 'radarsys.sqlite', |
|
101 | 101 | # } |
|
102 | 102 | 'default': { |
|
103 | 103 | 'ENGINE': 'django.db.backends.postgresql_psycopg2', |
|
104 | 104 | 'NAME': os.environ.get('DB_NAME', 'radarsys'), |
|
105 | 105 | 'USER': os.environ.get('DB_USER', 'docker'), |
|
106 | 106 | 'PASSWORD': os.environ.get('DB_PASSWORD', 'docker'), |
|
107 | 107 | 'HOST': os.environ.get('POSTGRES_PORT_5432_TCP_ADDR', 'localhost'), |
|
108 | 108 | 'PORT': os.environ.get('POSTGRES_PORT_5432_TCP_PORT', '5432'), |
|
109 | 109 | } |
|
110 | 110 | } |
|
111 | 111 | |
|
112 | 112 | # Internationalization |
|
113 | 113 | # https://docs.djangoproject.com/en/1.8/topics/i18n/ |
|
114 | 114 | |
|
115 | 115 | LANGUAGE_CODE = 'en-us' |
|
116 | 116 | |
|
117 | 117 | USE_TZ = False #True |
|
118 | 118 | |
|
119 | 119 | TIME_ZONE = os.environ.get('TZ', 'America/Lima') |
|
120 | 120 | |
|
121 | 121 | USE_I18N = True |
|
122 | 122 | |
|
123 | 123 | USE_L10N = True |
|
124 | 124 | |
|
125 | 125 | # Static files (CSS, JavaScript, Images) |
|
126 | 126 | # https://docs.djangoproject.com/en/1.8/howto/static-files/ |
|
127 | 127 | |
|
128 | 128 | MEDIA_URL = '/media/' |
|
129 | 129 | MEDIA_ROOT = os.path.join(BASE_DIR, 'media') |
|
130 | 130 | |
|
131 | 131 | STATICFILES_DIRS = [ |
|
132 | 132 | os.path.join(BASE_DIR, 'radarsys/static/') |
|
133 | 133 | ] |
|
134 | 134 | |
|
135 | 135 | STATIC_URL = '/static/' |
|
136 | 136 | STATIC_ROOT = os.path.join(BASE_DIR, 'static') |
|
137 | 137 | |
|
138 | 138 | LOGIN_URL = '/accounts/login' |
|
139 | 139 | LOGOUT_URL = 'logout' |
|
140 | 140 | LOGIN_REDIRECT_URL = '/admin' |
|
141 | 141 | LOGOUT_REDIRECT_URL = '/' |
|
142 | 142 | |
|
143 | 143 | STATICFILES_FINDERS = ( |
|
144 | 144 | 'django.contrib.staticfiles.finders.FileSystemFinder', |
|
145 | 145 | 'django.contrib.staticfiles.finders.AppDirectoriesFinder', |
|
146 | 146 | ) |
|
147 | 147 | |
|
148 | 148 | # # Celery stuff |
|
149 | 149 | |
|
150 | 150 | # REDIS_HOST = os.environ.get('REDIS_HOST', 'localhost') |
|
151 | 151 | # #REDIS_HOST = os.environ.get('REDIS_HOST', '127.0.0.1') |
|
152 | 152 | # REDIS_PORT = os.environ.get('REDIS_PORT', 6379) |
|
153 | 153 | |
|
154 | 154 | # BROKER_TRANSPORT = 'redis' |
|
155 | 155 | # #BROKER_URL = 'redis://{}:{}/0'.format(REDIS_HOST, REDIS_PORT) |
|
156 | 156 | # BROKER_URL = 'redis://{}:{}'.format(REDIS_HOST, REDIS_PORT) |
|
157 | 157 | |
|
158 | 158 | # CELERY_RESULT_BACKEND = 'redis://{}:{}/0'.format(REDIS_HOST, REDIS_PORT) |
|
159 | 159 | # CELERY_BROKER_TRANSPORT = BROKER_URL |
|
160 | 160 | # CELERY_ACCEPT_CONTENT = ['application/json'] |
|
161 | 161 | # CELERY_TASK_SERIALIZER = 'json' |
|
162 | 162 | # CELERY_RESULT_SERIALIZER = 'json' |
|
163 | 163 | # CELERY_ENABLE_UTC = False |
|
164 | 164 | # CELERY_TIMEZONE = 'America/Lima' |
|
165 | 165 | |
|
166 | 166 | import django |
|
167 | 167 | from django.utils.encoding import force_str |
|
168 | 168 | django.utils.encoding.force_text = force_str |
|
169 | 169 | |
|
170 | 170 | # choose of auto-created primary keys |
|
171 | 171 | DEFAULT_AUTO_FIELD='django.db.models.AutoField' |
|
172 | 172 | |
|
173 |
MQTT_SERVER = '10.10.10. |
|
|
173 | MQTT_SERVER = '10.10.10.200' | |
|
174 | 174 | MQTT_PORT = 1883 |
|
175 | 175 | MQTT_KEEPALIVE = 60 |
|
176 | 176 | MQTT_USER = '' |
|
177 | 177 | MQTT_PASSWORD = '' No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now