@@ -1,184 +1,261 | |||||
1 | from django.db import models |
|
1 | from django.db import models | |
2 | from apps.main.models import Configuration |
|
2 | from apps.main.models import Configuration | |
3 | from django.core.validators import MinValueValidator, MaxValueValidator |
|
3 | from django.core.validators import MinValueValidator, MaxValueValidator | |
4 |
|
4 | |||
5 | from .files import read_json_file |
|
5 | from .files import read_json_file | |
|
6 | import requests | |||
6 | # Create your models here. validators=[MinValueValidator(62.5e6), MaxValueValidator(450e6)] |
|
7 | # Create your models here. validators=[MinValueValidator(62.5e6), MaxValueValidator(450e6)] | |
7 |
|
8 | |||
8 | class CGSConfiguration(Configuration): |
|
9 | class CGSConfiguration(Configuration): | |
9 |
|
10 | |||
10 | freq0 = models.PositiveIntegerField(verbose_name='Frequency 0',validators=[MaxValueValidator(450e6)], default = 60) |
|
11 | freq0 = models.PositiveIntegerField(verbose_name='Frequency 0',validators=[MaxValueValidator(450e6)], default = 60) | |
11 | freq1 = models.PositiveIntegerField(verbose_name='Frequency 1',validators=[MaxValueValidator(450e6)], default = 60) |
|
12 | freq1 = models.PositiveIntegerField(verbose_name='Frequency 1',validators=[MaxValueValidator(450e6)], default = 60) | |
12 | freq2 = models.PositiveIntegerField(verbose_name='Frequency 2',validators=[MaxValueValidator(450e6)], default = 60) |
|
13 | freq2 = models.PositiveIntegerField(verbose_name='Frequency 2',validators=[MaxValueValidator(450e6)], default = 60) | |
13 | freq3 = models.PositiveIntegerField(verbose_name='Frequency 3',validators=[MaxValueValidator(450e6)], default = 60) |
|
14 | freq3 = models.PositiveIntegerField(verbose_name='Frequency 3',validators=[MaxValueValidator(450e6)], default = 60) | |
14 |
|
15 | |||
15 | def verify_frequencies(self): |
|
16 | def verify_frequencies(self): | |
16 |
|
17 | |||
17 | return True |
|
18 | return True | |
18 |
|
19 | |||
19 |
|
20 | |||
20 | def update_from_file(self, fp): |
|
21 | def update_from_file(self, fp): | |
21 |
|
22 | |||
22 | kwargs = read_json_file(fp) |
|
23 | kwargs = read_json_file(fp) | |
23 |
|
24 | |||
24 | if not kwargs: |
|
25 | if not kwargs: | |
25 | return False |
|
26 | return False | |
26 |
|
27 | |||
27 | self.freq0 = kwargs['freq0'] |
|
28 | self.freq0 = kwargs['freq0'] | |
28 | self.freq1 = kwargs['freq1'] |
|
29 | self.freq1 = kwargs['freq1'] | |
29 | self.freq2 = kwargs['freq2'] |
|
30 | self.freq2 = kwargs['freq2'] | |
30 | self.freq3 = kwargs['freq3'] |
|
31 | self.freq3 = kwargs['freq3'] | |
31 |
|
32 | |||
32 | return True |
|
33 | return True | |
33 |
|
34 | |||
34 | def parms_to_dict(self): |
|
35 | def parms_to_dict(self): | |
35 |
|
36 | |||
36 | parameters = {} |
|
37 | parameters = {} | |
37 |
|
38 | |||
38 | parameters['device_id'] = self.device.id |
|
39 | parameters['device_id'] = self.device.id | |
39 |
|
40 | |||
40 | if self.freq0 == None or self.freq0 == '': |
|
41 | if self.freq0 == None or self.freq0 == '': | |
41 | parameters['freq0'] = 0 |
|
42 | parameters['freq0'] = 0 | |
42 | else: |
|
43 | else: | |
43 | parameters['freq0'] = self.freq0 |
|
44 | parameters['freq0'] = self.freq0 | |
44 |
|
45 | |||
45 | if self.freq1 == None or self.freq1 == '': |
|
46 | if self.freq1 == None or self.freq1 == '': | |
46 | parameters['freq1'] = 0 |
|
47 | parameters['freq1'] = 0 | |
47 | else: |
|
48 | else: | |
48 | parameters['freq1'] = self.freq1 |
|
49 | parameters['freq1'] = self.freq1 | |
49 |
|
50 | |||
50 | if self.freq2 == None or self.freq2 == '': |
|
51 | if self.freq2 == None or self.freq2 == '': | |
51 | parameters['freq2'] = 0 |
|
52 | parameters['freq2'] = 0 | |
52 | else: |
|
53 | else: | |
53 | parameters['freq2'] = self.freq2 |
|
54 | parameters['freq2'] = self.freq2 | |
54 |
|
55 | |||
55 | if self.freq3 == None or self.freq3 == '': |
|
56 | if self.freq3 == None or self.freq3 == '': | |
56 | parameters['freq3'] = 0 |
|
57 | parameters['freq3'] = 0 | |
57 | else: |
|
58 | else: | |
58 | parameters['freq3'] = self.freq3 |
|
59 | parameters['freq3'] = self.freq3 | |
59 |
|
60 | |||
60 | return parameters |
|
61 | return parameters | |
61 |
|
62 | |||
62 |
|
63 | |||
63 | def dict_to_parms(self, parameters): |
|
64 | def dict_to_parms(self, parameters): | |
64 |
|
65 | |||
65 | self.freq0 = parameters['freq0'] |
|
66 | self.freq0 = parameters['freq0'] | |
66 | self.freq1 = parameters['freq1'] |
|
67 | self.freq1 = parameters['freq1'] | |
67 | self.freq2 = parameters['freq2'] |
|
68 | self.freq2 = parameters['freq2'] | |
68 | self.freq3 = parameters['freq3'] |
|
69 | self.freq3 = parameters['freq3'] | |
69 |
|
70 | |||
70 |
|
71 | |||
71 | def status_device(self): |
|
72 | def status_device(self): | |
72 |
|
73 | |||
73 | import requests |
|
74 | import requests | |
74 |
|
75 | |||
75 | ip=self.device.ip_address |
|
76 | ip=self.device.ip_address | |
76 | port=self.device.port_address |
|
77 | port=self.device.port_address | |
77 |
|
78 | |||
78 | route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" |
|
79 | route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" | |
79 | try: |
|
80 | try: | |
80 | r = requests.get(route,timeout=0.5) |
|
81 | r = requests.get(route,timeout=0.5) | |
81 | except: |
|
82 | except: | |
82 | self.device.status = 0 |
|
83 | self.device.status = 0 | |
83 | self.device.save() |
|
84 | self.device.save() | |
84 | self.message = 'Could not read CGS status' |
|
85 | self.message = 'Could not read CGS status' | |
85 | return False |
|
86 | return False | |
86 |
|
87 | |||
87 | response = str(r.text) |
|
88 | response = str(r.text) | |
88 | response = response.split(";") |
|
89 | response = response.split(";") | |
89 | icon = response[0] |
|
90 | icon = response[0] | |
90 | status = response[-1] |
|
91 | status = response[-1] | |
91 |
|
92 | |||
92 | #print(icon, status) |
|
93 | #print(icon, status) | |
93 | #"icon" could be: "alert" or "okay" |
|
94 | #"icon" could be: "alert" or "okay" | |
94 | if "alert" in icon: |
|
95 | if "alert" in icon: | |
95 | if "Starting Up" in status: #No Esta conectado |
|
96 | if "Starting Up" in status: #No Esta conectado | |
96 | self.device.status = 0 |
|
97 | self.device.status = 0 | |
97 | else: |
|
98 | else: | |
98 | self.device.status = 1 |
|
99 | self.device.status = 1 | |
99 | elif "okay" in icon: |
|
100 | elif "okay" in icon: | |
100 | self.device.status = 3 |
|
101 | self.device.status = 3 | |
101 | else: |
|
102 | else: | |
102 | self.device.status = 1 |
|
103 | self.device.status = 1 | |
103 |
|
104 | |||
104 | self.message = status |
|
105 | self.message = status | |
105 | self.device.save() |
|
106 | self.device.save() | |
106 |
|
107 | |||
107 |
|
108 | |||
108 | return True |
|
109 | return True | |
109 |
|
110 | |||
110 |
|
111 | |||
|
112 | def start_device(self): | |||
|
113 | ||||
|
114 | ip=self.device.ip_address | |||
|
115 | port=self.device.port_address | |||
|
116 | ||||
|
117 | #---Frequencies from form | |||
|
118 | f0 = self.freq0 | |||
|
119 | f1 = self.freq1 | |||
|
120 | f2 = self.freq2 | |||
|
121 | f3 = self.freq3 | |||
|
122 | post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} | |||
|
123 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" | |||
|
124 | ||||
|
125 | try: | |||
|
126 | r = requests.post(route, post_data, timeout=0.7) | |||
|
127 | except: | |||
|
128 | self.message = "Could not start CGS device" | |||
|
129 | return False | |||
|
130 | ||||
|
131 | text = r.text | |||
|
132 | text = text.split(',') | |||
|
133 | ||||
|
134 | if len(text)>1: | |||
|
135 | title = text[0] | |||
|
136 | status = text[1] | |||
|
137 | if title == "okay": | |||
|
138 | self.message = status | |||
|
139 | self.device.status = 3 | |||
|
140 | self.device.save() | |||
|
141 | return True | |||
|
142 | else: | |||
|
143 | self.message = title + ", " + status | |||
|
144 | self.device.status = 1 | |||
|
145 | self.device.save() | |||
|
146 | return False | |||
|
147 | ||||
|
148 | return False | |||
|
149 | ||||
|
150 | ||||
|
151 | def stop_device(self): | |||
|
152 | ||||
|
153 | ip=self.device.ip_address | |||
|
154 | port=self.device.port_address | |||
|
155 | ||||
|
156 | f0 = 0 | |||
|
157 | f1 = 0 | |||
|
158 | f2 = 0 | |||
|
159 | f3 = 0 | |||
|
160 | post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} | |||
|
161 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" | |||
|
162 | ||||
|
163 | try: | |||
|
164 | r = requests.post(route, post_data, timeout=0.7) | |||
|
165 | except: | |||
|
166 | self.message = "Could not stop CGS device" | |||
|
167 | return False | |||
|
168 | ||||
|
169 | text = r.text | |||
|
170 | text = text.split(',') | |||
|
171 | ||||
|
172 | if len(text)>1: | |||
|
173 | title = text[0] | |||
|
174 | status = text[1] | |||
|
175 | if title == "okay": | |||
|
176 | self.message = status | |||
|
177 | self.device.status = 1 | |||
|
178 | self.device.save() | |||
|
179 | self.message = "CGS device has been stopped" | |||
|
180 | return True | |||
|
181 | else: | |||
|
182 | self.message = title + ", " + status | |||
|
183 | self.device.status = 0 | |||
|
184 | self.device.save() | |||
|
185 | return False | |||
|
186 | ||||
|
187 | return False | |||
|
188 | ||||
|
189 | ||||
111 | def read_device(self): |
|
190 | def read_device(self): | |
112 |
|
191 | |||
113 | import requests |
|
192 | import requests | |
114 |
|
193 | |||
115 | ip=self.device.ip_address |
|
194 | ip=self.device.ip_address | |
116 | port=self.device.port_address |
|
195 | port=self.device.port_address | |
117 |
|
196 | |||
118 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" |
|
197 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" | |
119 | try: |
|
198 | try: | |
120 |
frequencies = requests.get(route,timeout=0. |
|
199 | frequencies = requests.get(route,timeout=0.7) | |
121 |
|
200 | |||
122 | except: |
|
201 | except: | |
123 | self.message = "Could not read CGS parameters from this device" |
|
202 | self.message = "Could not read CGS parameters from this device" | |
124 | return None |
|
203 | return None | |
125 |
|
204 | |||
126 | frequencies = frequencies.json() |
|
205 | frequencies = frequencies.json() | |
127 | frequencies = frequencies.get("Frecuencias") |
|
206 | frequencies = frequencies.get("Frecuencias") | |
128 | f0 = frequencies.get("f0") |
|
207 | f0 = frequencies.get("f0") | |
129 | f1 = frequencies.get("f1") |
|
208 | f1 = frequencies.get("f1") | |
130 | f2 = frequencies.get("f2") |
|
209 | f2 = frequencies.get("f2") | |
131 | f3 = frequencies.get("f3") |
|
210 | f3 = frequencies.get("f3") | |
132 |
|
211 | |||
133 | parms = {'freq0': f0, |
|
212 | parms = {'freq0': f0, | |
134 | 'freq1': f1, |
|
213 | 'freq1': f1, | |
135 | 'freq2': f2, |
|
214 | 'freq2': f2, | |
136 | 'freq3': f3} |
|
215 | 'freq3': f3} | |
137 |
|
216 | |||
138 | self.message = "" |
|
217 | self.message = "" | |
139 | return parms |
|
218 | return parms | |
140 |
|
219 | |||
141 |
|
220 | |||
142 | def write_device(self): |
|
221 | def write_device(self): | |
143 |
|
222 | |||
144 | import requests |
|
|||
145 |
|
||||
146 | ip=self.device.ip_address |
|
223 | ip=self.device.ip_address | |
147 | port=self.device.port_address |
|
224 | port=self.device.port_address | |
148 |
|
225 | |||
149 | #---Frequencies from form |
|
226 | #---Frequencies from form | |
150 | f0 = self.freq0 |
|
227 | f0 = self.freq0 | |
151 | f1 = self.freq1 |
|
228 | f1 = self.freq1 | |
152 | f2 = self.freq2 |
|
229 | f2 = self.freq2 | |
153 | f3 = self.freq3 |
|
230 | f3 = self.freq3 | |
154 | post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} |
|
231 | post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} | |
155 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" |
|
232 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" | |
156 |
|
233 | |||
157 | try: |
|
234 | try: | |
158 |
r = requests.post(route, post_data, timeout=0. |
|
235 | r = requests.post(route, post_data, timeout=0.7) | |
159 | except: |
|
236 | except: | |
160 | self.message = "Could not write CGS parameters" |
|
237 | self.message = "Could not write CGS parameters" | |
161 | return False |
|
238 | return False | |
162 |
|
239 | |||
163 | text = r.text |
|
240 | text = r.text | |
164 | text = text.split(',') |
|
241 | text = text.split(',') | |
165 |
|
242 | |||
166 | if len(text)>1: |
|
243 | if len(text)>1: | |
167 | title = text[0] |
|
244 | title = text[0] | |
168 | status = text[1] |
|
245 | status = text[1] | |
169 | if title == "okay": |
|
246 | if title == "okay": | |
170 | self.message = status |
|
247 | self.message = status | |
171 | self.device.status = 3 |
|
248 | self.device.status = 3 | |
172 | self.device.save() |
|
249 | self.device.save() | |
173 | return True |
|
250 | return True | |
174 | else: |
|
251 | else: | |
175 | self.message = title + ", " + status |
|
252 | self.message = title + ", " + status | |
176 | self.device.status = 1 |
|
253 | self.device.status = 1 | |
177 | self.device.save() |
|
254 | self.device.save() | |
178 | return False |
|
255 | return False | |
179 |
|
256 | |||
180 | return False |
|
257 | return False | |
181 |
|
258 | |||
182 |
|
259 | |||
183 | class Meta: |
|
260 | class Meta: | |
184 | db_table = 'cgs_configurations' |
|
261 | db_table = 'cgs_configurations' |
@@ -1,322 +1,322 | |||||
1 | from django.shortcuts import redirect, render, get_object_or_404 |
|
1 | from django.shortcuts import redirect, render, get_object_or_404 | |
2 | from django.contrib import messages |
|
2 | from django.contrib import messages | |
3 | from django.http import HttpResponse |
|
3 | from django.http import HttpResponse | |
4 |
|
4 | |||
5 | from apps.main.models import Experiment |
|
5 | from apps.main.models import Experiment | |
6 | from .models import CGSConfiguration |
|
6 | from .models import CGSConfiguration | |
7 |
|
7 | |||
8 | from .forms import CGSConfigurationForm, UploadFileForm |
|
8 | from .forms import CGSConfigurationForm, UploadFileForm | |
9 | from apps.main.views import sidebar |
|
9 | from apps.main.views import sidebar | |
10 |
|
10 | |||
11 | import requests |
|
11 | import requests | |
12 | import json |
|
12 | import json | |
13 | #from __builtin__ import None |
|
13 | #from __builtin__ import None | |
14 | # Create your views here. |
|
14 | # Create your views here. | |
15 |
|
15 | |||
16 | def cgs_conf(request, id_conf): |
|
16 | def cgs_conf(request, id_conf): | |
17 |
|
17 | |||
18 | conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
18 | conf = get_object_or_404(CGSConfiguration, pk=id_conf) | |
19 |
|
19 | |||
20 | ip=conf.device.ip_address |
|
20 | ip=conf.device.ip_address | |
21 | port=conf.device.port_address |
|
21 | port=conf.device.port_address | |
22 |
|
22 | |||
23 | kwargs = {} |
|
23 | kwargs = {} | |
24 |
|
24 | |||
25 | kwargs['status'] = conf.device.get_status_display() |
|
25 | kwargs['status'] = conf.device.get_status_display() | |
26 |
|
26 | |||
27 | #if request.method=='GET': |
|
27 | #if request.method=='GET': | |
28 | #r: response = icon, status |
|
28 | #r: response = icon, status | |
29 | # try: |
|
29 | # try: | |
30 | # route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" |
|
30 | # route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" | |
31 | # r = requests.get(route) |
|
31 | # r = requests.get(route) | |
32 | # response = str(r.text) |
|
32 | # response = str(r.text) | |
33 | # response = response.split(";") |
|
33 | # response = response.split(";") | |
34 | # icon = response[0] |
|
34 | # icon = response[0] | |
35 | # status = response[-1] |
|
35 | # status = response[-1] | |
36 | #print r.text |
|
36 | #print r.text | |
37 | #"icon" could be: "alert" or "okay" |
|
37 | #"icon" could be: "alert" or "okay" | |
38 | # Si hay alerta pero esta conectado |
|
38 | # Si hay alerta pero esta conectado | |
39 | # if "alert" in icon: |
|
39 | # if "alert" in icon: | |
40 | # if "Starting Up" in status: #No Esta conectado |
|
40 | # if "Starting Up" in status: #No Esta conectado | |
41 | # kwargs['connected'] = False |
|
41 | # kwargs['connected'] = False | |
42 | # else: |
|
42 | # else: | |
43 | # kwargs['connected'] = True |
|
43 | # kwargs['connected'] = True | |
44 | # elif "okay" in icon: |
|
44 | # elif "okay" in icon: | |
45 | # kwargs['connected'] = True |
|
45 | # kwargs['connected'] = True | |
46 | # else: |
|
46 | # else: | |
47 | # kwargs['connected'] = False |
|
47 | # kwargs['connected'] = False | |
48 |
|
48 | |||
49 | # except: |
|
49 | # except: | |
50 | # kwargs['connected'] = False |
|
50 | # kwargs['connected'] = False | |
51 | # status = "The Device is not connected." |
|
51 | # status = "The Device is not connected." | |
52 |
|
52 | |||
53 | #if not kwargs['connected']: |
|
53 | #if not kwargs['connected']: | |
54 | # messages.error(request, message=status) |
|
54 | # messages.error(request, message=status) | |
55 |
|
55 | |||
56 | kwargs['dev_conf'] = conf |
|
56 | kwargs['dev_conf'] = conf | |
57 | kwargs['dev_conf_keys'] = ['name', |
|
57 | kwargs['dev_conf_keys'] = ['name', | |
58 | 'freq0', 'freq1', |
|
58 | 'freq0', 'freq1', | |
59 | 'freq2', 'freq3'] |
|
59 | 'freq2', 'freq3'] | |
60 |
|
60 | |||
61 | kwargs['title'] = 'CGS Configuration' |
|
61 | kwargs['title'] = 'CGS Configuration' | |
62 | kwargs['suptitle'] = 'Details' |
|
62 | kwargs['suptitle'] = 'Details' | |
63 |
|
63 | |||
64 | kwargs['button'] = 'Edit Configuration' |
|
64 | kwargs['button'] = 'Edit Configuration' | |
65 |
|
65 | |||
66 | kwargs['no_play'] = True |
|
66 | #kwargs['no_play'] = True | |
67 |
|
67 | |||
68 | ###### SIDEBAR ###### |
|
68 | ###### SIDEBAR ###### | |
69 | kwargs.update(sidebar(conf=conf)) |
|
69 | kwargs.update(sidebar(conf=conf)) | |
70 |
|
70 | |||
71 | return render(request, 'cgs_conf.html', kwargs) |
|
71 | return render(request, 'cgs_conf.html', kwargs) | |
72 |
|
72 | |||
73 | def cgs_conf_edit(request, id_conf): |
|
73 | def cgs_conf_edit(request, id_conf): | |
74 |
|
74 | |||
75 | conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
75 | conf = get_object_or_404(CGSConfiguration, pk=id_conf) | |
76 |
|
76 | |||
77 | if request.method=='GET': |
|
77 | if request.method=='GET': | |
78 | form = CGSConfigurationForm(instance=conf) |
|
78 | form = CGSConfigurationForm(instance=conf) | |
79 |
|
79 | |||
80 | if request.method=='POST': |
|
80 | if request.method=='POST': | |
81 | form = CGSConfigurationForm(request.POST, instance=conf) |
|
81 | form = CGSConfigurationForm(request.POST, instance=conf) | |
82 |
|
82 | |||
83 | if form.is_valid(): |
|
83 | if form.is_valid(): | |
84 | if conf.freq0 == None: conf.freq0 = 0 |
|
84 | if conf.freq0 == None: conf.freq0 = 0 | |
85 | if conf.freq1 == None: conf.freq1 = 0 |
|
85 | if conf.freq1 == None: conf.freq1 = 0 | |
86 | if conf.freq2 == None: conf.freq2 = 0 |
|
86 | if conf.freq2 == None: conf.freq2 = 0 | |
87 | if conf.freq3 == None: conf.freq3 = 0 |
|
87 | if conf.freq3 == None: conf.freq3 = 0 | |
88 |
|
88 | |||
89 | conf = form.save(commit=False) |
|
89 | conf = form.save(commit=False) | |
90 |
|
90 | |||
91 | if conf.verify_frequencies(): |
|
91 | if conf.verify_frequencies(): | |
92 | conf.save() |
|
92 | conf.save() | |
93 | return redirect('url_cgs_conf', id_conf=conf.id) |
|
93 | return redirect('url_cgs_conf', id_conf=conf.id) | |
94 |
|
94 | |||
95 | ##ERRORS |
|
95 | ##ERRORS | |
96 |
|
96 | |||
97 | kwargs = {} |
|
97 | kwargs = {} | |
98 | kwargs['id_dev'] = conf.id |
|
98 | kwargs['id_dev'] = conf.id | |
99 | kwargs['form'] = form |
|
99 | kwargs['form'] = form | |
100 | kwargs['title'] = 'Device Configuration' |
|
100 | kwargs['title'] = 'Device Configuration' | |
101 | kwargs['suptitle'] = 'Edit' |
|
101 | kwargs['suptitle'] = 'Edit' | |
102 | kwargs['button'] = 'Save' |
|
102 | kwargs['button'] = 'Save' | |
103 |
|
103 | |||
104 | return render(request, 'cgs_conf_edit.html', kwargs) |
|
104 | return render(request, 'cgs_conf_edit.html', kwargs) | |
105 | # |
|
105 | # | |
106 | # def cgs_conf_write(request, id_conf): |
|
106 | # def cgs_conf_write(request, id_conf): | |
107 | # |
|
107 | # | |
108 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
108 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) | |
109 | # ip=conf.device.ip_address |
|
109 | # ip=conf.device.ip_address | |
110 | # port=conf.device.port_address |
|
110 | # port=conf.device.port_address | |
111 | # |
|
111 | # | |
112 | # #Frequencies from form |
|
112 | # #Frequencies from form | |
113 | # f0 = conf.freq0 |
|
113 | # f0 = conf.freq0 | |
114 | # f1 = conf.freq1 |
|
114 | # f1 = conf.freq1 | |
115 | # f2 = conf.freq2 |
|
115 | # f2 = conf.freq2 | |
116 | # f3 = conf.freq3 |
|
116 | # f3 = conf.freq3 | |
117 | # |
|
117 | # | |
118 | # try: |
|
118 | # try: | |
119 | # post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} |
|
119 | # post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} | |
120 | # route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" |
|
120 | # route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" | |
121 | # r = requests.post(route, post_data) |
|
121 | # r = requests.post(route, post_data) | |
122 | # text = r.text |
|
122 | # text = r.text | |
123 | # text = text.split(',') |
|
123 | # text = text.split(',') | |
124 | # |
|
124 | # | |
125 | # try: |
|
125 | # try: | |
126 | # if len(text)>1: |
|
126 | # if len(text)>1: | |
127 | # title = text[0] |
|
127 | # title = text[0] | |
128 | # status = text[1] |
|
128 | # status = text[1] | |
129 | # status_ok = r.status_code |
|
129 | # status_ok = r.status_code | |
130 | # if title == "okay": |
|
130 | # if title == "okay": | |
131 | # messages.success(request, status) |
|
131 | # messages.success(request, status) | |
132 | # else: |
|
132 | # else: | |
133 | # messages.error(request, status) |
|
133 | # messages.error(request, status) | |
134 | # |
|
134 | # | |
135 | # else: |
|
135 | # else: | |
136 | # title = text[0] |
|
136 | # title = text[0] | |
137 | # messages.error(request, title) |
|
137 | # messages.error(request, title) | |
138 | # |
|
138 | # | |
139 | # except: |
|
139 | # except: | |
140 | # messages.error(request, "An hardware error was found.") |
|
140 | # messages.error(request, "An hardware error was found.") | |
141 | # |
|
141 | # | |
142 | # except: |
|
142 | # except: | |
143 | # messages.error(request, "Could not write parameters.") |
|
143 | # messages.error(request, "Could not write parameters.") | |
144 | # |
|
144 | # | |
145 | # |
|
145 | # | |
146 | # |
|
146 | # | |
147 | # |
|
147 | # | |
148 | # return redirect('url_cgs_conf', id_conf=conf.id) |
|
148 | # return redirect('url_cgs_conf', id_conf=conf.id) | |
149 | # |
|
149 | # | |
150 | # def cgs_conf_read(request, id_conf): |
|
150 | # def cgs_conf_read(request, id_conf): | |
151 | # |
|
151 | # | |
152 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
152 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) | |
153 | # |
|
153 | # | |
154 | # ip=conf.device.ip_address |
|
154 | # ip=conf.device.ip_address | |
155 | # port=conf.device.port_address |
|
155 | # port=conf.device.port_address | |
156 | # |
|
156 | # | |
157 | # if request.method=='POST': |
|
157 | # if request.method=='POST': | |
158 | # form = CGSConfigurationForm(request.POST, instance=conf) |
|
158 | # form = CGSConfigurationForm(request.POST, instance=conf) | |
159 | # |
|
159 | # | |
160 | # if form.is_valid(): |
|
160 | # if form.is_valid(): | |
161 | # cgs_model = form.save(commit=False) |
|
161 | # cgs_model = form.save(commit=False) | |
162 | # |
|
162 | # | |
163 | # if cgs_model.verify_frequencies(): |
|
163 | # if cgs_model.verify_frequencies(): | |
164 | # |
|
164 | # | |
165 | # cgs_model.save() |
|
165 | # cgs_model.save() | |
166 | # return redirect('url_cgs_conf', id_conf=conf.id) |
|
166 | # return redirect('url_cgs_conf', id_conf=conf.id) | |
167 | # |
|
167 | # | |
168 | # messages.error(request, "Parameters could not be saved. Invalid parameters") |
|
168 | # messages.error(request, "Parameters could not be saved. Invalid parameters") | |
169 | # |
|
169 | # | |
170 | # data = {} |
|
170 | # data = {} | |
171 | # |
|
171 | # | |
172 | # |
|
172 | # | |
173 | # if request.method=='GET': |
|
173 | # if request.method=='GET': | |
174 | # #r: response = icon, status |
|
174 | # #r: response = icon, status | |
175 | # route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" |
|
175 | # route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" | |
176 | # try: |
|
176 | # try: | |
177 | # r = requests.get(route) |
|
177 | # r = requests.get(route) | |
178 | # response = str(r.text) |
|
178 | # response = str(r.text) | |
179 | # response = response.split(";") |
|
179 | # response = response.split(";") | |
180 | # icon = response[0] |
|
180 | # icon = response[0] | |
181 | # status = response[-1] |
|
181 | # status = response[-1] | |
182 | # print r.text |
|
182 | # print r.text | |
183 | # #"icon" could be: "alert" or "okay" |
|
183 | # #"icon" could be: "alert" or "okay" | |
184 | # if "okay" in icon: |
|
184 | # if "okay" in icon: | |
185 | # messages.success(request, status) |
|
185 | # messages.success(request, status) | |
186 | # else: |
|
186 | # else: | |
187 | # messages.error(request, status) |
|
187 | # messages.error(request, status) | |
188 | # #Get Frequencies |
|
188 | # #Get Frequencies | |
189 | # route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" |
|
189 | # route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" | |
190 | # #frequencies = requests.get('http://10.10.10.175:8080/frequencies/') |
|
190 | # #frequencies = requests.get('http://10.10.10.175:8080/frequencies/') | |
191 | # frequencies = requests.get(route) |
|
191 | # frequencies = requests.get(route) | |
192 | # frequencies = frequencies.json() |
|
192 | # frequencies = frequencies.json() | |
193 | # frequencies = frequencies.get("Frecuencias") |
|
193 | # frequencies = frequencies.get("Frecuencias") | |
194 | # f0 = frequencies.get("f0") |
|
194 | # f0 = frequencies.get("f0") | |
195 | # f1 = frequencies.get("f1") |
|
195 | # f1 = frequencies.get("f1") | |
196 | # f2 = frequencies.get("f2") |
|
196 | # f2 = frequencies.get("f2") | |
197 | # f3 = frequencies.get("f3") |
|
197 | # f3 = frequencies.get("f3") | |
198 | # print f0,f1,f2,f3 |
|
198 | # print f0,f1,f2,f3 | |
199 | # |
|
199 | # | |
200 | # |
|
200 | # | |
201 | # if not response: |
|
201 | # if not response: | |
202 | # messages.error(request, "Could not read parameters from Device") |
|
202 | # messages.error(request, "Could not read parameters from Device") | |
203 | # return redirect('url_cgs_conf', id_conf=conf.id) |
|
203 | # return redirect('url_cgs_conf', id_conf=conf.id) | |
204 | # |
|
204 | # | |
205 | # data = {'experiment' : conf.experiment.id, |
|
205 | # data = {'experiment' : conf.experiment.id, | |
206 | # 'device' : conf.device.id, |
|
206 | # 'device' : conf.device.id, | |
207 | # 'freq0' : f0, |
|
207 | # 'freq0' : f0, | |
208 | # 'freq1' : f1, |
|
208 | # 'freq1' : f1, | |
209 | # 'freq2' : f2, |
|
209 | # 'freq2' : f2, | |
210 | # 'freq3' : f3, |
|
210 | # 'freq3' : f3, | |
211 | # } |
|
211 | # } | |
212 | # except: |
|
212 | # except: | |
213 | # messages.error(request, "Could not read parameters from Device") |
|
213 | # messages.error(request, "Could not read parameters from Device") | |
214 | # data = {'experiment' : conf.experiment.id, |
|
214 | # data = {'experiment' : conf.experiment.id, | |
215 | # 'device' : conf.device.id, |
|
215 | # 'device' : conf.device.id, | |
216 | # 'freq0' : None, |
|
216 | # 'freq0' : None, | |
217 | # 'freq1' : None, |
|
217 | # 'freq1' : None, | |
218 | # 'freq2' : None, |
|
218 | # 'freq2' : None, | |
219 | # 'freq3' : None, |
|
219 | # 'freq3' : None, | |
220 | # } |
|
220 | # } | |
221 | # return redirect('url_cgs_conf', id_conf=conf.id) |
|
221 | # return redirect('url_cgs_conf', id_conf=conf.id) | |
222 | # |
|
222 | # | |
223 | # form = CGSConfigurationForm(initial = data) |
|
223 | # form = CGSConfigurationForm(initial = data) | |
224 | # |
|
224 | # | |
225 | # kwargs = {} |
|
225 | # kwargs = {} | |
226 | # kwargs['id_dev'] = conf.id |
|
226 | # kwargs['id_dev'] = conf.id | |
227 | # kwargs['form'] = form |
|
227 | # kwargs['form'] = form | |
228 | # kwargs['title'] = 'Device Configuration' |
|
228 | # kwargs['title'] = 'Device Configuration' | |
229 | # kwargs['suptitle'] = 'Parameters read from device' |
|
229 | # kwargs['suptitle'] = 'Parameters read from device' | |
230 | # kwargs['button'] = 'Save' |
|
230 | # kwargs['button'] = 'Save' | |
231 | # |
|
231 | # | |
232 | # ###### SIDEBAR ###### |
|
232 | # ###### SIDEBAR ###### | |
233 | # kwargs.update(sidebar(conf)) |
|
233 | # kwargs.update(sidebar(conf)) | |
234 | # |
|
234 | # | |
235 | # return render(request, 'cgs_conf_edit.html', kwargs) |
|
235 | # return render(request, 'cgs_conf_edit.html', kwargs) | |
236 | # |
|
236 | # | |
237 | # def cgs_conf_import(request, id_conf): |
|
237 | # def cgs_conf_import(request, id_conf): | |
238 | # |
|
238 | # | |
239 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
239 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) | |
240 | # |
|
240 | # | |
241 | # if request.method == 'POST': |
|
241 | # if request.method == 'POST': | |
242 | # file_form = UploadFileForm(request.POST, request.FILES) |
|
242 | # file_form = UploadFileForm(request.POST, request.FILES) | |
243 | # |
|
243 | # | |
244 | # if file_form.is_valid(): |
|
244 | # if file_form.is_valid(): | |
245 | # |
|
245 | # | |
246 | # try: |
|
246 | # try: | |
247 | # if conf.update_from_file(request.FILES['file']): |
|
247 | # if conf.update_from_file(request.FILES['file']): | |
248 | # |
|
248 | # | |
249 | # try: |
|
249 | # try: | |
250 | # conf.full_clean() |
|
250 | # conf.full_clean() | |
251 | # except ValidationError as e: |
|
251 | # except ValidationError as e: | |
252 | # messages.error(request, e) |
|
252 | # messages.error(request, e) | |
253 | # else: |
|
253 | # else: | |
254 | # conf.save() |
|
254 | # conf.save() | |
255 | # |
|
255 | # | |
256 | # messages.success(request, "Parameters imported from file: '%s'." %request.FILES['file'].name) |
|
256 | # messages.success(request, "Parameters imported from file: '%s'." %request.FILES['file'].name) | |
257 | # #messages.warning(request,"") |
|
257 | # #messages.warning(request,"") | |
258 | # return redirect('url_cgs_conf', id_conf=conf.id) |
|
258 | # return redirect('url_cgs_conf', id_conf=conf.id) | |
259 | # except: |
|
259 | # except: | |
260 | # messages.error(request, "No JSON object could be decoded.") |
|
260 | # messages.error(request, "No JSON object could be decoded.") | |
261 | # |
|
261 | # | |
262 | # messages.error(request, "Could not import parameters from file") |
|
262 | # messages.error(request, "Could not import parameters from file") | |
263 | # |
|
263 | # | |
264 | # else: |
|
264 | # else: | |
265 | # file_form = UploadFileForm(initial={'title': '.json'}) |
|
265 | # file_form = UploadFileForm(initial={'title': '.json'}) | |
266 | # |
|
266 | # | |
267 | # |
|
267 | # | |
268 | # kwargs = {} |
|
268 | # kwargs = {} | |
269 | # kwargs['id_dev'] = conf.id |
|
269 | # kwargs['id_dev'] = conf.id | |
270 | # kwargs['title'] = 'Device Configuration' |
|
270 | # kwargs['title'] = 'Device Configuration' | |
271 | # kwargs['form'] = file_form |
|
271 | # kwargs['form'] = file_form | |
272 | # kwargs['suptitle'] = 'Importing file' |
|
272 | # kwargs['suptitle'] = 'Importing file' | |
273 | # kwargs['button'] = 'Import' |
|
273 | # kwargs['button'] = 'Import' | |
274 | # |
|
274 | # | |
275 | # kwargs.update(sidebar(conf)) |
|
275 | # kwargs.update(sidebar(conf)) | |
276 | # |
|
276 | # | |
277 | # return render(request, 'cgs_conf_import.html', kwargs) |
|
277 | # return render(request, 'cgs_conf_import.html', kwargs) | |
278 | # |
|
278 | # | |
279 | # def handle_uploaded_file(f): |
|
279 | # def handle_uploaded_file(f): | |
280 | # |
|
280 | # | |
281 | # data = {'freq0' : 62500000, |
|
281 | # data = {'freq0' : 62500000, | |
282 | # 'freq1' : 62500000, |
|
282 | # 'freq1' : 62500000, | |
283 | # 'freq2' : 62500000, |
|
283 | # 'freq2' : 62500000, | |
284 | # 'freq3' : 62500000, |
|
284 | # 'freq3' : 62500000, | |
285 | # } |
|
285 | # } | |
286 | # |
|
286 | # | |
287 | # return data |
|
287 | # return data | |
288 | # |
|
288 | # | |
289 | # def cgs_conf_export(request, id_conf): |
|
289 | # def cgs_conf_export(request, id_conf): | |
290 | # |
|
290 | # | |
291 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
291 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) | |
292 | # ip=conf.device.ip_address |
|
292 | # ip=conf.device.ip_address | |
293 | # port=conf.device.port_address |
|
293 | # port=conf.device.port_address | |
294 | # |
|
294 | # | |
295 | # #if request.method=='GET': |
|
295 | # #if request.method=='GET': | |
296 | # # data = {"Frequencies": [ |
|
296 | # # data = {"Frequencies": [ | |
297 | # # ["freq0", conf.freq0], |
|
297 | # # ["freq0", conf.freq0], | |
298 | # # ["freq1", conf.freq1], |
|
298 | # # ["freq1", conf.freq1], | |
299 | # # ["freq2", conf.freq2], |
|
299 | # # ["freq2", conf.freq2], | |
300 | # # ["freq3", conf.freq3] |
|
300 | # # ["freq3", conf.freq3] | |
301 | # # ]} |
|
301 | # # ]} | |
302 | # # json_data = json.dumps(data) |
|
302 | # # json_data = json.dumps(data) | |
303 | # # conf.parameters = json_data |
|
303 | # # conf.parameters = json_data | |
304 | # # response = HttpResponse(conf.parameters, content_type="application/json") |
|
304 | # # response = HttpResponse(conf.parameters, content_type="application/json") | |
305 | # # response['Content-Disposition'] = 'attachment; filename="data.json"' |
|
305 | # # response['Content-Disposition'] = 'attachment; filename="data.json"' | |
306 | # |
|
306 | # | |
307 | # # return response |
|
307 | # # return response | |
308 | # |
|
308 | # | |
309 | # kwargs = {} |
|
309 | # kwargs = {} | |
310 | # kwargs['dev_conf'] = conf |
|
310 | # kwargs['dev_conf'] = conf | |
311 | # kwargs['dev_conf_keys'] = ['experiment', 'device', |
|
311 | # kwargs['dev_conf_keys'] = ['experiment', 'device', | |
312 | # 'freq0', 'freq1', |
|
312 | # 'freq0', 'freq1', | |
313 | # 'freq2', 'freq3'] |
|
313 | # 'freq2', 'freq3'] | |
314 | # |
|
314 | # | |
315 | # kwargs['title'] = 'CGS Configuration' |
|
315 | # kwargs['title'] = 'CGS Configuration' | |
316 | # kwargs['suptitle'] = 'Details' |
|
316 | # kwargs['suptitle'] = 'Details' | |
317 | # |
|
317 | # | |
318 | # kwargs['button'] = 'Edit Configuration' |
|
318 | # kwargs['button'] = 'Edit Configuration' | |
319 | # |
|
319 | # | |
320 | # ###### SIDEBAR ###### |
|
320 | # ###### SIDEBAR ###### | |
321 | # kwargs.update(sidebar(conf)) |
|
321 | # kwargs.update(sidebar(conf)) | |
322 | # return render(request, 'cgs_conf.html', kwargs) |
|
322 | # return render(request, 'cgs_conf.html', kwargs) |
General Comments 0
You need to be logged in to leave comments.
Login now