+
+/** Array of sensor threshold structures defining the safety values of each sensor**/
+const SensorThreshold thresholds[NUMSENSORS]= {
+ //Max Safety, Min safety, Max warning, Min warning
+ {1,-1,1,-1}, // ANALOG_TEST0
+ {500,0,499,0}, // ANALOG_TEST1
+ {5,-5,4,-4}, // ANALOG_FAIL0
+ {1,0,1,0}, // DIGITAL_TEST0
+ {1,0,1,0}, // DIGITAL_TEST1
+ {1,0,1,0} // DIGITAL_FAIL0
+};
+
+/** Human readable names for the sensors **/
+const char * g_sensor_names[NUMSENSORS] = {
+ "analog_test0", "analog_test1",
+ "analog_fail0", "digital_test0",
+ "digital_test1", "digital_fail0"
+};
+
+/**
+ * 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;
+ }
+}
+