Skip to content

Commit 8b6fdba

Browse files
SuGlidermrengineer7777
authored andcommitted
Added Printable, constructor and extra operators
Added a few changes to make it closer to IPAddress Class implementation.
1 parent 0e84fad commit 8b6fdba

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

cores/esp32/MacAddress.h

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <WString.h>
2222

2323
// A class to make it easier to handle and pass around 6-byte BSSID and MAC addresses.
24-
class MacAddress {
24+
class MacAddress : public Printable {
2525
private:
2626
union {
2727
struct {
@@ -35,6 +35,7 @@ class MacAddress {
3535
MacAddress();
3636
MacAddress(uint64_t mac);
3737
MacAddress(const uint8_t *macbytearray);
38+
MAcAddress(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5, uint8_t b6);
3839
virtual ~MacAddress() {}
3940
bool fromCStr(const char *buf);
4041
bool fromString(const String &macstr);
@@ -43,11 +44,43 @@ class MacAddress {
4344
String toString() const;
4445
uint64_t Value();
4546

46-
operator uint64_t() const;
47+
// Overloaded index operator to allow getting and setting individual octets of the address
48+
uint8_t operator[](int index) const
49+
{
50+
return _mac.bytes[index];
51+
}
52+
uint8_t& operator[](int index)
53+
{
54+
return _mac.bytes[index];
55+
}
56+
4757
MacAddress& operator=(const uint8_t *mac);
4858
MacAddress& operator=(uint64_t macval);
4959
bool operator==(const uint8_t *mac) const;
5060
bool operator==(const MacAddress& mac2) const;
61+
62+
operator uint64_t() const
63+
{
64+
return _mac.val;
65+
}
66+
operator const uint8_t*() const
67+
{
68+
return _mac.bytes;
69+
}
70+
operator const uint64_t*() const
71+
{
72+
return &_mac.val;
73+
}
74+
75+
virtual size_t printTo(Print& p) const;
76+
77+
// future use in Arduino Networking
78+
friend class EthernetClass;
79+
friend class UDP;
80+
friend class Client;
81+
friend class Server;
82+
friend class DhcpClass;
83+
friend class DNSClient;
5184
};
5285

5386
#endif

0 commit comments

Comments
 (0)