@@ -8,6 +8,8 from .forms import CGSConfigurationForm | |||||
8 | from apps.main.views import sidebar |
|
8 | from apps.main.views import sidebar | |
9 |
|
9 | |||
10 | import requests |
|
10 | import requests | |
|
11 | import json | |||
|
12 | from __builtin__ import None | |||
11 | # Create your views here. |
|
13 | # Create your views here. | |
12 |
|
14 | |||
13 | def cgs_conf(request, id_conf): |
|
15 | def cgs_conf(request, id_conf): | |
@@ -21,6 +23,7 def cgs_conf(request, id_conf): | |||||
21 |
|
23 | |||
22 | if request.method=='GET': |
|
24 | if request.method=='GET': | |
23 | #r: response = icon, status |
|
25 | #r: response = icon, status | |
|
26 | try: | |||
24 | route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" |
|
27 | route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" | |
25 | r = requests.get(route) |
|
28 | r = requests.get(route) | |
26 | response = str(r.text) |
|
29 | response = str(r.text) | |
@@ -40,6 +43,10 def cgs_conf(request, id_conf): | |||||
40 | else: |
|
43 | else: | |
41 | kwargs['connected'] = False |
|
44 | kwargs['connected'] = False | |
42 |
|
45 | |||
|
46 | except: | |||
|
47 | kwargs['connected'] = False | |||
|
48 | status = "The Device is not connected." | |||
|
49 | ||||
43 | if not kwargs['connected']: |
|
50 | if not kwargs['connected']: | |
44 | messages.error(request, message=status) |
|
51 | messages.error(request, message=status) | |
45 |
|
52 | |||
@@ -73,6 +80,17 def cgs_conf_edit(request, id_conf): | |||||
73 |
|
80 | |||
74 | if conf.verify_frequencies(): |
|
81 | if conf.verify_frequencies(): | |
75 |
|
82 | |||
|
83 | if conf.freq0 == None: conf.freq0 = 0 | |||
|
84 | if conf.freq1 == None: conf.freq0 = 0 | |||
|
85 | if conf.freq2 == None: conf.freq0 = 0 | |||
|
86 | if conf.freq3 == None: conf.freq0 = 0 | |||
|
87 | ||||
|
88 | ||||
|
89 | data = {'f0': str(conf.freq0), 'f1': str(conf.freq1), | |||
|
90 | 'f2': str(conf.freq2), 'f3': str(conf.freq3)} | |||
|
91 | json_data = json.dumps(data) | |||
|
92 | conf.parameters = json_data | |||
|
93 | ||||
76 | conf.save() |
|
94 | conf.save() | |
77 | return redirect('url_cgs_conf', id_conf=conf.id) |
|
95 | return redirect('url_cgs_conf', id_conf=conf.id) | |
78 |
|
96 | |||
@@ -85,6 +103,7 def cgs_conf_edit(request, id_conf): | |||||
85 | kwargs['suptitle'] = 'Edit' |
|
103 | kwargs['suptitle'] = 'Edit' | |
86 | kwargs['button'] = 'Save' |
|
104 | kwargs['button'] = 'Save' | |
87 |
|
105 | |||
|
106 | ||||
88 | ###### SIDEBAR ###### |
|
107 | ###### SIDEBAR ###### | |
89 | kwargs.update(sidebar(conf)) |
|
108 | kwargs.update(sidebar(conf)) | |
90 |
|
109 | |||
@@ -97,10 +116,16 def cgs_conf_write(request, id_conf): | |||||
97 | port=conf.device.port_address |
|
116 | port=conf.device.port_address | |
98 |
|
117 | |||
99 | #Frequencies from form |
|
118 | #Frequencies from form | |
|
119 | if conf.freq0 == None: conf.freq0 = 0 | |||
|
120 | if conf.freq1 == None: conf.freq0 = 0 | |||
|
121 | if conf.freq2 == None: conf.freq0 = 0 | |||
|
122 | if conf.freq3 == None: conf.freq0 = 0 | |||
100 | f0 = int(conf.freq0) |
|
123 | f0 = int(conf.freq0) | |
101 | f1 = int(conf.freq1) |
|
124 | f1 = int(conf.freq1) | |
102 | f2 = int(conf.freq2) |
|
125 | f2 = int(conf.freq2) | |
103 | f3 = int(conf.freq3) |
|
126 | f3 = int(conf.freq3) | |
|
127 | ||||
|
128 | ||||
104 | post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} |
|
129 | post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} | |
105 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" |
|
130 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" | |
106 | r = requests.post(route, post_data) |
|
131 | r = requests.post(route, post_data) | |
@@ -108,13 +133,19 def cgs_conf_write(request, id_conf): | |||||
108 | text = text.split(',') |
|
133 | text = text.split(',') | |
109 |
|
134 | |||
110 | try: |
|
135 | try: | |
|
136 | if len(text)>1: | |||
111 | title = text[0] |
|
137 | title = text[0] | |
112 | status = text[1] |
|
138 | status = text[1] | |
113 | status_ok = r.status_code |
|
139 | status_ok = r.status_code | |
114 |
if |
|
140 | if title == "okay": | |
115 | messages.success(request, status) |
|
141 | messages.success(request, status) | |
116 | else: |
|
142 | else: | |
117 | messages.error(request, status) |
|
143 | messages.error(request, status) | |
|
144 | ||||
|
145 | else: | |||
|
146 | title = text[0] | |||
|
147 | messages.error(request, title) | |||
|
148 | ||||
118 | except: |
|
149 | except: | |
119 | messages.error(request, "An hardware error was found") |
|
150 | messages.error(request, "An hardware error was found") | |
120 |
|
151 | |||
@@ -126,6 +157,7 def cgs_conf_write(request, id_conf): | |||||
126 | def cgs_conf_read(request, id_conf): |
|
157 | def cgs_conf_read(request, id_conf): | |
127 |
|
158 | |||
128 | conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
159 | conf = get_object_or_404(CGSConfiguration, pk=id_conf) | |
|
160 | ||||
129 | ip=conf.device.ip_address |
|
161 | ip=conf.device.ip_address | |
130 | port=conf.device.port_address |
|
162 | port=conf.device.port_address | |
131 |
|
163 | |||
@@ -148,6 +180,7 def cgs_conf_read(request, id_conf): | |||||
148 | if request.method=='GET': |
|
180 | if request.method=='GET': | |
149 | #r: response = icon, status |
|
181 | #r: response = icon, status | |
150 | route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" |
|
182 | route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" | |
|
183 | try: | |||
151 | r = requests.get(route) |
|
184 | r = requests.get(route) | |
152 | response = str(r.text) |
|
185 | response = str(r.text) | |
153 | response = response.split(";") |
|
186 | response = response.split(";") | |
@@ -183,6 +216,15 def cgs_conf_read(request, id_conf): | |||||
183 | 'freq2' : f2, |
|
216 | 'freq2' : f2, | |
184 | 'freq3' : f3, |
|
217 | 'freq3' : f3, | |
185 | } |
|
218 | } | |
|
219 | except: | |||
|
220 | messages.error(request, "Could not read parameters from Device") | |||
|
221 | data = {'experiment' : conf.experiment.id, | |||
|
222 | 'device' : conf.device.id, | |||
|
223 | 'freq0' : None, | |||
|
224 | 'freq1' : None, | |||
|
225 | 'freq2' : None, | |||
|
226 | 'freq3' : None, | |||
|
227 | } | |||
186 |
|
228 | |||
187 | form = CGSConfigurationForm(initial = data) |
|
229 | form = CGSConfigurationForm(initial = data) | |
188 |
|
230 | |||
@@ -198,10 +240,15 def cgs_conf_read(request, id_conf): | |||||
198 |
|
240 | |||
199 | return render(request, 'cgs_conf_edit.html', kwargs) |
|
241 | return render(request, 'cgs_conf_edit.html', kwargs) | |
200 |
|
242 | |||
201 |
|
|
243 | def cgs_conf_export(request, id_conf): | |
|
244 | ||||
|
245 | conf = get_object_or_404(CGSConfiguration, pk=id_conf) | |||
|
246 | ip=conf.device.ip_address | |||
|
247 | port=conf.device.port_address | |||
|
248 | ||||
|
249 | if request.method=='POST': | |||
|
250 | return HttpResponse(conf.parameters, content_type="application/json") | |||
202 |
|
251 | |||
203 | # conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
252 | return render(request, 'cgs_conf.html') | |
204 | # ip=conf.device.ip_address |
|
253 | #return redirect(conf.get_absolute_url()) | |
205 | # port=conf.device.port_address |
|
|||
206 |
|
254 | |||
207 | # return render(request, 'cgs_conf_export.html', kwargs) No newline at end of file |
|
General Comments 0
You need to be logged in to leave comments.
Login now