# HG changeset patch # User Michiel Broek # Date 1404316626 -7200 # Node ID 55f1315c94f13357a072e5db40430a829d6a9c1b # Parent 3d7a241329e23cfead070b46b743bc342a22afc1 Added unit command and list unit command diff -r 3d7a241329e2 -r 55f1315c94f1 thermferm/server.c --- a/thermferm/server.c Tue Jul 01 23:14:57 2014 +0200 +++ b/thermferm/server.c Wed Jul 02 17:57:06 2014 +0200 @@ -168,13 +168,13 @@ */ int cmd_list(char *buf) { - char *cmd, *opt, *mypath; + char *opt, *mypath; units_list *unit; int i; DIR *fd; struct dirent *de; - cmd = strtok(buf, " \0"); + opt = strtok(buf, " \0"); opt = strtok(NULL, " \0"); if (opt == NULL) { @@ -245,7 +245,47 @@ if (current_unit == -1) { srv_send((char *)"401 No fermenter unit selected"); } else { - + srv_send((char *)"213 Unit %d listing follows:", current_unit); + i = 0; + for (unit = Config.units; unit; unit = unit->next) { + i++; + if (i == current_unit) { + srv_send((char *)"Name of the unit/beer %s", unit->name); + srv_send((char *)"UUID of this unit %s", unit->uuid); + if (unit->air_address) { + srv_send((char *)"1-wire address air sensor %s", unit->air_address); + srv_send((char *)"Air temperature %.1f", unit->air_temp); + } + if (unit->beer_address) { + srv_send((char *)"1-wire address beer sensor %s", unit->air_address); + srv_send((char *)"Beer temperature %.1f", unit->air_temp); + } + if (unit->io1_address) { + srv_send((char *)"1-wire address cool/heat %s", unit->io1_address); + } + if (unit->io2_address) { + srv_send((char *)"1-wire address fan/door %s", unit->io2_address); + } + if (unit->heater_available) { + srv_send((char *)"Heater available %s", unit->heater_available); + } + if (unit->cooler_available) { + srv_send((char *)"Cooler available %s", unit->cooler_available); + } + if (unit->fan_available) { + srv_send((char *)"Fan available %s", unit->fan_available); + } + srv_send((char *)"Unit mode %s", UNITMODE[unit->mode]); + srv_send((char *)"Fridge temperature set to %.1f", unit->fridge_set); + srv_send((char *)"Beer temperature set to %.1f", unit->fridge_set); + if (unit->profile) { + srv_send((char *)"Profile name %s", unit->profile); + } + srv_send((char *)"Temperature range %.1f .. %.1f", unit->temp_set_min, unit->temp_set_max); + srv_send((char *)"Idle temperature range %.1f .. %.1f", unit->idle_rangeL, unit->idle_rangeH); + } + } + srv_send((char *)"."); } } else { srv_send((char *)"502 Unknown command option"); @@ -256,6 +296,63 @@ +/* + * UNIT n + * UNIT uuid + */ +int cmd_unit(char *buf) +{ + char *opt; + units_list *tmp; + int i, unit_no; + + opt = strtok(buf, " \0"); + opt = strtok(NULL, " \0"); + + if (opt == NULL) { + srv_send((char *)"501 Parameter missing"); + return 1; + } + + i = 0; + if (strlen(opt) == 36) { + /* + * Search using uuid + */ + for (tmp = Config.units; tmp; tmp = tmp->next) { + i++; + if (strcmp(opt, tmp->uuid) == 0) { + srv_send((char *)"210 Unit %d selected", i); + current_unit = i; + return 0; + } + } + srv_send((char *)"410 No such unit"); + return 1; + } + + if (sscanf(opt, "%d", &unit_no) == 1) { + /* + * We got a number, see if it is valid. + */ + for (tmp = Config.units; tmp; tmp = tmp->next) { + i++; + if (unit_no == i) { + srv_send((char *)"210 Unit %d selected", i); + current_unit = i; + return 0; + } + } + srv_send((char *)"410 No such unit"); + return 1; + } + + srv_send((char *)"502 Unknown command option"); + return 1; +} + + + void cmd_server(void) { char *inp, *p, *q, buf[SS_BUFSIZE], obuf[SS_BUFSIZE]; @@ -309,8 +406,8 @@ srv_send((char *)"LCD Get LCD screen (allways 4 rows of 20 characters)"); srv_send((char *)"LIST List all fermenter units"); srv_send((char *)"LIST BUS List 1-wire bus"); -// srv_send((char *)"LIST PROFILES List available profiles"); -// srv_send((char *)"LIST UNIT List fermenter unit"); + srv_send((char *)"LIST PROFILES List available profiles"); + srv_send((char *)"LIST UNIT List fermenter unit"); // srv_send((char *)"MODE off|none|beer|fridge|profile"); // srv_send((char *)"PROFILE Profile status"); // srv_send((char *)"PROFILE start|stop|pause Profile start, stop or pause"); @@ -325,7 +422,7 @@ // srv_send((char *)"SET TEMP MIN val Set unit minimum temperature"); // srv_send((char *)"SET TEMP MAX val Set unit maximum temperature"); // srv_send((char *)"SET VOLUME Set unit volume"); -// srv_send((char *)"UNIT n|uuid Select unit by number or uuid"); + srv_send((char *)"UNIT n|uuid Select unit by number or uuid"); srv_send((char *)"."); } else if (strncmp(buf, "LCD", 3) == 0) { #ifdef HAVE_WIRINGPI_H @@ -343,6 +440,8 @@ #endif } else if (strncmp(buf, "LIST", 4) == 0) { cmd_list(buf); + } else if (strncmp(buf, "UNIT", 4) == 0) { + cmd_unit(buf); } else if (strncmp(buf, "ack", 3) == 0) { srv_send((char *)"ack"); } else if (strncmp(buf, "lcd", 3) == 0) {