@@ -3,6 +3,7 from apps.main.models import Configuration | |||
|
3 | 3 | from django.core.validators import MinValueValidator, MaxValueValidator |
|
4 | 4 | |
|
5 | 5 | from .files import read_json_file |
|
6 | import requests | |
|
6 | 7 | # Create your models here. validators=[MinValueValidator(62.5e6), MaxValueValidator(450e6)] |
|
7 | 8 | |
|
8 | 9 | class CGSConfiguration(Configuration): |
@@ -108,6 +109,84 class CGSConfiguration(Configuration): | |||
|
108 | 109 | return True |
|
109 | 110 | |
|
110 | 111 | |
|
112 | def start_device(self): | |
|
113 | ||
|
114 | ip=self.device.ip_address | |
|
115 | port=self.device.port_address | |
|
116 | ||
|
117 | #---Frequencies from form | |
|
118 | f0 = self.freq0 | |
|
119 | f1 = self.freq1 | |
|
120 | f2 = self.freq2 | |
|
121 | f3 = self.freq3 | |
|
122 | post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} | |
|
123 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" | |
|
124 | ||
|
125 | try: | |
|
126 | r = requests.post(route, post_data, timeout=0.7) | |
|
127 | except: | |
|
128 | self.message = "Could not start CGS device" | |
|
129 | return False | |
|
130 | ||
|
131 | text = r.text | |
|
132 | text = text.split(',') | |
|
133 | ||
|
134 | if len(text)>1: | |
|
135 | title = text[0] | |
|
136 | status = text[1] | |
|
137 | if title == "okay": | |
|
138 | self.message = status | |
|
139 | self.device.status = 3 | |
|
140 | self.device.save() | |
|
141 | return True | |
|
142 | else: | |
|
143 | self.message = title + ", " + status | |
|
144 | self.device.status = 1 | |
|
145 | self.device.save() | |
|
146 | return False | |
|
147 | ||
|
148 | return False | |
|
149 | ||
|
150 | ||
|
151 | def stop_device(self): | |
|
152 | ||
|
153 | ip=self.device.ip_address | |
|
154 | port=self.device.port_address | |
|
155 | ||
|
156 | f0 = 0 | |
|
157 | f1 = 0 | |
|
158 | f2 = 0 | |
|
159 | f3 = 0 | |
|
160 | post_data = {"f0":f0, "f1":f1, "f2":f2, "f3":f3} | |
|
161 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" | |
|
162 | ||
|
163 | try: | |
|
164 | r = requests.post(route, post_data, timeout=0.7) | |
|
165 | except: | |
|
166 | self.message = "Could not stop CGS device" | |
|
167 | return False | |
|
168 | ||
|
169 | text = r.text | |
|
170 | text = text.split(',') | |
|
171 | ||
|
172 | if len(text)>1: | |
|
173 | title = text[0] | |
|
174 | status = text[1] | |
|
175 | if title == "okay": | |
|
176 | self.message = status | |
|
177 | self.device.status = 1 | |
|
178 | self.device.save() | |
|
179 | self.message = "CGS device has been stopped" | |
|
180 | return True | |
|
181 | else: | |
|
182 | self.message = title + ", " + status | |
|
183 | self.device.status = 0 | |
|
184 | self.device.save() | |
|
185 | return False | |
|
186 | ||
|
187 | return False | |
|
188 | ||
|
189 | ||
|
111 | 190 | def read_device(self): |
|
112 | 191 | |
|
113 | 192 | import requests |
@@ -117,7 +196,7 class CGSConfiguration(Configuration): | |||
|
117 | 196 | |
|
118 | 197 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" |
|
119 | 198 | try: |
|
120 |
frequencies = requests.get(route,timeout=0. |
|
|
199 | frequencies = requests.get(route,timeout=0.7) | |
|
121 | 200 | |
|
122 | 201 | except: |
|
123 | 202 | self.message = "Could not read CGS parameters from this device" |
@@ -141,8 +220,6 class CGSConfiguration(Configuration): | |||
|
141 | 220 | |
|
142 | 221 | def write_device(self): |
|
143 | 222 | |
|
144 | import requests | |
|
145 | ||
|
146 | 223 | ip=self.device.ip_address |
|
147 | 224 | port=self.device.port_address |
|
148 | 225 | |
@@ -155,7 +232,7 class CGSConfiguration(Configuration): | |||
|
155 | 232 | route = "http://" + str(ip) + ":" + str(port) + "/frequencies/" |
|
156 | 233 | |
|
157 | 234 | try: |
|
158 |
r = requests.post(route, post_data, timeout=0. |
|
|
235 | r = requests.post(route, post_data, timeout=0.7) | |
|
159 | 236 | except: |
|
160 | 237 | self.message = "Could not write CGS parameters" |
|
161 | 238 | return False |
General Comments 0
You need to be logged in to leave comments.
Login now