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

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