Update Titlepage with links to individual sections
[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 #include "device.h"
11
12
13 /** 
14  * Maximum number of sensors program can be compiled with
15  * (If you get an error "Increase SENSORS_MAX from %d" this is what it refers to)
16  */
17 #define SENSORS_MAX 10
18 extern int g_num_sensors; // in sensor.c
19
20
21 /** Structure to define the warning and error thresholds of the sensors **/
22 //TODO: Replace with a call to an appropriate "Sanity" function? (see the actuator code)
23 typedef struct
24 {
25         /** Maximum safe value **/
26         double max_error;
27         /** Minimum safe value **/
28         double min_error;
29         /** Maximum value before a warning is reported **/
30         double max_warn;
31         /** Minimum value before a warning is reported **/
32         double min_warn;
33 } SensorThreshold;
34
35 /** Structure to represent a sensor **/
36 typedef struct
37 {
38         /** ID number of the sensor **/
39         int id;
40         /** User defined ID number **/
41         int user_id;
42         /** DataFile to store sensor values in **/
43         DataFile data_file;
44         /** Indicates whether the Sensor is active or not **/
45         bool activated;
46         /** Thread the Sensor is running in **/
47         pthread_t thread;
48         /** Function to read the sensor **/
49         ReadFn read;
50         /** Function to initialise the sensor **/
51         InitFn init;
52         /** Function to cleanup the sensor **/
53         CleanFn cleanup;
54         /** Function to sanity check the sensor readings **/
55         SanityFn sanity;
56         /** Human readable name of the sensor **/
57         const char * name;
58         /** Sampling rate **/
59         struct timespec sample_time;
60         /** Number of averages per sample **/
61         int averages;
62         /** Current data **/
63         DataPoint current_data;
64
65         /** Summed data **/
66         DataPoint averaged_data;
67         /** Number of points read so far before applying average **/
68         int num_read;
69
70
71         
72 } Sensor;
73
74
75
76 extern void Sensor_Init(); // One off initialisation of *all* sensors
77 extern void Sensor_Cleanup(); // Cleanup all sensors
78
79 extern void Sensor_SetModeAll(ControlModes mode, void * arg);
80 extern void Sensor_SetMode(Sensor * s, ControlModes mode, void * arg);
81
82 extern void * Sensor_Loop(void * args); // Main loop for a thread that handles a Sensor
83 extern bool Sensor_Read(Sensor * s, DataPoint * d); // Read a single DataPoint, indicating if it has changed since the last one
84 extern Sensor * Sensor_Identify(const char * str); // Identify a Sensor from a string
85
86 extern void Sensor_Handler(FCGIContext *context, char * params); // Handle a FCGI request for Sensor data
87
88 extern DataPoint Sensor_LastData(int id);
89
90 extern const char * Sensor_GetName(int id);
91
92
93
94 #endif //_SENSOR_H
95
96

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