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

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