Skip to content

Commit dca7e22

Browse files
SuGlidermrengineer7777
authored andcommitted
Added Printble and some more operators
1 parent 450c4dd commit dca7e22

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

Diff for: cores/esp32/MacAddress8.h

+32-1
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
#ifndef MacAddress8_h
1919
#define MacAddress8_h
2020

21+
#include <stdint.h>
2122
#include <WString.h>
23+
#include <Printable.h>
2224

2325
// A class to make it easier to handle and pass around 8-byte EUI-64(used for IEEE 802.15.4) addresses. See <esp_mac.h>.
24-
class MacAddress8 {
26+
class MacAddress8 : public Printable {
2527
private:
2628
union {
2729
uint8_t bytes[8];
@@ -45,6 +47,35 @@ class MacAddress8 {
4547
MacAddress8& operator=(uint64_t macval);
4648
bool operator==(const uint8_t *mac) const;
4749
bool operator==(const MacAddress8& mac2) const;
50+
51+
// Overloaded index operator to allow getting and setting individual octets of the address
52+
uint8_t operator[](int index) const
53+
{
54+
return _mac.bytes[index];
55+
}
56+
uint8_t& operator[](int index)
57+
{
58+
return _mac.bytes[index];
59+
}
60+
61+
operator const uint8_t*() const
62+
{
63+
return _mac.bytes;
64+
}
65+
operator const uint64_t*() const
66+
{
67+
return &_mac.val;
68+
}
69+
70+
virtual size_t printTo(Print& p) const;
71+
72+
// future use in Arduino Networking
73+
friend class EthernetClass;
74+
friend class UDP;
75+
friend class Client;
76+
friend class Server;
77+
friend class DhcpClass;
78+
friend class DNSClient;
4879
};
4980

5081
#endif

0 commit comments

Comments
 (0)