-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffer_pile.h
More file actions
77 lines (66 loc) · 2.17 KB
/
buffer_pile.h
File metadata and controls
77 lines (66 loc) · 2.17 KB
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
/************************************************
This is a library to add a buffer "pile" of data.
The aim is to allow mqtt interruption for a while
without loss of datas
It is a buffer "first in is first out"
If buffer is full, oldest data is replaced by new one
You must define Ecoset Structure to match datas you want to store and modify read and add function
P.Chaumeil 2024
************************************************/
#ifndef BUFFER_PILE_h
#define BUFFER_PILE_h
#define NUM_BUFFERED 25 //number of possible datas stored in buffer for transmission. One item is reserved empty for storing current value.
#define LIMIT_BUFFERED 6 //warning limit if buffer is too full
#include <Arduino.h>
#include "RTClib.h" //bibliotheque RTC pour DS3231
//WARNING: the struct members must be sorted in a descending order to minimize memory footprint
#define BUFFER_DEBUG 1
struct Ecoset
{
public:
byte day; //1 octet
byte month;
int year; //2 octets
byte hour;
byte minute;
byte second;
int UTCoffset;
float MHTemp; //4 octets
float MHHum;
float MHPatm;
float MHRay;
float MHPDavis;
float MHTempWater;
float MHVit;
float MHDir;
float MHPluie;
//float MHWaterVolt;
//float MHWaterColonne;
float MHWaterHauteur;
// Default builder that resets everything to zero
Ecoset() :
day(0), month(0), year(0), hour(0), minute(0), second(0), UTCoffset(0),
MHTemp(0), MHHum(0), MHPatm(0), MHRay(0), MHPDavis(0),
MHTempWater(0),MHVit(0), MHDir(0), MHPluie(0),
//MHWaterVolt(0), MHWaterColonne(0),
MHWaterHauteur(0) {}
};
class BUFFER_PILE {
public:
BUFFER_PILE();
void add_pile(const Ecoset& mydataset);
bool read_pile(Ecoset& mydataset);
void next_pile();
byte available_pile();
byte alert_full_pile();
void debug_cpt();
void get_formatted_datetime_bufferpile(const Ecoset& dataset, char* datetime);
void get_formatted_UTC_bufferpile(const Ecoset& dataset, char* utc_datetime);
private:
byte buf_CR; // reading counter index
byte buf_CI; // insertion counter index
Ecoset ecobuffer[NUM_BUFFERED];
void inc_CI();
void inc_CR();
};
#endif //BUFFER_PILE_H