thermferm/server.c

changeset 213
2317b8d644fa
parent 209
c5b1dfd83e81
child 217
2922d439ff63
equal deleted inserted replaced
212:a76cbe676bf1 213:2317b8d644fa
14 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details. 16 * General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with EC-65K; see the file COPYING. If not, write to the Free 19 * along with ThermFerm; see the file COPYING. If not, write to the Free
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *****************************************************************************/ 21 *****************************************************************************/
22 22
23 #include "rdconfig.h" 23 #include "rdconfig.h"
24 #include "thermferm.h" 24 #include "thermferm.h"
224 224
225 opt = strtok(buf, " \0"); 225 opt = strtok(buf, " \0");
226 opt = strtok(NULL, " \0"); 226 opt = strtok(NULL, " \0");
227 227
228 if (opt == NULL) { 228 if (opt == NULL) {
229 srv_send((char *)"502 Missing command option"); 229 srv_send((char *)"501 Subcommand missing");
230 return 1; 230 return 1;
231 } 231 }
232 param = strtok(NULL, "\0"); 232 param = strtok(NULL, "\0");
233 233
234 if (strcmp(opt, (char *)"LIST") == 0) { 234 if (strcmp(opt, (char *)"LIST") == 0) {
235 srv_send((char *)"212 bus devices:"); 235 srv_send((char *)"212 Devices list follows:");
236 for (device = Config.devices; device; device = device->next) { 236 for (device = Config.devices; device; device = device->next) {
237 srv_send((char *)"%s,%s,%d,%d,%s,%s", device->uuid, device->address, device->subdevice, device->inuse, device->comment, DEVDIR[device->direction]); 237 srv_send((char *)"%s,%s,%d,%d,%s,%s", device->uuid, device->address, device->subdevice, device->inuse, device->comment, DEVDIR[device->direction]);
238 } 238 }
239 srv_send((char *)"."); 239 srv_send((char *)".");
240 return 0; 240 return 0;
241 } 241 }
242 242
243 if (param == NULL) { 243 if (param == NULL) {
244 srv_send((char *)"502 Missing command parameter"); 244 srv_send((char *)"502 Parameter missing");
245 return 1; 245 return 1;
246 } 246 }
247 247
248 if (strcmp(opt, (char *)"ADD") == 0) { 248 if (strcmp(opt, (char *)"ADD") == 0) {
249 if ((strcmp(param, (char *)"RC433") == 0) || (strcmp(param, (char *)"DHT") == 0) || 249 if ((strcmp(param, (char *)"RC433") == 0) || (strcmp(param, (char *)"DHT") == 0) ||
277 tmpd->next = device; 277 tmpd->next = device;
278 break; 278 break;
279 } 279 }
280 } 280 }
281 } 281 }
282 syslog(LOG_NOTICE, "Device with uuid %s added", device->uuid); 282 syslog(LOG_NOTICE, "Device %s added", device->uuid);
283 srv_send((char *)"211 Device with uuid %s added", device->uuid); 283 srv_send((char *)"211 Device %s added", device->uuid);
284 return 0; 284 return 0;
285 285
286 } else { 286 } else {
287 srv_send((char *)"506 Wrong device parameter"); 287 srv_send((char *)"503 Parameter error");
288 return 1; 288 return 1;
289 } 289 }
290 } 290 }
291 291
292 if (strcmp(opt, (char *)"DEL") == 0) { 292 if (strcmp(opt, (char *)"DEL") == 0) {
293 293
294 if (delete_Device(param)) { 294 if (delete_Device(param)) {
295 syslog(LOG_NOTICE, "Deleted device with %s", param); 295 syslog(LOG_NOTICE, "Device %s deleted", param);
296 srv_send((char *)"211 Device %s deleted", param); 296 srv_send((char *)"211 Device %s deleted", param);
297 return 0; 297 return 0;
298 } else { 298 } else {
299 srv_send((char *)"440 Delete Device: No such device %s", param); 299 srv_send((char *)"440 No such device");
300 return 1; 300 return 1;
301 } 301 }
302 } 302 }
303 303
304 if (strcmp(opt, (char *)"GET") == 0) { 304 if (strcmp(opt, (char *)"GET") == 0) {
305 for (device = Config.devices; device; device = device->next) { 305 for (device = Config.devices; device; device = device->next) {
306 if (strcmp(device->uuid, param) == 0) { 306 if (strcmp(device->uuid, param) == 0) {
307 srv_send((char *)"213 Device %s record follows:", device->uuid); 307 srv_send((char *)"213 Device record follows:");
308 srv_send((char *)"TYPE,%s", DEVTYPE[device->type]); 308 srv_send((char *)"TYPE,%s", DEVTYPE[device->type]);
309 srv_send((char *)"DIRECTION,%s", DEVDIR[device->direction]); 309 srv_send((char *)"DIRECTION,%s", DEVDIR[device->direction]);
310 srv_send((char *)"VALUE,%d", device->value); 310 srv_send((char *)"VALUE,%d", device->value);
311 srv_send((char *)"OFFSET,%d", device->offset); 311 srv_send((char *)"OFFSET,%d", device->offset);
312 srv_send((char *)"PRESENT,%s", DEVPRESENT[device->present]); 312 srv_send((char *)"PRESENT,%s", DEVPRESENT[device->present]);
424 } 424 }
425 srv_send((char *)"440 No such device"); 425 srv_send((char *)"440 No such device");
426 return 1; 426 return 1;
427 } 427 }
428 428
429 srv_send((char *)"502 Unknown command option"); 429 srv_send((char *)"504 Subcommand error");
430 return 1; 430 return 1;
431 } 431 }
432 432
433 433
434 434
444 444
445 opt = strtok(buf, " \0"); 445 opt = strtok(buf, " \0");
446 opt = strtok(NULL, "\0"); 446 opt = strtok(NULL, "\0");
447 447
448 if (opt == NULL) { 448 if (opt == NULL) {
449 srv_send((char *)"502 Missing command option"); 449 srv_send((char *)"501 Subcommand missing");
450 return 1; 450 return 1;
451 } 451 }
452 452
453 if (strcmp(opt, (char *)"GET") == 0) { 453 if (strcmp(opt, (char *)"GET") == 0) {
454 srv_send((char *)"213 Global Settings record follows:"); 454 srv_send((char *)"213 Global Settings record follows:");
554 } 554 }
555 } 555 }
556 } 556 }
557 } 557 }
558 558
559 srv_send((char *)"502 Unknown command option"); 559 srv_send((char *)"504 Subcommand error");
560 return 1; 560 return 1;
561 } 561 }
562 562
563 563
564 564
588 588
589 } else if (strcmp(opt, (char *)"LOG") == 0) { 589 } else if (strcmp(opt, (char *)"LOG") == 0) {
590 590
591 param = strtok(NULL, "\0"); 591 param = strtok(NULL, "\0");
592 if (param == NULL) { 592 if (param == NULL) {
593 srv_send((char *)"501 Parameter missing"); 593 srv_send((char *)"502 Parameter missing");
594 return 1; 594 return 1;
595 } 595 }
596 596
597 q[0] = q[1] = 'a'; 597 q[0] = q[1] = 'a';
598 for (unit = Config.units; unit; unit = unit->next) { 598 for (unit = Config.units; unit; unit = unit->next) {
626 filename = NULL; 626 filename = NULL;
627 srv_send((char *)"."); 627 srv_send((char *)".");
628 return 0; 628 return 0;
629 } 629 }
630 630
631 srv_send((char *)"502 Unknown command option"); 631 srv_send((char *)"504 Subcommand error");
632 return 1; 632 return 1;
633 } 633 }
634 634
635 635
636 636
662 662
663 if (strcmp(opt, (char *)"LIST") == 0) { 663 if (strcmp(opt, (char *)"LIST") == 0) {
664 /* 664 /*
665 * Fermenting profiles 665 * Fermenting profiles
666 */ 666 */
667 srv_send((char *)"212 profiles:"); 667 srv_send((char *)"212 Profiles list follows:");
668 for (profile = Config.profiles; profile; profile = profile->next) { 668 for (profile = Config.profiles; profile; profile = profile->next) {
669 j = 0; 669 j = 0;
670 for (step = profile->steps; step; step = step->next) 670 for (step = profile->steps; step; step = step->next)
671 j++; 671 j++;
672 srv_send((char *)"%s,%s,%d,%d", profile->uuid, profile->name, j, profile->busy); 672 srv_send((char *)"%s,%s,%d,%d", profile->uuid, profile->name, j, profile->busy);
675 return 1; 675 return 1;
676 } 676 }
677 677
678 param = strtok(NULL, "\0"); 678 param = strtok(NULL, "\0");
679 if (param == NULL) { 679 if (param == NULL) {
680 srv_send((char *)"501 Parameter missing"); 680 srv_send((char *)"502 Parameter missing");
681 return 1; 681 return 1;
682 } 682 }
683 683
684 if (strcmp(opt, (char *)"ADD") == 0) { 684 if (strcmp(opt, (char *)"ADD") == 0) {
685 profile = (profiles_list *)malloc(sizeof(profiles_list)); 685 profile = (profiles_list *)malloc(sizeof(profiles_list));
701 break; 701 break;
702 } 702 }
703 } 703 }
704 } 704 }
705 705
706 syslog(LOG_NOTICE, "Profile \"%s\" with uuid %s added", param, profile->uuid); 706 syslog(LOG_NOTICE, "Profile %s added", profile->uuid);
707 srv_send((char *)"211 Profile \"%s\" with uuid %s added", param, profile->uuid); 707 srv_send((char *)"211 Profile %s added", profile->uuid);
708 return 0; 708 return 0;
709 709
710 710
711 } else if (strcmp(opt, (char *)"DEL") == 0) { 711 } else if (strcmp(opt, (char *)"DEL") == 0) {
712 if (delete_Profile(param)) { 712 if (delete_Profile(param)) {
713 syslog(LOG_NOTICE, "Deleted Profile with %s", param); 713 syslog(LOG_NOTICE, "Profile %s deleted", param);
714 srv_send((char *)"211 Profile %s deleted", param); 714 srv_send((char *)"211 Profile %s deleted", param);
715 return 0; 715 return 0;
716 } else { 716 } else {
717 srv_send((char *)"440 Delete Profile: No such profile%s", param); 717 srv_send((char *)"440 No such profile");
718 return 1; 718 return 1;
719 } 719 }
720 720
721 } else if (strcmp(opt, (char *)"GET") == 0) { 721 } else if (strcmp(opt, (char *)"GET") == 0) {
722 for (profile = Config.profiles; profile; profile = profile->next) { 722 for (profile = Config.profiles; profile; profile = profile->next) {
723 if (strcmp(profile->uuid, param) == 0) { 723 if (strcmp(profile->uuid, param) == 0) {
724 srv_send((char *)"213 Profile %s record follows:", profile->uuid); 724 srv_send((char *)"213 Profile record follows:");
725 srv_send((char *)"UUID,%s", profile->uuid); 725 srv_send((char *)"UUID,%s", profile->uuid);
726 srv_send((char *)"NAME,%s", profile->name); 726 srv_send((char *)"NAME,%s", profile->name);
727 srv_send((char *)"INITTEMP,%.1f", profile->inittemp); 727 srv_send((char *)"INITTEMP,%.1f", profile->inittemp);
728 srv_send((char *)"."); 728 srv_send((char *)".");
729 return 1; 729 return 1;
760 if (debug) { 760 if (debug) {
761 syslog(LOG_NOTICE, "recv: \"%s\"", ibuf); 761 syslog(LOG_NOTICE, "recv: \"%s\"", ibuf);
762 fprintf(stdout, "recv: \"%s\"\n", ibuf); 762 fprintf(stdout, "recv: \"%s\"\n", ibuf);
763 } 763 }
764 if (strcmp(ibuf, (char *)".") == 0) { 764 if (strcmp(ibuf, (char *)".") == 0) {
765 srv_send((char *)"219 Accepted Device record"); 765 srv_send((char *)"219 Accepted Profile record");
766 return 0; 766 return 0;
767 } 767 }
768 kwd = strtok(ibuf, ",\0"); 768 kwd = strtok(ibuf, ",\0");
769 val = strtok(NULL, "\0"); 769 val = strtok(NULL, "\0");
770 if (kwd && val) { 770 if (kwd && val) {
839 syslog(LOG_NOTICE, "recv: \"%s\"", ibuf); 839 syslog(LOG_NOTICE, "recv: \"%s\"", ibuf);
840 fprintf(stdout, "recv: \"%s\"\n", ibuf); 840 fprintf(stdout, "recv: \"%s\"\n", ibuf);
841 } 841 }
842 if (strcmp(ibuf, (char *)".") == 0) { 842 if (strcmp(ibuf, (char *)".") == 0) {
843 843
844 srv_send((char *)"219 Accepted profile steps"); 844 srv_send((char *)"219 Accepted Profile steps");
845 return 0; 845 return 0;
846 } 846 }
847 sstep = strtok(ibuf, ",\0"); 847 sstep = strtok(ibuf, ",\0");
848 rest = strtok(NULL, ",\0"); 848 rest = strtok(NULL, ",\0");
849 targ = strtok(NULL, "\0"); 849 targ = strtok(NULL, "\0");
878 878
879 srv_send((char *)"440 No such profile"); 879 srv_send((char *)"440 No such profile");
880 return 1; 880 return 1;
881 } 881 }
882 882
883 srv_send((char *)"502 Unknown command option"); 883 srv_send((char *)"504 Subcommand error");
884 return 1; 884 return 1;
885 } 885 }
886 886
887 887
888 888
980 980
981 opt = strtok(buf, " \0"); 981 opt = strtok(buf, " \0");
982 opt = strtok(NULL, " \0"); 982 opt = strtok(NULL, " \0");
983 983
984 if (opt == NULL) { 984 if (opt == NULL) {
985 srv_send((char *)"501 Parameter missing"); 985 srv_send((char *)"501 Subcommand missing");
986 return 1; 986 return 1;
987 } 987 }
988 param = strtok(NULL, "\0"); 988 param = strtok(NULL, "\0");
989 989
990 if ((strcmp(opt, (char *)"LIST") == 0) && (param == NULL)) { 990 if ((strcmp(opt, (char *)"LIST") == 0) && (param == NULL)) {
991 srv_send((char *)"212 Fermenter Units list follows:"); 991 srv_send((char *)"212 Fermenter list follows:");
992 for (unit = Config.units; unit; unit = unit->next) { 992 for (unit = Config.units; unit; unit = unit->next) {
993 srv_send((char *)"%s,%s,%s", unit->uuid, unit->name, UNITMODE[unit->mode]); 993 srv_send((char *)"%s,%s,%s", unit->uuid, unit->name, UNITMODE[unit->mode]);
994 } 994 }
995 srv_send((char *)"."); 995 srv_send((char *)".");
996 return 1; 996 return 1;
997 } 997 }
998 998
999 if (param == NULL) { 999 if (param == NULL) {
1000 srv_send((char *)"501 Parameter missing"); 1000 srv_send((char *)"502 Parameter missing");
1001 return 1; 1001 return 1;
1002 } 1002 }
1003 1003
1004 if (strcmp(opt, (char *)"ADD") == 0) { 1004 if (strcmp(opt, (char *)"ADD") == 0) {
1005 unit = (units_list *)malloc(sizeof(units_list)); 1005 unit = (units_list *)malloc(sizeof(units_list));
1032 break; 1032 break;
1033 } 1033 }
1034 } 1034 }
1035 } 1035 }
1036 1036
1037 syslog(LOG_NOTICE, "Unit with uuid %s added", unit->uuid); 1037 syslog(LOG_NOTICE, "Unit %s added", unit->uuid);
1038 srv_send((char *)"211 Unit with uuid %s added", unit->uuid); 1038 srv_send((char *)"211 Unit %s added", unit->uuid);
1039 return 0; 1039 return 0;
1040 } 1040 }
1041 1041
1042 if (strcmp(opt, (char *)"DEL") == 0) { 1042 if (strcmp(opt, (char *)"DEL") == 0) {
1043 if (delete_Unit(param)) { 1043 if (delete_Unit(param)) {
1044 syslog(LOG_NOTICE, "Deleted Unit with %s", param); 1044 syslog(LOG_NOTICE, "Unit %s deleted", param);
1045 srv_send((char *)"211 Unit %s deleted", param); 1045 srv_send((char *)"211 Unit %s deleted", param);
1046 return 0; 1046 return 0;
1047 } else { 1047 } else {
1048 srv_send((char *)"440 Delete Unit: No such unit %s", param); 1048 srv_send((char *)"440 No such unit");
1049 return 1; 1049 return 1;
1050 } 1050 }
1051 } 1051 }
1052 1052
1053 if (strcmp(opt, (char *)"GET") == 0) { 1053 if (strcmp(opt, (char *)"GET") == 0) {
1054 for (unit = Config.units; unit; unit = unit->next) { 1054 for (unit = Config.units; unit; unit = unit->next) {
1055 if (strcmp(param, unit->uuid) == 0) { 1055 if (strcmp(param, unit->uuid) == 0) {
1056 srv_send((char *)"213 Unit %s listing follows:", unit->uuid); 1056 srv_send((char *)"213 Unit listing follows:");
1057 srv_send((char *)"NAME,%s", unit->name); 1057 srv_send((char *)"NAME,%s", unit->name);
1058 srv_send((char *)"UUID,%s", unit->uuid); 1058 srv_send((char *)"UUID,%s", unit->uuid);
1059 srv_send((char *)"VOLUME,%2f", unit->volume); 1059 srv_send((char *)"VOLUME,%2f", unit->volume);
1060 srv_send((char *)"AIR_ADDRESS,%s", unit->air_address); 1060 srv_send((char *)"AIR_ADDRESS,%s", unit->air_address);
1061 srv_send((char *)"AIR_STATE,%s", TEMPSTATE[unit->air_state]); 1061 srv_send((char *)"AIR_STATE,%s", TEMPSTATE[unit->air_state]);
1086 srv_send((char *)"IDLE_RANGE_H,%.1f", unit->idle_rangeH); 1086 srv_send((char *)"IDLE_RANGE_H,%.1f", unit->idle_rangeH);
1087 srv_send((char *)"."); 1087 srv_send((char *)".");
1088 return 1; 1088 return 1;
1089 } 1089 }
1090 } 1090 }
1091 srv_send((char *)"410 No such unit"); 1091 srv_send((char *)"440 No such unit");
1092 return 1; 1092 return 1;
1093 } 1093 }
1094 1094
1095 if (strcmp(opt, (char *)"PUT") == 0) { 1095 if (strcmp(opt, (char *)"PUT") == 0) {
1096 for (unit = Config.units ; unit; unit = unit->next) { 1096 for (unit = Config.units ; unit; unit = unit->next) {
1295 } 1295 }
1296 } 1296 }
1297 } 1297 }
1298 } 1298 }
1299 } 1299 }
1300 srv_send((char *)"440 No such device"); 1300 srv_send((char *)"440 No such unit");
1301 return 1; 1301 return 1;
1302 } 1302 }
1303 1303
1304 1304
1305 srv_send((char *)"502 Unknown command option"); 1305 srv_send((char *)"504 Subcommand error");
1306 return 1; 1306 return 1;
1307 } 1307 }
1308 1308
1309 1309
1310 1310
1380 srv_send((char *)"UNIT GET uuid Get Unit record by uuid"); 1380 srv_send((char *)"UNIT GET uuid Get Unit record by uuid");
1381 srv_send((char *)"UNIT PUT uuid Put Unit record by uuid"); 1381 srv_send((char *)"UNIT PUT uuid Put Unit record by uuid");
1382 srv_send((char *)"."); 1382 srv_send((char *)".");
1383 } else if (strncmp(buf, "LCD", 3) == 0) { 1383 } else if (strncmp(buf, "LCD", 3) == 0) {
1384 #ifdef HAVE_WIRINGPI_H 1384 #ifdef HAVE_WIRINGPI_H
1385 srv_send((char *)"201 information follows"); 1385 srv_send((char *)"201 Information follows");
1386 for (j = 0; j < 4; j++) { 1386 for (j = 0; j < 4; j++) {
1387 sprintf(obuf, " "); 1387 sprintf(obuf, " ");
1388 obuf[20] = '\0'; 1388 obuf[20] = '\0';
1389 for (i = 0; i < 20; i++) 1389 for (i = 0; i < 20; i++)
1390 obuf[i] = lcdbuf[lcdHandle][i][j]; 1390 obuf[i] = lcdbuf[lcdHandle][i][j];
1401 wrconfig(); 1401 wrconfig();
1402 } else if (strncmp(buf, "UNIT", 4) == 0) { 1402 } else if (strncmp(buf, "UNIT", 4) == 0) {
1403 if (cmd_unit(buf) == 0) 1403 if (cmd_unit(buf) == 0)
1404 wrconfig(); 1404 wrconfig();
1405 } else { 1405 } else {
1406 if (debug)
1407 fprintf(stdout, "unknown command \"%s\"\n", buf);
1408 srv_send((char *)"500 Unknown command"); 1406 srv_send((char *)"500 Unknown command");
1409 } 1407 }
1410 } 1408 }
1411 } 1409 }
1412 1410

mercurial