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 1
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         struct timeval time_stamp; //TODO: Consider; use float instead?
24         /** Value of data **/
25         float value;
26 } DataPoint;
27
28 /** Structure to represent a sensor **/
29 typedef struct
30 {
31         /** ID number of the sensor **/
32         enum {SENSOR_TEST0=0, SENSOR_TEST1=1} 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         /** Offset position in binary file for query thread to read from**/
38         int read_offset;
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 extern void Sensor_Spawn(); // Initialise sensor
52 extern void Sensor_Join(); //Join sensor threads
53 extern void * Sensor_Main(void * args); // main loop for sensor thread; pass a Sensor* cast to void*
54
55 extern int Sensor_Query(Sensor * s, DataPoint * buffer, int bufsiz); // fill buffer with sensor data
56
57 extern void Sensor_Handler(FCGIContext *context, char * params);
58
59
60 #endif //_SENSOR_H
61

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