Fix g_sensor_names (enum out of order) and add identification
[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 /** Number of data points to keep in sensor buffers **/
10 #define SENSOR_DATABUFSIZ 10
11
12 #define SENSOR_QUERYBUFSIZ 10
13
14 /** Number of sensors **/
15 #define NUMSENSORS 4
16
17 typedef enum SensorId{
18         ANALOG_TEST0,
19         ANALOG_TEST1,
20         DIGITAL_TEST0,
21         DIGITAL_TEST1
22 } SensorId;
23
24 extern const char * g_sensor_names[NUMSENSORS];
25
26 /** Structure to represent data recorded by a sensor at an instant in time **/
27 typedef struct
28 {
29         /** Time at which data was taken **/
30         double time_stamp; 
31         /** Value of data **/
32         double value;
33 } DataPoint;
34
35 /** Structure to represent a sensor **/
36 typedef struct
37 {
38         /** ID number of the sensor **/
39         SensorId id;
40         /** Buffer to store data from the sensor **/
41         DataPoint buffer[SENSOR_DATABUFSIZ];
42         /** Index of last point written in the data buffer **/
43         int write_index;
44         /** Number of points read **/
45         long points_read;
46         /** Binary file to write data into when buffer is full **/
47         FILE * file;
48         /** Thread running the sensor **/
49         pthread_t thread;
50         /** Mutex to protect access to stuff **/
51         pthread_mutex_t mutex;
52
53         
54 } Sensor;
55
56
57
58
59 extern void Sensor_Spawn(); // Initialise sensor
60 extern void Sensor_Join(); //Join sensor threads
61 extern void * Sensor_Main(void * args); // main loop for sensor thread; pass a Sensor* cast to void*
62
63 extern int Sensor_Query(Sensor * s, DataPoint * buffer, int bufsiz); // fill buffer with sensor data
64
65 extern void Sensor_Handler(FCGIContext *context, char * params);
66
67
68 #endif //_SENSOR_H
69

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