@@ -8,6 +8,8 from .forms import CGSConfigurationForm | |||
|
8 | 8 | from apps.main.views import sidebar |
|
9 | 9 | |
|
10 | 10 | import requests |
|
11 | import json | |
|
12 | from __builtin__ import None | |
|
11 | 13 | # Create your views here. |
|
12 | 14 | |
|
13 | 15 | def cgs_conf(request, id_conf): |
@@ -21,6 +23,7 def cgs_conf(request, id_conf): | |||
|
21 | 23 | |
|
22 | 24 | if request.method=='GET': |
|
23 | 25 | #r: response = icon, status |
|
26 | try: | |
|
24 | 27 | route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" |
|
25 | 28 | r = requests.get(route) |
|
26 | 29 | response = str(r.text) |
@@ -40,6 +43,10 def cgs_conf(request, id_conf): | |||
|
40 | 43 | else: |
|
41 | 44 | kwargs['connected'] = False |
|
42 | 45 | |
|
46 | except: | |
|
47 | kwargs['connected'] = False | |
|
48 | status = "The Device is not connected." | |
|
49 | ||
|
43 | 50 | if not kwargs['connected']: |
|
44 | 51 | messages.error(request, message=status) |
|
45 | 52 | |
@@ -73,6 +80,17 def cgs_conf_edit(request, id_conf): | |||
|
73 | 80 | |
|
74 | 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 | 94 | conf.save() |
|
77 | 95 | return redirect('url_cgs_conf', id_conf=conf.id) |
|
78 | 96 | |
@@ -85,6 +103,7 def cgs_conf_edit(request, id_conf): | |||
|
85 | 103 | kwargs['suptitle'] = 'Edit' |
|
86 | 104 | kwargs['button'] = 'Save' |
|
87 | 105 | |
|
106 | ||
|
88 | 107 | ###### SIDEBAR ###### |
|
89 | 108 | kwargs.update(sidebar(conf)) |
|
90 | 109 | |
@@ -97,10 +116,16 def cgs_conf_write(request, id_conf): | |||
|
97 | 116 | port=conf.device.port_address |
|
98 | 117 | |
|
99 | 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 | 123 | f0 = int(conf.freq0) |
|
101 | 124 | f1 = int(conf.freq1) |
|
102 | 125 | f2 = int(conf.freq2) |
|
103 | 126 | f3 = int(conf.freq3) |
|
127 | ||
|
128 | ||
|
104 | 129 | post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} |
|
105 | 130 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" |
|
106 | 131 | r = requests.post(route, post_data) |
@@ -108,13 +133,19 def cgs_conf_write(request, id_conf): | |||
|
108 | 133 | text = text.split(',') |
|
109 | 134 | |
|
110 | 135 | try: |
|
136 | if len(text)>1: | |
|
111 | 137 | title = text[0] |
|
112 | 138 | status = text[1] |
|
113 | 139 | status_ok = r.status_code |
|
114 |
if |
|
|
140 | if title == "okay": | |
|
115 | 141 | messages.success(request, status) |
|
116 | 142 | else: |
|
117 | 143 | messages.error(request, status) |
|
144 | ||
|
145 | else: | |
|
146 | title = text[0] | |
|
147 | messages.error(request, title) | |
|
148 | ||
|
118 | 149 | except: |
|
119 | 150 | messages.error(request, "An hardware error was found") |
|
120 | 151 | |
@@ -126,6 +157,7 def cgs_conf_write(request, id_conf): | |||
|
126 | 157 | def cgs_conf_read(request, id_conf): |
|
127 | 158 | |
|
128 | 159 | conf = get_object_or_404(CGSConfiguration, pk=id_conf) |
|
160 | ||
|
129 | 161 | ip=conf.device.ip_address |
|
130 | 162 | port=conf.device.port_address |
|
131 | 163 | |
@@ -148,6 +180,7 def cgs_conf_read(request, id_conf): | |||
|
148 | 180 | if request.method=='GET': |
|
149 | 181 | #r: response = icon, status |
|
150 | 182 | route = "http://" + str(ip) + ":" + str(port) + "/status/ad9548" |
|
183 | try: | |
|
151 | 184 | r = requests.get(route) |
|
152 | 185 | response = str(r.text) |
|
153 | 186 | response = response.split(";") |
@@ -183,6 +216,15 def cgs_conf_read(request, id_conf): | |||
|
183 | 216 | 'freq2' : f2, |
|
184 | 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 | 229 | form = CGSConfigurationForm(initial = data) |
|
188 | 230 | |
@@ -198,10 +240,15 def cgs_conf_read(request, id_conf): | |||
|
198 | 240 | |
|
199 | 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) | |
|
204 | # ip=conf.device.ip_address | |
|
205 | # port=conf.device.port_address | |
|
252 | return render(request, 'cgs_conf.html') | |
|
253 | #return redirect(conf.get_absolute_url()) | |
|
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