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