+ * One off initialisation of *all* sensors
+ */
+void Sensor_Init()
+{
+ for (int i = 0; i < NUMSENSORS; ++i)
+ {
+ g_sensors[i].id = i;
+ Data_Init(&(g_sensors[i].data_file));
+ g_sensors[i].record_data = false;
+ }
+}
+
+/**
+ * Start a Sensor recording DataPoints
+ * @param s - The Sensor to start
+ * @param experiment_name - Prepended to DataFile filename
+ */
+void Sensor_Start(Sensor * s, const char * experiment_name)
+{
+ // Set filename
+ char filename[BUFSIZ];
+ if (sprintf(filename, "%s_%d", experiment_name, s->id) >= BUFSIZ)
+ {
+ Fatal("Experiment name \"%s\" too long (>%d)", experiment_name, BUFSIZ);
+ }
+
+ Log(LOGDEBUG, "Sensor %d with DataFile \"%s\"", s->id, filename);
+ // Open DataFile
+ Data_Open(&(s->data_file), filename);
+
+ s->record_data = true; // Don't forget this!
+
+ // Create the thread
+ pthread_create(&(s->thread), NULL, Sensor_Loop, (void*)(s));
+}
+
+/**
+ * Stop a Sensor from recording DataPoints. Blocks until it has stopped.
+ * @param s - The Sensor to stop
+ */
+void Sensor_Stop(Sensor * s)
+{
+ // Stop
+ if (s->record_data)
+ {
+ s->record_data = false;
+ pthread_join(s->thread, NULL); // Wait for thread to exit
+ Data_Close(&(s->data_file)); // Close DataFile
+ s->newest_data.time_stamp = 0;
+ s->newest_data.value = 0;
+ }
+}
+
+/**
+ * Stop all Sensors
+ */
+void Sensor_StopAll()
+{
+ for (int i = 0; i < NUMSENSORS; ++i)
+ Sensor_Stop(g_sensors+i);
+}
+
+/**
+ * Start all Sensors
+ */
+void Sensor_StartAll(const char * experiment_name)
+{
+ for (int i = 0; i < NUMSENSORS; ++i)
+ Sensor_Start(g_sensors+i, experiment_name);
+}
+
+
+/**
+ * Checks the sensor data for unsafe or unexpected results