V148
Fork of RadioHead-148 by
RHDatagram.cpp@0:ab4e012489ef, 2015-10-15 (annotated)
- Committer:
- davidr99
- Date:
- Thu Oct 15 01:27:00 2015 +0000
- Revision:
- 0:ab4e012489ef
Messy start, but a port for RadioHead.; Currently the SPI modulus are the only ones that work.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
davidr99 | 0:ab4e012489ef | 1 | // RHDatagram.cpp |
davidr99 | 0:ab4e012489ef | 2 | // |
davidr99 | 0:ab4e012489ef | 3 | // Copyright (C) 2011 Mike McCauley |
davidr99 | 0:ab4e012489ef | 4 | // $Id: RHDatagram.cpp,v 1.6 2014/05/23 02:20:17 mikem Exp $ |
davidr99 | 0:ab4e012489ef | 5 | |
davidr99 | 0:ab4e012489ef | 6 | #include <RHDatagram.h> |
davidr99 | 0:ab4e012489ef | 7 | |
davidr99 | 0:ab4e012489ef | 8 | RHDatagram::RHDatagram(RHGenericDriver& driver, uint8_t thisAddress) |
davidr99 | 0:ab4e012489ef | 9 | : |
davidr99 | 0:ab4e012489ef | 10 | _driver(driver), |
davidr99 | 0:ab4e012489ef | 11 | _thisAddress(thisAddress) |
davidr99 | 0:ab4e012489ef | 12 | { |
davidr99 | 0:ab4e012489ef | 13 | } |
davidr99 | 0:ab4e012489ef | 14 | |
davidr99 | 0:ab4e012489ef | 15 | //////////////////////////////////////////////////////////////////// |
davidr99 | 0:ab4e012489ef | 16 | // Public methods |
davidr99 | 0:ab4e012489ef | 17 | bool RHDatagram::init() |
davidr99 | 0:ab4e012489ef | 18 | { |
davidr99 | 0:ab4e012489ef | 19 | bool ret = _driver.init(); |
davidr99 | 0:ab4e012489ef | 20 | if (ret) |
davidr99 | 0:ab4e012489ef | 21 | setThisAddress(_thisAddress); |
davidr99 | 0:ab4e012489ef | 22 | return ret; |
davidr99 | 0:ab4e012489ef | 23 | } |
davidr99 | 0:ab4e012489ef | 24 | |
davidr99 | 0:ab4e012489ef | 25 | void RHDatagram::setThisAddress(uint8_t thisAddress) |
davidr99 | 0:ab4e012489ef | 26 | { |
davidr99 | 0:ab4e012489ef | 27 | _driver.setThisAddress(thisAddress); |
davidr99 | 0:ab4e012489ef | 28 | // Use this address in the transmitted FROM header |
davidr99 | 0:ab4e012489ef | 29 | setHeaderFrom(thisAddress); |
davidr99 | 0:ab4e012489ef | 30 | _thisAddress = thisAddress; |
davidr99 | 0:ab4e012489ef | 31 | } |
davidr99 | 0:ab4e012489ef | 32 | |
davidr99 | 0:ab4e012489ef | 33 | bool RHDatagram::sendto(uint8_t* buf, uint8_t len, uint8_t address) |
davidr99 | 0:ab4e012489ef | 34 | { |
davidr99 | 0:ab4e012489ef | 35 | setHeaderTo(address); |
davidr99 | 0:ab4e012489ef | 36 | return _driver.send(buf, len); |
davidr99 | 0:ab4e012489ef | 37 | } |
davidr99 | 0:ab4e012489ef | 38 | |
davidr99 | 0:ab4e012489ef | 39 | bool RHDatagram::recvfrom(uint8_t* buf, uint8_t* len, uint8_t* from, uint8_t* to, uint8_t* id, uint8_t* flags) |
davidr99 | 0:ab4e012489ef | 40 | { |
davidr99 | 0:ab4e012489ef | 41 | if (_driver.recv(buf, len)) |
davidr99 | 0:ab4e012489ef | 42 | { |
davidr99 | 0:ab4e012489ef | 43 | if (from) *from = headerFrom(); |
davidr99 | 0:ab4e012489ef | 44 | if (to) *to = headerTo(); |
davidr99 | 0:ab4e012489ef | 45 | if (id) *id = headerId(); |
davidr99 | 0:ab4e012489ef | 46 | if (flags) *flags = headerFlags(); |
davidr99 | 0:ab4e012489ef | 47 | return true; |
davidr99 | 0:ab4e012489ef | 48 | } |
davidr99 | 0:ab4e012489ef | 49 | return false; |
davidr99 | 0:ab4e012489ef | 50 | } |
davidr99 | 0:ab4e012489ef | 51 | |
davidr99 | 0:ab4e012489ef | 52 | bool RHDatagram::available() |
davidr99 | 0:ab4e012489ef | 53 | { |
davidr99 | 0:ab4e012489ef | 54 | return _driver.available(); |
davidr99 | 0:ab4e012489ef | 55 | } |
davidr99 | 0:ab4e012489ef | 56 | |
davidr99 | 0:ab4e012489ef | 57 | void RHDatagram::waitAvailable() |
davidr99 | 0:ab4e012489ef | 58 | { |
davidr99 | 0:ab4e012489ef | 59 | _driver.waitAvailable(); |
davidr99 | 0:ab4e012489ef | 60 | } |
davidr99 | 0:ab4e012489ef | 61 | |
davidr99 | 0:ab4e012489ef | 62 | bool RHDatagram::waitPacketSent() |
davidr99 | 0:ab4e012489ef | 63 | { |
davidr99 | 0:ab4e012489ef | 64 | return _driver.waitPacketSent(); |
davidr99 | 0:ab4e012489ef | 65 | } |
davidr99 | 0:ab4e012489ef | 66 | |
davidr99 | 0:ab4e012489ef | 67 | bool RHDatagram::waitPacketSent(uint16_t timeout) |
davidr99 | 0:ab4e012489ef | 68 | { |
davidr99 | 0:ab4e012489ef | 69 | return _driver.waitPacketSent(timeout); |
davidr99 | 0:ab4e012489ef | 70 | } |
davidr99 | 0:ab4e012489ef | 71 | |
davidr99 | 0:ab4e012489ef | 72 | bool RHDatagram::waitAvailableTimeout(uint16_t timeout) |
davidr99 | 0:ab4e012489ef | 73 | { |
davidr99 | 0:ab4e012489ef | 74 | return _driver.waitAvailableTimeout(timeout); |
davidr99 | 0:ab4e012489ef | 75 | } |
davidr99 | 0:ab4e012489ef | 76 | |
davidr99 | 0:ab4e012489ef | 77 | uint8_t RHDatagram::thisAddress() |
davidr99 | 0:ab4e012489ef | 78 | { |
davidr99 | 0:ab4e012489ef | 79 | return _thisAddress; |
davidr99 | 0:ab4e012489ef | 80 | } |
davidr99 | 0:ab4e012489ef | 81 | |
davidr99 | 0:ab4e012489ef | 82 | void RHDatagram::setHeaderTo(uint8_t to) |
davidr99 | 0:ab4e012489ef | 83 | { |
davidr99 | 0:ab4e012489ef | 84 | _driver.setHeaderTo(to); |
davidr99 | 0:ab4e012489ef | 85 | } |
davidr99 | 0:ab4e012489ef | 86 | |
davidr99 | 0:ab4e012489ef | 87 | void RHDatagram::setHeaderFrom(uint8_t from) |
davidr99 | 0:ab4e012489ef | 88 | { |
davidr99 | 0:ab4e012489ef | 89 | _driver.setHeaderFrom(from); |
davidr99 | 0:ab4e012489ef | 90 | } |
davidr99 | 0:ab4e012489ef | 91 | |
davidr99 | 0:ab4e012489ef | 92 | void RHDatagram::setHeaderId(uint8_t id) |
davidr99 | 0:ab4e012489ef | 93 | { |
davidr99 | 0:ab4e012489ef | 94 | _driver.setHeaderId(id); |
davidr99 | 0:ab4e012489ef | 95 | } |
davidr99 | 0:ab4e012489ef | 96 | |
davidr99 | 0:ab4e012489ef | 97 | void RHDatagram::setHeaderFlags(uint8_t set, uint8_t clear) |
davidr99 | 0:ab4e012489ef | 98 | { |
davidr99 | 0:ab4e012489ef | 99 | _driver.setHeaderFlags(set, clear); |
davidr99 | 0:ab4e012489ef | 100 | } |
davidr99 | 0:ab4e012489ef | 101 | |
davidr99 | 0:ab4e012489ef | 102 | uint8_t RHDatagram::headerTo() |
davidr99 | 0:ab4e012489ef | 103 | { |
davidr99 | 0:ab4e012489ef | 104 | return _driver.headerTo(); |
davidr99 | 0:ab4e012489ef | 105 | } |
davidr99 | 0:ab4e012489ef | 106 | |
davidr99 | 0:ab4e012489ef | 107 | uint8_t RHDatagram::headerFrom() |
davidr99 | 0:ab4e012489ef | 108 | { |
davidr99 | 0:ab4e012489ef | 109 | return _driver.headerFrom(); |
davidr99 | 0:ab4e012489ef | 110 | } |
davidr99 | 0:ab4e012489ef | 111 | |
davidr99 | 0:ab4e012489ef | 112 | uint8_t RHDatagram::headerId() |
davidr99 | 0:ab4e012489ef | 113 | { |
davidr99 | 0:ab4e012489ef | 114 | return _driver.headerId(); |
davidr99 | 0:ab4e012489ef | 115 | } |
davidr99 | 0:ab4e012489ef | 116 | |
davidr99 | 0:ab4e012489ef | 117 | uint8_t RHDatagram::headerFlags() |
davidr99 | 0:ab4e012489ef | 118 | { |
davidr99 | 0:ab4e012489ef | 119 | return _driver.headerFlags(); |
davidr99 | 0:ab4e012489ef | 120 | } |
davidr99 | 0:ab4e012489ef | 121 | |
davidr99 | 0:ab4e012489ef | 122 | |
davidr99 | 0:ab4e012489ef | 123 |