8ae56609d9c63b5a8d217d809106722c86400fec
[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 /** Size of the query buffer. @see Sensor_Handler **/
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 /** Human readable names for the sensors **/
25 extern const char * g_sensor_names[NUMSENSORS];
26
27 /** Structure to represent data recorded by a sensor at an instant in time **/
28 typedef struct
29 {
30         /** Time at which data was taken **/
31         double time_stamp; 
32         /** Value of data **/
33         double value;
34 } DataPoint;
35
36 /** Structure to represent a sensor **/
37 typedef struct
38 {
39         /** ID number of the sensor **/
40         SensorId id;
41         /** Buffer to store data from the sensor **/
42         DataPoint buffer[SENSOR_DATABUFSIZ];
43         /** Index of last point written in the data buffer **/
44         int write_index;
45         /** Number of points read **/
46         long points_read;
47         /** Binary file to write data into when buffer is full **/
48         FILE * file;
49         /** Thread running the sensor **/
50         pthread_t thread;
51         /** Mutex to protect access to stuff **/
52         pthread_mutex_t mutex;
53
54         
55 } Sensor;
56
57
58
59
60 extern void Sensor_Spawn(); // Initialise sensor
61 extern void Sensor_Join(); //Join sensor threads
62 extern void * Sensor_Main(void * args); // main loop for sensor thread; pass a Sensor* cast to void*
63
64 extern int Sensor_Query(Sensor * s, DataPoint * buffer, int bufsiz); // fill buffer with sensor data
65
66 extern void Sensor_Handler(FCGIContext *context, char * params);
67
68 #endif //_SENSOR_H
69

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