X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=server%2Ffastcgi.c;h=4b7f13729900b6dd09f45aaf05d700600ede19f6;hb=7518a87e619085f9622d268dd7130726b5947dea;hp=bddac21383a1e4df1da6ecfb95d92afdb459f7a9;hpb=91c67a417caaeeedb38b385d27b927344872abe2;p=matches%2FMCTX3420.git diff --git a/server/fastcgi.c b/server/fastcgi.c index bddac21..4b7f137 100644 --- a/server/fastcgi.c +++ b/server/fastcgi.c @@ -8,7 +8,6 @@ #include #include -#include #include "common.h" #include "sensor.h" @@ -35,9 +34,43 @@ struct FCGIContext { * TODO - Consider adding info about available sensors and actuators (eg capabilities)? */ static void IdentifyHandler(FCGIContext *context, char *params) { + bool identSensors = false, identActuators = false; + const char *key, *value; + int i; + + while ((params = FCGI_KeyPair(params, &key, &value))) { + if (!strcmp(key, "sensors")) { + identSensors = !identSensors; + } else if (!strcmp(key, "actuators")) { + identActuators = !identActuators; + } + } + FCGI_BeginJSON(context, STATUS_OK); FCGI_JSONPair("description", "MCTX3420 Server API (2013)"); FCGI_JSONPair("build_date", __DATE__ " " __TIME__); + if (identSensors) { + FCGI_JSONKey("sensors"); + FCGI_JSONValue("{\n\t\t"); + for (i = 0; i < NUMSENSORS; i++) { + if (i > 0) { + FCGI_JSONValue(",\n\t\t"); + } + FCGI_JSONValue("\"%d\" : \"%s\"", i, g_sensor_names[i]); + } + FCGI_JSONValue("\n\t}"); + } + if (identActuators) { + FCGI_JSONKey("actuators"); + FCGI_JSONValue("{\n\t\t"); + for (i = 0; i < NUMACTUATORS; i++) { + if (i > 0) { + FCGI_JSONValue(",\n\t\t"); + } + FCGI_JSONValue("\"%d\" : \"%s\"", i, g_actuator_names[i]); + } + FCGI_JSONValue("\n\t}"); + } FCGI_EndJSON(); }