forked from mcauser/RadioHead
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RHDatagram.cpp
123 lines (100 loc) · 2.21 KB
/
RHDatagram.cpp
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// RHDatagram.cpp
//
// Copyright (C) 2011 Mike McCauley
// $Id: RHDatagram.cpp,v 1.6 2014/05/23 02:20:17 mikem Exp $
#include <RHDatagram.h>
RHDatagram::RHDatagram(RHGenericDriver& driver, uint8_t thisAddress)
:
_driver(driver),
_thisAddress(thisAddress)
{
}
////////////////////////////////////////////////////////////////////
// Public methods
bool RHDatagram::init()
{
bool ret = _driver.init();
if (ret)
setThisAddress(_thisAddress);
return ret;
}
void RHDatagram::setThisAddress(uint8_t thisAddress)
{
_driver.setThisAddress(thisAddress);
// Use this address in the transmitted FROM header
setHeaderFrom(thisAddress);
_thisAddress = thisAddress;
}
bool RHDatagram::sendto(uint8_t* buf, uint8_t len, uint8_t address)
{
setHeaderTo(address);
return _driver.send(buf, len);
}
bool RHDatagram::recvfrom(uint8_t* buf, uint8_t* len, uint8_t* from, uint8_t* to, uint8_t* id, uint8_t* flags)
{
if (_driver.recv(buf, len))
{
if (from) *from = headerFrom();
if (to) *to = headerTo();
if (id) *id = headerId();
if (flags) *flags = headerFlags();
return true;
}
return false;
}
bool RHDatagram::available()
{
return _driver.available();
}
void RHDatagram::waitAvailable()
{
_driver.waitAvailable();
}
bool RHDatagram::waitPacketSent()
{
return _driver.waitPacketSent();
}
bool RHDatagram::waitPacketSent(uint16_t timeout)
{
return _driver.waitPacketSent(timeout);
}
bool RHDatagram::waitAvailableTimeout(uint16_t timeout)
{
return _driver.waitAvailableTimeout(timeout);
}
uint8_t RHDatagram::thisAddress()
{
return _thisAddress;
}
void RHDatagram::setHeaderTo(uint8_t to)
{
_driver.setHeaderTo(to);
}
void RHDatagram::setHeaderFrom(uint8_t from)
{
_driver.setHeaderFrom(from);
}
void RHDatagram::setHeaderId(uint8_t id)
{
_driver.setHeaderId(id);
}
void RHDatagram::setHeaderFlags(uint8_t set, uint8_t clear)
{
_driver.setHeaderFlags(set, clear);
}
uint8_t RHDatagram::headerTo()
{
return _driver.headerTo();
}
uint8_t RHDatagram::headerFrom()
{
return _driver.headerFrom();
}
uint8_t RHDatagram::headerId()
{
return _driver.headerId();
}
uint8_t RHDatagram::headerFlags()
{
return _driver.headerFlags();
}