forked from Seeed-Shield/NFC_Shield_DEV
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathSNEP.cpp
More file actions
58 lines (43 loc) · 1.37 KB
/
SNEP.cpp
File metadata and controls
58 lines (43 loc) · 1.37 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
#include "SNEP.h"
SNEP::SNEP(NFCLinkLayer *linkLayer) :
_linkLayer(linkLayer)
{
}
SNEP::~SNEP()
{
}
uint32_t SNEP::rxNDEFPayload(uint8_t *&data)
{
uint32_t result = _linkLayer->openSNEPServerLink();
if(RESULT_OK(result)) //if connection is error-free
{
//Serial.println(F("CONNECTED."));
result = _linkLayer->serverLinkRxData(data);
if (RESULT_OK(result))
{
// TODO: to check header of SNEP packet
uint8_t *ptr = data;
uint8_t version = *ptr;
uint8_t require = *(ptr + 1);
uint32_t length = (ptr[2] << 24) + (ptr[3] << 16) + (ptr[4] << 8) + ptr[5];
data = ptr + 6;
// Serial.print("NDEF message length: ");
// Serial.println(length);
return length;
}
}
return result;
}
uint32_t SNEP::pushPayload(uint8_t *NDEFMessage, uint32_t length)
{
SNEP_MESSAGE *snepMessage = (SNEP_MESSAGE *) ALLOCATE_HEADER_SPACE(NDEFMessage, SNEP_MESSAGE_HDR_LEN);
snepMessage->version = 0x10;
snepMessage->action = 0x02;
snepMessage->length = MODIFY_ENDIAN(length);
uint32_t result = _linkLayer->openSNEPClientLink();
if(RESULT_OK(result)) //if connection is error-free
{
result = _linkLayer->clientLinkTxData((uint8_t *)snepMessage, length + SNEP_MESSAGE_HDR_LEN);
}
return result;
}