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