X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=server%2Fcontrol.c;h=1f33eeab9ae3b17cf7dfea5730c55d3dae57d747;hb=4f1f3077d6b38e212527b0aaaf7564ba83f0ba81;hp=12e340a649def53f63dac46432b40e292f7d6119;hpb=744b902d7f7b532ddb19d95828d8787653e1b84c;p=matches%2FMCTX3420.git diff --git a/server/control.c b/server/control.c index 12e340a..1f33eea 100644 --- a/server/control.c +++ b/server/control.c @@ -1,14 +1,19 @@ +/** + * @file control.c + * @brief Handles all client control requests (admin/actuator related) + */ #include "common.h" #include "control.h" + /** * Handles control of the actuators. - */ -void ActuatorHandler(FCGIContext *context, int id, const char *set_value) { + * +void ActuatorHandler(FCGIContext *context, ActuatorId id, const char *set_value) { char *ptr; switch(id) { //Add new actuators here - case ACT_PREG: //Suppose is pressure regulator. 0-700 input (kPa) + case ACT_PRESSURE: //Suppose is pressure regulator. 0-700 input (kPa) { int value = strtol(set_value, &ptr, 10); if (*ptr == '\0' && value >= 0 && value <= 700) { @@ -33,7 +38,7 @@ void ActuatorHandler(FCGIContext *context, int id, const char *set_value) { FCGI_JSONValue("\"Solenoid 1 turned %s!\"", state); FCGI_EndJSON(); } else { - FCGI_RejectJSON(context); + FCGI_RejectJSON(context, "Invalid actuator value specified"); } } break; default: @@ -41,6 +46,7 @@ void ActuatorHandler(FCGIContext *context, int id, const char *set_value) { STATUS_ERROR, "Invalid actuator id specified."); } } +*/ /** * System control handler. This covers control over all aspects of the system. @@ -53,7 +59,7 @@ void Control_Handler(FCGIContext *context, char *params) { const char *action = NULL, *set_value = NULL; bool force = false; char *ptr; - int id = ACT_NONE; + int id = -1; while ((params = FCGI_KeyPair(params, &key, &value))) { if (!strcmp(key, "action")) @@ -71,9 +77,10 @@ void Control_Handler(FCGIContext *context, char *params) { set_value = value; } } + Log(LOGDEBUG, "Id %d", id); // to stop compiler complaining for now if (action == NULL) { //Must have an action - FCGI_RejectJSON(context); + FCGI_RejectJSON(context, "No action specified"); } else if (!strcmp(action, "start")) { FCGI_BeginControl(context, force); } else if (!strcmp(action, "stop")) { //Don't require control key to stop... @@ -91,8 +98,9 @@ void Control_Handler(FCGIContext *context, char *params) { 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 + { +// ActuatorHandler(context, id, set_value); } } }