-/**
- * Handles control of the actuators.
- */
-void ActuatorHandler(FCGIContext *context, ActuatorId id, const char *set_value) {
- char *ptr;
-
- switch(id) { //Add new actuators here
- 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) {
- FCGI_BeginJSON(context, STATUS_OK);
- FCGI_JSONKey("description");
- FCGI_JSONValue("\"Set pressure to %d kPa!\"", value);
- FCGI_EndJSON();
- } else {
- FCGI_RejectJSONEx(context,
- STATUS_ERROR, "Invalid pressure specified.");
- }
- } break;
- case ACT_SOLENOID1:
- {
- int value = strtol(set_value, &ptr, 10);
- if (*ptr == '\0') {
- const char *state = "off";
- if (value)
- state = "on";
- FCGI_BeginJSON(context, STATUS_OK);
- FCGI_JSONKey("description");
- FCGI_JSONValue("\"Solenoid 1 turned %s!\"", state);
- FCGI_EndJSON();
- } else {
- FCGI_RejectJSON(context, "Invalid actuator value specified");
- }
- } break;
- default:
- FCGI_RejectJSONEx(context,
- STATUS_ERROR, "Invalid actuator id specified.");
- }
+typedef enum Mode {
+ START,
+ PAUSE,
+ RESUME,
+ STOP
+} Mode;
+
+typedef struct ControlData {
+ ControlState state;
+ pthread_mutex_t mutex;
+ struct timeval start_time;
+} ControlData;
+
+ControlData g_controls = {STATE_STOPPED, PTHREAD_MUTEX_INITIALIZER, {0}};
+
+static bool ExperimentExists(const char *experiment_name) {
+ FILE *fp = fopen(experiment_name, "r");
+ if (!fp)
+ return false;
+ fclose(fp);
+ return true;