-
Notifications
You must be signed in to change notification settings - Fork 200
Expand file tree
/
Copy pathMac.cpp
More file actions
69 lines (56 loc) · 1.32 KB
/
Mac.cpp
File metadata and controls
69 lines (56 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "Mac.h"
Mac::Mac(){
for(int i=0;i<6;i++){
adress[i] = 0x00;
}
}
Mac::Mac(uint8_t first, uint8_t second, uint8_t third, uint8_t fourth, uint8_t fifth, uint8_t sixth){
adress[0] = first;
adress[1] = second;
adress[2] = third;
adress[3] = fourth;
adress[4] = fifth;
adress[5] = sixth;
}
void Mac::set(uint8_t first, uint8_t second, uint8_t third, uint8_t fourth, uint8_t fifth, uint8_t sixth){
adress[0] = first;
adress[1] = second;
adress[2] = third;
adress[3] = fourth;
adress[4] = fifth;
adress[5] = sixth;
}
void Mac::setAt(uint8_t first, int num){
if(num > -1 && num < 6) adress[num] = first;
}
void Mac::setMac(Mac adr){
for(int i=0;i<6;i++){
adress[i] = adr._get(i);
}
}
bool Mac::valid(){
for(int i=0;i<6;i++){
if(adress[i] != 0xFF && adress[i] != 0x00) return true;
}
return false;
}
String Mac::toString(){
String value = "";
for(int i=0; i<6; i++) {
if(adress[i]<0x10) {
value += "0";
}
value += String(adress[i],HEX);
if(i<5) value += ":";
}
return value;
}
void Mac::_print(){Serial.print(Mac::toString());}
void Mac::_println(){Serial.println(Mac::toString());}
uint8_t Mac::_get(int num){return adress[num];}
bool Mac::compare(Mac target){
for(int i=0;i<6;i++){
if(adress[i] != target._get(i)) return false;
}
return true;
}