Thu, 02 Apr 2015 22:23:18 +0200
Plot room temperature on the dashboard.
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | /***************************************************************************** |
306
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2 | * Copyright (C) 2008-2015 |
42
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 |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
19 | * along with ThermFerm; see the file COPYING. If not, write to the Free |
42
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" |
184 | 26 | #include "devices.h" |
106 | 27 | #include "server.h" |
245
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
28 | #include "lcd-buffer.h" |
106 | 29 | #include "xutil.h" |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
30 | |
58
e8e7b46b705b
Fixed compilation without wiringpi
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
31 | |
75
4b976601737d
Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents:
74
diff
changeset
|
32 | 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
|
33 | extern int debug; |
245
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
34 | extern int run_pause; |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
35 | extern int run_hold; |
43 | 36 | extern sys_config Config; |
81 | 37 | extern const char UNITMODE[5][8]; |
101
1302abe92eb1
Made temperature sensors working in the units
Michiel Broek <mbroek@mbse.eu>
parents:
100
diff
changeset
|
38 | extern const char TEMPSTATE[3][8]; |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
39 | extern const char DEVTYPE[8][6]; |
174 | 40 | extern const char DEVPRESENT[4][6]; |
41 | extern const char DEVDIR[7][11]; | |
217 | 42 | extern const char PROFSTATE[5][6]; |
174 | 43 | |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
44 | |
43 | 45 | int s; /* connected socket */ |
46 | int ls; /* listen socket */ | |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
47 | |
43 | 48 | struct sockaddr_in myaddr_in; /* for local socket address */ |
49 | struct sockaddr_in peeraddr_in; /* for peer socket address */ | |
50 | ||
51 | struct hostent *hp; | |
52 | ||
53 | #define SS_BUFSIZE 1024 | |
54 | #define SS_TIMEOUT 300 | |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
55 | |
300
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
56 | #define MAX_INTERVALS 6 |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
57 | const int GRAPH_INTERVAL[MAX_INTERVALS] = { 0, 1, 5, 15, 30, 60, }; |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
58 | const int GRAPH_DATALINES[MAX_INTERVALS] = { 0, 800, 3200, 12000, 24000, 48000, }; |
329 | 59 | const char MONTH[12][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; |
60 | ||
61 | ||
62 | typedef struct _ls_list { | |
63 | struct _ls_list *next; /* Next record pointer */ | |
64 | char d_name[256]; /* File name */ | |
65 | mode_t mode; /* File mode */ | |
66 | off_t size; /* File size */ | |
67 | time_t mtime; /* File modification time */ | |
68 | } ls_list; | |
69 | ||
70 | ||
71 | ||
72 | void tidy_lslist(ls_list **); | |
73 | void fill_list(ls_list **, char *, mode_t, off_t, time_t); | |
74 | int comp(ls_list **,ls_list **); | |
75 | void sort_list(ls_list **); | |
76 | ||
77 | ||
46
000399c64d3f
More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
78 | |
43 | 79 | /* |
80 | * Send message to client | |
81 | */ | |
82 | int srv_send(const char *format, ...) | |
83 | { | |
84 | char out[SS_BUFSIZE]; | |
85 | va_list va_ptr; | |
86 | ||
87 | if (s == -1) | |
88 | return -1; | |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
89 | |
43 | 90 | va_start(va_ptr, format); |
91 | vsnprintf(out, SS_BUFSIZE-1, format, va_ptr); | |
92 | va_end(va_ptr); | |
93 | ||
48 | 94 | if (debug) { |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
95 | syslog(LOG_NOTICE, "send: \"%s\"", out); |
45
053c4657105f
Mirror LCD display on the webpage works
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
96 | fprintf(stdout, "send: \"%s\"\n", out); |
48 | 97 | } |
44 | 98 | |
43 | 99 | if (send(s, out, strlen(out), 0) != strlen(out)) { |
268
dda91dfa4aa8
All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents:
266
diff
changeset
|
100 | syslog(LOG_NOTICE, "srv_send failed"); |
43 | 101 | return -1; |
102 | } | |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
103 | |
43 | 104 | if (send(s, (char *)"\r\n", 2, 0) != 2) { |
268
dda91dfa4aa8
All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents:
266
diff
changeset
|
105 | syslog(LOG_NOTICE, "srv_send failed"); |
43 | 106 | return -1; |
107 | } | |
108 | ||
109 | return 0; | |
110 | } | |
111 | ||
112 | ||
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
113 | |
88 | 114 | /* |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
115 | * Update the device inuse counter. |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
116 | */ |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
117 | void device_count(int plus, char *uuid) |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
118 | { |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
119 | devices_list *device; |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
120 | |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
121 | for (device = Config.devices; device; device = device->next) { |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
122 | if (strcmp(device->uuid, uuid) == 0) { |
240
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
123 | #ifdef HAVE_WIRINGPI_H |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
124 | piLock(LOCK_DEVICES); |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
125 | #endif |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
126 | if (plus == TRUE) { |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
127 | device->inuse++; |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
128 | } else { |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
129 | if (device->inuse) |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
130 | device->inuse--; |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
131 | } |
240
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
132 | #ifdef HAVE_WIRINGPI_H |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
133 | piUnlock(LOCK_DEVICES); |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
134 | #endif |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
135 | } |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
136 | } |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
137 | } |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
138 | |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
139 | |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
140 | |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
141 | int delete_Profile(char *uuid) |
138 | 142 | { |
143 | profiles_list *current = Config.profiles; | |
144 | profiles_list *previous = NULL; | |
145 | prof_step *step, *olds; | |
146 | ||
147 | while (current) { | |
148 | if (strcmp(current->uuid, uuid) == 0) { | |
149 | if (previous == NULL) { | |
150 | Config.profiles = current->next; | |
151 | free(current->uuid); | |
152 | current->uuid = NULL; | |
153 | free(current->name); | |
154 | current->name = NULL; | |
155 | if (current->steps) { | |
156 | for (step = current->steps; step; step = olds) { | |
157 | olds = step->next; | |
158 | free(step); | |
159 | } | |
160 | current->steps = NULL; | |
161 | } | |
162 | free(current); | |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
163 | return 1; |
138 | 164 | } else { |
165 | free(current->uuid); | |
166 | current->uuid = NULL; | |
167 | free(current->name); | |
168 | current->name = NULL; | |
169 | if (current->steps) { | |
170 | for (step = current->steps; step; step = olds) { | |
171 | olds = step->next; | |
172 | free(step); | |
173 | } | |
174 | current->steps = NULL; | |
175 | } | |
176 | previous->next = current->next; | |
177 | free(current); | |
178 | current = previous->next; | |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
179 | return 1; |
138 | 180 | } |
181 | } else { | |
182 | previous = current; | |
183 | current = current->next; | |
184 | } | |
185 | } | |
186 | ||
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
187 | return 0; |
138 | 188 | } |
189 | ||
190 | ||
191 | ||
329 | 192 | void tidy_lslist(ls_list **lap) |
193 | { | |
194 | ls_list *tmp, *old; | |
195 | ||
196 | for (tmp = *lap; tmp; tmp = old) { | |
197 | old = tmp->next; | |
198 | free(tmp); | |
199 | } | |
200 | *lap = NULL; | |
201 | } | |
202 | ||
203 | ||
204 | ||
205 | void fill_list(ls_list **lap, char *name, mode_t mode, off_t size, time_t mtime) | |
206 | { | |
207 | ls_list **tmp; | |
208 | ||
209 | for (tmp = lap; *tmp; tmp = &((*tmp)->next)); | |
210 | ||
211 | *tmp = (ls_list *)malloc(sizeof(ls_list)); | |
212 | (*tmp)->next = NULL; | |
213 | strncpy((*tmp)->d_name, name, 256); | |
214 | (*tmp)->mode = mode; | |
215 | (*tmp)->size = size; | |
216 | (*tmp)->mtime = mtime; | |
217 | tmp = &((*tmp)->next); | |
218 | } | |
219 | ||
220 | ||
221 | ||
222 | void sort_list(ls_list **lap) | |
223 | { | |
224 | ls_list *ta, **vector; | |
225 | size_t n = 0, i; | |
226 | ||
227 | if (*lap == NULL) | |
228 | return; | |
229 | ||
230 | for (ta = *lap; ta; ta = ta->next) | |
231 | n++; | |
232 | vector = (ls_list **)malloc(n * sizeof(ls_list *)); | |
233 | i = 0; | |
234 | ||
235 | for (ta = *lap; ta; ta = ta->next) { | |
236 | vector[i++] = ta; | |
237 | } | |
238 | qsort(vector, n, sizeof(ls_list *), (int(*)(const void*, const void*))comp); | |
239 | ||
240 | (*lap) = vector[0]; | |
241 | i = 1; | |
242 | ||
243 | for (ta = *lap; ta; ta = ta->next) { | |
244 | if (i < n) | |
245 | ta->next = vector[i++]; | |
246 | else | |
247 | ta->next = NULL; | |
248 | } | |
249 | ||
250 | free(vector); | |
251 | return; | |
252 | } | |
253 | ||
254 | ||
255 | ||
256 | int comp(ls_list **lsp1, ls_list **lsp2) | |
257 | { | |
258 | return strcmp((*lsp1)->d_name, (*lsp2)->d_name); | |
259 | } | |
260 | ||
261 | ||
262 | ||
263 | /* | |
264 | * ARCHIVE DIR | |
265 | * ARCHIVE GET filename | |
331 | 266 | * ARCHIVE LOG filename |
329 | 267 | * ARCHIVE HELP |
268 | */ | |
269 | int cmd_archive(char *buf) | |
270 | { | |
271 | char *opt, *param, *name = NULL, *filename = NULL, mbits[11], tstr[24]; | |
272 | DIR *dd; | |
273 | FILE *fp; | |
274 | struct dirent entry, *result; | |
275 | ls_list *lsx = NULL, *tmp; | |
276 | struct stat sbuf; | |
277 | struct tm *tbuf; | |
278 | time_t ftime; | |
279 | ||
280 | opt = strtok(buf, " \0"); | |
281 | opt = strtok(NULL, " \0"); | |
282 | ||
283 | if (opt == NULL) { | |
284 | srv_send((char *)"501 Subcommand missing"); | |
285 | return 1; | |
286 | } | |
287 | param = strtok(NULL, "\0"); | |
288 | ||
289 | if (strcmp(opt, (char *)"HELP") == 0) { | |
290 | srv_send((char *)"100 Help text follows:"); | |
291 | srv_send((char *)"Recognized commands:"); | |
292 | srv_send((char *)"ARCHIVE DIR Archived logfiles directory"); | |
293 | srv_send((char *)"ARCHIVE GET filename Archived logfile download"); | |
331 | 294 | srv_send((char *)"ARCHIVE LOG filename Archived logfile data in graphsteps"); |
329 | 295 | srv_send((char *)"."); |
296 | return 0; | |
297 | } | |
298 | ||
299 | if (strcmp(opt, (char *)"DIR") == 0) { | |
300 | ||
301 | if (getenv((char *)"USER") == NULL) { | |
302 | name = xstrcpy((char *)"/root"); | |
303 | } else { | |
304 | name = xstrcpy(getenv((char *)"HOME")); | |
305 | } | |
306 | name = xstrcat(name, (char *)"/.thermferm/log/"); | |
307 | ||
308 | if ((dd = opendir(name))) { | |
309 | for (;;) { | |
310 | if ((readdir_r(dd, &entry, &result)) != 0) { | |
311 | syslog(LOG_NOTICE, "readdir_r: error=%d", errno); | |
312 | break; | |
313 | } | |
314 | if (result == NULL) /* End of directory */ | |
315 | break; | |
316 | if (result->d_name[0] != '.') { | |
317 | filename = xstrcpy(name); | |
318 | filename = xstrcat(filename, result->d_name); | |
319 | if ((stat(filename, &sbuf)) == 0) { | |
320 | fill_list(&lsx, result->d_name, sbuf.st_mode, sbuf.st_size, sbuf.st_mtime); | |
321 | } | |
322 | free(filename); | |
323 | filename = NULL; | |
324 | } | |
325 | } | |
326 | closedir(dd); | |
327 | } else { | |
328 | syslog(LOG_NOTICE, "opendir: \"%s\" error=%d", name, errno); | |
329 | } | |
330 | ||
331 | sort_list(&lsx); | |
332 | ||
333 | srv_send((char *)"212 Archive directory follows:"); | |
334 | for (tmp = lsx; tmp; tmp = tmp->next) { | |
335 | sprintf(mbits, "----------"); | |
336 | if (tmp->mode & S_IRUSR) | |
337 | mbits[1] = 'r'; | |
338 | if (tmp->mode & S_IWUSR) | |
339 | mbits[2] = 'w'; | |
340 | if (tmp->mode & S_IXUSR) | |
341 | mbits[3] = 'x'; | |
342 | if (tmp->mode & S_IRGRP) | |
343 | mbits[4] = 'r'; | |
344 | if (tmp->mode & S_IWGRP) | |
345 | mbits[5] = 'w'; | |
346 | if (tmp->mode & S_IXGRP) | |
347 | mbits[6] = 'x'; | |
348 | if (tmp->mode & S_IROTH) | |
349 | mbits[7] = 'r'; | |
350 | if (tmp->mode & S_IWOTH) | |
351 | mbits[8] = 'w'; | |
352 | if (tmp->mode & S_IXOTH) | |
353 | mbits[9] = 'x'; | |
354 | ftime = tmp->mtime; | |
355 | tbuf = localtime(&ftime); | |
356 | sprintf(tstr, "%02d %s %04d %02d:%02d", tbuf->tm_mday, MONTH[tbuf->tm_mon], tbuf->tm_year+1900, tbuf->tm_hour, tbuf->tm_min); | |
357 | srv_send((char *)"%s,%s,%d,%s", tmp->d_name, mbits, tmp->size, tstr); | |
358 | } | |
359 | srv_send((char *)"."); | |
360 | tidy_lslist(&lsx); | |
361 | ||
362 | free(name); | |
363 | name = NULL; | |
364 | return 1; | |
365 | } | |
366 | ||
367 | if (param == NULL) { | |
368 | srv_send((char *)"502 Parameter missing"); | |
369 | return 1; | |
370 | } | |
371 | ||
372 | if (strcmp(opt, (char *)"GET") == 0) { | |
373 | if (getenv((char *)"USER") == NULL) { | |
374 | name = xstrcpy((char *)"/root"); | |
375 | } else { | |
376 | name = xstrcpy(getenv((char *)"HOME")); | |
377 | } | |
378 | name = xstrcat(name, (char *)"/.thermferm/log/"); | |
379 | name = xstrcat(name, param); | |
380 | ||
381 | if ((fp = fopen(name, "r"))) { | |
382 | char buffer[256]; | |
383 | ||
384 | srv_send((char *)"212 Archive file follows:"); | |
385 | while (fgets(buffer, sizeof(buffer)-1, fp) != NULL) { | |
386 | int i; | |
387 | ||
388 | for (i = 0; i < strlen(buffer); i++) { | |
389 | if (buffer[i] == '\n') | |
390 | buffer[i] = '\0'; | |
391 | if (buffer[i] == '\r') | |
392 | buffer[i] = '\0'; | |
393 | } | |
394 | srv_send(buffer); | |
395 | } | |
396 | srv_send((char *)"."); | |
397 | fclose(fp); | |
398 | } else { | |
399 | srv_send((char *)"440 No such file"); | |
331 | 400 | } |
401 | ||
402 | free(name); | |
403 | name = NULL; | |
404 | return 1; | |
405 | } | |
406 | ||
407 | if (strcmp(opt, (char *)"LOG") == 0) { | |
408 | if (getenv((char *)"USER") == NULL) { | |
409 | name = xstrcpy((char *)"/root"); | |
410 | } else { | |
411 | name = xstrcpy(getenv((char *)"HOME")); | |
412 | } | |
413 | name = xstrcat(name, (char *)"/.thermferm/log/"); | |
414 | name = xstrcat(name, param); | |
415 | ||
416 | if ((fp = fopen(name, "r"))) { | |
417 | char buffer[256], outbuf[256], q[5]; | |
356
44bcfe087f9e
Added room temperature to ARCHIVE LOG command output.
Michiel Broek <mbroek@mbse.eu>
parents:
345
diff
changeset
|
418 | char *date_n, *mode_n, *air_n, *beer_n, *target_n, *heater_n, *cooler_n, *room_n; |
331 | 419 | char *heater_u, *cooler_u; |
420 | int lines = 0, heater_l = 0, cooler_l = 0, h = 0, c = 0, heat_used = 0, cool_used = 0, graphstep = 0; | |
356
44bcfe087f9e
Added room temperature to ARCHIVE LOG command output.
Michiel Broek <mbroek@mbse.eu>
parents:
345
diff
changeset
|
421 | float room_t = 0.0; |
331 | 422 | |
423 | srv_send((char *)"212 Logfile list follows:"); | |
424 | while (fgets(buffer, sizeof(buffer)-1, fp) != NULL) { | |
425 | lines++; | |
426 | } | |
427 | fseek(fp, 0L, SEEK_SET); | |
428 | /* | |
429 | * We have counted the lines in the logfile including the header lines. | |
430 | * The header lines should be ignored but there are so few of them, we | |
431 | * just include them in the total. | |
432 | * Now find a reasonable interval of lines to sent to the client. | |
433 | */ | |
434 | for (graphstep = 1; graphstep <= MAX_INTERVALS; graphstep++) { | |
435 | if (lines < GRAPH_DATALINES[graphstep]) { | |
436 | break; | |
437 | } | |
438 | } | |
439 | syslog(LOG_NOTICE, "ARCHIVE LOG %s: lines=%d, interval=%d, graphstep=%d", param, lines, GRAPH_INTERVAL[graphstep], graphstep); | |
440 | ||
441 | while (fgets(buffer, sizeof(buffer)-1, fp) != NULL) { | |
442 | /* | |
356
44bcfe087f9e
Added room temperature to ARCHIVE LOG command output.
Michiel Broek <mbroek@mbse.eu>
parents:
345
diff
changeset
|
443 | * 2014-11-15 18:39,BEER,20.312,19.750,20.0,0,NA,NA,NA,78105,NA,NA,18.000 |
44bcfe087f9e
Added room temperature to ARCHIVE LOG command output.
Michiel Broek <mbroek@mbse.eu>
parents:
345
diff
changeset
|
444 | * | | | | | | | | | | | | | |
44bcfe087f9e
Added room temperature to ARCHIVE LOG command output.
Michiel Broek <mbroek@mbse.eu>
parents:
345
diff
changeset
|
445 | * date_n | | | | | | | | | | | | |
44bcfe087f9e
Added room temperature to ARCHIVE LOG command output.
Michiel Broek <mbroek@mbse.eu>
parents:
345
diff
changeset
|
446 | * mode_n ----------+ | | | | | | | | | | | |
44bcfe087f9e
Added room temperature to ARCHIVE LOG command output.
Michiel Broek <mbroek@mbse.eu>
parents:
345
diff
changeset
|
447 | * air_n -----------------+ | | | | | | | | | | |
44bcfe087f9e
Added room temperature to ARCHIVE LOG command output.
Michiel Broek <mbroek@mbse.eu>
parents:
345
diff
changeset
|
448 | * beer_n -----------------------+ | | | | | | | | | |
44bcfe087f9e
Added room temperature to ARCHIVE LOG command output.
Michiel Broek <mbroek@mbse.eu>
parents:
345
diff
changeset
|
449 | * target_n ---------------------------+ | | | | | | | | |
44bcfe087f9e
Added room temperature to ARCHIVE LOG command output.
Michiel Broek <mbroek@mbse.eu>
parents:
345
diff
changeset
|
450 | * heater_n -------------------------------+ | | | | | | | |
44bcfe087f9e
Added room temperature to ARCHIVE LOG command output.
Michiel Broek <mbroek@mbse.eu>
parents:
345
diff
changeset
|
451 | * cooler_n ---------------------------------+ | | | | | | |
44bcfe087f9e
Added room temperature to ARCHIVE LOG command output.
Michiel Broek <mbroek@mbse.eu>
parents:
345
diff
changeset
|
452 | * not used ------------------------------------+ | | | | | |
44bcfe087f9e
Added room temperature to ARCHIVE LOG command output.
Michiel Broek <mbroek@mbse.eu>
parents:
345
diff
changeset
|
453 | * not used ---------------------------------------+ | | | | |
44bcfe087f9e
Added room temperature to ARCHIVE LOG command output.
Michiel Broek <mbroek@mbse.eu>
parents:
345
diff
changeset
|
454 | * heater_u --------------------------------------------+ | | | |
44bcfe087f9e
Added room temperature to ARCHIVE LOG command output.
Michiel Broek <mbroek@mbse.eu>
parents:
345
diff
changeset
|
455 | * cooler_u ------------------------------------------------+ | | |
44bcfe087f9e
Added room temperature to ARCHIVE LOG command output.
Michiel Broek <mbroek@mbse.eu>
parents:
345
diff
changeset
|
456 | * not used ---------------------------------------------------+ | |
44bcfe087f9e
Added room temperature to ARCHIVE LOG command output.
Michiel Broek <mbroek@mbse.eu>
parents:
345
diff
changeset
|
457 | * room_n ----------------------------------------------------------+ |
331 | 458 | */ |
459 | q[0] = buffer[11]; | |
460 | q[1] = buffer[12]; | |
461 | q[2] = buffer[14]; | |
462 | q[3] = buffer[15]; | |
463 | buffer[strlen(buffer) -1] = '\0'; | |
464 | date_n = strtok(buffer, ",\0"); /* timestamp */ | |
465 | mode_n = strtok(NULL, ",\0"); /* unit mode */ | |
466 | air_n = strtok(NULL, ",\0"); /* air temp */ | |
467 | beer_n = strtok(NULL, ",\0"); /* beer temp */ | |
468 | target_n = strtok(NULL, ",\0"); /* target temp */ | |
469 | heater_n = strtok(NULL, ",\0"); /* current heater state */ | |
470 | cooler_n = strtok(NULL, ",\0"); /* current cooler state */ | |
471 | heater_u = strtok(NULL, ",\0"); /* current fan state */ | |
472 | heater_u = strtok(NULL, ",\0"); /* current door state */ | |
473 | heater_u = strtok(NULL, ",\0"); /* heater use counter */ | |
474 | cooler_u = strtok(NULL, ",\0"); /* cooler use counter */ | |
356
44bcfe087f9e
Added room temperature to ARCHIVE LOG command output.
Michiel Broek <mbroek@mbse.eu>
parents:
345
diff
changeset
|
475 | room_n = strtok(NULL, ",\0"); /* fan use counter */ |
44bcfe087f9e
Added room temperature to ARCHIVE LOG command output.
Michiel Broek <mbroek@mbse.eu>
parents:
345
diff
changeset
|
476 | room_n = strtok(NULL, ",\0"); /* room temperature */ |
331 | 477 | |
478 | if (strncmp(mode_n, (char *)"Mode", 4)) { | |
479 | /* | |
480 | * Output a line at the right intervals | |
481 | */ | |
482 | if (((graphstep == 1)) || | |
483 | ((graphstep == 2) && (q[3] == '0' || q[3] == '5')) || | |
484 | ((graphstep == 3) && ((q[2] == '0' && q[3] == '0') || (q[2] == '1' && q[3] == '5') || (q[2] == '3' && q[3] == '0') || (q[2] == '4' && q[3] == '5'))) || | |
485 | ((graphstep == 4) && ((q[2] == '0' && q[3] == '0') || (q[2] == '3' && q[3] == '0'))) || | |
486 | ((graphstep == 5) && (q[2] == '0' && q[3] == '0')) ) { | |
487 | heat_used = cool_used = 0; | |
356
44bcfe087f9e
Added room temperature to ARCHIVE LOG command output.
Michiel Broek <mbroek@mbse.eu>
parents:
345
diff
changeset
|
488 | if (heater_u && strcmp(heater_u, "NA") && (sscanf(heater_u, "%d", &h) == 1)) { |
331 | 489 | if (h && heater_l) { |
490 | heat_used = ((h - heater_l) * 100) / (GRAPH_INTERVAL[graphstep] * 60); | |
491 | } | |
492 | } | |
356
44bcfe087f9e
Added room temperature to ARCHIVE LOG command output.
Michiel Broek <mbroek@mbse.eu>
parents:
345
diff
changeset
|
493 | if (cooler_u && strcmp(cooler_u, "NA") && (sscanf(cooler_u, "%d", &c) == 1)) { |
331 | 494 | if (c && cooler_l) { |
495 | cool_used = ((c - cooler_l) * 100) / (GRAPH_INTERVAL[graphstep] * 60); | |
496 | } | |
497 | } | |
356
44bcfe087f9e
Added room temperature to ARCHIVE LOG command output.
Michiel Broek <mbroek@mbse.eu>
parents:
345
diff
changeset
|
498 | if (room_n) |
44bcfe087f9e
Added room temperature to ARCHIVE LOG command output.
Michiel Broek <mbroek@mbse.eu>
parents:
345
diff
changeset
|
499 | sscanf(room_n, "%f", &room_t); |
44bcfe087f9e
Added room temperature to ARCHIVE LOG command output.
Michiel Broek <mbroek@mbse.eu>
parents:
345
diff
changeset
|
500 | snprintf(outbuf, 255, "%s,%s,%s,%s,%s,%s,%s,%d,%d,%.1f", |
44bcfe087f9e
Added room temperature to ARCHIVE LOG command output.
Michiel Broek <mbroek@mbse.eu>
parents:
345
diff
changeset
|
501 | date_n, mode_n, air_n, beer_n, target_n, heater_n, cooler_n, heat_used, cool_used, room_t); |
331 | 502 | srv_send(outbuf); |
356
44bcfe087f9e
Added room temperature to ARCHIVE LOG command output.
Michiel Broek <mbroek@mbse.eu>
parents:
345
diff
changeset
|
503 | if (heater_u && h && strcmp(heater_u, "NA")) |
331 | 504 | heater_l = h; |
356
44bcfe087f9e
Added room temperature to ARCHIVE LOG command output.
Michiel Broek <mbroek@mbse.eu>
parents:
345
diff
changeset
|
505 | if (cooler_u && c & strcmp(cooler_u, "NA")) |
331 | 506 | cooler_l = c; |
507 | } | |
508 | } | |
509 | } | |
510 | ||
511 | srv_send((char *)"."); | |
512 | fclose(fp); | |
513 | } else { | |
514 | srv_send((char *)"440 No such file"); | |
329 | 515 | } |
516 | ||
517 | free(name); | |
518 | name = NULL; | |
519 | return 1; | |
520 | } | |
521 | ||
522 | return 0; | |
523 | } | |
524 | ||
525 | ||
526 | ||
174 | 527 | int delete_Device(char *uuid) |
528 | { | |
529 | devices_list *current = Config.devices; | |
530 | devices_list *previous = NULL; | |
531 | ||
532 | while (current) { | |
533 | if (strcmp(current->uuid, uuid) == 0) { | |
534 | if (previous == NULL) { | |
535 | Config.devices = current->next; | |
536 | free(current->uuid); | |
537 | current->uuid = NULL; | |
538 | free(current->address); | |
539 | current->address = NULL; | |
540 | free(current->description); | |
541 | current->description = NULL; | |
542 | free(current->comment); | |
543 | current->comment = NULL; | |
544 | free(current); | |
545 | return 1; | |
546 | } else { | |
547 | free(current->uuid); | |
548 | current->uuid = NULL; | |
549 | free(current->address); | |
550 | current->address = NULL; | |
551 | free(current->description); | |
552 | current->description = NULL; | |
553 | free(current->comment); | |
554 | current->comment = NULL; | |
555 | previous->next = current->next; | |
556 | free(current); | |
557 | current = previous->next; | |
558 | return 1; | |
559 | } | |
560 | } else { | |
561 | previous = current; | |
562 | current = current->next; | |
563 | } | |
564 | } | |
565 | return 0; | |
566 | } | |
567 | ||
568 | ||
569 | ||
81 | 570 | /* |
174 | 571 | * DEVICE ADD type |
572 | * DEVICE DEL uuid | |
573 | * DEVICE LIST | |
574 | * DEVICE GET uuid | |
575 | * DEVICE PUT uuid | |
157
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
576 | */ |
174 | 577 | int cmd_device(char *buf) |
157
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
578 | { |
174 | 579 | char *opt, *param, *kwd, *val, ibuf[SS_BUFSIZE]; |
580 | devices_list *device, *tmpd; | |
581 | socklen_t fromlen; | |
240
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
582 | int i, rc, rlen, ival; |
174 | 583 | uuid_t uu; |
157
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
584 | |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
585 | opt = strtok(buf, " \0"); |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
586 | opt = strtok(NULL, " \0"); |
174 | 587 | |
588 | if (opt == NULL) { | |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
589 | srv_send((char *)"501 Subcommand missing"); |
174 | 590 | return 1; |
591 | } | |
592 | param = strtok(NULL, "\0"); | |
157
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
593 | |
174 | 594 | if (strcmp(opt, (char *)"LIST") == 0) { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
595 | srv_send((char *)"212 Devices list follows:"); |
174 | 596 | for (device = Config.devices; device; device = device->next) { |
345
9894b559441c
Added device direction and value in devices maintenance screen
Michiel Broek <mbroek@mbse.eu>
parents:
344
diff
changeset
|
597 | srv_send((char *)"%s,%s,%d,%d,%s,%s,%d", device->uuid, device->address, device->subdevice, |
9894b559441c
Added device direction and value in devices maintenance screen
Michiel Broek <mbroek@mbse.eu>
parents:
344
diff
changeset
|
598 | device->inuse, device->comment, DEVDIR[device->direction], device->value + device->offset); |
174 | 599 | } |
600 | srv_send((char *)"."); | |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
601 | return 1; |
174 | 602 | } |
603 | ||
604 | if (param == NULL) { | |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
605 | srv_send((char *)"502 Parameter missing"); |
157
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
606 | return 1; |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
607 | } |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
608 | |
174 | 609 | if (strcmp(opt, (char *)"ADD") == 0) { |
610 | if ((strcmp(param, (char *)"RC433") == 0) || (strcmp(param, (char *)"DHT") == 0) || | |
611 | (strcmp(param, (char *)"I2C") == 0) || (strcmp(param, (char *)"SPI") == 0)) { | |
170 | 612 | |
174 | 613 | device = (devices_list *)malloc(sizeof(devices_list)); |
614 | device->next = NULL; | |
615 | device->version = 1; | |
616 | device->uuid = malloc(37); | |
617 | uuid_generate(uu); | |
618 | uuid_unparse(uu, device->uuid); | |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
619 | for (i = 0; i < 8; i++) { |
174 | 620 | if (strcmp(param, DEVTYPE[i]) == 0) { |
621 | device->type = i; | |
622 | break; | |
623 | } | |
624 | } | |
625 | device->direction = DEVDIR_UNDEF; | |
209
c5b1dfd83e81
Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents:
208
diff
changeset
|
626 | device->value = device->offset = device->subdevice = device->inuse = 0; |
174 | 627 | device->present = DEVPRESENT_UNDEF; |
628 | device->address = xstrcpy((char *)"Enter address here"); | |
629 | device->gpiopin = -1; | |
630 | device->description = xstrcpy((char *)"Describe me here"); | |
631 | device->comment = xstrcpy((char *)"Comment here"); | |
170 | 632 | |
240
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
633 | #ifdef HAVE_WIRINGPI_H |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
634 | piLock(LOCK_DEVICES); |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
635 | #endif |
174 | 636 | if (Config.devices == NULL) { |
637 | Config.devices = device; | |
638 | } else { | |
639 | for (tmpd = Config.devices; tmpd; tmpd = tmpd->next) { | |
640 | if (tmpd->next == NULL) { | |
641 | tmpd->next = device; | |
642 | break; | |
643 | } | |
157
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
644 | } |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
645 | } |
240
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
646 | #ifdef HAVE_WIRINGPI_H |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
647 | piUnlock(LOCK_DEVICES); |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
648 | #endif |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
649 | syslog(LOG_NOTICE, "Device %s added", device->uuid); |
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
650 | srv_send((char *)"211 Device %s added", device->uuid); |
174 | 651 | return 0; |
157
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
652 | |
174 | 653 | } else { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
654 | srv_send((char *)"503 Parameter error"); |
157
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
655 | return 1; |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
656 | } |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
657 | } |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
658 | |
174 | 659 | if (strcmp(opt, (char *)"DEL") == 0) { |
660 | ||
240
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
661 | #ifdef HAVE_WIRINGPI_H |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
662 | piLock(LOCK_DEVICES); |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
663 | #endif |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
664 | rc = delete_Device(param); |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
665 | #ifdef HAVE_WIRINGPI_H |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
666 | piUnlock(LOCK_DEVICES); |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
667 | #endif |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
668 | if (rc) { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
669 | syslog(LOG_NOTICE, "Device %s deleted", param); |
174 | 670 | srv_send((char *)"211 Device %s deleted", param); |
671 | return 0; | |
672 | } else { | |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
673 | srv_send((char *)"440 No such device"); |
174 | 674 | return 1; |
675 | } | |
676 | } | |
677 | ||
678 | if (strcmp(opt, (char *)"GET") == 0) { | |
679 | for (device = Config.devices; device; device = device->next) { | |
680 | if (strcmp(device->uuid, param) == 0) { | |
325
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
681 | #ifdef HAVE_WIRINGPI_H |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
682 | piLock(LOCK_DEVICES); |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
683 | #endif |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
684 | int my_value = device->value; |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
685 | int my_timestamp = (int)device->timestamp; |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
686 | #ifdef HAVE_WIRINGPI_H |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
687 | piUnlock(LOCK_DEVICES); |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
688 | #endif |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
689 | srv_send((char *)"213 Device record follows:"); |
174 | 690 | srv_send((char *)"TYPE,%s", DEVTYPE[device->type]); |
344
acd840c9fcc0
Fixed Offset label in device editor. Added code to edit pin states for DS2408 and DS2413 1-wire devices.
Michiel Broek <mbroek@mbse.eu>
parents:
331
diff
changeset
|
691 | srv_send((char *)"ADDRESS,%s", device->address); |
174 | 692 | srv_send((char *)"DIRECTION,%s", DEVDIR[device->direction]); |
325
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
693 | srv_send((char *)"VALUE,%d", my_value); |
209
c5b1dfd83e81
Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents:
208
diff
changeset
|
694 | srv_send((char *)"OFFSET,%d", device->offset); |
174 | 695 | srv_send((char *)"PRESENT,%s", DEVPRESENT[device->present]); |
696 | srv_send((char *)"SUBDEVICE,%d", device->subdevice); | |
697 | srv_send((char *)"GPIOPIN,%d", device->gpiopin); | |
698 | srv_send((char *)"DESCRIPTION,%s", device->description); | |
699 | srv_send((char *)"INUSE,%d", device->inuse); | |
700 | srv_send((char *)"COMMENT,%s", device->comment); | |
325
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
701 | srv_send((char *)"TIMESTAMP,%d", my_timestamp); |
174 | 702 | srv_send((char *)"."); |
703 | return 1; | |
704 | } | |
705 | } | |
706 | srv_send((char *)"440 No such device"); | |
707 | return 1; | |
708 | } | |
709 | ||
710 | if (strcmp(opt, (char *)"PUT") == 0) { | |
711 | for (device = Config.devices; device; device = device->next) { | |
712 | if (strcmp(device->uuid, param) == 0) { | |
713 | while (1) { | |
714 | memset((char *)&ibuf, 0, SS_BUFSIZE); | |
715 | fromlen = sizeof(peeraddr_in); | |
716 | rlen = recvfrom(s, ibuf, sizeof(ibuf) -1, 0, (struct sockaddr *)&peeraddr_in, &fromlen); | |
717 | if (rlen == -1) { | |
268
dda91dfa4aa8
All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents:
266
diff
changeset
|
718 | syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno)); |
174 | 719 | srv_send((char *)"518 recfrom(): %s", strerror(errno)); |
720 | return 1; | |
721 | } | |
722 | for (i = 0; i < strlen(ibuf); i++) { | |
723 | if (ibuf[i] == '\n') | |
724 | ibuf[i] = '\0'; | |
725 | if (ibuf[i] == '\r') | |
726 | ibuf[i] = '\0'; | |
727 | } | |
728 | for (i = strlen(ibuf) -1; i > 0; i--) { | |
729 | if (ibuf[i] == ' ') | |
730 | ibuf[i] = '\0'; | |
731 | else | |
732 | break; | |
733 | } | |
734 | if (strlen(ibuf)) { | |
735 | if (debug) { | |
736 | syslog(LOG_NOTICE, "recv: \"%s\"", ibuf); | |
737 | fprintf(stdout, "recv: \"%s\"\n", ibuf); | |
738 | } | |
739 | if (strcmp(ibuf, (char *)".") == 0) { | |
740 | srv_send((char *)"219 Accepted Device record"); | |
741 | return 0; | |
742 | } | |
743 | kwd = strtok(ibuf, ",\0"); | |
744 | val = strtok(NULL, "\0"); | |
745 | if (kwd && val) { | |
746 | if (strcmp(kwd, (char *)"TYPE") == 0) { | |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
747 | for (i = 0; i < 8; i++) { |
174 | 748 | if (strcmp(val, DEVTYPE[i]) == 0) { |
325
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
749 | #ifdef HAVE_WIRINGPI_H |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
750 | piLock(LOCK_DEVICES); |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
751 | #endif |
276
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
752 | if (device->type != i) |
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
753 | syslog(LOG_NOTICE, "Device %s changed type %s to %s", device->uuid, DEVTYPE[device->type], DEVTYPE[i]); |
174 | 754 | device->type = i; |
325
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
755 | #ifdef HAVE_WIRINGPI_H |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
756 | piUnlock(LOCK_DEVICES); |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
757 | #endif |
174 | 758 | break; |
759 | } | |
760 | } | |
761 | ||
762 | } else if (strcmp(kwd, (char *)"DIRECTION") == 0) { | |
763 | for (i = 0; i < 7; i++) { | |
764 | if (strcmp(val, DEVDIR[i]) == 0) { | |
325
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
765 | #ifdef HAVE_WIRINGPI_H |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
766 | piLock(LOCK_DEVICES); |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
767 | #endif |
276
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
768 | if (device->direction != i) |
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
769 | syslog(LOG_NOTICE, "Device %s changed direction %s to %s", device->uuid, DEVDIR[device->type], DEVDIR[i]); |
174 | 770 | device->direction = i; |
325
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
771 | #ifdef HAVE_WIRINGPI_H |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
772 | piUnlock(LOCK_DEVICES); |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
773 | #endif |
174 | 774 | break; |
775 | } | |
776 | } | |
777 | ||
778 | } else if (strcmp(kwd, (char *)"VALUE") == 0) { | |
276
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
779 | if (sscanf(val, "%d", &ival) == 1) { |
325
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
780 | #ifdef HAVE_WIRINGPI_H |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
781 | piLock(LOCK_DEVICES); |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
782 | #endif |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
783 | if (device->value != ival) |
276
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
784 | syslog(LOG_NOTICE, "Device %s changed value %d to %d", device->uuid, device->value, ival); |
174 | 785 | device->value = ival; |
325
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
786 | #ifdef HAVE_WIRINGPI_H |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
787 | piUnlock(LOCK_DEVICES); |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
788 | #endif |
276
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
789 | } |
174 | 790 | |
209
c5b1dfd83e81
Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents:
208
diff
changeset
|
791 | } else if (strcmp(kwd, (char *)"OFFSET") == 0) { |
276
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
792 | if (sscanf(val, "%d", &ival) == 1) { |
325
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
793 | #ifdef HAVE_WIRINGPI_H |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
794 | piLock(LOCK_DEVICES); |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
795 | #endif |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
796 | if (device->offset != ival) |
276
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
797 | syslog(LOG_NOTICE, "Device %s changed offset %d to %d", device->uuid, device->offset, ival); |
209
c5b1dfd83e81
Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents:
208
diff
changeset
|
798 | device->offset = ival; |
325
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
799 | #ifdef HAVE_WIRINGPI_H |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
800 | piUnlock(LOCK_DEVICES); |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
801 | #endif |
276
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
802 | } |
209
c5b1dfd83e81
Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents:
208
diff
changeset
|
803 | |
174 | 804 | } else if (strcmp(kwd, (char *)"PRESENT") == 0) { |
805 | for (i = 0; i < 4; i++) { | |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
806 | if (strcmp(val, DEVPRESENT[i]) == 0) { |
325
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
807 | #ifdef HAVE_WIRINGPI_H |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
808 | piLock(LOCK_DEVICES); |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
809 | #endif |
276
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
810 | if (device->present != i) |
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
811 | syslog(LOG_NOTICE, "Device %s changed present %s to %s", device->uuid, DEVPRESENT[device->present], DEVPRESENT[i]); |
174 | 812 | device->present = i; |
325
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
813 | #ifdef HAVE_WIRINGPI_H |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
814 | piUnlock(LOCK_DEVICES); |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
815 | #endif |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
816 | break; |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
817 | } |
174 | 818 | } |
819 | ||
820 | } else if (strcmp(kwd, (char *)"ADDRESS") == 0) { | |
325
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
821 | #ifdef HAVE_WIRINGPI_H |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
822 | piLock(LOCK_DEVICES); |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
823 | #endif |
276
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
824 | if (device->address) { |
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
825 | if (strcmp(device->address, val)) |
278
76c8a6f18e4d
GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
276
diff
changeset
|
826 | syslog(LOG_NOTICE, "Device %s changed address `%s' to `%s'", device->uuid, device->address, val); |
174 | 827 | free(device->address); |
276
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
828 | } |
174 | 829 | device->address = xstrcpy(val); |
325
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
830 | #ifdef HAVE_WIRINGPI_H |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
831 | piUnlock(LOCK_DEVICES); |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
832 | #endif |
174 | 833 | |
834 | } else if (strcmp(kwd, (char *)"SUBDEVICE") == 0) { | |
276
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
835 | if (sscanf(val, "%d", &ival) == 1) { |
325
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
836 | #ifdef HAVE_WIRINGPI_H |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
837 | piLock(LOCK_DEVICES); |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
838 | #endif |
276
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
839 | if (device->subdevice != ival) |
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
840 | syslog(LOG_NOTICE, "Device %s changed subdevice %d to %d", device->uuid, device->subdevice, ival); |
174 | 841 | device->subdevice = ival; |
325
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
842 | #ifdef HAVE_WIRINGPI_H |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
843 | piUnlock(LOCK_DEVICES); |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
844 | #endif |
276
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
845 | } |
174 | 846 | |
847 | } else if (strcmp(kwd, (char *)"GPIOPIN") == 0) { | |
276
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
848 | if (sscanf(val, "%d", &ival) == 1) { |
325
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
849 | #ifdef HAVE_WIRINGPI_H |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
850 | piLock(LOCK_DEVICES); |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
851 | #endif |
276
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
852 | if (device->gpiopin != ival) |
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
853 | syslog(LOG_NOTICE, "Device %s changed gpiopin %d to %d", device->uuid, device->gpiopin, ival); |
174 | 854 | device->gpiopin = ival; |
325
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
855 | #ifdef HAVE_WIRINGPI_H |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
856 | piUnlock(LOCK_DEVICES); |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
857 | #endif |
276
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
858 | } |
174 | 859 | |
860 | } else if (strcmp(kwd, (char *)"DESCRIPTION") == 0) { | |
325
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
861 | #ifdef HAVE_WIRINGPI_H |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
862 | piLock(LOCK_DEVICES); |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
863 | #endif |
276
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
864 | if (device->description) { |
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
865 | if (strcmp(device->description, val)) |
278
76c8a6f18e4d
GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
276
diff
changeset
|
866 | syslog(LOG_NOTICE, "Device %s changed description `%s' to `%s'", device->uuid, device->description, val); |
174 | 867 | free(device->description); |
276
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
868 | } |
174 | 869 | device->description = xstrcpy(val); |
325
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
870 | #ifdef HAVE_WIRINGPI_H |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
871 | piUnlock(LOCK_DEVICES); |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
872 | #endif |
174 | 873 | |
874 | } else if (strcmp(kwd, (char *)"COMMENT") == 0) { | |
325
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
875 | #ifdef HAVE_WIRINGPI_H |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
876 | piLock(LOCK_DEVICES); |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
877 | #endif |
276
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
878 | if (device->comment) { |
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
879 | if (strcmp(device->comment, val)) |
278
76c8a6f18e4d
GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
276
diff
changeset
|
880 | syslog(LOG_NOTICE, "Device %s changed comment `%s' to `%s'", device->uuid, device->comment, val); |
174 | 881 | free(device->comment); |
276
a19cc3770f09
Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents:
274
diff
changeset
|
882 | } |
174 | 883 | device->comment = xstrcpy(val); |
325
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
884 | #ifdef HAVE_WIRINGPI_H |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
885 | piUnlock(LOCK_DEVICES); |
35b6f6605ae3
More device locks in the network server
Michiel Broek <mbroek@mbse.eu>
parents:
313
diff
changeset
|
886 | #endif |
174 | 887 | |
888 | } | |
889 | } | |
890 | } | |
891 | } | |
892 | } | |
893 | } | |
894 | srv_send((char *)"440 No such device"); | |
895 | return 1; | |
896 | } | |
897 | ||
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
898 | srv_send((char *)"504 Subcommand error"); |
157
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
899 | return 1; |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
900 | } |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
901 | |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
902 | |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
903 | |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
904 | /* |
206
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
905 | * GLOBAL GET |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
906 | * GLOBAL PUT |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
907 | */ |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
908 | int cmd_global(char *buf) |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
909 | { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
910 | char *opt, *kwd, *val, ibuf[SS_BUFSIZE]; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
911 | int ival, i, rlen; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
912 | socklen_t fromlen; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
913 | |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
914 | opt = strtok(buf, " \0"); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
915 | opt = strtok(NULL, "\0"); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
916 | |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
917 | if (opt == NULL) { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
918 | srv_send((char *)"501 Subcommand missing"); |
206
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
919 | return 1; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
920 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
921 | |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
922 | if (strcmp(opt, (char *)"GET") == 0) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
923 | srv_send((char *)"213 Global Settings record follows:"); |
269
dc88583a068d
All web screens now show the program name and version
Michiel Broek <mbroek@mbse.eu>
parents:
268
diff
changeset
|
924 | srv_send((char *)"RELEASE,%s", VERSION); |
206
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
925 | srv_send((char *)"NAME,%s", Config.name); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
926 | srv_send((char *)"PORT,%d", Config.my_port); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
927 | srv_send((char *)"TEMPFORMAT,%c", Config.tempFormat); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
928 | srv_send((char *)"TEMP_ADDRESS,%s", Config.temp_address); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
929 | srv_send((char *)"TEMP_STATE,%s", TEMPSTATE[Config.temp_state]); |
208
934d45d9751d
Added room temperature and humidity to the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
206
diff
changeset
|
930 | srv_send((char *)"TEMP_VALUE,%.1f", Config.temp_value / 1000.0); |
206
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
931 | srv_send((char *)"HUM_ADDRESS,%s", Config.hum_address); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
932 | srv_send((char *)"HUM_STATE,%s", TEMPSTATE[Config.hum_state]); |
208
934d45d9751d
Added room temperature and humidity to the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
206
diff
changeset
|
933 | srv_send((char *)"HUM_VALUE,%.0f", Config.hum_value / 1000.0); |
206
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
934 | #ifdef HAVE_WIRINGPI_H |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
935 | srv_send((char *)"LCD_COLS,%d", Config.lcd_cols); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
936 | srv_send((char *)"LCD_ROWS,%d", Config.lcd_rows); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
937 | #endif |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
938 | srv_send((char *)"."); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
939 | return 1; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
940 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
941 | |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
942 | if (strcmp(opt, (char *)"PUT") == 0) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
943 | while (1) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
944 | memset((char *)&ibuf, 0, SS_BUFSIZE); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
945 | fromlen = sizeof(peeraddr_in); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
946 | rlen = recvfrom(s, ibuf, sizeof(ibuf) -1, 0, (struct sockaddr *)&peeraddr_in, &fromlen); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
947 | if (rlen == -1) { |
268
dda91dfa4aa8
All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents:
266
diff
changeset
|
948 | syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno)); |
206
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
949 | srv_send((char *)"518 recfrom(): %s", strerror(errno)); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
950 | return 1; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
951 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
952 | for (i = 0; i < strlen(ibuf); i++) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
953 | if (ibuf[i] == '\n') |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
954 | ibuf[i] = '\0'; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
955 | if (ibuf[i] == '\r') |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
956 | ibuf[i] = '\0'; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
957 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
958 | for (i = strlen(ibuf) -1; i > 0; i--) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
959 | if (ibuf[i] == ' ') |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
960 | ibuf[i] = '\0'; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
961 | else |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
962 | break; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
963 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
964 | if (strlen(ibuf)) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
965 | if (debug) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
966 | syslog(LOG_NOTICE, "recv: \"%s\"", ibuf); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
967 | fprintf(stdout, "recv: \"%s\"\n", ibuf); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
968 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
969 | if (strcmp(ibuf, (char *)".") == 0) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
970 | srv_send((char *)"219 Accepted Global record"); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
971 | return 0; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
972 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
973 | kwd = strtok(ibuf, ",\0"); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
974 | val = strtok(NULL, "\0"); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
975 | if (kwd) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
976 | if (strcmp(kwd, (char *)"NAME") == 0) { |
278
76c8a6f18e4d
GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
276
diff
changeset
|
977 | if (val && Config.name && strcmp(val, Config.name)) |
76c8a6f18e4d
GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
276
diff
changeset
|
978 | syslog(LOG_NOTICE, "Global name `%s' to `%s'", Config.name, val); |
206
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
979 | if (Config.name) |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
980 | free(Config.name); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
981 | if (val) |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
982 | Config.name = xstrcpy(val); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
983 | else |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
984 | Config.name = NULL; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
985 | |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
986 | } else if (val && (strcmp(kwd, (char *)"PORT") == 0)) { |
278
76c8a6f18e4d
GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
276
diff
changeset
|
987 | if (sscanf(val, "%d", &ival) == 1) { |
76c8a6f18e4d
GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
276
diff
changeset
|
988 | if (Config.my_port != ival) |
76c8a6f18e4d
GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
276
diff
changeset
|
989 | syslog(LOG_NOTICE, "Global port %d to %d", Config.my_port, ival); |
206
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
990 | Config.my_port = ival; |
278
76c8a6f18e4d
GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
276
diff
changeset
|
991 | } |
206
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
992 | |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
993 | } else if (val && (strcmp(kwd, (char *)"TEMPFORMAT") == 0)) { |
278
76c8a6f18e4d
GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
276
diff
changeset
|
994 | if ((val[0] == 'C') || (val[0] == 'F')) { |
76c8a6f18e4d
GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
276
diff
changeset
|
995 | if (Config.tempFormat != val[0]) |
76c8a6f18e4d
GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
276
diff
changeset
|
996 | syslog(LOG_NOTICE, "Global port %c to %c", Config.tempFormat, val[0]); |
206
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
997 | Config.tempFormat = val[0]; |
278
76c8a6f18e4d
GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
276
diff
changeset
|
998 | } |
206
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
999 | |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1000 | } else if (strcmp(kwd, (char *)"TEMP_ADDRESS") == 0) { |
278
76c8a6f18e4d
GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
276
diff
changeset
|
1001 | if (val && Config.temp_address && (strcmp(val, Config.temp_address))) |
76c8a6f18e4d
GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
276
diff
changeset
|
1002 | syslog(LOG_NOTICE, "Global temperature address `%s' to `%s'", Config.temp_address, val); |
206
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1003 | if (Config.temp_address) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1004 | device_count(FALSE, Config.temp_address); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1005 | free(Config.temp_address); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1006 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1007 | if (val) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1008 | Config.temp_address = xstrcpy(val); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1009 | device_count(TRUE, Config.temp_address); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1010 | } else |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1011 | Config.temp_address = NULL; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1012 | |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1013 | } else if (strcmp(kwd, (char *)"HUM_ADDRESS") == 0) { |
278
76c8a6f18e4d
GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
276
diff
changeset
|
1014 | if (val && Config.hum_address && (strcmp(val, Config.hum_address))) |
76c8a6f18e4d
GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
276
diff
changeset
|
1015 | syslog(LOG_NOTICE, "Global humidity address `%s' to `%s'", Config.hum_address, val); |
206
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1016 | if (Config.hum_address) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1017 | device_count(FALSE, Config.hum_address); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1018 | free(Config.hum_address); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1019 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1020 | if (val) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1021 | Config.hum_address = xstrcpy(val); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1022 | device_count(TRUE, Config.hum_address); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1023 | } else |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1024 | Config.hum_address = NULL; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1025 | |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1026 | #ifdef HAVE_WIRINGPI_H |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1027 | } else if (val && (strcmp(kwd, (char *)"LCD_COLS") == 0)) { |
278
76c8a6f18e4d
GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
276
diff
changeset
|
1028 | if (sscanf(val, "%d", &ival) == 1) { |
76c8a6f18e4d
GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
276
diff
changeset
|
1029 | if (Config.lcd_cols != ival) |
76c8a6f18e4d
GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
276
diff
changeset
|
1030 | syslog(LOG_NOTICE, "Global LCD columns %d to %d", Config.lcd_cols, ival); |
206
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1031 | Config.lcd_cols = ival; |
278
76c8a6f18e4d
GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
276
diff
changeset
|
1032 | } |
206
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1033 | |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1034 | } else if (val && (strcmp(kwd, (char *)"LCD_ROWS") == 0)) { |
278
76c8a6f18e4d
GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
276
diff
changeset
|
1035 | if (sscanf(val, "%d", &ival) == 1) { |
76c8a6f18e4d
GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
276
diff
changeset
|
1036 | if (Config.lcd_rows != ival) |
76c8a6f18e4d
GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
276
diff
changeset
|
1037 | syslog(LOG_NOTICE, "Global LCD rows %d to %d", Config.lcd_rows, ival); |
206
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1038 | Config.lcd_rows = ival; |
278
76c8a6f18e4d
GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
276
diff
changeset
|
1039 | } |
206
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1040 | #endif |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1041 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1042 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1043 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1044 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1045 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1046 | |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1047 | srv_send((char *)"504 Subcommand error"); |
206
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1048 | return 1; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1049 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1050 | |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1051 | |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1052 | |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1053 | /* |
81 | 1054 | * LIST |
120 | 1055 | * LIST LOG |
81 | 1056 | */ |
1057 | int cmd_list(char *buf) | |
1058 | { | |
299
d1c52fb43e30
Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents:
293
diff
changeset
|
1059 | char *opt, *param, *filename, q[5], buffer[256], outbuf[256]; |
358
8b7ef338bf49
Plot room temperature on the dashboard.
Michiel Broek <mbroek@mbse.eu>
parents:
356
diff
changeset
|
1060 | char *date_n, *mode_n, *air_n, *beer_n, *target_n, *heater_n, *cooler_n, *room_n; |
299
d1c52fb43e30
Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents:
293
diff
changeset
|
1061 | char *heater_u, *cooler_u; |
300
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1062 | int heater_l = 0, cooler_l = 0, h = 0, c = 0, heat_used = 0, cool_used = 0, lines = 0, graphstep = 0; |
84 | 1063 | units_list *unit; |
120 | 1064 | FILE *fp; |
358
8b7ef338bf49
Plot room temperature on the dashboard.
Michiel Broek <mbroek@mbse.eu>
parents:
356
diff
changeset
|
1065 | float room_t; |
81 | 1066 | |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1067 | opt = strtok(buf, " \0"); |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1068 | opt = strtok(NULL, " \0"); |
84 | 1069 | |
81 | 1070 | if (opt == NULL) { |
92 | 1071 | /* |
1072 | * Default, list available units | |
1073 | */ | |
81 | 1074 | srv_send((char *)"212 Fermenter list follows:"); |
1075 | 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
|
1076 | srv_send((char *)"%s,%s,%s", unit->uuid, unit->name, UNITMODE[unit->mode]); |
81 | 1077 | } |
1078 | srv_send((char *)"."); | |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1079 | return 1; |
92 | 1080 | |
120 | 1081 | } else if (strcmp(opt, (char *)"LOG") == 0) { |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1082 | |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1083 | param = strtok(NULL, "\0"); |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1084 | if (param == NULL) { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1085 | srv_send((char *)"502 Parameter missing"); |
120 | 1086 | return 1; |
1087 | } | |
1088 | ||
266
07819a7ad3c1
Better log output for web graphs. Webgraphs can now display heater and cooler usage.
Michiel Broek <mbroek@mbse.eu>
parents:
264
diff
changeset
|
1089 | q[0] = q[1] = q[2] = q[3] = q[4] = 'a'; |
120 | 1090 | for (unit = Config.units; unit; unit = unit->next) { |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1091 | if (strcmp(param, unit->uuid) == 0) |
120 | 1092 | break; |
1093 | } | |
1094 | ||
1095 | srv_send((char *)"212 Logfile list follows:"); | |
1096 | if (getenv((char *)"USER") == NULL) { | |
1097 | filename = xstrcpy((char *)"/root"); | |
1098 | } else { | |
1099 | filename = xstrcpy(getenv((char *)"HOME")); | |
1100 | } | |
1101 | filename = xstrcat(filename, (char *)"/.thermferm/log/"); | |
1102 | filename = xstrcat(filename, unit->name); | |
1103 | filename = xstrcat(filename, (char *)".log"); | |
1104 | if ((fp = fopen(filename, "r"))) { | |
300
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1105 | |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1106 | /* |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1107 | * Count the lines in the logfile |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1108 | */ |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1109 | lines = 0; |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1110 | while (fgets(buffer, sizeof(buffer)-1, fp) != NULL) { |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1111 | lines++; |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1112 | } |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1113 | fseek(fp, 0L, SEEK_SET); |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1114 | /* |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1115 | * We have counted the lines in the logfile including the header lines. |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1116 | * The header lines should be ignored but there are so few of them, we |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1117 | * just include them in the total. |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1118 | * Now find a reasonable interval of lines to sent to the client. |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1119 | */ |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1120 | for (graphstep = 1; graphstep <= MAX_INTERVALS; graphstep++) { |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1121 | if (lines < GRAPH_DATALINES[graphstep]) { |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1122 | break; |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1123 | } |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1124 | } |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1125 | syslog(LOG_NOTICE, "LIST LOG %s: lines=%d, interval=%d, graphstep=%d", unit->name, lines, GRAPH_INTERVAL[graphstep], graphstep); |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1126 | |
120 | 1127 | while (fgets(buffer, sizeof(buffer)-1, fp) != NULL) { |
299
d1c52fb43e30
Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents:
293
diff
changeset
|
1128 | /* |
d1c52fb43e30
Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents:
293
diff
changeset
|
1129 | * 2014-11-15 18:39,BEER,20.312,19.750,20.0,0,NA,NA,NA,78105,NA,NA |
d1c52fb43e30
Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents:
293
diff
changeset
|
1130 | */ |
300
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1131 | q[0] = buffer[11]; |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1132 | q[1] = buffer[12]; |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1133 | q[2] = buffer[14]; |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1134 | q[3] = buffer[15]; |
120 | 1135 | buffer[strlen(buffer) -1] = '\0'; |
299
d1c52fb43e30
Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents:
293
diff
changeset
|
1136 | date_n = strtok(buffer, ",\0"); /* timestamp */ |
d1c52fb43e30
Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents:
293
diff
changeset
|
1137 | mode_n = strtok(NULL, ",\0"); /* unit mode */ |
d1c52fb43e30
Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents:
293
diff
changeset
|
1138 | air_n = strtok(NULL, ",\0"); /* air temp */ |
d1c52fb43e30
Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents:
293
diff
changeset
|
1139 | beer_n = strtok(NULL, ",\0"); /* beer temp */ |
d1c52fb43e30
Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents:
293
diff
changeset
|
1140 | target_n = strtok(NULL, ",\0"); /* target temp */ |
d1c52fb43e30
Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents:
293
diff
changeset
|
1141 | heater_n = strtok(NULL, ",\0"); /* current heater state */ |
d1c52fb43e30
Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents:
293
diff
changeset
|
1142 | cooler_n = strtok(NULL, ",\0"); /* current cooler state */ |
d1c52fb43e30
Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents:
293
diff
changeset
|
1143 | heater_u = strtok(NULL, ",\0"); /* current fan state */ |
d1c52fb43e30
Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents:
293
diff
changeset
|
1144 | heater_u = strtok(NULL, ",\0"); /* current door state */ |
d1c52fb43e30
Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents:
293
diff
changeset
|
1145 | heater_u = strtok(NULL, ",\0"); /* heater use counter */ |
d1c52fb43e30
Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents:
293
diff
changeset
|
1146 | cooler_u = strtok(NULL, ",\0"); /* cooler use counter */ |
358
8b7ef338bf49
Plot room temperature on the dashboard.
Michiel Broek <mbroek@mbse.eu>
parents:
356
diff
changeset
|
1147 | room_n = strtok(NULL, ",\0"); /* fan use counter */ |
8b7ef338bf49
Plot room temperature on the dashboard.
Michiel Broek <mbroek@mbse.eu>
parents:
356
diff
changeset
|
1148 | room_n = strtok(NULL, ",\0"); /* room temperature */ |
264
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
1149 | |
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
1150 | if (strncmp(mode_n, (char *)"Mode", 4)) { |
266
07819a7ad3c1
Better log output for web graphs. Webgraphs can now display heater and cooler usage.
Michiel Broek <mbroek@mbse.eu>
parents:
264
diff
changeset
|
1151 | /* |
300
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1152 | * Output a line at the right intervals |
266
07819a7ad3c1
Better log output for web graphs. Webgraphs can now display heater and cooler usage.
Michiel Broek <mbroek@mbse.eu>
parents:
264
diff
changeset
|
1153 | */ |
300
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1154 | if (((graphstep == 1)) || |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1155 | ((graphstep == 2) && (q[3] == '0' || q[3] == '5')) || |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1156 | ((graphstep == 3) && ((q[2] == '0' && q[3] == '0') || (q[2] == '1' && q[3] == '5') || (q[2] == '3' && q[3] == '0') || (q[2] == '4' && q[3] == '5'))) || |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1157 | ((graphstep == 4) && ((q[2] == '0' && q[3] == '0') || (q[2] == '3' && q[3] == '0'))) || |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1158 | ((graphstep == 5) && (q[2] == '0' && q[3] == '0')) ) { |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1159 | heat_used = cool_used = 0; |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1160 | if (strcmp(heater_u, "NA") && (sscanf(heater_u, "%d", &h) == 1)) { |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1161 | if (h && heater_l) { |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1162 | heat_used = ((h - heater_l) * 100) / (GRAPH_INTERVAL[graphstep] * 60); |
299
d1c52fb43e30
Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents:
293
diff
changeset
|
1163 | } |
300
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1164 | } |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1165 | if (strcmp(cooler_u, "NA") && (sscanf(cooler_u, "%d", &c) == 1)) { |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1166 | if (c && cooler_l) { |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1167 | cool_used = ((c - cooler_l) * 100) / (GRAPH_INTERVAL[graphstep] * 60); |
299
d1c52fb43e30
Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents:
293
diff
changeset
|
1168 | } |
300
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1169 | } |
358
8b7ef338bf49
Plot room temperature on the dashboard.
Michiel Broek <mbroek@mbse.eu>
parents:
356
diff
changeset
|
1170 | if (room_n) |
8b7ef338bf49
Plot room temperature on the dashboard.
Michiel Broek <mbroek@mbse.eu>
parents:
356
diff
changeset
|
1171 | sscanf(room_n, "%f", &room_t); |
8b7ef338bf49
Plot room temperature on the dashboard.
Michiel Broek <mbroek@mbse.eu>
parents:
356
diff
changeset
|
1172 | else |
8b7ef338bf49
Plot room temperature on the dashboard.
Michiel Broek <mbroek@mbse.eu>
parents:
356
diff
changeset
|
1173 | room_t = 0.0; |
8b7ef338bf49
Plot room temperature on the dashboard.
Michiel Broek <mbroek@mbse.eu>
parents:
356
diff
changeset
|
1174 | snprintf(outbuf, 255, "%s,%s,%s,%s,%s,%s,%s,%d,%d,%.1f", |
8b7ef338bf49
Plot room temperature on the dashboard.
Michiel Broek <mbroek@mbse.eu>
parents:
356
diff
changeset
|
1175 | date_n, mode_n, air_n, beer_n, target_n, heater_n, cooler_n, heat_used, cool_used, room_t); |
300
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1176 | srv_send(outbuf); |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1177 | if (h && strcmp(heater_u, "NA")) |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1178 | heater_l = h; |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1179 | if (c & strcmp(cooler_u, "NA")) |
4ce46ff3e37d
The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents:
299
diff
changeset
|
1180 | cooler_l = c; |
120 | 1181 | } |
266
07819a7ad3c1
Better log output for web graphs. Webgraphs can now display heater and cooler usage.
Michiel Broek <mbroek@mbse.eu>
parents:
264
diff
changeset
|
1182 | } |
120 | 1183 | } |
1184 | } | |
1185 | free(filename); | |
1186 | filename = NULL; | |
1187 | srv_send((char *)"."); | |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1188 | return 1; |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1189 | } |
120 | 1190 | |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1191 | srv_send((char *)"504 Subcommand error"); |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1192 | return 1; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1193 | } |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1194 | |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1195 | |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1196 | |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1197 | /* |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1198 | * PROFILE ADD name Add a new profile |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1199 | * PROFILE DEL uuid Delete profile with uuid |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1200 | * PROFILE LIST List available profiles |
258
e02393b29733
Updated web dashboard layout
Michiel Broek <mbroek@mbse.eu>
parents:
249
diff
changeset
|
1201 | * PROFILE GET uuid Get profile record |
e02393b29733
Updated web dashboard layout
Michiel Broek <mbroek@mbse.eu>
parents:
249
diff
changeset
|
1202 | * PROFILE PUT uuid Put profile record |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1203 | * PROFILE GETS uuid Get profile steps list |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1204 | * PROFILE PUTS uuid Put profile steps list |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1205 | */ |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1206 | int cmd_profile(char *buf) |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1207 | { |
192
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1208 | char ibuf[SS_BUFSIZE], *sstep, *rest, *targ, *param, *kwd, *val; |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1209 | int i, j, rlen, istep, irest; |
192
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1210 | float ftarg, fval; |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1211 | socklen_t fromlen; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1212 | char *opt; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1213 | profiles_list *profile, *tmpp; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1214 | prof_step *step, *olds; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1215 | uuid_t uu; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1216 | |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1217 | opt = strtok(buf, " \0"); |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1218 | opt = strtok(NULL, " \0"); |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1219 | |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1220 | if (opt == NULL) { |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1221 | srv_send((char *)"501 Subcommand missing"); |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1222 | return 1; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1223 | } |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1224 | |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1225 | if (strcmp(opt, (char *)"LIST") == 0) { |
86
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
1226 | /* |
92 | 1227 | * Fermenting profiles |
86
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
1228 | */ |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1229 | srv_send((char *)"212 Profiles list follows:"); |
92 | 1230 | 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
|
1231 | j = 0; |
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
1232 | 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
|
1233 | j++; |
136
264e5ee5abfc
Profiles now have a busy state
Michiel Broek <mbroek@mbse.eu>
parents:
133
diff
changeset
|
1234 | 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
|
1235 | } |
92 | 1236 | srv_send((char *)"."); |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1237 | return 1; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1238 | } |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1239 | |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1240 | param = strtok(NULL, "\0"); |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1241 | if (param == NULL) { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1242 | srv_send((char *)"502 Parameter missing"); |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1243 | return 1; |
81 | 1244 | } |
1245 | ||
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1246 | if (strcmp(opt, (char *)"ADD") == 0) { |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1247 | profile = (profiles_list *)malloc(sizeof(profiles_list)); |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1248 | profile->next = NULL; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1249 | profile->version = 1; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1250 | profile->uuid = malloc(37); |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1251 | uuid_generate(uu); |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1252 | uuid_unparse(uu, profile->uuid); |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1253 | profile->name = xstrcpy(param); |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1254 | profile->busy = 0; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1255 | profile->inittemp = 20.0; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1256 | profile->steps = NULL; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1257 | if (Config.profiles == NULL) { |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1258 | Config.profiles = profile; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1259 | } else { |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1260 | for (tmpp = Config.profiles; tmpp; tmpp = tmpp->next) { |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1261 | if (tmpp->next == NULL) { |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1262 | tmpp->next = profile; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1263 | break; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1264 | } |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1265 | } |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1266 | } |
81 | 1267 | |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1268 | syslog(LOG_NOTICE, "Profile %s added", profile->uuid); |
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1269 | srv_send((char *)"211 Profile %s added", profile->uuid); |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1270 | return 0; |
81 | 1271 | |
1272 | ||
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1273 | } else if (strcmp(opt, (char *)"DEL") == 0) { |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1274 | if (delete_Profile(param)) { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1275 | syslog(LOG_NOTICE, "Profile %s deleted", param); |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1276 | srv_send((char *)"211 Profile %s deleted", param); |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1277 | return 0; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1278 | } else { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1279 | srv_send((char *)"440 No such 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
|
1280 | 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
|
1281 | } |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1282 | |
192
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1283 | } else if (strcmp(opt, (char *)"GET") == 0) { |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1284 | for (profile = Config.profiles; profile; profile = profile->next) { |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1285 | if (strcmp(profile->uuid, param) == 0) { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1286 | srv_send((char *)"213 Profile record follows:"); |
192
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1287 | srv_send((char *)"UUID,%s", profile->uuid); |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1288 | srv_send((char *)"NAME,%s", profile->name); |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1289 | srv_send((char *)"INITTEMP,%.1f", profile->inittemp); |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1290 | srv_send((char *)"."); |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1291 | return 1; |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1292 | } |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1293 | } |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1294 | srv_send((char *)"440 No such profile"); |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1295 | return 1; |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1296 | |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1297 | } else if (strcmp(opt, (char *)"PUT") == 0) { |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1298 | for (profile = Config.profiles; profile; profile = profile->next) { |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1299 | if (strcmp(profile->uuid, param) == 0) { |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1300 | while (1) { |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1301 | memset((char *)&ibuf, 0, SS_BUFSIZE); |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1302 | fromlen = sizeof(peeraddr_in); |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1303 | rlen = recvfrom(s, ibuf, sizeof(ibuf) -1, 0, (struct sockaddr *)&peeraddr_in, &fromlen); |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1304 | if (rlen == -1) { |
268
dda91dfa4aa8
All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents:
266
diff
changeset
|
1305 | syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno)); |
192
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1306 | srv_send((char *)"518 recfrom(): %s", strerror(errno)); |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1307 | return 1; |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1308 | } |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1309 | for (i = 0; i < strlen(ibuf); i++) { |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1310 | if (ibuf[i] == '\n') |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1311 | ibuf[i] = '\0'; |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1312 | if (ibuf[i] == '\r') |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1313 | ibuf[i] = '\0'; |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1314 | } |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1315 | for (i = strlen(ibuf) -1; i > 0; i--) { |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1316 | if (ibuf[i] == ' ') |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1317 | ibuf[i] = '\0'; |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1318 | else |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1319 | break; |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1320 | } |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1321 | if (strlen(ibuf)) { |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1322 | if (debug) { |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1323 | syslog(LOG_NOTICE, "recv: \"%s\"", ibuf); |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1324 | fprintf(stdout, "recv: \"%s\"\n", ibuf); |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1325 | } |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1326 | if (strcmp(ibuf, (char *)".") == 0) { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1327 | srv_send((char *)"219 Accepted Profile record"); |
192
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1328 | return 0; |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1329 | } |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1330 | kwd = strtok(ibuf, ",\0"); |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1331 | val = strtok(NULL, "\0"); |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1332 | if (kwd && val) { |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1333 | if (strcmp(kwd, (char *)"NAME") == 0) { |
279
4c505414435c
PROFILE PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
278
diff
changeset
|
1334 | if (profile->name) { |
4c505414435c
PROFILE PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
278
diff
changeset
|
1335 | if (strcmp(profile->name, val)) |
4c505414435c
PROFILE PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
278
diff
changeset
|
1336 | syslog(LOG_NOTICE, "Profile %s name `%s' to `%s'", profile->uuid, profile->name, val); |
192
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1337 | free(profile->name); |
279
4c505414435c
PROFILE PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
278
diff
changeset
|
1338 | } |
192
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1339 | profile->name = xstrcpy(val); |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1340 | } else if (strcmp(kwd, (char *)"INITTEMP") == 0) { |
279
4c505414435c
PROFILE PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
278
diff
changeset
|
1341 | if (sscanf(val, "%f", &fval) == 1) { |
4c505414435c
PROFILE PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
278
diff
changeset
|
1342 | if (profile->inittemp != fval) |
4c505414435c
PROFILE PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
278
diff
changeset
|
1343 | syslog(LOG_NOTICE, "Profile %s initial temperature %.1f to %.1f", profile->uuid, profile->inittemp, fval); |
192
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1344 | profile->inittemp = fval; |
279
4c505414435c
PROFILE PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
278
diff
changeset
|
1345 | } |
192
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1346 | } |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1347 | } |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1348 | } |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1349 | } |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1350 | } |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1351 | } |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1352 | srv_send((char *)"440 No such profile"); |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1353 | return 1; |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
1354 | |
140
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1355 | } else if (strcmp(opt, (char *)"GETS") == 0) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1356 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1357 | for (profile = Config.profiles; profile; profile = profile->next) { |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1358 | if (strcmp(profile->uuid, param) == 0) { |
140
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1359 | srv_send((char *)"215 Profile steps follow:"); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1360 | for (step = profile->steps; step; step = step->next) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1361 | 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
|
1362 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1363 | srv_send((char *)"."); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1364 | return 1; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1365 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1366 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1367 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1368 | srv_send((char *)"440 No such profile"); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1369 | return 1; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1370 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1371 | } else if (strcmp(opt, (char *)"PUTS") == 0) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1372 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1373 | for (profile = Config.profiles; profile; profile = profile->next) { |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1374 | if (strcmp(profile->uuid, param) == 0) { |
140
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1375 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1376 | if (profile->steps) { |
280
de3dc781ba65
PROFILE PUTS command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
279
diff
changeset
|
1377 | syslog(LOG_NOTICE, "PROFILE PUTS %s erased all old steps", profile->uuid); |
140
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1378 | for (step = profile->steps; step; step = olds) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1379 | olds = step->next; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1380 | free(step); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1381 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1382 | profile->steps = NULL; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1383 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1384 | |
280
de3dc781ba65
PROFILE PUTS command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
279
diff
changeset
|
1385 | j = 0; |
140
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1386 | while (1) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1387 | memset((char *)&ibuf, 0, SS_BUFSIZE); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1388 | fromlen = sizeof(peeraddr_in); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1389 | 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
|
1390 | if (rlen == -1) { |
268
dda91dfa4aa8
All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents:
266
diff
changeset
|
1391 | syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno)); |
140
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1392 | srv_send((char *)"518 recfrom(): %s", strerror(errno)); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1393 | return 1; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1394 | } else { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1395 | for (i = 0; i < strlen(ibuf); i++) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1396 | if (ibuf[i] == '\n') |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1397 | ibuf[i] = '\0'; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1398 | if (ibuf[i] == '\r') |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1399 | ibuf[i] = '\0'; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1400 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1401 | for (i = strlen(ibuf) -1; i > 0; i--) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1402 | if (ibuf[i] == ' ') |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1403 | ibuf[i] = '\0'; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1404 | else |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1405 | break; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1406 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1407 | if (strlen(ibuf)) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1408 | if (debug) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1409 | syslog(LOG_NOTICE, "recv: \"%s\"", ibuf); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1410 | fprintf(stdout, "recv: \"%s\"\n", ibuf); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1411 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1412 | if (strcmp(ibuf, (char *)".") == 0) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1413 | |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1414 | srv_send((char *)"219 Accepted Profile steps"); |
140
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1415 | return 0; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1416 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1417 | sstep = strtok(ibuf, ",\0"); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1418 | rest = strtok(NULL, ",\0"); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1419 | targ = strtok(NULL, "\0"); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1420 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1421 | if ((sscanf(sstep, "%d", &istep) == 1) && |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1422 | (sscanf(rest, "%d", &irest) == 1) && |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1423 | (sscanf(targ, "%f", &ftarg) == 1)) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1424 | |
280
de3dc781ba65
PROFILE PUTS command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
279
diff
changeset
|
1425 | j++; |
de3dc781ba65
PROFILE PUTS command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
279
diff
changeset
|
1426 | syslog(LOG_NOTICE, "PROFILE PUTS %s add step %d: steptime=%d resttime=%d target=%.1f", |
de3dc781ba65
PROFILE PUTS command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
279
diff
changeset
|
1427 | profile->uuid, j, istep, irest, ftarg); |
140
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1428 | step = (prof_step *)malloc(sizeof(prof_step)); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1429 | step->next = NULL; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1430 | step->version = 1; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1431 | step->steptime = istep; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1432 | step->resttime = irest; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1433 | step->target = ftarg; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1434 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1435 | if (profile->steps == NULL) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1436 | profile->steps = step; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1437 | } else { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1438 | for (olds = profile->steps; olds; olds = olds->next) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1439 | if (olds->next == NULL) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1440 | olds->next = step; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1441 | break; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1442 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1443 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1444 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1445 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1446 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1447 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1448 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1449 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1450 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1451 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1452 | srv_send((char *)"440 No such profile"); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1453 | return 1; |
88 | 1454 | } |
1455 | ||
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1456 | srv_send((char *)"504 Subcommand error"); |
88 | 1457 | return 1; |
1458 | } | |
1459 | ||
1460 | ||
1461 | ||
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1462 | #ifdef USE_SIMULATOR |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1463 | int delete_Simulator(char *uuid) |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1464 | { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1465 | simulator_list *current = Config.simulators; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1466 | simulator_list *previous = NULL; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1467 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1468 | while (current) { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1469 | if (strcmp(current->uuid, uuid) == 0) { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1470 | if (previous == NULL) { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1471 | Config.simulators = current->next; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1472 | free(current->uuid); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1473 | current->uuid = NULL; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1474 | free(current->name); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1475 | current->name = NULL; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1476 | free(current); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1477 | return 1; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1478 | } else { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1479 | free(current->uuid); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1480 | current->uuid = NULL; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1481 | free(current->name); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1482 | current->name = NULL; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1483 | previous->next = current->next; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1484 | free(current); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1485 | current = previous->next; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1486 | return 1; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1487 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1488 | } else { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1489 | previous = current; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1490 | current = current->next; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1491 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1492 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1493 | return 0; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1494 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1495 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1496 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1497 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1498 | /* |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1499 | * SIMULATOR ADD name |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1500 | * SIMULATOR DEL uuid |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1501 | * SIMULATOR LIST |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1502 | * SIMULATOR GET uuid |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1503 | * SIMULATOR PUT uuid |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1504 | */ |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1505 | int cmd_simulator(char *buf) |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1506 | { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1507 | char *opt, *param, *kwd, *val, ibuf[SS_BUFSIZE]; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1508 | simulator_list *simulator, *tmps; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1509 | socklen_t fromlen; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1510 | int i, rc, rlen, ival; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1511 | float fval; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1512 | uuid_t uu; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1513 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1514 | opt = strtok(buf, " \0"); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1515 | opt = strtok(NULL, " \0"); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1516 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1517 | if (opt == NULL) { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1518 | srv_send((char *)"501 Subcommand missing"); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1519 | return 1; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1520 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1521 | param = strtok(NULL, "\0"); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1522 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1523 | if (strcmp(opt, (char *)"LIST") == 0) { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1524 | srv_send((char *)"212 Simulators list follows:"); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1525 | for (simulator = Config.simulators; simulator; simulator = simulator->next) { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1526 | srv_send((char *)"%s,%s", simulator->uuid, simulator->name); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1527 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1528 | srv_send((char *)"."); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1529 | return 1; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1530 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1531 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1532 | if (param == NULL) { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1533 | srv_send((char *)"502 Parameter missing"); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1534 | return 1; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1535 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1536 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1537 | if (strcmp(opt, (char *)"ADD") == 0) { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1538 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1539 | /* |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1540 | * For now, only one simulator is allowed. |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1541 | */ |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1542 | if (Config.simulators) { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1543 | srv_send((char *)"441 Maximum simulators reached"); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1544 | return 1; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1545 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1546 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1547 | simulator = (simulator_list *)malloc(sizeof(simulator_list)); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1548 | simulator->next = NULL; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1549 | simulator->version = 1; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1550 | simulator->uuid = malloc(37); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1551 | uuid_generate(uu); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1552 | uuid_unparse(uu, simulator->uuid); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1553 | simulator->name = xstrcpy(param); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1554 | simulator->volume_air = 150; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1555 | simulator->volume_beer = 50; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1556 | simulator->room_temperature = simulator->air_temperature = simulator->beer_temperature = simulator->s_cool_temp = simulator->s_heat_temp = 20.0; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1557 | simulator->cooler_temp = -3.0; /* Cooling temperature */ |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1558 | simulator->cooler_time = 720; /* About 12 minutes for the cooler plate */ |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1559 | simulator->cooler_size = 0.8; /* 0.8 square meter cooler plate */ |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1560 | simulator->heater_temp = 150.0; /* Heating temperature */ |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1561 | simulator->heater_time = 3; /* 3 seconds to heat-up */ |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1562 | simulator->heater_size = 0.01; /* 0.01 square meter heater plate */ |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1563 | simulator->heater_state = simulator->cooler_state = 0; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1564 | simulator->frigo_isolation = 0.002; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1565 | simulator->s_yeast_heat = 0.0; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1566 | simulator->s_yeast_started = simulator->s_cool_changed = simulator->s_heat_changed = (int)0; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1567 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1568 | if (Config.simulators == NULL) { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1569 | Config.simulators = simulator; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1570 | } else { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1571 | for (tmps = Config.simulators; tmps; tmps = tmps->next) { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1572 | if (tmps->next == NULL) { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1573 | tmps->next = simulator; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1574 | break; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1575 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1576 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1577 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1578 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1579 | syslog(LOG_NOTICE, "Simulator %s added", simulator->uuid); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1580 | srv_send((char *)"211 Simulator %s added", simulator->uuid); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1581 | return 0; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1582 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1583 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1584 | if (strcmp(opt, (char *)"DEL") == 0) { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1585 | rc = delete_Simulator(param); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1586 | if (rc) { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1587 | syslog(LOG_NOTICE, "Simulator %s deleted", param); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1588 | srv_send((char *)"211 Simulator %s deleted", param); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1589 | return 0; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1590 | } else { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1591 | srv_send((char *)"440 No such simulator"); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1592 | return 1; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1593 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1594 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1595 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1596 | if (strcmp(opt, (char *)"GET") == 0) { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1597 | for (simulator = Config.simulators; simulator; simulator = simulator->next) { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1598 | if (strcmp(simulator->uuid, param) == 0) { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1599 | srv_send((char *)"213 Simulator record follows:"); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1600 | srv_send((char *)"NAME,%s", simulator->name); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1601 | srv_send((char *)"VOLUME_AIR,%d", simulator->volume_air); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1602 | srv_send((char *)"VOLUME_BEER,%d", simulator->volume_beer); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1603 | srv_send((char *)"ROOM_TEMPERATURE,%.1f", simulator->room_temperature); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1604 | srv_send((char *)"AIR_TEMPERATURE,%.3f", simulator->air_temperature); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1605 | srv_send((char *)"BEER_TEMPERATURE,%.3f", simulator->beer_temperature); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1606 | srv_send((char *)"COOLER_TEMP,%.1f", simulator->cooler_temp); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1607 | srv_send((char *)"COOLER_TIME,%d", simulator->cooler_time); |
261 | 1608 | srv_send((char *)"COOLER_SIZE,%.3f", simulator->cooler_size); |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1609 | srv_send((char *)"HEATER_TEMP,%.1f", simulator->heater_temp); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1610 | srv_send((char *)"HEATER_TIME,%d", simulator->heater_time); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1611 | srv_send((char *)"HEATER_SIZE,%.3f", simulator->heater_size); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1612 | srv_send((char *)"HEATER_STATE,%d", simulator->heater_state); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1613 | srv_send((char *)"COOLER_STATE,%d", simulator->cooler_state); |
261 | 1614 | srv_send((char *)"FRIGO_ISOLATION,%.3f", simulator->frigo_isolation); |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1615 | srv_send((char *)"."); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1616 | return 1; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1617 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1618 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1619 | srv_send((char *)"440 No such simulator"); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1620 | return 1; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1621 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1622 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1623 | if (strcmp(opt, (char *)"PUT") == 0) { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1624 | for (simulator = Config.simulators; simulator; simulator = simulator->next) { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1625 | if (strcmp(simulator->uuid, param) == 0) { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1626 | while (1) { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1627 | memset((char *)&ibuf, 0, SS_BUFSIZE); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1628 | fromlen = sizeof(peeraddr_in); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1629 | rlen = recvfrom(s, ibuf, sizeof(ibuf) -1, 0, (struct sockaddr *)&peeraddr_in, &fromlen); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1630 | if (rlen == -1) { |
268
dda91dfa4aa8
All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents:
266
diff
changeset
|
1631 | syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno)); |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1632 | srv_send((char *)"518 recfrom(): %s", strerror(errno)); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1633 | return 1; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1634 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1635 | for (i = 0; i < strlen(ibuf); i++) { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1636 | if (ibuf[i] == '\n') |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1637 | ibuf[i] = '\0'; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1638 | if (ibuf[i] == '\r') |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1639 | ibuf[i] = '\0'; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1640 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1641 | for (i = strlen(ibuf) -1; i > 0; i--) { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1642 | if (ibuf[i] == ' ') |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1643 | ibuf[i] = '\0'; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1644 | else |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1645 | break; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1646 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1647 | if (strlen(ibuf)) { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1648 | if (debug) { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1649 | syslog(LOG_NOTICE, "recv: \"%s\"", ibuf); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1650 | fprintf(stdout, "recv: \"%s\"\n", ibuf); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1651 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1652 | if (strcmp(ibuf, (char *)".") == 0) { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1653 | srv_send((char *)"219 Accepted Simulator record"); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1654 | return 0; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1655 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1656 | kwd = strtok(ibuf, ",\0"); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1657 | val = strtok(NULL, "\0"); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1658 | if (kwd && val) { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1659 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1660 | if (strcmp(kwd, (char *)"NAME") == 0) { |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1661 | if (simulator->name) { |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1662 | if (strcmp(simulator->name, val)) |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1663 | syslog(LOG_NOTICE, "Simulator %s name `%s' to `%s'", simulator->uuid, simulator->name, val); |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1664 | free(simulator->name); |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1665 | } |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1666 | simulator->name = xstrcpy(val); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1667 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1668 | } else if (strcmp(kwd, (char *)"VOLUME_AIR") == 0) { |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1669 | if (sscanf(val, "%d", &ival) == 1) { |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1670 | if (simulator->volume_air != ival) |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1671 | syslog(LOG_NOTICE, "Simulator %s volume air %d to %d", simulator->uuid, simulator->volume_air, ival); |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1672 | simulator->volume_air = ival; |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1673 | } |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1674 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1675 | } else if (strcmp(kwd, (char *)"VOLUME_BEER") == 0) { |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1676 | if (sscanf(val, "%d", &ival) == 1) { |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1677 | if (simulator->volume_beer != ival) |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1678 | syslog(LOG_NOTICE, "Simulator %s volume beer %d to %d", simulator->uuid, simulator->volume_beer, ival); |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1679 | simulator->volume_beer = ival; |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1680 | } |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1681 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1682 | } else if (strcmp(kwd, (char *)"ROOM_TEMPERATURE") == 0) { |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1683 | if (sscanf(val, "%f", &fval) == 1) { |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1684 | if (simulator->room_temperature != fval) |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1685 | syslog(LOG_NOTICE, "Simulator %s room temperature %.1f to %.1f", simulator->uuid, simulator->room_temperature, fval); |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1686 | simulator->room_temperature = fval; |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1687 | } |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1688 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1689 | } else if (strcmp(kwd, (char *)"AIR_TEMPERATURE") == 0) { |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1690 | if (sscanf(val, "%f", &fval) == 1) { |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1691 | if (simulator->air_temperature != fval) |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1692 | syslog(LOG_NOTICE, "Simulator %s air temperature %.1f to %.1f", simulator->uuid, simulator->air_temperature, fval); |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1693 | simulator->air_temperature = fval; |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1694 | } |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1695 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1696 | } else if (strcmp(kwd, (char *)"BEER_TEMPERATURE") == 0) { |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1697 | if (sscanf(val, "%f", &fval) == 1) { |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1698 | if (simulator->beer_temperature != fval) |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1699 | syslog(LOG_NOTICE, "Simulator %s beer temperature %.1f to %.1f", simulator->uuid, simulator->beer_temperature, fval); |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1700 | simulator->beer_temperature = fval; |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1701 | } |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1702 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1703 | } else if (strcmp(kwd, (char *)"COOLER_TEMP") == 0) { |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1704 | if (sscanf(val, "%f", &fval) == 1) { |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1705 | if (simulator->cooler_temp != fval) |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1706 | syslog(LOG_NOTICE, "Simulator %s cooler temperature %.1f to %.1f", simulator->uuid, simulator->cooler_temp, fval); |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1707 | simulator->cooler_temp = fval; |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1708 | } |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1709 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1710 | } else if (strcmp(kwd, (char *)"COOLER_TIME") == 0) { |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1711 | if (sscanf(val, "%d", &ival) == 1) { |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1712 | if (simulator->cooler_time != ival) |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1713 | syslog(LOG_NOTICE, "Simulator %s cooler time %d to %d", simulator->uuid, simulator->cooler_time, ival); |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1714 | simulator->cooler_time = ival; |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1715 | } |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1716 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1717 | } else if (strcmp(kwd, (char *)"COOLER_SIZE") == 0) { |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1718 | if (sscanf(val, "%f", &fval) == 1) { |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1719 | if (simulator->cooler_size != fval) |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1720 | syslog(LOG_NOTICE, "Simulator %s cooler size %.1f to %.1f", simulator->uuid, simulator->cooler_size, fval); |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1721 | simulator->cooler_size = fval; |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1722 | } |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1723 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1724 | } else if (strcmp(kwd, (char *)"HEATER_TEMP") == 0) { |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1725 | if (sscanf(val, "%f", &fval) == 1) { |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1726 | if (simulator->heater_temp != fval) |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1727 | syslog(LOG_NOTICE, "Simulator %s heater temperature %.1f to %.1f", simulator->uuid, simulator->heater_temp, fval); |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1728 | simulator->heater_temp = fval; |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1729 | } |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1730 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1731 | } else if (strcmp(kwd, (char *)"HEATER_TIME") == 0) { |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1732 | if (sscanf(val, "%d", &ival) == 1) { |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1733 | if (simulator->heater_time != ival) |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1734 | syslog(LOG_NOTICE, "Simulator %s heater time %d to %d", simulator->uuid, simulator->heater_time, ival); |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1735 | simulator->heater_time = ival; |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1736 | } |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1737 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1738 | } else if (strcmp(kwd, (char *)"HEATER_SIZE") == 0) { |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1739 | if (sscanf(val, "%f", &fval) == 1) { |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1740 | if (simulator->heater_size != fval) |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1741 | syslog(LOG_NOTICE, "Simulator %s heater size %.1f to %.1f", simulator->uuid, simulator->heater_size, fval); |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1742 | simulator->heater_size = fval; |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1743 | } |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1744 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1745 | } else if (strcmp(kwd, (char *)"HEATER_STATE") == 0) { |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1746 | if (sscanf(val, "%d", &ival) == 1) { |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1747 | if (simulator->heater_state != ival) |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1748 | syslog(LOG_NOTICE, "Simulator %s heater state %d to %d", simulator->uuid, simulator->heater_state, ival); |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1749 | simulator->heater_state = ival; |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1750 | } |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1751 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1752 | } else if (strcmp(kwd, (char *)"COOLER_STATE") == 0) { |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1753 | if (sscanf(val, "%d", &ival) == 1) { |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1754 | if (simulator->cooler_state != ival) |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1755 | syslog(LOG_NOTICE, "Simulator %s cooler state %d to %d", simulator->uuid, simulator->cooler_state, ival); |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1756 | simulator->cooler_state = ival; |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1757 | } |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1758 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1759 | } else if (strcmp(kwd, (char *)"FRIGO_ISOLATION") == 0) { |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1760 | if (sscanf(val, "%f", &fval) == 1) { |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1761 | if (simulator->frigo_isolation != fval) |
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1762 | syslog(LOG_NOTICE, "Simulator %s frigo isolation %.1f to %.1f", simulator->uuid, simulator->frigo_isolation, fval); |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1763 | simulator->frigo_isolation = fval; |
281
12a5dbbfd0e3
SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
280
diff
changeset
|
1764 | } |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1765 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1766 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1767 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1768 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1769 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1770 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1771 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1772 | srv_send((char *)"440 No such simulator"); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1773 | return 1; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1774 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1775 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1776 | srv_send((char *)"504 Subcommand error"); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1777 | return 1; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1778 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1779 | #endif |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1780 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1781 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1782 | |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1783 | int delete_Unit(char *uuid) |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1784 | { |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1785 | units_list *current = Config.units; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1786 | units_list *previous = NULL; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1787 | |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1788 | while (current) { |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1789 | if (strcmp(current->uuid, uuid) == 0) { |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1790 | if (previous == NULL) { |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1791 | Config.units = current->next; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1792 | free(current->uuid); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1793 | current->uuid = NULL; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1794 | free(current->name); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1795 | current->name = NULL; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1796 | if (current->air_address) |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1797 | free(current->air_address); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1798 | current->air_address = NULL; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1799 | if (current->beer_address) |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1800 | free(current->beer_address); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1801 | current->beer_address = NULL; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1802 | if (current->heater_address) |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1803 | free(current->heater_address); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1804 | current->heater_address = NULL; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1805 | if (current->cooler_address) |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1806 | free(current->cooler_address); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1807 | current->cooler_address = NULL; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1808 | if (current->fan_address) |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1809 | free(current->fan_address); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1810 | current->fan_address = NULL; |
306
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
1811 | if (current->light_address) |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
1812 | free(current->light_address); |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
1813 | current->light_address = NULL; |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1814 | if (current->door_address) |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1815 | free(current->door_address); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1816 | current->door_address = NULL; |
306
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
1817 | if (current->psu_address) |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
1818 | free(current->psu_address); |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
1819 | current->psu_address = NULL; |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1820 | if (current->profile) |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1821 | free(current->profile); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1822 | current->profile = NULL; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1823 | free(current); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1824 | return 1; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1825 | } else { |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1826 | free(current->uuid); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1827 | current->uuid = NULL; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1828 | free(current->name); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1829 | current->name = NULL; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1830 | if (current->air_address) |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1831 | free(current->air_address); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1832 | current->air_address = NULL; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1833 | if (current->beer_address) |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1834 | free(current->beer_address); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1835 | current->beer_address = NULL; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1836 | if (current->heater_address) |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1837 | free(current->heater_address); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1838 | current->heater_address = NULL; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1839 | if (current->cooler_address) |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1840 | free(current->cooler_address); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1841 | current->cooler_address = NULL; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1842 | if (current->fan_address) |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1843 | free(current->fan_address); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1844 | current->fan_address = NULL; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1845 | if (current->door_address) |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1846 | free(current->door_address); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1847 | current->door_address = NULL; |
306
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
1848 | if (current->light_address) |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
1849 | free(current->light_address); |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
1850 | current->light_address = NULL; |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
1851 | if (current->psu_address) |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
1852 | free(current->psu_address); |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
1853 | current->psu_address = NULL; |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1854 | if (current->profile) |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1855 | free(current->profile); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1856 | current->profile = NULL; |
245
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1857 | previous->next = current->next; |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1858 | free(current); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1859 | current = previous->next; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1860 | return 1; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1861 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1862 | } else { |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1863 | previous = current; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1864 | current = current->next; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1865 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1866 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1867 | return 0; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1868 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1869 | |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1870 | |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1871 | |
88 | 1872 | /* |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1873 | * UNIT ADD name |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1874 | * UNIT DEL uuid |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1875 | * UNIT LIST |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1876 | * UNIT GET uuid |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1877 | * UNIT PUT uuid |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1878 | */ |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1879 | int cmd_unit(char *buf) |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1880 | { |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1881 | char *opt, *param = NULL, *kwd, *val, ibuf[SS_BUFSIZE]; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1882 | units_list *unit, *tmpu; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1883 | uuid_t uu; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1884 | socklen_t fromlen; |
245
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1885 | int ival, i, rc, rlen; |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1886 | float fval; |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1887 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1888 | opt = strtok(buf, " \0"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1889 | opt = strtok(NULL, " \0"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1890 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1891 | if (opt == NULL) { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1892 | srv_send((char *)"501 Subcommand missing"); |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1893 | return 1; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1894 | } |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1895 | param = strtok(NULL, "\0"); |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1896 | |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1897 | if ((strcmp(opt, (char *)"LIST") == 0) && (param == NULL)) { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1898 | srv_send((char *)"212 Fermenter list follows:"); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1899 | for (unit = Config.units; unit; unit = unit->next) { |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1900 | srv_send((char *)"%s,%s,%s", unit->uuid, unit->name, UNITMODE[unit->mode]); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1901 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1902 | srv_send((char *)"."); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1903 | return 1; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1904 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1905 | |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1906 | if (param == NULL) { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1907 | srv_send((char *)"502 Parameter missing"); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1908 | return 1; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1909 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1910 | |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1911 | if (strcmp(opt, (char *)"ADD") == 0) { |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1912 | unit = (units_list *)malloc(sizeof(units_list)); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1913 | unit->next = NULL; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1914 | unit->version = 1; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1915 | unit->uuid = malloc(37); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1916 | uuid_generate(uu); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1917 | uuid_unparse(uu, unit->uuid); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1918 | unit->name = xstrcpy(param); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1919 | unit->air_address = unit->beer_address = unit->heater_address = unit->cooler_address = \ |
306
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
1920 | unit->fan_address = unit->door_address = unit->light_address = \ |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
1921 | unit->psu_address = unit->profile = NULL; |
289
d810df0df36a
Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents:
285
diff
changeset
|
1922 | unit->volume = unit->prof_peak_abs = unit->prof_peak_rel = 0.0; |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1923 | unit->air_state = unit->beer_state = 1; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1924 | unit->air_temperature = unit->beer_temperature = 20000; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1925 | unit->beer_set = unit->fridge_set = 20.0; |
306
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
1926 | unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->mode = \ |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
1927 | unit->light_state = unit->psu_state = unit->prof_state = 0; |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
1928 | unit->heater_delay = unit->cooler_delay = unit->fan_delay = 20; /* 5 minutes delay */ |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
1929 | unit->light_delay = 1; /* 15 seconds delay */ |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
1930 | unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0; |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
1931 | unit->heater_usage = unit->cooler_usage = unit->fan_usage = unit->light_usage = 0; |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1932 | unit->temp_set_min = 1.0; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1933 | unit->temp_set_max = 30.0; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1934 | unit->idle_rangeH = 1.0; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1935 | unit->idle_rangeL = -1.0; |
289
d810df0df36a
Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents:
285
diff
changeset
|
1936 | unit->prof_started = unit->prof_paused = unit->prof_primary_done = (time_t)0; |
284
9e6fb5aed618
Profile progress is visible in the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
282
diff
changeset
|
1937 | unit->prof_percent = 0; |
313 | 1938 | unit->PID_dState = unit->PID_iState = unit->PID_Kp = unit->PID_Kd = unit->PID_Ki = 0.0; |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1939 | |
245
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1940 | /* |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1941 | * Block main process |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1942 | */ |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1943 | run_pause = TRUE; |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1944 | for (;;) { |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1945 | usleep(100000); |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1946 | if (run_hold) |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1947 | break; |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1948 | } |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1949 | |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1950 | if (Config.units == NULL) { |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1951 | Config.units = unit; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1952 | } else { |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1953 | for (tmpu = Config.units; tmpu; tmpu = tmpu->next) { |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1954 | if (tmpu->next == NULL) { |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1955 | tmpu->next = unit; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1956 | break; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1957 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1958 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1959 | } |
249 | 1960 | #ifdef HAVE_WIRINGPI_H |
245
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1961 | lcd_buf_reset(); |
249 | 1962 | #endif |
245
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1963 | run_pause = FALSE; |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1964 | |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1965 | syslog(LOG_NOTICE, "Unit %s added", unit->uuid); |
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1966 | srv_send((char *)"211 Unit %s added", unit->uuid); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1967 | return 0; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1968 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1969 | |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1970 | if (strcmp(opt, (char *)"DEL") == 0) { |
245
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1971 | /* |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1972 | * Block main process. |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1973 | */ |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1974 | run_pause = TRUE; |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1975 | for (;;) { |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1976 | usleep(100000); |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1977 | if (run_hold) |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1978 | break; |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1979 | } |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1980 | |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1981 | rc = delete_Unit(param); |
249 | 1982 | #ifdef HAVE_WIRINGPI_H |
245
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1983 | lcd_buf_reset(); |
249 | 1984 | #endif |
245
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1985 | run_pause = FALSE; |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1986 | |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1987 | if (rc) { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1988 | syslog(LOG_NOTICE, "Unit %s deleted", param); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1989 | srv_send((char *)"211 Unit %s deleted", param); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1990 | return 0; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1991 | } else { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1992 | srv_send((char *)"440 No such unit"); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1993 | return 1; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1994 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1995 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1996 | |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1997 | if (strcmp(opt, (char *)"GET") == 0) { |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1998 | for (unit = Config.units; unit; unit = unit->next) { |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1999 | if (strcmp(param, unit->uuid) == 0) { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
2000 | srv_send((char *)"213 Unit listing follows:"); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2001 | srv_send((char *)"NAME,%s", unit->name); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2002 | srv_send((char *)"UUID,%s", unit->uuid); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2003 | srv_send((char *)"VOLUME,%2f", unit->volume); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2004 | srv_send((char *)"AIR_ADDRESS,%s", unit->air_address); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2005 | srv_send((char *)"AIR_STATE,%s", TEMPSTATE[unit->air_state]); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2006 | srv_send((char *)"AIR_TEMPERATURE,%.3f", unit->air_temperature / 1000.0); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2007 | srv_send((char *)"BEER_ADDRESS,%s", MBSE_SS(unit->beer_address)); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2008 | srv_send((char *)"BEER_STATE,%s", TEMPSTATE[unit->beer_state]); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2009 | srv_send((char *)"BEER_TEMPERATURE,%.3f", unit->beer_temperature / 1000.0); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2010 | srv_send((char *)"HEATER_ADDRESS,%s", unit->heater_address); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2011 | srv_send((char *)"HEATER_STATE,%d", unit->heater_state); |
270
df81d583c2c3
The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents:
269
diff
changeset
|
2012 | srv_send((char *)"HEATER_DELAY,%d", unit->heater_delay); |
293 | 2013 | srv_send((char *)"HEATER_USAGE,%d", unit->heater_usage); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2014 | srv_send((char *)"COOLER_ADDRESS,%s", unit->cooler_address); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2015 | srv_send((char *)"COOLER_STATE,%d", unit->cooler_state); |
270
df81d583c2c3
The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents:
269
diff
changeset
|
2016 | srv_send((char *)"COOLER_DELAY,%d", unit->cooler_delay); |
293 | 2017 | srv_send((char *)"COOLER_USAGE,%d", unit->cooler_usage); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2018 | srv_send((char *)"FAN_ADDRESS,%s", unit->fan_address); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2019 | srv_send((char *)"FAN_STATE,%d", unit->fan_state); |
270
df81d583c2c3
The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents:
269
diff
changeset
|
2020 | srv_send((char *)"FAN_DELAY,%d", unit->fan_delay); |
293 | 2021 | srv_send((char *)"FAN_USAGE,%d", unit->fan_usage); |
306
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2022 | srv_send((char *)"LIGHT_ADDRESS,%s", unit->light_address); |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2023 | srv_send((char *)"LIGHT_STATE,%d", unit->light_state); |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2024 | srv_send((char *)"LIGHT_DELAY,%d", unit->light_delay); |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2025 | srv_send((char *)"LIGHT_USAGE,%d", unit->light_usage); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2026 | srv_send((char *)"DOOR_ADDRESS,%s", unit->door_address); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2027 | srv_send((char *)"DOOR_STATE,%d", unit->door_state); |
306
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2028 | srv_send((char *)"PSU_ADDRESS,%s", unit->psu_address); |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2029 | srv_send((char *)"PSU_STATE,%d", unit->psu_state); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2030 | srv_send((char *)"MODE,%s", UNITMODE[unit->mode]); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2031 | srv_send((char *)"FRIDGE_SET,%.1f", unit->fridge_set); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2032 | srv_send((char *)"BEER_SET,%.1f", unit->beer_set); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2033 | srv_send((char *)"PROFILE,%s", unit->profile); |
217 | 2034 | srv_send((char *)"PROF_STARTED,%d", (int)unit->prof_started); |
284
9e6fb5aed618
Profile progress is visible in the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
282
diff
changeset
|
2035 | if (unit->prof_state == PROFILE_RUN) { |
9e6fb5aed618
Profile progress is visible in the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
282
diff
changeset
|
2036 | srv_send((char *)"PROF_STATE,%s %d%%", PROFSTATE[unit->prof_state], unit->prof_percent); |
9e6fb5aed618
Profile progress is visible in the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
282
diff
changeset
|
2037 | } else { |
9e6fb5aed618
Profile progress is visible in the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
282
diff
changeset
|
2038 | srv_send((char *)"PROF_STATE,%s", PROFSTATE[unit->prof_state]); |
9e6fb5aed618
Profile progress is visible in the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
282
diff
changeset
|
2039 | } |
217 | 2040 | srv_send((char *)"PROF_TARGET,%.3f", unit->prof_target); |
289
d810df0df36a
Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents:
285
diff
changeset
|
2041 | srv_send((char *)"PROF_PEAK_ABS,%.3f", unit->prof_peak_abs); |
d810df0df36a
Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents:
285
diff
changeset
|
2042 | srv_send((char *)"PROF_PEAK_REL,%.3f", unit->prof_peak_rel); |
d810df0df36a
Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents:
285
diff
changeset
|
2043 | srv_send((char *)"PROF_PRIMARY_DONE,%d", (int)unit->prof_primary_done); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2044 | srv_send((char *)"TEMP_SET_MIN,%.1f", unit->temp_set_min); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2045 | srv_send((char *)"TEMP_SET_MAX,%.1f", unit->temp_set_max); |
312
7b0f819a3805
Added more precision to the unit low and high black window margins. Switched to PID routine from Pid without a PhD. The PID compute routine is now in the one second loop. The switch delay times are now in seconds, 0..720.
Michiel Broek <mbroek@mbse.eu>
parents:
311
diff
changeset
|
2046 | srv_send((char *)"IDLE_RANGE_L,%.2f", unit->idle_rangeL); |
7b0f819a3805
Added more precision to the unit low and high black window margins. Switched to PID routine from Pid without a PhD. The PID compute routine is now in the one second loop. The switch delay times are now in seconds, 0..720.
Michiel Broek <mbroek@mbse.eu>
parents:
311
diff
changeset
|
2047 | srv_send((char *)"IDLE_RANGE_H,%.2f", unit->idle_rangeH); |
310
53774295e14a
Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents:
306
diff
changeset
|
2048 | srv_send((char *)"PID_KP,%.2f", unit->PID_Kp); |
311
f3b0e9ac9bcb
PID changes and algorithm tuning.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
2049 | srv_send((char *)"PID_KI,%.2f", unit->PID_Ki); |
310
53774295e14a
Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents:
306
diff
changeset
|
2050 | srv_send((char *)"PID_KD,%.2f", unit->PID_Kd); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2051 | srv_send((char *)"."); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2052 | return 1; |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
2053 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
2054 | } |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
2055 | srv_send((char *)"440 No such unit"); |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
2056 | return 1; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
2057 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
2058 | |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2059 | if (strcmp(opt, (char *)"PUT") == 0) { |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2060 | for (unit = Config.units ; unit; unit = unit->next) { |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2061 | if (strcmp(unit->uuid, param) == 0) { |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2062 | while (1) { |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2063 | memset((char *)&ibuf, 0, SS_BUFSIZE); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2064 | fromlen = sizeof(peeraddr_in); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2065 | rlen = recvfrom(s, ibuf, sizeof(ibuf) -1, 0, (struct sockaddr *)&peeraddr_in, &fromlen); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2066 | if (rlen == -1) { |
268
dda91dfa4aa8
All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents:
266
diff
changeset
|
2067 | syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno)); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2068 | srv_send((char *)"518 recfrom(): %s", strerror(errno)); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2069 | return 1; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2070 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2071 | for (i = 0; i < strlen(ibuf); i++) { |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2072 | if (ibuf[i] == '\n') |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2073 | ibuf[i] = '\0'; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2074 | if (ibuf[i] == '\r') |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2075 | ibuf[i] = '\0'; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2076 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2077 | for (i = strlen(ibuf) -1; i > 0; i--) { |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2078 | if (ibuf[i] == ' ') |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2079 | ibuf[i] = '\0'; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2080 | else |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2081 | break; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2082 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2083 | if (strlen(ibuf)) { |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2084 | if (debug) { |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2085 | syslog(LOG_NOTICE, "recv: \"%s\"", ibuf); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2086 | fprintf(stdout, "recv: \"%s\"\n", ibuf); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2087 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2088 | if (strcmp(ibuf, (char *)".") == 0) { |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2089 | srv_send((char *)"219 Accepted Unit record"); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2090 | return 0; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2091 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2092 | kwd = strtok(ibuf, ",\0"); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2093 | val = strtok(NULL, "\0"); |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2094 | if (kwd) { |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2095 | /* |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2096 | * Accept writable data. The client can sent just one line, |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2097 | * but may also sent everything. Simply ignore things we |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2098 | * don't understand. |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2099 | */ |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2100 | if (val && (strcmp(kwd, (char *)"NAME") == 0)) { |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2101 | if (unit->name) { |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2102 | if (strcmp(unit->name, val)) |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2103 | syslog(LOG_NOTICE, "Fermenter unit %s name `%s' to `%s'", unit->uuid, unit->name, val); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2104 | free(unit->name); |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2105 | } |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2106 | unit->name = xstrcpy(val); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2107 | |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2108 | } else if (val && (strcmp(kwd, (char *)"VOLUME") == 0)) { |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2109 | if (sscanf(val, "%f", &fval) == 1) { |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2110 | if (unit->volume != fval) |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2111 | syslog(LOG_NOTICE, "Fermenter unit %s volume %.3f to %.3f", unit->uuid, unit->volume, fval); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2112 | unit->volume = fval; |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2113 | } |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2114 | |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2115 | } else if (strcmp(kwd, (char *)"AIR_ADDRESS") == 0) { |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2116 | if (val && unit->air_address && (strcmp(val, unit->air_address))) |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2117 | syslog(LOG_NOTICE, "Fermenter unit %s air address `%s' to `%s'", unit->uuid, unit->air_address, val); |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2118 | if (unit->air_address) { |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2119 | device_count(FALSE, unit->air_address); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2120 | free(unit->air_address); |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2121 | } |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2122 | if (val) { |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2123 | unit->air_address = xstrcpy(val); |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2124 | device_count(TRUE, unit->air_address); |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2125 | } else |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2126 | unit->air_address = NULL; |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2127 | |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2128 | } else if (strcmp(kwd, (char *)"BEER_ADDRESS") == 0) { |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2129 | if (val && unit->beer_address && (strcmp(val, unit->beer_address))) |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2130 | syslog(LOG_NOTICE, "Fermenter unit %s beer address `%s' to `%s'", unit->uuid, unit->beer_address, val); |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2131 | if (unit->beer_address) { |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2132 | device_count(FALSE, unit->beer_address); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2133 | free(unit->beer_address); |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2134 | } |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2135 | if (val) { |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2136 | unit->beer_address = xstrcpy(val); |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2137 | device_count(TRUE, unit->beer_address); |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2138 | } else |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2139 | unit->beer_address = NULL; |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2140 | |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2141 | } else if (strcmp(kwd, (char *)"HEATER_ADDRESS") == 0) { |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2142 | if (val && unit->heater_address && (strcmp(val, unit->heater_address))) |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2143 | syslog(LOG_NOTICE, "Fermenter unit %s heater address `%s' to `%s'", unit->uuid, unit->heater_address, val); |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2144 | if (unit->heater_address) { |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2145 | device_count(FALSE, unit->heater_address); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2146 | free(unit->heater_address); |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2147 | } |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2148 | if (val) { |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2149 | unit->heater_address = xstrcpy(val); |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2150 | device_count(TRUE, unit->heater_address); |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2151 | } else |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2152 | unit->heater_address = NULL; |
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2153 | |
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2154 | } else if (val && (strcmp(kwd, (char *)"HEATER_STATE") == 0)) { |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2155 | if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) { |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2156 | if (unit->heater_state != ival) |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2157 | syslog(LOG_NOTICE, "Fermenter unit %s heater state %d to %d", unit->uuid, unit->heater_state, ival); |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2158 | unit->heater_state = ival; |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2159 | } |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2160 | |
270
df81d583c2c3
The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents:
269
diff
changeset
|
2161 | } else if (val && (strcmp(kwd, (char *)"HEATER_DELAY") == 0)) { |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2162 | if (sscanf(val, "%d", &ival) == 1) { |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2163 | if (unit->heater_delay != ival) |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2164 | syslog(LOG_NOTICE, "Fermenter unit %s heater delay %d to %d", unit->uuid, unit->heater_delay, ival); |
270
df81d583c2c3
The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents:
269
diff
changeset
|
2165 | unit->heater_delay = ival; |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2166 | } |
270
df81d583c2c3
The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents:
269
diff
changeset
|
2167 | |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2168 | } else if (strcmp(kwd, (char *)"COOLER_ADDRESS") == 0) { |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2169 | if (val && unit->cooler_address && (strcmp(val, unit->cooler_address))) |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2170 | syslog(LOG_NOTICE, "Fermenter unit %s cooler address `%s' to `%s'", unit->uuid, unit->cooler_address, val); |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2171 | if (unit->cooler_address) { |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2172 | device_count(FALSE, unit->cooler_address); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2173 | free(unit->cooler_address); |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2174 | } |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2175 | if (val) { |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2176 | unit->cooler_address = xstrcpy(val); |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2177 | device_count(TRUE, unit->cooler_address); |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2178 | } else |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2179 | unit->cooler_address = NULL; |
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2180 | |
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2181 | } else if (val && (strcmp(kwd, (char *)"COOLER_STATE") == 0)) { |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2182 | if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) { |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2183 | if (unit->cooler_state != ival) |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2184 | syslog(LOG_NOTICE, "Fermenter unit %s cooler state %d to %d", unit->uuid, unit->cooler_state, ival); |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2185 | unit->cooler_state = ival; |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2186 | } |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2187 | |
270
df81d583c2c3
The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents:
269
diff
changeset
|
2188 | } else if (val && (strcmp(kwd, (char *)"COOLER_DELAY") == 0)) { |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2189 | if (sscanf(val, "%d", &ival) == 1) { |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2190 | if (unit->cooler_delay != ival) |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2191 | syslog(LOG_NOTICE, "Fermenter unit %s cooler delay %d to %d", unit->uuid, unit->cooler_delay, ival); |
270
df81d583c2c3
The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents:
269
diff
changeset
|
2192 | unit->cooler_delay = ival; |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2193 | } |
270
df81d583c2c3
The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents:
269
diff
changeset
|
2194 | |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2195 | } else if (strcmp(kwd, (char *)"FAN_ADDRESS") == 0) { |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2196 | if (val && unit->fan_address && (strcmp(val, unit->fan_address))) |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2197 | syslog(LOG_NOTICE, "Fermenter unit %s fan address `%s' to `%s'", unit->uuid, unit->fan_address, val); |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2198 | if (unit->fan_address) { |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2199 | device_count(FALSE, unit->fan_address); |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2200 | free(unit->fan_address); |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2201 | } |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2202 | if (val) { |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2203 | unit->fan_address = xstrcpy(val); |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2204 | device_count(TRUE, unit->fan_address); |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2205 | } else |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2206 | unit->fan_address = NULL; |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2207 | |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2208 | } else if (val && (strcmp(kwd, (char *)"FAN_STATE") == 0)) { |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2209 | if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) { |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2210 | if (unit->fan_state != ival) |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2211 | syslog(LOG_NOTICE, "Fermenter unit %s fan state %d to %d", unit->uuid, unit->fan_state, ival); |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2212 | unit->fan_state = ival; |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2213 | } |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2214 | |
270
df81d583c2c3
The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents:
269
diff
changeset
|
2215 | } else if (val && (strcmp(kwd, (char *)"FAN_DELAY") == 0)) { |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2216 | if (sscanf(val, "%d", &ival) == 1) { |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2217 | if (unit->fan_delay != ival) |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2218 | syslog(LOG_NOTICE, "Fermenter unit %s fan delay %d to %d", unit->uuid, unit->fan_delay, ival); |
270
df81d583c2c3
The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents:
269
diff
changeset
|
2219 | unit->fan_delay = ival; |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2220 | } |
270
df81d583c2c3
The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents:
269
diff
changeset
|
2221 | |
306
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2222 | } else if (strcmp(kwd, (char *)"LIGHT_ADDRESS") == 0) { |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2223 | if (val && unit->light_address && (strcmp(val, unit->light_address))) |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2224 | syslog(LOG_NOTICE, "Fermenter unit %s light address `%s' to `%s'", unit->uuid, unit->light_address, val); |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2225 | if (unit->light_address) { |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2226 | device_count(FALSE, unit->light_address); |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2227 | free(unit->light_address); |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2228 | } |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2229 | if (val) { |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2230 | unit->light_address = xstrcpy(val); |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2231 | device_count(TRUE, unit->light_address); |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2232 | } else |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2233 | unit->light_address = NULL; |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2234 | |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2235 | } else if (val && (strcmp(kwd, (char *)"LIGHT_STATE") == 0)) { |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2236 | if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) { |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2237 | if (unit->light_state != ival) |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2238 | syslog(LOG_NOTICE, "Fermenter unit %s light state %d to %d", unit->uuid, unit->light_state, ival); |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2239 | unit->light_state = ival; |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2240 | } |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2241 | |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2242 | } else if (val && (strcmp(kwd, (char *)"LIGHT_DELAY") == 0)) { |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2243 | if (sscanf(val, "%d", &ival) == 1) { |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2244 | if (unit->light_delay != ival) |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2245 | syslog(LOG_NOTICE, "Fermenter unit %s light delay %d to %d", unit->uuid, unit->light_delay, ival); |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2246 | unit->light_delay = ival; |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2247 | } |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2248 | |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2249 | } else if (strcmp(kwd, (char *)"DOOR_ADDRESS") == 0) { |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2250 | if (val && unit->door_address && (strcmp(val, unit->door_address))) |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2251 | syslog(LOG_NOTICE, "Fermenter unit %s door address `%s' to `%s'", unit->uuid, unit->door_address, val); |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2252 | if (unit->door_address) { |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2253 | device_count(FALSE, unit->door_address); |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2254 | free(unit->door_address); |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2255 | } |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2256 | if (val) { |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2257 | unit->door_address = xstrcpy(val); |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2258 | device_count(TRUE, unit->door_address); |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
2259 | } else |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2260 | unit->door_address = NULL; |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2261 | |
306
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2262 | } else if (strcmp(kwd, (char *)"PSU_ADDRESS") == 0) { |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2263 | if (val && unit->psu_address && (strcmp(val, unit->psu_address))) |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2264 | syslog(LOG_NOTICE, "Fermenter unit %s psu address `%s' to `%s'", unit->uuid, unit->psu_address, val); |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2265 | if (unit->psu_address) { |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2266 | device_count(FALSE, unit->psu_address); |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2267 | free(unit->psu_address); |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2268 | } |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2269 | if (val) { |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2270 | unit->psu_address = xstrcpy(val); |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2271 | device_count(TRUE, unit->psu_address); |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2272 | } else |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2273 | unit->psu_address = NULL; |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2274 | |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2275 | } else if (val && (strcmp(kwd, (char *)"MODE") == 0)) { |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2276 | for (i = 0; i < 5; i++) { |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2277 | if (strcmp(val, UNITMODE[i]) == 0) { |
189
cc2b04d4db99
Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents:
185
diff
changeset
|
2278 | /* Initialize log if the unit is turned on */ |
cc2b04d4db99
Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents:
185
diff
changeset
|
2279 | if ((unit->mode == UNITMODE_OFF) && (i != UNITMODE_OFF)) |
cc2b04d4db99
Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents:
185
diff
changeset
|
2280 | initlog(unit->name); |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2281 | syslog(LOG_NOTICE, "Fermenter unit %s mode %s to %s", unit->uuid, UNITMODE[unit->mode], UNITMODE[i]); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2282 | unit->mode = i; |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2283 | /* Allways turn everything off after a mode change */ |
313 | 2284 | unit->PID_iState = unit->PID_dState = 0.0; |
306
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2285 | unit->heater_state = unit->cooler_state = unit->fan_state = unit->light_state = 0; |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2286 | unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0; |
184 | 2287 | device_out(unit->heater_address, unit->heater_state); |
2288 | device_out(unit->cooler_address, unit->cooler_state); | |
2289 | device_out(unit->fan_address, unit->fan_state); | |
306
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2290 | device_out(unit->light_address, unit->light_state); |
237
51a294d683cd
Add a sane default for profile precessing.
Michiel Broek <mbroek@mbse.eu>
parents:
235
diff
changeset
|
2291 | if (unit->mode == UNITMODE_PROFILE) { |
51a294d683cd
Add a sane default for profile precessing.
Michiel Broek <mbroek@mbse.eu>
parents:
235
diff
changeset
|
2292 | /* |
51a294d683cd
Add a sane default for profile precessing.
Michiel Broek <mbroek@mbse.eu>
parents:
235
diff
changeset
|
2293 | * Set a sane default until it will be overruled by the |
51a294d683cd
Add a sane default for profile precessing.
Michiel Broek <mbroek@mbse.eu>
parents:
235
diff
changeset
|
2294 | * main processing loop. |
51a294d683cd
Add a sane default for profile precessing.
Michiel Broek <mbroek@mbse.eu>
parents:
235
diff
changeset
|
2295 | */ |
51a294d683cd
Add a sane default for profile precessing.
Michiel Broek <mbroek@mbse.eu>
parents:
235
diff
changeset
|
2296 | unit->prof_target = 20.0; |
51a294d683cd
Add a sane default for profile precessing.
Michiel Broek <mbroek@mbse.eu>
parents:
235
diff
changeset
|
2297 | } |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2298 | break; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2299 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2300 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2301 | |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2302 | } else if (val && (strcmp(kwd, (char *)"FRIDGE_SET") == 0)) { |
246
6df404da3537
Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
2303 | if ((sscanf(val, "%f", &fval) == 1) && (fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) { |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2304 | if (unit->fridge_set != fval) |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2305 | syslog(LOG_NOTICE, "Fermenter unit %s fridge temperature %.1f to %.1f", unit->uuid, unit->fridge_set, fval); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2306 | unit->fridge_set = fval; |
246
6df404da3537
Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
2307 | } |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2308 | |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2309 | } else if (val && (strcmp(kwd, (char *)"BEER_SET") == 0)) { |
246
6df404da3537
Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
2310 | if ((sscanf(val, "%f", &fval) == 1) && (fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) { |
310
53774295e14a
Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents:
306
diff
changeset
|
2311 | if (unit->beer_set != fval) |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2312 | syslog(LOG_NOTICE, "Fermenter unit %s beer temperature %.1f to %.1f", unit->uuid, unit->beer_set, fval); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2313 | unit->beer_set = fval; |
246
6df404da3537
Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
2314 | } |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2315 | |
310
53774295e14a
Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents:
306
diff
changeset
|
2316 | } else if (val && (strcmp(kwd, (char *)"PID_KP") == 0)) { |
53774295e14a
Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents:
306
diff
changeset
|
2317 | if ((sscanf(val, "%f", &fval) == 1) && (fval >= 0.0)) { |
53774295e14a
Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents:
306
diff
changeset
|
2318 | if (unit->PID_Kp != fval) |
53774295e14a
Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents:
306
diff
changeset
|
2319 | syslog(LOG_NOTICE, "Fermenter unit %s PID Kp %.2f to %.2f", unit->uuid, unit->PID_Kp, fval); |
53774295e14a
Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents:
306
diff
changeset
|
2320 | unit->PID_Kp = fval; |
53774295e14a
Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents:
306
diff
changeset
|
2321 | } |
53774295e14a
Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents:
306
diff
changeset
|
2322 | |
53774295e14a
Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents:
306
diff
changeset
|
2323 | } else if (val && (strcmp(kwd, (char *)"PID_KD") == 0)) { |
53774295e14a
Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents:
306
diff
changeset
|
2324 | if ((sscanf(val, "%f", &fval) == 1) && (fval >= 0.0)) { |
53774295e14a
Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents:
306
diff
changeset
|
2325 | if (unit->PID_Kd != fval) |
53774295e14a
Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents:
306
diff
changeset
|
2326 | syslog(LOG_NOTICE, "Fermenter unit %s PID Kd %.2f to %.2f", unit->uuid, unit->PID_Kd, fval); |
53774295e14a
Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents:
306
diff
changeset
|
2327 | unit->PID_Kd = fval; |
53774295e14a
Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents:
306
diff
changeset
|
2328 | } |
53774295e14a
Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents:
306
diff
changeset
|
2329 | |
53774295e14a
Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents:
306
diff
changeset
|
2330 | } else if (val && (strcmp(kwd, (char *)"PID_KI") == 0)) { |
53774295e14a
Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents:
306
diff
changeset
|
2331 | if ((sscanf(val, "%f", &fval) == 1) && (fval >= 0.0)) { |
53774295e14a
Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents:
306
diff
changeset
|
2332 | if (unit->PID_Ki != fval) |
53774295e14a
Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents:
306
diff
changeset
|
2333 | syslog(LOG_NOTICE, "Fermenter unit %s PID Ki %.2f to %.2f", unit->uuid, unit->PID_Ki, fval); |
53774295e14a
Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents:
306
diff
changeset
|
2334 | unit->PID_Ki = fval; |
53774295e14a
Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents:
306
diff
changeset
|
2335 | } |
53774295e14a
Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents:
306
diff
changeset
|
2336 | |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2337 | } else if (strcmp(kwd, (char *)"PROFILE") == 0) { |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
2338 | if (unit->prof_state == PROFILE_OFF) { |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
2339 | /* |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
2340 | * Only change profile if it is not active, else drop this one. |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
2341 | */ |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2342 | if (unit->profile && val && strcmp(unit->profile, val)) |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2343 | syslog(LOG_NOTICE, "Fermenter unit %s profile name `%s' to `%s'", unit->uuid, unit->profile, val); |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
2344 | if (unit->profile) |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
2345 | free(unit->profile); |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2346 | |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
2347 | if (val) |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
2348 | unit->profile = xstrcpy(val); |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
2349 | else |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
2350 | unit->profile = NULL; |
195
b34a1b2421fb
Reset output when a different profile is selected. Better startup logging about the unit state. Added Beer, Fridge and partial Profile settings from the liveview weeb screen.
Michiel Broek <mbroek@mbse.eu>
parents:
194
diff
changeset
|
2351 | /* |
b34a1b2421fb
Reset output when a different profile is selected. Better startup logging about the unit state. Added Beer, Fridge and partial Profile settings from the liveview weeb screen.
Michiel Broek <mbroek@mbse.eu>
parents:
194
diff
changeset
|
2352 | * Reset all output devices |
b34a1b2421fb
Reset output when a different profile is selected. Better startup logging about the unit state. Added Beer, Fridge and partial Profile settings from the liveview weeb screen.
Michiel Broek <mbroek@mbse.eu>
parents:
194
diff
changeset
|
2353 | */ |
313 | 2354 | unit->PID_iState = unit->PID_dState = 0.0; |
306
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2355 | unit->heater_state = unit->cooler_state = unit->fan_state = unit->light_state = 0; |
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2356 | unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0; |
195
b34a1b2421fb
Reset output when a different profile is selected. Better startup logging about the unit state. Added Beer, Fridge and partial Profile settings from the liveview weeb screen.
Michiel Broek <mbroek@mbse.eu>
parents:
194
diff
changeset
|
2357 | device_out(unit->heater_address, unit->heater_state); |
b34a1b2421fb
Reset output when a different profile is selected. Better startup logging about the unit state. Added Beer, Fridge and partial Profile settings from the liveview weeb screen.
Michiel Broek <mbroek@mbse.eu>
parents:
194
diff
changeset
|
2358 | device_out(unit->cooler_address, unit->cooler_state); |
b34a1b2421fb
Reset output when a different profile is selected. Better startup logging about the unit state. Added Beer, Fridge and partial Profile settings from the liveview weeb screen.
Michiel Broek <mbroek@mbse.eu>
parents:
194
diff
changeset
|
2359 | device_out(unit->fan_address, unit->fan_state); |
306
97602274eb58
Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents:
303
diff
changeset
|
2360 | device_out(unit->light_address, unit->light_state); |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
2361 | } |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2362 | |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2363 | } else if (val && (strcmp(kwd, (char *)"PROF_STATE") == 0)) { |
217 | 2364 | for (i = 0; i < 5; i++) { |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2365 | if (strcmp(val, PROFSTATE[i]) == 0) { |
219
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
2366 | switch (i) { |
274
111b0e9663dc
Added logging if profile state is changed via the web interface. Log profile progress each half hour in syslog. Profile resttime steps 0 hours is allowed, meaning resttime or steptime must be set for a valid step. Updated the helptext on the web page.
Michiel Broek <mbroek@mbse.eu>
parents:
273
diff
changeset
|
2367 | case PROFILE_OFF: if (unit->prof_state == PROFILE_DONE) { |
219
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
2368 | unit->prof_state = PROFILE_OFF; |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2369 | syslog(LOG_NOTICE, "Fermenter unit %s profile to OFF", unit->uuid); |
274
111b0e9663dc
Added logging if profile state is changed via the web interface. Log profile progress each half hour in syslog. Profile resttime steps 0 hours is allowed, meaning resttime or steptime must be set for a valid step. Updated the helptext on the web page.
Michiel Broek <mbroek@mbse.eu>
parents:
273
diff
changeset
|
2370 | } |
219
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
2371 | break; |
274
111b0e9663dc
Added logging if profile state is changed via the web interface. Log profile progress each half hour in syslog. Profile resttime steps 0 hours is allowed, meaning resttime or steptime must be set for a valid step. Updated the helptext on the web page.
Michiel Broek <mbroek@mbse.eu>
parents:
273
diff
changeset
|
2372 | case PROFILE_PAUSE: if (unit->prof_state == PROFILE_RUN) { |
219
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
2373 | unit->prof_state = PROFILE_PAUSE; |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2374 | syslog(LOG_NOTICE, "Fermenter unit %s profile PAUSE", unit->uuid); |
274
111b0e9663dc
Added logging if profile state is changed via the web interface. Log profile progress each half hour in syslog. Profile resttime steps 0 hours is allowed, meaning resttime or steptime must be set for a valid step. Updated the helptext on the web page.
Michiel Broek <mbroek@mbse.eu>
parents:
273
diff
changeset
|
2375 | } else if (unit->prof_state == PROFILE_PAUSE) { |
219
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
2376 | unit->prof_state = PROFILE_RUN; |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2377 | syslog(LOG_NOTICE, "Fermenter unit %s profile RESUME", unit->uuid); |
274
111b0e9663dc
Added logging if profile state is changed via the web interface. Log profile progress each half hour in syslog. Profile resttime steps 0 hours is allowed, meaning resttime or steptime must be set for a valid step. Updated the helptext on the web page.
Michiel Broek <mbroek@mbse.eu>
parents:
273
diff
changeset
|
2378 | } |
219
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
2379 | break; |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
2380 | case PROFILE_RUN: if (unit->prof_state == PROFILE_OFF) { |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
2381 | unit->prof_state = PROFILE_RUN; |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
2382 | unit->prof_started = time(NULL); |
289
d810df0df36a
Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents:
285
diff
changeset
|
2383 | unit->prof_paused = unit->prof_primary_done = 0; |
d810df0df36a
Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents:
285
diff
changeset
|
2384 | unit->prof_peak_abs = unit->prof_peak_rel = 0.0; |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2385 | syslog(LOG_NOTICE, "Fermenter unit %s profile to RUN", unit->uuid); |
219
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
2386 | } |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
2387 | break; |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
2388 | case PROFILE_DONE: break; /* Command is illegal */ |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
2389 | case PROFILE_ABORT: if ((unit->prof_state == PROFILE_RUN) || (unit->prof_state == PROFILE_PAUSE)) { |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
2390 | unit->prof_state = PROFILE_OFF; |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
2391 | unit->prof_started = 0; |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2392 | syslog(LOG_NOTICE, "Fermenter unit %s profile ABORT", unit->uuid); |
219
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
2393 | } |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
2394 | break; |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
2395 | } |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2396 | break; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2397 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2398 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2399 | |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2400 | } else if (val && (strcmp(kwd, (char *)"TEMP_SET_MIN") == 0)) { |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2401 | if (sscanf(val, "%f", &fval) == 1) { |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2402 | if (unit->temp_set_min != fval) |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2403 | syslog(LOG_NOTICE, "Fermenter unit %s temperature set minimum %.1f to %.1f", unit->uuid, unit->temp_set_min, fval); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2404 | unit->temp_set_min = fval; |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2405 | } |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2406 | |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2407 | } else if (val && (strcmp(kwd, (char *)"TEMP_SET_MAX") == 0)) { |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2408 | if (sscanf(val, "%f", &fval) == 1) { |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2409 | if (unit->temp_set_max != fval) |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2410 | syslog(LOG_NOTICE, "Fermenter unit %s temperature set maximum %.1f to %.1f", unit->uuid, unit->temp_set_max, fval); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2411 | unit->temp_set_max = fval; |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2412 | } |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2413 | |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2414 | } else if (val && (strcmp(kwd, (char *)"IDLE_RANGE_L") == 0)) { |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2415 | if (sscanf(val, "%f", &fval) == 1) { |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2416 | if (unit->idle_rangeL != fval) |
312
7b0f819a3805
Added more precision to the unit low and high black window margins. Switched to PID routine from Pid without a PhD. The PID compute routine is now in the one second loop. The switch delay times are now in seconds, 0..720.
Michiel Broek <mbroek@mbse.eu>
parents:
311
diff
changeset
|
2417 | syslog(LOG_NOTICE, "Fermenter unit %s idle range low %.2f to %.2f", unit->uuid, unit->idle_rangeL, fval); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2418 | unit->idle_rangeL = fval; |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2419 | } |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2420 | |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
2421 | } else if (val && (strcmp(kwd, (char *)"IDLE_RANGE_H") == 0)) { |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2422 | if (sscanf(val, "%f", &fval) == 1) { |
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2423 | if (unit->idle_rangeH != fval) |
312
7b0f819a3805
Added more precision to the unit low and high black window margins. Switched to PID routine from Pid without a PhD. The PID compute routine is now in the one second loop. The switch delay times are now in seconds, 0..720.
Michiel Broek <mbroek@mbse.eu>
parents:
311
diff
changeset
|
2424 | syslog(LOG_NOTICE, "Fermenter unit %s idle range high %.2f to %.2f", unit->uuid, unit->idle_rangeH, fval); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2425 | unit->idle_rangeH = fval; |
282
885e5243bb50
UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents:
281
diff
changeset
|
2426 | } |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2427 | |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2428 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2429 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2430 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2431 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2432 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2433 | } |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
2434 | srv_send((char *)"440 No such unit"); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2435 | return 1; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2436 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2437 | |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
2438 | srv_send((char *)"504 Subcommand error"); |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
2439 | return 1; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
2440 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
2441 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
2442 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
2443 | |
43 | 2444 | void cmd_server(void) |
2445 | { | |
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
|
2446 | 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
|
2447 | int i, rlen; |
43 | 2448 | socklen_t fromlen; |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2449 | |
48 | 2450 | memset((char *)&buf, 0, SS_BUFSIZE); |
2451 | fromlen = sizeof(peeraddr_in); | |
2452 | rlen = recvfrom(s, buf, sizeof(buf) -1, 0, (struct sockaddr *)&peeraddr_in, &fromlen); | |
2453 | if (rlen == -1) { | |
268
dda91dfa4aa8
All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents:
266
diff
changeset
|
2454 | syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno)); |
48 | 2455 | } else { |
2456 | for (i = 0; i < strlen(buf); i++) { | |
2457 | if (buf[i] == '\n') | |
2458 | buf[i] = '\0'; | |
2459 | if (buf[i] == '\r') | |
2460 | buf[i] = '\0'; | |
2461 | } | |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
2462 | for (i = strlen(buf) -1; i > 0; i--) { |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
2463 | if (buf[i] == ' ') |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
2464 | buf[i] = '\0'; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
2465 | else |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
2466 | break; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
2467 | } |
48 | 2468 | if (strlen(buf)) { |
2469 | if (debug) { | |
2470 | syslog(LOG_NOTICE, "recv: \"%s\"", buf); | |
2471 | fprintf(stdout, "recv: \"%s\"\n", buf); | |
43 | 2472 | } |
2473 | ||
2474 | /* | |
48 | 2475 | * Process commands from the client |
43 | 2476 | */ |
329 | 2477 | if (strncmp(buf, "ARCHIVE", 7) == 0) { |
2478 | cmd_archive(buf); | |
2479 | } else if (strncmp(buf, "DEVICE", 6) == 0) { | |
174 | 2480 | if (cmd_device(buf) == 0) |
2481 | wrconfig(); | |
206
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
2482 | } else if (strncmp(buf, "GLOBAL", 6) == 0) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
2483 | if (cmd_global(buf) == 0) |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
2484 | wrconfig(); |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
2485 | } 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
|
2486 | srv_send((char *)"100 Help text follows"); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
2487 | srv_send((char *)"Recognized commands:"); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
2488 | 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
|
2489 | // 12345678901234567890123456789012345678901234567890123456789012345678901234567890 |
331 | 2490 | srv_send((char *)"ARCHIVE <CMD> [parameters] Archive commands"); |
2491 | srv_send((char *)"ARCHIVE HELP Archive help screen"); | |
174 | 2492 | srv_send((char *)"DEVICE ADD type Add new Device type"); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2493 | srv_send((char *)"DEVICE DEL uuid Delete Device by uuid"); |
174 | 2494 | srv_send((char *)"DEVICE LIST List Devices"); |
2495 | srv_send((char *)"DEVICE GET uuid Get Device record by uuid"); | |
2496 | srv_send((char *)"DEVICE PUT uuid Put Device record by uuid"); | |
206
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
2497 | srv_send((char *)"GLOBAL GET Get global settings"); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
2498 | srv_send((char *)"GLOBAL PUT Put global settings"); |
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
|
2499 | srv_send((char *)"LIST List all fermenter units"); |
331 | 2500 | srv_send((char *)"LIST LOG uuid List logfile data graphsteps"); |
330 | 2501 | srv_send((char *)"PING Check if server is alive"); |
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
|
2502 | srv_send((char *)"PROFILE uuid,name Profile rename"); |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
2503 | srv_send((char *)"PROFILE ADD name Add new Profile with name"); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
2504 | srv_send((char *)"PROFILE DEL uuid Delete Profile by uuid"); |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
2505 | srv_send((char *)"PROFILE LIST List available profiles"); |
192
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
2506 | srv_send((char *)"PROFILE GET uuid Get Profile record by uuid"); |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
2507 | srv_send((char *)"PROFILE PUT uuid Put Profile record by uuid"); |
140
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
2508 | srv_send((char *)"PROFILE GETS uuid Profile get steps list"); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
2509 | srv_send((char *)"PROFILE PUTS uuid Profile put steps list"); |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
2510 | #ifdef USE_SIMULATOR |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
2511 | srv_send((char *)"SIMULATOR ADD name Add a new Simulator with name"); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
2512 | srv_send((char *)"SIMULATOR DEL uuid Delete Simulator by uuid"); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
2513 | srv_send((char *)"SIMULATOR LIST List all Simulators"); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
2514 | srv_send((char *)"SIMULATOR GET uuid Get Simulator record by uuid"); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
2515 | srv_send((char *)"SIMULATOR PUT uuid Put Simulator record by uuid"); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
2516 | #endif |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
2517 | srv_send((char *)"UNIT ADD name Add a new Unit with name"); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2518 | srv_send((char *)"UNIT DEL uuid Delete Unit by uuid"); |
206
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
2519 | srv_send((char *)"UNIT LIST List all Units"); |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2520 | srv_send((char *)"UNIT GET uuid Get Unit record by uuid"); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2521 | srv_send((char *)"UNIT PUT uuid Put Unit record by uuid"); |
68
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
2522 | srv_send((char *)"."); |
81 | 2523 | } else if (strncmp(buf, "LIST", 4) == 0) { |
2524 | cmd_list(buf); | |
303
19a9a3912d03
Added PING/PONG command to the server. Bumped to version 0.2.7
Michiel Broek <mbroek@mbse.eu>
parents:
300
diff
changeset
|
2525 | } else if (strncmp(buf, "PING", 4) == 0) { |
19a9a3912d03
Added PING/PONG command to the server. Bumped to version 0.2.7
Michiel Broek <mbroek@mbse.eu>
parents:
300
diff
changeset
|
2526 | srv_send((char *)"101 PONG"); |
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
|
2527 | } 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
|
2528 | 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
|
2529 | wrconfig(); |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
2530 | #ifdef USE_SIMULATOR |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
2531 | } else if (strncmp(buf, "SIMULATOR", 9) == 0) { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
2532 | if (cmd_simulator(buf) == 0) |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
2533 | wrconfig(); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
2534 | #endif |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
2535 | } else if (strncmp(buf, "UNIT", 4) == 0) { |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2536 | if (cmd_unit(buf) == 0) |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
2537 | wrconfig(); |
43 | 2538 | } else { |
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
|
2539 | srv_send((char *)"500 Unknown command"); |
43 | 2540 | } |
2541 | } | |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2542 | } |
44 | 2543 | |
2544 | close(s); | |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2545 | } |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2546 | |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2547 | |
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
|
2548 | |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
2549 | #ifdef HAVE_WIRINGPI_H |
43 | 2550 | PI_THREAD (my_server_loop) |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
2551 | #else |
74 | 2552 | 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
|
2553 | #endif |
43 | 2554 | { |
2555 | socklen_t addrlen; | |
44 | 2556 | int optval = 1; |
43 | 2557 | |
2558 | syslog(LOG_NOTICE, "Thread my_server_loop started"); | |
2559 | if (debug) | |
2560 | fprintf(stdout, "Thread my_server_loop started\n"); | |
2561 | ||
44 | 2562 | memset((char *)&myaddr_in, 0, sizeof(struct sockaddr_in)); |
2563 | memset((char *)&peeraddr_in, 0, sizeof(struct sockaddr_in)); | |
2564 | myaddr_in.sin_family = AF_INET; | |
2565 | myaddr_in.sin_addr.s_addr = INADDR_ANY; | |
2566 | myaddr_in.sin_port = htons(Config.my_port); | |
2567 | ||
2568 | ls = socket(AF_INET, SOCK_STREAM, 0); | |
2569 | if (ls == -1) { | |
268
dda91dfa4aa8
All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents:
266
diff
changeset
|
2570 | syslog(LOG_NOTICE, "Can't create listen socket: %s", strerror(errno)); |
44 | 2571 | fprintf(stderr, "Can't create listen socket: %s\n", strerror(errno)); |
2572 | return 0; | |
2573 | } | |
2574 | ||
2575 | if (setsockopt(ls, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(optval)) == -1) { | |
268
dda91dfa4aa8
All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents:
266
diff
changeset
|
2576 | syslog(LOG_NOTICE, "Can't setsockopt SO_KEEPALIVE socket: %s", strerror(errno)); |
44 | 2577 | close(ls); |
2578 | return 0; | |
2579 | } | |
2580 | ||
2581 | if (setsockopt(ls, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) == -1) { | |
268
dda91dfa4aa8
All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents:
266
diff
changeset
|
2582 | syslog(LOG_NOTICE, "Can't setsockopt SO_REUSEADDR socket: %s", strerror(errno)); |
44 | 2583 | close(ls); |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
2584 | return 0; |
44 | 2585 | } |
2586 | ||
2587 | if (bind(ls, (struct sockaddr *)&myaddr_in, sizeof(struct sockaddr_in)) == -1) { | |
268
dda91dfa4aa8
All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents:
266
diff
changeset
|
2588 | syslog(LOG_NOTICE, "Can't bind to listen socket: %s", strerror(errno)); |
44 | 2589 | close(ls); |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
2590 | return 0; |
44 | 2591 | } |
2592 | ||
2593 | if (listen(ls, 5) == -1) { | |
268
dda91dfa4aa8
All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents:
266
diff
changeset
|
2594 | syslog(LOG_NOTICE, "Can't listen on listen socket: %s", strerror(errno)); |
44 | 2595 | close(ls); |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
2596 | return 0; |
44 | 2597 | } |
2598 | ||
2599 | syslog(LOG_NOTICE, "listen socket created %d", ls); | |
2600 | ||
2601 | ||
43 | 2602 | /* |
2603 | * Loop forever until the external shutdown variable is set. | |
2604 | */ | |
2605 | for (;;) { | |
2606 | ||
2607 | addrlen = sizeof(struct sockaddr_in); | |
2608 | /* | |
2609 | * This call will block until a new connection | |
2610 | * arrives. Then it will return the address of | |
2611 | * the connecting peer, and a new socket | |
2612 | * descriptor, s, for that connection. | |
2613 | */ | |
2614 | s = accept(ls, (struct sockaddr *)&peeraddr_in, &addrlen); | |
2615 | if (s == -1) { | |
268
dda91dfa4aa8
All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents:
266
diff
changeset
|
2616 | syslog(LOG_NOTICE, "my_server_loop accept failed %s", strerror(errno)); |
43 | 2617 | if (debug) |
2618 | fprintf(stdout, "my_server_loop accept failed %s\n", strerror(errno)); | |
44 | 2619 | return 0; |
43 | 2620 | } |
2621 | ||
48 | 2622 | cmd_server(); |
43 | 2623 | |
2624 | if (my_shutdown) { | |
2625 | syslog(LOG_NOTICE, "Thread my_server_loop stopped"); | |
2626 | if (debug) | |
2627 | fprintf(stdout, "Thread my_server_loop stopped\n"); | |
2628 | return 0; | |
2629 | } | |
2630 | ||
2631 | } | |
2632 | } | |
2633 | ||
2634 |