Refactor Sensor related code; introduce seperate functions for dealing with DataPoints
[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 #include "data.h"
10
11 /** Number of sensors **/
12 #define NUMSENSORS 4
13
14 /** Safety Values for sensors **/
15 //TODO: Probably better to use an array instead
16 #define ANALOG_TEST0_SAFETY 1000
17 #define ANALOG_TEST1_SAFETY 1000
18 #define DIGITAL_TEST0_SAFETY 1
19 #define DIGITAL_TEST1_SAFETY 1
20
21
22 typedef enum SensorId 
23 {
24         ANALOG_TEST0,
25         ANALOG_TEST1,
26         DIGITAL_TEST0,
27         DIGITAL_TEST1
28 } SensorId;
29
30
31
32 /** Human readable names for the sensors **/
33 extern const char * g_sensor_names[NUMSENSORS];
34
35
36 /** Structure to represent a sensor **/
37 typedef struct
38 {
39         /** ID number of the sensor **/
40         SensorId id;
41         /** DataFile to store sensor values in **/
42         DataFile data_file;
43         /** Indicates whether the Sensor should record data **/
44         bool record_data;
45         /** Thread the Sensor is running in **/
46         pthread_t thread;
47         /** Most recently recorded data **/
48         DataPoint newest_data;
49
50         
51 } Sensor;
52
53
54 extern void Sensor_Init(); // One off initialisation of *all* sensors
55
56 extern void Sensor_StartAll(const char * experiment_name); // Start all Sensors recording data
57 extern void Sensor_StopAll(); // Stop all Sensors recording data
58 extern void Sensor_Start(Sensor * s, const char * experiment_name); // Start a sensor recording datas
59 extern void Sensor_Stop(Sensor * s); // Stop a Sensor from recording data
60
61
62 extern void * Sensor_Loop(void * args); // Main loop for a thread that handles a Sensor
63 extern bool Sensor_Read(Sensor * s, DataPoint * d); // Read a single DataPoint, indicating if it has changed since the last one
64 extern void Sensor_CheckData(SensorId id, DataPoint * d); // Check a DataPoint
65 extern Sensor * Sensor_Identify(const char * str); // Identify a Sensor from a string Id
66
67 extern void Sensor_Handler(FCGIContext *context, char * params); // Handle a FCGI request for Sensor data
68
69
70
71 #endif //_SENSOR_H
72

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