Fri, 11 Jul 2014 22:53:33 +0200
Basic web idea
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++; | |
100 | 212 | srv_send((char *)"%d,%s,%s,%s", i, unit->uuid, unit->name, UNITMODE[unit->mode]); |
81 | 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) { |
100 | 226 | srv_send((char *)"%s,N/A,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
|
227 | } else if (strncmp(de->d_name, (char *)"10", 2) == 0) { |
100 | 228 | srv_send((char *)"%s,18S20,Digital thermometer", de->d_name); |
86
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) { |
100 | 230 | srv_send((char *)"%s,18B20,Digital thermometer", de->d_name); |
86
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) { |
100 | 232 | srv_send((char *)"%s,2408,8 Channel addressable switch/LCD", de->d_name); |
86
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) { |
100 | 234 | srv_send((char *)"%s,2413,Dual channel addressable switchs", de->d_name); |
86
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
235 | } else { |
100 | 236 | srv_send((char *)"%s,N/A,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++; | |
100 | 256 | srv_send((char *)"%d,%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) { | |
100 | 275 | srv_send((char *)"NAME,%s", unit->name); |
276 | srv_send((char *)"UUID,%s", unit->uuid); | |
92 | 277 | if (unit->air_address) { |
100 | 278 | srv_send((char *)"AIR_ADDRESS,%s", unit->air_address); |
279 | srv_send((char *)"AIR_TEMP,%.1f", unit->air_temp); | |
92 | 280 | } |
281 | if (unit->beer_address) { | |
100 | 282 | srv_send((char *)"BEER_ADDRESS,%s", unit->beer_address); |
283 | srv_send((char *)"BEER_TEMP,%.1f", unit->beer_temp); | |
92 | 284 | } |
285 | if (unit->io1_address) { | |
100 | 286 | 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
|
287 | } |
92 | 288 | if (unit->io2_address) { |
100 | 289 | srv_send((char *)"IO2_ADDRESS,%s", unit->io2_address); |
92 | 290 | } |
291 | if (unit->heater_available) { | |
100 | 292 | srv_send((char *)"HEATER_AVAILABLE,%s", unit->heater_available); |
92 | 293 | } |
294 | if (unit->cooler_available) { | |
100 | 295 | srv_send((char *)"COOLER_AVAILABLE,%s", unit->cooler_available); |
92 | 296 | } |
297 | if (unit->fan_available) { | |
100 | 298 | srv_send((char *)"FAN_AVAILABLE,%s", unit->fan_available); |
92 | 299 | } |
100 | 300 | srv_send((char *)"MODE,%s", UNITMODE[unit->mode]); |
301 | srv_send((char *)"FRIDGE_SET,%.1f", unit->fridge_set); | |
302 | srv_send((char *)"BEER_SET,%.1f", unit->beer_set); | |
92 | 303 | if (unit->profile) { |
100 | 304 | srv_send((char *)"PROFILE,%s", unit->profile); |
92 | 305 | } |
100 | 306 | srv_send((char *)"TEMP_SET_MIN,%.1f", unit->temp_set_min); |
307 | srv_send((char *)"TEMP_SET_MAX,%.1f", unit->temp_set_max); | |
308 | srv_send((char *)"IDLE_RANGE_L,%.1f", unit->idle_rangeL); | |
309 | 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
|
310 | } |
84 | 311 | } |
92 | 312 | srv_send((char *)"."); |
313 | return 0; | |
81 | 314 | } |
315 | ||
92 | 316 | srv_send((char *)"502 Unknown command option"); |
317 | return 1; | |
81 | 318 | } |
319 | ||
320 | ||
321 | ||
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
322 | /* |
88 | 323 | * Set new operating mode |
324 | * MODE OFF|NONE|BEER|FRIDGE|PROFILE | |
325 | */ | |
326 | int cmd_mode(char *buf) | |
327 | { | |
328 | return 1; | |
329 | } | |
330 | ||
331 | ||
332 | ||
333 | /* | |
92 | 334 | * SET BEER float |
335 | * SET FRIDGE float | |
336 | * SET VOLUME float | |
337 | * SET IDLE_LOW float | |
338 | * SET IDLE_HIGH float | |
339 | * SET TEMP_MIN float | |
340 | * SET TEMP_MAX float | |
341 | * SET NAME string | |
342 | * SET PROFILE string | |
88 | 343 | */ |
344 | int cmd_set(char *buf) | |
345 | { | |
346 | char *opt, *param; | |
347 | units_list *unit; | |
348 | int i, rc; | |
349 | float fval; | |
350 | ||
351 | opt = strtok(buf, " \0"); | |
352 | opt = strtok(NULL, " \0"); | |
353 | if (opt == NULL) { | |
354 | srv_send((char *)"501 Subcommand missing"); | |
355 | return 1; | |
356 | } | |
357 | ||
358 | param = strtok(NULL, "\0"); | |
359 | if (param == NULL) { | |
360 | srv_send((char *)"501 Parameter missing"); | |
361 | return 1; | |
362 | } | |
363 | ||
364 | rc = sscanf(param, "%f", &fval); | |
365 | ||
366 | if (debug) | |
367 | fprintf(stdout, "opt='%s' param='%s' rc=%d fval=%.1f\n", opt, param, rc, fval); | |
368 | ||
369 | /* | |
370 | * Commands below need a selected unit | |
371 | */ | |
372 | if (current_unit == -1) { | |
373 | srv_send((char *)"401 No fermenter unit selected"); | |
374 | return 1; | |
375 | } | |
376 | ||
377 | i = 0; | |
378 | for (unit = Config.units; unit; unit = unit->next) { | |
379 | i++; | |
380 | if (i == current_unit) | |
381 | break; | |
382 | } | |
383 | ||
384 | /* | |
385 | * If a valid parameter float value | |
386 | */ | |
387 | if (rc == 1) { | |
388 | if (strcmp(opt, (char *)"BEER") == 0) { | |
389 | if ((fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) { | |
390 | unit->beer_set = fval; | |
391 | srv_send((char *)"214 Unit %d BEER set to %.1f", current_unit, fval); | |
392 | return 0; | |
393 | } else { | |
394 | srv_send((char *)"510 New temperature not between %.1f and %.1f", unit->temp_set_min, unit->temp_set_max); | |
395 | return 1; | |
396 | } | |
397 | } else if (strcmp(opt, (char *)"FRIDGE") == 0) { | |
398 | if ((fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) { | |
399 | unit->fridge_set = fval; | |
400 | srv_send((char *)"214 Unit %d BEER set to %.1f", current_unit, fval); | |
401 | return 0; | |
402 | } else { | |
403 | srv_send((char *)"510 New temperature not between %.1f and %.1f", unit->temp_set_min, unit->temp_set_max); | |
404 | return 1; | |
405 | } | |
406 | } else if (strcmp(opt, (char *)"VOLUME") == 0) { | |
407 | /* | |
408 | * Must fit in a 2 TEU container | |
409 | */ | |
410 | if ((fval >= 0.0) && (fval <= 77020.0)) { | |
411 | unit->volume = fval; | |
412 | srv_send((char *)"214 Unit %d VOLUME set to %.1f", current_unit, fval); | |
413 | return 0; | |
414 | } else { | |
415 | srv_send((char *)"510 New volume not between 0 and 77020"); | |
416 | return 1; | |
417 | } | |
418 | } else if (strcmp(opt, (char *)"IDLE_LOW") == 0) { | |
419 | if ((fval >= -5.0) && (fval <= -0.1)) { | |
420 | unit->idle_rangeL = fval; | |
421 | srv_send((char *)"214 Unit %d IDLE_LOW set to %.1f", current_unit, fval); | |
422 | return 0; | |
423 | } else { | |
424 | srv_send((char *)"510 New value not between -5.0 and -0.1"); | |
425 | return 1; | |
426 | } | |
427 | } else if (strcmp(opt, (char *)"IDLE_HIGH") == 0) { | |
428 | if ((fval >= 0.1) && (fval <= 5.0)) { | |
429 | unit->idle_rangeH = fval; | |
430 | srv_send((char *)"214 Unit %d IDLE_HIGH set to %.1f", current_unit, fval); | |
431 | return 0; | |
432 | } else { | |
433 | srv_send((char *)"510 New value not between -5.0 and -0.1"); | |
434 | return 1; | |
435 | } | |
436 | } else if (strcmp(opt, (char *)"TEMP_MIN") == 0) { | |
437 | if ((fval >= -2.0) && (fval <= 35.0) && (fval < unit->temp_set_max)) { | |
438 | unit->temp_set_min = fval; | |
439 | srv_send((char *)"214 Unit %d TEMP_MIN set to %.1f", current_unit, fval); | |
440 | return 0; | |
441 | } else { | |
442 | srv_send((char *)"510 New value not between -2.0 and 35.0 and lower then TEMP_MAX"); | |
443 | return 1; | |
444 | } | |
445 | } else if (strcmp(opt, (char *)"TEMP_MAX") == 0) { | |
446 | if ((fval >= -2.0) && (fval <= 35.0) && (fval > unit->temp_set_min)) { | |
447 | unit->temp_set_max = fval; | |
448 | srv_send((char *)"214 Unit %d TEMP_MAX set to %.1f", current_unit, fval); | |
449 | return 0; | |
450 | } else { | |
451 | srv_send((char *)"510 New value not between -2.0 and 35.0 and higher then TEMP_MIN"); | |
452 | return 1; | |
453 | } | |
454 | } | |
455 | } | |
456 | ||
457 | /* | |
458 | * Set new unit or beer name | |
459 | */ | |
460 | if (strcmp(opt, (char *)"NAME") == 0) { | |
461 | if (unit->name) | |
462 | free(unit->name); | |
463 | unit->name = xstrcpy(param); | |
464 | srv_send((char *)"214 Unit %d NAME set to '%s'", current_unit, param); | |
465 | // TODO: change logfile name | |
466 | return 0; | |
467 | } else if (strcmp(opt, (char *)"PROFILE") == 0) { | |
468 | // check profile file, excists, type, at least one profile item | |
469 | } | |
470 | ||
471 | srv_send((char *)"502 Unknown command option"); | |
472 | return 1; | |
473 | } | |
474 | ||
475 | ||
476 | ||
477 | /* | |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
478 | * UNIT n |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
479 | * UNIT uuid |
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 | int cmd_unit(char *buf) |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
482 | { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
483 | char *opt; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
484 | units_list *tmp; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
485 | int i, unit_no; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
486 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
487 | opt = strtok(buf, " \0"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
488 | opt = strtok(NULL, " \0"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
489 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
490 | if (opt == NULL) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
491 | srv_send((char *)"501 Parameter missing"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
492 | return 1; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
493 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
494 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
495 | i = 0; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
496 | if (strlen(opt) == 36) { |
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 | * Search using uuid |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
499 | */ |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
500 | 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
|
501 | i++; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
502 | if (strcmp(opt, tmp->uuid) == 0) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
503 | 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
|
504 | current_unit = i; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
505 | return 0; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
506 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
507 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
508 | srv_send((char *)"410 No such unit"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
509 | return 1; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
510 | } |
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 | if (sscanf(opt, "%d", &unit_no) == 1) { |
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 | * 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
|
515 | */ |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
516 | 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
|
517 | i++; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
518 | if (unit_no == i) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
519 | 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
|
520 | current_unit = i; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
521 | return 0; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
522 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
523 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
524 | srv_send((char *)"410 No such unit"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
525 | return 1; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
526 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
527 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
528 | srv_send((char *)"502 Unknown command option"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
529 | return 1; |
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 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
532 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
533 | |
43 | 534 | void cmd_server(void) |
535 | { | |
54
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
536 | char *inp, *p, *q, buf[SS_BUFSIZE], obuf[SS_BUFSIZE]; |
48 | 537 | int i, rc, rlen; |
43 | 538 | socklen_t fromlen; |
46
000399c64d3f
More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
539 | float newtemp; |
68
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
540 | #ifdef HAVE_WIRINGPI_H |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
541 | int j; |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
542 | #endif |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
543 | |
48 | 544 | memset((char *)&buf, 0, SS_BUFSIZE); |
545 | fromlen = sizeof(peeraddr_in); | |
546 | rlen = recvfrom(s, buf, sizeof(buf) -1, 0, (struct sockaddr *)&peeraddr_in, &fromlen); | |
547 | if (rlen == -1) { | |
548 | syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno)); | |
549 | } else { | |
550 | for (i = 0; i < strlen(buf); i++) { | |
551 | if (buf[i] == '\n') | |
552 | buf[i] = '\0'; | |
553 | if (buf[i] == '\r') | |
554 | buf[i] = '\0'; | |
555 | } | |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
556 | for (i = strlen(buf) -1; i > 0; i--) { |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
557 | if (buf[i] == ' ') |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
558 | buf[i] = '\0'; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
559 | else |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
560 | break; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
561 | } |
48 | 562 | if (strlen(buf)) { |
563 | if (debug) { | |
564 | syslog(LOG_NOTICE, "recv: \"%s\"", buf); | |
565 | fprintf(stdout, "recv: \"%s\"\n", buf); | |
43 | 566 | } |
567 | ||
568 | /* | |
48 | 569 | * Process commands from the client |
43 | 570 | */ |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
571 | if (strncmp(buf, "ADD", 3) == 0) { |
92 | 572 | if (unit_add(buf) == 0) |
573 | wrconfig(); | |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
574 | } 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
|
575 | srv_send((char *)"100 Help text follows"); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
576 | srv_send((char *)"Recognized commands:"); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
577 | srv_send((char *)""); |
92 | 578 | srv_send((char *)"ADD PROFILE name Add a new profile with \"name\""); |
579 | 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
|
580 | srv_send((char *)"LCD Get LCD screen (allways 4 rows of 20 characters)"); |
81 | 581 | srv_send((char *)"LIST List all fermenter units"); |
84 | 582 | 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
|
583 | 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
|
584 | srv_send((char *)"LIST UNIT List fermenter unit"); |
88 | 585 | srv_send((char *)"MODE OFF|NONE|BEER|FRIDGE|PROFILE"); |
81 | 586 | // srv_send((char *)"PROFILE Profile status"); |
587 | // srv_send((char *)"PROFILE start|stop|pause Profile start, stop or pause"); | |
88 | 588 | srv_send((char *)"SET BEER val Set beer temperature"); |
589 | srv_send((char *)"SET FRIDGE val Set fridge temperature"); | |
590 | srv_send((char *)"SET IDLE_LOW val Set idle temperature low (-5.0 .. -0.1)"); | |
591 | srv_send((char *)"SET IDLE_HIGH val Set idle temperature high (0.1 .. 5.0)"); | |
592 | srv_send((char *)"SET NAME name Set name or beername for the unit"); | |
81 | 593 | // srv_send((char *)"SET PROFILE name Set named profile"); |
88 | 594 | srv_send((char *)"SET TEMP_MIN val Set unit minimum temperature"); |
595 | srv_send((char *)"SET TEMP_MAX val Set unit maximum temperature"); | |
596 | 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
|
597 | 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
|
598 | srv_send((char *)"."); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
599 | } else if (strncmp(buf, "LCD", 3) == 0) { |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
600 | #ifdef HAVE_WIRINGPI_H |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
601 | srv_send((char *)"201 information follows"); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
602 | for (j = 0; j < 4; j++) { |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
603 | sprintf(obuf, " "); |
70 | 604 | obuf[20] = '\0'; |
68
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
605 | for (i = 0; i < 20; i++) |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
606 | obuf[i] = lcdbuf[lcdHandle][i][j]; |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
607 | srv_send(obuf); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
608 | } |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
609 | srv_send((char *)"."); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
610 | #else |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
611 | srv_send((char *)"403 LCD not available"); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
612 | #endif |
81 | 613 | } else if (strncmp(buf, "LIST", 4) == 0) { |
614 | cmd_list(buf); | |
88 | 615 | } else if (strncmp(buf, "MODE", 4) == 0) { |
616 | cmd_mode(buf); | |
617 | } else if (strncmp(buf, "SET", 3) == 0) { | |
92 | 618 | if (cmd_set(buf) == 0) |
619 | wrconfig(); | |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
620 | } else if (strncmp(buf, "UNIT", 4) == 0) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
621 | cmd_unit(buf); |
95 | 622 | |
623 | /* | |
624 | * Now the old style (brewPi) commands. These will go away. | |
625 | */ | |
68
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
626 | } else if (strncmp(buf, "ack", 3) == 0) { |
48 | 627 | srv_send((char *)"ack"); |
628 | } else if (strncmp(buf, "lcd", 3) == 0) { | |
629 | sprintf(obuf, "[\" \", \" \", \" \", \" \"]"); | |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
630 | #ifdef HAVE_WIRINGPI_H |
48 | 631 | for (i = 0; i < 20; i++) { |
632 | obuf[i+2] = lcdbuf[lcdHandle][i][0]; | |
633 | obuf[i+26] = lcdbuf[lcdHandle][i][1]; | |
634 | obuf[i+50] = lcdbuf[lcdHandle][i][2]; | |
635 | obuf[i+74] = lcdbuf[lcdHandle][i][3]; | |
636 | } | |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
637 | #endif |
48 | 638 | srv_send(obuf); |
639 | } else if (strncmp(buf, "getMode", 7) == 0) { | |
95 | 640 | srv_send("%c", UNITmode[Config.units->mode]); |
48 | 641 | } else if (strncmp(buf, "getFridge", 9) == 0) { |
95 | 642 | srv_send("%.1f", Config.units->fridge_set); |
48 | 643 | } else if (strncmp(buf, "getBeer", 7) == 0) { |
95 | 644 | srv_send("%.1f", Config.units->beer_set); |
48 | 645 | } else if (strncmp(buf, "getControlConstants", 19) == 0) { |
646 | srv_send("{ \"tempFormat\":\"%c\", \"tempSetMin\":%.1f, \"tempSetMax\":%.1f, \"idleRangeH\":%.3f, \"idleRangeL\":%.3f }", | |
95 | 647 | Config.tempFormat, Config.units->temp_set_min, Config.units->temp_set_max, Config.units->idle_rangeH, Config.units->idle_rangeL); |
48 | 648 | } else if (strncmp(buf, "getControlSettings", 18) == 0) { |
649 | srv_send("{ \"mode\":\"%c\", \"beerSet\":%.1f, \"fridgeSet\":%.1f, \"heatEstimator\":%.1f, \"coolEstimator\":%.1f }", | |
95 | 650 | UNITmode[Config.units->mode], Config.units->beer_set, Config.units->fridge_set, cs_heatEstimator, cs_coolEstimator); |
48 | 651 | } else if (strncmp(buf, "getControlVariables", 19) == 0) { |
652 | srv_send("{ \"beerDiff\":%.2f }", cv_beerDiff); | |
49
92a9ca143677
Fixed temperature logging, added some commands
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
653 | } else if (strncmp(buf, "loadDefaultControlSettings", 26) == 0) { |
95 | 654 | // Does nothing anymore |
49
92a9ca143677
Fixed temperature logging, added some commands
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
655 | srv_send("ack"); |
92a9ca143677
Fixed temperature logging, added some commands
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
656 | } else if (strncmp(buf, "loadDefaultControlConstants", 27) == 0) { |
95 | 657 | // Does nothing anymore |
49
92a9ca143677
Fixed temperature logging, added some commands
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
658 | srv_send("ack"); |
48 | 659 | } else if (strncmp(buf, "setBeer=", 8) == 0) { |
660 | inp = xstrcpy(buf+8); | |
661 | rc = sscanf(inp, "%f", &newtemp); | |
662 | if (debug) | |
663 | fprintf(stdout, "new temp from %s, %.1f, rc=%d\n", inp, newtemp, rc); | |
664 | if (rc == 1) { | |
95 | 665 | 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
|
666 | 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
|
667 | srv_send("ack"); |
95 | 668 | Config.units->mode = UNITMODE_BEER; |
669 | Config.units->beer_set = newtemp; | |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
670 | } else { |
95 | 671 | 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
|
672 | srv_send("err"); |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
673 | } |
48 | 674 | } else { |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
675 | syslog(LOG_NOTICE, "Cannot convert temperature '%s' to float", inp); |
48 | 676 | srv_send("err"); |
677 | } | |
678 | free(inp); | |
679 | } else if (strncmp(buf, "setFridge=", 10) == 0) { | |
680 | inp = xstrcpy(buf+10); | |
681 | rc = sscanf(inp, "%f", &newtemp); | |
682 | if (debug) | |
683 | fprintf(stdout, "new temp from %s, %.1f, rc=%d\n", inp, newtemp, rc); | |
684 | if (rc == 1) { | |
95 | 685 | 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
|
686 | 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
|
687 | srv_send("ack"); |
95 | 688 | Config.units->mode = UNITMODE_FRIDGE; |
689 | Config.units->fridge_set = newtemp; | |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
690 | } else { |
95 | 691 | 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
|
692 | srv_send("err"); |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
693 | } |
48 | 694 | } else { |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
695 | syslog(LOG_NOTICE, "Cannot convert temperature '%s' to float", inp); |
48 | 696 | srv_send("err"); |
697 | } | |
698 | free(inp); | |
49
92a9ca143677
Fixed temperature logging, added some commands
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
699 | } else if (strncmp(buf, "setOff", 6) == 0) { |
92a9ca143677
Fixed temperature logging, added some commands
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
700 | if (debug) |
92a9ca143677
Fixed temperature logging, added some commands
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
701 | 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
|
702 | syslog(LOG_NOTICE, "Notification: Temperature control disabled"); |
95 | 703 | Config.units->mode = UNITMODE_OFF; |
49
92a9ca143677
Fixed temperature logging, added some commands
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
704 | srv_send("ack"); |
54
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
705 | } else if (strncmp(buf, "setParameters=", 14) == 0) { |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
706 | 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
|
707 | if (debug) |
54
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
708 | fprintf(stdout, "setParameters: %s\n", inp); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
709 | strtok(inp, (char *)"\""); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
710 | p = strtok(NULL, (char *)"\""); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
711 | q = strtok(NULL, (char *)":,}"); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
712 | if (strcmp(p, (char *)"tempSetMin") == 0) { |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
713 | rc = sscanf(q, "%f", &newtemp); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
714 | if (rc == 1) { |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
715 | syslog(LOG_NOTICE, "cc_tempSetMin = %1.f", newtemp); |
95 | 716 | Config.units->temp_set_min = newtemp; |
54
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
717 | srv_send("ack"); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
718 | } else { |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
719 | srv_send("ERR"); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
720 | } |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
721 | } else if (strcmp(p, (char *)"tempSetMax") == 0) { |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
722 | rc = sscanf(q, "%f", &newtemp); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
723 | if (rc == 1) { |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
724 | syslog(LOG_NOTICE, "cc_tempSetMax = %1.f", newtemp); |
95 | 725 | Config.units->temp_set_max = newtemp; |
54
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
726 | srv_send("ack"); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
727 | } else { |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
728 | srv_send("ERR"); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
729 | } |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
730 | } else { |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
731 | 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
|
732 | srv_send("ERR"); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
733 | } |
62 | 734 | free(inp); |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
735 | // stopScript |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
736 | // quit |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
737 | // eraseLogs |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
738 | // interval |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
739 | // startNewBrew |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
740 | // pauseLogging |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
741 | // stopLogging |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
742 | // resumeLogging |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
743 | // dateTimeFormatDisplay |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
744 | } 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
|
745 | 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
|
746 | // programArduino |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
747 | // refreshDeviceList |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
748 | // getDeviceList |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
749 | // applyDevice |
43 | 750 | } else { |
48 | 751 | if (debug) |
752 | fprintf(stdout, "unknown command \"%s\"\n", buf); | |
753 | srv_send((char *)"ERR"); | |
43 | 754 | } |
755 | } | |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
756 | } |
44 | 757 | |
758 | close(s); | |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
759 | } |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
760 | |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
761 | |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
762 | #ifdef HAVE_WIRINGPI_H |
43 | 763 | PI_THREAD (my_server_loop) |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
764 | #else |
74 | 765 | 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
|
766 | #endif |
43 | 767 | { |
768 | socklen_t addrlen; | |
44 | 769 | int optval = 1; |
43 | 770 | |
771 | syslog(LOG_NOTICE, "Thread my_server_loop started"); | |
772 | if (debug) | |
773 | fprintf(stdout, "Thread my_server_loop started\n"); | |
774 | ||
44 | 775 | memset((char *)&myaddr_in, 0, sizeof(struct sockaddr_in)); |
776 | memset((char *)&peeraddr_in, 0, sizeof(struct sockaddr_in)); | |
777 | myaddr_in.sin_family = AF_INET; | |
778 | myaddr_in.sin_addr.s_addr = INADDR_ANY; | |
779 | myaddr_in.sin_port = htons(Config.my_port); | |
780 | ||
781 | ls = socket(AF_INET, SOCK_STREAM, 0); | |
782 | if (ls == -1) { | |
783 | syslog(LOG_NOTICE, "Can't create listen socket: %s", strerror(errno)); | |
784 | fprintf(stderr, "Can't create listen socket: %s\n", strerror(errno)); | |
785 | return 0; | |
786 | } | |
787 | ||
788 | if (setsockopt(ls, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(optval)) == -1) { | |
789 | syslog(LOG_NOTICE, "Can't setsockopt SO_KEEPALIVE socket: %s", strerror(errno)); | |
790 | close(ls); | |
791 | return 0; | |
792 | } | |
793 | ||
794 | if (setsockopt(ls, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) == -1) { | |
795 | syslog(LOG_NOTICE, "Can't setsockopt SO_REUSEADDR socket: %s", strerror(errno)); | |
796 | close(ls); | |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
797 | return 0; |
44 | 798 | } |
799 | ||
800 | if (bind(ls, (struct sockaddr *)&myaddr_in, sizeof(struct sockaddr_in)) == -1) { | |
801 | syslog(LOG_NOTICE, "Can't bind to listen socket: %s", strerror(errno)); | |
802 | close(ls); | |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
803 | return 0; |
44 | 804 | } |
805 | ||
806 | if (listen(ls, 5) == -1) { | |
807 | syslog(LOG_NOTICE, "Can't listen on listen socket: %s", strerror(errno)); | |
808 | close(ls); | |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
809 | return 0; |
44 | 810 | } |
811 | ||
812 | syslog(LOG_NOTICE, "listen socket created %d", ls); | |
813 | if (debug) | |
814 | fprintf(stdout, "listen socket created %d\n", ls); | |
815 | ||
816 | ||
43 | 817 | /* |
818 | * Loop forever until the external shutdown variable is set. | |
819 | */ | |
820 | for (;;) { | |
821 | ||
822 | addrlen = sizeof(struct sockaddr_in); | |
823 | /* | |
824 | * This call will block until a new connection | |
825 | * arrives. Then it will return the address of | |
826 | * the connecting peer, and a new socket | |
827 | * descriptor, s, for that connection. | |
828 | */ | |
829 | s = accept(ls, (struct sockaddr *)&peeraddr_in, &addrlen); | |
830 | if (s == -1) { | |
831 | syslog(LOG_NOTICE, "my_server_loop accept failed %s", strerror(errno)); | |
832 | if (debug) | |
833 | fprintf(stdout, "my_server_loop accept failed %s\n", strerror(errno)); | |
44 | 834 | return 0; |
43 | 835 | } |
836 | ||
48 | 837 | cmd_server(); |
43 | 838 | |
839 | if (my_shutdown) { | |
840 | syslog(LOG_NOTICE, "Thread my_server_loop stopped"); | |
841 | if (debug) | |
842 | fprintf(stdout, "Thread my_server_loop stopped\n"); | |
843 | return 0; | |
844 | } | |
845 | ||
846 | } | |
847 | } | |
848 | ||
849 |