thermferm/server.c

changeset 87
55f1315c94f1
parent 86
3d7a241329e2
child 88
12259362595b
equal deleted inserted replaced
86:3d7a241329e2 87:55f1315c94f1
166 * LIST PROFILES 166 * LIST PROFILES
167 * LIST UNIT 167 * LIST UNIT
168 */ 168 */
169 int cmd_list(char *buf) 169 int cmd_list(char *buf)
170 { 170 {
171 char *cmd, *opt, *mypath; 171 char *opt, *mypath;
172 units_list *unit; 172 units_list *unit;
173 int i; 173 int i;
174 DIR *fd; 174 DIR *fd;
175 struct dirent *de; 175 struct dirent *de;
176 176
177 cmd = strtok(buf, " \0"); 177 opt = strtok(buf, " \0");
178 opt = strtok(NULL, " \0"); 178 opt = strtok(NULL, " \0");
179 179
180 if (opt == NULL) { 180 if (opt == NULL) {
181 srv_send((char *)"212 Fermenter list follows:"); 181 srv_send((char *)"212 Fermenter list follows:");
182 i = 0; 182 i = 0;
243 * List configured and selected fermenter unit 243 * List configured and selected fermenter unit
244 */ 244 */
245 if (current_unit == -1) { 245 if (current_unit == -1) {
246 srv_send((char *)"401 No fermenter unit selected"); 246 srv_send((char *)"401 No fermenter unit selected");
247 } else { 247 } else {
248 248 srv_send((char *)"213 Unit %d listing follows:", current_unit);
249 i = 0;
250 for (unit = Config.units; unit; unit = unit->next) {
251 i++;
252 if (i == current_unit) {
253 srv_send((char *)"Name of the unit/beer %s", unit->name);
254 srv_send((char *)"UUID of this unit %s", unit->uuid);
255 if (unit->air_address) {
256 srv_send((char *)"1-wire address air sensor %s", unit->air_address);
257 srv_send((char *)"Air temperature %.1f", unit->air_temp);
258 }
259 if (unit->beer_address) {
260 srv_send((char *)"1-wire address beer sensor %s", unit->air_address);
261 srv_send((char *)"Beer temperature %.1f", unit->air_temp);
262 }
263 if (unit->io1_address) {
264 srv_send((char *)"1-wire address cool/heat %s", unit->io1_address);
265 }
266 if (unit->io2_address) {
267 srv_send((char *)"1-wire address fan/door %s", unit->io2_address);
268 }
269 if (unit->heater_available) {
270 srv_send((char *)"Heater available %s", unit->heater_available);
271 }
272 if (unit->cooler_available) {
273 srv_send((char *)"Cooler available %s", unit->cooler_available);
274 }
275 if (unit->fan_available) {
276 srv_send((char *)"Fan available %s", unit->fan_available);
277 }
278 srv_send((char *)"Unit mode %s", UNITMODE[unit->mode]);
279 srv_send((char *)"Fridge temperature set to %.1f", unit->fridge_set);
280 srv_send((char *)"Beer temperature set to %.1f", unit->fridge_set);
281 if (unit->profile) {
282 srv_send((char *)"Profile name %s", unit->profile);
283 }
284 srv_send((char *)"Temperature range %.1f .. %.1f", unit->temp_set_min, unit->temp_set_max);
285 srv_send((char *)"Idle temperature range %.1f .. %.1f", unit->idle_rangeL, unit->idle_rangeH);
286 }
287 }
288 srv_send((char *)".");
249 } 289 }
250 } else { 290 } else {
251 srv_send((char *)"502 Unknown command option"); 291 srv_send((char *)"502 Unknown command option");
252 } 292 }
253 293
254 return 0; 294 return 0;
295 }
296
297
298
299 /*
300 * UNIT n
301 * UNIT uuid
302 */
303 int cmd_unit(char *buf)
304 {
305 char *opt;
306 units_list *tmp;
307 int i, unit_no;
308
309 opt = strtok(buf, " \0");
310 opt = strtok(NULL, " \0");
311
312 if (opt == NULL) {
313 srv_send((char *)"501 Parameter missing");
314 return 1;
315 }
316
317 i = 0;
318 if (strlen(opt) == 36) {
319 /*
320 * Search using uuid
321 */
322 for (tmp = Config.units; tmp; tmp = tmp->next) {
323 i++;
324 if (strcmp(opt, tmp->uuid) == 0) {
325 srv_send((char *)"210 Unit %d selected", i);
326 current_unit = i;
327 return 0;
328 }
329 }
330 srv_send((char *)"410 No such unit");
331 return 1;
332 }
333
334 if (sscanf(opt, "%d", &unit_no) == 1) {
335 /*
336 * We got a number, see if it is valid.
337 */
338 for (tmp = Config.units; tmp; tmp = tmp->next) {
339 i++;
340 if (unit_no == i) {
341 srv_send((char *)"210 Unit %d selected", i);
342 current_unit = i;
343 return 0;
344 }
345 }
346 srv_send((char *)"410 No such unit");
347 return 1;
348 }
349
350 srv_send((char *)"502 Unknown command option");
351 return 1;
255 } 352 }
256 353
257 354
258 355
259 void cmd_server(void) 356 void cmd_server(void)
307 srv_send((char *)""); 404 srv_send((char *)"");
308 srv_send((char *)"ADD name Add a new unit with \"name\""); 405 srv_send((char *)"ADD name Add a new unit with \"name\"");
309 srv_send((char *)"LCD Get LCD screen (allways 4 rows of 20 characters)"); 406 srv_send((char *)"LCD Get LCD screen (allways 4 rows of 20 characters)");
310 srv_send((char *)"LIST List all fermenter units"); 407 srv_send((char *)"LIST List all fermenter units");
311 srv_send((char *)"LIST BUS List 1-wire bus"); 408 srv_send((char *)"LIST BUS List 1-wire bus");
312 // srv_send((char *)"LIST PROFILES List available profiles"); 409 srv_send((char *)"LIST PROFILES List available profiles");
313 // srv_send((char *)"LIST UNIT List fermenter unit"); 410 srv_send((char *)"LIST UNIT List fermenter unit");
314 // srv_send((char *)"MODE off|none|beer|fridge|profile"); 411 // srv_send((char *)"MODE off|none|beer|fridge|profile");
315 // srv_send((char *)"PROFILE Profile status"); 412 // srv_send((char *)"PROFILE Profile status");
316 // srv_send((char *)"PROFILE start|stop|pause Profile start, stop or pause"); 413 // srv_send((char *)"PROFILE start|stop|pause Profile start, stop or pause");
317 // srv_send((char *)"SET BEER Set beer temperature"); 414 // srv_send((char *)"SET BEER Set beer temperature");
318 // srv_send((char *)"SET FRIDGE Set fridge temperature"); 415 // srv_send((char *)"SET FRIDGE Set fridge temperature");
323 // srv_send((char *)"SET OFF Set unit off"); 420 // srv_send((char *)"SET OFF Set unit off");
324 // srv_send((char *)"SET PROFILE name Set named profile"); 421 // srv_send((char *)"SET PROFILE name Set named profile");
325 // srv_send((char *)"SET TEMP MIN val Set unit minimum temperature"); 422 // srv_send((char *)"SET TEMP MIN val Set unit minimum temperature");
326 // srv_send((char *)"SET TEMP MAX val Set unit maximum temperature"); 423 // srv_send((char *)"SET TEMP MAX val Set unit maximum temperature");
327 // srv_send((char *)"SET VOLUME Set unit volume"); 424 // srv_send((char *)"SET VOLUME Set unit volume");
328 // srv_send((char *)"UNIT n|uuid Select unit by number or uuid"); 425 srv_send((char *)"UNIT n|uuid Select unit by number or uuid");
329 srv_send((char *)"."); 426 srv_send((char *)".");
330 } else if (strncmp(buf, "LCD", 3) == 0) { 427 } else if (strncmp(buf, "LCD", 3) == 0) {
331 #ifdef HAVE_WIRINGPI_H 428 #ifdef HAVE_WIRINGPI_H
332 srv_send((char *)"201 information follows"); 429 srv_send((char *)"201 information follows");
333 for (j = 0; j < 4; j++) { 430 for (j = 0; j < 4; j++) {
341 #else 438 #else
342 srv_send((char *)"403 LCD not available"); 439 srv_send((char *)"403 LCD not available");
343 #endif 440 #endif
344 } else if (strncmp(buf, "LIST", 4) == 0) { 441 } else if (strncmp(buf, "LIST", 4) == 0) {
345 cmd_list(buf); 442 cmd_list(buf);
443 } else if (strncmp(buf, "UNIT", 4) == 0) {
444 cmd_unit(buf);
346 } else if (strncmp(buf, "ack", 3) == 0) { 445 } else if (strncmp(buf, "ack", 3) == 0) {
347 srv_send((char *)"ack"); 446 srv_send((char *)"ack");
348 } else if (strncmp(buf, "lcd", 3) == 0) { 447 } else if (strncmp(buf, "lcd", 3) == 0) {
349 sprintf(obuf, "[\" \", \" \", \" \", \" \"]"); 448 sprintf(obuf, "[\" \", \" \", \" \", \" \"]");
350 #ifdef HAVE_WIRINGPI_H 449 #ifdef HAVE_WIRINGPI_H

mercurial