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

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