-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatamgr.h
71 lines (57 loc) · 2.39 KB
/
datamgr.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* \author Kerem Okyay
*/
#ifndef DATAMGR_H_
#define DATAMGR_H_
#include <stdlib.h>
#include <stdio.h>
#include "config.h"
#include "sbuffer.h"
/*
* Use ERROR_HANDLER() for handling memory allocation problems, invalid sensor IDs, non-existing files, etc.
*/
#define ERROR_HANDLER(condition, ...) do { \
if (condition) { \
printf("\nError: in %s - function %s at line %d: %s\n", __FILE__, __func__, __LINE__, __VA_ARGS__); \
exit(EXIT_FAILURE); \
} \
} while(0)
/**
* This method holds the core functionality of your datamgr. It takes in 2 file pointers to the sensor files and parses them.
* When the method finishes all data should be in the internal pointer list and all log messages should be printed to stderr.
* \param fp_sensor_map file pointer to the map file
* \param fp_sensor_data file pointer to the binary data file
*/
void datamgr_parse_sensor_data(FILE *fp_sensor_map, sbuffer_t ** sbuffer);
/**
* This method should be called to clean up the datamgr, and to free all used memory.
* After this, any call to datamgr_get_room_id, datamgr_get_avg, datamgr_get_last_modified or datamgr_get_total_sensors will not return a valid result
*/
void datamgr_free();
/**
* Gets the room ID for a certain sensor ID
* Use ERROR_HANDLER() if sensor_id is invalid
* \param sensor_id the sensor id to look for
* \return the corresponding room id
*/
uint16_t datamgr_get_room_id(sensor_id_t sensor_id);
/**
* Gets the running AVG of a certain senor ID (if less then RUN_AVG_LENGTH measurements are recorded the avg is 0)
* Use ERROR_HANDLER() if sensor_id is invalid
* \param sensor_id the sensor id to look for
* \return the running AVG of the given sensor
*/
sensor_value_t datamgr_get_avg(sensor_id_t sensor_id);
/**
* Returns the time of the last reading for a certain sensor ID
* Use ERROR_HANDLER() if sensor_id is invalid
* \param sensor_id the sensor id to look for
* \return the last modified timestamp for the given sensor
*/
time_t datamgr_get_last_modified(sensor_id_t sensor_id);
/**
* Return the total amount of unique sensor ID's recorded by the datamgr
* \return the total amount of sensors
*/
int datamgr_get_total_sensors();
#endif //DATAMGR_H_