Merge pull request #26 from jtanx/master
[matches/MCTX3420.git] / server / sensor.h
1 /**
2  * @file sensor.h
3  * @brief Declarations for sensor thread related stuff
4  */
5
6
7 #ifndef _SENSOR_H
8 #define _SENSOR_H
9
10 /** Number of data points to keep in sensor buffers **/
11 #define SENSOR_DATABUFSIZ 10
12
13 #define SENSOR_QUERYBUFSIZ 10
14
15 /** Number of sensors **/
16 #define NUMSENSORS 4
17
18
19 /** Structure to represent data recorded by a sensor at an instant in time **/
20 typedef struct
21 {
22         /** Time at which data was taken **/
23         double time_stamp; 
24         /** Value of data **/
25         double value;
26 } DataPoint;
27
28 /** Structure to represent a sensor **/
29 typedef struct
30 {
31         /** ID number of the sensor **/
32         enum {ANALOG_TEST0=2, ANALOG_TEST1=0, DIGITAL_TEST0=1, DIGITAL_TEST1=3} id;
33         /** Buffer to store data from the sensor **/
34         DataPoint buffer[SENSOR_DATABUFSIZ];
35         /** Index of last point written in the data buffer **/
36         int write_index;
37         /** Number of points read **/
38         long points_read;
39         /** Binary file to write data into when buffer is full **/
40         FILE * file;
41         /** Thread running the sensor **/
42         pthread_t thread;
43         /** Mutex to protect access to stuff **/
44         pthread_mutex_t mutex;
45
46         
47 } Sensor;
48
49
50
51
52 extern void Sensor_Spawn(); // Initialise sensor
53 extern void Sensor_Join(); //Join sensor threads
54 extern void * Sensor_Main(void * args); // main loop for sensor thread; pass a Sensor* cast to void*
55
56 extern int Sensor_Query(Sensor * s, DataPoint * buffer, int bufsiz); // fill buffer with sensor data
57
58 extern void Sensor_Handler(FCGIContext *context, char * params);
59
60
61 #endif //_SENSOR_H
62

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