Skip to content

Commit

Permalink
Merge pull request #6 from matthijskooijman/improvements
Browse files Browse the repository at this point in the history
XBeeAddress64 improvements
  • Loading branch information
andrewrapp committed Aug 4, 2015
2 parents 29177e8 + 289db61 commit ce5f8cf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 48 deletions.
39 changes: 0 additions & 39 deletions XBee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1051,45 +1051,6 @@ void PayloadRequest::setPayloadLength(uint8_t payloadLength) {
_payloadLength = payloadLength;
}


XBeeAddress::XBeeAddress() {

}

XBeeAddress64::XBeeAddress64() : XBeeAddress() {

}

XBeeAddress64::XBeeAddress64(uint32_t msb, uint32_t lsb) : XBeeAddress() {
_msb = msb;
_lsb = lsb;
}

uint32_t XBeeAddress64::getMsb() {
return _msb;
}

void XBeeAddress64::setMsb(uint32_t msb) {
_msb = msb;
}

uint32_t XBeeAddress64::getLsb() {
return _lsb;
}

void XBeeAddress64::setLsb(uint32_t lsb) {
_lsb = lsb;
}

// contributed by user repat123 on issue tracker
//bool XBeeAddress64::operator==(XBeeAddress64 addr) {
// return ((_lsb == addr.getLsb()) && (_msb == addr.getMsb()));
//}

//bool XBeeAddress64::operator!=(XBeeAddress64 addr) {
// return !(*this == addr);
//}

#ifdef SERIES_2

ZBTxRequest::ZBTxRequest() : PayloadRequest(ZB_TX_REQUEST, DEFAULT_FRAME_ID, NULL, 0) {
Expand Down
43 changes: 34 additions & 9 deletions XBee.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,20 @@
#define PACKET_EXCEEDS_BYTE_ARRAY_LENGTH 2
#define UNEXPECTED_START_BYTE 3

/**
* C++11 introduced the constexpr as a hint to the compiler that things
* can be evaluated at compiletime. This can help to remove
* startup code for global objects, or otherwise help the compiler to
* optimize. Since the keyword is introduced in C++11, but supporting
* older compilers is a matter of removing the keyword, we use a macro
* for this.
*/
#if __cplusplus >= 201103L
#define CONSTEXPR constexpr
#else
#define CONSTEXPR
#endif

/**
* The super class of all XBee responses (RX packets)
* Users should never attempt to create an instance of this class; instead
Expand Down Expand Up @@ -301,23 +315,34 @@ class XBeeResponse {

class XBeeAddress {
public:
XBeeAddress();
CONSTEXPR XBeeAddress() {};
};

/**
* Represents a 64-bit XBee Address
*
* Note that avr-gcc as of 4.9 doesn't optimize uint64_t very well, so
* for the smallest and fastest code, use msb and lsb separately. See
* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66511
*/
class XBeeAddress64 : public XBeeAddress {
public:
XBeeAddress64(uint32_t msb, uint32_t lsb);
XBeeAddress64();
uint32_t getMsb();
uint32_t getLsb();
void setMsb(uint32_t msb);
void setLsb(uint32_t lsb);
//bool operator==(XBeeAddress64 addr);
//bool operator!=(XBeeAddress64 addr);
CONSTEXPR XBeeAddress64(uint64_t addr) : _msb(addr >> 32), _lsb(addr) {}
CONSTEXPR XBeeAddress64(uint32_t msb, uint32_t lsb) : _msb(msb), _lsb(lsb) {}
CONSTEXPR XBeeAddress64() : _msb(0), _lsb(0) {}
uint32_t getMsb() {return _msb;}
uint32_t getLsb() {return _lsb;}
uint64_t get() {return (static_cast<uint64_t>(_msb) << 32) | _lsb;}
operator uint64_t() {return get();}
void setMsb(uint32_t msb) {_msb = msb;}
void setLsb(uint32_t lsb) {_lsb = lsb;}
void set(uint64_t addr) {
_msb = addr >> 32;
_lsb = addr;
}
private:
// Once https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66511 is
// fixed, it might make sense to merge these into a uint64_t.
uint32_t _msb;
uint32_t _lsb;
};
Expand Down

0 comments on commit ce5f8cf

Please sign in to comment.