forked from danned/Weather-station
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmem.h
142 lines (120 loc) · 4.72 KB
/
mem.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/************************************************************************/
/* Memory module */
/* This is the declaration of the memory module for the project */
/* This module will perform all memory specific code */
/* Uses a single liked list data structure and requires only calls to */
/* add and get data. Will set flag and remove oldest entry when */
/* memory is full */
/************************************************************************/
/************************************************************************/
/* Type definitions crucial for memory module */
/************************************************************************/
#ifndef _MEM_H_
#define _MEM_H_
typedef struct {
int date : 5;
int month : 4;
int year : 7;
}datestamp_t;
/* datastructures for temperature start */
/*typedef struct {
short min;
short avg;
short max;
short count; // this might be removed
}mem_temp_t;
*/
typedef struct node{
short min;
short avg;
short max;
datestamp_t date;
struct node *next;
}mem_temp_t;
/* temperature end */
/* datastructures for air pressure start */
/*typedef struct{
}pres_value_t;
*/
typedef struct {
char day;
char count;
unsigned int max[7];
unsigned int avg[7];
unsigned int min[7];
}mem_air_pres_t;
/* air pressure end */
typedef struct{
char MEM_FULL : 1;
char MEM_ERROR : 1;
}mem_status_t;
typedef struct{
mem_temp_t *temp;
char temp_count;
float cur_temp;
mem_air_pres_t pres;
mem_status_t status;
}mem_t;
//extern mem_temp_t *mem_root_pr;
extern mem_t mem;
/************************************************************************/
/* Will initialize the datastructure. Call this method only once */
/************************************************************************/
int MEM_init( void );
/************************************************************************/
/* Saves new value at first place in data structure for temp */
/* If there are no more memory, it will remove oldest entry */
/* try again. */
/* Return value: */
/* 1 on success, no overwrite */
/* 1 on success, old value overwritten */
/* -1 on error */
/************************************************************************/
int MEM_saveTemp(float new_value_f);
/************************************************************************/
/* Updates pressure values of current day */
/* if new meas is less then saved min. Min val is updated */
/* same for max. Avg will hold sum of values until new day event */
/* count holds number of measurements */
/* 0 Success. No new min, max saved */
/* 1 Success. new min saved */
/* 2 Success. New Max saved */
/* 3 Success. New Max and Min saved */
/* -1 fail. no value TODO: implement */
/************************************************************************/
int MEM_savePres(unsigned int new_value_u32);
/************************************************************************/
/* Updates pressure and temp values of current day */
/* calls MEM_savePress and MEM_saveTemp */
/* 1 only temp value saved */
/* 2 only pressure value saved */
/* 3 Success. pressure and temp value saved */
/* -1 fail. unable to save any value */
/************************************************************************/
int MEM_save(float new_temp_f, unsigned int new_pres_u32);
/************************************************************************/
/* Removes oldest entry of list */
/* Returns 1 if success. */
/* -1 = unable to remove entry */
/************************************************************************/
int MEM_remove();
/************************************************************************/
/* Adds new day to linked list */
/* Returns 1 if success. */
/* Returns -1 if fail */
/************************************************************************/
int MEM_newDay();
/************************************************************************/
/* Fills memory with random data */
/* Returns number of days added */
/************************************************************************/
int MEM_fill(void);
/************************************************************************/
/* Memory Test */
/* Returns 1 if success. */
/* Returns -2 if number of elements is not equal to expected size */
/* Returns -4 if temp is not saved properly */
/* Returns -5 if pressure is not saved properly */
/************************************************************************/
int MEM_test(void);
#endif // _MEM_H_