diff -r 50675fd80fed -r 75afd21885f2 thermferm/server.c --- a/thermferm/server.c Sat Jun 27 12:52:04 2015 +0200 +++ b/thermferm/server.c Sat Jun 27 14:08:49 2015 +0200 @@ -313,7 +313,7 @@ */ int cmd_archive(char *buf) { - char *opt, *param, *name = NULL, *filename = NULL, mbits[11], tstr[24]; + char *opt, *param, *name = NULL, *filename = NULL, *logname = NULL, mbits[11], tstr[24]; DIR *dd; FILE *fp; struct dirent entry, *result; @@ -321,6 +321,9 @@ struct stat sbuf; struct tm *tbuf; time_t ftime; + int found; + units_list *unit; + opt = strtok(buf, " \0"); opt = strtok(NULL, " \0"); @@ -361,7 +364,21 @@ if (result->d_name[0] != '.') { filename = xstrcpy(name); filename = xstrcat(filename, result->d_name); - if ((stat(filename, &sbuf)) == 0) { + /* + * Remove files from the list when they are in use + */ + found = 0; + for (unit = Config.units; unit; unit = unit->next) { + if (unit->mode != UNITMODE_OFF) { + logname = xstrcpy(unit->name); + logname = xstrcat(logname, (char *)".log"); + if (! strcmp(result->d_name, logname)) + found = 1; + free(logname); + logname = NULL; + } + } + if ((found == 0) && ((stat(filename, &sbuf)) == 0)) { fill_list(&lsx, result->d_name, sbuf.st_mode, sbuf.st_size, sbuf.st_mtime); } free(filename); @@ -635,6 +652,18 @@ } param = strtok(NULL, "\0"); + if (strcmp(opt, (char *)"HELP") == 0) { + srv_send((char *)"100 Help text follows:"); + srv_send((char *)"Recognized commands:"); + srv_send((char *)"DEVICE ADD type Add device (RC433/DHT/I2C/SPI)"); + srv_send((char *)"DEVICE DEL uuid Delete device by uuid"); + srv_send((char *)"DEVICE LIST List all devices"); + srv_send((char *)"DEVICE GET uuid Read device by uuid parameters"); + srv_send((char *)"DEVICE PUT uuid Write device by uuid parameters"); + srv_send((char *)"."); + return 0; + } + if (strcmp(opt, (char *)"LIST") == 0) { srv_send((char *)"212 Devices list follows:"); for (device = Config.devices; device; device = device->next) { @@ -942,6 +971,15 @@ return 1; } + if (strcmp(opt, (char *)"HELP") == 0) { + srv_send((char *)"100 Help text follows:"); + srv_send((char *)"Recognized commands:"); + srv_send((char *)"GLOBAL GET Get global settings"); + srv_send((char *)"GLOBAL PUT Put global settings"); + srv_send((char *)"."); + return 0; + } + if (strcmp(opt, (char *)"GET") == 0) { srv_send((char *)"213 Global Settings record follows:"); srv_send((char *)"RELEASE,%s", VERSION); @@ -1081,6 +1119,14 @@ srv_send((char *)"."); return 1; + } else if (strcmp(opt, (char *)"HELP") == 0) { + srv_send((char *)"100 Help text follows:"); + srv_send((char *)"Recognized commands:"); + srv_send((char *)"LIST List available units"); + srv_send((char *)"LIST LOG uuid List logfile of unit by uuid"); + srv_send((char *)"."); + return 0; + } else if (strcmp(opt, (char *)"LOG") == 0) { param = strtok(NULL, "\0"); @@ -1224,6 +1270,21 @@ return 1; } + if (strcmp(opt, (char *)"HELP") == 0) { + srv_send((char *)"100 Help text follows:"); + srv_send((char *)"Recognized commands:"); + srv_send((char *)"PROFILE uuid,name Profile rename"); + srv_send((char *)"PROFILE ADD name Add new Profile with name"); + srv_send((char *)"PROFILE DEL uuid Delete Profile by uuid"); + srv_send((char *)"PROFILE LIST List available profiles"); + srv_send((char *)"PROFILE GET uuid Get Profile record by uuid"); + srv_send((char *)"PROFILE PUT uuid Put Profile record by uuid"); + srv_send((char *)"PROFILE GETS uuid Profile get steps list"); + srv_send((char *)"PROFILE PUTS uuid Profile put steps list"); + srv_send((char *)"."); + return 0; + } + if (strcmp(opt, (char *)"LIST") == 0) { /* * Fermenting profiles @@ -1481,6 +1542,18 @@ } param = strtok(NULL, "\0"); + if (strcmp(opt, (char *)"HELP") == 0) { + srv_send((char *)"100 Help text follows:"); + srv_send((char *)"Recognized commands:"); + srv_send((char *)"SIMULATOR ADD name Add a new Simulator with name"); + srv_send((char *)"SIMULATOR DEL uuid Delete Simulator by uuid"); + srv_send((char *)"SIMULATOR LIST List all Simulators"); + srv_send((char *)"SIMULATOR GET uuid Get Simulator record by uuid"); + srv_send((char *)"SIMULATOR PUT uuid Put Simulator record by uuid"); + srv_send((char *)"."); + return 0; + } + if (strcmp(opt, (char *)"LIST") == 0) { srv_send((char *)"212 Simulators list follows:"); for (simulator = Config.simulators; simulator; simulator = simulator->next) { @@ -1846,6 +1919,18 @@ } param = strtok(NULL, "\0"); + if (strcmp(opt, (char *)"HELP") == 0) { + srv_send((char *)"100 Help text follows:"); + srv_send((char *)"Recognized commands:"); + srv_send((char *)"UNIT ADD name Add a new Unit with name"); + srv_send((char *)"UNIT DEL uuid Delete Unit by uuid"); + srv_send((char *)"UNIT LIST List all Units"); + srv_send((char *)"UNIT GET uuid Get Unit record by uuid"); + srv_send((char *)"UNIT PUT uuid Put Unit record by uuid"); + srv_send((char *)"."); + return 0; + } + if ((strcmp(opt, (char *)"LIST") == 0) && (param == NULL)) { srv_send((char *)"212 Fermenter list follows:"); for (unit = Config.units; unit; unit = unit->next) { @@ -2459,36 +2544,21 @@ // 12345678901234567890123456789012345678901234567890123456789012345678901234567890 srv_send((char *)"ARCHIVE [parameters] Archive commands"); srv_send((char *)"ARCHIVE HELP Archive help screen"); - srv_send((char *)"DEVICE ADD type Add new Device type"); - srv_send((char *)"DEVICE DEL uuid Delete Device by uuid"); - srv_send((char *)"DEVICE LIST List Devices"); - srv_send((char *)"DEVICE GET uuid Get Device record by uuid"); - srv_send((char *)"DEVICE PUT uuid Put Device record by uuid"); - srv_send((char *)"GLOBAL GET Get global settings"); - srv_send((char *)"GLOBAL PUT Put global settings"); - srv_send((char *)"LIST List all fermenter units"); - srv_send((char *)"LIST LOG uuid List logfile data graphsteps"); + srv_send((char *)"DEVICE [parameters] Device commands"); + srv_send((char *)"DEVICE HELP Device help screen"); + srv_send((char *)"GLOBAL [parameters] Global commands"); + srv_send((char *)"GLOBAL HELP Global help screen"); + srv_send((char *)"LIST [parameters] List commands"); + srv_send((char *)"LIST HELP List help screen"); srv_send((char *)"PING Check if server is alive"); - srv_send((char *)"PROFILE uuid,name Profile rename"); - srv_send((char *)"PROFILE ADD name Add new Profile with name"); - srv_send((char *)"PROFILE DEL uuid Delete Profile by uuid"); - srv_send((char *)"PROFILE LIST List available profiles"); - srv_send((char *)"PROFILE GET uuid Get Profile record by uuid"); - srv_send((char *)"PROFILE PUT uuid Put Profile record by uuid"); - srv_send((char *)"PROFILE GETS uuid Profile get steps list"); - srv_send((char *)"PROFILE PUTS uuid Profile put steps list"); + srv_send((char *)"PROFILE [parameters] Profile commands"); + srv_send((char *)"PROFILE HELP Profile help screen"); #ifdef USE_SIMULATOR - srv_send((char *)"SIMULATOR ADD name Add a new Simulator with name"); - srv_send((char *)"SIMULATOR DEL uuid Delete Simulator by uuid"); - srv_send((char *)"SIMULATOR LIST List all Simulators"); - srv_send((char *)"SIMULATOR GET uuid Get Simulator record by uuid"); - srv_send((char *)"SIMULATOR PUT uuid Put Simulator record by uuid"); + srv_send((char *)"SIMULATOR [parameters] Simulator commands"); + srv_send((char *)"SIMULATOR HELP Simulator help screen"); #endif - srv_send((char *)"UNIT ADD name Add a new Unit with name"); - srv_send((char *)"UNIT DEL uuid Delete Unit by uuid"); - srv_send((char *)"UNIT LIST List all Units"); - srv_send((char *)"UNIT GET uuid Get Unit record by uuid"); - srv_send((char *)"UNIT PUT uuid Put Unit record by uuid"); + srv_send((char *)"UNIT [parameters] Unit commands"); + srv_send((char *)"UNIT HELP Unit help screen"); srv_send((char *)"."); } else if (strncmp(buf, "LIST", 4) == 0) { cmd_list(buf);