Merge remote-tracking branch 'upstream/master'
[matches/MCTX3420.git] / server / sensor.h
1
2 /**
3  * @file sensor.h
4  * @purpose Declarations for sensor thread related stuff
5  */
6
7
8
9 #ifndef _SENSOR_H
10 #define _SENSOR_H
11
12 #include "common.h"
13
14 /** Number of data points to keep in sensor buffers **/
15 #define SENSOR_DATABUFSIZ 10
16
17 /** Number of sensors **/
18 #define NUMSENSORS 1
19
20 #define FILENAMESIZE 10
21
22 /** Structure to represent data recorded by a sensor at an instant in time **/
23 typedef struct
24 {
25         /** Time at which data was taken **/
26         float time;
27         /** Value of data **/
28         float value;
29 } DataPoint;
30
31 /** Structure to represent a sensor **/
32 typedef struct
33 {
34         /** ID number of the sensor **/
35         enum {SENSOR_TEST0=0, SENSOR_TEST1=1} id;
36         /** Buffer to store data from the sensor **/
37         DataPoint buffer[SENSOR_DATABUFSIZ];
38         /** Index of last point written in the data buffer **/
39         int write_index;
40         /** Offset position in binary file for query thread to read from**/
41         int read_offset;
42         /** File to write data into when buffer is full **/
43         char filename[FILENAMESIZE];
44         /** Thread running the sensor **/
45         pthread_t thread;
46         /** Mutex to protect access to stuff **/
47         pthread_mutex_t mutex;
48
49         
50 } Sensor;
51
52 /** Array of Sensors **/
53 extern Sensor g_sensors[];
54
55 extern void Sensor_Init(Sensor * s, int id); // Initialise sensor
56 extern void * Sensor_Main(void * args); // main loop for sensor thread; pass a Sensor* cast to void*
57
58
59 #endif //_SENSOR_H
60

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