forked from jeelabs/jeelib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RF12sio.h
61 lines (49 loc) · 2.9 KB
/
RF12sio.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
// 2009-05-07 <[email protected]> http://opensource.org/licenses/mit-license.php
/// @file
/// Streaming I/O layer on top of the RF12.h driver.
/// This class is NOT the %RF12 driver. It provides a way to construct packets.
class RF12 {
enum { F_EXT = -6, F_STR, F_8, F_4, F_2, F_1 };
MilliTimer sendTimer, ackTimer;
uint8_t txbase, txfill, txfields, txPending;
uint8_t txbuf[138]; // one full packet plus room for constructing next one
uint8_t rxpos, rxfield, ackHead, ackData;
void initBuf(uint8_t base);
void addToBuf(uint8_t type, const void *ptr, uint8_t len);
public:
RF12 () : txPending (0), ackHead (0) { initBuf(0); }
RF12& put(const void*, char);
RF12& get(void*, char);
uint8_t read() { char v; get(&v, F_1); return v; }
RF12& operator<< (char v) { return put(&v, F_1); }
RF12& operator<< (unsigned char v) { return put(&v, F_1); }
RF12& operator<< (int v) { return put(&v, F_2); }
RF12& operator<< (unsigned v) { return put(&v, F_2); }
RF12& operator<< (long v) { return put(&v, F_4); }
RF12& operator<< (unsigned long v) { return put(&v, F_4); }
RF12& operator<< (long long v) { return put(&v, F_8); }
RF12& operator<< (unsigned long long v) { return put(&v, F_8); }
RF12& operator<< (float v) { return put(&v, F_4); }
RF12& operator<< (double v) { return put(&v, F_8); }
RF12& operator<< (const char* v) { return put(v, F_STR); }
RF12& operator<< (const unsigned char* v) { return put(v, F_STR); }
// max payload is one string arg of 63 chars: needs 64b, plus 8 for fields
uint8_t ready() const { return txfill <= sizeof txbuf - 72; }
void send(uint8_t v);
RF12& operator>> (char& v) { return get(&v, F_1); }
RF12& operator>> (unsigned char& v) { return get(&v, F_1); }
RF12& operator>> (int& v) { return get(&v, F_2); }
RF12& operator>> (unsigned& v) { return get(&v, F_2); }
RF12& operator>> (long& v) { return get(&v, F_4); }
RF12& operator>> (unsigned long& v) { return get(&v, F_4); }
RF12& operator>> (long long& v) { return get(&v, F_8); }
RF12& operator>> (unsigned long long& v) { return get(&v, F_8); }
RF12& operator>> (float& v) { return get(&v, F_4); }
RF12& operator>> (double& v) { return get(&v, F_8); }
RF12& operator>> (char* v) { return get(v, F_STR); }
RF12& operator>> (unsigned char* v) { return get(v, F_STR); }
uint8_t poll();
uint8_t nextSize();
void to(uint8_t node) {}
uint8_t from() { return 0; }
};