Merge branch 'master' of https://github.com/szmoore/MCTX3420.git
authorJeremy Tan <[email protected]>
Sat, 14 Sep 2013 03:04:12 +0000 (11:04 +0800)
committerJeremy Tan <[email protected]>
Sat, 14 Sep 2013 03:04:12 +0000 (11:04 +0800)
Conflicts:
server/control.c

server/control.c
server/fastcgi.c

index 1f33eea..70fc2ee 100644 (file)
@@ -5,10 +5,13 @@
 #include "common.h"
 #include "control.h"
 
+const char * g_actuator_names[NUMACTUATORS] = {        
+       "Pressure regulator", "Solenoid 1" 
+};
 
 /**
  * Handles control of the actuators.
- *
+ */
 void ActuatorHandler(FCGIContext *context, ActuatorId id, const char *set_value) {
        char *ptr;
        
@@ -46,7 +49,6 @@ void ActuatorHandler(FCGIContext *context, ActuatorId id, const char *set_value)
                                STATUS_ERROR, "Invalid actuator id specified.");
        }
 }
-*/
 
 /**
  * System control handler. This covers control over all aspects of the system.
@@ -55,53 +57,47 @@ void ActuatorHandler(FCGIContext *context, ActuatorId id, const char *set_value)
  * @param params The input parameters
  */
 void Control_Handler(FCGIContext *context, char *params) {
-       const char *key, *value, *control_key = NULL;
-       const char *action = NULL, *set_value = NULL;
+       const char *action, *key = "", *mode = "", *name = "";
        bool force = false;
-       char *ptr;
-       int id = -1;
-       
-       while ((params = FCGI_KeyPair(params, &key, &value))) {
-               if (!strcmp(key, "action"))
-                       action = value;
-               else if (!strcmp(key, "key"))
-                       control_key = value;
-               else if (!strcmp(key, "force"))
-                       force = !force;
-               else if (!strcmp(key, "id") && *value) { //Ensure non-empty value
-                       int parsed = strtol(value, &ptr, 10);
-                       if (*ptr == '\0') {
-                               id = parsed;
-                       }
-               } else if (!strcmp(key, "value")) {
-                       set_value = value;
-               }
-       }
-       Log(LOGDEBUG, "Id %d", id); // to stop compiler complaining for now
-       
-       if (action == NULL) { //Must have an action
-               FCGI_RejectJSON(context, "No action specified");
-       } else if (!strcmp(action, "start")) {
+
+       FCGIValue values[5] = {
+               {"action", &action, FCGI_REQUIRED(FCGI_STRING_T)},
+               {"key", &key, FCGI_STRING_T},
+               {"force", &force, FCGI_BOOL_T},
+               {"mode", &mode, FCGI_STRING_T},
+               {"name", &name, FCGI_STRING_T}
+       };
+
+       if (!FCGI_ParseRequest(context, params, values, 5))
+               return;
+
+       if (!strcmp(action, "gain")) {
                FCGI_BeginControl(context, force);
-       } else if (!strcmp(action, "stop")) { //Don't require control key to stop...
-               //EMERGENCY STOP!! TODO - replace!
-               FCGI_BeginJSON(context, STATUS_OK);
-               FCGI_JSONPair("description", "stopped! (not)");
-               FCGI_EndJSON();
-       } else { //Under this section, the user must have the current control key.
-               if (!FCGI_HasControl(context, control_key)) {
+       } else { 
+               if (!FCGI_HasControl(context, key)) {
                        FCGI_RejectJSONEx(context, 
                                STATUS_UNAUTHORIZED, "Invalid control key specified.");
-               } else if (!strcmp(action, "end")) {
+                       
+               } else if (!strcmp(action, "release")) {
                        FCGI_EndControl(context);
-               } else if (!strcmp(action, "set")) {
-                       if (set_value == NULL || *set_value == '\0') {
-                               FCGI_RejectJSONEx(context, 
-                                       STATUS_ERROR, "Set called but no value specified.");
-                       } else 
-                       {
-//                             ActuatorHandler(context, id, set_value);
+               } else if (!strcmp(action, "experiment")) {
+                       if (!strcmp(mode, "start")) {
+                               FCGI_BeginJSON(context, STATUS_OK);
+                               FCGI_JSONPair("description", mode);
+                               FCGI_EndJSON();
+                       } else if (!strcmp(mode, "pause")) {
+                               FCGI_BeginJSON(context, STATUS_OK);
+                               FCGI_JSONPair("description", mode);
+                               FCGI_EndJSON();
+                       } else if (!strcmp(mode, "stop")) {
+                               FCGI_BeginJSON(context, STATUS_OK);
+                               FCGI_JSONPair("description", mode);
+                               FCGI_EndJSON();
+                       } else {
+                               FCGI_RejectJSON(context, "Unknown experiment mode specified");
                        }
+               } else {
+                       FCGI_RejectJSON(context, "Unknown action specified");
                }
        }
 }
index f4b0f2d..8714db2 100644 (file)
@@ -40,24 +40,14 @@ struct FCGIContext {
  */ 
 static void IdentifyHandler(FCGIContext *context, char *params) {
        bool ident_sensors = false, ident_actuators = false;
-       //const char *key, *value;
 
        int i;
 
        FCGIValue values[2] = {{"sensors", &ident_sensors, FCGI_BOOL_T},
                                         {"actuators", &ident_actuators, FCGI_BOOL_T}};
-
        if (!FCGI_ParseRequest(context, params, values, 2))
                return;
 
-       /*while ((params = FCGI_KeyPair(params, &key, &value))) {
-               if (!strcmp(key, "sensors")) {
-                       ident_sensors = !ident_sensors;
-               } else if (!strcmp(key, "actuators")) {
-                       ident_actuators = !ident_actuators;
-               }
-       }*/
-
        FCGI_BeginJSON(context, STATUS_OK);
        FCGI_JSONPair("description", "MCTX3420 Server API (2013)");
        FCGI_JSONPair("build_date", __DATE__ " " __TIME__);

UCC git Repository :: git.ucc.asn.au