|
151 | 151 | #define PACKET_EXCEEDS_BYTE_ARRAY_LENGTH 2
|
152 | 152 | #define UNEXPECTED_START_BYTE 3
|
153 | 153 |
|
| 154 | +/** |
| 155 | + * C++11 introduced the constexpr as a hint to the compiler that things |
| 156 | + * can be evaluated at compiletime. This can help to remove |
| 157 | + * startup code for global objects, or otherwise help the compiler to |
| 158 | + * optimize. Since the keyword is introduced in C++11, but supporting |
| 159 | + * older compilers is a matter of removing the keyword, we use a macro |
| 160 | + * for this. |
| 161 | + */ |
| 162 | +#if __cplusplus >= 201103L |
| 163 | +#define CONSTEXPR constexpr |
| 164 | +#else |
| 165 | +#define CONSTEXPR |
| 166 | +#endif |
| 167 | + |
154 | 168 | /**
|
155 | 169 | * The super class of all XBee responses (RX packets)
|
156 | 170 | * Users should never attempt to create an instance of this class; instead
|
@@ -301,23 +315,34 @@ class XBeeResponse {
|
301 | 315 |
|
302 | 316 | class XBeeAddress {
|
303 | 317 | public:
|
304 |
| - XBeeAddress(); |
| 318 | + CONSTEXPR XBeeAddress() {}; |
305 | 319 | };
|
306 | 320 |
|
307 | 321 | /**
|
308 | 322 | * Represents a 64-bit XBee Address
|
| 323 | + * |
| 324 | + * Note that avr-gcc as of 4.9 doesn't optimize uint64_t very well, so |
| 325 | + * for the smallest and fastest code, use msb and lsb separately. See |
| 326 | + * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66511 |
309 | 327 | */
|
310 | 328 | class XBeeAddress64 : public XBeeAddress {
|
311 | 329 | public:
|
312 |
| - XBeeAddress64(uint32_t msb, uint32_t lsb); |
313 |
| - XBeeAddress64(); |
314 |
| - uint32_t getMsb(); |
315 |
| - uint32_t getLsb(); |
316 |
| - void setMsb(uint32_t msb); |
317 |
| - void setLsb(uint32_t lsb); |
318 |
| - //bool operator==(XBeeAddress64 addr); |
319 |
| - //bool operator!=(XBeeAddress64 addr); |
| 330 | + CONSTEXPR XBeeAddress64(uint64_t addr) : _msb(addr >> 32), _lsb(addr) {} |
| 331 | + CONSTEXPR XBeeAddress64(uint32_t msb, uint32_t lsb) : _msb(msb), _lsb(lsb) {} |
| 332 | + CONSTEXPR XBeeAddress64() : _msb(0), _lsb(0) {} |
| 333 | + uint32_t getMsb() {return _msb;} |
| 334 | + uint32_t getLsb() {return _lsb;} |
| 335 | + uint64_t get() {return (static_cast<uint64_t>(_msb) << 32) | _lsb;} |
| 336 | + operator uint64_t() {return get();} |
| 337 | + void setMsb(uint32_t msb) {_msb = msb;} |
| 338 | + void setLsb(uint32_t lsb) {_lsb = lsb;} |
| 339 | + void set(uint64_t addr) { |
| 340 | + _msb = addr >> 32; |
| 341 | + _lsb = addr; |
| 342 | + } |
320 | 343 | private:
|
| 344 | + // Once https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66511 is |
| 345 | + // fixed, it might make sense to merge these into a uint64_t. |
321 | 346 | uint32_t _msb;
|
322 | 347 | uint32_t _lsb;
|
323 | 348 | };
|
|
0 commit comments