thermferm/server.c

changeset 696
fe042f9484ac
parent 693
3518c07737d8
child 698
92a080c1a5d5
equal deleted inserted replaced
695:ea20d8adbcaa 696:fe042f9484ac
21 *****************************************************************************/ 21 *****************************************************************************/
22 22
23 #include "rdconfig.h" 23 #include "rdconfig.h"
24 #include "thermferm.h" 24 #include "thermferm.h"
25 #include "delay.h" 25 #include "delay.h"
26 #include "one-wire.h"
26 #include "devices.h" 27 #include "devices.h"
27 #include "server.h" 28 #include "server.h"
28 #include "lcd-buffer.h" 29 #include "lcd-buffer.h"
29 #include "xutil.h" 30 #include "xutil.h"
30 #include "mqtt.h" 31 #include "mqtt.h"
32 33
33 extern int debug; 34 extern int debug;
34 extern int run_pause; 35 extern int run_pause;
35 extern int run_hold; 36 extern int run_hold;
36 extern sys_config Config; 37 extern sys_config Config;
38 extern w1_list *w1_devices;
37 extern const char UNITMODE[5][8]; 39 extern const char UNITMODE[5][8];
38 extern const char UNITSTAGE[4][12]; 40 extern const char UNITSTAGE[4][12];
39 extern const char DEVTYPE[8][6]; 41 extern const char DEVTYPE[8][6];
40 extern const char DEVPRESENT[4][6]; 42 extern const char DEVPRESENT[4][6];
41 extern const char DEVDIR[7][11]; 43 extern const char DEVDIR[7][11];
609 } 611 }
610 } 612 }
611 } 613 }
612 srv_send(s, (char *)"440 No such device"); 614 srv_send(s, (char *)"440 No such device");
613 return 0; 615 return 0;
616 }
617
618 srv_send(s, (char *)"504 Subcommand error");
619 return 0;
620 }
621
622
623
624 /*
625 * ONEWIRE JSON
626 */
627 int cmd_onewire(int s, char *buf)
628 {
629 char *opt, *param;
630 w1_list *dev_w1;
631
632 opt = strtok(buf, " \0");
633 opt = strtok(NULL, " \0");
634
635 if (opt == NULL) {
636 srv_send(s, (char *)"501 Subcommand missing");
637 return 0;
638 }
639 param = strtok(NULL, "\0");
640
641 if (strcmp(opt, (char *)"HELP") == 0) {
642 srv_send(s, (char *)"100 Help text follows:");
643 srv_send(s, (char *)"Recognized commands:");
644 srv_send(s, (char *)"ONEWIRE JSON Json list all or a single one-wire device");
645 srv_send(s, (char *)".");
646 return 0;
647 }
648
649 if (strcmp(opt, (char *)"JSON") == 0) {
650 char *payload = NULL, *payloadu = NULL;
651 bool comma = false;
652
653 if (param == NULL) {
654 srv_send(s, (char *)"212 One-wire json list follows:");
655 payload = xstrcpy((char *)"[");
656 for (dev_w1 = w1_devices; dev_w1; dev_w1 = dev_w1->next) {
657 if (comma)
658 payload = xstrcat(payload, (char *)",");
659 payloadu = one_wire_json(dev_w1);
660 payload = xstrcat(payload, payloadu);
661 comma = true;
662 free(payloadu);
663 payloadu = NULL;
664 }
665 payload = xstrcat(payload, (char *)"]");
666 srv_send(s, payload);
667 srv_send(s, (char *)".");
668 free(payload);
669 payload = NULL;
670 return 0;
671 }
614 } 672 }
615 673
616 srv_send(s, (char *)"504 Subcommand error"); 674 srv_send(s, (char *)"504 Subcommand error");
617 return 0; 675 return 0;
618 } 676 }
2219 srv_send(s, (char *)"DEVICE HELP Device help screen"); 2277 srv_send(s, (char *)"DEVICE HELP Device help screen");
2220 srv_send(s, (char *)"GLOBAL <CMD> [parameters] Global commands"); 2278 srv_send(s, (char *)"GLOBAL <CMD> [parameters] Global commands");
2221 srv_send(s, (char *)"GLOBAL HELP Global help screen"); 2279 srv_send(s, (char *)"GLOBAL HELP Global help screen");
2222 srv_send(s, (char *)"LIST <CMD> [parameters] List commands"); 2280 srv_send(s, (char *)"LIST <CMD> [parameters] List commands");
2223 srv_send(s, (char *)"LIST HELP List help screen"); 2281 srv_send(s, (char *)"LIST HELP List help screen");
2282 srv_send(s, (char *)"ONEWIRE <CMD> [parameters] One-wire commands");
2283 srv_send(s, (char *)"ONEWIRE HELP One-wire help screen");
2224 srv_send(s, (char *)"PING Check if server is alive"); 2284 srv_send(s, (char *)"PING Check if server is alive");
2225 #ifdef USE_SIMULATOR 2285 #ifdef USE_SIMULATOR
2226 srv_send(s, (char *)"SIMULATOR <CMD> [parameters] Simulator commands"); 2286 srv_send(s, (char *)"SIMULATOR <CMD> [parameters] Simulator commands");
2227 srv_send(s, (char *)"SIMULATOR HELP Simulator help screen"); 2287 srv_send(s, (char *)"SIMULATOR HELP Simulator help screen");
2228 #endif 2288 #endif
2230 srv_send(s, (char *)"UNIT HELP Unit help screen"); 2290 srv_send(s, (char *)"UNIT HELP Unit help screen");
2231 srv_send(s, (char *)"."); 2291 srv_send(s, (char *)".");
2232 2292
2233 } else if (strncmp(buf, "LIST", 4) == 0) { 2293 } else if (strncmp(buf, "LIST", 4) == 0) {
2234 cmd_list(s, buf); 2294 cmd_list(s, buf);
2295
2296 } else if (strncmp(buf, "ONEWIRE", 7) == 0) {
2297 cmd_onewire(s, buf);
2235 2298
2236 } else if (strncmp(buf, "PING", 4) == 0) { 2299 } else if (strncmp(buf, "PING", 4) == 0) {
2237 srv_send(s, (char *)"101 PONG"); 2300 srv_send(s, (char *)"101 PONG");
2238 2301
2239 #ifdef USE_SIMULATOR 2302 #ifdef USE_SIMULATOR

mercurial