Skip to content

XBeeAddress64 improvements #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 0 additions & 39 deletions XBee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1014,45 +1014,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 @@ -142,6 +142,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 @@ -287,23 +301,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