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