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