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