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

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