##// 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]
93
94 #"icon" could be: "alert" or "okay"
95 if "alert" in icon:
96 self.device.status = 1
97 self.device.save()
90 self.device.save()
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
92 if response['components_status']==0:
106 self.device.save()
93 return False
107
94
108 return True
95 return True
109
96
@@ -152,43 +139,37 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
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"
166 return False
144 return False
167
145
168 text = r.text
146 post_data = {"freq0":0, "freq1":0, "freq2":0, "freq3":0}
169 text = text.split(',')
147 route = "http://" + str(ip) + ":" + str(port) + "/write/"
170
148
171 if len(text)>1:
149 try:
172 title = text[0]
150 r = requests.post(route, post_data, timeout=0.7)
173 status = text[1]
151 except Exception as e:
174 if title == "okay":
152 self.message = "Could not write CGS parameters. "+str(e)
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
153 self.device.status = 0
183 self.device.save()
154 self.device.save()
184 return False
155 return False
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 return False
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 ip=self.device.ip_address
174 ip=self.device.ip_address
194 port=self.device.port_address
175 port=self.device.port_address
General Comments 0
You need to be logged in to leave comments. Login now