Thu, 31 Jul 2014 17:44:50 +0200
Added device configuration
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 | 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 | 26 | #include "server.h" |
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 | 37 | extern sys_config Config; |
81 | 38 | extern const char UNITMODE[5][8]; |
95 | 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]; |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
41 | |
43 | 42 | int s; /* connected socket */ |
43 | int ls; /* listen socket */ | |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
44 | |
43 | 45 | struct sockaddr_in myaddr_in; /* for local socket address */ |
46 | struct sockaddr_in peeraddr_in; /* for peer socket address */ | |
47 | ||
48 | struct hostent *hp; | |
49 | ||
50 | #define SS_BUFSIZE 1024 | |
51 | #define SS_TIMEOUT 300 | |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
52 | |
48 | 53 | |
95 | 54 | float cs_heatEstimator = 0.2; |
55 | float cs_coolEstimator = 5; | |
48 | 56 | float cv_beerDiff = 0.0; |
57 | ||
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
58 | |
46
000399c64d3f
More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
59 | |
43 | 60 | /* |
61 | * Send message to client | |
62 | */ | |
63 | int srv_send(const char *format, ...) | |
64 | { | |
65 | char out[SS_BUFSIZE]; | |
66 | va_list va_ptr; | |
67 | ||
68 | if (s == -1) | |
69 | return -1; | |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
70 | |
43 | 71 | va_start(va_ptr, format); |
72 | vsnprintf(out, SS_BUFSIZE-1, format, va_ptr); | |
73 | va_end(va_ptr); | |
74 | ||
48 | 75 | if (debug) { |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
76 | syslog(LOG_NOTICE, "send: \"%s\"", out); |
45
053c4657105f
Mirror LCD display on the webpage works
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
77 | fprintf(stdout, "send: \"%s\"\n", out); |
48 | 78 | } |
44 | 79 | |
43 | 80 | if (send(s, out, strlen(out), 0) != strlen(out)) { |
81 | syslog(LOG_NOTICE, "srv_send failed"); | |
82 | return -1; | |
83 | } | |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
84 | |
43 | 85 | if (send(s, (char *)"\r\n", 2, 0) != 2) { |
86 | syslog(LOG_NOTICE, "srv_send failed"); | |
87 | return -1; | |
88 | } | |
89 | ||
90 | return 0; | |
91 | } | |
92 | ||
93 | ||
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
94 | |
88 | 95 | /* |
92 | 96 | * ADD PROFILE name |
97 | * ADD UNIT name | |
88 | 98 | */ |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
99 | int unit_add(char *buf) |
43 | 100 | { |
92 | 101 | units_list *unit, *tmpu; |
102 | profiles_list *profile, *tmpp; | |
103 | uuid_t uu; | |
104 | char *opt, *param; | |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
105 | |
92 | 106 | opt = strtok(buf, " \0"); |
107 | opt = strtok(NULL, " \0"); | |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
108 | if (opt == NULL) { |
92 | 109 | srv_send((char *)"501 Subcommand missing"); |
110 | return 1; | |
111 | } | |
112 | ||
113 | param = strtok(NULL, "\0"); | |
114 | if (param == NULL) { | |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
115 | srv_send((char *)"501 Parameter missing"); |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
116 | return 1; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
117 | } |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
118 | |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
119 | if (debug) |
92 | 120 | 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
|
121 | |
92 | 122 | if (strcmp(opt, (char *)"PROFILE") == 0) { |
123 | profile = (profiles_list *)malloc(sizeof(profiles_list)); | |
124 | profile->next = NULL; | |
125 | profile->version = 1; | |
126 | profile->uuid = malloc(37); | |
127 | uuid_generate(uu); | |
128 | uuid_unparse(uu, profile->uuid); | |
129 | profile->name = xstrcpy(param); | |
138 | 130 | profile->busy = 0; |
92 | 131 | profile->steps = NULL; |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
132 | |
92 | 133 | if (Config.profiles == NULL) { |
134 | Config.profiles = profile; | |
135 | } else { | |
136 | for (tmpp = Config.profiles; tmpp; tmpp = tmpp->next) { | |
137 | if (tmpp->next == NULL) { | |
138 | tmpp->next = profile; | |
139 | break; | |
140 | } | |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
141 | } |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
142 | } |
92 | 143 | |
144 | syslog(LOG_NOTICE, "Profile \"%s\" with uuid %s added", param, profile->uuid); | |
145 | srv_send((char *)"211 Profile \"%s\" with uuid %s added", param, profile->uuid); | |
146 | return 0; | |
147 | ||
148 | } else if (strcmp(opt, (char *)"UNIT") == 0) { | |
149 | unit = (units_list *)malloc(sizeof(units_list)); | |
150 | unit->next = NULL; | |
151 | unit->version = 1; | |
152 | unit->uuid = malloc(37); | |
153 | uuid_generate(uu); | |
154 | uuid_unparse(uu, 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
|
155 | 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
|
156 | free(current_unit); |
528dc0bb81ab
Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents:
125
diff
changeset
|
157 | current_unit = xstrcpy(unit->uuid); |
92 | 158 | unit->name = xstrcpy(param); |
159 | unit->air_address = unit->beer_address = unit->io1_address = unit->io2_address = unit->profile = NULL; | |
160 | unit->volume = 0.0; | |
101
1302abe92eb1
Made temperature sensors working in the units
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
161 | unit->air_state = unit->beer_state = 1; |
92 | 162 | unit->heater_available = unit->cooler_available = unit->fan_available = FALSE; |
101
1302abe92eb1
Made temperature sensors working in the units
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
163 | unit->air_temperature = unit->beer_temperature = 20000; |
1302abe92eb1
Made temperature sensors working in the units
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
164 | unit->beer_set = unit->fridge_set = 20.0; |
92 | 165 | unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->mode = unit->prof_state = 0; |
166 | unit->temp_set_min = 1.0; | |
167 | unit->temp_set_max = 30.0; | |
168 | unit->idle_rangeH = 1.0; | |
169 | unit->idle_rangeL = -1.0; | |
170 | unit->prof_started = (time_t)0; | |
171 | ||
172 | if (Config.units == NULL) { | |
173 | Config.units = unit; | |
174 | } else { | |
175 | for (tmpu = Config.units; tmpu; tmpu = tmpu->next) { | |
176 | if (tmpu->next == NULL) { | |
177 | tmpu->next = unit; | |
178 | break; | |
179 | } | |
180 | } | |
181 | } | |
182 | ||
131
528dc0bb81ab
Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents:
125
diff
changeset
|
183 | syslog(LOG_NOTICE, "Unit with uuid %s added", unit->uuid); |
528dc0bb81ab
Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents:
125
diff
changeset
|
184 | srv_send((char *)"211 Unit with uuid %s added", unit->uuid); |
92 | 185 | return 0; |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
186 | } |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
187 | |
92 | 188 | srv_send((char *)"502 Unknown command option"); |
189 | return 1; | |
43 | 190 | } |
191 | ||
192 | ||
193 | ||
138 | 194 | |
195 | void delete_Profile(char *uuid) | |
196 | { | |
197 | profiles_list *current = Config.profiles; | |
198 | profiles_list *previous = NULL; | |
199 | prof_step *step, *olds; | |
200 | ||
201 | ||
202 | while (current) { | |
203 | if (strcmp(current->uuid, uuid) == 0) { | |
204 | if (previous == NULL) { | |
205 | Config.profiles = current->next; | |
206 | free(current->uuid); | |
207 | current->uuid = NULL; | |
208 | free(current->name); | |
209 | current->name = NULL; | |
210 | if (current->steps) { | |
211 | for (step = current->steps; step; step = olds) { | |
212 | olds = step->next; | |
213 | free(step); | |
214 | } | |
215 | current->steps = NULL; | |
216 | } | |
217 | free(current); | |
218 | return; | |
219 | } else { | |
220 | free(current->uuid); | |
221 | current->uuid = NULL; | |
222 | free(current->name); | |
223 | current->name = NULL; | |
224 | if (current->steps) { | |
225 | for (step = current->steps; step; step = olds) { | |
226 | olds = step->next; | |
227 | free(step); | |
228 | } | |
229 | current->steps = NULL; | |
230 | } | |
231 | previous->next = current->next; | |
232 | free(current); | |
233 | current = previous->next; | |
234 | return; | |
235 | } | |
236 | } else { | |
237 | previous = current; | |
238 | current = current->next; | |
239 | } | |
240 | } | |
241 | } | |
242 | ||
243 | ||
244 | ||
245 | /* | |
246 | * DEL PROFILE | |
247 | */ | |
248 | int cmd_del(char *buf) | |
249 | { | |
250 | char *opt, *param; | |
251 | ||
252 | opt = strtok(buf, " \0"); | |
253 | opt = strtok(NULL, " \0"); | |
254 | if (opt == NULL) { | |
255 | srv_send((char *)"501 Subcommand missing"); | |
256 | return 1; | |
257 | } | |
258 | ||
259 | param = strtok(NULL, "\0"); | |
260 | if (param == NULL) { | |
261 | srv_send((char *)"501 Parameter missing"); | |
262 | return 1; | |
263 | } | |
264 | ||
265 | if (debug) | |
266 | fprintf(stdout, "opt: '%s' param: '%s'\n", MBSE_SS(opt), MBSE_SS(param)); | |
267 | ||
268 | if (strcmp(opt, (char *)"PROFILE") == 0) { | |
269 | delete_Profile(param); | |
270 | srv_send((char *)"211 Profile %s deleted", param); | |
271 | return 0; | |
272 | } | |
273 | ||
274 | srv_send((char *)"502 Unknown command option"); | |
275 | return 1; | |
276 | } | |
277 | ||
278 | ||
279 | ||
81 | 280 | /* |
157
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
281 | * GET AIR uuid |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
282 | * GET BEER uuid |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
283 | * GET TARGET uuid |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
284 | */ |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
285 | int cmd_get(char *buf) |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
286 | { |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
287 | char *opt, *uuid; |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
288 | units_list *unit; |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
289 | |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
290 | opt = strtok(buf, " \0"); |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
291 | opt = strtok(NULL, " \0"); |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
292 | uuid = strtok(NULL, "\0"); |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
293 | |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
294 | if (uuid == NULL) { |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
295 | srv_send((char *)"502 Missing command option"); |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
296 | return 1; |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
297 | } |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
298 | |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
299 | for (unit = Config.units; unit; unit = unit->next) { |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
300 | if (strcmp(uuid, unit->uuid) == 0) { |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
301 | |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
302 | if (strcmp(opt, (char *)"AIR") == 0) { |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
303 | if (unit->air_state == 0) |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
304 | srv_send((char *)"215 AIR,%.3f", unit->air_temperature); |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
305 | else |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
306 | srv_send((char *)"215 AIR,NA"); |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
307 | return 0; |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
308 | } else if (strcmp(opt, (char *)"BEER") == 0) { |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
309 | if (unit->beer_state == 0) |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
310 | srv_send((char *)"215 BEER,%.3f", unit->beer_temperature); |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
311 | else |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
312 | srv_send((char *)"215 BEER,NA"); |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
313 | return 0; |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
314 | } else if (strcmp(opt, (char *)"TARGET") == 0) { |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
315 | if (unit->mode == UNITMODE_BEER) { |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
316 | srv_send((char *)"215 TARGET,%.3f", unit->beer_set); |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
317 | } else if (unit->mode == UNITMODE_FRIDGE) { |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
318 | srv_send((char *)"215 TARGET,%.3f", unit->fridge_set); |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
319 | } else if (unit->mode == UNITMODE_PROFILE) { |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
320 | srv_send((char *)"215 TARGET,%.3f", unit->prof_target); |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
321 | } else { |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
322 | srv_send((char *)"215 TARGET,NA"); |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
323 | } |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
324 | return 0; |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
325 | } |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
326 | |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
327 | srv_send((char *)"502 Unknown command option"); |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
328 | return 1; |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
329 | } |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
330 | } |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
331 | |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
332 | srv_send((char *)"440 No such profile"); |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
333 | return 1; |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
334 | } |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
335 | |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
336 | |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
337 | |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
338 | /* |
81 | 339 | * LIST |
84 | 340 | * LIST BUS |
120 | 341 | * LIST LOG |
84 | 342 | * LIST PROFILES |
343 | * LIST UNIT | |
81 | 344 | */ |
345 | int cmd_list(char *buf) | |
346 | { | |
120 | 347 | char *opt, *filename, *p, q[2], buffer[256]; |
84 | 348 | units_list *unit; |
92 | 349 | profiles_list *profile; |
124
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
350 | prof_step *step; |
131
528dc0bb81ab
Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents:
125
diff
changeset
|
351 | int j, ref; |
84 | 352 | DIR *fd; |
120 | 353 | FILE *fp; |
84 | 354 | struct dirent *de; |
81 | 355 | |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
356 | opt = strtok(buf, " \0"); |
92 | 357 | opt = strtok(NULL, "\0"); |
84 | 358 | |
81 | 359 | if (opt == NULL) { |
92 | 360 | /* |
361 | * Default, list available units | |
362 | */ | |
81 | 363 | srv_send((char *)"212 Fermenter list follows:"); |
364 | 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
|
365 | srv_send((char *)"%s,%s,%s", unit->uuid, unit->name, UNITMODE[unit->mode]); |
81 | 366 | } |
367 | srv_send((char *)"."); | |
92 | 368 | return 0; |
369 | ||
84 | 370 | } else if (strcmp(opt, (char *)"BUS") == 0) { |
86
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
371 | /* |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
372 | * 1-wire bus |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
373 | */ |
84 | 374 | if ((fd = opendir((char *)"/sys/bus/w1/devices"))) { |
86
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
375 | srv_send((char *)"212 1-wire bus devices:"); |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
376 | while ((de = readdir(fd))) { |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
377 | if (de->d_name[0] != '.') { |
124
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
378 | ref = 0; |
86
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
379 | if (strncmp(de->d_name, (char *)"w1", 2) == 0) { |
124
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
380 | srv_send((char *)"%s,0,NA,System device", de->d_name); |
86
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
381 | } else if (strncmp(de->d_name, (char *)"10", 2) == 0) { |
125 | 382 | if (Config.air_address && (strcmp(de->d_name, Config.air_address) == 0)) |
124
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
383 | ref++; |
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
384 | for (unit = Config.units; unit; unit = unit->next) { |
125 | 385 | if (unit->air_address && (strcmp(de->d_name, unit->air_address) == 0)) |
124
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
386 | ref++; |
125 | 387 | if (unit->beer_address && (strcmp(de->d_name, unit->beer_address) == 0)) |
124
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
388 | ref++; |
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
389 | } |
125 | 390 | srv_send((char *)"%s,%d,18S20,Digital thermometer", de->d_name, ref); |
86
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
391 | } else if (strncmp(de->d_name, (char *)"28", 2) == 0) { |
125 | 392 | if (Config.air_address && (strcmp(de->d_name, Config.air_address) == 0)) |
124
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
393 | ref++; |
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
394 | for (unit = Config.units; unit; unit = unit->next) { |
125 | 395 | if (unit->air_address && (strcmp(de->d_name, unit->air_address) == 0)) |
124
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
396 | ref++; |
125 | 397 | if (unit->beer_address && (strcmp(de->d_name, unit->beer_address) == 0)) |
124
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
398 | ref++; |
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
399 | } |
125 | 400 | srv_send((char *)"%s,%d,18B20,Digital thermometer", de->d_name, ref); |
86
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
401 | } else if (strncmp(de->d_name, (char *)"29", 2) == 0) { |
124
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
402 | for (unit = Config.units; unit; unit = unit->next) { |
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
403 | if (unit->io1_address && (strncmp((char *)"29", unit->io1_address, 2) == 0)) |
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
404 | ref++; |
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
405 | if (unit->io2_address && (strncmp((char *)"29", unit->io2_address, 2) == 0)) |
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
406 | ref++; |
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
407 | } |
125 | 408 | srv_send((char *)"%s,%d,2408,8 Channel addressable switch/LCD", de->d_name, ref); |
86
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
409 | } else if (strncmp(de->d_name, (char *)"3a", 2) == 0) { |
124
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
410 | for (unit = Config.units; unit; unit = unit->next) { |
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
411 | if (unit->io1_address && (strncmp((char *)"3a", unit->io1_address, 2) == 0)) |
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
412 | ref++; |
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
413 | if (unit->io2_address && (strncmp((char *)"3a", unit->io2_address, 2) == 0)) |
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
414 | ref++; |
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
415 | } |
158 | 416 | srv_send((char *)"%s,%d,2413,Dual channel addressable switch", de->d_name, ref); |
86
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
417 | } else { |
124
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
418 | srv_send((char *)"%s,0,NA,Unknown device", de->d_name); |
84 | 419 | } |
420 | } | |
86
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
421 | } |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
422 | srv_send((char *)"."); |
84 | 423 | closedir(fd); |
92 | 424 | return 0; |
84 | 425 | } else { |
426 | srv_send((char *)"503 directory /sys/bus/w1/devices: %s", strerror(errno)); | |
92 | 427 | return 1; |
84 | 428 | } |
92 | 429 | |
120 | 430 | } else if (strcmp(opt, (char *)"LOG") == 0) { |
431 | /* | |
432 | * Get the logfile data and emit only one line per hour. | |
433 | */ | |
131
528dc0bb81ab
Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents:
125
diff
changeset
|
434 | if (current_unit == NULL) { |
120 | 435 | srv_send((char *)"401 No fermenter unit selected"); |
436 | return 1; | |
437 | } | |
438 | ||
439 | q[0] = q[1] = 'a'; | |
440 | 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
|
441 | if (strcmp(current_unit, unit->uuid) == 0) |
120 | 442 | break; |
443 | } | |
444 | ||
445 | srv_send((char *)"212 Logfile list follows:"); | |
446 | if (getenv((char *)"USER") == NULL) { | |
447 | filename = xstrcpy((char *)"/root"); | |
448 | } else { | |
449 | filename = xstrcpy(getenv((char *)"HOME")); | |
450 | } | |
451 | filename = xstrcat(filename, (char *)"/.thermferm/log/"); | |
452 | filename = xstrcat(filename, unit->name); | |
453 | filename = xstrcat(filename, (char *)".log"); | |
454 | if ((fp = fopen(filename, "r"))) { | |
455 | while (fgets(buffer, sizeof(buffer)-1, fp) != NULL) { | |
456 | buffer[strlen(buffer) -1] = '\0'; | |
457 | p = buffer + 17; | |
458 | if (strncmp(p, (char *)"Mode", 4)) { | |
459 | if ((q[0] != buffer[11]) || (q[1] != buffer[12])) { | |
460 | q[0] = buffer[11]; | |
461 | q[1] = buffer[12]; | |
462 | srv_send(buffer); | |
463 | } | |
464 | } | |
465 | } | |
466 | } | |
467 | free(filename); | |
468 | filename = NULL; | |
469 | srv_send((char *)"."); | |
470 | return 0; | |
471 | ||
84 | 472 | } 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
|
473 | /* |
92 | 474 | * Fermenting profiles |
86
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
475 | */ |
92 | 476 | srv_send((char *)"212 profiles:"); |
477 | 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
|
478 | j = 0; |
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
479 | 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
|
480 | j++; |
136
264e5ee5abfc
Profiles now have a busy state
Michiel Broek <mbroek@mbse.eu>
parents:
133
diff
changeset
|
481 | 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
|
482 | } |
92 | 483 | srv_send((char *)"."); |
484 | return 0; | |
485 | ||
84 | 486 | } else if (strcmp(opt, (char *)"UNIT") == 0) { |
86
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
487 | /* |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
488 | * List configured and selected fermenter unit |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
489 | */ |
131
528dc0bb81ab
Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents:
125
diff
changeset
|
490 | if (current_unit == NULL) { |
84 | 491 | srv_send((char *)"401 No fermenter unit selected"); |
92 | 492 | return 1; |
493 | } | |
494 | ||
131
528dc0bb81ab
Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents:
125
diff
changeset
|
495 | srv_send((char *)"213 Unit %s listing follows:", current_unit); |
92 | 496 | 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
|
497 | if (strcmp(current_unit, unit->uuid) == 0) { |
100 | 498 | srv_send((char *)"NAME,%s", unit->name); |
499 | srv_send((char *)"UUID,%s", unit->uuid); | |
92 | 500 | if (unit->air_address) { |
100 | 501 | srv_send((char *)"AIR_ADDRESS,%s", unit->air_address); |
101
1302abe92eb1
Made temperature sensors working in the units
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
502 | srv_send((char *)"AIR_STATE,%s", TEMPSTATE[unit->air_state]); |
1302abe92eb1
Made temperature sensors working in the units
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
503 | srv_send((char *)"AIR_TEMPERATURE,%.3f", unit->air_temperature / 1000.0); |
92 | 504 | } |
505 | if (unit->beer_address) { | |
100 | 506 | srv_send((char *)"BEER_ADDRESS,%s", unit->beer_address); |
101
1302abe92eb1
Made temperature sensors working in the units
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
507 | srv_send((char *)"BEER_STATE,%s", TEMPSTATE[unit->beer_state]); |
1302abe92eb1
Made temperature sensors working in the units
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
508 | srv_send((char *)"BEER_TEMPERATURE,%.3f", unit->beer_temperature / 1000.0); |
92 | 509 | } |
510 | if (unit->io1_address) { | |
100 | 511 | srv_send((char *)"IO1_ADDRESS,%s", unit->io1_address); |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
512 | } |
92 | 513 | if (unit->io2_address) { |
100 | 514 | srv_send((char *)"IO2_ADDRESS,%s", unit->io2_address); |
92 | 515 | } |
516 | if (unit->heater_available) { | |
100 | 517 | srv_send((char *)"HEATER_AVAILABLE,%s", unit->heater_available); |
92 | 518 | } |
519 | if (unit->cooler_available) { | |
100 | 520 | srv_send((char *)"COOLER_AVAILABLE,%s", unit->cooler_available); |
92 | 521 | } |
522 | if (unit->fan_available) { | |
100 | 523 | srv_send((char *)"FAN_AVAILABLE,%s", unit->fan_available); |
92 | 524 | } |
100 | 525 | srv_send((char *)"MODE,%s", UNITMODE[unit->mode]); |
526 | srv_send((char *)"FRIDGE_SET,%.1f", unit->fridge_set); | |
527 | srv_send((char *)"BEER_SET,%.1f", unit->beer_set); | |
92 | 528 | if (unit->profile) { |
100 | 529 | srv_send((char *)"PROFILE,%s", unit->profile); |
92 | 530 | } |
100 | 531 | srv_send((char *)"TEMP_SET_MIN,%.1f", unit->temp_set_min); |
532 | srv_send((char *)"TEMP_SET_MAX,%.1f", unit->temp_set_max); | |
533 | srv_send((char *)"IDLE_RANGE_L,%.1f", unit->idle_rangeL); | |
534 | srv_send((char *)"IDLE_RANGE_H,%.1f", unit->idle_rangeH); | |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
535 | } |
84 | 536 | } |
92 | 537 | srv_send((char *)"."); |
538 | return 0; | |
81 | 539 | } |
540 | ||
92 | 541 | srv_send((char *)"502 Unknown command option"); |
542 | return 1; | |
81 | 543 | } |
544 | ||
545 | ||
546 | ||
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
547 | /* |
88 | 548 | * Set new operating mode |
549 | * MODE OFF|NONE|BEER|FRIDGE|PROFILE | |
550 | */ | |
551 | int cmd_mode(char *buf) | |
552 | { | |
155
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
553 | char *opt; |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
554 | units_list *unit; |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
555 | |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
556 | opt = strtok(buf, " \0"); |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
557 | opt = strtok(NULL, "\0"); |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
558 | |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
559 | if (opt == NULL) { |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
560 | 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
|
561 | return 1; |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
562 | } |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
563 | |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
564 | if (current_unit == NULL) { |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
565 | 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
|
566 | return 1; |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
567 | } |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
568 | 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
|
569 | 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
|
570 | break; |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
571 | } |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
572 | |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
573 | if (strcmp(opt, (char *)"OFF") == 0) { |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
574 | if (unit->mode != UNITMODE_OFF) { |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
575 | unit->mode = UNITMODE_OFF; |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
576 | 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
|
577 | } |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
578 | 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
|
579 | return 0; |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
580 | |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
581 | } 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
|
582 | if (unit->mode != UNITMODE_NONE) { |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
583 | unit->mode = UNITMODE_NONE; |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
584 | 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
|
585 | initlog(unit->name); |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
586 | } |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
587 | 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
|
588 | return 0; |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
589 | |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
590 | } 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
|
591 | |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
592 | } 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
|
593 | |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
594 | } 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
|
595 | |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
596 | } |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
597 | |
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
140
diff
changeset
|
598 | srv_send((char *)"502 Unknown command option"); |
88 | 599 | return 1; |
600 | } | |
601 | ||
602 | ||
603 | ||
604 | /* | |
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
|
605 | * 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
|
606 | * PROFILE uuid,name Rename profile name |
140
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
607 | * PROFILE GETS uuid Get profile steps list |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
608 | * 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
|
609 | */ |
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
|
610 | 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
|
611 | { |
140
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
612 | char ibuf[SS_BUFSIZE], *sstep, *rest, *targ; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
613 | int i, rlen, istep, irest; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
614 | float ftarg; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
615 | 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
|
616 | 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
|
617 | profiles_list *profile; |
140
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
618 | 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
|
619 | 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
|
620 | |
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
|
621 | opt = strtok(buf, " \0"); |
140
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
622 | 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
|
623 | |
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
|
624 | 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
|
625 | /* |
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
|
626 | * 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
|
627 | */ |
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
|
628 | 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
|
629 | 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
|
630 | 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
|
631 | } |
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
|
632 | 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
|
633 | 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
|
634 | 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
|
635 | } |
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
|
636 | |
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
|
637 | 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
|
638 | 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
|
639 | 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
|
640 | } |
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
|
641 | 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
|
642 | 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
|
643 | 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
|
644 | } |
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
|
645 | 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
|
646 | |
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
|
647 | |
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
|
648 | 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
|
649 | 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
|
650 | |
140
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
651 | } else if (strcmp(opt, (char *)"GETS") == 0) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
652 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
653 | uuid = strtok(NULL, "\0\n\r"); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
654 | if (uuid == NULL) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
655 | srv_send((char *)"502 Unknown command option"); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
656 | return 1; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
657 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
658 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
659 | for (profile = Config.profiles; profile; profile = profile->next) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
660 | if (strcmp(profile->uuid, uuid) == 0) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
661 | srv_send((char *)"215 Profile steps follow:"); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
662 | for (step = profile->steps; step; step = step->next) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
663 | 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
|
664 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
665 | srv_send((char *)"."); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
666 | return 1; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
667 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
668 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
669 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
670 | srv_send((char *)"440 No such profile"); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
671 | return 1; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
672 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
673 | } else if (strcmp(opt, (char *)"PUTS") == 0) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
674 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
675 | uuid = strtok(NULL, "\0\n\r"); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
676 | if (uuid == NULL) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
677 | srv_send((char *)"502 Unknown command option"); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
678 | return 1; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
679 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
680 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
681 | for (profile = Config.profiles; profile; profile = profile->next) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
682 | if (strcmp(profile->uuid, uuid) == 0) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
683 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
684 | fprintf(stdout, "profile found\n"); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
685 | if (profile->steps) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
686 | for (step = profile->steps; step; step = olds) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
687 | olds = step->next; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
688 | free(step); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
689 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
690 | profile->steps = NULL; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
691 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
692 | fprintf(stdout, "profile cleared\n"); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
693 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
694 | while (1) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
695 | memset((char *)&ibuf, 0, SS_BUFSIZE); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
696 | fromlen = sizeof(peeraddr_in); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
697 | 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
|
698 | if (rlen == -1) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
699 | syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno)); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
700 | srv_send((char *)"518 recfrom(): %s", strerror(errno)); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
701 | return 1; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
702 | } else { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
703 | for (i = 0; i < strlen(ibuf); i++) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
704 | if (ibuf[i] == '\n') |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
705 | ibuf[i] = '\0'; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
706 | if (ibuf[i] == '\r') |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
707 | ibuf[i] = '\0'; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
708 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
709 | for (i = strlen(ibuf) -1; i > 0; i--) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
710 | if (ibuf[i] == ' ') |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
711 | ibuf[i] = '\0'; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
712 | else |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
713 | break; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
714 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
715 | if (strlen(ibuf)) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
716 | if (debug) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
717 | syslog(LOG_NOTICE, "recv: \"%s\"", ibuf); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
718 | fprintf(stdout, "recv: \"%s\"\n", ibuf); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
719 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
720 | if (strcmp(ibuf, (char *)".") == 0) { |
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 | srv_send((char *)"219 Accepted profile steps"); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
723 | return 0; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
724 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
725 | sstep = strtok(ibuf, ",\0"); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
726 | rest = strtok(NULL, ",\0"); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
727 | targ = strtok(NULL, "\0"); |
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 | if ((sscanf(sstep, "%d", &istep) == 1) && |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
730 | (sscanf(rest, "%d", &irest) == 1) && |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
731 | (sscanf(targ, "%f", &ftarg) == 1)) { |
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 | step = (prof_step *)malloc(sizeof(prof_step)); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
734 | step->next = NULL; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
735 | step->version = 1; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
736 | step->steptime = istep; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
737 | step->resttime = irest; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
738 | step->target = ftarg; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
739 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
740 | if (profile->steps == NULL) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
741 | profile->steps = step; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
742 | } else { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
743 | for (olds = profile->steps; olds; olds = olds->next) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
744 | if (olds->next == NULL) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
745 | olds->next = step; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
746 | break; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
747 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
748 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
749 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
750 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
751 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
752 | fprintf(stdout, "this was data\n"); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
753 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
754 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
755 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
756 | } |
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 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
759 | srv_send((char *)"440 No such profile"); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
760 | return 1; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
761 | |
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
|
762 | } 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
|
763 | /* |
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
|
764 | * 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
|
765 | */ |
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
|
766 | 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
|
767 | 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
|
768 | 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
|
769 | 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
|
770 | 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
|
771 | 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
|
772 | 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
|
773 | 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
|
774 | 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
|
775 | 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
|
776 | 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
|
777 | } |
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
|
778 | } |
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
|
779 | 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
|
780 | 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
|
781 | } |
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
|
782 | |
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
|
783 | 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
|
784 | 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
|
785 | } |
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
|
786 | |
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
|
787 | |
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
|
788 | |
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
|
789 | /* |
92 | 790 | * SET BEER float |
791 | * SET FRIDGE float | |
792 | * SET VOLUME float | |
793 | * SET IDLE_LOW float | |
794 | * SET IDLE_HIGH float | |
795 | * SET TEMP_MIN float | |
796 | * SET TEMP_MAX float | |
797 | * SET NAME string | |
798 | * SET PROFILE string | |
88 | 799 | */ |
800 | int cmd_set(char *buf) | |
801 | { | |
802 | char *opt, *param; | |
803 | 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
|
804 | 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
|
805 | int rc; |
88 | 806 | float fval; |
807 | ||
808 | opt = strtok(buf, " \0"); | |
809 | opt = strtok(NULL, " \0"); | |
810 | if (opt == NULL) { | |
811 | srv_send((char *)"501 Subcommand missing"); | |
812 | return 1; | |
813 | } | |
814 | ||
815 | param = strtok(NULL, "\0"); | |
816 | if (param == NULL) { | |
817 | srv_send((char *)"501 Parameter missing"); | |
818 | return 1; | |
819 | } | |
820 | ||
821 | rc = sscanf(param, "%f", &fval); | |
822 | ||
823 | if (debug) | |
824 | fprintf(stdout, "opt='%s' param='%s' rc=%d fval=%.1f\n", opt, param, rc, fval); | |
825 | ||
826 | /* | |
827 | * Commands below need a selected unit | |
828 | */ | |
131
528dc0bb81ab
Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents:
125
diff
changeset
|
829 | if (current_unit == NULL) { |
88 | 830 | srv_send((char *)"401 No fermenter unit selected"); |
831 | return 1; | |
832 | } | |
833 | ||
834 | 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
|
835 | if (strcmp(current_unit, unit->uuid) == 0) |
88 | 836 | break; |
837 | } | |
838 | ||
839 | /* | |
840 | * If a valid parameter float value | |
841 | */ | |
842 | if (rc == 1) { | |
843 | if (strcmp(opt, (char *)"BEER") == 0) { | |
844 | if ((fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) { | |
845 | unit->beer_set = fval; | |
131
528dc0bb81ab
Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents:
125
diff
changeset
|
846 | srv_send((char *)"214 Unit %s BEER set to %.1f", current_unit, fval); |
88 | 847 | return 0; |
848 | } else { | |
849 | srv_send((char *)"510 New temperature not between %.1f and %.1f", unit->temp_set_min, unit->temp_set_max); | |
850 | return 1; | |
851 | } | |
852 | } else if (strcmp(opt, (char *)"FRIDGE") == 0) { | |
853 | if ((fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) { | |
854 | unit->fridge_set = fval; | |
131
528dc0bb81ab
Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents:
125
diff
changeset
|
855 | srv_send((char *)"214 Unit %s BEER set to %.1f", current_unit, fval); |
88 | 856 | return 0; |
857 | } else { | |
858 | srv_send((char *)"510 New temperature not between %.1f and %.1f", unit->temp_set_min, unit->temp_set_max); | |
859 | return 1; | |
860 | } | |
861 | } else if (strcmp(opt, (char *)"VOLUME") == 0) { | |
862 | /* | |
863 | * Must fit in a 2 TEU container | |
864 | */ | |
865 | if ((fval >= 0.0) && (fval <= 77020.0)) { | |
866 | unit->volume = fval; | |
131
528dc0bb81ab
Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents:
125
diff
changeset
|
867 | srv_send((char *)"214 Unit %s VOLUME set to %.1f", current_unit, fval); |
88 | 868 | return 0; |
869 | } else { | |
870 | srv_send((char *)"510 New volume not between 0 and 77020"); | |
871 | return 1; | |
872 | } | |
873 | } else if (strcmp(opt, (char *)"IDLE_LOW") == 0) { | |
874 | if ((fval >= -5.0) && (fval <= -0.1)) { | |
875 | unit->idle_rangeL = fval; | |
131
528dc0bb81ab
Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents:
125
diff
changeset
|
876 | srv_send((char *)"214 Unit %s IDLE_LOW set to %.1f", current_unit, fval); |
88 | 877 | return 0; |
878 | } else { | |
879 | srv_send((char *)"510 New value not between -5.0 and -0.1"); | |
880 | return 1; | |
881 | } | |
882 | } else if (strcmp(opt, (char *)"IDLE_HIGH") == 0) { | |
883 | if ((fval >= 0.1) && (fval <= 5.0)) { | |
884 | unit->idle_rangeH = fval; | |
131
528dc0bb81ab
Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents:
125
diff
changeset
|
885 | srv_send((char *)"214 Unit %s IDLE_HIGH set to %.1f", current_unit, fval); |
88 | 886 | return 0; |
887 | } else { | |
888 | srv_send((char *)"510 New value not between -5.0 and -0.1"); | |
889 | return 1; | |
890 | } | |
891 | } else if (strcmp(opt, (char *)"TEMP_MIN") == 0) { | |
892 | if ((fval >= -2.0) && (fval <= 35.0) && (fval < unit->temp_set_max)) { | |
893 | unit->temp_set_min = fval; | |
131
528dc0bb81ab
Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents:
125
diff
changeset
|
894 | srv_send((char *)"214 Unit %s TEMP_MIN set to %.1f", current_unit, fval); |
88 | 895 | return 0; |
896 | } else { | |
897 | srv_send((char *)"510 New value not between -2.0 and 35.0 and lower then TEMP_MAX"); | |
898 | return 1; | |
899 | } | |
900 | } else if (strcmp(opt, (char *)"TEMP_MAX") == 0) { | |
901 | if ((fval >= -2.0) && (fval <= 35.0) && (fval > unit->temp_set_min)) { | |
902 | unit->temp_set_max = fval; | |
131
528dc0bb81ab
Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents:
125
diff
changeset
|
903 | srv_send((char *)"214 Unit %s TEMP_MAX set to %.1f", current_unit, fval); |
88 | 904 | return 0; |
905 | } else { | |
906 | srv_send((char *)"510 New value not between -2.0 and 35.0 and higher then TEMP_MIN"); | |
907 | return 1; | |
908 | } | |
909 | } | |
910 | } | |
911 | ||
912 | /* | |
913 | * Set new unit or beer name | |
914 | */ | |
915 | if (strcmp(opt, (char *)"NAME") == 0) { | |
916 | if (unit->name) | |
917 | free(unit->name); | |
918 | unit->name = xstrcpy(param); | |
131
528dc0bb81ab
Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents:
125
diff
changeset
|
919 | srv_send((char *)"214 Unit %s NAME set to '%s'", current_unit, param); |
88 | 920 | // TODO: change logfile name |
921 | return 0; | |
922 | } else 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
|
923 | /* |
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
|
924 | * 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
|
925 | */ |
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
|
926 | 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
|
927 | 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
|
928 | 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
|
929 | } |
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
|
930 | 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
|
931 | 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
|
932 | 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
|
933 | } |
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
|
934 | 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
|
935 | 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
|
936 | 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
|
937 | 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
|
938 | 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
|
939 | 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
|
940 | 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
|
941 | } |
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
|
942 | } |
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
|
943 | 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
|
944 | return 1; |
88 | 945 | } |
946 | ||
947 | srv_send((char *)"502 Unknown command option"); | |
948 | return 1; | |
949 | } | |
950 | ||
951 | ||
952 | ||
953 | /* | |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
954 | * UNIT uuid |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
955 | */ |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
956 | int cmd_unit(char *buf) |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
957 | { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
958 | char *opt; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
959 | units_list *tmp; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
960 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
961 | opt = strtok(buf, " \0"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
962 | opt = strtok(NULL, " \0"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
963 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
964 | if (opt == NULL) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
965 | srv_send((char *)"501 Parameter missing"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
966 | return 1; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
967 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
968 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
969 | if (strlen(opt) == 36) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
970 | /* |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
971 | * Search using uuid |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
972 | */ |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
973 | for (tmp = Config.units; tmp; tmp = tmp->next) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
974 | if (strcmp(opt, tmp->uuid) == 0) { |
131
528dc0bb81ab
Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents:
125
diff
changeset
|
975 | srv_send((char *)"210 Unit %s selected", tmp->uuid); |
528dc0bb81ab
Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents:
125
diff
changeset
|
976 | 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
|
977 | free(current_unit); |
528dc0bb81ab
Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents:
125
diff
changeset
|
978 | current_unit = xstrcpy(tmp->uuid);; |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
979 | return 0; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
980 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
981 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
982 | srv_send((char *)"410 No such unit"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
983 | return 1; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
984 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
985 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
986 | srv_send((char *)"502 Unknown command option"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
987 | return 1; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
988 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
989 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
990 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
991 | |
43 | 992 | void cmd_server(void) |
993 | { | |
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
|
994 | 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
|
995 | int i, rlen; |
43 | 996 | socklen_t fromlen; |
68
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
997 | #ifdef HAVE_WIRINGPI_H |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
998 | int j; |
133
345307762220
Fixed compiling on systems with wiringpi libs
Michiel Broek <mbroek@mbse.eu>
parents:
132
diff
changeset
|
999 | char obuf[SS_BUFSIZE]; |
68
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
1000 | #endif |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1001 | |
48 | 1002 | memset((char *)&buf, 0, SS_BUFSIZE); |
1003 | fromlen = sizeof(peeraddr_in); | |
1004 | rlen = recvfrom(s, buf, sizeof(buf) -1, 0, (struct sockaddr *)&peeraddr_in, &fromlen); | |
1005 | if (rlen == -1) { | |
1006 | syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno)); | |
1007 | } else { | |
1008 | for (i = 0; i < strlen(buf); i++) { | |
1009 | if (buf[i] == '\n') | |
1010 | buf[i] = '\0'; | |
1011 | if (buf[i] == '\r') | |
1012 | buf[i] = '\0'; | |
1013 | } | |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
1014 | for (i = strlen(buf) -1; i > 0; i--) { |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
1015 | if (buf[i] == ' ') |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
1016 | buf[i] = '\0'; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
1017 | else |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
1018 | break; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
1019 | } |
48 | 1020 | if (strlen(buf)) { |
1021 | if (debug) { | |
1022 | syslog(LOG_NOTICE, "recv: \"%s\"", buf); | |
1023 | fprintf(stdout, "recv: \"%s\"\n", buf); | |
43 | 1024 | } |
1025 | ||
1026 | /* | |
48 | 1027 | * Process commands from the client |
43 | 1028 | */ |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
1029 | if (strncmp(buf, "ADD", 3) == 0) { |
92 | 1030 | if (unit_add(buf) == 0) |
1031 | wrconfig(); | |
138 | 1032 | } else if (strncmp(buf, "DEL", 3) == 0) { |
1033 | if (cmd_del(buf) == 0) | |
1034 | wrconfig(); | |
157
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
1035 | } else if (strncmp(buf, "GET", 3) == 0) { |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
1036 | cmd_get(buf); |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
1037 | } 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
|
1038 | srv_send((char *)"100 Help text follows"); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
1039 | srv_send((char *)"Recognized commands:"); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
1040 | 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
|
1041 | // 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
|
1042 | srv_send((char *)"ADD PROFILE name Add a new profile with \"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
|
1043 | srv_send((char *)"ADD UNIT name Add a new unit with \"name\""); |
138 | 1044 | srv_send((char *)"DEL PROFILE uuid Delete profile with 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
|
1045 | // srv_send((char *)"DEL UNIT uuid Delete unit with uuid"); |
157
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
1046 | srv_send((char *)"GET AIR uuid Get Air temperature with uuid"); |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
1047 | srv_send((char *)"GET BEER uuid Get Beer temperature with uuid"); |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
1048 | // srv_send((char *)"GET LED1 uuid Get LED 1 (cooler) state"); |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
1049 | // srv_send((char *)"GET LED2 uuid Get LED 2 (heater) state"); |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
1050 | // srv_send((char *)"GET LED3 uuid Get LED 3 (fan) state"); |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
1051 | // srv_send((char *)"GET DOOR uuid Get Door state"); |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
1052 | srv_send((char *)"GET TARGET uuid Get Target temperature with 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
|
1053 | 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
|
1054 | 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
|
1055 | srv_send((char *)"LIST BUS List 1-wire bus"); |
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
|
1056 | 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
|
1057 | srv_send((char *)"LIST PROFILES List available profiles"); |
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
|
1058 | srv_send((char *)"LIST UNIT List fermenter unit"); |
88 | 1059 | 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
|
1060 | // 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
|
1061 | srv_send((char *)"PROFILE uuid,name Profile rename"); |
140
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1062 | srv_send((char *)"PROFILE GETS uuid Profile get steps list"); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1063 | 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
|
1064 | srv_send((char *)"SET BEER val Set beer temperature"); |
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
|
1065 | srv_send((char *)"SET FRIDGE val Set fridge temperature"); |
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
|
1066 | srv_send((char *)"SET IDLE_LOW val Set idle temperature low (-5.0 .. -0.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
|
1067 | srv_send((char *)"SET IDLE_HIGH val Set idle temperature high (0.1 .. 5.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
|
1068 | srv_send((char *)"SET NAME name Set name or beername for the 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
|
1069 | 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
|
1070 | // 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
|
1071 | srv_send((char *)"SET TEMP_MIN val Set unit minimum temperature"); |
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
|
1072 | srv_send((char *)"SET TEMP_MAX val Set unit maximum temperature"); |
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
|
1073 | 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
|
1074 | srv_send((char *)"UNIT uuid Select unit by uuid"); |
68
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
1075 | srv_send((char *)"."); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
1076 | } else if (strncmp(buf, "LCD", 3) == 0) { |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
1077 | #ifdef HAVE_WIRINGPI_H |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
1078 | srv_send((char *)"201 information follows"); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
1079 | for (j = 0; j < 4; j++) { |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
1080 | sprintf(obuf, " "); |
70 | 1081 | obuf[20] = '\0'; |
68
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
1082 | for (i = 0; i < 20; i++) |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
1083 | obuf[i] = lcdbuf[lcdHandle][i][j]; |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
1084 | srv_send(obuf); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
1085 | } |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
1086 | srv_send((char *)"."); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
1087 | #else |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
1088 | srv_send((char *)"403 LCD not available"); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
1089 | #endif |
81 | 1090 | } else if (strncmp(buf, "LIST", 4) == 0) { |
1091 | cmd_list(buf); | |
88 | 1092 | } 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
|
1093 | if (cmd_mode(buf) == 0) |
5fb74d89f571
Update LCD even when unit is off
Michiel Broek <mbroek@mbse.eu>
parents:
155
diff
changeset
|
1094 | 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
|
1095 | } 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
|
1096 | 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
|
1097 | wrconfig(); |
88 | 1098 | } else if (strncmp(buf, "SET", 3) == 0) { |
92 | 1099 | if (cmd_set(buf) == 0) |
1100 | wrconfig(); | |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1101 | } else if (strncmp(buf, "UNIT", 4) == 0) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1102 | cmd_unit(buf); |
43 | 1103 | } else { |
48 | 1104 | if (debug) |
1105 | 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
|
1106 | srv_send((char *)"500 Unknown command"); |
43 | 1107 | } |
1108 | } | |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1109 | } |
44 | 1110 | |
1111 | close(s); | |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1112 | } |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1113 | |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1114 | |
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
|
1115 | |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
1116 | #ifdef HAVE_WIRINGPI_H |
43 | 1117 | PI_THREAD (my_server_loop) |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
1118 | #else |
74 | 1119 | 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
|
1120 | #endif |
43 | 1121 | { |
1122 | socklen_t addrlen; | |
44 | 1123 | int optval = 1; |
43 | 1124 | |
1125 | syslog(LOG_NOTICE, "Thread my_server_loop started"); | |
1126 | if (debug) | |
1127 | fprintf(stdout, "Thread my_server_loop started\n"); | |
1128 | ||
44 | 1129 | memset((char *)&myaddr_in, 0, sizeof(struct sockaddr_in)); |
1130 | memset((char *)&peeraddr_in, 0, sizeof(struct sockaddr_in)); | |
1131 | myaddr_in.sin_family = AF_INET; | |
1132 | myaddr_in.sin_addr.s_addr = INADDR_ANY; | |
1133 | myaddr_in.sin_port = htons(Config.my_port); | |
1134 | ||
1135 | ls = socket(AF_INET, SOCK_STREAM, 0); | |
1136 | if (ls == -1) { | |
1137 | syslog(LOG_NOTICE, "Can't create listen socket: %s", strerror(errno)); | |
1138 | fprintf(stderr, "Can't create listen socket: %s\n", strerror(errno)); | |
1139 | return 0; | |
1140 | } | |
1141 | ||
1142 | if (setsockopt(ls, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(optval)) == -1) { | |
1143 | syslog(LOG_NOTICE, "Can't setsockopt SO_KEEPALIVE socket: %s", strerror(errno)); | |
1144 | close(ls); | |
1145 | return 0; | |
1146 | } | |
1147 | ||
1148 | if (setsockopt(ls, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) == -1) { | |
1149 | syslog(LOG_NOTICE, "Can't setsockopt SO_REUSEADDR socket: %s", strerror(errno)); | |
1150 | close(ls); | |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
1151 | return 0; |
44 | 1152 | } |
1153 | ||
1154 | if (bind(ls, (struct sockaddr *)&myaddr_in, sizeof(struct sockaddr_in)) == -1) { | |
1155 | syslog(LOG_NOTICE, "Can't bind to listen socket: %s", strerror(errno)); | |
1156 | close(ls); | |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
1157 | return 0; |
44 | 1158 | } |
1159 | ||
1160 | if (listen(ls, 5) == -1) { | |
1161 | syslog(LOG_NOTICE, "Can't listen on listen socket: %s", strerror(errno)); | |
1162 | close(ls); | |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
1163 | return 0; |
44 | 1164 | } |
1165 | ||
1166 | syslog(LOG_NOTICE, "listen socket created %d", ls); | |
1167 | if (debug) | |
1168 | fprintf(stdout, "listen socket created %d\n", ls); | |
1169 | ||
1170 | ||
43 | 1171 | /* |
1172 | * Loop forever until the external shutdown variable is set. | |
1173 | */ | |
1174 | for (;;) { | |
1175 | ||
1176 | addrlen = sizeof(struct sockaddr_in); | |
1177 | /* | |
1178 | * This call will block until a new connection | |
1179 | * arrives. Then it will return the address of | |
1180 | * the connecting peer, and a new socket | |
1181 | * descriptor, s, for that connection. | |
1182 | */ | |
1183 | s = accept(ls, (struct sockaddr *)&peeraddr_in, &addrlen); | |
1184 | if (s == -1) { | |
1185 | syslog(LOG_NOTICE, "my_server_loop accept failed %s", strerror(errno)); | |
1186 | if (debug) | |
1187 | fprintf(stdout, "my_server_loop accept failed %s\n", strerror(errno)); | |
44 | 1188 | return 0; |
43 | 1189 | } |
1190 | ||
48 | 1191 | cmd_server(); |
43 | 1192 | |
1193 | if (my_shutdown) { | |
1194 | syslog(LOG_NOTICE, "Thread my_server_loop stopped"); | |
1195 | if (debug) | |
1196 | fprintf(stdout, "Thread my_server_loop stopped\n"); | |
1197 | return 0; | |
1198 | } | |
1199 | ||
1200 | } | |
1201 | } | |
1202 | ||
1203 |