Added GET AIR, GET BEER, GET TARGET commands

Thu, 31 Jul 2014 13:43:09 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 31 Jul 2014 13:43:09 +0200
changeset 157
259a018758f9
parent 156
5fb74d89f571
child 158
f1b7e2ef90be

Added GET AIR, GET BEER, GET TARGET commands

thermferm/server.c file | annotate | diff | comparison | revisions
thermferm/thermferm.h file | annotate | diff | comparison | revisions
--- a/thermferm/server.c	Wed Jul 30 23:06:46 2014 +0200
+++ b/thermferm/server.c	Thu Jul 31 13:43:09 2014 +0200
@@ -278,6 +278,64 @@
 
 
 /*
+ * GET AIR uuid
+ * GET BEER uuid
+ * GET TARGET uuid
+ */
+int cmd_get(char *buf)
+{
+    char	*opt, *uuid;
+    units_list	*unit;
+
+    opt = strtok(buf, " \0");
+    opt = strtok(NULL, " \0");
+    uuid = strtok(NULL, "\0");
+
+    if (uuid == NULL) {
+	srv_send((char *)"502 Missing command option");
+	return 1;
+    }
+
+    for (unit = Config.units; unit; unit = unit->next) {
+	if (strcmp(uuid, unit->uuid) == 0) {
+
+	    if (strcmp(opt, (char *)"AIR") == 0) {
+		if (unit->air_state == 0)
+		    srv_send((char *)"215 AIR,%.3f", unit->air_temperature);
+		else
+		    srv_send((char *)"215 AIR,NA");
+		return 0;
+	    } else if (strcmp(opt, (char *)"BEER") == 0) {
+		if (unit->beer_state == 0)
+		    srv_send((char *)"215 BEER,%.3f", unit->beer_temperature);
+		else
+		    srv_send((char *)"215 BEER,NA");
+		return 0;
+	    } else if (strcmp(opt, (char *)"TARGET") == 0) {
+		if (unit->mode == UNITMODE_BEER) {
+		    srv_send((char *)"215 TARGET,%.3f", unit->beer_set);
+		} else if (unit->mode == UNITMODE_FRIDGE) {
+		    srv_send((char *)"215 TARGET,%.3f", unit->fridge_set);
+		} else if (unit->mode == UNITMODE_PROFILE) {
+		    srv_send((char *)"215 TARGET,%.3f", unit->prof_target);
+		} else {
+		    srv_send((char *)"215 TARGET,NA");
+		}
+		return 0;
+	    }
+
+	    srv_send((char *)"502 Unknown command option");
+	    return 1;
+	}
+    }
+
+    srv_send((char *)"440 No such profile");
+    return 1;
+}
+
+
+
+/*
  * LIST
  * LIST BUS
  * LIST LOG
@@ -974,6 +1032,8 @@
 	    } else if (strncmp(buf, "DEL", 3) == 0) {
 		if (cmd_del(buf) == 0)
 		    wrconfig();
+	    } else if (strncmp(buf, "GET", 3) == 0) {
+		cmd_get(buf);
 	    } else if (strncmp(buf, "HELP", 4) == 0) {
 		srv_send((char *)"100 Help text follows");
 		srv_send((char *)"Recognized commands:");
@@ -983,6 +1043,13 @@
 		srv_send((char *)"ADD UNIT name                 Add a new unit with \"name\"");
 		srv_send((char *)"DEL PROFILE uuid              Delete profile with uuid");
 //		srv_send((char *)"DEL UNIT uuid                 Delete unit with uuid");
+		srv_send((char *)"GET AIR uuid                  Get Air temperature with uuid");
+		srv_send((char *)"GET BEER uuid                 Get Beer temperature with uuid");
+//		srv_send((char *)"GET LED1 uuid                 Get LED 1 (cooler) state");
+//		srv_send((char *)"GET LED2 uuid                 Get LED 2 (heater) state");
+//		srv_send((char *)"GET LED3 uuid                 Get LED 3 (fan) state");
+//		srv_send((char *)"GET DOOR uuid                 Get Door state");
+		srv_send((char *)"GET TARGET uuid               Get Target temperature with uuid");
 		srv_send((char *)"LCD                           Get LCD screen (allways 4 rows of 20 characters)");
 		srv_send((char *)"LIST                          List all fermenter units");
 		srv_send((char *)"LIST BUS                      List 1-wire bus");
--- a/thermferm/thermferm.h	Wed Jul 30 23:06:46 2014 +0200
+++ b/thermferm/thermferm.h	Thu Jul 31 13:43:09 2014 +0200
@@ -91,6 +91,7 @@
     char		*profile;		/* Active profile uuid		*/
     time_t		prof_started;		/* Profile start time		*/
     int			prof_state;		/* Profile OFF|PAUSE|RUN|DONE	*/
+    float		prof_target;		/* Profile current target temp	*/
 } units_list;
 
 #define	UNITMODE_OFF		0		/* Unit turned off		*/

mercurial