Add semi working control code
[matches/MCTX3420.git] / server / sensor.h
1 /**
2  * @file sensor.h
3  * @brief Declarations for sensor thread related stuff
4  */
5
6 #ifndef _SENSOR_H
7 #define _SENSOR_H
8
9 #include "data.h"
10
11 /** Number of sensors **/
12 #define NUMSENSORS 6 
13
14 /** Sensor ids - there should be correspondence with the names in g_sensor_names **/
15 typedef enum SensorId 
16 {
17         ANALOG_TEST0,
18         ANALOG_TEST1,
19         ANALOG_FAIL0,
20         DIGITAL_TEST0,
21         DIGITAL_TEST1,
22         DIGITAL_FAIL0
23 } SensorId;
24
25 /** Human readable names for the sensors **/
26 extern const char * g_sensor_names[NUMSENSORS];
27
28 /** Structure to represent a sensor **/
29 typedef struct
30 {
31         /** ID number of the sensor **/
32         SensorId id;
33         /** DataFile to store sensor values in **/
34         DataFile data_file;
35         /** Indicates whether the Sensor should record data **/
36         bool record_data;
37         /** Thread the Sensor is running in **/
38         pthread_t thread;
39         /** Most recently recorded data **/
40         DataPoint newest_data;
41 } Sensor;
42
43 // Structure to define the warning and error thresholds of the sensors
44 typedef struct
45 {
46         double max_error;
47         double min_error;
48         double max_warn;
49         double min_warn;
50 } SensorThreshold;
51
52 extern void Sensor_Init(); // One off initialisation of *all* sensors
53
54 extern void Sensor_StartAll(const char * experiment_name); // Start all Sensors recording data
55 extern void Sensor_StopAll(); // Stop all Sensors recording data
56 extern void Sensor_Start(Sensor * s, const char * experiment_name); // Start a sensor recording datas
57 extern void Sensor_Stop(Sensor * s); // Stop a Sensor from recording data
58 extern void Sensor_Pause(Sensor *s);
59 extern void Sensor_Resume(Sensor *s);
60 extern void Sensor_PauseAll();
61 extern void Sensor_ResumeAll();
62
63 extern void * Sensor_Loop(void * args); // Main loop for a thread that handles a Sensor
64 extern bool Sensor_Read(Sensor * s, DataPoint * d); // Read a single DataPoint, indicating if it has changed since the last one
65 extern void Sensor_CheckData(SensorId id, double value); // Check a DataPoint
66 extern Sensor * Sensor_Identify(const char * str); // Identify a Sensor from a string Id
67
68 extern void Sensor_Handler(FCGIContext *context, char * params); // Handle a FCGI request for Sensor data
69
70 #endif //_SENSOR_H
71
72

UCC git Repository :: git.ucc.asn.au