forked from Integreight/1Sheeld-Arduino-Library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NFCTag.cpp
126 lines (104 loc) · 2.25 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
Project: 1Sheeld Library
File: NFCTag.cpp
Version: 1.5
Compiler: Arduino avr-gcc 4.3.2
Author: Integreight
Date: 2015.3
*/
#define FROM_ONESHEELD_LIBRARY
#include "OneSheeld.h"
#include "NFCTag.h"
NFCRecord NFCTag::nullRecord;
NFCTag::NFCTag(byte * _tagId,byte tagIdLength, int _tagSize, int _tagMaxSize, byte _recordsNumber)
{
isTypeCallBackAssigned= false;
isDataCallBackAssigned= false;
isParsedDataCallBackAssigned= false;
tagId=NULL;
if(tagIdLength!=0)
{
tagId = (byte *) malloc(sizeof(byte)*(tagIdLength));
memcpy(tagId,_tagId,tagIdLength);
}
tagSize =_tagSize;
tagMaxSize =_tagMaxSize;
recordsNumber =_recordsNumber;
if(recordsNumber>0)
{
recordsArray = (NFCRecord **) malloc(sizeof(NFCRecord*)*recordsNumber);
for (int i = 0; i < recordsNumber; i++)
{
recordsArray[i]=new NFCRecord(i);
}
}
}
NFCTag::NFCTag()
{
isTypeCallBackAssigned= false;
isDataCallBackAssigned= false;
isParsedDataCallBackAssigned= false;
tagId=NULL;
tagSize=0;
tagMaxSize=0;
recordsNumber=0;
recordsArray=NULL;
}
NFCRecord & NFCTag::getRecord(int index)
{
if(index>=recordsNumber)return NFCTag::nullRecord;
return *(recordsArray[index]);
}
int NFCTag::getSize()
{
return tagSize;
}
int NFCTag::getMaxSize()
{
return tagMaxSize;
}
byte NFCTag::getNumberOfRecords()
{
return recordsNumber;
}
bool NFCTag::isEmpty()
{
return !recordsNumber;
}
byte NFCTag::getIdLength()
{
return tagIdLength;
}
byte * NFCTag::getId()
{
return tagId;
}
void NFCTag::setOnRecordTypeResponse(void (*userFunction)(byte id, byte data[], byte typeLength))
{
isTypeCallBackAssigned =true;
recordTypeCallBack = userFunction;
}
void NFCTag::setOnRecordParsedDataResponse(void (*userFunction)(byte id, char data[]))
{
isParsedDataCallBackAssigned =true;
recordParsedCallBack = userFunction;
}
void NFCTag::setOnRecordDataResponse(void (userFunction)(byte id,byte data [], byte dataLength))
{
isDataCallBackAssigned =true;
recordDataCallBack = userFunction;
}
bool NFCTag::isNull()
{
return tagMaxSize==0;
}
NFCTag::~NFCTag()
{
if(recordsNumber>0&&recordsArray!=NULL)
{
for(int i=0;i<recordsNumber;i++)
delete recordsArray[i];
free (recordsArray);
}
if(tagId!=NULL)free (tagId);
}