Merge pull request #85 from Callum-/dilatometer
[matches/MCTX3420.git] / server / data.h
1 /**
2  * @file data.h
3  * @brief Declaration of data handling functions; saving, loading, displaying, selecting.
4  */
5
6 #ifndef _DATAPOINT_H
7 #define _DATAPOINT_H
8
9 /** Size to use for DataPoint buffers (TODO: Optimise) **/
10 #define DATA_BUFSIZ 10 
11
12
13 #include "common.h"
14
15 /** Structure to represent a time, value DataPoint **/
16 typedef struct
17 {
18         /** Time at which data was taken **/
19         double time_stamp; 
20         /** Value of data **/
21         double value;
22 } DataPoint;
23
24 /** Enum of output format types for DataPoints **/
25 typedef enum
26 {
27         JSON, /** JSON data */
28         TSV /** Tab seperated vector */
29 } DataFormat;
30
31 /** 
32  * Structure to represent a collection of data. 
33  * All operations involving this structure are thread safe.
34  * NOTE: It is essentially a wrapper around a binary file.
35  */
36 typedef struct
37 {
38         FILE * file; /** file pointer */
39         int num_points; /** Number of DataPoints in the file */
40         char * filename; /** Name of the file */
41         pthread_mutex_t mutex; /** Mutex around num_points */
42 } DataFile;
43
44
45 extern void Data_Init(DataFile * df);  // One off initialisation of DataFile
46 extern void Data_Open(DataFile * df, const char * filename); // Open data file
47 extern void Data_Close(DataFile * df);
48 extern void Data_Save(DataFile * df, DataPoint * buffer, int amount); // Save data to file
49 extern int Data_Read(DataFile * df, DataPoint * buffer, int index, int amount); // Retrieve data from file
50 extern void Data_PrintByIndexes(DataFile * df, int start_index, int end_index, DataFormat format);  // Print data buffer
51 extern void Data_PrintByTimes(DataFile * df, double start_time, double end_time, DataFormat format); // Print data between time values
52 extern int Data_FindByTime(DataFile * df, double time_stamp, DataPoint * closest); // Find index of DataPoint with the closest timestamp to that given
53 extern double Data_Calibrate(double value, double x[], double y[], int size);
54
55 extern void Data_Handler(DataFile * df, FCGIValue * start, FCGIValue * end, DataFormat format, double current_time); // Helper; given FCGI params print data
56 extern DataFormat Data_GetFormat(FCGIValue * fmt); // Helper; convert human readable format string to DataFormat
57
58 #endif //_DATAPOINT_H

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