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