Skip to content

Commit 6dcd752

Browse files
authored
Added construtor and Printable
Makes it closer to IPAddress Class implementation
1 parent 93b30a9 commit 6dcd752

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

cores/esp32/MacAddress.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ MacAddress::MacAddress(const uint8_t *macbytearray) {
1414
memcpy(_mac.bytes, macbytearray, sizeof(_mac.bytes));
1515
}
1616

17+
MacAddress::MacAddress((uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5, uint8_t b6) {
18+
_mac.bytes[0] = b1;
19+
_mac.bytes[1] = b2;
20+
_mac.bytes[2] = b3;
21+
_mac.bytes[3] = b4;
22+
_mac.bytes[4] = b5;
23+
_mac.bytes[5] = b6;
24+
}
25+
1726
//Parse user entered string into MAC address
1827
bool MacAddress::fromCStr(const char *buf) {
1928
char cs[18];
@@ -63,12 +72,6 @@ uint64_t MacAddress::Value() {
6372
return _mac.val;
6473
}
6574

66-
//Implicit conversion object to number [same as .Value()]
67-
MacAddress::operator uint64_t() const
68-
{
69-
return _mac.val;
70-
}
71-
7275
//Overloaded copy operators to allow initialisation of MacAddress objects from other types
7376
MacAddress& MacAddress::operator=(const uint8_t *mac)
7477
{
@@ -93,3 +96,16 @@ bool MacAddress::operator==(const MacAddress& mac2) const
9396
{
9497
return _mac.val == mac2._mac.val;
9598
}
99+
100+
size_t MacAddress::printTo(Print& p) const
101+
{
102+
size_t n = 0;
103+
for(int i = 0; i < 6; i++) {
104+
if(i){
105+
n += p.print(':');
106+
}
107+
n += p.printf("%02x", _mac.bytes[i]);
108+
}
109+
return n;
110+
}
111+

0 commit comments

Comments
 (0)