RF22Datagram.cpp@0:e16ffa7cb900, 2012-07-02 (annotated)
- Committer:
- SangSTBK
- Date:
- Mon Jul 02 01:29:58 2012 +0000
- Revision:
- 0:e16ffa7cb900
RF
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
SangSTBK | 0:e16ffa7cb900 | 1 | // RF22Datagram.cpp |
SangSTBK | 0:e16ffa7cb900 | 2 | // |
SangSTBK | 0:e16ffa7cb900 | 3 | // Copyright (C) 2011 Mike McCauley |
SangSTBK | 0:e16ffa7cb900 | 4 | // $Id: RF22Datagram.cpp,v 1.2 2011/02/09 22:26:09 mikem Exp $ |
SangSTBK | 0:e16ffa7cb900 | 5 | // ported to mbed by Karl Zweimueller |
SangSTBK | 0:e16ffa7cb900 | 6 | |
SangSTBK | 0:e16ffa7cb900 | 7 | #include <RF22Datagram.h> |
SangSTBK | 0:e16ffa7cb900 | 8 | //#include <SPI.h> |
SangSTBK | 0:e16ffa7cb900 | 9 | |
SangSTBK | 0:e16ffa7cb900 | 10 | RF22Datagram::RF22Datagram(uint8_t thisAddress, PinName slaveSelectPin , PinName mosi, PinName miso, PinName sclk, PinName interrupt ) |
SangSTBK | 0:e16ffa7cb900 | 11 | : RF22(slaveSelectPin , mosi, miso, sclk, interrupt ) |
SangSTBK | 0:e16ffa7cb900 | 12 | { |
SangSTBK | 0:e16ffa7cb900 | 13 | _thisAddress = thisAddress; |
SangSTBK | 0:e16ffa7cb900 | 14 | } |
SangSTBK | 0:e16ffa7cb900 | 15 | |
SangSTBK | 0:e16ffa7cb900 | 16 | //////////////////////////////////////////////////////////////////// |
SangSTBK | 0:e16ffa7cb900 | 17 | // Public methods |
SangSTBK | 0:e16ffa7cb900 | 18 | boolean RF22Datagram::init() |
SangSTBK | 0:e16ffa7cb900 | 19 | { |
SangSTBK | 0:e16ffa7cb900 | 20 | boolean ret = this->RF22::init(); |
SangSTBK | 0:e16ffa7cb900 | 21 | if (ret) |
SangSTBK | 0:e16ffa7cb900 | 22 | setThisAddress(_thisAddress); |
SangSTBK | 0:e16ffa7cb900 | 23 | return ret; |
SangSTBK | 0:e16ffa7cb900 | 24 | } |
SangSTBK | 0:e16ffa7cb900 | 25 | |
SangSTBK | 0:e16ffa7cb900 | 26 | void RF22Datagram::setThisAddress(uint8_t thisAddress) |
SangSTBK | 0:e16ffa7cb900 | 27 | { |
SangSTBK | 0:e16ffa7cb900 | 28 | _thisAddress = thisAddress; |
SangSTBK | 0:e16ffa7cb900 | 29 | // Check the TO header against RF22_DEFAULT_NODE_ADDRESS |
SangSTBK | 0:e16ffa7cb900 | 30 | spiWrite(RF22_REG_3F_CHECK_HEADER3, _thisAddress); |
SangSTBK | 0:e16ffa7cb900 | 31 | // Use this address in the transmitted FROM header |
SangSTBK | 0:e16ffa7cb900 | 32 | setHeaderFrom(_thisAddress); |
SangSTBK | 0:e16ffa7cb900 | 33 | } |
SangSTBK | 0:e16ffa7cb900 | 34 | |
SangSTBK | 0:e16ffa7cb900 | 35 | boolean RF22Datagram::sendto(uint8_t* buf, uint8_t len, uint8_t address) |
SangSTBK | 0:e16ffa7cb900 | 36 | { |
SangSTBK | 0:e16ffa7cb900 | 37 | setHeaderTo(address); |
SangSTBK | 0:e16ffa7cb900 | 38 | return send(buf, len); |
SangSTBK | 0:e16ffa7cb900 | 39 | } |
SangSTBK | 0:e16ffa7cb900 | 40 | |
SangSTBK | 0:e16ffa7cb900 | 41 | boolean RF22Datagram::recvfrom(uint8_t* buf, uint8_t* len, uint8_t* from, uint8_t* to, uint8_t* id, uint8_t* flags) |
SangSTBK | 0:e16ffa7cb900 | 42 | { |
SangSTBK | 0:e16ffa7cb900 | 43 | if (from) *from = headerFrom(); |
SangSTBK | 0:e16ffa7cb900 | 44 | if (to) *to = headerTo(); |
SangSTBK | 0:e16ffa7cb900 | 45 | if (id) *id = headerId(); |
SangSTBK | 0:e16ffa7cb900 | 46 | if (flags) *flags = headerFlags(); |
SangSTBK | 0:e16ffa7cb900 | 47 | return recv(buf, len); |
SangSTBK | 0:e16ffa7cb900 | 48 | } |
SangSTBK | 0:e16ffa7cb900 | 49 | |
SangSTBK | 0:e16ffa7cb900 | 50 | |
SangSTBK | 0:e16ffa7cb900 | 51 |