-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDB.h
66 lines (53 loc) · 1.67 KB
/
DB.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
/*
DB.h
Database library for Arduino
Written by Madhusudana das
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 DB_PROM
#define DB_PROM
#include "EEPROM.h"
struct DB_Header
{
byte n_recs;
byte rec_size;
};
// slightly padded for the time being
#define DB_HEAD_SIZE 4
// DB_error values
#define DB_OK 0
#define DB_RECNO_OUT_OF_RANGE 1
#define DB_REC (byte*)(void*)&
typedef byte* DB_Rec;
class DB {
public:
void create(int head_ptr, byte recsize);
void open(int head_ptr);
boolean write(byte recno, const DB_Rec rec);
boolean read(byte recno, DB_Rec rec);
boolean deleteRec(byte recno); // delete is a reserved word
boolean insert(byte recno, const DB_Rec rec);
void append(DB_Rec rec);
byte nRecs();
DB_Header DB_head;
byte DB_error;
private:
int writeHead();
int readHead();
int EEPROM_dbWrite(int ee, const byte* p);
int EEPROM_dbRead(int ee, byte* p);
int DB_head_ptr;
int DB_tbl_ptr;
};
extern DB db;
#endif