• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "nfcForum.h"
2 #include <string.h>
3 
rtdHeader(uint8_t type,NDEFRecordStr * ndefRecord,uint8_t * I2CMsg)4 static void rtdHeader(uint8_t type, NDEFRecordStr *ndefRecord, uint8_t *I2CMsg)
5 {
6     ndefRecord->header |= 1;
7     ndefRecord->header |= BIT_SR;
8     I2CMsg[HEADER] = ndefRecord->header;
9 
10     ndefRecord->typeLength = 1;
11     I2CMsg[TYPE_LENGTH] = ndefRecord->typeLength;
12 
13     ndefRecord->type.typeCode = type;
14     I2CMsg[TYPE_CODE] = ndefRecord->type.typeCode;
15 }
16 
composeRtdText(const NDEFDataStr * ndef,NDEFRecordStr * ndefRecord,uint8_t * I2CMsg)17 uint8_t composeRtdText(const NDEFDataStr *ndef, NDEFRecordStr *ndefRecord, uint8_t *I2CMsg)
18 {
19     uint8_t retLen;
20 
21     rtdHeader(RTD_TEXT, ndefRecord, I2CMsg);
22 
23     uint8_t payLoadLen = addRtdText(&ndefRecord->type.typePayload.text);
24     memcpy_s(&I2CMsg[TYPE_PAYLOAD], payLoadLen, &ndefRecord->type.typePayload.text, payLoadLen);
25 
26     ndefRecord->payloadLength = ndef->rtdPayloadlength + payLoadLen; // added the typePayload
27     I2CMsg[PAYLOAD_LENGTH] = ndefRecord->payloadLength;
28     return TEXT_RECORD_LEN;
29 }
30 
composeRtdUri(const NDEFDataStr * ndef,NDEFRecordStr * ndefRecord,uint8_t * I2CMsg)31 uint8_t composeRtdUri(const NDEFDataStr *ndef, NDEFRecordStr *ndefRecord, uint8_t *I2CMsg)
32 {
33     rtdHeader(RTD_URI, ndefRecord, I2CMsg);
34 
35     uint8_t payLoadLen = addRtdUriRecord(ndef, &ndefRecord->type.typePayload.uri);
36     memcpy_s(&I2CMsg[TYPE_PAYLOAD], payLoadLen, &ndefRecord->type.typePayload.uri, payLoadLen);
37 
38     ndefRecord->payloadLength = ndef->rtdPayloadlength + payLoadLen; // added the typePayload
39     I2CMsg[PAYLOAD_LENGTH] = ndefRecord->payloadLength;
40 
41     return URI_RECORD_LEN;
42 }
43 
composeNDEFMBME(bool isFirstRecord,bool isLastRecord,NDEFRecordStr * ndefRecord)44 void composeNDEFMBME(bool isFirstRecord, bool isLastRecord, NDEFRecordStr *ndefRecord)
45 {
46     if (isFirstRecord)
47         ndefRecord->header |= BIT_MB;
48     else
49         ndefRecord->header &= ~MASK_MB;
50 
51     if (isLastRecord)
52         ndefRecord->header |= BIT_ME;
53     else
54         ndefRecord->header &= ~MASK_ME;
55 }
56