thermferm/server.c

Mon, 04 Aug 2014 15:18:29 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 04 Aug 2014 15:18:29 +0200
changeset 176
8c7d87a2c094
parent 175
b73490398368
child 178
988a898974f3
permissions
-rw-r--r--

Initial code for a simple PID controller.

42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /*****************************************************************************
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * Copyright (C) 2008-2014
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * Michiel Broek <mbroek at mbse dot eu>
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 *
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * This file is part of the mbsePi-apps
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 *
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 * This is free software; you can redistribute it and/or modify it
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * under the terms of the GNU General Public License as published by the
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * Free Software Foundation; either version 2, or (at your option) any
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * later version.
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 *
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 * mbsePi-apps is distributed in the hope that it will be useful, but
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 * General Public License for more details.
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 *
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 * along with EC-65K; see the file COPYING. If not, write to the Free
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 *****************************************************************************/
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22
106
1bd9a16f5061 Added .h files
Michiel Broek <mbroek@mbse.eu>
parents: 101
diff changeset
23 #include "rdconfig.h"
46
000399c64d3f More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
24 #include "thermferm.h"
155
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
25 #include "logger.h"
106
1bd9a16f5061 Added .h files
Michiel Broek <mbroek@mbse.eu>
parents: 101
diff changeset
26 #include "server.h"
1bd9a16f5061 Added .h files
Michiel Broek <mbroek@mbse.eu>
parents: 101
diff changeset
27 #include "xutil.h"
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28
58
e8e7b46b705b Fixed compilation without wiringpi
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
29
75
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
30 extern int my_shutdown;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
31 extern int debug;
131
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
32 extern char *current_unit;
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 62
diff changeset
33 #ifdef HAVE_WIRINGPI_H
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 extern int lcdHandle;
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 extern unsigned char lcdbuf[MAX_LCDS][20][4];
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 62
diff changeset
36 #endif
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
37 extern sys_config Config;
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
38 extern const char UNITMODE[5][8];
95
2c28afc329a5 Removed old brewPi settings
Michiel Broek <mbroek@mbse.eu>
parents: 92
diff changeset
39 extern const char UNITmode[5];
101
1302abe92eb1 Made temperature sensors working in the units
Michiel Broek <mbroek@mbse.eu>
parents: 100
diff changeset
40 extern const char TEMPSTATE[3][8];
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
41 extern const char DEVTYPE[7][6];
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
42 extern const char DEVPRESENT[4][6];
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
43 extern const char DEVDIR[7][11];
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
44 extern const char PROFSTATE[4][6];
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
45
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
47 int s; /* connected socket */
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
48 int ls; /* listen socket */
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
50 struct sockaddr_in myaddr_in; /* for local socket address */
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
51 struct sockaddr_in peeraddr_in; /* for peer socket address */
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
52
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
53 struct hostent *hp;
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
54
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
55 #define SS_BUFSIZE 1024
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
56 #define SS_TIMEOUT 300
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
58
95
2c28afc329a5 Removed old brewPi settings
Michiel Broek <mbroek@mbse.eu>
parents: 92
diff changeset
59 float cs_heatEstimator = 0.2;
2c28afc329a5 Removed old brewPi settings
Michiel Broek <mbroek@mbse.eu>
parents: 92
diff changeset
60 float cs_coolEstimator = 5;
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
61 float cv_beerDiff = 0.0;
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
62
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63
46
000399c64d3f More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
64
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
65 /*
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
66 * Send message to client
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
67 */
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
68 int srv_send(const char *format, ...)
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
69 {
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
70 char out[SS_BUFSIZE];
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
71 va_list va_ptr;
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
72
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
73 if (s == -1)
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
74 return -1;
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
76 va_start(va_ptr, format);
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
77 vsnprintf(out, SS_BUFSIZE-1, format, va_ptr);
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
78 va_end(va_ptr);
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
79
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
80 if (debug) {
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
81 syslog(LOG_NOTICE, "send: \"%s\"", out);
45
053c4657105f Mirror LCD display on the webpage works
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
82 fprintf(stdout, "send: \"%s\"\n", out);
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
83 }
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
84
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
85 if (send(s, out, strlen(out), 0) != strlen(out)) {
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
86 syslog(LOG_NOTICE, "srv_send failed");
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
87 return -1;
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
88 }
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
89
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
90 if (send(s, (char *)"\r\n", 2, 0) != 2) {
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
91 syslog(LOG_NOTICE, "srv_send failed");
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
92 return -1;
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
93 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
94
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
95 return 0;
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
96 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
97
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
98
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
100 /*
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
101 * ADD PROFILE name
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
102 */
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
103 int unit_add(char *buf)
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
104 {
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
105 profiles_list *profile, *tmpp;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
106 uuid_t uu;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
107 char *opt, *param;
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
108
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
109 opt = strtok(buf, " \0");
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
110 opt = strtok(NULL, " \0");
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
111 if (opt == NULL) {
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
112 srv_send((char *)"501 Subcommand missing");
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
113 return 1;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
114 }
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
115
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
116 param = strtok(NULL, "\0");
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
117 if (param == NULL) {
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
118 srv_send((char *)"501 Parameter missing");
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
119 return 1;
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
120 }
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
121
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
122 if (debug)
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
123 fprintf(stdout, "opt: '%s' param: '%s'\n", MBSE_SS(opt), MBSE_SS(param));
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
124
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
125 if (strcmp(opt, (char *)"PROFILE") == 0) {
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
126 profile = (profiles_list *)malloc(sizeof(profiles_list));
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
127 profile->next = NULL;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
128 profile->version = 1;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
129 profile->uuid = malloc(37);
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
130 uuid_generate(uu);
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
131 uuid_unparse(uu, profile->uuid);
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
132 profile->name = xstrcpy(param);
138
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
133 profile->busy = 0;
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
134 profile->steps = NULL;
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
135
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
136 if (Config.profiles == NULL) {
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
137 Config.profiles = profile;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
138 } else {
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
139 for (tmpp = Config.profiles; tmpp; tmpp = tmpp->next) {
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
140 if (tmpp->next == NULL) {
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
141 tmpp->next = profile;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
142 break;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
143 }
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
144 }
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
145 }
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
146
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
147 syslog(LOG_NOTICE, "Profile \"%s\" with uuid %s added", param, profile->uuid);
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
148 srv_send((char *)"211 Profile \"%s\" with uuid %s added", param, profile->uuid);
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
149 return 0;
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
150 }
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
151
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
152 srv_send((char *)"502 Unknown command option");
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
153 return 1;
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
154 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
155
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
156
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
157
138
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
158
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
159 void delete_Profile(char *uuid)
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
160 {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
161 profiles_list *current = Config.profiles;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
162 profiles_list *previous = NULL;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
163 prof_step *step, *olds;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
164
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
165 while (current) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
166 if (strcmp(current->uuid, uuid) == 0) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
167 if (previous == NULL) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
168 Config.profiles = current->next;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
169 free(current->uuid);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
170 current->uuid = NULL;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
171 free(current->name);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
172 current->name = NULL;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
173 if (current->steps) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
174 for (step = current->steps; step; step = olds) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
175 olds = step->next;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
176 free(step);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
177 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
178 current->steps = NULL;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
179 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
180 free(current);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
181 return;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
182 } else {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
183 free(current->uuid);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
184 current->uuid = NULL;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
185 free(current->name);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
186 current->name = NULL;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
187 if (current->steps) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
188 for (step = current->steps; step; step = olds) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
189 olds = step->next;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
190 free(step);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
191 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
192 current->steps = NULL;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
193 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
194 previous->next = current->next;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
195 free(current);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
196 current = previous->next;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
197 return;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
198 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
199 } else {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
200 previous = current;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
201 current = current->next;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
202 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
203 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
204 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
205
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
206
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
207
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
208 /*
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
209 * DEL PROFILE
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
210 */
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
211 int cmd_del(char *buf)
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
212 {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
213 char *opt, *param;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
214
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
215 opt = strtok(buf, " \0");
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
216 opt = strtok(NULL, " \0");
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
217 if (opt == NULL) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
218 srv_send((char *)"501 Subcommand missing");
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
219 return 1;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
220 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
221
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
222 param = strtok(NULL, "\0");
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
223 if (param == NULL) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
224 srv_send((char *)"501 Parameter missing");
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
225 return 1;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
226 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
227
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
228 if (debug)
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
229 fprintf(stdout, "opt: '%s' param: '%s'\n", MBSE_SS(opt), MBSE_SS(param));
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
230
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
231 if (strcmp(opt, (char *)"PROFILE") == 0) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
232 delete_Profile(param);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
233 srv_send((char *)"211 Profile %s deleted", param);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
234 return 0;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
235 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
236
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
237 srv_send((char *)"502 Unknown command option");
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
238 return 1;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
239 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
240
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
241
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
242
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
243 int delete_Device(char *uuid)
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
244 {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
245 devices_list *current = Config.devices;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
246 devices_list *previous = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
247
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
248 while (current) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
249 if (strcmp(current->uuid, uuid) == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
250 if (previous == NULL) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
251 Config.devices = current->next;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
252 free(current->uuid);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
253 current->uuid = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
254 free(current->address);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
255 current->address = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
256 free(current->description);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
257 current->description = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
258 free(current->comment);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
259 current->comment = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
260 free(current);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
261 return 1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
262 } else {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
263 free(current->uuid);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
264 current->uuid = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
265 free(current->address);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
266 current->address = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
267 free(current->description);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
268 current->description = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
269 free(current->comment);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
270 current->comment = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
271 previous->next = current->next;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
272 free(current);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
273 current = previous->next;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
274 return 1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
275 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
276 } else {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
277 previous = current;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
278 current = current->next;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
279 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
280 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
281 return 0;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
282 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
283
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
284
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
285
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
286 /*
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
287 * DEVICE ADD type
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
288 * DEVICE DEL uuid
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
289 * DEVICE LIST
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
290 * DEVICE GET uuid
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
291 * DEVICE PUT uuid
157
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
292 */
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
293 int cmd_device(char *buf)
157
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
294 {
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
295 char *opt, *param, *kwd, *val, ibuf[SS_BUFSIZE];
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
296 devices_list *device, *tmpd;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
297 socklen_t fromlen;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
298 int i, rlen, ival;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
299 uuid_t uu;
157
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
300
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
301 opt = strtok(buf, " \0");
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
302 opt = strtok(NULL, " \0");
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
303
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
304 if (opt == NULL) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
305 srv_send((char *)"502 Missing command option");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
306 return 1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
307 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
308 param = strtok(NULL, "\0");
157
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
309
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
310 if (strcmp(opt, (char *)"LIST") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
311 srv_send((char *)"212 bus devices:");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
312 for (device = Config.devices; device; device = device->next) {
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
313 srv_send((char *)"%s,%s,%d,%d,%s,%s", device->uuid, device->address, device->subdevice, device->inuse, device->comment, DEVDIR[device->direction]);
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
314 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
315 srv_send((char *)".");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
316 return 0;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
317 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
318
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
319 if (param == NULL) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
320 srv_send((char *)"502 Missing command parameter");
157
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
321 return 1;
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
322 }
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
323
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
324 if (strcmp(opt, (char *)"ADD") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
325 if ((strcmp(param, (char *)"RC433") == 0) || (strcmp(param, (char *)"DHT") == 0) ||
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
326 (strcmp(param, (char *)"I2C") == 0) || (strcmp(param, (char *)"SPI") == 0)) {
170
3cb99272b84b A bit of code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 167
diff changeset
327
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
328 device = (devices_list *)malloc(sizeof(devices_list));
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
329 device->next = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
330 device->version = 1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
331 device->uuid = malloc(37);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
332 uuid_generate(uu);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
333 uuid_unparse(uu, device->uuid);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
334 for (i = 0; i < 7; i++) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
335 if (strcmp(param, DEVTYPE[i]) == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
336 device->type = i;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
337 break;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
338 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
339 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
340 device->direction = DEVDIR_UNDEF;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
341 device->value = device->subdevice = device->inuse = 0;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
342 device->present = DEVPRESENT_UNDEF;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
343 device->address = xstrcpy((char *)"Enter address here");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
344 device->gpiopin = -1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
345 device->description = xstrcpy((char *)"Describe me here");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
346 device->comment = xstrcpy((char *)"Comment here");
170
3cb99272b84b A bit of code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 167
diff changeset
347
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
348 if (Config.devices == NULL) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
349 Config.devices = device;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
350 } else {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
351 for (tmpd = Config.devices; tmpd; tmpd = tmpd->next) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
352 if (tmpd->next == NULL) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
353 tmpd->next = device;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
354 break;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
355 }
157
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
356 }
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
357 }
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
358 syslog(LOG_NOTICE, "Device with uuid %s added", device->uuid);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
359 srv_send((char *)"211 Device with uuid %s added", device->uuid);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
360 return 0;
157
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
361
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
362 } else {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
363 srv_send((char *)"506 Wrong device parameter");
157
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
364 return 1;
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
365 }
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
366 }
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
367
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
368 if (strcmp(opt, (char *)"DEL") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
369
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
370 if (delete_Device(param)) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
371 syslog(LOG_NOTICE, "Deleted device with %s", param);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
372 srv_send((char *)"211 Device %s deleted", param);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
373 return 0;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
374 } else {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
375 srv_send((char *)"440 Delete Device: No such device %s", param);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
376 return 1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
377 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
378 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
379
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
380 if (strcmp(opt, (char *)"GET") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
381 for (device = Config.devices; device; device = device->next) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
382 if (strcmp(device->uuid, param) == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
383 srv_send((char *)"213 Device %s record follows:", device->uuid);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
384 srv_send((char *)"TYPE,%s", DEVTYPE[device->type]);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
385 srv_send((char *)"DIRECTION,%s", DEVDIR[device->direction]);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
386 srv_send((char *)"VALUE,%d", device->value);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
387 srv_send((char *)"PRESENT,%s", DEVPRESENT[device->present]);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
388 srv_send((char *)"ADDRESS,%s", device->address);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
389 srv_send((char *)"SUBDEVICE,%d", device->subdevice);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
390 srv_send((char *)"GPIOPIN,%d", device->gpiopin);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
391 srv_send((char *)"DESCRIPTION,%s", device->description);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
392 srv_send((char *)"INUSE,%d", device->inuse);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
393 srv_send((char *)"COMMENT,%s", device->comment);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
394 srv_send((char *)"TIMESTAMP,%d", (int)device->timestamp);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
395 srv_send((char *)".");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
396 return 1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
397 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
398 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
399 srv_send((char *)"440 No such device");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
400 return 1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
401 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
402
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
403 if (strcmp(opt, (char *)"PUT") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
404 for (device = Config.devices; device; device = device->next) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
405 if (strcmp(device->uuid, param) == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
406 while (1) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
407 memset((char *)&ibuf, 0, SS_BUFSIZE);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
408 fromlen = sizeof(peeraddr_in);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
409 rlen = recvfrom(s, ibuf, sizeof(ibuf) -1, 0, (struct sockaddr *)&peeraddr_in, &fromlen);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
410 if (rlen == -1) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
411 syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno));
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
412 srv_send((char *)"518 recfrom(): %s", strerror(errno));
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
413 return 1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
414 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
415 for (i = 0; i < strlen(ibuf); i++) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
416 if (ibuf[i] == '\n')
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
417 ibuf[i] = '\0';
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
418 if (ibuf[i] == '\r')
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
419 ibuf[i] = '\0';
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
420 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
421 for (i = strlen(ibuf) -1; i > 0; i--) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
422 if (ibuf[i] == ' ')
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
423 ibuf[i] = '\0';
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
424 else
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
425 break;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
426 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
427 if (strlen(ibuf)) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
428 if (debug) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
429 syslog(LOG_NOTICE, "recv: \"%s\"", ibuf);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
430 fprintf(stdout, "recv: \"%s\"\n", ibuf);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
431 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
432 if (strcmp(ibuf, (char *)".") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
433 srv_send((char *)"219 Accepted Device record");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
434 return 0;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
435 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
436 kwd = strtok(ibuf, ",\0");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
437 val = strtok(NULL, "\0");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
438 if (kwd && val) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
439 if (strcmp(kwd, (char *)"TYPE") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
440 for (i = 0; i < 7; i++) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
441 if (strcmp(val, DEVTYPE[i]) == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
442 device->type = i;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
443 break;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
444 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
445 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
446
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
447 } else if (strcmp(kwd, (char *)"DIRECTION") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
448 for (i = 0; i < 7; i++) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
449 if (strcmp(val, DEVDIR[i]) == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
450 device->direction = i;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
451 break;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
452 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
453 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
454
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
455 } else if (strcmp(kwd, (char *)"VALUE") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
456 if (sscanf(val, "%d", &ival) == 1)
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
457 device->value = ival;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
458
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
459 } else if (strcmp(kwd, (char *)"PRESENT") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
460 for (i = 0; i < 4; i++) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
461 if (strcmp(val, DEVPRESENT[i]) == 0)
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
462 device->present = i;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
463 break;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
464 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
465
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
466 } else if (strcmp(kwd, (char *)"ADDRESS") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
467 if (device->address)
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
468 free(device->address);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
469 device->address = xstrcpy(val);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
470
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
471 } else if (strcmp(kwd, (char *)"SUBDEVICE") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
472 if (sscanf(val, "%d", &ival) == 1)
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
473 device->subdevice = ival;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
474
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
475 } else if (strcmp(kwd, (char *)"GPIOPIN") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
476 if (sscanf(val, "%d", &ival) == 1)
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
477 device->gpiopin = ival;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
478
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
479 } else if (strcmp(kwd, (char *)"DESCRIPTION") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
480 if (device->description)
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
481 free(device->description);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
482 device->description = xstrcpy(val);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
483
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
484 } else if (strcmp(kwd, (char *)"COMMENT") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
485 if (device->comment)
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
486 free(device->comment);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
487 device->comment = xstrcpy(val);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
488
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
489 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
490 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
491 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
492 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
493 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
494 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
495 srv_send((char *)"440 No such device");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
496 return 1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
497 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
498
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
499 srv_send((char *)"502 Unknown command option");
157
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
500 return 1;
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
501 }
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
502
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
503
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
504
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
505 /*
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
506 * LIST
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
507 * LIST LOG
84
ef4c0032b51f Can list the 1-wire bus
Michiel Broek <mbroek@mbse.eu>
parents: 81
diff changeset
508 * LIST PROFILES
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
509 */
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
510 int cmd_list(char *buf)
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
511 {
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
512 char *opt, *filename, *p, q[2], buffer[256];
84
ef4c0032b51f Can list the 1-wire bus
Michiel Broek <mbroek@mbse.eu>
parents: 81
diff changeset
513 units_list *unit;
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
514 profiles_list *profile;
124
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
515 prof_step *step;
163
3d813570a5e3 LIST BUS now displays the new devices table. Adjusted the web screen
Michiel Broek <mbroek@mbse.eu>
parents: 158
diff changeset
516 int j;
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
517 FILE *fp;
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
518
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
519 opt = strtok(buf, " \0");
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
520 opt = strtok(NULL, "\0");
84
ef4c0032b51f Can list the 1-wire bus
Michiel Broek <mbroek@mbse.eu>
parents: 81
diff changeset
521
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
522 if (opt == NULL) {
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
523 /*
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
524 * Default, list available units
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
525 */
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
526 srv_send((char *)"212 Fermenter list follows:");
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
527 for (unit = Config.units; unit; unit = unit->next) {
131
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
528 srv_send((char *)"%s,%s,%s", unit->uuid, unit->name, UNITMODE[unit->mode]);
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
529 }
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
530 srv_send((char *)".");
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
531 return 0;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
532
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
533 } else if (strcmp(opt, (char *)"LOG") == 0) {
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
534 /*
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
535 * Get the logfile data and emit only one line per hour.
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
536 */
131
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
537 if (current_unit == NULL) {
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
538 srv_send((char *)"401 No fermenter unit selected");
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
539 return 1;
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
540 }
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
541
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
542 q[0] = q[1] = 'a';
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
543 for (unit = Config.units; unit; unit = unit->next) {
131
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
544 if (strcmp(current_unit, unit->uuid) == 0)
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
545 break;
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
546 }
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
547
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
548 srv_send((char *)"212 Logfile list follows:");
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
549 if (getenv((char *)"USER") == NULL) {
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
550 filename = xstrcpy((char *)"/root");
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
551 } else {
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
552 filename = xstrcpy(getenv((char *)"HOME"));
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
553 }
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
554 filename = xstrcat(filename, (char *)"/.thermferm/log/");
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
555 filename = xstrcat(filename, unit->name);
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
556 filename = xstrcat(filename, (char *)".log");
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
557 if ((fp = fopen(filename, "r"))) {
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
558 while (fgets(buffer, sizeof(buffer)-1, fp) != NULL) {
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
559 buffer[strlen(buffer) -1] = '\0';
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
560 p = buffer + 17;
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
561 if (strncmp(p, (char *)"Mode", 4)) {
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
562 if ((q[0] != buffer[11]) || (q[1] != buffer[12])) {
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
563 q[0] = buffer[11];
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
564 q[1] = buffer[12];
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
565 srv_send(buffer);
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
566 }
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
567 }
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
568 }
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
569 }
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
570 free(filename);
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
571 filename = NULL;
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
572 srv_send((char *)".");
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
573 return 0;
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
574
84
ef4c0032b51f Can list the 1-wire bus
Michiel Broek <mbroek@mbse.eu>
parents: 81
diff changeset
575 } else if (strcmp(opt, (char *)"PROFILES") == 0) {
86
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 85
diff changeset
576 /*
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
577 * Fermenting profiles
86
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 85
diff changeset
578 */
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
579 srv_send((char *)"212 profiles:");
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
580 for (profile = Config.profiles; profile; profile = profile->next) {
124
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
581 j = 0;
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
582 for (step = profile->steps; step; step = step->next)
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
583 j++;
136
264e5ee5abfc Profiles now have a busy state
Michiel Broek <mbroek@mbse.eu>
parents: 133
diff changeset
584 srv_send((char *)"%s,%s,%d,%d", profile->uuid, profile->name, j, profile->busy);
86
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 85
diff changeset
585 }
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
586 srv_send((char *)".");
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
587 return 0;
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
588 }
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
589
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
590 srv_send((char *)"502 Unknown command option");
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
591 return 1;
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
592 }
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
593
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
594
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
595
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
596 /*
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
597 * Set new operating mode
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
598 * MODE OFF|NONE|BEER|FRIDGE|PROFILE
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
599 */
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
600 int cmd_mode(char *buf)
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
601 {
155
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
602 char *opt;
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
603 units_list *unit;
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
604
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
605 opt = strtok(buf, " \0");
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
606 opt = strtok(NULL, "\0");
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
607
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
608 if (opt == NULL) {
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
609 srv_send((char *)"502 Missing command option");
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
610 return 1;
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
611 }
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
612
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
613 if (current_unit == NULL) {
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
614 srv_send((char *)"401 No fermenter unit selected");
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
615 return 1;
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
616 }
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
617 for (unit = Config.units; unit; unit = unit->next) {
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
618 if (strcmp(current_unit, unit->uuid) == 0)
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
619 break;
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
620 }
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
621
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
622 if (strcmp(opt, (char *)"OFF") == 0) {
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
623 if (unit->mode != UNITMODE_OFF) {
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
624 unit->mode = UNITMODE_OFF;
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
625 syslog(LOG_NOTICE, "Unit %s mode set to OFF", unit->name);
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
626 }
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
627 srv_send((char *)"218 Unit mode to OFF");
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
628 return 0;
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
629
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
630 } else if (strcmp(opt, (char *)"NONE") == 0) {
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
631 if (unit->mode != UNITMODE_NONE) {
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
632 unit->mode = UNITMODE_NONE;
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
633 syslog(LOG_NOTICE, "Unit %s mode set to NONE", unit->name);
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
634 initlog(unit->name);
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
635 }
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
636 srv_send((char *)"218 Unit mode to NONE");
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
637 return 0;
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
638
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
639 } else if (strcmp(opt, (char *)"FRIDGE") == 0) {
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
640
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
641 } else if (strcmp(opt, (char *)"BEER") == 0) {
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
642
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
643 } else if (strcmp(opt, (char *)"PROFILE") == 0) {
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
644
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
645 }
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
646
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
647 srv_send((char *)"502 Unknown command option");
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
648 return 1;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
649 }
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
650
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
651
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
652
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
653 /*
132
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
654 * PROFILE List profile status of current unit
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
655 * PROFILE uuid,name Rename profile name
140
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
656 * PROFILE GETS uuid Get profile steps list
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
657 * PROFILE PUTS uuid Put profile steps list
132
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
658 */
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
659 int cmd_profile(char *buf)
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
660 {
140
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
661 char ibuf[SS_BUFSIZE], *sstep, *rest, *targ;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
662 int i, rlen, istep, irest;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
663 float ftarg;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
664 socklen_t fromlen;
132
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
665 char *opt, *uuid, *param;
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
666 profiles_list *profile;
140
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
667 prof_step *step, *olds;
132
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
668 units_list *unit;
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
669
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
670 opt = strtok(buf, " \0");
140
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
671 opt = strtok(NULL, " \0");
132
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
672
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
673 if (opt == NULL) {
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
674 /*
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
675 * Profile status of current unit
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
676 */
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
677 if (current_unit == NULL) {
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
678 srv_send((char *)"401 No fermenter unit selected");
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
679 return 1;
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
680 }
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
681 for (unit = Config.units; unit; unit = unit->next) {
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
682 if (strcmp(current_unit, unit->uuid) == 0)
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
683 break;
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
684 }
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
685
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
686 if (unit->profile == NULL) {
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
687 srv_send((char *)"441 Unit has no profile");
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
688 return 1;
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
689 }
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
690 if (unit->mode != UNITMODE_PROFILE) {
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
691 srv_send((char *)"442 Unit is not using a profile");
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
692 return 1;
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
693 }
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
694 srv_send((char *)"241 Profile status follows:");
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
695
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
696
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
697 srv_send((char *)".");
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
698 return 1;
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
699
140
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
700 } else if (strcmp(opt, (char *)"GETS") == 0) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
701
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
702 uuid = strtok(NULL, "\0\n\r");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
703 if (uuid == NULL) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
704 srv_send((char *)"502 Unknown command option");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
705 return 1;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
706 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
707
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
708 for (profile = Config.profiles; profile; profile = profile->next) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
709 if (strcmp(profile->uuid, uuid) == 0) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
710 srv_send((char *)"215 Profile steps follow:");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
711 for (step = profile->steps; step; step = step->next) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
712 srv_send((char *)"%d,%d,%.1f", step->steptime, step->resttime, step->target);
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
713 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
714 srv_send((char *)".");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
715 return 1;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
716 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
717 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
718
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
719 srv_send((char *)"440 No such profile");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
720 return 1;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
721
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
722 } else if (strcmp(opt, (char *)"PUTS") == 0) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
723
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
724 uuid = strtok(NULL, "\0\n\r");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
725 if (uuid == NULL) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
726 srv_send((char *)"502 Unknown command option");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
727 return 1;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
728 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
729
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
730 for (profile = Config.profiles; profile; profile = profile->next) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
731 if (strcmp(profile->uuid, uuid) == 0) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
732
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
733 fprintf(stdout, "profile found\n");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
734 if (profile->steps) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
735 for (step = profile->steps; step; step = olds) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
736 olds = step->next;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
737 free(step);
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
738 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
739 profile->steps = NULL;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
740 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
741 fprintf(stdout, "profile cleared\n");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
742
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
743 while (1) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
744 memset((char *)&ibuf, 0, SS_BUFSIZE);
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
745 fromlen = sizeof(peeraddr_in);
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
746 rlen = recvfrom(s, ibuf, sizeof(ibuf) -1, 0, (struct sockaddr *)&peeraddr_in, &fromlen);
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
747 if (rlen == -1) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
748 syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno));
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
749 srv_send((char *)"518 recfrom(): %s", strerror(errno));
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
750 return 1;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
751 } else {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
752 for (i = 0; i < strlen(ibuf); i++) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
753 if (ibuf[i] == '\n')
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
754 ibuf[i] = '\0';
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
755 if (ibuf[i] == '\r')
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
756 ibuf[i] = '\0';
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
757 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
758 for (i = strlen(ibuf) -1; i > 0; i--) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
759 if (ibuf[i] == ' ')
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
760 ibuf[i] = '\0';
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
761 else
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
762 break;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
763 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
764 if (strlen(ibuf)) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
765 if (debug) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
766 syslog(LOG_NOTICE, "recv: \"%s\"", ibuf);
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
767 fprintf(stdout, "recv: \"%s\"\n", ibuf);
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
768 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
769 if (strcmp(ibuf, (char *)".") == 0) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
770
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
771 srv_send((char *)"219 Accepted profile steps");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
772 return 0;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
773 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
774 sstep = strtok(ibuf, ",\0");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
775 rest = strtok(NULL, ",\0");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
776 targ = strtok(NULL, "\0");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
777
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
778 if ((sscanf(sstep, "%d", &istep) == 1) &&
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
779 (sscanf(rest, "%d", &irest) == 1) &&
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
780 (sscanf(targ, "%f", &ftarg) == 1)) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
781
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
782 step = (prof_step *)malloc(sizeof(prof_step));
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
783 step->next = NULL;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
784 step->version = 1;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
785 step->steptime = istep;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
786 step->resttime = irest;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
787 step->target = ftarg;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
788
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
789 if (profile->steps == NULL) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
790 profile->steps = step;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
791 } else {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
792 for (olds = profile->steps; olds; olds = olds->next) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
793 if (olds->next == NULL) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
794 olds->next = step;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
795 break;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
796 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
797 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
798 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
799 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
800
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
801 fprintf(stdout, "this was data\n");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
802 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
803 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
804 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
805 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
806 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
807
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
808 srv_send((char *)"440 No such profile");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
809 return 1;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
810
132
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
811 } else {
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
812 /*
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
813 * uuid,name rename profile
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
814 */
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
815 uuid = strtok(opt, ",");
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
816 param = strtok(NULL, "\0");
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
817 fprintf(stdout, "uuid: '%s' param: '%s'\n", uuid, param);
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
818 for (profile = Config.profiles; profile; profile = profile->next) {
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
819 if (strcmp(profile->uuid, uuid) == 0) {
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
820 syslog(LOG_NOTICE, "Profile %s rename from '%s' to '%s'", uuid, profile->name, param);
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
821 if (profile->name)
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
822 free(profile->name);
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
823 profile->name = xstrcpy(param);
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
824 srv_send((char *)"240 Profile updated");
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
825 return 0;
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
826 }
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
827 }
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
828 srv_send((char *)"440 No such profile");
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
829 return 1;
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
830 }
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
831
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
832 srv_send((char *)"502 Unknown command option");
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
833 return 1;
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
834 }
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
835
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
836
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
837
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
838 /*
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
839 * SET PROFILE string
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
840 */
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
841 int cmd_set(char *buf)
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
842 {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
843 char *opt, *param;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
844 units_list *unit;
132
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
845 profiles_list *profile;
131
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
846 int rc;
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
847 float fval;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
848
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
849 opt = strtok(buf, " \0");
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
850 opt = strtok(NULL, " \0");
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
851 if (opt == NULL) {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
852 srv_send((char *)"501 Subcommand missing");
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
853 return 1;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
854 }
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
855
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
856 param = strtok(NULL, "\0");
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
857 if (param == NULL) {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
858 srv_send((char *)"501 Parameter missing");
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
859 return 1;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
860 }
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
861
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
862 rc = sscanf(param, "%f", &fval);
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
863
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
864 if (debug)
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
865 fprintf(stdout, "opt='%s' param='%s' rc=%d fval=%.1f\n", opt, param, rc, fval);
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
866
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
867 /*
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
868 * Commands below need a selected unit
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
869 */
131
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
870 if (current_unit == NULL) {
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
871 srv_send((char *)"401 No fermenter unit selected");
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
872 return 1;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
873 }
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
874
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
875 for (unit = Config.units; unit; unit = unit->next) {
131
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
876 if (strcmp(current_unit, unit->uuid) == 0)
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
877 break;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
878 }
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
879
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
880 if (strcmp(opt, (char *)"PROFILE") == 0) {
132
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
881 /*
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
882 * Check for active profile, already selected etc.
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
883 */
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
884 if (unit->profile && (unit->mode == UNITMODE_PROFILE)) {
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
885 srv_send((char *)"541 Cannot change profile while a profile is active");
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
886 return 1;
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
887 }
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
888 if (unit->profile && (strcmp(unit->profile, param) == 0)) {
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
889 srv_send((char *)"542 Profile already set");
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
890 return 1;
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
891 }
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
892 for (profile = Config.profiles; profile; profile = profile->next) {
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
893 if (strcmp(profile->uuid, param) == 0) {
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
894 if (unit->profile)
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
895 free(unit->profile);
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
896 unit->profile = xstrcpy(param);
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
897 srv_send((char *)"242 Unit profile changed to %s", param);
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
898 return 0;
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
899 }
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
900 }
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
901 srv_send((char *)"543 Invalid profile");
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
902 return 1;
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
903 }
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
904
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
905 srv_send((char *)"502 Unknown command option");
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
906 return 1;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
907 }
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
908
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
909
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
910
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
911 int delete_Unit(char *uuid)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
912 {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
913 units_list *current = Config.units;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
914 units_list *previous = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
915
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
916 while (current) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
917 if (strcmp(current->uuid, uuid) == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
918 if (previous == NULL) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
919 Config.units = current->next;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
920 free(current->uuid);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
921 current->uuid = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
922 free(current->name);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
923 current->name = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
924 if (current->air_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
925 free(current->air_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
926 current->air_address = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
927 if (current->beer_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
928 free(current->beer_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
929 current->beer_address = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
930 if (current->heater_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
931 free(current->heater_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
932 current->heater_address = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
933 if (current->cooler_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
934 free(current->cooler_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
935 current->cooler_address = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
936 if (current->fan_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
937 free(current->fan_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
938 current->fan_address = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
939 if (current->door_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
940 free(current->door_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
941 current->door_address = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
942 if (current->profile)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
943 free(current->profile);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
944 current->profile = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
945 free(current);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
946 return 1;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
947 } else {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
948 free(current->uuid);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
949 current->uuid = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
950 free(current->name);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
951 current->name = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
952 if (current->air_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
953 free(current->air_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
954 current->air_address = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
955 if (current->beer_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
956 free(current->beer_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
957 current->beer_address = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
958 if (current->heater_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
959 free(current->heater_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
960 current->heater_address = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
961 if (current->cooler_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
962 free(current->cooler_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
963 current->cooler_address = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
964 if (current->fan_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
965 free(current->fan_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
966 current->fan_address = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
967 if (current->door_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
968 free(current->door_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
969 current->door_address = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
970 if (current->profile)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
971 free(current->profile);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
972 current->profile = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
973 free(current);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
974 current = previous->next;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
975 return 1;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
976 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
977 } else {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
978 previous = current;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
979 current = current->next;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
980 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
981 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
982 return 0;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
983 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
984
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
985
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
986
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
987 /*
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
988 * UNIT uuid
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
989 * UNIT ADD name
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
990 * UNIT DEL uuid
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
991 * UNIT LIST
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
992 * UNIT GET uuid
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
993 * UNIT PUT uuid
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
994 */
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
995 int cmd_unit(char *buf)
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
996 {
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
997 char *opt, *param = NULL, *kwd, *val, ibuf[SS_BUFSIZE];
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
998 units_list *unit, *tmpu;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
999 uuid_t uu;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1000 socklen_t fromlen;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1001 int i, rlen;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1002 float fval;
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1003
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1004 opt = strtok(buf, " \0");
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1005 opt = strtok(NULL, " \0");
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1006
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1007 if (opt == NULL) {
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1008 srv_send((char *)"501 Parameter missing");
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1009 return 1;
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1010 }
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1011 param = strtok(NULL, "\0");
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1012
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1013 /*
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1014 * UNIT uuid
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1015 */
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1016 if ((strlen(opt) == 36) && (param == NULL)) {
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1017 /*
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1018 * Search using uuid
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1019 */
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1020 for (unit = Config.units; unit; unit = unit->next) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1021 if (strcmp(opt, unit->uuid) == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1022 srv_send((char *)"210 Unit %s selected", unit->uuid);
131
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
1023 if (current_unit)
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
1024 free(current_unit);
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1025 current_unit = xstrcpy(unit->uuid);;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1026 return 1;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1027 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1028 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1029 srv_send((char *)"410 No such unit");
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1030 return 1;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1031 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1032
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1033 if ((strcmp(opt, (char *)"LIST") == 0) && (param == NULL)) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1034 srv_send((char *)"212 Fermenter Units list follows:");
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1035 for (unit = Config.units; unit; unit = unit->next) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1036 srv_send((char *)"%s,%s,%s", unit->uuid, unit->name, UNITMODE[unit->mode]);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1037 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1038 srv_send((char *)".");
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1039 return 1;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1040 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1041
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1042 if (param == NULL) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1043 srv_send((char *)"501 Parameter missing");
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1044 return 1;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1045 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1046
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1047 if (strcmp(opt, (char *)"ADD") == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1048 unit = (units_list *)malloc(sizeof(units_list));
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1049 unit->next = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1050 unit->version = 1;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1051 unit->uuid = malloc(37);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1052 uuid_generate(uu);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1053 uuid_unparse(uu, unit->uuid);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1054 if (current_unit)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1055 free(current_unit);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1056 current_unit = xstrcpy(unit->uuid);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1057 unit->name = xstrcpy(param);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1058 unit->air_address = unit->beer_address = unit->heater_address = unit->cooler_address = \
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1059 unit->fan_address = unit->door_address = unit->profile = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1060 unit->volume = 0.0;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1061 unit->air_state = unit->beer_state = 1;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1062 unit->air_temperature = unit->beer_temperature = 20000;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1063 unit->beer_set = unit->fridge_set = 20.0;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1064 unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->mode = unit->prof_state = 0;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1065 unit->temp_set_min = 1.0;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1066 unit->temp_set_max = 30.0;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1067 unit->idle_rangeH = 1.0;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1068 unit->idle_rangeL = -1.0;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1069 unit->prof_started = (time_t)0;
176
8c7d87a2c094 Initial code for a simple PID controller.
Michiel Broek <mbroek@mbse.eu>
parents: 175
diff changeset
1070 unit->PID_err_old = 0.0;
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1071
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1072 if (Config.units == NULL) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1073 Config.units = unit;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1074 } else {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1075 for (tmpu = Config.units; tmpu; tmpu = tmpu->next) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1076 if (tmpu->next == NULL) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1077 tmpu->next = unit;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1078 break;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1079 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1080 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1081 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1082
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1083 syslog(LOG_NOTICE, "Unit with uuid %s added", unit->uuid);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1084 srv_send((char *)"211 Unit with uuid %s added", unit->uuid);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1085 return 0;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1086 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1087
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1088 if (strcmp(opt, (char *)"DEL") == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1089 if (delete_Unit(param)) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1090 syslog(LOG_NOTICE, "Deleted Unit with %s", param);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1091 srv_send((char *)"211 Unit %s deleted", param);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1092 return 0;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1093 } else {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1094 srv_send((char *)"440 Delete Unit: No such unit %s", param);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1095 return 1;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1096 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1097 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1098
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1099 if (strcmp(opt, (char *)"GET") == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1100 for (unit = Config.units; unit; unit = unit->next) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1101 if (strcmp(param, unit->uuid) == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1102 srv_send((char *)"213 Unit %s listing follows:", unit->uuid);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1103 srv_send((char *)"NAME,%s", unit->name);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1104 srv_send((char *)"UUID,%s", unit->uuid);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1105 srv_send((char *)"VOLUME,%2f", unit->volume);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1106 srv_send((char *)"AIR_ADDRESS,%s", unit->air_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1107 srv_send((char *)"AIR_STATE,%s", TEMPSTATE[unit->air_state]);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1108 srv_send((char *)"AIR_TEMPERATURE,%.3f", unit->air_temperature / 1000.0);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1109 srv_send((char *)"BEER_ADDRESS,%s", MBSE_SS(unit->beer_address));
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1110 srv_send((char *)"BEER_STATE,%s", TEMPSTATE[unit->beer_state]);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1111 srv_send((char *)"BEER_TEMPERATURE,%.3f", unit->beer_temperature / 1000.0);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1112 srv_send((char *)"HEATER_ADDRESS,%s", unit->heater_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1113 srv_send((char *)"HEATER_STATE,%d", unit->heater_state);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1114 srv_send((char *)"COOLER_ADDRESS,%s", unit->cooler_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1115 srv_send((char *)"COOLER_STATE,%d", unit->cooler_state);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1116 srv_send((char *)"FAN_ADDRESS,%s", unit->fan_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1117 srv_send((char *)"FAN_STATE,%d", unit->fan_state);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1118 srv_send((char *)"DOOR_ADDRESS,%s", unit->door_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1119 srv_send((char *)"DOOR_STATE,%d", unit->door_state);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1120 srv_send((char *)"MODE,%s", UNITMODE[unit->mode]);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1121 srv_send((char *)"FRIDGE_SET,%.1f", unit->fridge_set);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1122 srv_send((char *)"BEER_SET,%.1f", unit->beer_set);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1123 srv_send((char *)"PROFILE,%s", unit->profile);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1124 if (unit->profile) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1125 srv_send((char *)"PROF_STARTED,%d", (int)unit->prof_started);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1126 srv_send((char *)"PROF_STATE,%s", PROFSTATE[unit->prof_state]);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1127 srv_send((char *)"PROF_TARGET,%.3f", unit->prof_target);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1128 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1129 srv_send((char *)"TEMP_SET_MIN,%.1f", unit->temp_set_min);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1130 srv_send((char *)"TEMP_SET_MAX,%.1f", unit->temp_set_max);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1131 srv_send((char *)"IDLE_RANGE_L,%.1f", unit->idle_rangeL);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1132 srv_send((char *)"IDLE_RANGE_H,%.1f", unit->idle_rangeH);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1133 srv_send((char *)".");
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1134 return 1;
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1135 }
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1136 }
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1137 srv_send((char *)"410 No such unit");
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1138 return 1;
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1139 }
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1140
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1141 if (strcmp(opt, (char *)"PUT") == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1142 for (unit = Config.units ; unit; unit = unit->next) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1143 if (strcmp(unit->uuid, param) == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1144 while (1) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1145 memset((char *)&ibuf, 0, SS_BUFSIZE);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1146 fromlen = sizeof(peeraddr_in);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1147 rlen = recvfrom(s, ibuf, sizeof(ibuf) -1, 0, (struct sockaddr *)&peeraddr_in, &fromlen);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1148 if (rlen == -1) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1149 syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno));
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1150 srv_send((char *)"518 recfrom(): %s", strerror(errno));
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1151 return 1;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1152 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1153 for (i = 0; i < strlen(ibuf); i++) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1154 if (ibuf[i] == '\n')
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1155 ibuf[i] = '\0';
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1156 if (ibuf[i] == '\r')
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1157 ibuf[i] = '\0';
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1158 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1159 for (i = strlen(ibuf) -1; i > 0; i--) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1160 if (ibuf[i] == ' ')
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1161 ibuf[i] = '\0';
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1162 else
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1163 break;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1164 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1165 if (strlen(ibuf)) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1166 if (debug) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1167 syslog(LOG_NOTICE, "recv: \"%s\"", ibuf);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1168 fprintf(stdout, "recv: \"%s\"\n", ibuf);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1169 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1170 if (strcmp(ibuf, (char *)".") == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1171 srv_send((char *)"219 Accepted Unit record");
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1172 return 0;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1173 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1174 kwd = strtok(ibuf, ",\0");
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1175 val = strtok(NULL, "\0");
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1176 if (kwd && val) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1177 /*
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1178 * Accept writable data. The client can sent just one line,
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1179 * but may also sent everything. Simply ignore things we
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1180 * don't understand.
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1181 */
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1182 if (strcmp(kwd, (char *)"NAME") == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1183 if (unit->name)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1184 free(unit->name);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1185 unit->name = xstrcpy(val);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1186
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1187 } else if (strcmp(kwd, (char *)"VOLUME") == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1188 if (sscanf(val, "%f", &fval) == 1)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1189 unit->volume = fval;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1190
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1191 } else if (strcmp(kwd, (char *)"AIR_ADDRESS") == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1192 if (unit->air_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1193 free(unit->air_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1194 unit->air_address = xstrcpy(val);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1195
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1196 } else if (strcmp(kwd, (char *)"BEER_ADDRESS") == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1197 if (unit->beer_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1198 free(unit->beer_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1199 unit->beer_address = xstrcpy(val);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1200
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1201 } else if (strcmp(kwd, (char *)"HEATER_ADDRESS") == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1202 if (unit->heater_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1203 free(unit->heater_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1204 unit->heater_address = xstrcpy(val);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1205
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1206 } else if (strcmp(kwd, (char *)"COOLER_ADDRESS") == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1207 if (unit->cooler_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1208 free(unit->cooler_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1209 unit->cooler_address = xstrcpy(val);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1210
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1211 } else if (strcmp(kwd, (char *)"FAN_ADDRESS") == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1212 if (unit->fan_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1213 free(unit->fan_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1214 unit->fan_address = xstrcpy(val);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1215
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1216 } else if (strcmp(kwd, (char *)"DOOR_ADDRESS") == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1217 if (unit->door_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1218 free(unit->door_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1219 unit->door_address = xstrcpy(val);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1220
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1221 } else if (strcmp(kwd, (char *)"MODE") == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1222 for (i = 0; i < 5; i++) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1223 if (strcmp(val, UNITMODE[i]) == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1224 unit->mode = i;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1225 break;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1226 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1227 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1228
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1229 } else if (strcmp(kwd, (char *)"FRIDGE_SET") == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1230 if (sscanf(val, "%f", &fval) == 1)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1231 unit->fridge_set = fval;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1232
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1233 } else if (strcmp(kwd, (char *)"BEER_SET") == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1234 if (sscanf(val, "%f", &fval) == 1)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1235 unit->beer_set = fval;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1236
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1237 } else if (strcmp(kwd, (char *)"PROFILE") == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1238 if (unit->profile)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1239 free(unit->profile);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1240 unit->profile = xstrcpy(val);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1241
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1242 } else if (strcmp(kwd, (char *)"PROF_STATE") == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1243 for (i = 0; i < 4; i++) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1244 if (strcmp(val, PROFSTATE[i]) == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1245 unit->prof_state = i;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1246 break;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1247 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1248 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1249
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1250 } else if (strcmp(kwd, (char *)"TEMP_SET_MIN") == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1251 if (sscanf(val, "%f", &fval) == 1)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1252 unit->temp_set_min = fval;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1253
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1254 } else if (strcmp(kwd, (char *)"TEMP_SET_MAX") == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1255 if (sscanf(val, "%f", &fval) == 1)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1256 unit->temp_set_max = fval;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1257
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1258 } else if (strcmp(kwd, (char *)"IDLE_RANGE_L") == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1259 if (sscanf(val, "%f", &fval) == 1)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1260 unit->idle_rangeL = fval;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1261
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1262 } else if (strcmp(kwd, (char *)"IDLE_RANGE_H") == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1263 if (sscanf(val, "%f", &fval) == 1)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1264 unit->idle_rangeH = fval;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1265
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1266 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1267 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1268 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1269 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1270 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1271 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1272 srv_send((char *)"440 No such device");
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1273 return 1;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1274 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1275
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1276
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1277 srv_send((char *)"502 Unknown command option");
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1278 return 1;
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1279 }
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1280
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1281
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1282
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1283 void cmd_server(void)
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1284 {
132
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
1285 char buf[SS_BUFSIZE];
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
1286 int i, rlen;
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1287 socklen_t fromlen;
68
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1288 #ifdef HAVE_WIRINGPI_H
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1289 int j;
133
345307762220 Fixed compiling on systems with wiringpi libs
Michiel Broek <mbroek@mbse.eu>
parents: 132
diff changeset
1290 char obuf[SS_BUFSIZE];
68
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1291 #endif
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1292
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1293 memset((char *)&buf, 0, SS_BUFSIZE);
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1294 fromlen = sizeof(peeraddr_in);
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1295 rlen = recvfrom(s, buf, sizeof(buf) -1, 0, (struct sockaddr *)&peeraddr_in, &fromlen);
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1296 if (rlen == -1) {
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1297 syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno));
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1298 } else {
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1299 for (i = 0; i < strlen(buf); i++) {
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1300 if (buf[i] == '\n')
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1301 buf[i] = '\0';
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1302 if (buf[i] == '\r')
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1303 buf[i] = '\0';
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1304 }
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
1305 for (i = strlen(buf) -1; i > 0; i--) {
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
1306 if (buf[i] == ' ')
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
1307 buf[i] = '\0';
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
1308 else
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
1309 break;
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
1310 }
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1311 if (strlen(buf)) {
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1312 if (debug) {
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1313 syslog(LOG_NOTICE, "recv: \"%s\"", buf);
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1314 fprintf(stdout, "recv: \"%s\"\n", buf);
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1315 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1316
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1317 /*
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1318 * Process commands from the client
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1319 */
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
1320 if (strncmp(buf, "ADD", 3) == 0) {
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
1321 if (unit_add(buf) == 0)
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
1322 wrconfig();
138
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
1323 } else if (strncmp(buf, "DEL", 3) == 0) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
1324 if (cmd_del(buf) == 0)
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
1325 wrconfig();
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
1326 } else if (strncmp(buf, "DEVICE", 6) == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
1327 if (cmd_device(buf) == 0)
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
1328 wrconfig();
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
1329 } else if (strncmp(buf, "HELP", 4) == 0) {
68
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1330 srv_send((char *)"100 Help text follows");
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1331 srv_send((char *)"Recognized commands:");
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1332 srv_send((char *)"");
132
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
1333 // 12345678901234567890123456789012345678901234567890123456789012345678901234567890
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
1334 srv_send((char *)"ADD PROFILE name Add a new profile with \"name\"");
138
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
1335 srv_send((char *)"DEL PROFILE uuid Delete profile with uuid");
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
1336 srv_send((char *)"DEVICE ADD type Add new Device type");
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1337 srv_send((char *)"DEVICE DEL uuid Delete Device by uuid");
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
1338 srv_send((char *)"DEVICE LIST List Devices");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
1339 srv_send((char *)"DEVICE GET uuid Get Device record by uuid");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
1340 srv_send((char *)"DEVICE PUT uuid Put Device record by uuid");
132
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
1341 srv_send((char *)"LCD Get LCD screen (allways 4 rows of 20 characters)");
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
1342 srv_send((char *)"LIST List all fermenter units");
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
1343 srv_send((char *)"LIST LOG List logfile data in 1 hour lines");
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
1344 srv_send((char *)"LIST PROFILES List available profiles");
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
1345 srv_send((char *)"MODE OFF|NONE|BEER|FRIDGE|PROFILE");
132
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
1346 // srv_send((char *)"PROFILE Profile status of current unit");
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
1347 srv_send((char *)"PROFILE uuid,name Profile rename");
140
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
1348 srv_send((char *)"PROFILE GETS uuid Profile get steps list");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
1349 srv_send((char *)"PROFILE PUTS uuid Profile put steps list");
132
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
1350 srv_send((char *)"SET PROFILE uuid Set unit profile");
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
1351 // srv_send((char *)"SET PROFILE start|stop|pause Profile start, stop or pause");
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
1352 srv_send((char *)"SET VOLUME val Set unit volume");
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
1353 srv_send((char *)"UNIT uuid Select unit by uuid");
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1354 srv_send((char *)"UNIT ADD name Add a new unit with name");
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1355 srv_send((char *)"UNIT DEL uuid Delete Unit by uuid");
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1356 srv_send((char *)"UNIT LIST List Units");
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1357 srv_send((char *)"UNIT GET uuid Get Unit record by uuid");
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1358 srv_send((char *)"UNIT PUT uuid Put Unit record by uuid");
68
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1359 srv_send((char *)".");
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1360 } else if (strncmp(buf, "LCD", 3) == 0) {
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1361 #ifdef HAVE_WIRINGPI_H
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1362 srv_send((char *)"201 information follows");
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1363 for (j = 0; j < 4; j++) {
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1364 sprintf(obuf, " ");
70
920eface3ec5 Small fix for LCD output
Michiel Broek <mbroek@mbse.eu>
parents: 68
diff changeset
1365 obuf[20] = '\0';
68
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1366 for (i = 0; i < 20; i++)
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1367 obuf[i] = lcdbuf[lcdHandle][i][j];
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1368 srv_send(obuf);
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1369 }
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1370 srv_send((char *)".");
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1371 #else
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1372 srv_send((char *)"403 LCD not available");
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1373 #endif
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
1374 } else if (strncmp(buf, "LIST", 4) == 0) {
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
1375 cmd_list(buf);
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
1376 } else if (strncmp(buf, "MODE", 4) == 0) {
156
5fb74d89f571 Update LCD even when unit is off
Michiel Broek <mbroek@mbse.eu>
parents: 155
diff changeset
1377 if (cmd_mode(buf) == 0)
5fb74d89f571 Update LCD even when unit is off
Michiel Broek <mbroek@mbse.eu>
parents: 155
diff changeset
1378 wrconfig();
132
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
1379 } else if (strncmp(buf, "PROFILE", 7) == 0) {
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
1380 if (cmd_profile(buf) == 0)
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
1381 wrconfig();
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
1382 } else if (strncmp(buf, "SET", 3) == 0) {
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
1383 if (cmd_set(buf) == 0)
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
1384 wrconfig();
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1385 } else if (strncmp(buf, "UNIT", 4) == 0) {
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1386 if (cmd_unit(buf) == 0)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1387 wrconfig();
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1388 } else {
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1389 if (debug)
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1390 fprintf(stdout, "unknown command \"%s\"\n", buf);
132
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
1391 srv_send((char *)"500 Unknown command");
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1392 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1393 }
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1394 }
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1395
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1396 close(s);
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1397 }
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1398
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1399
132
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
1400
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 62
diff changeset
1401 #ifdef HAVE_WIRINGPI_H
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1402 PI_THREAD (my_server_loop)
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 62
diff changeset
1403 #else
74
879bd09e2b96 Reinstalled threads
Michiel Broek <mbroek@mbse.eu>
parents: 71
diff changeset
1404 void *my_server_loop(void *threadid)
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 62
diff changeset
1405 #endif
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1406 {
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1407 socklen_t addrlen;
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1408 int optval = 1;
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1409
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1410 syslog(LOG_NOTICE, "Thread my_server_loop started");
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1411 if (debug)
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1412 fprintf(stdout, "Thread my_server_loop started\n");
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1413
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1414 memset((char *)&myaddr_in, 0, sizeof(struct sockaddr_in));
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1415 memset((char *)&peeraddr_in, 0, sizeof(struct sockaddr_in));
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1416 myaddr_in.sin_family = AF_INET;
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1417 myaddr_in.sin_addr.s_addr = INADDR_ANY;
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1418 myaddr_in.sin_port = htons(Config.my_port);
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1419
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1420 ls = socket(AF_INET, SOCK_STREAM, 0);
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1421 if (ls == -1) {
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1422 syslog(LOG_NOTICE, "Can't create listen socket: %s", strerror(errno));
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1423 fprintf(stderr, "Can't create listen socket: %s\n", strerror(errno));
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1424 return 0;
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1425 }
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1426
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1427 if (setsockopt(ls, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(optval)) == -1) {
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1428 syslog(LOG_NOTICE, "Can't setsockopt SO_KEEPALIVE socket: %s", strerror(errno));
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1429 close(ls);
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1430 return 0;
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1431 }
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1432
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1433 if (setsockopt(ls, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) == -1) {
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1434 syslog(LOG_NOTICE, "Can't setsockopt SO_REUSEADDR socket: %s", strerror(errno));
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1435 close(ls);
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 62
diff changeset
1436 return 0;
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1437 }
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1438
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1439 if (bind(ls, (struct sockaddr *)&myaddr_in, sizeof(struct sockaddr_in)) == -1) {
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1440 syslog(LOG_NOTICE, "Can't bind to listen socket: %s", strerror(errno));
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1441 close(ls);
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 62
diff changeset
1442 return 0;
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1443 }
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1444
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1445 if (listen(ls, 5) == -1) {
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1446 syslog(LOG_NOTICE, "Can't listen on listen socket: %s", strerror(errno));
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1447 close(ls);
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 62
diff changeset
1448 return 0;
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1449 }
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1450
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1451 syslog(LOG_NOTICE, "listen socket created %d", ls);
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1452 if (debug)
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1453 fprintf(stdout, "listen socket created %d\n", ls);
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1454
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1455
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1456 /*
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1457 * Loop forever until the external shutdown variable is set.
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1458 */
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1459 for (;;) {
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1460
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1461 addrlen = sizeof(struct sockaddr_in);
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1462 /*
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1463 * This call will block until a new connection
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1464 * arrives. Then it will return the address of
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1465 * the connecting peer, and a new socket
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1466 * descriptor, s, for that connection.
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1467 */
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1468 s = accept(ls, (struct sockaddr *)&peeraddr_in, &addrlen);
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1469 if (s == -1) {
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1470 syslog(LOG_NOTICE, "my_server_loop accept failed %s", strerror(errno));
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1471 if (debug)
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1472 fprintf(stdout, "my_server_loop accept failed %s\n", strerror(errno));
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1473 return 0;
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1474 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1475
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1476 cmd_server();
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1477
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1478 if (my_shutdown) {
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1479 syslog(LOG_NOTICE, "Thread my_server_loop stopped");
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1480 if (debug)
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1481 fprintf(stdout, "Thread my_server_loop stopped\n");
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1482 return 0;
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1483 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1484
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1485 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1486 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1487
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1488

mercurial