497 |
497 |
498 |
498 |
499 /* |
499 /* |
500 * PROFILE List profile status of current unit |
500 * PROFILE List profile status of current unit |
501 * PROFILE uuid,name Rename profile name |
501 * PROFILE uuid,name Rename profile name |
|
502 * PROFILE GETS uuid Get profile steps list |
|
503 * PROFILE PUTS uuid Put profile steps list |
502 */ |
504 */ |
503 int cmd_profile(char *buf) |
505 int cmd_profile(char *buf) |
504 { |
506 { |
|
507 char ibuf[SS_BUFSIZE], *sstep, *rest, *targ; |
|
508 int i, rlen, istep, irest; |
|
509 float ftarg; |
|
510 socklen_t fromlen; |
505 char *opt, *uuid, *param; |
511 char *opt, *uuid, *param; |
506 profiles_list *profile; |
512 profiles_list *profile; |
|
513 prof_step *step, *olds; |
507 units_list *unit; |
514 units_list *unit; |
508 |
515 |
509 opt = strtok(buf, " \0"); |
516 opt = strtok(buf, " \0"); |
510 opt = strtok(NULL, "\0"); |
517 opt = strtok(NULL, " \0"); |
511 |
518 |
512 if (opt == NULL) { |
519 if (opt == NULL) { |
513 /* |
520 /* |
514 * Profile status of current unit |
521 * Profile status of current unit |
515 */ |
522 */ |
532 } |
539 } |
533 srv_send((char *)"241 Profile status follows:"); |
540 srv_send((char *)"241 Profile status follows:"); |
534 |
541 |
535 |
542 |
536 srv_send((char *)"."); |
543 srv_send((char *)"."); |
|
544 return 1; |
|
545 |
|
546 } else if (strcmp(opt, (char *)"GETS") == 0) { |
|
547 |
|
548 uuid = strtok(NULL, "\0\n\r"); |
|
549 if (uuid == NULL) { |
|
550 srv_send((char *)"502 Unknown command option"); |
|
551 return 1; |
|
552 } |
|
553 |
|
554 for (profile = Config.profiles; profile; profile = profile->next) { |
|
555 if (strcmp(profile->uuid, uuid) == 0) { |
|
556 srv_send((char *)"215 Profile steps follow:"); |
|
557 for (step = profile->steps; step; step = step->next) { |
|
558 srv_send((char *)"%d,%d,%.1f", step->steptime, step->resttime, step->target); |
|
559 } |
|
560 srv_send((char *)"."); |
|
561 return 1; |
|
562 } |
|
563 } |
|
564 |
|
565 srv_send((char *)"440 No such profile"); |
|
566 return 1; |
|
567 |
|
568 } else if (strcmp(opt, (char *)"PUTS") == 0) { |
|
569 |
|
570 uuid = strtok(NULL, "\0\n\r"); |
|
571 if (uuid == NULL) { |
|
572 srv_send((char *)"502 Unknown command option"); |
|
573 return 1; |
|
574 } |
|
575 |
|
576 for (profile = Config.profiles; profile; profile = profile->next) { |
|
577 if (strcmp(profile->uuid, uuid) == 0) { |
|
578 |
|
579 fprintf(stdout, "profile found\n"); |
|
580 if (profile->steps) { |
|
581 for (step = profile->steps; step; step = olds) { |
|
582 olds = step->next; |
|
583 free(step); |
|
584 } |
|
585 profile->steps = NULL; |
|
586 } |
|
587 fprintf(stdout, "profile cleared\n"); |
|
588 |
|
589 while (1) { |
|
590 memset((char *)&ibuf, 0, SS_BUFSIZE); |
|
591 fromlen = sizeof(peeraddr_in); |
|
592 rlen = recvfrom(s, ibuf, sizeof(ibuf) -1, 0, (struct sockaddr *)&peeraddr_in, &fromlen); |
|
593 if (rlen == -1) { |
|
594 syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno)); |
|
595 srv_send((char *)"518 recfrom(): %s", strerror(errno)); |
|
596 return 1; |
|
597 } else { |
|
598 for (i = 0; i < strlen(ibuf); i++) { |
|
599 if (ibuf[i] == '\n') |
|
600 ibuf[i] = '\0'; |
|
601 if (ibuf[i] == '\r') |
|
602 ibuf[i] = '\0'; |
|
603 } |
|
604 for (i = strlen(ibuf) -1; i > 0; i--) { |
|
605 if (ibuf[i] == ' ') |
|
606 ibuf[i] = '\0'; |
|
607 else |
|
608 break; |
|
609 } |
|
610 if (strlen(ibuf)) { |
|
611 if (debug) { |
|
612 syslog(LOG_NOTICE, "recv: \"%s\"", ibuf); |
|
613 fprintf(stdout, "recv: \"%s\"\n", ibuf); |
|
614 } |
|
615 if (strcmp(ibuf, (char *)".") == 0) { |
|
616 |
|
617 srv_send((char *)"219 Accepted profile steps"); |
|
618 return 0; |
|
619 } |
|
620 sstep = strtok(ibuf, ",\0"); |
|
621 rest = strtok(NULL, ",\0"); |
|
622 targ = strtok(NULL, "\0"); |
|
623 |
|
624 if ((sscanf(sstep, "%d", &istep) == 1) && |
|
625 (sscanf(rest, "%d", &irest) == 1) && |
|
626 (sscanf(targ, "%f", &ftarg) == 1)) { |
|
627 |
|
628 step = (prof_step *)malloc(sizeof(prof_step)); |
|
629 step->next = NULL; |
|
630 step->version = 1; |
|
631 step->steptime = istep; |
|
632 step->resttime = irest; |
|
633 step->target = ftarg; |
|
634 |
|
635 if (profile->steps == NULL) { |
|
636 profile->steps = step; |
|
637 } else { |
|
638 for (olds = profile->steps; olds; olds = olds->next) { |
|
639 if (olds->next == NULL) { |
|
640 olds->next = step; |
|
641 break; |
|
642 } |
|
643 } |
|
644 } |
|
645 } |
|
646 |
|
647 fprintf(stdout, "this was data\n"); |
|
648 } |
|
649 } |
|
650 } |
|
651 } |
|
652 } |
|
653 |
|
654 srv_send((char *)"440 No such profile"); |
537 return 1; |
655 return 1; |
538 |
656 |
539 } else { |
657 } else { |
540 /* |
658 /* |
541 * uuid,name rename profile |
659 * uuid,name rename profile |
825 srv_send((char *)"LIST PROFILES List available profiles"); |
943 srv_send((char *)"LIST PROFILES List available profiles"); |
826 srv_send((char *)"LIST UNIT List fermenter unit"); |
944 srv_send((char *)"LIST UNIT List fermenter unit"); |
827 srv_send((char *)"MODE OFF|NONE|BEER|FRIDGE|PROFILE"); |
945 srv_send((char *)"MODE OFF|NONE|BEER|FRIDGE|PROFILE"); |
828 // srv_send((char *)"PROFILE Profile status of current unit"); |
946 // srv_send((char *)"PROFILE Profile status of current unit"); |
829 srv_send((char *)"PROFILE uuid,name Profile rename"); |
947 srv_send((char *)"PROFILE uuid,name Profile rename"); |
|
948 srv_send((char *)"PROFILE GETS uuid Profile get steps list"); |
|
949 srv_send((char *)"PROFILE PUTS uuid Profile put steps list"); |
830 srv_send((char *)"SET BEER val Set beer temperature"); |
950 srv_send((char *)"SET BEER val Set beer temperature"); |
831 srv_send((char *)"SET FRIDGE val Set fridge temperature"); |
951 srv_send((char *)"SET FRIDGE val Set fridge temperature"); |
832 srv_send((char *)"SET IDLE_LOW val Set idle temperature low (-5.0 .. -0.1)"); |
952 srv_send((char *)"SET IDLE_LOW val Set idle temperature low (-5.0 .. -0.1)"); |
833 srv_send((char *)"SET IDLE_HIGH val Set idle temperature high (0.1 .. 5.0)"); |
953 srv_send((char *)"SET IDLE_HIGH val Set idle temperature high (0.1 .. 5.0)"); |
834 srv_send((char *)"SET NAME name Set name or beername for the unit"); |
954 srv_send((char *)"SET NAME name Set name or beername for the unit"); |