--- a/thermferm/server.c Mon Aug 04 19:31:03 2014 +0200 +++ b/thermferm/server.c Mon Aug 04 23:34:22 2014 +0200 @@ -56,11 +56,6 @@ #define SS_TIMEOUT 300 -float cs_heatEstimator = 0.2; -float cs_coolEstimator = 5; -float cv_beerDiff = 0.0; - - /* * Send message to client @@ -98,6 +93,27 @@ /* + * Update the device inuse counter. + */ +void device_count(int plus, char *uuid) +{ + devices_list *device; + + for (device = Config.devices; device; device = device->next) { + if (strcmp(device->uuid, uuid) == 0) { + if (plus == TRUE) { + device->inuse++; + } else { + if (device->inuse) + device->inuse--; + } + } + } +} + + + +/* * ADD PROFILE name */ int unit_add(char *buf) @@ -458,9 +474,10 @@ } else if (strcmp(kwd, (char *)"PRESENT") == 0) { for (i = 0; i < 4; i++) { - if (strcmp(val, DEVPRESENT[i]) == 0) + if (strcmp(val, DEVPRESENT[i]) == 0) { device->present = i; break; + } } } else if (strcmp(kwd, (char *)"ADDRESS") == 0) { @@ -1174,7 +1191,6 @@ kwd = strtok(ibuf, ",\0"); val = strtok(NULL, "\0"); if (kwd) { - fprintf(stdout, "strlen(%s) %d\n", val, strlen(val)); /* * Accept writable data. The client can sent just one line, * but may also sent everything. Simply ignore things we @@ -1190,27 +1206,36 @@ unit->volume = fval; } else if (strcmp(kwd, (char *)"AIR_ADDRESS") == 0) { - if (unit->air_address) + if (unit->air_address) { + device_count(FALSE, unit->air_address); free(unit->air_address); - if (val) + } + if (val) { unit->air_address = xstrcpy(val); - else + device_count(TRUE, unit->air_address); + } else unit->air_address = NULL; } else if (strcmp(kwd, (char *)"BEER_ADDRESS") == 0) { - if (unit->beer_address) + if (unit->beer_address) { + device_count(FALSE, unit->beer_address); free(unit->beer_address); - if (val) + } + if (val) { unit->beer_address = xstrcpy(val); - else + device_count(TRUE, unit->beer_address); + } else unit->beer_address = NULL; } else if (strcmp(kwd, (char *)"HEATER_ADDRESS") == 0) { - if (unit->heater_address) + if (unit->heater_address) { + device_count(FALSE, unit->heater_address); free(unit->heater_address); - if (val) + } + if (val) { unit->heater_address = xstrcpy(val); - else + device_count(TRUE, unit->heater_address); + } else unit->heater_address = NULL; } else if (val && (strcmp(kwd, (char *)"HEATER_STATE") == 0)) { @@ -1218,11 +1243,14 @@ unit->heater_state = ival; } else if (strcmp(kwd, (char *)"COOLER_ADDRESS") == 0) { - if (unit->cooler_address) + if (unit->cooler_address) { + device_count(FALSE, unit->cooler_address); free(unit->cooler_address); - if (val) + } + if (val) { unit->cooler_address = xstrcpy(val); - else + device_count(TRUE, unit->cooler_address); + } else unit->cooler_address = NULL; } else if (val && (strcmp(kwd, (char *)"COOLER_STATE") == 0)) { @@ -1230,11 +1258,14 @@ unit->cooler_state = ival; } else if (strcmp(kwd, (char *)"FAN_ADDRESS") == 0) { - if (unit->fan_address) + if (unit->fan_address) { + device_count(FALSE, unit->fan_address); free(unit->fan_address); - if (val) + } + if (val) { unit->fan_address = xstrcpy(val); - else + device_count(TRUE, unit->fan_address); + } else unit->fan_address = NULL; } else if (val && (strcmp(kwd, (char *)"FAN_STATE") == 0)) { @@ -1242,11 +1273,14 @@ unit->fan_state = ival; } else if (strcmp(kwd, (char *)"DOOR_ADDRESS") == 0) { - if (unit->door_address) + if (unit->door_address) { + device_count(FALSE, unit->door_address); free(unit->door_address); - if (val) + } + if (val) { unit->door_address = xstrcpy(val); - else + device_count(TRUE, unit->door_address); + } else unit->door_address = NULL; } else if (val && (strcmp(kwd, (char *)"MODE") == 0)) {