MAJOR refactoring of Sensors 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
12 /** 
13  * Maximum number of sensors program can be compiled with
14  * (If you get an error "Increase SENSORS_MAX from %d" this is what it refers to)
15  */
16 #define SENSORS_MAX 10
17 extern int g_num_sensors; // in sensor.c
18
19
20 /** Structure to define the warning and error thresholds of the sensors **/
21 typedef struct
22 {
23         /** Maximum safe value **/
24         double max_error;
25         /** Minimum safe value **/
26         double min_error;
27         /** Maximum value before a warning is reported **/
28         double max_warn;
29         /** Minimum value before a warning is reported **/
30         double min_warn;
31 } SensorThreshold;
32
33 /** Function pointer for sensor reading **/
34 typedef bool (*ReadFn)(int, double * val);
35 /** Function pointer for sensor initialisation **/
36 typedef bool (*InitFn)(const char *, int);
37 /** Function pointer for sensor cleanup **/
38 typedef bool (*CleanFn)(int);
39
40 /** Structure to represent a sensor **/
41 typedef struct
42 {
43         /** ID number of the sensor **/
44         int id;
45         /** User defined ID number **/
46         int user_id;
47         /** DataFile to store sensor values in **/
48         DataFile data_file;
49         /** Indicates whether the Sensor is active or not **/
50         bool activated;
51         /** Thread the Sensor is running in **/
52         pthread_t thread;
53         /** Function to read the sensor **/
54         ReadFn read;
55         /** Function to initialise the sensor **/
56         InitFn init;
57         /** Function to cleanup the sensor **/
58         CleanFn cleanup;
59         /** Human readable name of the sensor **/
60         const char * name;
61         /** Thresholds on the sensor **/
62         SensorThreshold thresholds;
63         
64 } Sensor;
65
66
67
68 extern void Sensor_Init(); // One off initialisation of *all* sensors
69 extern void Sensor_Cleanup(); // Cleanup all sensors
70
71 extern void Sensor_SetModeAll(ControlModes mode, void * arg);
72 extern void Sensor_SetMode(Sensor * s, ControlModes mode, void * arg);
73
74 extern void * Sensor_Loop(void * args); // Main loop for a thread that handles a Sensor
75 extern bool Sensor_Read(Sensor * s, DataPoint * d); // Read a single DataPoint, indicating if it has changed since the last one
76 extern void Sensor_CheckData(Sensor * s, double value); // Check a DataPoint
77 extern Sensor * Sensor_Identify(const char * str); // Identify a Sensor from a string
78
79 extern void Sensor_Handler(FCGIContext *context, char * params); // Handle a FCGI request for Sensor data
80
81 extern const char * Sensor_GetName(int id);
82
83
84
85 #endif //_SENSOR_H
86
87

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