Tue, 05 Aug 2014 15:44:29 +0200
Removing units thread
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | <?php |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2 | /***************************************************************************** |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
3 | * Copyright (C) 2014 |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
4 | * |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
5 | * Michiel Broek <mbroek at mbse dot eu> |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
6 | * |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
7 | * This file is part of ThermFerm |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
8 | * |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
9 | * This is free software; you can redistribute it and/or modify it |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
10 | * under the terms of the GNU General Public License as published by the |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
11 | * Free Software Foundation; either version 2, or (at your option) any |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
12 | * later version. |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
13 | * |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
14 | * ThermFerm is distributed in the hope that it will be useful, but |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
17 | * General Public License for more details. |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
18 | * |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
19 | * You should have received a copy of the GNU General Public License |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
20 | * along with ThermFerm; see the file COPYING. If not, write to the Free |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
21 | * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
22 | *****************************************************************************/ |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
23 | |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
24 | require_once('utilities.php'); |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
25 | |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
26 | |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
27 | $sock = open_socket(); |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
28 | if ($sock == false) { |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
29 | echo ""; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
30 | return; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
31 | } |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
32 | |
174 | 33 | socket_write($sock, "DEVICE LIST", 4096); |
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
34 | $answer = ""; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
35 | while (1) { |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
36 | $line = socket_read($sock, 4096); |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
37 | if ($line === '') |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
38 | break; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
39 | $answer .= $line; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
40 | } |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
41 | socket_close($sock); |
174 | 42 | |
43 | /* | |
44 | * $arr contains the complete reply of the LIST BUS command | |
45 | */ | |
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
46 | $arr = explode("\r\n", $answer); |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
47 | |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
48 | |
174 | 49 | if (isset($_GET['action'])) { |
50 | switch ($_GET['action']) { | |
51 | case 'edit': device_edit(); | |
52 | break; | |
53 | default: break; | |
54 | } | |
55 | } elseif (isset($_POST['action'])) { | |
56 | switch ($_POST['action']) { | |
57 | case 'testdata': testdata(); | |
58 | break; | |
59 | default: break; | |
60 | } | |
61 | } else { | |
62 | device_list(); | |
63 | } | |
64 | ||
65 | exit; | |
66 | ||
67 | /**************************************************************************** | |
68 | * | |
69 | */ | |
70 | ||
71 | ||
72 | /* | |
73 | * Device add | |
74 | * | |
75 | * @param string $_POST['Name'] The rpofile name | |
76 | */ | |
77 | function device_add() { | |
78 | ||
79 | if ($_POST['key'] == 'Add') { | |
80 | ||
81 | $cmd = "DEVICE ADD ".$_POST['Type']; | |
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
82 | |
174 | 83 | $sock = open_socket(); |
84 | if ($sock != false) { | |
85 | /* | |
86 | * Send command and absorb the result. | |
87 | */ | |
88 | socket_write($sock, $cmd, 4096); | |
89 | while (1) { | |
90 | $line = socket_read($sock, 4096); | |
91 | if ($line === '') | |
92 | break; | |
93 | } | |
94 | socket_close($sock); | |
95 | } | |
96 | } | |
97 | ||
98 | unset($_POST['UUID']); | |
99 | unset($_POST['Name']); | |
100 | unset($_POST['key']); | |
101 | unset($_POST['command']); | |
102 | load('devices.php'); | |
103 | } | |
104 | ||
105 | ||
106 | ||
107 | /* | |
108 | * Device update | |
109 | * | |
110 | * @param string $_POST['UUID'] The device UUID | |
111 | * @param string $_POST['Type'] The device Type | |
112 | * @param string $_POST['Direction'] The device IO Direction | |
113 | * @param string $_POST['Value'] The device value | |
114 | * @param string $_POST['Present'] The device Present state | |
115 | * @param string $_POST['Address'] The device Address | |
116 | * @param string $_POST['Subdevice'] The device Subaddress | |
117 | * @param string $_POST['Gpiopin'] The device GPIO pin | |
118 | * @param string $_POST['Description'] The device Description | |
119 | * @param string $_POST['Comment'] The device Comment | |
120 | * @param string $_POST['key'] The button pressed. | |
121 | */ | |
122 | function device_update() { | |
123 | /* | |
124 | * Build the update command | |
125 | */ | |
126 | if ($_POST['key'] == 'Delete') { | |
127 | $sock = open_socket(); | |
128 | if ($sock != false) { | |
129 | socket_write($sock, "DEVICE DEL ".$_POST['UUID'], 4096); | |
130 | /* Absorb response */ | |
131 | while (1) { | |
132 | $line = socket_read($sock, 4096); | |
133 | if ($line === '') | |
134 | break; | |
135 | } | |
136 | socket_close($sock); | |
137 | } | |
138 | } | |
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
139 | |
174 | 140 | if ($_POST['key'] == 'Save') { |
141 | $sock = open_socket(); | |
142 | if ($sock != false) { | |
143 | /* | |
144 | * Send command and absorb the result. | |
145 | */ | |
146 | socket_write($sock, "DEVICE PUT ".$_POST['UUID'], 4096); | |
147 | usleep(20000); | |
148 | socket_write($sock, "TYPE,".$_POST['Type'], 4096); | |
149 | usleep(20000); | |
150 | socket_write($sock, "DIRECTION,".$_POST['Direction'], 4096); | |
151 | usleep(20000); | |
152 | socket_write($sock, "VALUE,".$_POST['Value'], 4096); | |
153 | usleep(20000); | |
154 | socket_write($sock, "PRESENT,".$_POST['Present'], 4096); | |
155 | usleep(20000); | |
156 | socket_write($sock, "ADDRESS,".$_POST['Address'], 4096); | |
157 | usleep(20000); | |
158 | socket_write($sock, "SUBDEVICE,".$_POST['Subdevice'], 4096); | |
159 | usleep(20000); | |
160 | socket_write($sock, "GPIOPIN,".$_POST['Gpiopin'], 4096); | |
161 | usleep(20000); | |
162 | socket_write($sock, "DESCRIPTION,".$_POST['Description'], 4096); | |
163 | usleep(20000); | |
164 | socket_write($sock, "COMMENT,".$_POST['Comment'], 4096); | |
165 | usleep(20000); | |
166 | socket_write($sock, '.', 4096); | |
167 | /* Absorb response */ | |
168 | while (1) { | |
169 | $line = socket_read($sock, 4096); | |
170 | if ($line === '') | |
171 | break; | |
172 | } | |
173 | socket_close($sock); | |
174 | } | |
175 | } | |
176 | ||
177 | unset($_POST['UUID']); | |
178 | unset($_POST['Type']); | |
179 | unset($_POST['Direction']); | |
180 | unset($_POST['Value']); | |
181 | unset($_POST['Present']); | |
182 | unset($_POST['Address']); | |
183 | unset($_POST['Subdevice']); | |
184 | unset($_POST['Gpiopin']); | |
185 | unset($_POST['Description']); | |
186 | unset($_POST['Comment']); | |
187 | unset($_POST['key']); | |
188 | unset($_POST['command']); | |
189 | load('devices.php'); | |
190 | } | |
191 | ||
192 | ||
193 | ||
194 | /* | |
195 | * Test input of a modified or new device. | |
196 | * | |
197 | * @param string $_POST['UUID'] Unique record UUID | |
198 | * @param string $_POST['Type'] Device Type | |
199 | * @param string $_POST['Direction'] | |
200 | * @param string $_POST['Value'] | |
201 | * @param string $_POST['Present'] | |
202 | * @param string $_POST['Address'] | |
203 | * @param string $_POST['Subdevice'] | |
204 | * @param string $_POST['Gpiopin'] | |
205 | * @param string $_POST['Description'] | |
206 | * @param string $_POST['Comment'] | |
207 | * @param string $_POST['key'] Key choice, Save or Cancel | |
208 | * @param string $_POST['command'] Command used, 'add' or 'update' | |
209 | * | |
210 | * Return: 0 = Ok | |
211 | * 1 = Missing data | |
212 | * 2 = Address field too short | |
213 | * 3 = Address/Subdevice already in use | |
214 | * 4 = Description field too short | |
215 | * 5 = Comment field too short | |
216 | * 99 = Cancel key | |
217 | */ | |
218 | function test_thedata() { | |
219 | ||
220 | global $arr; | |
221 | ||
222 | if (isset($_POST['UUID']) && isset($_POST['Type']) && isset($_POST['Direction']) && isset($_POST['Value']) && | |
223 | isset($_POST['Present']) && isset($_POST['Address']) && isset($_POST['Subdevice']) && isset($_POST['Gpiopin']) && | |
224 | isset($_POST['Description']) && isset($_POST['Comment']) && isset($_POST['key']) && isset($_POST['command'])) { | |
225 | ||
226 | if ($_POST['key'] == 'Cancel') | |
227 | return 99; | |
228 | ||
229 | if (strlen($_POST['Address']) < 2) | |
230 | return 2; | |
231 | ||
232 | if (startsWith($arr[0], "212")) { | |
233 | $j = 1; | |
234 | while (1) { | |
235 | if (strcmp($arr[$j], ".") == 0) | |
236 | break; | |
237 | $f = explode(",", $arr[$j]); | |
238 | if (strcmp($f[0], $_POST['UUID']) && ($f[1] == $_POST['Address']) && ($f[2] == $_POST['Subdevice'])) { | |
239 | return 3; | |
240 | } | |
241 | $j++; | |
242 | } | |
243 | } | |
244 | ||
245 | if (strlen($_POST['Description']) < 2) | |
246 | return 4; | |
247 | ||
248 | if (strlen($_POST['Comment']) < 2) | |
249 | return 5; | |
250 | ||
251 | } else { | |
252 | return 1; | |
253 | } | |
254 | ||
255 | return 0; | |
256 | } | |
257 | ||
258 | ||
259 | ||
260 | /* | |
261 | * Test result from edit screen and do next action | |
262 | */ | |
263 | function testdata() { | |
264 | ||
265 | $result = test_thedata(); | |
266 | $error = ''; | |
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
267 | |
174 | 268 | switch ($result) { |
269 | case 0: if ($_POST['command'] == 'add') { | |
270 | device_add(); | |
271 | return; | |
272 | } else if ($_POST['command'] == 'update') { | |
273 | device_update(); | |
274 | return; | |
275 | } | |
276 | break; | |
277 | case 1: $error = 'Missing data'; | |
278 | break; | |
279 | case 2: $error = 'The Address is too short'; | |
280 | break; | |
281 | case 3: $error = 'The Address + Subdevice is already in use, choose another one'; | |
282 | break; | |
283 | case 4: $error = 'The Description is too short'; | |
284 | break; | |
285 | case 5: $error = 'The Comment is too short'; | |
286 | break; | |
287 | case 99: | |
288 | load('devices.php'); | |
289 | break; | |
290 | } | |
291 | ||
292 | if ($_POST['command'] == 'add') { | |
293 | $heading = 'ThermFerm - Add Device'; | |
294 | } else { | |
295 | $heading = 'ThermFerm - Edit Device'; | |
296 | } | |
297 | ||
298 | edit_screen($_POST['UUID'], $_POST['command'], $heading, $error); | |
299 | } | |
300 | ||
301 | ||
302 | ||
303 | /* | |
304 | * Unit edit screen. Used by unit_edit(), unit_add() and testdata() | |
305 | * | |
306 | * @param string $UUID The record UUID (fixed). | |
307 | * @param string $command 'add' or 'update' | |
308 | * @param string $heading Page heading title. | |
309 | * @Param string $error_message Blank or previous error. | |
310 | */ | |
311 | function edit_screen($UUID, $command, $heading, $error_message) { | |
312 | ||
313 | $sock = open_socket(); | |
314 | if ($sock == false) { | |
315 | load('devices.php'); | |
316 | } | |
317 | ||
318 | socket_write($sock, "DEVICE GET ".$UUID, 4096); | |
319 | $answer = ""; | |
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
320 | while (1) { |
174 | 321 | $line = socket_read($sock, 4096); |
322 | if ($line === '') | |
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
323 | break; |
174 | 324 | $answer .= $line; |
325 | } | |
326 | socket_close($sock); | |
327 | $reply = explode("\r\n", $answer); | |
328 | ||
329 | $outstr = build_header($heading); | |
330 | $outstr .= ' <div id="errors">'.PHP_EOL; | |
331 | $outstr .= ' '.$error_message.PHP_EOL; | |
332 | $outstr .= ' </div> <!-- errors -->'.PHP_EOL; | |
333 | $outstr .= ' <div id="etable">'.PHP_EOL; | |
334 | $outstr .= ' <form method="POST" action="devices.php">'.PHP_EOL; | |
335 | $outstr .= ' <table class="editor">'.PHP_EOL; | |
336 | ||
337 | if (startsWith($reply[0], "213")) { | |
338 | $j = 1; | |
339 | while (1) { | |
340 | if (strcmp($reply[$j], ".") == 0) | |
341 | break; | |
342 | $f = explode(",", $reply[$j]); | |
343 | if ($f[0] == "TYPE") { | |
344 | $type = $f[1]; | |
345 | /* | |
346 | * Only allow certain types to edit. Auto detected hardware cannot be changed. | |
347 | */ | |
348 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
349 | $outstr .= ' <td class="editname">Device Type</td>'.PHP_EOL; | |
350 | if (($type == "W1") || ($type == "GPIO")) | |
351 | $outstr .= ' <td class="editfield"><input type="hidden" name="Type" value="'.$f[1].'">'.$f[1].'</td>'.PHP_EOL; | |
352 | else | |
353 | $outstr .= ' <td class="editfield"><input type="text" name="Type" size="50" value="'.$f[1].'"></td>'.PHP_EOL; | |
354 | $outstr .= ' </tr>'.PHP_EOL; | |
355 | } | |
356 | if ($f[0] == "DIRECTION") { | |
357 | $direction = $f[1]; | |
358 | /* | |
359 | * Only devices that cannot auto detect can be changed. | |
360 | */ | |
361 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
362 | $outstr .= ' <td class="editname">IO Direction and mode</td>'.PHP_EOL; | |
363 | if ($type == "W1") | |
364 | $outstr .= ' <td class="editfield"><input type="hidden" name="Direction" value="'.$f[1].'">'.$f[1].'</td>'.PHP_EOL; | |
365 | else { | |
366 | $outstr .= ' <td class="editfield"><select name="Direction">'.PHP_EOL; | |
367 | if ($type == "GPIO") { | |
368 | $se = ($f[1] == "UNDEF")?" selected":""; | |
369 | $outstr .= ' <option value="UNDEF"'.$se.'>Undefined</option>'.PHP_EOL; | |
370 | $se = ($f[1] == "IN_BIN")?" selected":""; | |
371 | $outstr .= ' <option value="IN_BIN"'.$se.'>Binary input</option>'.PHP_EOL; | |
372 | $se = ($f[1] == "OUT_BIN")?" selected":""; | |
373 | $outstr .= ' <option value="OUT_BIN"'.$se.'>Binary output</option>'.PHP_EOL; | |
374 | $se = ($f[1] == "OUT_PWM")?" selected":""; | |
375 | $outstr .= ' <option value="OUT_PWM"'.$se.'>PWM output</option>'.PHP_EOL; | |
376 | } | |
377 | if ($type == "RC433") { | |
378 | $se = ($f[1] == "UNDEF")?" selected":""; | |
379 | $outstr .= ' <option value="UNDEF"'.$se.'>Undefined</option>'.PHP_EOL; | |
380 | $se = ($f[1] == "OUT_BIN")?" selected":""; | |
381 | $outstr .= ' <option value="OUT_BIN"'.$se.'>Binary output</option>'.PHP_EOL; | |
382 | } | |
383 | if ($type == "DHT") { | |
384 | $se = ($f[1] == "UNDEF")?" selected":""; | |
385 | $outstr .= ' <option value="UNDEF"'.$se.'>Undefined</option>'.PHP_EOL; | |
386 | $se = ($f[1] == "IN_ANALOG")?" selected":""; | |
387 | $outstr .= ' <option value="IN_ANALOG"'.$se.'>Analog input</option>'.PHP_EOL; | |
388 | } | |
389 | $outstr .= ' </select></td>'.PHP_EOL; | |
390 | } | |
391 | $outstr .= ' </tr>'.PHP_EOL; | |
392 | } | |
393 | if ($f[0] == "VALUE") { | |
394 | /* | |
395 | * Only output can be changed | |
396 | */ | |
397 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
398 | $outstr .= ' <td class="editname">Value</td>'.PHP_EOL; | |
399 | if (($direction == "OUT_BIN") || ($direction == "OUT_ANALOG") || ($direction == "OUT_PWM")) | |
400 | $outstr .= ' <td class="editfield"><input type="text" name="Value" size="50" value="'.$f[1].'"></td>'.PHP_EOL; | |
401 | else | |
402 | $outstr .= ' <td class="editfield"><input type="hidden" name="Value" value="'.$f[1].'">'.$f[1].'</td>'.PHP_EOL; | |
403 | $outstr .= ' </tr>'.PHP_EOL; | |
404 | } | |
405 | if ($f[0] == "PRESENT") { | |
406 | /* | |
407 | * Only devices that cannot auto detect can be changed. | |
408 | */ | |
409 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
410 | $outstr .= ' <td class="editname">Device Present</td>'.PHP_EOL; | |
411 | if (($type == "W1") || ($type == "GPIO")) | |
412 | $outstr .= ' <td class="editfield"><input type="hidden" name="Present" value="'.$f[1].'">'.$f[1].'</td>'.PHP_EOL; | |
413 | else { | |
414 | $outstr .= ' <td class="editfield"><select name="Present">'.PHP_EOL; | |
415 | $se = ($f[1] == "UNDEF")?" selected":""; | |
416 | $outstr .= ' <option value="UNDEF"'.$se.'>Undefined</option>'.PHP_EOL; | |
417 | $se = ($f[1] == "NO")?" selected":""; | |
418 | $outstr .= ' <option value="NO"'.$se.'>Not present</option>'.PHP_EOL; | |
419 | $se = ($f[1] == "YES")?" selected":""; | |
420 | $outstr .= ' <option value="YES"'.$se.'>Present and Ok</option>'.PHP_EOL; | |
421 | $se = ($f[1] == "ERROR")?" selected":""; | |
422 | $outstr .= ' <option value="ERROR"'.$se.'>Present and Error</option>'.PHP_EOL; | |
423 | $outstr .= ' </select></td>'.PHP_EOL; | |
424 | } | |
425 | $outstr .= ' </tr>'.PHP_EOL; | |
426 | } | |
427 | if ($f[0] == "ADDRESS") { | |
428 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
429 | $outstr .= ' <td class="editname">Address</td>'.PHP_EOL; | |
430 | if (($type == "W1") || ($type == "GPIO")) | |
431 | $outstr .= ' <td class="editfield"><input type="hidden" name="Address" value="'.$f[1].'">'.$f[1].'</td>'.PHP_EOL; | |
432 | else | |
433 | $outstr .= ' <td class="editfield"><input type="text" name="Address" size="50" value="'.$f[1].'"></td>'.PHP_EOL; | |
434 | $outstr .= ' </tr>'.PHP_EOL; | |
435 | } | |
436 | if ($f[0] == "SUBDEVICE") { | |
437 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
438 | $outstr .= ' <td class="editname">Subdevice</td>'.PHP_EOL; | |
439 | if (($type == "W1") || ($type == "GPIO")) | |
440 | $outstr .= ' <td class="editfield"><input type="hidden" name="Subdevice" value="'.$f[1].'">'.$f[1].'</td>'.PHP_EOL; | |
441 | else | |
442 | $outstr .= ' <td class="editfield"><input type="text" name="Subdevice" size="5" value="'.$f[1].'"></td>'.PHP_EOL; | |
443 | $outstr .= ' </tr>'.PHP_EOL; | |
444 | } | |
445 | if ($f[0] == "GPIOPIN") { | |
446 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
447 | $outstr .= ' <td class="editname">GPIO pin</td>'.PHP_EOL; | |
448 | $outstr .= ' <td class="editfield"><input type="text" name="Gpiopin" size="5" value="'.$f[1].'"></td>'.PHP_EOL; | |
449 | $outstr .= ' </tr>'.PHP_EOL; | |
450 | } | |
451 | if ($f[0] == "DESCRIPTION") { | |
452 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
453 | $outstr .= ' <td class="editname">Description</td>'.PHP_EOL; | |
454 | $outstr .= ' <td class="editfield"><input type="text" name="Description" size="50" value="'.$f[1].'"></td>'.PHP_EOL; | |
455 | $outstr .= ' </tr>'.PHP_EOL; | |
456 | } | |
457 | if ($f[0] == "COMMENT") { | |
458 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
459 | $outstr .= ' <td class="editname">Comment</td>'.PHP_EOL; | |
460 | $outstr .= ' <td class="editfield"><input type="text" name="Comment" size="50" value="'.$f[1].'"></td>'.PHP_EOL; | |
461 | $outstr .= ' </tr>'.PHP_EOL; | |
462 | } | |
463 | $j++; | |
464 | } | |
465 | } | |
466 | ||
467 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
468 | $outstr .= ' <td class="editname"><input type="submit" value="Save" name="key"></td>'.PHP_EOL; | |
469 | $outstr .= ' <td class="editfield"><input type="submit" value="Cancel" name="key">'; | |
470 | $outstr .= '<input type="submit" value="Delete" name="key" style="margin-left: 100px;">'; | |
471 | $outstr .= '<input type="hidden" value="testdata" name="action">'; | |
472 | $outstr .= '<input type="hidden" value="'.$command.'" name="command">'; | |
473 | $outstr .= '<input type="hidden" value="'.$UUID.'" name="UUID"></td>'.PHP_EOL; | |
474 | $outstr .= ' </tr>'.PHP_EOL; | |
475 | $outstr .= ' </table>'.PHP_EOL; | |
476 | $outstr .= ' </form>'.PHP_EOL; | |
477 | $outstr .= ' </div> <!-- etable -->'.PHP_EOL; | |
478 | $outstr .= build_footer(); | |
479 | echo $outstr; | |
480 | } | |
481 | ||
482 | ||
483 | ||
484 | /* | |
485 | * Edit a Device. Fetches the record data and shows the edit screen. | |
486 | * | |
487 | * @param string $_GET['action'] Must be 'edit'. | |
488 | * @param string $_GET['UUID'] The UUID of the Unit. | |
489 | */ | |
490 | function device_edit() { | |
491 | if ($_GET['action'] == 'edit') { | |
492 | edit_screen($_GET['UUID'], 'update', 'ThermFerm - Edit Device', ''); | |
493 | return; | |
494 | } else { | |
495 | load('devices.php'); | |
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
496 | } |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
497 | } |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
498 | |
174 | 499 | |
500 | ||
501 | /* | |
502 | * @link edit device | |
503 | * @link add device | |
504 | */ | |
505 | function device_list() { | |
506 | global $arr; | |
507 | ||
508 | $outstr = build_header("ThermFerm - Devices Setup"); | |
509 | $outstr .= ' <div id="errors">'.PHP_EOL; | |
510 | $outstr .= ' </div> <!-- errors -->'.PHP_EOL; | |
511 | $outstr .= ' <div id="etable">'.PHP_EOL; | |
512 | $outstr .= ' <table class="setup">'.PHP_EOL; | |
513 | $outstr .= ' <tr class="trhead">'.PHP_EOL; | |
514 | $outstr .= ' <td class="setup" style="width: 300px;">UUID</td>'.PHP_EOL; | |
515 | $outstr .= ' <td class="setup" style="width: 120px;">Address</td>'.PHP_EOL; | |
516 | $outstr .= ' <td class="setup" style="width: 30px;">Sub</td>'.PHP_EOL; | |
517 | $outstr .= ' <td class="setup" style="width: 30px;">Ref</td>'.PHP_EOL; | |
518 | $outstr .= ' <td class="setup" style="width: 300px;">Cmt</td>'.PHP_EOL; | |
519 | $outstr .= ' <td class="setup" style="width: 35px;">Edit</td>'.PHP_EOL; | |
520 | $outstr .= ' </tr>'.PHP_EOL; | |
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
521 | |
174 | 522 | if (startsWith($arr[0], "212")) { |
523 | $j = 1; | |
524 | while (1) { | |
525 | if (strcmp($arr[$j], ".") == 0) | |
526 | break; | |
527 | $f = explode(",", $arr[$j]); | |
528 | $outstr .= ' <tr class="setup">'.PHP_EOL; | |
529 | $outstr .= ' <td class="setup">'.$f[0].'</td>'.PHP_EOL; | |
530 | $outstr .= ' <td class="setup">'.$f[1].'</td>'.PHP_EOL; | |
531 | $outstr .= ' <td class="setup">'.$f[2].'</td>'.PHP_EOL; | |
532 | $outstr .= ' <td class="setup">'.$f[3].'</td>'.PHP_EOL; | |
533 | $outstr .= ' <td class="setup">'.$f[4].'</td>'.PHP_EOL; | |
534 | if ($f[3] == 0) | |
535 | $outstr .= ' <td class="setup"><a href="devices.php?action=edit&UUID='.$f[0].'">Edit</a></td>'.PHP_EOL; | |
536 | else | |
537 | $outstr .= ' <td class="setup">Busy</td>'.PHP_EOL; | |
538 | $outstr .= ' </tr>'.PHP_EOL; | |
539 | $j++; | |
540 | } | |
541 | } | |
542 | ||
543 | $outstr .= ' </table>'.PHP_EOL; | |
544 | $outstr .= ' </div> <!-- etable -->'.PHP_EOL; | |
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
545 | |
174 | 546 | $outstr .= ' <div id="atable">'.PHP_EOL; |
547 | $outstr .= ' <form method="POST" action="devices.php">'.PHP_EOL; | |
548 | $outstr .= ' <table class="editor">'.PHP_EOL; | |
549 | $outstr .= ' <tr class="trhead"><td colspan="3">Add new Device</td></tr>'.PHP_EOL; | |
550 | $outstr .= ' <tr class="editor">'.PHP_EOL; | |
551 | $outstr .= ' <td class="editname">Select Device type</td>'.PHP_EOL; | |
552 | $outstr .= ' <td class="editfield">'.PHP_EOL; | |
553 | $outstr .= ' <select name="Type">'.PHP_EOL; | |
554 | $outstr .= ' <option value="NA">Not Available</option>'.PHP_EOL; | |
555 | $outstr .= ' <option value="RC433">433 Mhz Radio Controller</option>'.PHP_EOL; | |
556 | $outstr .= ' <option value="DHT">DHTnn type sensor</option>'.PHP_EOL; | |
557 | $outstr .= ' <option value="I2C">I2C bus device</option>'.PHP_EOL; | |
558 | $outstr .= ' <option value="SPI">SPI bus device</option>'.PHP_EOL; | |
559 | $outstr .= ' </select>'.PHP_EOL; | |
560 | $outstr .= ' </td>'.PHP_EOL; | |
561 | $outstr .= ' <td class="editsub"><input type="submit" value="Add" name="key"></td>'.PHP_EOL; | |
562 | $outstr .= '<input type="hidden" value="testdata" name="action">'; | |
563 | $outstr .= '<input type="hidden" value="add" name="command">'; | |
564 | $outstr .= '<input type="hidden" value="00000000-0000-0000-0000-000000000000" name="UUID">'; | |
565 | $outstr .= '<input type="hidden" value="UNDEF" name="Direction">'; | |
566 | $outstr .= '<input type="hidden" value="0" name="Value">'; | |
567 | $outstr .= '<input type="hidden" value="UNDEF" name="Present">'; | |
568 | $outstr .= '<input type="hidden" value="address unknown" name="Address">'; | |
569 | $outstr .= '<input type="hidden" value="0" name="Subdevice">'; | |
570 | $outstr .= '<input type="hidden" value="-1" name="Gpiopin">'; | |
571 | $outstr .= '<input type="hidden" value="Describe me" name="Description">'; | |
572 | $outstr .= '<input type="hidden" value="Comment me" name="Comment">'; | |
573 | $outstr .= ' </tr>'.PHP_EOL; | |
574 | $outstr .= ' </table>'.PHP_EOL; | |
575 | $outstr .= ' </form>'.PHP_EOL; | |
576 | $outstr .= ' </div> <!-- atable -->'.PHP_EOL; | |
577 | ||
578 | $outstr .= build_footer(); | |
579 | ||
580 | echo $outstr; | |
581 | } | |
582 |