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

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