@@ -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] | |
|
93 | ||
|
94 | #"icon" could be: "alert" or "okay" | |
|
95 | if "alert" in icon: | |
|
96 | self.device.status = 1 | |
|
87 | response = r.json() | |
|
88 | self.device.status = response['status'] | |
|
89 | self.message = response['message'] | |
|
97 | 90 |
|
|
98 | self.message = status | |
|
99 | return False | |
|
100 | elif "okay" in icon: | |
|
101 | self.device.status = 3 | |
|
102 | else: | |
|
103 | self.device.status = 1 | |
|
104 | 91 | |
|
105 | self.message = status | |
|
106 | self.device.save() | |
|
92 | if response['components_status']==0: | |
|
93 | return False | |
|
107 | 94 | |
|
108 | 95 | return True |
|
109 | 96 | |
@@ -152,43 +139,37 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":f0, "f1":f1, "f2":f2, "f3":f3} | |
|
160 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" | |
|
161 | ||
|
162 | try: | |
|
163 | r = requests.post(route, post_data, timeout=0.7) | |
|
164 | except: | |
|
165 | self.message = "Could not stop CGS device" | |
|
142 | if self.device.status == 2: #Configured | |
|
143 | self.message = 'CGS device is already stopped.' | |
|
166 | 144 | return False |
|
167 | 145 | |
|
168 | text = r.text | |
|
169 | text = text.split(',') | |
|
146 | post_data = {"freq0":0, "freq1":0, "freq2":0, "freq3":0} | |
|
147 | route = "http://" + str(ip) + ":" + str(port) + "/write/" | |
|
170 | 148 | |
|
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 | |
|
149 | try: | |
|
150 | r = requests.post(route, post_data, timeout=0.7) | |
|
151 | except Exception as e: | |
|
152 | self.message = "Could not write CGS parameters. "+str(e) | |
|
182 | 153 |
|
|
183 | 154 |
|
|
184 | 155 |
|
|
185 | 156 | |
|
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.' | |
|
186 | 163 | return False |
|
187 | 164 | |
|
165 | self.message = 'CGS device has been stopped successfully.' | |
|
166 | self.device.status = 2 | |
|
167 | self.device.save() | |
|
188 | 168 | |
|
189 | def read_device(self): | |
|
169 | return True | |
|
190 | 170 | |
|
191 | import requests | |
|
171 | ||
|
172 | def read_device(self): | |
|
192 | 173 | |
|
193 | 174 | ip=self.device.ip_address |
|
194 | 175 | port=self.device.port_address |
General Comments 0
You need to be logged in to leave comments.
Login now