-
Notifications
You must be signed in to change notification settings - Fork 7
/
EDB.h
80 lines (67 loc) · 2.46 KB
/
EDB.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
/*
EDB.h
Extended Database Library for Arduino
http://www.arduino.cc/playground/Code/ExtendedDatabaseLibrary
Based on code from:
Database library for Arduino
Written by Madhusudana das
http://www.arduino.cc/playground/Code/DatabaseLibrary
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef EDB_PROM
#define EDB_PROM
#define EDB_FLAG B11011011
struct EDB_Header
{
byte flag;
unsigned long n_recs;
unsigned int rec_size;
unsigned long table_size;
};
enum EDB_Status {
EDB_OK,
EDB_ERROR,
EDB_OUT_OF_RANGE,
EDB_TABLE_FULL
};
typedef byte* EDB_Rec;
#define EDB_REC (byte*)(void*)&
class EDB {
public:
typedef void EDB_Write_Handler(unsigned long, const uint8_t);
typedef uint8_t EDB_Read_Handler(unsigned long);
EDB(EDB_Write_Handler *, EDB_Read_Handler *);
EDB_Status create(unsigned long, unsigned long, unsigned int);
EDB_Status open(unsigned long);
EDB_Status readRec(unsigned long, EDB_Rec);
EDB_Status deleteRec(unsigned long);
EDB_Status insertRec(unsigned long, const EDB_Rec);
EDB_Status updateRec(unsigned long, const EDB_Rec);
EDB_Status appendRec(EDB_Rec rec);
unsigned long limit();
unsigned long count();
void clear();
private:
unsigned long EDB_head_ptr;
unsigned long EDB_table_ptr;
EDB_Write_Handler *_write_byte;
EDB_Read_Handler *_read_byte;
EDB_Header EDB_head;
void edbWrite(unsigned long ee, const byte* p, unsigned int);
void edbRead(unsigned long ee, byte* p, unsigned int);
void writeHead();
void readHead();
EDB_Status writeRec(unsigned long, const EDB_Rec);
};
extern EDB edb;
#endif