Skip to content

Commit c94a815

Browse files
Allow XBeeAddress64 to work with uint64_t variables
This adds: - A constructor that takes a single uint64_t variable. This allows implicitly converting integers to XBeeAddress64 values, so these will work: XBeeAddress64 dest = 0x0; request.setAddress64(0x0013A21234567890); (note that the latter also requires some const-correctness fixes in methods taking XBeeAddress64 arguments). - A get() and set() method for getting and setting the address as a uint64_t. - A operator uint64_t() which allows the XBeeAddress64 to be implicitely converted to a uint64_t. E.g.: uint64_t address = resp.getRemoteAddress64(); But also comparison: resp.getRemoteAddress64() == XBeeAddress64(0, 0) resp.getRemoteAddress64() == 0x0013A21234567890); Note that both comparisons above work by converting to uint64_t and comparing those. Because this removes the need for separate comparison operators, the ones that were there (but still commented out) were removed. Note that avr-gcc doesn't currently optimize uint64_t values very well, so the storage is still left as two separate uint32_t values. If you use the msb/lsb accessors, code should be unchanged compared to before, but if you use the uint64_t accessors or compare addresses, code will be less efficient. This will hopefully be fixed in a future compiler version, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66511.
1 parent 197e360 commit c94a815

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

XBee.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,10 @@ XBeeAddress64::XBeeAddress64(uint32_t msb, uint32_t lsb) : XBeeAddress() {
10281028
_lsb = lsb;
10291029
}
10301030

1031+
XBeeAddress64::XBeeAddress64(uint64_t addr) : XBeeAddress() {
1032+
set(addr);
1033+
}
1034+
10311035
uint32_t XBeeAddress64::getMsb() {
10321036
return _msb;
10331037
}
@@ -1044,14 +1048,18 @@ void XBeeAddress64::setLsb(uint32_t lsb) {
10441048
_lsb = lsb;
10451049
}
10461050

1047-
// contributed by user repat123 on issue tracker
1048-
//bool XBeeAddress64::operator==(XBeeAddress64 addr) {
1049-
// return ((_lsb == addr.getLsb()) && (_msb == addr.getMsb()));
1050-
//}
1051+
uint64_t XBeeAddress64::get() {
1052+
return (static_cast<uint64_t>(_msb) << 32) | _lsb;
1053+
}
10511054

1052-
//bool XBeeAddress64::operator!=(XBeeAddress64 addr) {
1053-
// return !(*this == addr);
1054-
//}
1055+
void XBeeAddress64::set(uint64_t addr) {
1056+
_msb = addr >> 32;
1057+
_lsb = addr;
1058+
}
1059+
1060+
XBeeAddress64::operator uint64_t() {
1061+
return get();
1062+
}
10551063

10561064
#ifdef SERIES_2
10571065

XBee.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,18 +292,26 @@ class XBeeAddress {
292292

293293
/**
294294
* Represents a 64-bit XBee Address
295+
*
296+
* Note that avr-gcc as of 4.9 doesn't optimize uint64_t very well, so
297+
* for the smallest and fastest code, use msb and lsb separately. See
298+
* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66511
295299
*/
296300
class XBeeAddress64 : public XBeeAddress {
297301
public:
302+
XBeeAddress64(uint64_t addr);
298303
XBeeAddress64(uint32_t msb, uint32_t lsb);
299304
XBeeAddress64();
300305
uint32_t getMsb();
301306
uint32_t getLsb();
307+
uint64_t get();
308+
operator uint64_t();
302309
void setMsb(uint32_t msb);
303310
void setLsb(uint32_t lsb);
304-
//bool operator==(XBeeAddress64 addr);
305-
//bool operator!=(XBeeAddress64 addr);
311+
void set(uint64_t addr);
306312
private:
313+
// Once https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66511 is
314+
// fixed, it might make sense to merge these into a uint64_t.
307315
uint32_t _msb;
308316
uint32_t _lsb;
309317
};

0 commit comments

Comments
 (0)