forked from jwhiddon/EDB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EDB.h
61 lines (53 loc) · 1.68 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
/*
EDB.h
Extended Database Library for Arduino
http://www.arduino.cc/playground/Code/ExtendedDatabaseLibrary
*/
#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;
};
/*typedef enum EDB_Status { */
typedef enum {
EDB_OK,
EDB_ERROR,
EDB_OUT_OF_RANGE,
EDB_TABLE_FULL
} EDB_Status;
typedef byte* EDB_Rec;
#define EDB_REC (byte*)(void*)&
class EDB {
public:
typedef void EDB_Write_Handler(unsigned long, const uint8_t*, unsigned int);
typedef void EDB_Read_Handler(unsigned long, uint8_t*, unsigned int);
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