Holds the 64-bit address of a device on a 1-wire bus. More...
#include <DS2482-RK.h>
Public Member Functions | |
DS24821WireAddress () | |
Construct an empty 1-wire address (all 0s) | |
virtual | ~DS24821WireAddress () |
Destructor. | |
DS24821WireAddress (const DS24821WireAddress &other) | |
Construct as a copy of another (copy constructor) | |
DS24821WireAddress & | operator= (const DS24821WireAddress &other) |
Set this address to be the same as another (copy operator) | |
bool | operator== (const DS24821WireAddress &other) const |
Test against another address for equality (comparing the 8-byte address values, not pointer) | |
DS24821WireAddress & | withBytes (const uint8_t *buf) |
Set the 1-wire address from a buffer of 8 unsigned bytes. | |
bool | getBit (size_t bitNum) const |
Get a specific bit from the address. More... | |
void | setBit (size_t bitNum, bool value=true) |
Set a specific bit from the address. More... | |
uint8_t | operator[] (size_t offset) const |
Get a byte from the address by offset. More... | |
void | clear () |
Clears the address to all 0s. More... | |
bool | isValid () const |
Returns true if the 1-wire address is valid. More... | |
String | toString () const |
Outputs the 1-wire address as a string, 8 hexadecimal bytes. More... | |
Static Public Attributes | |
static const size_t | ADDR_SIZE = 8 |
The size of a 1-wire address in bytes (8 bytes = 64 bits). | |
Protected Attributes | |
uint8_t | addr [ADDR_SIZE] |
The 1-wire address in wire order. More... | |
Holds the 64-bit address of a device on a 1-wire bus.
The address is unique for every device, set at the factory.
void DS24821WireAddress::clear | ( | ) |
Clears the address to all 0s.
This is done during construction.
bool DS24821WireAddress::getBit | ( | size_t | bitNum | ) | const |
Get a specific bit from the address.
bitNum | Bits are numbered 0 <= bitNum < 64 and are in wire order. Bit 0 is the least significant bit of the least significant byte. |
bool DS24821WireAddress::isValid | ( | ) | const |
Returns true if the 1-wire address is valid.
A 1-wire address contains a CRC, and this method validates the CRC.
|
inline |
Get a byte from the address by offset.
offset | The byte to get 0 <= offset < 8 |
Note that the bytes are in wire order, LSB first. When printed, they're printed in reverse order, MSB first like a normal 64-bit integer.
void DS24821WireAddress::setBit | ( | size_t | bitNum, |
bool | value = true |
||
) |
Set a specific bit from the address.
bitNum | Bits are numbered 0 <= bitNum < 64 and are in wire order. Bit 0 is the least significant bit of the least significant byte. |
value | Value to set the bit to. true or false, default is true. |
String DS24821WireAddress::toString | ( | ) | const |
Outputs the 1-wire address as a string, 8 hexadecimal bytes.
Note that the presentation of addresses is MSB first, so the hex bytes will appear in the opposite order they're in the addr buffer.
|
protected |
The 1-wire address in wire order.
Note that addr is in wire order (LSB first). When addresses are displayed to the user at 8 hexadecimal bytes, they're presented in the opposite order!