3 * @brief Handles all client control requests (admin/actuator related)
8 const char * g_actuator_names[NUMACTUATORS] = {
9 "Pressure regulator", "Solenoid 1"
13 * Handles control of the actuators.
15 void ActuatorHandler(FCGIContext *context, ActuatorId id, const char *set_value) {
18 switch(id) { //Add new actuators here
19 case ACT_PRESSURE: //Suppose is pressure regulator. 0-700 input (kPa)
21 int value = strtol(set_value, &ptr, 10);
22 if (*ptr == '\0' && value >= 0 && value <= 700) {
23 FCGI_BeginJSON(context, STATUS_OK);
24 FCGI_JSONKey("description");
25 FCGI_JSONValue("\"Set pressure to %d kPa!\"", value);
28 FCGI_RejectJSONEx(context,
29 STATUS_ERROR, "Invalid pressure specified.");
34 int value = strtol(set_value, &ptr, 10);
36 const char *state = "off";
39 FCGI_BeginJSON(context, STATUS_OK);
40 FCGI_JSONKey("description");
41 FCGI_JSONValue("\"Solenoid 1 turned %s!\"", state);
44 FCGI_RejectJSON(context, "Invalid actuator value specified");
48 FCGI_RejectJSONEx(context,
49 STATUS_ERROR, "Invalid actuator id specified.");
54 * System control handler. This covers control over all aspects of the system.
55 * E.g: Actuators, system commands (start/stop experiment/recording) etc
56 * @param context The context to work in
57 * @param params The input parameters
59 void Control_Handler(FCGIContext *context, char *params) {
60 const char *action, *key = "", *mode = "", *name = "";
63 FCGIValue values[5] = {
64 {"action", &action, FCGI_REQUIRED(FCGI_STRING_T)},
65 {"key", &key, FCGI_STRING_T},
66 {"force", &force, FCGI_BOOL_T},
67 {"mode", &mode, FCGI_STRING_T},
68 {"name", &name, FCGI_STRING_T}
71 if (!FCGI_ParseRequest(context, params, values, 5))
74 if (!strcmp(action, "gain")) {
75 FCGI_BeginControl(context, force);
77 if (!FCGI_HasControl(context, key)) {
78 FCGI_RejectJSONEx(context,
79 STATUS_UNAUTHORIZED, "Invalid control key specified.");
81 } else if (!strcmp(action, "release")) {
82 FCGI_EndControl(context);
83 } else if (!strcmp(action, "experiment")) {
84 if (!strcmp(mode, "start")) {
85 FCGI_BeginJSON(context, STATUS_OK);
86 FCGI_JSONPair("description", mode);
88 } else if (!strcmp(mode, "pause")) {
89 FCGI_BeginJSON(context, STATUS_OK);
90 FCGI_JSONPair("description", mode);
92 } else if (!strcmp(mode, "stop")) {
93 FCGI_BeginJSON(context, STATUS_OK);
94 FCGI_JSONPair("description", mode);
97 FCGI_RejectJSON(context, "Unknown experiment mode specified");
100 FCGI_RejectJSON(context, "Unknown action specified");