thermferm/server.c

changeset 157
259a018758f9
parent 156
5fb74d89f571
child 158
f1b7e2ef90be
equal deleted inserted replaced
156:5fb74d89f571 157:259a018758f9
270 srv_send((char *)"211 Profile %s deleted", param); 270 srv_send((char *)"211 Profile %s deleted", param);
271 return 0; 271 return 0;
272 } 272 }
273 273
274 srv_send((char *)"502 Unknown command option"); 274 srv_send((char *)"502 Unknown command option");
275 return 1;
276 }
277
278
279
280 /*
281 * GET AIR uuid
282 * GET BEER uuid
283 * GET TARGET uuid
284 */
285 int cmd_get(char *buf)
286 {
287 char *opt, *uuid;
288 units_list *unit;
289
290 opt = strtok(buf, " \0");
291 opt = strtok(NULL, " \0");
292 uuid = strtok(NULL, "\0");
293
294 if (uuid == NULL) {
295 srv_send((char *)"502 Missing command option");
296 return 1;
297 }
298
299 for (unit = Config.units; unit; unit = unit->next) {
300 if (strcmp(uuid, unit->uuid) == 0) {
301
302 if (strcmp(opt, (char *)"AIR") == 0) {
303 if (unit->air_state == 0)
304 srv_send((char *)"215 AIR,%.3f", unit->air_temperature);
305 else
306 srv_send((char *)"215 AIR,NA");
307 return 0;
308 } else if (strcmp(opt, (char *)"BEER") == 0) {
309 if (unit->beer_state == 0)
310 srv_send((char *)"215 BEER,%.3f", unit->beer_temperature);
311 else
312 srv_send((char *)"215 BEER,NA");
313 return 0;
314 } else if (strcmp(opt, (char *)"TARGET") == 0) {
315 if (unit->mode == UNITMODE_BEER) {
316 srv_send((char *)"215 TARGET,%.3f", unit->beer_set);
317 } else if (unit->mode == UNITMODE_FRIDGE) {
318 srv_send((char *)"215 TARGET,%.3f", unit->fridge_set);
319 } else if (unit->mode == UNITMODE_PROFILE) {
320 srv_send((char *)"215 TARGET,%.3f", unit->prof_target);
321 } else {
322 srv_send((char *)"215 TARGET,NA");
323 }
324 return 0;
325 }
326
327 srv_send((char *)"502 Unknown command option");
328 return 1;
329 }
330 }
331
332 srv_send((char *)"440 No such profile");
275 return 1; 333 return 1;
276 } 334 }
277 335
278 336
279 337
972 if (unit_add(buf) == 0) 1030 if (unit_add(buf) == 0)
973 wrconfig(); 1031 wrconfig();
974 } else if (strncmp(buf, "DEL", 3) == 0) { 1032 } else if (strncmp(buf, "DEL", 3) == 0) {
975 if (cmd_del(buf) == 0) 1033 if (cmd_del(buf) == 0)
976 wrconfig(); 1034 wrconfig();
1035 } else if (strncmp(buf, "GET", 3) == 0) {
1036 cmd_get(buf);
977 } else if (strncmp(buf, "HELP", 4) == 0) { 1037 } else if (strncmp(buf, "HELP", 4) == 0) {
978 srv_send((char *)"100 Help text follows"); 1038 srv_send((char *)"100 Help text follows");
979 srv_send((char *)"Recognized commands:"); 1039 srv_send((char *)"Recognized commands:");
980 srv_send((char *)""); 1040 srv_send((char *)"");
981 // 12345678901234567890123456789012345678901234567890123456789012345678901234567890 1041 // 12345678901234567890123456789012345678901234567890123456789012345678901234567890
982 srv_send((char *)"ADD PROFILE name Add a new profile with \"name\""); 1042 srv_send((char *)"ADD PROFILE name Add a new profile with \"name\"");
983 srv_send((char *)"ADD UNIT name Add a new unit with \"name\""); 1043 srv_send((char *)"ADD UNIT name Add a new unit with \"name\"");
984 srv_send((char *)"DEL PROFILE uuid Delete profile with uuid"); 1044 srv_send((char *)"DEL PROFILE uuid Delete profile with uuid");
985 // srv_send((char *)"DEL UNIT uuid Delete unit with uuid"); 1045 // srv_send((char *)"DEL UNIT uuid Delete unit with uuid");
1046 srv_send((char *)"GET AIR uuid Get Air temperature with uuid");
1047 srv_send((char *)"GET BEER uuid Get Beer temperature with uuid");
1048 // srv_send((char *)"GET LED1 uuid Get LED 1 (cooler) state");
1049 // srv_send((char *)"GET LED2 uuid Get LED 2 (heater) state");
1050 // srv_send((char *)"GET LED3 uuid Get LED 3 (fan) state");
1051 // srv_send((char *)"GET DOOR uuid Get Door state");
1052 srv_send((char *)"GET TARGET uuid Get Target temperature with uuid");
986 srv_send((char *)"LCD Get LCD screen (allways 4 rows of 20 characters)"); 1053 srv_send((char *)"LCD Get LCD screen (allways 4 rows of 20 characters)");
987 srv_send((char *)"LIST List all fermenter units"); 1054 srv_send((char *)"LIST List all fermenter units");
988 srv_send((char *)"LIST BUS List 1-wire bus"); 1055 srv_send((char *)"LIST BUS List 1-wire bus");
989 srv_send((char *)"LIST LOG List logfile data in 1 hour lines"); 1056 srv_send((char *)"LIST LOG List logfile data in 1 hour lines");
990 srv_send((char *)"LIST PROFILES List available profiles"); 1057 srv_send((char *)"LIST PROFILES List available profiles");

mercurial