Sun, 24 Aug 2014 14:41:31 +0200
LIST LOG also output lines on state changes
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | /***************************************************************************** |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2 | * Copyright (C) 2008-2014 |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
3 | * |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
4 | * Michiel Broek <mbroek at mbse dot eu> |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
5 | * |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
6 | * This file is part of the mbsePi-apps |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
7 | * |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
8 | * This is free software; you can redistribute it and/or modify it |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
9 | * under the terms of the GNU General Public License as published by the |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
10 | * Free Software Foundation; either version 2, or (at your option) any |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
11 | * later version. |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
12 | * |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
13 | * mbsePi-apps is distributed in the hope that it will be useful, but |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
16 | * General Public License for more details. |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
17 | * |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
18 | * You should have received a copy of the GNU General Public License |
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 | |
48 | 56 | |
46
000399c64d3f
More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
57 | |
43 | 58 | /* |
59 | * Send message to client | |
60 | */ | |
61 | int srv_send(const char *format, ...) | |
62 | { | |
63 | char out[SS_BUFSIZE]; | |
64 | va_list va_ptr; | |
65 | ||
66 | if (s == -1) | |
67 | return -1; | |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
68 | |
43 | 69 | va_start(va_ptr, format); |
70 | vsnprintf(out, SS_BUFSIZE-1, format, va_ptr); | |
71 | va_end(va_ptr); | |
72 | ||
48 | 73 | if (debug) { |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
74 | syslog(LOG_NOTICE, "send: \"%s\"", out); |
45
053c4657105f
Mirror LCD display on the webpage works
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
75 | fprintf(stdout, "send: \"%s\"\n", out); |
48 | 76 | } |
44 | 77 | |
43 | 78 | if (send(s, out, strlen(out), 0) != strlen(out)) { |
235 | 79 | syslog(LOG_WARNING, "srv_send failed"); |
43 | 80 | return -1; |
81 | } | |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
82 | |
43 | 83 | if (send(s, (char *)"\r\n", 2, 0) != 2) { |
235 | 84 | syslog(LOG_WARNING, "srv_send failed"); |
43 | 85 | return -1; |
86 | } | |
87 | ||
88 | return 0; | |
89 | } | |
90 | ||
91 | ||
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
92 | |
88 | 93 | /* |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
94 | * 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
|
95 | */ |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
96 | 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
|
97 | { |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
98 | 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
|
99 | |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
100 | 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
|
101 | if (strcmp(device->uuid, uuid) == 0) { |
240
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
102 | #ifdef HAVE_WIRINGPI_H |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
103 | piLock(LOCK_DEVICES); |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
104 | #endif |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
105 | 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
|
106 | device->inuse++; |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
107 | } else { |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
108 | 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
|
109 | device->inuse--; |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
110 | } |
240
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
111 | #ifdef HAVE_WIRINGPI_H |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
112 | piUnlock(LOCK_DEVICES); |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
113 | #endif |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
114 | } |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
115 | } |
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 | |
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 | |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
120 | int delete_Profile(char *uuid) |
138 | 121 | { |
122 | profiles_list *current = Config.profiles; | |
123 | profiles_list *previous = NULL; | |
124 | prof_step *step, *olds; | |
125 | ||
126 | while (current) { | |
127 | if (strcmp(current->uuid, uuid) == 0) { | |
128 | if (previous == NULL) { | |
129 | Config.profiles = current->next; | |
130 | free(current->uuid); | |
131 | current->uuid = NULL; | |
132 | free(current->name); | |
133 | current->name = NULL; | |
134 | if (current->steps) { | |
135 | for (step = current->steps; step; step = olds) { | |
136 | olds = step->next; | |
137 | free(step); | |
138 | } | |
139 | current->steps = NULL; | |
140 | } | |
141 | free(current); | |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
142 | return 1; |
138 | 143 | } else { |
144 | free(current->uuid); | |
145 | current->uuid = NULL; | |
146 | free(current->name); | |
147 | current->name = NULL; | |
148 | if (current->steps) { | |
149 | for (step = current->steps; step; step = olds) { | |
150 | olds = step->next; | |
151 | free(step); | |
152 | } | |
153 | current->steps = NULL; | |
154 | } | |
155 | previous->next = current->next; | |
156 | free(current); | |
157 | current = previous->next; | |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
158 | return 1; |
138 | 159 | } |
160 | } else { | |
161 | previous = current; | |
162 | current = current->next; | |
163 | } | |
164 | } | |
165 | ||
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
166 | return 0; |
138 | 167 | } |
168 | ||
169 | ||
170 | ||
174 | 171 | int delete_Device(char *uuid) |
172 | { | |
173 | devices_list *current = Config.devices; | |
174 | devices_list *previous = NULL; | |
175 | ||
176 | while (current) { | |
177 | if (strcmp(current->uuid, uuid) == 0) { | |
178 | if (previous == NULL) { | |
179 | Config.devices = current->next; | |
180 | free(current->uuid); | |
181 | current->uuid = NULL; | |
182 | free(current->address); | |
183 | current->address = NULL; | |
184 | free(current->description); | |
185 | current->description = NULL; | |
186 | free(current->comment); | |
187 | current->comment = NULL; | |
188 | free(current); | |
189 | return 1; | |
190 | } else { | |
191 | free(current->uuid); | |
192 | current->uuid = NULL; | |
193 | free(current->address); | |
194 | current->address = NULL; | |
195 | free(current->description); | |
196 | current->description = NULL; | |
197 | free(current->comment); | |
198 | current->comment = NULL; | |
199 | previous->next = current->next; | |
200 | free(current); | |
201 | current = previous->next; | |
202 | return 1; | |
203 | } | |
204 | } else { | |
205 | previous = current; | |
206 | current = current->next; | |
207 | } | |
208 | } | |
209 | return 0; | |
210 | } | |
211 | ||
212 | ||
213 | ||
81 | 214 | /* |
174 | 215 | * DEVICE ADD type |
216 | * DEVICE DEL uuid | |
217 | * DEVICE LIST | |
218 | * DEVICE GET uuid | |
219 | * DEVICE PUT uuid | |
157
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
220 | */ |
174 | 221 | int cmd_device(char *buf) |
157
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
222 | { |
174 | 223 | char *opt, *param, *kwd, *val, ibuf[SS_BUFSIZE]; |
224 | devices_list *device, *tmpd; | |
225 | socklen_t fromlen; | |
240
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
226 | int i, rc, rlen, ival; |
174 | 227 | uuid_t uu; |
157
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
228 | |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
229 | opt = strtok(buf, " \0"); |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
230 | opt = strtok(NULL, " \0"); |
174 | 231 | |
232 | if (opt == NULL) { | |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
233 | srv_send((char *)"501 Subcommand missing"); |
174 | 234 | return 1; |
235 | } | |
236 | param = strtok(NULL, "\0"); | |
157
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
237 | |
174 | 238 | if (strcmp(opt, (char *)"LIST") == 0) { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
239 | srv_send((char *)"212 Devices list follows:"); |
174 | 240 | for (device = Config.devices; device; device = device->next) { |
175
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
241 | srv_send((char *)"%s,%s,%d,%d,%s,%s", device->uuid, device->address, device->subdevice, device->inuse, device->comment, DEVDIR[device->direction]); |
174 | 242 | } |
243 | 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
|
244 | return 1; |
174 | 245 | } |
246 | ||
247 | if (param == NULL) { | |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
248 | 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
|
249 | return 1; |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
250 | } |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
251 | |
174 | 252 | if (strcmp(opt, (char *)"ADD") == 0) { |
253 | if ((strcmp(param, (char *)"RC433") == 0) || (strcmp(param, (char *)"DHT") == 0) || | |
254 | (strcmp(param, (char *)"I2C") == 0) || (strcmp(param, (char *)"SPI") == 0)) { | |
170 | 255 | |
174 | 256 | device = (devices_list *)malloc(sizeof(devices_list)); |
257 | device->next = NULL; | |
258 | device->version = 1; | |
259 | device->uuid = malloc(37); | |
260 | uuid_generate(uu); | |
261 | 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
|
262 | for (i = 0; i < 8; i++) { |
174 | 263 | if (strcmp(param, DEVTYPE[i]) == 0) { |
264 | device->type = i; | |
265 | break; | |
266 | } | |
267 | } | |
268 | device->direction = DEVDIR_UNDEF; | |
209
c5b1dfd83e81
Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents:
208
diff
changeset
|
269 | device->value = device->offset = device->subdevice = device->inuse = 0; |
174 | 270 | device->present = DEVPRESENT_UNDEF; |
271 | device->address = xstrcpy((char *)"Enter address here"); | |
272 | device->gpiopin = -1; | |
273 | device->description = xstrcpy((char *)"Describe me here"); | |
274 | device->comment = xstrcpy((char *)"Comment here"); | |
170 | 275 | |
240
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
276 | #ifdef HAVE_WIRINGPI_H |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
277 | piLock(LOCK_DEVICES); |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
278 | #endif |
174 | 279 | if (Config.devices == NULL) { |
280 | Config.devices = device; | |
281 | } else { | |
282 | for (tmpd = Config.devices; tmpd; tmpd = tmpd->next) { | |
283 | if (tmpd->next == NULL) { | |
284 | tmpd->next = device; | |
285 | break; | |
286 | } | |
157
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
287 | } |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
288 | } |
240
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
289 | #ifdef HAVE_WIRINGPI_H |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
290 | piUnlock(LOCK_DEVICES); |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
291 | #endif |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
292 | syslog(LOG_NOTICE, "Device %s added", device->uuid); |
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
293 | srv_send((char *)"211 Device %s added", device->uuid); |
174 | 294 | return 0; |
157
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
295 | |
174 | 296 | } else { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
297 | 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
|
298 | return 1; |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
299 | } |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
300 | } |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
301 | |
174 | 302 | if (strcmp(opt, (char *)"DEL") == 0) { |
303 | ||
240
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
304 | #ifdef HAVE_WIRINGPI_H |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
305 | piLock(LOCK_DEVICES); |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
306 | #endif |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
307 | rc = delete_Device(param); |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
308 | #ifdef HAVE_WIRINGPI_H |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
309 | piUnlock(LOCK_DEVICES); |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
310 | #endif |
6bdda35b4a13
Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents:
237
diff
changeset
|
311 | if (rc) { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
312 | syslog(LOG_NOTICE, "Device %s deleted", param); |
174 | 313 | srv_send((char *)"211 Device %s deleted", param); |
314 | return 0; | |
315 | } else { | |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
316 | srv_send((char *)"440 No such device"); |
174 | 317 | return 1; |
318 | } | |
319 | } | |
320 | ||
321 | if (strcmp(opt, (char *)"GET") == 0) { | |
322 | for (device = Config.devices; device; device = device->next) { | |
323 | if (strcmp(device->uuid, param) == 0) { | |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
324 | srv_send((char *)"213 Device record follows:"); |
174 | 325 | srv_send((char *)"TYPE,%s", DEVTYPE[device->type]); |
326 | srv_send((char *)"DIRECTION,%s", DEVDIR[device->direction]); | |
327 | srv_send((char *)"VALUE,%d", device->value); | |
209
c5b1dfd83e81
Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents:
208
diff
changeset
|
328 | srv_send((char *)"OFFSET,%d", device->offset); |
174 | 329 | srv_send((char *)"PRESENT,%s", DEVPRESENT[device->present]); |
330 | srv_send((char *)"ADDRESS,%s", device->address); | |
331 | srv_send((char *)"SUBDEVICE,%d", device->subdevice); | |
332 | srv_send((char *)"GPIOPIN,%d", device->gpiopin); | |
333 | srv_send((char *)"DESCRIPTION,%s", device->description); | |
334 | srv_send((char *)"INUSE,%d", device->inuse); | |
335 | srv_send((char *)"COMMENT,%s", device->comment); | |
336 | srv_send((char *)"TIMESTAMP,%d", (int)device->timestamp); | |
337 | srv_send((char *)"."); | |
338 | return 1; | |
339 | } | |
340 | } | |
341 | srv_send((char *)"440 No such device"); | |
342 | return 1; | |
343 | } | |
344 | ||
345 | if (strcmp(opt, (char *)"PUT") == 0) { | |
346 | for (device = Config.devices; device; device = device->next) { | |
347 | if (strcmp(device->uuid, param) == 0) { | |
348 | while (1) { | |
349 | memset((char *)&ibuf, 0, SS_BUFSIZE); | |
350 | fromlen = sizeof(peeraddr_in); | |
351 | rlen = recvfrom(s, ibuf, sizeof(ibuf) -1, 0, (struct sockaddr *)&peeraddr_in, &fromlen); | |
352 | if (rlen == -1) { | |
235 | 353 | syslog(LOG_WARNING, "recvfrom(): %s", strerror(errno)); |
174 | 354 | srv_send((char *)"518 recfrom(): %s", strerror(errno)); |
355 | return 1; | |
356 | } | |
357 | for (i = 0; i < strlen(ibuf); i++) { | |
358 | if (ibuf[i] == '\n') | |
359 | ibuf[i] = '\0'; | |
360 | if (ibuf[i] == '\r') | |
361 | ibuf[i] = '\0'; | |
362 | } | |
363 | for (i = strlen(ibuf) -1; i > 0; i--) { | |
364 | if (ibuf[i] == ' ') | |
365 | ibuf[i] = '\0'; | |
366 | else | |
367 | break; | |
368 | } | |
369 | if (strlen(ibuf)) { | |
370 | if (debug) { | |
371 | syslog(LOG_NOTICE, "recv: \"%s\"", ibuf); | |
372 | fprintf(stdout, "recv: \"%s\"\n", ibuf); | |
373 | } | |
374 | if (strcmp(ibuf, (char *)".") == 0) { | |
375 | srv_send((char *)"219 Accepted Device record"); | |
376 | return 0; | |
377 | } | |
378 | kwd = strtok(ibuf, ",\0"); | |
379 | val = strtok(NULL, "\0"); | |
380 | if (kwd && val) { | |
381 | 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
|
382 | for (i = 0; i < 8; i++) { |
174 | 383 | if (strcmp(val, DEVTYPE[i]) == 0) { |
384 | device->type = i; | |
385 | break; | |
386 | } | |
387 | } | |
388 | ||
389 | } else if (strcmp(kwd, (char *)"DIRECTION") == 0) { | |
390 | for (i = 0; i < 7; i++) { | |
391 | if (strcmp(val, DEVDIR[i]) == 0) { | |
392 | device->direction = i; | |
393 | break; | |
394 | } | |
395 | } | |
396 | ||
397 | } else if (strcmp(kwd, (char *)"VALUE") == 0) { | |
398 | if (sscanf(val, "%d", &ival) == 1) | |
399 | device->value = ival; | |
400 | ||
209
c5b1dfd83e81
Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents:
208
diff
changeset
|
401 | } else if (strcmp(kwd, (char *)"OFFSET") == 0) { |
c5b1dfd83e81
Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents:
208
diff
changeset
|
402 | if (sscanf(val, "%d", &ival) == 1) |
c5b1dfd83e81
Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents:
208
diff
changeset
|
403 | device->offset = ival; |
c5b1dfd83e81
Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents:
208
diff
changeset
|
404 | |
174 | 405 | } else if (strcmp(kwd, (char *)"PRESENT") == 0) { |
406 | 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
|
407 | if (strcmp(val, DEVPRESENT[i]) == 0) { |
174 | 408 | device->present = i; |
409 | break; | |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
410 | } |
174 | 411 | } |
412 | ||
413 | } else if (strcmp(kwd, (char *)"ADDRESS") == 0) { | |
414 | if (device->address) | |
415 | free(device->address); | |
416 | device->address = xstrcpy(val); | |
417 | ||
418 | } else if (strcmp(kwd, (char *)"SUBDEVICE") == 0) { | |
419 | if (sscanf(val, "%d", &ival) == 1) | |
420 | device->subdevice = ival; | |
421 | ||
422 | } else if (strcmp(kwd, (char *)"GPIOPIN") == 0) { | |
423 | if (sscanf(val, "%d", &ival) == 1) | |
424 | device->gpiopin = ival; | |
425 | ||
426 | } else if (strcmp(kwd, (char *)"DESCRIPTION") == 0) { | |
427 | if (device->description) | |
428 | free(device->description); | |
429 | device->description = xstrcpy(val); | |
430 | ||
431 | } else if (strcmp(kwd, (char *)"COMMENT") == 0) { | |
432 | if (device->comment) | |
433 | free(device->comment); | |
434 | device->comment = xstrcpy(val); | |
435 | ||
436 | } | |
437 | } | |
438 | } | |
439 | } | |
440 | } | |
441 | } | |
442 | srv_send((char *)"440 No such device"); | |
443 | return 1; | |
444 | } | |
445 | ||
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
446 | 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
|
447 | return 1; |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
448 | } |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
449 | |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
450 | |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
451 | |
259a018758f9
Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents:
156
diff
changeset
|
452 | /* |
206
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
453 | * GLOBAL GET |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
454 | * GLOBAL PUT |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
455 | */ |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
456 | int cmd_global(char *buf) |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
457 | { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
458 | char *opt, *kwd, *val, ibuf[SS_BUFSIZE]; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
459 | int ival, i, rlen; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
460 | socklen_t fromlen; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
461 | |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
462 | opt = strtok(buf, " \0"); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
463 | opt = strtok(NULL, "\0"); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
464 | |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
465 | if (opt == NULL) { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
466 | srv_send((char *)"501 Subcommand missing"); |
206
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
467 | return 1; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
468 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
469 | |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
470 | if (strcmp(opt, (char *)"GET") == 0) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
471 | srv_send((char *)"213 Global Settings record follows:"); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
472 | srv_send((char *)"NAME,%s", Config.name); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
473 | 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
|
474 | srv_send((char *)"TEMPFORMAT,%c", Config.tempFormat); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
475 | 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
|
476 | 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
|
477 | 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
|
478 | 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
|
479 | 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
|
480 | 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
|
481 | #ifdef HAVE_WIRINGPI_H |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
482 | 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
|
483 | 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
|
484 | #endif |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
485 | srv_send((char *)"."); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
486 | return 1; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
487 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
488 | |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
489 | if (strcmp(opt, (char *)"PUT") == 0) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
490 | while (1) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
491 | memset((char *)&ibuf, 0, SS_BUFSIZE); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
492 | fromlen = sizeof(peeraddr_in); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
493 | 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
|
494 | if (rlen == -1) { |
235 | 495 | syslog(LOG_WARNING, "recvfrom(): %s", strerror(errno)); |
206
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
496 | 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
|
497 | return 1; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
498 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
499 | for (i = 0; i < strlen(ibuf); i++) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
500 | if (ibuf[i] == '\n') |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
501 | ibuf[i] = '\0'; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
502 | if (ibuf[i] == '\r') |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
503 | ibuf[i] = '\0'; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
504 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
505 | 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
|
506 | if (ibuf[i] == ' ') |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
507 | ibuf[i] = '\0'; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
508 | else |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
509 | break; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
510 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
511 | if (strlen(ibuf)) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
512 | if (debug) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
513 | syslog(LOG_NOTICE, "recv: \"%s\"", ibuf); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
514 | fprintf(stdout, "recv: \"%s\"\n", ibuf); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
515 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
516 | if (strcmp(ibuf, (char *)".") == 0) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
517 | srv_send((char *)"219 Accepted Global record"); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
518 | return 0; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
519 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
520 | kwd = strtok(ibuf, ",\0"); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
521 | val = strtok(NULL, "\0"); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
522 | if (kwd) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
523 | if (strcmp(kwd, (char *)"NAME") == 0) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
524 | if (Config.name) |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
525 | free(Config.name); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
526 | if (val) |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
527 | Config.name = xstrcpy(val); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
528 | else |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
529 | Config.name = NULL; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
530 | |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
531 | } else if (val && (strcmp(kwd, (char *)"PORT") == 0)) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
532 | if (sscanf(val, "%d", &ival) == 1) |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
533 | Config.my_port = ival; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
534 | |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
535 | } else if (val && (strcmp(kwd, (char *)"TEMPFORMAT") == 0)) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
536 | if ((val[0] == 'C') || (val[0] == 'F')) |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
537 | Config.tempFormat = val[0]; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
538 | |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
539 | } else if (strcmp(kwd, (char *)"TEMP_ADDRESS") == 0) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
540 | if (Config.temp_address) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
541 | device_count(FALSE, Config.temp_address); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
542 | free(Config.temp_address); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
543 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
544 | if (val) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
545 | Config.temp_address = xstrcpy(val); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
546 | device_count(TRUE, Config.temp_address); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
547 | } else |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
548 | Config.temp_address = NULL; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
549 | |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
550 | } else if (strcmp(kwd, (char *)"HUM_ADDRESS") == 0) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
551 | if (Config.hum_address) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
552 | device_count(FALSE, Config.hum_address); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
553 | free(Config.hum_address); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
554 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
555 | if (val) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
556 | Config.hum_address = xstrcpy(val); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
557 | device_count(TRUE, Config.hum_address); |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
558 | } else |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
559 | Config.hum_address = NULL; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
560 | |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
561 | #ifdef HAVE_WIRINGPI_H |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
562 | } else if (val && (strcmp(kwd, (char *)"LCD_COLS") == 0)) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
563 | if (sscanf(val, "%d", &ival) == 1) |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
564 | Config.lcd_cols = ival; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
565 | |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
566 | } else if (val && (strcmp(kwd, (char *)"LCD_ROWS") == 0)) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
567 | if (sscanf(val, "%d", &ival) == 1) |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
568 | Config.lcd_rows = ival; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
569 | #endif |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
570 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
571 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
572 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
573 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
574 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
575 | |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
576 | srv_send((char *)"504 Subcommand error"); |
206
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
577 | return 1; |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
578 | } |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
579 | |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
580 | |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
581 | |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
582 | /* |
81 | 583 | * LIST |
120 | 584 | * LIST LOG |
81 | 585 | */ |
586 | int cmd_list(char *buf) | |
587 | { | |
264
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
588 | char *opt, *param, *filename, q[2], buffer[256], *copy = NULL; |
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
589 | char *mode_o = NULL, *mode_n, *target_o = NULL, *target_n, *heater_o = NULL, *heater_n, *cooler_o = NULL, *cooler_n; |
84 | 590 | units_list *unit; |
120 | 591 | FILE *fp; |
81 | 592 | |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
593 | opt = strtok(buf, " \0"); |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
594 | opt = strtok(NULL, " \0"); |
84 | 595 | |
81 | 596 | if (opt == NULL) { |
92 | 597 | /* |
598 | * Default, list available units | |
599 | */ | |
81 | 600 | srv_send((char *)"212 Fermenter list follows:"); |
601 | 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
|
602 | srv_send((char *)"%s,%s,%s", unit->uuid, unit->name, UNITMODE[unit->mode]); |
81 | 603 | } |
604 | 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
|
605 | return 1; |
92 | 606 | |
120 | 607 | } 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
|
608 | |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
609 | param = strtok(NULL, "\0"); |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
610 | if (param == NULL) { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
611 | srv_send((char *)"502 Parameter missing"); |
120 | 612 | return 1; |
613 | } | |
614 | ||
615 | q[0] = q[1] = 'a'; | |
616 | 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
|
617 | if (strcmp(param, unit->uuid) == 0) |
120 | 618 | break; |
619 | } | |
620 | ||
621 | srv_send((char *)"212 Logfile list follows:"); | |
622 | if (getenv((char *)"USER") == NULL) { | |
623 | filename = xstrcpy((char *)"/root"); | |
624 | } else { | |
625 | filename = xstrcpy(getenv((char *)"HOME")); | |
626 | } | |
627 | filename = xstrcat(filename, (char *)"/.thermferm/log/"); | |
628 | filename = xstrcat(filename, unit->name); | |
629 | filename = xstrcat(filename, (char *)".log"); | |
630 | if ((fp = fopen(filename, "r"))) { | |
631 | while (fgets(buffer, sizeof(buffer)-1, fp) != NULL) { | |
632 | buffer[strlen(buffer) -1] = '\0'; | |
264
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
633 | copy = xstrcpy(buffer); |
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
634 | mode_n = strtok(buffer, ",\0"); |
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
635 | mode_n = strtok(NULL, ",\0"); |
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
636 | target_n = strtok(NULL, ",\0"); /* skip air_temp */ |
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
637 | target_n = strtok(NULL, ",\0"); /* skip beer temp */ |
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
638 | target_n = strtok(NULL, ",\0"); |
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
639 | heater_n = strtok(NULL, ",\0"); |
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
640 | cooler_n = strtok(NULL, ",\0"); |
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
641 | |
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
642 | if (strncmp(mode_n, (char *)"Mode", 4)) { |
120 | 643 | if ((q[0] != buffer[11]) || (q[1] != buffer[12])) { |
644 | q[0] = buffer[11]; | |
645 | q[1] = buffer[12]; | |
264
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
646 | srv_send(copy); |
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
647 | } else if ((mode_o && strcmp(mode_o, mode_n)) || (target_o && strcmp(target_o, target_n)) || |
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
648 | (heater_o && strcmp(heater_o, heater_n)) || (cooler_o && strcmp(cooler_o, cooler_n))) { |
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
649 | srv_send(copy); |
120 | 650 | } |
651 | } | |
264
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
652 | |
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
653 | free(copy); |
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
654 | copy = NULL; |
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
655 | if (mode_o) |
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
656 | free(mode_o); |
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
657 | mode_o = xstrcpy(mode_n); |
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
658 | if (target_o) |
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
659 | free(target_o); |
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
660 | target_o = xstrcpy(target_n); |
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
661 | if (heater_o) |
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
662 | free(heater_o); |
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
663 | heater_o = xstrcpy(heater_n); |
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
664 | if (cooler_o) |
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
665 | free(cooler_o); |
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
261
diff
changeset
|
666 | cooler_o = xstrcpy(cooler_n); |
120 | 667 | } |
668 | } | |
669 | free(filename); | |
670 | filename = NULL; | |
671 | 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
|
672 | return 1; |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
673 | } |
120 | 674 | |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
675 | srv_send((char *)"504 Subcommand error"); |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
676 | return 1; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
677 | } |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
678 | |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
679 | |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
680 | |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
681 | /* |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
682 | * PROFILE ADD name Add a new profile |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
683 | * PROFILE DEL uuid Delete profile with uuid |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
684 | * PROFILE LIST List available profiles |
258
e02393b29733
Updated web dashboard layout
Michiel Broek <mbroek@mbse.eu>
parents:
249
diff
changeset
|
685 | * PROFILE GET uuid Get profile record |
e02393b29733
Updated web dashboard layout
Michiel Broek <mbroek@mbse.eu>
parents:
249
diff
changeset
|
686 | * PROFILE PUT uuid Put profile record |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
687 | * PROFILE GETS uuid Get profile steps list |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
688 | * PROFILE PUTS uuid Put profile steps list |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
689 | */ |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
690 | int cmd_profile(char *buf) |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
691 | { |
192
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
692 | 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
|
693 | 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
|
694 | float ftarg, fval; |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
695 | socklen_t fromlen; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
696 | char *opt; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
697 | profiles_list *profile, *tmpp; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
698 | prof_step *step, *olds; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
699 | uuid_t uu; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
700 | |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
701 | opt = strtok(buf, " \0"); |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
702 | opt = strtok(NULL, " \0"); |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
703 | |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
704 | if (opt == NULL) { |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
705 | srv_send((char *)"501 Subcommand missing"); |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
706 | return 1; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
707 | } |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
708 | |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
709 | 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
|
710 | /* |
92 | 711 | * Fermenting profiles |
86
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
712 | */ |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
713 | srv_send((char *)"212 Profiles list follows:"); |
92 | 714 | 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
|
715 | j = 0; |
350401bac16e
Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents:
120
diff
changeset
|
716 | 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
|
717 | j++; |
136
264e5ee5abfc
Profiles now have a busy state
Michiel Broek <mbroek@mbse.eu>
parents:
133
diff
changeset
|
718 | 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
|
719 | } |
92 | 720 | srv_send((char *)"."); |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
721 | return 1; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
722 | } |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
723 | |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
724 | param = strtok(NULL, "\0"); |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
725 | if (param == NULL) { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
726 | srv_send((char *)"502 Parameter missing"); |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
727 | return 1; |
81 | 728 | } |
729 | ||
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
730 | if (strcmp(opt, (char *)"ADD") == 0) { |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
731 | profile = (profiles_list *)malloc(sizeof(profiles_list)); |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
732 | profile->next = NULL; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
733 | profile->version = 1; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
734 | profile->uuid = malloc(37); |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
735 | uuid_generate(uu); |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
736 | uuid_unparse(uu, profile->uuid); |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
737 | profile->name = xstrcpy(param); |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
738 | profile->busy = 0; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
739 | profile->inittemp = 20.0; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
740 | profile->steps = NULL; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
741 | if (Config.profiles == NULL) { |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
742 | Config.profiles = profile; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
743 | } else { |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
744 | 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
|
745 | if (tmpp->next == NULL) { |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
746 | tmpp->next = profile; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
747 | break; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
748 | } |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
749 | } |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
750 | } |
81 | 751 | |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
752 | syslog(LOG_NOTICE, "Profile %s added", profile->uuid); |
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
753 | 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
|
754 | return 0; |
81 | 755 | |
756 | ||
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
757 | } else if (strcmp(opt, (char *)"DEL") == 0) { |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
758 | if (delete_Profile(param)) { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
759 | 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
|
760 | 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
|
761 | return 0; |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
762 | } else { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
763 | 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
|
764 | 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
|
765 | } |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
766 | |
192
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
767 | } 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
|
768 | 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
|
769 | if (strcmp(profile->uuid, param) == 0) { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
770 | 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
|
771 | 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
|
772 | 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
|
773 | 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
|
774 | srv_send((char *)"."); |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
775 | return 1; |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
776 | } |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
777 | } |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
778 | 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
|
779 | return 1; |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
780 | |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
781 | } 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
|
782 | 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
|
783 | 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
|
784 | while (1) { |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
785 | 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
|
786 | 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
|
787 | 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
|
788 | if (rlen == -1) { |
235 | 789 | syslog(LOG_WARNING, "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
|
790 | 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
|
791 | return 1; |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
792 | } |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
793 | 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
|
794 | 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
|
795 | ibuf[i] = '\0'; |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
796 | 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
|
797 | ibuf[i] = '\0'; |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
798 | } |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
799 | 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
|
800 | if (ibuf[i] == ' ') |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
801 | ibuf[i] = '\0'; |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
802 | else |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
803 | break; |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
804 | } |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
805 | if (strlen(ibuf)) { |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
806 | if (debug) { |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
807 | 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
|
808 | 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
|
809 | } |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
810 | if (strcmp(ibuf, (char *)".") == 0) { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
811 | 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
|
812 | return 0; |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
813 | } |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
814 | 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
|
815 | 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
|
816 | if (kwd && val) { |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
817 | if (strcmp(kwd, (char *)"NAME") == 0) { |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
818 | if (profile->name) |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
819 | free(profile->name); |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
820 | 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
|
821 | } else if (strcmp(kwd, (char *)"INITTEMP") == 0) { |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
822 | if (sscanf(val, "%f", &fval) == 1) |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
823 | profile->inittemp = fval; |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
824 | } |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
825 | } |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
826 | } |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
827 | } |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
828 | } |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
829 | } |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
830 | 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
|
831 | return 1; |
5d013b4a9138
Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
191
diff
changeset
|
832 | |
140
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
833 | } else if (strcmp(opt, (char *)"GETS") == 0) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
834 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
835 | 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
|
836 | if (strcmp(profile->uuid, param) == 0) { |
140
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
837 | srv_send((char *)"215 Profile steps follow:"); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
838 | for (step = profile->steps; step; step = step->next) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
839 | 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
|
840 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
841 | srv_send((char *)"."); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
842 | return 1; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
843 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
844 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
845 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
846 | srv_send((char *)"440 No such profile"); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
847 | return 1; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
848 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
849 | } else if (strcmp(opt, (char *)"PUTS") == 0) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
850 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
851 | 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
|
852 | if (strcmp(profile->uuid, param) == 0) { |
140
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
853 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
854 | if (profile->steps) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
855 | for (step = profile->steps; step; step = olds) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
856 | olds = step->next; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
857 | free(step); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
858 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
859 | profile->steps = NULL; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
860 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
861 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
862 | while (1) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
863 | memset((char *)&ibuf, 0, SS_BUFSIZE); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
864 | fromlen = sizeof(peeraddr_in); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
865 | 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
|
866 | if (rlen == -1) { |
235 | 867 | syslog(LOG_WARNING, "recvfrom(): %s", strerror(errno)); |
140
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
868 | srv_send((char *)"518 recfrom(): %s", strerror(errno)); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
869 | return 1; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
870 | } else { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
871 | for (i = 0; i < strlen(ibuf); i++) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
872 | if (ibuf[i] == '\n') |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
873 | ibuf[i] = '\0'; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
874 | if (ibuf[i] == '\r') |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
875 | ibuf[i] = '\0'; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
876 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
877 | for (i = strlen(ibuf) -1; i > 0; i--) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
878 | if (ibuf[i] == ' ') |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
879 | ibuf[i] = '\0'; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
880 | else |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
881 | break; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
882 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
883 | if (strlen(ibuf)) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
884 | if (debug) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
885 | syslog(LOG_NOTICE, "recv: \"%s\"", ibuf); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
886 | fprintf(stdout, "recv: \"%s\"\n", ibuf); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
887 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
888 | if (strcmp(ibuf, (char *)".") == 0) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
889 | |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
890 | srv_send((char *)"219 Accepted Profile steps"); |
140
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
891 | return 0; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
892 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
893 | sstep = strtok(ibuf, ",\0"); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
894 | rest = strtok(NULL, ",\0"); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
895 | targ = strtok(NULL, "\0"); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
896 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
897 | if ((sscanf(sstep, "%d", &istep) == 1) && |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
898 | (sscanf(rest, "%d", &irest) == 1) && |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
899 | (sscanf(targ, "%f", &ftarg) == 1)) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
900 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
901 | step = (prof_step *)malloc(sizeof(prof_step)); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
902 | step->next = NULL; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
903 | step->version = 1; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
904 | step->steptime = istep; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
905 | step->resttime = irest; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
906 | step->target = ftarg; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
907 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
908 | if (profile->steps == NULL) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
909 | profile->steps = step; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
910 | } else { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
911 | for (olds = profile->steps; olds; olds = olds->next) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
912 | if (olds->next == NULL) { |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
913 | olds->next = step; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
914 | break; |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
915 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
916 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
917 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
918 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
919 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
920 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
921 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
922 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
923 | } |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
924 | |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
925 | srv_send((char *)"440 No such profile"); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
926 | return 1; |
88 | 927 | } |
928 | ||
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
929 | srv_send((char *)"504 Subcommand error"); |
88 | 930 | return 1; |
931 | } | |
932 | ||
933 | ||
934 | ||
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
|
935 | #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
|
936 | 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
|
937 | { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
938 | 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
|
939 | 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
|
940 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
941 | 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
|
942 | 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
|
943 | 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
|
944 | 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
|
945 | 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
|
946 | 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
|
947 | 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
|
948 | 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
|
949 | 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
|
950 | 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
|
951 | } 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
|
952 | 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
|
953 | 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
|
954 | 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
|
955 | 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
|
956 | 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
|
957 | 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
|
958 | 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
|
959 | 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
|
960 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
961 | } 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
|
962 | 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
|
963 | 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
|
964 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
965 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
966 | 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
|
967 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
968 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
969 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
970 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
971 | /* |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
972 | * 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
|
973 | * 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
|
974 | * 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
|
975 | * 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
|
976 | * 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
|
977 | */ |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
978 | 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
|
979 | { |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
980 | 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
|
981 | 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
|
982 | 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
|
983 | 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
|
984 | 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
|
985 | 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
|
986 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
987 | 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
|
988 | 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
|
989 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
990 | 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
|
991 | 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
|
992 | 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
|
993 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
994 | 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
|
995 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
996 | 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
|
997 | 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
|
998 | 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
|
999 | 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
|
1000 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1001 | 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
|
1002 | 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
|
1003 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1004 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1005 | 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
|
1006 | 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
|
1007 | 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
|
1008 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1009 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1010 | 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
|
1011 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1012 | /* |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1013 | * 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
|
1014 | */ |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1015 | 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
|
1016 | 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
|
1017 | 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
|
1018 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1019 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1020 | 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
|
1021 | 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
|
1022 | 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
|
1023 | 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
|
1024 | 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
|
1025 | 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
|
1026 | 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
|
1027 | 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
|
1028 | 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
|
1029 | 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
|
1030 | 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
|
1031 | 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
|
1032 | 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
|
1033 | 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
|
1034 | 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
|
1035 | 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
|
1036 | 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
|
1037 | 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
|
1038 | 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
|
1039 | 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
|
1040 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1041 | 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
|
1042 | 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
|
1043 | } 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
|
1044 | 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
|
1045 | 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
|
1046 | 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
|
1047 | 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
|
1048 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1049 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1050 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1051 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1052 | 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
|
1053 | 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
|
1054 | 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
|
1055 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1056 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1057 | 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
|
1058 | 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
|
1059 | 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
|
1060 | 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
|
1061 | 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
|
1062 | 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
|
1063 | } 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
|
1064 | 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
|
1065 | 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
|
1066 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1067 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1068 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1069 | 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
|
1070 | 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
|
1071 | 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
|
1072 | 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
|
1073 | 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
|
1074 | 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
|
1075 | 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
|
1076 | 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
|
1077 | 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
|
1078 | 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
|
1079 | 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
|
1080 | srv_send((char *)"COOLER_TIME,%d", simulator->cooler_time); |
261 | 1081 | 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
|
1082 | 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
|
1083 | 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
|
1084 | 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
|
1085 | 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
|
1086 | srv_send((char *)"COOLER_STATE,%d", simulator->cooler_state); |
261 | 1087 | 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
|
1088 | 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
|
1089 | 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
|
1090 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1091 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1092 | 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
|
1093 | 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
|
1094 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1095 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1096 | 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
|
1097 | 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
|
1098 | 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
|
1099 | 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
|
1100 | 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
|
1101 | 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
|
1102 | 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
|
1103 | if (rlen == -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
|
1104 | syslog(LOG_WARNING, "recvfrom(): %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
|
1105 | 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
|
1106 | 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
|
1107 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1108 | 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
|
1109 | 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
|
1110 | 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
|
1111 | 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
|
1112 | 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
|
1113 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1114 | 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
|
1115 | 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
|
1116 | 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
|
1117 | 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
|
1118 | 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
|
1119 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1120 | 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
|
1121 | 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
|
1122 | 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
|
1123 | 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
|
1124 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1125 | 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
|
1126 | 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
|
1127 | 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
|
1128 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1129 | 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
|
1130 | 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
|
1131 | 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
|
1132 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1133 | if (strcmp(kwd, (char *)"NAME") == 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
|
1134 | if (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
|
1135 | free(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
|
1136 | 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
|
1137 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1138 | } else if (strcmp(kwd, (char *)"VOLUME_AIR") == 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
|
1139 | if (sscanf(val, "%d", &ival) == 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
|
1140 | simulator->volume_air = 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
|
1141 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1142 | } else if (strcmp(kwd, (char *)"VOLUME_BEER") == 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
|
1143 | if (sscanf(val, "%d", &ival) == 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
|
1144 | simulator->volume_beer = 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
|
1145 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1146 | } else if (strcmp(kwd, (char *)"ROOM_TEMPERATURE") == 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
|
1147 | if (sscanf(val, "%f", &fval) == 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
|
1148 | simulator->room_temperature = 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
|
1149 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1150 | } else if (strcmp(kwd, (char *)"AIR_TEMPERATURE") == 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
|
1151 | if (sscanf(val, "%f", &fval) == 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
|
1152 | simulator->air_temperature = 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
|
1153 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1154 | } else if (strcmp(kwd, (char *)"BEER_TEMPERATURE") == 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
|
1155 | if (sscanf(val, "%f", &fval) == 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
|
1156 | simulator->beer_temperature = 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
|
1157 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1158 | } else if (strcmp(kwd, (char *)"COOLER_TEMP") == 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
|
1159 | if (sscanf(val, "%f", &fval) == 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
|
1160 | simulator->cooler_temp = 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
|
1161 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1162 | } else if (strcmp(kwd, (char *)"COOLER_TIME") == 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
|
1163 | if (sscanf(val, "%d", &ival) == 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
|
1164 | simulator->cooler_time = 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
|
1165 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1166 | } else if (strcmp(kwd, (char *)"COOLER_SIZE") == 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
|
1167 | if (sscanf(val, "%f", &fval) == 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
|
1168 | simulator->cooler_size = 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
|
1169 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1170 | } else if (strcmp(kwd, (char *)"HEATER_TEMP") == 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
|
1171 | if (sscanf(val, "%f", &fval) == 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
|
1172 | simulator->heater_temp = 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
|
1173 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1174 | } else if (strcmp(kwd, (char *)"HEATER_TIME") == 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
|
1175 | if (sscanf(val, "%d", &ival) == 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
|
1176 | simulator->heater_time = 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
|
1177 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1178 | } else if (strcmp(kwd, (char *)"HEATER_SIZE") == 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
|
1179 | if (sscanf(val, "%f", &fval) == 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
|
1180 | simulator->heater_size = 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
|
1181 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1182 | } else if (strcmp(kwd, (char *)"HEATER_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
|
1183 | if (sscanf(val, "%d", &ival) == 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
|
1184 | simulator->heater_state = 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
|
1185 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1186 | } else if (strcmp(kwd, (char *)"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
|
1187 | if (sscanf(val, "%d", &ival) == 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
|
1188 | simulator->cooler_state = 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
|
1189 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1190 | } else if (strcmp(kwd, (char *)"FRIGO_ISOLATION") == 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
|
1191 | if (sscanf(val, "%f", &fval) == 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
|
1192 | simulator->frigo_isolation = 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
|
1193 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1194 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1195 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1196 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1197 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1198 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1199 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1200 | 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
|
1201 | 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
|
1202 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1203 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1204 | 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
|
1205 | 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
|
1206 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1207 | #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
|
1208 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1209 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
258
diff
changeset
|
1210 | |
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
|
1211 | 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
|
1212 | { |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1213 | 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
|
1214 | 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
|
1215 | |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1216 | 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
|
1217 | 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
|
1218 | 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
|
1219 | 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
|
1220 | 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
|
1221 | 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
|
1222 | 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
|
1223 | 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
|
1224 | 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
|
1225 | 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
|
1226 | 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
|
1227 | 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
|
1228 | 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
|
1229 | 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
|
1230 | 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
|
1231 | 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
|
1232 | 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
|
1233 | 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
|
1234 | 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
|
1235 | 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
|
1236 | 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
|
1237 | 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
|
1238 | 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
|
1239 | 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
|
1240 | 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
|
1241 | current->door_address = NULL; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1242 | 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
|
1243 | 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
|
1244 | 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
|
1245 | 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
|
1246 | 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
|
1247 | } 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
|
1248 | 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
|
1249 | 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
|
1250 | 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
|
1251 | 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
|
1252 | 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
|
1253 | 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
|
1254 | 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
|
1255 | 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
|
1256 | 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
|
1257 | 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
|
1258 | 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
|
1259 | 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
|
1260 | 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
|
1261 | 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
|
1262 | 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
|
1263 | 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
|
1264 | 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
|
1265 | 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
|
1266 | 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
|
1267 | 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
|
1268 | 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
|
1269 | current->door_address = NULL; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1270 | 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
|
1271 | 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
|
1272 | 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
|
1273 | 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
|
1274 | 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
|
1275 | 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
|
1276 | 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
|
1277 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1278 | } 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
|
1279 | 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
|
1280 | 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
|
1281 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1282 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1283 | 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
|
1284 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1285 | |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1286 | |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1287 | |
88 | 1288 | /* |
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
|
1289 | * 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
|
1290 | * 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
|
1291 | * 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
|
1292 | * 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
|
1293 | * UNIT PUT uuid |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1294 | */ |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1295 | int cmd_unit(char *buf) |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1296 | { |
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
|
1297 | 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
|
1298 | 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
|
1299 | 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
|
1300 | 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
|
1301 | 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
|
1302 | float fval; |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1303 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1304 | opt = strtok(buf, " \0"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1305 | opt = strtok(NULL, " \0"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1306 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1307 | if (opt == NULL) { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1308 | srv_send((char *)"501 Subcommand missing"); |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1309 | return 1; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1310 | } |
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
|
1311 | param = strtok(NULL, "\0"); |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1312 | |
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
|
1313 | if ((strcmp(opt, (char *)"LIST") == 0) && (param == NULL)) { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1314 | 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
|
1315 | 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
|
1316 | 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
|
1317 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1318 | 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
|
1319 | 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
|
1320 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1321 | |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1322 | if (param == NULL) { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1323 | 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
|
1324 | 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
|
1325 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1326 | |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1327 | 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
|
1328 | 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
|
1329 | 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
|
1330 | 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
|
1331 | 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
|
1332 | 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
|
1333 | 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
|
1334 | 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
|
1335 | unit->air_address = unit->beer_address = unit->heater_address = unit->cooler_address = \ |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1336 | unit->fan_address = unit->door_address = unit->profile = NULL; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1337 | unit->volume = 0.0; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1338 | 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
|
1339 | 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
|
1340 | unit->beer_set = unit->fridge_set = 20.0; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1341 | unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->mode = unit->prof_state = 0; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1342 | 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
|
1343 | 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
|
1344 | 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
|
1345 | unit->idle_rangeL = -1.0; |
194
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
192
diff
changeset
|
1346 | unit->prof_started = unit->prof_paused = (time_t)0; |
185 | 1347 | unit->PID_err_old = unit->PID_I_err = 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
|
1348 | |
245
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1349 | /* |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1350 | * 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
|
1351 | */ |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1352 | 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
|
1353 | for (;;) { |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1354 | usleep(100000); |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1355 | 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
|
1356 | break; |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1357 | } |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1358 | |
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
|
1359 | 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
|
1360 | 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
|
1361 | } 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
|
1362 | 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
|
1363 | 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
|
1364 | 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
|
1365 | 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
|
1366 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1367 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1368 | } |
249 | 1369 | #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
|
1370 | lcd_buf_reset(); |
249 | 1371 | #endif |
245
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1372 | 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
|
1373 | |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1374 | syslog(LOG_NOTICE, "Unit %s added", unit->uuid); |
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1375 | 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
|
1376 | 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
|
1377 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1378 | |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1379 | 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
|
1380 | /* |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1381 | * 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
|
1382 | */ |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1383 | 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
|
1384 | for (;;) { |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1385 | usleep(100000); |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1386 | 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
|
1387 | break; |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1388 | } |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1389 | |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1390 | rc = delete_Unit(param); |
249 | 1391 | #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
|
1392 | lcd_buf_reset(); |
249 | 1393 | #endif |
245
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1394 | 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
|
1395 | |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
240
diff
changeset
|
1396 | if (rc) { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1397 | 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
|
1398 | 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
|
1399 | 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
|
1400 | } else { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1401 | 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
|
1402 | 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
|
1403 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1404 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1405 | |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1406 | 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
|
1407 | 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
|
1408 | if (strcmp(param, unit->uuid) == 0) { |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1409 | 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
|
1410 | 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
|
1411 | 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
|
1412 | 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
|
1413 | 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
|
1414 | 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
|
1415 | 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
|
1416 | 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
|
1417 | 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
|
1418 | 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
|
1419 | 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
|
1420 | srv_send((char *)"HEATER_STATE,%d", unit->heater_state); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1421 | 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
|
1422 | srv_send((char *)"COOLER_STATE,%d", unit->cooler_state); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1423 | 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
|
1424 | srv_send((char *)"FAN_STATE,%d", unit->fan_state); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1425 | 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
|
1426 | srv_send((char *)"DOOR_STATE,%d", unit->door_state); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1427 | 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
|
1428 | 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
|
1429 | 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
|
1430 | srv_send((char *)"PROFILE,%s", unit->profile); |
217 | 1431 | srv_send((char *)"PROF_STARTED,%d", (int)unit->prof_started); |
1432 | srv_send((char *)"PROF_STATE,%s", PROFSTATE[unit->prof_state]); | |
1433 | srv_send((char *)"PROF_TARGET,%.3f", unit->prof_target); | |
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
|
1434 | 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
|
1435 | srv_send((char *)"TEMP_SET_MAX,%.1f", unit->temp_set_max); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1436 | srv_send((char *)"IDLE_RANGE_L,%.1f", unit->idle_rangeL); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1437 | srv_send((char *)"IDLE_RANGE_H,%.1f", unit->idle_rangeH); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1438 | 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
|
1439 | return 1; |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1440 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1441 | } |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1442 | 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
|
1443 | return 1; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1444 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1445 | |
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
|
1446 | 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
|
1447 | 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
|
1448 | 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
|
1449 | 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
|
1450 | 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
|
1451 | 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
|
1452 | 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
|
1453 | if (rlen == -1) { |
235 | 1454 | syslog(LOG_WARNING, "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
|
1455 | 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
|
1456 | 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
|
1457 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1458 | 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
|
1459 | 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
|
1460 | 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
|
1461 | 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
|
1462 | 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
|
1463 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1464 | 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
|
1465 | 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
|
1466 | 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
|
1467 | 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
|
1468 | 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
|
1469 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1470 | 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
|
1471 | 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
|
1472 | 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
|
1473 | 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
|
1474 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1475 | 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
|
1476 | 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
|
1477 | 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
|
1478 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1479 | 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
|
1480 | val = strtok(NULL, "\0"); |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1481 | 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
|
1482 | /* |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1483 | * 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
|
1484 | * 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
|
1485 | * 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
|
1486 | */ |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1487 | if (val && (strcmp(kwd, (char *)"NAME") == 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
|
1488 | if (unit->name) |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1489 | free(unit->name); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1490 | 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
|
1491 | |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1492 | } else if (val && (strcmp(kwd, (char *)"VOLUME") == 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
|
1493 | if (sscanf(val, "%f", &fval) == 1) |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1494 | unit->volume = fval; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1495 | |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1496 | } else if (strcmp(kwd, (char *)"AIR_ADDRESS") == 0) { |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
1497 | 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
|
1498 | 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
|
1499 | 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
|
1500 | } |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
1501 | if (val) { |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1502 | 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
|
1503 | 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
|
1504 | } else |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1505 | 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
|
1506 | |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1507 | } else if (strcmp(kwd, (char *)"BEER_ADDRESS") == 0) { |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
1508 | 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
|
1509 | 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
|
1510 | 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
|
1511 | } |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
1512 | if (val) { |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1513 | 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
|
1514 | 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
|
1515 | } else |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1516 | 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
|
1517 | |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1518 | } else if (strcmp(kwd, (char *)"HEATER_ADDRESS") == 0) { |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
1519 | 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
|
1520 | 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
|
1521 | 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
|
1522 | } |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
1523 | if (val) { |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1524 | 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
|
1525 | 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
|
1526 | } else |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1527 | unit->heater_address = NULL; |
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1528 | |
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1529 | } else if (val && (strcmp(kwd, (char *)"HEATER_STATE") == 0)) { |
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1530 | if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) |
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1531 | unit->heater_state = ival; |
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
|
1532 | |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1533 | } else if (strcmp(kwd, (char *)"COOLER_ADDRESS") == 0) { |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
1534 | 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
|
1535 | 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
|
1536 | 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
|
1537 | } |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
1538 | if (val) { |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1539 | 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
|
1540 | 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
|
1541 | } else |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1542 | unit->cooler_address = NULL; |
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1543 | |
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1544 | } else if (val && (strcmp(kwd, (char *)"COOLER_STATE") == 0)) { |
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1545 | if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) |
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1546 | unit->cooler_state = ival; |
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
|
1547 | |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1548 | } else if (strcmp(kwd, (char *)"FAN_ADDRESS") == 0) { |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
1549 | 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
|
1550 | device_count(FALSE, unit->fan_address); |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1551 | 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
|
1552 | } |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
1553 | if (val) { |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1554 | 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
|
1555 | 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
|
1556 | } else |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1557 | 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
|
1558 | |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1559 | } else if (val && (strcmp(kwd, (char *)"FAN_STATE") == 0)) { |
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1560 | if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) |
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1561 | unit->fan_state = ival; |
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1562 | |
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
|
1563 | } else if (strcmp(kwd, (char *)"DOOR_ADDRESS") == 0) { |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
1564 | 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
|
1565 | device_count(FALSE, unit->door_address); |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1566 | 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
|
1567 | } |
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
178
diff
changeset
|
1568 | if (val) { |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1569 | 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
|
1570 | 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
|
1571 | } else |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1572 | 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
|
1573 | |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1574 | } 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
|
1575 | 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
|
1576 | 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
|
1577 | /* 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
|
1578 | 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
|
1579 | initlog(unit->name); |
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
|
1580 | syslog(LOG_NOTICE, "Mode from %s to %s via web interface", 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
|
1581 | unit->mode = i; |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1582 | /* Allways turn everything off after a mode change */ |
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
|
1583 | unit->PID_I_err = unit->PID_err_old = 0.0; |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1584 | unit->heater_state = unit->cooler_state = unit->fan_state = 0; |
184 | 1585 | device_out(unit->heater_address, unit->heater_state); |
1586 | device_out(unit->cooler_address, unit->cooler_state); | |
1587 | device_out(unit->fan_address, unit->fan_state); | |
237
51a294d683cd
Add a sane default for profile precessing.
Michiel Broek <mbroek@mbse.eu>
parents:
235
diff
changeset
|
1588 | if (unit->mode == UNITMODE_PROFILE) { |
51a294d683cd
Add a sane default for profile precessing.
Michiel Broek <mbroek@mbse.eu>
parents:
235
diff
changeset
|
1589 | /* |
51a294d683cd
Add a sane default for profile precessing.
Michiel Broek <mbroek@mbse.eu>
parents:
235
diff
changeset
|
1590 | * 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
|
1591 | * main processing loop. |
51a294d683cd
Add a sane default for profile precessing.
Michiel Broek <mbroek@mbse.eu>
parents:
235
diff
changeset
|
1592 | */ |
51a294d683cd
Add a sane default for profile precessing.
Michiel Broek <mbroek@mbse.eu>
parents:
235
diff
changeset
|
1593 | unit->prof_target = 20.0; |
51a294d683cd
Add a sane default for profile precessing.
Michiel Broek <mbroek@mbse.eu>
parents:
235
diff
changeset
|
1594 | } |
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
|
1595 | 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
|
1596 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1597 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1598 | |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1599 | } 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
|
1600 | if ((sscanf(val, "%f", &fval) == 1) && (fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) { |
6df404da3537
Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
1601 | syslog(LOG_NOTICE, "Fridge temperature from %.1f to %.1f via web interface", 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
|
1602 | unit->fridge_set = fval; |
246
6df404da3537
Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
1603 | } |
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
|
1604 | |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1605 | } 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
|
1606 | if ((sscanf(val, "%f", &fval) == 1) && (fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) { |
6df404da3537
Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
1607 | syslog(LOG_NOTICE, "Beer temperature from %.1f to %.1f via web interface", 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
|
1608 | unit->beer_set = fval; |
246
6df404da3537
Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
1609 | } |
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
|
1610 | |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1611 | } 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
|
1612 | if (unit->prof_state == PROFILE_OFF) { |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1613 | /* |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1614 | * 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
|
1615 | */ |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1616 | if (unit->profile) |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1617 | free(unit->profile); |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1618 | if (val) |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1619 | unit->profile = xstrcpy(val); |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1620 | else |
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1621 | 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
|
1622 | /* |
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
|
1623 | * 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
|
1624 | */ |
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
|
1625 | unit->PID_I_err = unit->PID_err_old = 0.0; |
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
|
1626 | unit->heater_state = unit->cooler_state = unit->fan_state = 0; |
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
|
1627 | 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
|
1628 | 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
|
1629 | device_out(unit->fan_address, unit->fan_state); |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1630 | } |
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
|
1631 | |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1632 | } else if (val && (strcmp(kwd, (char *)"PROF_STATE") == 0)) { |
217 | 1633 | 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
|
1634 | if (strcmp(val, PROFSTATE[i]) == 0) { |
219
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
1635 | switch (i) { |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
1636 | case PROFILE_OFF: if (unit->prof_state == PROFILE_DONE) |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
1637 | unit->prof_state = PROFILE_OFF; |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
1638 | break; |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
1639 | case PROFILE_PAUSE: if (unit->prof_state == PROFILE_RUN) |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
1640 | unit->prof_state = PROFILE_PAUSE; |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
1641 | else if (unit->prof_state == PROFILE_PAUSE) |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
1642 | unit->prof_state = PROFILE_RUN; |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
1643 | break; |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
1644 | 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
|
1645 | unit->prof_state = PROFILE_RUN; |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
1646 | unit->prof_started = time(NULL); |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
1647 | unit->prof_paused = 0; |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
1648 | } |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
1649 | break; |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
1650 | case PROFILE_DONE: break; /* Command is illegal */ |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
1651 | 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
|
1652 | unit->prof_state = PROFILE_OFF; |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
1653 | unit->prof_started = 0; |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
1654 | } |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
1655 | break; |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
217
diff
changeset
|
1656 | } |
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
|
1657 | 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
|
1658 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1659 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1660 | |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1661 | } else if (val && (strcmp(kwd, (char *)"TEMP_SET_MIN") == 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
|
1662 | if (sscanf(val, "%f", &fval) == 1) |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1663 | unit->temp_set_min = fval; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1664 | |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1665 | } else if (val && (strcmp(kwd, (char *)"TEMP_SET_MAX") == 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
|
1666 | if (sscanf(val, "%f", &fval) == 1) |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1667 | unit->temp_set_max = fval; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1668 | |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1669 | } else if (val && (strcmp(kwd, (char *)"IDLE_RANGE_L") == 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
|
1670 | if (sscanf(val, "%f", &fval) == 1) |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1671 | unit->idle_rangeL = fval; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1672 | |
178
988a898974f3
Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents:
176
diff
changeset
|
1673 | } else if (val && (strcmp(kwd, (char *)"IDLE_RANGE_H") == 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
|
1674 | if (sscanf(val, "%f", &fval) == 1) |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1675 | unit->idle_rangeH = fval; |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1676 | |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1677 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1678 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1679 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1680 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1681 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1682 | } |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1683 | 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
|
1684 | 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
|
1685 | } |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
1686 | |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
1687 | srv_send((char *)"504 Subcommand error"); |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1688 | return 1; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1689 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1690 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1691 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1692 | |
43 | 1693 | void cmd_server(void) |
1694 | { | |
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
|
1695 | 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
|
1696 | int i, rlen; |
43 | 1697 | socklen_t fromlen; |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1698 | |
48 | 1699 | memset((char *)&buf, 0, SS_BUFSIZE); |
1700 | fromlen = sizeof(peeraddr_in); | |
1701 | rlen = recvfrom(s, buf, sizeof(buf) -1, 0, (struct sockaddr *)&peeraddr_in, &fromlen); | |
1702 | if (rlen == -1) { | |
235 | 1703 | syslog(LOG_WARNING, "recvfrom(): %s", strerror(errno)); |
48 | 1704 | } else { |
1705 | for (i = 0; i < strlen(buf); i++) { | |
1706 | if (buf[i] == '\n') | |
1707 | buf[i] = '\0'; | |
1708 | if (buf[i] == '\r') | |
1709 | buf[i] = '\0'; | |
1710 | } | |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
1711 | for (i = strlen(buf) -1; i > 0; i--) { |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
1712 | if (buf[i] == ' ') |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
1713 | buf[i] = '\0'; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
1714 | else |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
1715 | break; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
1716 | } |
48 | 1717 | if (strlen(buf)) { |
1718 | if (debug) { | |
1719 | syslog(LOG_NOTICE, "recv: \"%s\"", buf); | |
1720 | fprintf(stdout, "recv: \"%s\"\n", buf); | |
43 | 1721 | } |
1722 | ||
1723 | /* | |
48 | 1724 | * Process commands from the client |
43 | 1725 | */ |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1726 | if (strncmp(buf, "DEVICE", 6) == 0) { |
174 | 1727 | if (cmd_device(buf) == 0) |
1728 | wrconfig(); | |
206
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1729 | } else if (strncmp(buf, "GLOBAL", 6) == 0) { |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1730 | if (cmd_global(buf) == 0) |
78fb6f99e473
Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
1731 | wrconfig(); |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
1732 | } 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
|
1733 | srv_send((char *)"100 Help text follows"); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
1734 | srv_send((char *)"Recognized commands:"); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
1735 | 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
|
1736 | // 12345678901234567890123456789012345678901234567890123456789012345678901234567890 |
174 | 1737 | 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
|
1738 | srv_send((char *)"DEVICE DEL uuid Delete Device by uuid"); |
174 | 1739 | srv_send((char *)"DEVICE LIST List Devices"); |
1740 | srv_send((char *)"DEVICE GET uuid Get Device record by uuid"); | |
1741 | 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
|
1742 | 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
|
1743 | 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
|
1744 | srv_send((char *)"LIST List all fermenter units"); |
191
c74bbc24a1c8
Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
1745 | srv_send((char *)"LIST LOG uuid List logfile data in 1 hour lines"); |
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
|
1746 | 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
|
1747 | 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
|
1748 | 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
|
1749 | 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
|
1750 | 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
|
1751 | 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
|
1752 | srv_send((char *)"PROFILE GETS uuid Profile get steps list"); |
1b001de37945
Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents:
138
diff
changeset
|
1753 | 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
|
1754 | #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
|
1755 | 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
|
1756 | 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
|
1757 | 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
|
1758 | 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
|
1759 | 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
|
1760 | #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
|
1761 | 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
|
1762 | 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
|
1763 | 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
|
1764 | 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
|
1765 | 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
|
1766 | srv_send((char *)"."); |
81 | 1767 | } else if (strncmp(buf, "LIST", 4) == 0) { |
1768 | cmd_list(buf); | |
132
8bd209d1c020
Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents:
131
diff
changeset
|
1769 | } 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
|
1770 | 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
|
1771 | 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
|
1772 | #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
|
1773 | } 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
|
1774 | 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
|
1775 | 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
|
1776 | #endif |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
1777 | } 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
|
1778 | 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
|
1779 | wrconfig(); |
43 | 1780 | } 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
|
1781 | srv_send((char *)"500 Unknown command"); |
43 | 1782 | } |
1783 | } | |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1784 | } |
44 | 1785 | |
1786 | close(s); | |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1787 | } |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1788 | |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1789 | |
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
|
1790 | |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
1791 | #ifdef HAVE_WIRINGPI_H |
43 | 1792 | PI_THREAD (my_server_loop) |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
1793 | #else |
74 | 1794 | 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
|
1795 | #endif |
43 | 1796 | { |
1797 | socklen_t addrlen; | |
44 | 1798 | int optval = 1; |
43 | 1799 | |
1800 | syslog(LOG_NOTICE, "Thread my_server_loop started"); | |
1801 | if (debug) | |
1802 | fprintf(stdout, "Thread my_server_loop started\n"); | |
1803 | ||
44 | 1804 | memset((char *)&myaddr_in, 0, sizeof(struct sockaddr_in)); |
1805 | memset((char *)&peeraddr_in, 0, sizeof(struct sockaddr_in)); | |
1806 | myaddr_in.sin_family = AF_INET; | |
1807 | myaddr_in.sin_addr.s_addr = INADDR_ANY; | |
1808 | myaddr_in.sin_port = htons(Config.my_port); | |
1809 | ||
1810 | ls = socket(AF_INET, SOCK_STREAM, 0); | |
1811 | if (ls == -1) { | |
235 | 1812 | syslog(LOG_WARNING, "Can't create listen socket: %s", strerror(errno)); |
44 | 1813 | fprintf(stderr, "Can't create listen socket: %s\n", strerror(errno)); |
1814 | return 0; | |
1815 | } | |
1816 | ||
1817 | if (setsockopt(ls, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(optval)) == -1) { | |
235 | 1818 | syslog(LOG_WARNING, "Can't setsockopt SO_KEEPALIVE socket: %s", strerror(errno)); |
44 | 1819 | close(ls); |
1820 | return 0; | |
1821 | } | |
1822 | ||
1823 | if (setsockopt(ls, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) == -1) { | |
235 | 1824 | syslog(LOG_WARNING, "Can't setsockopt SO_REUSEADDR socket: %s", strerror(errno)); |
44 | 1825 | close(ls); |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
1826 | return 0; |
44 | 1827 | } |
1828 | ||
1829 | if (bind(ls, (struct sockaddr *)&myaddr_in, sizeof(struct sockaddr_in)) == -1) { | |
235 | 1830 | syslog(LOG_WARNING, "Can't bind to listen socket: %s", strerror(errno)); |
44 | 1831 | close(ls); |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
1832 | return 0; |
44 | 1833 | } |
1834 | ||
1835 | if (listen(ls, 5) == -1) { | |
235 | 1836 | syslog(LOG_WARNING, "Can't listen on listen socket: %s", strerror(errno)); |
44 | 1837 | close(ls); |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
1838 | return 0; |
44 | 1839 | } |
1840 | ||
1841 | syslog(LOG_NOTICE, "listen socket created %d", ls); | |
1842 | ||
1843 | ||
43 | 1844 | /* |
1845 | * Loop forever until the external shutdown variable is set. | |
1846 | */ | |
1847 | for (;;) { | |
1848 | ||
1849 | addrlen = sizeof(struct sockaddr_in); | |
1850 | /* | |
1851 | * This call will block until a new connection | |
1852 | * arrives. Then it will return the address of | |
1853 | * the connecting peer, and a new socket | |
1854 | * descriptor, s, for that connection. | |
1855 | */ | |
1856 | s = accept(ls, (struct sockaddr *)&peeraddr_in, &addrlen); | |
1857 | if (s == -1) { | |
235 | 1858 | syslog(LOG_WARNING, "my_server_loop accept failed %s", strerror(errno)); |
43 | 1859 | if (debug) |
1860 | fprintf(stdout, "my_server_loop accept failed %s\n", strerror(errno)); | |
44 | 1861 | return 0; |
43 | 1862 | } |
1863 | ||
48 | 1864 | cmd_server(); |
43 | 1865 | |
1866 | if (my_shutdown) { | |
1867 | syslog(LOG_NOTICE, "Thread my_server_loop stopped"); | |
1868 | if (debug) | |
1869 | fprintf(stdout, "Thread my_server_loop stopped\n"); | |
1870 | return 0; | |
1871 | } | |
1872 | ||
1873 | } | |
1874 | } | |
1875 | ||
1876 |