@@ -72,38 +72,25 class CGSConfiguration(Configuration): | |||
|
72 | 72 | |
|
73 | 73 | def status_device(self): |
|
74 | 74 | |
|
75 | import requests | |
|
76 | ||
|
77 | 75 | ip=self.device.ip_address |
|
78 | 76 | port=self.device.port_address |
|
79 | 77 | |
|
80 |
route = "http://" + str(ip) + ":" + str(port) + "/status/ |
|
|
78 | route = "http://" + str(ip) + ":" + str(port) + "/status/" | |
|
81 | 79 | try: |
|
82 |
r = requests.get(route, timeout=0. |
|
|
80 | r = requests.get(route, timeout=0.7) | |
|
83 | 81 | except Exception as e: |
|
84 | 82 | self.device.status = 0 |
|
85 | 83 | self.device.save() |
|
86 | 84 | self.message = 'Could not read CGS status: ' + str(e) |
|
87 | 85 | return False |
|
88 | 86 | |
|
89 |
response = |
|
|
90 | response = response.split(";") | |
|
91 |
|
|
|
92 | status = response[-1] | |
|
87 | response = r.json() | |
|
88 | self.device.status = response['status'] | |
|
89 | self.message = response['message'] | |
|
90 | self.device.save() | |
|
93 | 91 | |
|
94 | #"icon" could be: "alert" or "okay" | |
|
95 | if "alert" in icon: | |
|
96 | self.device.status = 1 | |
|
97 | self.device.save() | |
|
98 | self.message = status | |
|
92 | if response['components_status']==0: | |
|
99 | 93 | return False |
|
100 | elif "okay" in icon: | |
|
101 | self.device.status = 3 | |
|
102 | else: | |
|
103 | self.device.status = 1 | |
|
104 | ||
|
105 | self.message = status | |
|
106 | self.device.save() | |
|
107 | 94 | |
|
108 | 95 | return True |
|
109 | 96 | |
@@ -152,44 +139,38 class CGSConfiguration(Configuration): | |||
|
152 | 139 | ip=self.device.ip_address |
|
153 | 140 | port=self.device.port_address |
|
154 | 141 | |
|
155 | f0 = 0 | |
|
156 | f1 = 0 | |
|
157 | f2 = 0 | |
|
158 | f3 = 0 | |
|
159 |
post_data = {"f0": |
|
|
160 |
route = "http://" + str(ip) + ":" + str(port) + "/ |
|
|
142 | if self.device.status == 2: #Configured | |
|
143 | self.message = 'CGS device is already stopped.' | |
|
144 | return False | |
|
145 | ||
|
146 | post_data = {"freq0":0, "freq1":0, "freq2":0, "freq3":0} | |
|
147 | route = "http://" + str(ip) + ":" + str(port) + "/write/" | |
|
161 | 148 | |
|
162 | 149 | try: |
|
163 | 150 | r = requests.post(route, post_data, timeout=0.7) |
|
164 | except: | |
|
165 |
self.message = "Could not |
|
|
151 | except Exception as e: | |
|
152 | self.message = "Could not write CGS parameters. "+str(e) | |
|
153 | self.device.status = 0 | |
|
154 | self.device.save() | |
|
166 | 155 | return False |
|
167 | 156 | |
|
168 | text = r.text | |
|
169 | text = text.split(',') | |
|
157 | response = r.json() | |
|
158 | status = response['status'] | |
|
159 | if status == 1: | |
|
160 | self.device.status = status | |
|
161 | self.device.save() | |
|
162 | self.message = 'Could not stop CGS device.' | |
|
163 | return False | |
|
170 | 164 | |
|
171 | if len(text)>1: | |
|
172 | title = text[0] | |
|
173 | status = text[1] | |
|
174 | if title == "okay": | |
|
175 | self.message = status | |
|
176 | self.device.status = 1 | |
|
177 | self.device.save() | |
|
178 | self.message = "CGS device has been stopped" | |
|
179 | return True | |
|
180 | else: | |
|
181 | self.message = title + ", " + status | |
|
182 | self.device.status = 0 | |
|
183 | self.device.save() | |
|
184 | return False | |
|
165 | self.message = 'CGS device has been stopped successfully.' | |
|
166 | self.device.status = 2 | |
|
167 | self.device.save() | |
|
185 | 168 | |
|
186 |
return |
|
|
169 | return True | |
|
187 | 170 | |
|
188 | 171 | |
|
189 | 172 | def read_device(self): |
|
190 | 173 | |
|
191 | import requests | |
|
192 | ||
|
193 | 174 | ip=self.device.ip_address |
|
194 | 175 | port=self.device.port_address |
|
195 | 176 | |
@@ -249,7 +230,7 class CGSConfiguration(Configuration): | |||
|
249 | 230 | |
|
250 | 231 | if self.device.status==1: |
|
251 | 232 | return False |
|
252 | ||
|
233 | ||
|
253 | 234 | return True |
|
254 | 235 | |
|
255 | 236 |
General Comments 0
You need to be logged in to leave comments.
Login now