forked from don/NDEF
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNfcTag.cpp
102 lines (89 loc) · 2.05 KB
/
NfcTag.cpp
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <NfcTag.h>
NfcTag::NfcTag()
{
_uid = 0;
_uidLength = 0;
_tagType = NfcTag::UNKNOWN;
_ndefMessage = (NdefMessage*)NULL;
}
NfcTag::NfcTag(byte *uid, unsigned int uidLength)
{
_uid = uid;
_uidLength = uidLength;
_tagType = NfcTag::UNKNOWN;
_ndefMessage = (NdefMessage*)NULL;
}
NfcTag::NfcTag(byte *uid, unsigned int uidLength, NfcTag::Type tagType)
{
_uid = uid;
_uidLength = uidLength;
_tagType = tagType;
_ndefMessage = (NdefMessage*)NULL;
}
NfcTag::NfcTag(byte *uid, unsigned int uidLength, NfcTag::Type tagType, NdefMessage& ndefMessage)
{
_uid = uid;
_uidLength = uidLength;
_tagType = tagType;
_ndefMessage = new NdefMessage(ndefMessage);
}
// I don't like this version, but it will use less memory
NfcTag::NfcTag(byte *uid, unsigned int uidLength, NfcTag::Type tagType, const byte *ndefData, const int ndefDataLength)
{
_uid = uid;
_uidLength = uidLength;
_tagType = tagType;
_ndefMessage = new NdefMessage(ndefData, ndefDataLength);
}
NfcTag::~NfcTag()
{
delete _ndefMessage;
}
NfcTag& NfcTag::operator=(const NfcTag& rhs)
{
if (this != &rhs)
{
delete _ndefMessage;
_uid = rhs._uid;
_uidLength = rhs._uidLength;
_tagType = rhs._tagType;
// TODO do I need a copy here?
_ndefMessage = rhs._ndefMessage;
}
return *this;
}
uint8_t NfcTag::getUidLength()
{
return _uidLength;
}
void NfcTag::getUid(byte *uid, unsigned int uidLength)
{
memcpy(uid, _uid, _uidLength < uidLength ? _uidLength : uidLength);
}
NfcTag::Type NfcTag::getTagType()
{
return _tagType;
}
boolean NfcTag::hasNdefMessage()
{
return (_ndefMessage != NULL);
}
NdefMessage NfcTag::getNdefMessage()
{
return *_ndefMessage;
}
#ifdef NDEF_USE_SERIAL
void NfcTag::print()
{
Serial.print(F("NFC Tag - "));Serial.println(_tagType);
Serial.print(F("UID "));Serial.println(getUidString());
if (_ndefMessage == NULL)
{
Serial.println(F("\nNo NDEF Message"));
}
else
{
_ndefMessage->print();
}
}
#endif