Mon, 07 Jul 2014 22:31:07 +0200
Removed old brewPi settings
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 | |
46
000399c64d3f
More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
23 | #include "thermferm.h" |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
24 | |
58
e8e7b46b705b
Fixed compilation without wiringpi
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
25 | |
75
4b976601737d
Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents:
74
diff
changeset
|
26 | 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
|
27 | extern int debug; |
71 | 28 | extern int current_unit; |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
29 | #ifdef HAVE_WIRINGPI_H |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
30 | extern int lcdHandle; |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
31 | 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
|
32 | #endif |
43 | 33 | extern sys_config Config; |
81 | 34 | extern const char UNITMODE[5][8]; |
95 | 35 | extern const char UNITmode[5]; |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
36 | |
43 | 37 | int s; /* connected socket */ |
38 | int ls; /* listen socket */ | |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
39 | |
43 | 40 | struct sockaddr_in myaddr_in; /* for local socket address */ |
41 | struct sockaddr_in peeraddr_in; /* for peer socket address */ | |
42 | ||
43 | struct hostent *hp; | |
44 | ||
45 | #define SS_BUFSIZE 1024 | |
46 | #define SS_TIMEOUT 300 | |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
47 | |
48 | 48 | |
95 | 49 | float cs_heatEstimator = 0.2; |
50 | float cs_coolEstimator = 5; | |
48 | 51 | float cv_beerDiff = 0.0; |
52 | ||
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
53 | |
46
000399c64d3f
More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
54 | |
43 | 55 | /* |
56 | * Send message to client | |
57 | */ | |
58 | int srv_send(const char *format, ...) | |
59 | { | |
60 | char out[SS_BUFSIZE]; | |
61 | va_list va_ptr; | |
62 | ||
63 | if (s == -1) | |
64 | return -1; | |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
65 | |
43 | 66 | va_start(va_ptr, format); |
67 | vsnprintf(out, SS_BUFSIZE-1, format, va_ptr); | |
68 | va_end(va_ptr); | |
69 | ||
48 | 70 | if (debug) { |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
71 | syslog(LOG_NOTICE, "send: \"%s\"", out); |
45
053c4657105f
Mirror LCD display on the webpage works
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
72 | fprintf(stdout, "send: \"%s\"\n", out); |
48 | 73 | } |
44 | 74 | |
43 | 75 | if (send(s, out, strlen(out), 0) != strlen(out)) { |
76 | syslog(LOG_NOTICE, "srv_send failed"); | |
77 | return -1; | |
78 | } | |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
79 | |
43 | 80 | if (send(s, (char *)"\r\n", 2, 0) != 2) { |
81 | syslog(LOG_NOTICE, "srv_send failed"); | |
82 | return -1; | |
83 | } | |
84 | ||
85 | return 0; | |
86 | } | |
87 | ||
88 | ||
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
89 | |
88 | 90 | /* |
92 | 91 | * ADD PROFILE name |
92 | * ADD UNIT name | |
88 | 93 | */ |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
94 | int unit_add(char *buf) |
43 | 95 | { |
92 | 96 | units_list *unit, *tmpu; |
97 | profiles_list *profile, *tmpp; | |
98 | uuid_t uu; | |
99 | char *opt, *param; | |
100 | int id = 1; | |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
101 | |
92 | 102 | opt = strtok(buf, " \0"); |
103 | opt = strtok(NULL, " \0"); | |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
104 | if (opt == NULL) { |
92 | 105 | srv_send((char *)"501 Subcommand missing"); |
106 | return 1; | |
107 | } | |
108 | ||
109 | param = strtok(NULL, "\0"); | |
110 | if (param == NULL) { | |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
111 | srv_send((char *)"501 Parameter missing"); |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
112 | return 1; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
113 | } |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
114 | |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
115 | if (debug) |
92 | 116 | 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
|
117 | |
92 | 118 | if (strcmp(opt, (char *)"PROFILE") == 0) { |
119 | profile = (profiles_list *)malloc(sizeof(profiles_list)); | |
120 | profile->next = NULL; | |
121 | profile->version = 1; | |
122 | profile->uuid = malloc(37); | |
123 | uuid_generate(uu); | |
124 | uuid_unparse(uu, profile->uuid); | |
125 | profile->name = xstrcpy(param); | |
126 | profile->steps = NULL; | |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
127 | |
92 | 128 | if (Config.profiles == NULL) { |
129 | Config.profiles = profile; | |
130 | } else { | |
131 | for (tmpp = Config.profiles; tmpp; tmpp = tmpp->next) { | |
132 | if (tmpp->next == NULL) { | |
133 | tmpp->next = profile; | |
134 | break; | |
135 | } | |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
136 | } |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
137 | } |
92 | 138 | |
139 | syslog(LOG_NOTICE, "Profile \"%s\" with uuid %s added", param, profile->uuid); | |
140 | srv_send((char *)"211 Profile \"%s\" with uuid %s added", param, profile->uuid); | |
141 | return 0; | |
142 | ||
143 | } else if (strcmp(opt, (char *)"UNIT") == 0) { | |
144 | unit = (units_list *)malloc(sizeof(units_list)); | |
145 | unit->next = NULL; | |
146 | unit->version = 1; | |
147 | unit->uuid = malloc(37); | |
148 | uuid_generate(uu); | |
149 | uuid_unparse(uu, unit->uuid); | |
150 | unit->name = xstrcpy(param); | |
151 | unit->air_address = unit->beer_address = unit->io1_address = unit->io2_address = unit->profile = NULL; | |
152 | unit->volume = 0.0; | |
153 | unit->heater_available = unit->cooler_available = unit->fan_available = FALSE; | |
154 | unit->air_temp = unit->beer_temp = unit->beer_set = unit->fridge_set = 20.0; | |
155 | unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->mode = unit->prof_state = 0; | |
156 | unit->temp_set_min = 1.0; | |
157 | unit->temp_set_max = 30.0; | |
158 | unit->idle_rangeH = 1.0; | |
159 | unit->idle_rangeL = -1.0; | |
160 | unit->prof_started = (time_t)0; | |
161 | ||
162 | if (Config.units == NULL) { | |
163 | Config.units = unit; | |
164 | } else { | |
165 | for (tmpu = Config.units; tmpu; tmpu = tmpu->next) { | |
166 | id++; | |
167 | if (tmpu->next == NULL) { | |
168 | tmpu->next = unit; | |
169 | break; | |
170 | } | |
171 | } | |
172 | } | |
173 | ||
174 | syslog(LOG_NOTICE, "Unit %d with uuid %s added", id, unit->uuid); | |
175 | srv_send((char *)"211 Unit %d with uuid %s added", id, unit->uuid); | |
176 | current_unit = id; | |
177 | return 0; | |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
178 | } |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
179 | |
92 | 180 | srv_send((char *)"502 Unknown command option"); |
181 | return 1; | |
43 | 182 | } |
183 | ||
184 | ||
185 | ||
81 | 186 | /* |
187 | * LIST | |
84 | 188 | * LIST BUS |
189 | * LIST PROFILES | |
190 | * LIST UNIT | |
81 | 191 | */ |
192 | int cmd_list(char *buf) | |
193 | { | |
92 | 194 | char *opt; |
84 | 195 | units_list *unit; |
92 | 196 | profiles_list *profile; |
84 | 197 | int i; |
198 | DIR *fd; | |
199 | struct dirent *de; | |
81 | 200 | |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
201 | opt = strtok(buf, " \0"); |
92 | 202 | opt = strtok(NULL, "\0"); |
84 | 203 | |
81 | 204 | if (opt == NULL) { |
92 | 205 | /* |
206 | * Default, list available units | |
207 | */ | |
81 | 208 | srv_send((char *)"212 Fermenter list follows:"); |
209 | i = 0; | |
210 | for (unit = Config.units; unit; unit = unit->next) { | |
211 | i++; | |
212 | srv_send((char *)"%02d %s %-20s %-7s", i, unit->uuid, unit->name, UNITMODE[unit->mode]); | |
213 | } | |
214 | srv_send((char *)"."); | |
92 | 215 | return 0; |
216 | ||
84 | 217 | } 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
|
218 | /* |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
219 | * 1-wire bus |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
220 | */ |
84 | 221 | 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
|
222 | 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
|
223 | while ((de = readdir(fd))) { |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
224 | if (de->d_name[0] != '.') { |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
225 | if (strncmp(de->d_name, (char *)"w1", 2) == 0) { |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
226 | srv_send((char *)"%-15s system device", de->d_name); |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
227 | } else if (strncmp(de->d_name, (char *)"10", 2) == 0) { |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
228 | srv_send((char *)"%-15s 18S20 digital thermometer", de->d_name); |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
229 | } else if (strncmp(de->d_name, (char *)"28", 2) == 0) { |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
230 | srv_send((char *)"%-15s 18B20 digital thermometer", de->d_name); |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
231 | } else if (strncmp(de->d_name, (char *)"29", 2) == 0) { |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
232 | srv_send((char *)"%-15s 2408 8-channel addressable switch/LCD", de->d_name); |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
233 | } else if (strncmp(de->d_name, (char *)"3a", 2) == 0) { |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
234 | srv_send((char *)"%-15s 2413 dual channel addressable switchs", de->d_name); |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
235 | } else { |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
236 | srv_send((char *)"%-15s unknown device", de->d_name); |
84 | 237 | } |
238 | } | |
86
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
239 | } |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
240 | srv_send((char *)"."); |
84 | 241 | closedir(fd); |
92 | 242 | return 0; |
84 | 243 | } else { |
244 | srv_send((char *)"503 directory /sys/bus/w1/devices: %s", strerror(errno)); | |
92 | 245 | return 1; |
84 | 246 | } |
92 | 247 | |
84 | 248 | } 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
|
249 | /* |
92 | 250 | * Fermenting profiles |
86
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
251 | */ |
92 | 252 | srv_send((char *)"212 profiles:"); |
253 | i = 0; | |
254 | for (profile = Config.profiles; profile; profile = profile->next) { | |
255 | i++; | |
256 | srv_send((char *)"%02d %s %s", i, profile->uuid, profile->name); | |
86
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
257 | } |
92 | 258 | srv_send((char *)"."); |
259 | return 0; | |
260 | ||
84 | 261 | } 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
|
262 | /* |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
263 | * 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
|
264 | */ |
84 | 265 | if (current_unit == -1) { |
266 | srv_send((char *)"401 No fermenter unit selected"); | |
92 | 267 | return 1; |
268 | } | |
269 | ||
270 | srv_send((char *)"213 Unit %d listing follows:", current_unit); | |
271 | i = 0; | |
272 | for (unit = Config.units; unit; unit = unit->next) { | |
273 | i++; | |
274 | if (i == current_unit) { | |
275 | srv_send((char *)"Name of the unit/beer %s", unit->name); | |
276 | srv_send((char *)"UUID of this unit %s", unit->uuid); | |
277 | if (unit->air_address) { | |
278 | srv_send((char *)"1-wire address air sensor %s", unit->air_address); | |
279 | srv_send((char *)"Air temperature %.1f", unit->air_temp); | |
280 | } | |
281 | if (unit->beer_address) { | |
282 | srv_send((char *)"1-wire address beer sensor %s", unit->air_address); | |
283 | srv_send((char *)"Beer temperature %.1f", unit->air_temp); | |
284 | } | |
285 | if (unit->io1_address) { | |
286 | srv_send((char *)"1-wire address cool/heat %s", unit->io1_address); | |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
287 | } |
92 | 288 | if (unit->io2_address) { |
289 | srv_send((char *)"1-wire address fan/door %s", unit->io2_address); | |
290 | } | |
291 | if (unit->heater_available) { | |
292 | srv_send((char *)"Heater available %s", unit->heater_available); | |
293 | } | |
294 | if (unit->cooler_available) { | |
295 | srv_send((char *)"Cooler available %s", unit->cooler_available); | |
296 | } | |
297 | if (unit->fan_available) { | |
298 | srv_send((char *)"Fan available %s", unit->fan_available); | |
299 | } | |
300 | srv_send((char *)"Unit mode %s", UNITMODE[unit->mode]); | |
301 | srv_send((char *)"Fridge temperature set to %.1f", unit->fridge_set); | |
302 | srv_send((char *)"Beer temperature set to %.1f", unit->beer_set); | |
303 | if (unit->profile) { | |
304 | srv_send((char *)"Profile name %s", unit->profile); | |
305 | } | |
306 | srv_send((char *)"Temperature range %.1f .. %.1f", unit->temp_set_min, unit->temp_set_max); | |
307 | srv_send((char *)"Idle temperature range %.1f .. %.1f", unit->idle_rangeL, unit->idle_rangeH); | |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
308 | } |
84 | 309 | } |
92 | 310 | srv_send((char *)"."); |
311 | return 0; | |
81 | 312 | } |
313 | ||
92 | 314 | srv_send((char *)"502 Unknown command option"); |
315 | return 1; | |
81 | 316 | } |
317 | ||
318 | ||
319 | ||
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
320 | /* |
88 | 321 | * Set new operating mode |
322 | * MODE OFF|NONE|BEER|FRIDGE|PROFILE | |
323 | */ | |
324 | int cmd_mode(char *buf) | |
325 | { | |
326 | return 1; | |
327 | } | |
328 | ||
329 | ||
330 | ||
331 | /* | |
92 | 332 | * SET BEER float |
333 | * SET FRIDGE float | |
334 | * SET VOLUME float | |
335 | * SET IDLE_LOW float | |
336 | * SET IDLE_HIGH float | |
337 | * SET TEMP_MIN float | |
338 | * SET TEMP_MAX float | |
339 | * SET NAME string | |
340 | * SET PROFILE string | |
88 | 341 | */ |
342 | int cmd_set(char *buf) | |
343 | { | |
344 | char *opt, *param; | |
345 | units_list *unit; | |
346 | int i, rc; | |
347 | float fval; | |
348 | ||
349 | opt = strtok(buf, " \0"); | |
350 | opt = strtok(NULL, " \0"); | |
351 | if (opt == NULL) { | |
352 | srv_send((char *)"501 Subcommand missing"); | |
353 | return 1; | |
354 | } | |
355 | ||
356 | param = strtok(NULL, "\0"); | |
357 | if (param == NULL) { | |
358 | srv_send((char *)"501 Parameter missing"); | |
359 | return 1; | |
360 | } | |
361 | ||
362 | rc = sscanf(param, "%f", &fval); | |
363 | ||
364 | if (debug) | |
365 | fprintf(stdout, "opt='%s' param='%s' rc=%d fval=%.1f\n", opt, param, rc, fval); | |
366 | ||
367 | /* | |
368 | * Commands below need a selected unit | |
369 | */ | |
370 | if (current_unit == -1) { | |
371 | srv_send((char *)"401 No fermenter unit selected"); | |
372 | return 1; | |
373 | } | |
374 | ||
375 | i = 0; | |
376 | for (unit = Config.units; unit; unit = unit->next) { | |
377 | i++; | |
378 | if (i == current_unit) | |
379 | break; | |
380 | } | |
381 | ||
382 | /* | |
383 | * If a valid parameter float value | |
384 | */ | |
385 | if (rc == 1) { | |
386 | if (strcmp(opt, (char *)"BEER") == 0) { | |
387 | if ((fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) { | |
388 | unit->beer_set = fval; | |
389 | srv_send((char *)"214 Unit %d BEER set to %.1f", current_unit, fval); | |
390 | return 0; | |
391 | } else { | |
392 | srv_send((char *)"510 New temperature not between %.1f and %.1f", unit->temp_set_min, unit->temp_set_max); | |
393 | return 1; | |
394 | } | |
395 | } else if (strcmp(opt, (char *)"FRIDGE") == 0) { | |
396 | if ((fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) { | |
397 | unit->fridge_set = fval; | |
398 | srv_send((char *)"214 Unit %d BEER set to %.1f", current_unit, fval); | |
399 | return 0; | |
400 | } else { | |
401 | srv_send((char *)"510 New temperature not between %.1f and %.1f", unit->temp_set_min, unit->temp_set_max); | |
402 | return 1; | |
403 | } | |
404 | } else if (strcmp(opt, (char *)"VOLUME") == 0) { | |
405 | /* | |
406 | * Must fit in a 2 TEU container | |
407 | */ | |
408 | if ((fval >= 0.0) && (fval <= 77020.0)) { | |
409 | unit->volume = fval; | |
410 | srv_send((char *)"214 Unit %d VOLUME set to %.1f", current_unit, fval); | |
411 | return 0; | |
412 | } else { | |
413 | srv_send((char *)"510 New volume not between 0 and 77020"); | |
414 | return 1; | |
415 | } | |
416 | } else if (strcmp(opt, (char *)"IDLE_LOW") == 0) { | |
417 | if ((fval >= -5.0) && (fval <= -0.1)) { | |
418 | unit->idle_rangeL = fval; | |
419 | srv_send((char *)"214 Unit %d IDLE_LOW set to %.1f", current_unit, fval); | |
420 | return 0; | |
421 | } else { | |
422 | srv_send((char *)"510 New value not between -5.0 and -0.1"); | |
423 | return 1; | |
424 | } | |
425 | } else if (strcmp(opt, (char *)"IDLE_HIGH") == 0) { | |
426 | if ((fval >= 0.1) && (fval <= 5.0)) { | |
427 | unit->idle_rangeH = fval; | |
428 | srv_send((char *)"214 Unit %d IDLE_HIGH set to %.1f", current_unit, fval); | |
429 | return 0; | |
430 | } else { | |
431 | srv_send((char *)"510 New value not between -5.0 and -0.1"); | |
432 | return 1; | |
433 | } | |
434 | } else if (strcmp(opt, (char *)"TEMP_MIN") == 0) { | |
435 | if ((fval >= -2.0) && (fval <= 35.0) && (fval < unit->temp_set_max)) { | |
436 | unit->temp_set_min = fval; | |
437 | srv_send((char *)"214 Unit %d TEMP_MIN set to %.1f", current_unit, fval); | |
438 | return 0; | |
439 | } else { | |
440 | srv_send((char *)"510 New value not between -2.0 and 35.0 and lower then TEMP_MAX"); | |
441 | return 1; | |
442 | } | |
443 | } else if (strcmp(opt, (char *)"TEMP_MAX") == 0) { | |
444 | if ((fval >= -2.0) && (fval <= 35.0) && (fval > unit->temp_set_min)) { | |
445 | unit->temp_set_max = fval; | |
446 | srv_send((char *)"214 Unit %d TEMP_MAX set to %.1f", current_unit, fval); | |
447 | return 0; | |
448 | } else { | |
449 | srv_send((char *)"510 New value not between -2.0 and 35.0 and higher then TEMP_MIN"); | |
450 | return 1; | |
451 | } | |
452 | } | |
453 | } | |
454 | ||
455 | /* | |
456 | * Set new unit or beer name | |
457 | */ | |
458 | if (strcmp(opt, (char *)"NAME") == 0) { | |
459 | if (unit->name) | |
460 | free(unit->name); | |
461 | unit->name = xstrcpy(param); | |
462 | srv_send((char *)"214 Unit %d NAME set to '%s'", current_unit, param); | |
463 | // TODO: change logfile name | |
464 | return 0; | |
465 | } else if (strcmp(opt, (char *)"PROFILE") == 0) { | |
466 | // check profile file, excists, type, at least one profile item | |
467 | } | |
468 | ||
469 | srv_send((char *)"502 Unknown command option"); | |
470 | return 1; | |
471 | } | |
472 | ||
473 | ||
474 | ||
475 | /* | |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
476 | * UNIT n |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
477 | * UNIT uuid |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
478 | */ |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
479 | int cmd_unit(char *buf) |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
480 | { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
481 | char *opt; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
482 | units_list *tmp; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
483 | int i, unit_no; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
484 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
485 | opt = strtok(buf, " \0"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
486 | opt = strtok(NULL, " \0"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
487 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
488 | if (opt == NULL) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
489 | srv_send((char *)"501 Parameter missing"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
490 | return 1; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
491 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
492 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
493 | i = 0; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
494 | if (strlen(opt) == 36) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
495 | /* |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
496 | * Search using uuid |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
497 | */ |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
498 | 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
|
499 | i++; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
500 | if (strcmp(opt, tmp->uuid) == 0) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
501 | srv_send((char *)"210 Unit %d selected", i); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
502 | current_unit = i; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
503 | return 0; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
504 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
505 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
506 | srv_send((char *)"410 No such unit"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
507 | return 1; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
508 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
509 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
510 | if (sscanf(opt, "%d", &unit_no) == 1) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
511 | /* |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
512 | * We got a number, see if it is valid. |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
513 | */ |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
514 | 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
|
515 | i++; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
516 | if (unit_no == i) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
517 | srv_send((char *)"210 Unit %d selected", i); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
518 | current_unit = i; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
519 | return 0; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
520 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
521 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
522 | srv_send((char *)"410 No such unit"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
523 | return 1; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
524 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
525 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
526 | srv_send((char *)"502 Unknown command option"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
527 | return 1; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
528 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
529 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
530 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
531 | |
43 | 532 | void cmd_server(void) |
533 | { | |
54
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
534 | char *inp, *p, *q, buf[SS_BUFSIZE], obuf[SS_BUFSIZE]; |
48 | 535 | int i, rc, rlen; |
43 | 536 | socklen_t fromlen; |
46
000399c64d3f
More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
537 | float newtemp; |
68
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
538 | #ifdef HAVE_WIRINGPI_H |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
539 | int j; |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
540 | #endif |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
541 | |
48 | 542 | memset((char *)&buf, 0, SS_BUFSIZE); |
543 | fromlen = sizeof(peeraddr_in); | |
544 | rlen = recvfrom(s, buf, sizeof(buf) -1, 0, (struct sockaddr *)&peeraddr_in, &fromlen); | |
545 | if (rlen == -1) { | |
546 | syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno)); | |
547 | } else { | |
548 | for (i = 0; i < strlen(buf); i++) { | |
549 | if (buf[i] == '\n') | |
550 | buf[i] = '\0'; | |
551 | if (buf[i] == '\r') | |
552 | buf[i] = '\0'; | |
553 | } | |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
554 | for (i = strlen(buf) -1; i > 0; i--) { |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
555 | if (buf[i] == ' ') |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
556 | buf[i] = '\0'; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
557 | else |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
558 | break; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
559 | } |
48 | 560 | if (strlen(buf)) { |
561 | if (debug) { | |
562 | syslog(LOG_NOTICE, "recv: \"%s\"", buf); | |
563 | fprintf(stdout, "recv: \"%s\"\n", buf); | |
43 | 564 | } |
565 | ||
566 | /* | |
48 | 567 | * Process commands from the client |
43 | 568 | */ |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
569 | if (strncmp(buf, "ADD", 3) == 0) { |
92 | 570 | if (unit_add(buf) == 0) |
571 | wrconfig(); | |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
572 | } 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
|
573 | srv_send((char *)"100 Help text follows"); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
574 | srv_send((char *)"Recognized commands:"); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
575 | srv_send((char *)""); |
92 | 576 | srv_send((char *)"ADD PROFILE name Add a new profile with \"name\""); |
577 | srv_send((char *)"ADD UNIT name Add a new unit with \"name\""); | |
68
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
578 | srv_send((char *)"LCD Get LCD screen (allways 4 rows of 20 characters)"); |
81 | 579 | srv_send((char *)"LIST List all fermenter units"); |
84 | 580 | srv_send((char *)"LIST BUS List 1-wire bus"); |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
581 | srv_send((char *)"LIST PROFILES List available profiles"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
582 | srv_send((char *)"LIST UNIT List fermenter unit"); |
88 | 583 | srv_send((char *)"MODE OFF|NONE|BEER|FRIDGE|PROFILE"); |
81 | 584 | // srv_send((char *)"PROFILE Profile status"); |
585 | // srv_send((char *)"PROFILE start|stop|pause Profile start, stop or pause"); | |
88 | 586 | srv_send((char *)"SET BEER val Set beer temperature"); |
587 | srv_send((char *)"SET FRIDGE val Set fridge temperature"); | |
588 | srv_send((char *)"SET IDLE_LOW val Set idle temperature low (-5.0 .. -0.1)"); | |
589 | srv_send((char *)"SET IDLE_HIGH val Set idle temperature high (0.1 .. 5.0)"); | |
590 | srv_send((char *)"SET NAME name Set name or beername for the unit"); | |
81 | 591 | // srv_send((char *)"SET PROFILE name Set named profile"); |
88 | 592 | srv_send((char *)"SET TEMP_MIN val Set unit minimum temperature"); |
593 | srv_send((char *)"SET TEMP_MAX val Set unit maximum temperature"); | |
594 | srv_send((char *)"SET VOLUME val Set unit volume"); | |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
595 | srv_send((char *)"UNIT n|uuid Select unit by number or uuid"); |
68
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
596 | srv_send((char *)"."); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
597 | } else if (strncmp(buf, "LCD", 3) == 0) { |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
598 | #ifdef HAVE_WIRINGPI_H |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
599 | srv_send((char *)"201 information follows"); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
600 | for (j = 0; j < 4; j++) { |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
601 | sprintf(obuf, " "); |
70 | 602 | obuf[20] = '\0'; |
68
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
603 | for (i = 0; i < 20; i++) |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
604 | obuf[i] = lcdbuf[lcdHandle][i][j]; |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
605 | srv_send(obuf); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
606 | } |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
607 | srv_send((char *)"."); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
608 | #else |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
609 | srv_send((char *)"403 LCD not available"); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
610 | #endif |
81 | 611 | } else if (strncmp(buf, "LIST", 4) == 0) { |
612 | cmd_list(buf); | |
88 | 613 | } else if (strncmp(buf, "MODE", 4) == 0) { |
614 | cmd_mode(buf); | |
615 | } else if (strncmp(buf, "SET", 3) == 0) { | |
92 | 616 | if (cmd_set(buf) == 0) |
617 | wrconfig(); | |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
618 | } else if (strncmp(buf, "UNIT", 4) == 0) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
619 | cmd_unit(buf); |
95 | 620 | |
621 | /* | |
622 | * Now the old style (brewPi) commands. These will go away. | |
623 | */ | |
68
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
624 | } else if (strncmp(buf, "ack", 3) == 0) { |
48 | 625 | srv_send((char *)"ack"); |
626 | } else if (strncmp(buf, "lcd", 3) == 0) { | |
627 | sprintf(obuf, "[\" \", \" \", \" \", \" \"]"); | |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
628 | #ifdef HAVE_WIRINGPI_H |
48 | 629 | for (i = 0; i < 20; i++) { |
630 | obuf[i+2] = lcdbuf[lcdHandle][i][0]; | |
631 | obuf[i+26] = lcdbuf[lcdHandle][i][1]; | |
632 | obuf[i+50] = lcdbuf[lcdHandle][i][2]; | |
633 | obuf[i+74] = lcdbuf[lcdHandle][i][3]; | |
634 | } | |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
635 | #endif |
48 | 636 | srv_send(obuf); |
637 | } else if (strncmp(buf, "getMode", 7) == 0) { | |
95 | 638 | srv_send("%c", UNITmode[Config.units->mode]); |
48 | 639 | } else if (strncmp(buf, "getFridge", 9) == 0) { |
95 | 640 | srv_send("%.1f", Config.units->fridge_set); |
48 | 641 | } else if (strncmp(buf, "getBeer", 7) == 0) { |
95 | 642 | srv_send("%.1f", Config.units->beer_set); |
48 | 643 | } else if (strncmp(buf, "getControlConstants", 19) == 0) { |
644 | srv_send("{ \"tempFormat\":\"%c\", \"tempSetMin\":%.1f, \"tempSetMax\":%.1f, \"idleRangeH\":%.3f, \"idleRangeL\":%.3f }", | |
95 | 645 | Config.tempFormat, Config.units->temp_set_min, Config.units->temp_set_max, Config.units->idle_rangeH, Config.units->idle_rangeL); |
48 | 646 | } else if (strncmp(buf, "getControlSettings", 18) == 0) { |
647 | srv_send("{ \"mode\":\"%c\", \"beerSet\":%.1f, \"fridgeSet\":%.1f, \"heatEstimator\":%.1f, \"coolEstimator\":%.1f }", | |
95 | 648 | UNITmode[Config.units->mode], Config.units->beer_set, Config.units->fridge_set, cs_heatEstimator, cs_coolEstimator); |
48 | 649 | } else if (strncmp(buf, "getControlVariables", 19) == 0) { |
650 | srv_send("{ \"beerDiff\":%.2f }", cv_beerDiff); | |
49
92a9ca143677
Fixed temperature logging, added some commands
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
651 | } else if (strncmp(buf, "loadDefaultControlSettings", 26) == 0) { |
95 | 652 | // Does nothing anymore |
49
92a9ca143677
Fixed temperature logging, added some commands
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
653 | srv_send("ack"); |
92a9ca143677
Fixed temperature logging, added some commands
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
654 | } else if (strncmp(buf, "loadDefaultControlConstants", 27) == 0) { |
95 | 655 | // Does nothing anymore |
49
92a9ca143677
Fixed temperature logging, added some commands
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
656 | srv_send("ack"); |
48 | 657 | } else if (strncmp(buf, "setBeer=", 8) == 0) { |
658 | inp = xstrcpy(buf+8); | |
659 | rc = sscanf(inp, "%f", &newtemp); | |
660 | if (debug) | |
661 | fprintf(stdout, "new temp from %s, %.1f, rc=%d\n", inp, newtemp, rc); | |
662 | if (rc == 1) { | |
95 | 663 | if ((Config.units->temp_set_min <= newtemp) && (newtemp <= Config.units->temp_set_max)) { |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
664 | syslog(LOG_NOTICE, "Beer temperature set to %.1f degrees in web interface", newtemp); |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
665 | srv_send("ack"); |
95 | 666 | Config.units->mode = UNITMODE_BEER; |
667 | Config.units->beer_set = newtemp; | |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
668 | } else { |
95 | 669 | syslog(LOG_NOTICE, "Beer temperature setting %.1f is outside of allowed range %.1f - %.1f", newtemp, Config.units->temp_set_min, Config.units->temp_set_max); |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
670 | srv_send("err"); |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
671 | } |
48 | 672 | } else { |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
673 | syslog(LOG_NOTICE, "Cannot convert temperature '%s' to float", inp); |
48 | 674 | srv_send("err"); |
675 | } | |
676 | free(inp); | |
677 | } else if (strncmp(buf, "setFridge=", 10) == 0) { | |
678 | inp = xstrcpy(buf+10); | |
679 | rc = sscanf(inp, "%f", &newtemp); | |
680 | if (debug) | |
681 | fprintf(stdout, "new temp from %s, %.1f, rc=%d\n", inp, newtemp, rc); | |
682 | if (rc == 1) { | |
95 | 683 | if ((Config.units->temp_set_min <= newtemp) && (newtemp <= Config.units->temp_set_max)) { |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
684 | syslog(LOG_NOTICE, "Fridge temperature set to %.1f degrees in web interface", newtemp); |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
685 | srv_send("ack"); |
95 | 686 | Config.units->mode = UNITMODE_FRIDGE; |
687 | Config.units->fridge_set = newtemp; | |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
688 | } else { |
95 | 689 | syslog(LOG_NOTICE, "Fridge temperature setting %.1f is outside of allowed range %.1f - %.1f", newtemp, Config.units->temp_set_min, Config.units->temp_set_max); |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
690 | srv_send("err"); |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
691 | } |
48 | 692 | } else { |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
693 | syslog(LOG_NOTICE, "Cannot convert temperature '%s' to float", inp); |
48 | 694 | srv_send("err"); |
695 | } | |
696 | free(inp); | |
49
92a9ca143677
Fixed temperature logging, added some commands
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
697 | } else if (strncmp(buf, "setOff", 6) == 0) { |
92a9ca143677
Fixed temperature logging, added some commands
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
698 | if (debug) |
92a9ca143677
Fixed temperature logging, added some commands
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
699 | fprintf(stdout, "temperature control disabled\n"); |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
700 | syslog(LOG_NOTICE, "Notification: Temperature control disabled"); |
95 | 701 | Config.units->mode = UNITMODE_OFF; |
49
92a9ca143677
Fixed temperature logging, added some commands
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
702 | srv_send("ack"); |
54
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
703 | } else if (strncmp(buf, "setParameters=", 14) == 0) { |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
704 | inp = xstrcpy(buf+14); /* {"tempSetMax":30.5} */ |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
705 | if (debug) |
54
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
706 | fprintf(stdout, "setParameters: %s\n", inp); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
707 | strtok(inp, (char *)"\""); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
708 | p = strtok(NULL, (char *)"\""); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
709 | q = strtok(NULL, (char *)":,}"); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
710 | if (strcmp(p, (char *)"tempSetMin") == 0) { |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
711 | rc = sscanf(q, "%f", &newtemp); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
712 | if (rc == 1) { |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
713 | syslog(LOG_NOTICE, "cc_tempSetMin = %1.f", newtemp); |
95 | 714 | Config.units->temp_set_min = newtemp; |
54
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
715 | srv_send("ack"); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
716 | } else { |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
717 | srv_send("ERR"); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
718 | } |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
719 | } else if (strcmp(p, (char *)"tempSetMax") == 0) { |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
720 | rc = sscanf(q, "%f", &newtemp); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
721 | if (rc == 1) { |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
722 | syslog(LOG_NOTICE, "cc_tempSetMax = %1.f", newtemp); |
95 | 723 | Config.units->temp_set_max = newtemp; |
54
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
724 | srv_send("ack"); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
725 | } else { |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
726 | srv_send("ERR"); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
727 | } |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
728 | } else { |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
729 | fprintf(stdout, "p='%s' q='%s' inp='%s'\n", p, q, inp); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
730 | srv_send("ERR"); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
731 | } |
62 | 732 | free(inp); |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
733 | // stopScript |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
734 | // quit |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
735 | // eraseLogs |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
736 | // interval |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
737 | // startNewBrew |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
738 | // pauseLogging |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
739 | // stopLogging |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
740 | // resumeLogging |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
741 | // dateTimeFormatDisplay |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
742 | } else if (strncmp(buf, "setActiveProfile", 16) == 0) { |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
743 | syslog(LOG_NOTICE, "Setting profile '%s' as active profile", "undefined"); |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
744 | // programArduino |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
745 | // refreshDeviceList |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
746 | // getDeviceList |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
747 | // applyDevice |
43 | 748 | } else { |
48 | 749 | if (debug) |
750 | fprintf(stdout, "unknown command \"%s\"\n", buf); | |
751 | srv_send((char *)"ERR"); | |
43 | 752 | } |
753 | } | |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
754 | } |
44 | 755 | |
756 | close(s); | |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
757 | } |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
758 | |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
759 | |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
760 | #ifdef HAVE_WIRINGPI_H |
43 | 761 | PI_THREAD (my_server_loop) |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
762 | #else |
74 | 763 | 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
|
764 | #endif |
43 | 765 | { |
766 | socklen_t addrlen; | |
44 | 767 | int optval = 1; |
43 | 768 | |
769 | syslog(LOG_NOTICE, "Thread my_server_loop started"); | |
770 | if (debug) | |
771 | fprintf(stdout, "Thread my_server_loop started\n"); | |
772 | ||
44 | 773 | memset((char *)&myaddr_in, 0, sizeof(struct sockaddr_in)); |
774 | memset((char *)&peeraddr_in, 0, sizeof(struct sockaddr_in)); | |
775 | myaddr_in.sin_family = AF_INET; | |
776 | myaddr_in.sin_addr.s_addr = INADDR_ANY; | |
777 | myaddr_in.sin_port = htons(Config.my_port); | |
778 | ||
779 | ls = socket(AF_INET, SOCK_STREAM, 0); | |
780 | if (ls == -1) { | |
781 | syslog(LOG_NOTICE, "Can't create listen socket: %s", strerror(errno)); | |
782 | fprintf(stderr, "Can't create listen socket: %s\n", strerror(errno)); | |
783 | return 0; | |
784 | } | |
785 | ||
786 | if (setsockopt(ls, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(optval)) == -1) { | |
787 | syslog(LOG_NOTICE, "Can't setsockopt SO_KEEPALIVE socket: %s", strerror(errno)); | |
788 | close(ls); | |
789 | return 0; | |
790 | } | |
791 | ||
792 | if (setsockopt(ls, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) == -1) { | |
793 | syslog(LOG_NOTICE, "Can't setsockopt SO_REUSEADDR socket: %s", strerror(errno)); | |
794 | close(ls); | |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
795 | return 0; |
44 | 796 | } |
797 | ||
798 | if (bind(ls, (struct sockaddr *)&myaddr_in, sizeof(struct sockaddr_in)) == -1) { | |
799 | syslog(LOG_NOTICE, "Can't bind to listen socket: %s", strerror(errno)); | |
800 | close(ls); | |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
801 | return 0; |
44 | 802 | } |
803 | ||
804 | if (listen(ls, 5) == -1) { | |
805 | syslog(LOG_NOTICE, "Can't listen on listen socket: %s", strerror(errno)); | |
806 | close(ls); | |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
807 | return 0; |
44 | 808 | } |
809 | ||
810 | syslog(LOG_NOTICE, "listen socket created %d", ls); | |
811 | if (debug) | |
812 | fprintf(stdout, "listen socket created %d\n", ls); | |
813 | ||
814 | ||
43 | 815 | /* |
816 | * Loop forever until the external shutdown variable is set. | |
817 | */ | |
818 | for (;;) { | |
819 | ||
820 | addrlen = sizeof(struct sockaddr_in); | |
821 | /* | |
822 | * This call will block until a new connection | |
823 | * arrives. Then it will return the address of | |
824 | * the connecting peer, and a new socket | |
825 | * descriptor, s, for that connection. | |
826 | */ | |
827 | s = accept(ls, (struct sockaddr *)&peeraddr_in, &addrlen); | |
828 | if (s == -1) { | |
829 | syslog(LOG_NOTICE, "my_server_loop accept failed %s", strerror(errno)); | |
830 | if (debug) | |
831 | fprintf(stdout, "my_server_loop accept failed %s\n", strerror(errno)); | |
44 | 832 | return 0; |
43 | 833 | } |
834 | ||
48 | 835 | cmd_server(); |
43 | 836 | |
837 | if (my_shutdown) { | |
838 | syslog(LOG_NOTICE, "Thread my_server_loop stopped"); | |
839 | if (debug) | |
840 | fprintf(stdout, "Thread my_server_loop stopped\n"); | |
841 | return 0; | |
842 | } | |
843 | ||
844 | } | |
845 | } | |
846 | ||
847 |