Skip to content

Commit 323b097

Browse files
authored
Merge pull request #36 from gabrielebarola/export-ndef-types
Export ndef types and fix various issues
2 parents 2523072 + 78fa6cd commit 323b097

16 files changed

+214
-51
lines changed

.astyleignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.git
2+
BUILD
3+
CI
4+
system

keywords.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ writeGEO KEYWORD2
2323
readGEO KEYWORD2
2424
writeEMail KEYWORD2
2525
readEMail KEYWORD2
26+
writeWifi KEYWORD2
27+
readWifi KEYWORD2
28+
writeVcard KEYWORD2
29+
readVcard KEYWORD2
30+
appendAAR KEYWORD2
31+
appendBluetoothOOB KEYWORD2
32+
writeMyApp KEYWORD2
33+
writeText KEYWORD2
34+
readText KEYWORD2
2635

2736
#######################################
2837
# Constants (LITERAL1)

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=STM32duino ST25DV
2-
version=2.1.2
2+
version=2.2.0
33
author=STMicroelectronics
44
maintainer=stm32duino
55
sentence=Allows controlling the NFC ST25DV

src/ST25DVSensor.cpp

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,38 @@ int ST25DV::begin(uint8_t *buffer, uint16_t bufferLength)
5252
return NFCTAG_OK;
5353
};
5454

55+
int ST25DV::writeText(String text, String iso_lang, NDEF_Text_encoding_t encoding)
56+
{
57+
NDEF_Text_info_t text_info;
58+
59+
60+
strcpy(text_info.text, text.c_str());
61+
strcpy(text_info.language_code, iso_lang.c_str());
62+
text_info.encoding = encoding;
63+
64+
return ndef.NDEF_WriteText(&text_info);
65+
}
66+
67+
int ST25DV::readText(String *text)
68+
{
69+
uint16_t ret;
70+
NDEF_Text_info_t info;
71+
sRecordInfo_t recordInfo;
72+
73+
ret = ndef.NDEF_IdentifyNDEF(&recordInfo);
74+
if (ret) {
75+
return ret;
76+
}
77+
78+
ret = ndef.NDEF_ReadText(&recordInfo, &info);
79+
if (ret) {
80+
return ret;
81+
}
82+
*text = String(info.text);
83+
84+
return 0;
85+
}
86+
5587
int ST25DV::writeURI(String protocol, String uri, String info)
5688
{
5789
sURI_Info _URI;
@@ -273,6 +305,80 @@ int ST25DV::readEMail(String *emailAdd, String *subject, String *message)
273305
return NDEF_OK;
274306
}
275307

308+
/**
309+
* @brief Writes a WIFI record
310+
*
311+
* @param SSID
312+
* @param auth: authentication type
313+
* @param enc: Encryption type
314+
* @param key
315+
* @retval success or failure
316+
*/
317+
int ST25DV::writeWifi(String SSID, Ndef_Wifi_Authentication_t auth, Ndef_Wifi_Encryption_t enc, String key)
318+
{
319+
sWifiTokenInfo _wifi;
320+
321+
strncpy(_wifi.NetworkSSID, SSID.c_str(), 32);
322+
strncpy(_wifi.NetworkKey, key.c_str(), 32);
323+
324+
_wifi.AuthenticationType = auth;
325+
_wifi.EncryptionType = enc;
326+
327+
return ndef.NDEF_WriteWifiToken(&_wifi);
328+
}
329+
330+
int ST25DV::readWifi(sWifiTokenInfo *wifitoken)
331+
{
332+
uint16_t ret;
333+
sRecordInfo_t recordInfo;
334+
335+
ret = ndef.NDEF_IdentifyNDEF(&recordInfo);
336+
if (ret) {
337+
return ret;
338+
}
339+
340+
return ndef.NDEF_ReadWifiToken(&recordInfo, wifitoken);
341+
342+
}
343+
344+
int ST25DV::writeVcard(sVcardInfo vcard)
345+
{
346+
347+
return ndef.NDEF_WriteVcard(&vcard);
348+
}
349+
350+
int ST25DV::readVcard(sVcardInfo *vcard)
351+
{
352+
uint16_t ret;
353+
sRecordInfo_t recordInfo;
354+
355+
ret = ndef.NDEF_IdentifyNDEF(&recordInfo);
356+
if (ret) {
357+
return ret;
358+
}
359+
360+
return ndef.NDEF_ReadVcard(&recordInfo, vcard);
361+
362+
}
363+
364+
int ST25DV::appendAAR(String pkgName)
365+
{
366+
sAARInfo _info;
367+
strncpy(_info.PackageName, pkgName.c_str(), 80);
368+
369+
return ndef.NDEF_AddAAR(&_info);
370+
}
371+
372+
int ST25DV::appendBluetoothOOB(Ndef_Bluetooth_OOB_t bluetooth, char *recordId)
373+
{
374+
return ndef.NDEF_AppendBluetoothOOB(&bluetooth, recordId);
375+
}
376+
377+
int ST25DV::writeMyApp(sMyAppInfo *pMyAppStruct)
378+
{
379+
return ndef.NDEF_WriteMyApp(pMyAppStruct);
380+
}
381+
276382
/**
277383
* @brief reads the type of NDEF on the tag
278384
* @param None

src/ST25DVSensor.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class ST25DV {
3838
int begin(uint8_t *buffer, uint16_t bufferLength);
3939
int writeURI(String protocol, String uri, String info);
4040
int readURI(String *s);
41+
int writeText(String text, String iso_lang, NDEF_Text_encoding_t encoding);
42+
int readText(String *text);
4143
int writeUnabridgedURI(String uri, String info);
4244
int readUnabridgedURI(String *s);
4345
int writeSMS(String phoneNumber, String message, String info);
@@ -46,6 +48,13 @@ class ST25DV {
4648
int readGEO(String *latitude, String *longitude);
4749
int writeEMail(String emailAdd, String subject, String message, String info);
4850
int readEMail(String *emailAdd, String *subject, String *message);
51+
int writeWifi(String SSID, Ndef_Wifi_Authentication_t auth, Ndef_Wifi_Encryption_t enc, String key);
52+
int readWifi(sWifiTokenInfo *wifitoken);
53+
int writeVcard(sVcardInfo vcard);
54+
int readVcard(sVcardInfo *vcard);
55+
int appendAAR(String pkgName);
56+
int appendBluetoothOOB(Ndef_Bluetooth_OOB_t bluetooth, char *recordId);
57+
int writeMyApp(sMyAppInfo *pMyAppStruct);
4958
NDEF_TypeDef readNDEFType();
5059
NDEF *getNDEF();
5160

src/libNDEF/NDEF_class.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class NDEF {
115115
void NDEF_PrepareSMSMessage(sSMSInfo *pSMSStruct, uint8_t *pNDEFMessage, uint16_t *size);
116116

117117
//lib_NDEF_Text
118-
uint16_t NDEF_WriteText(char *text);
118+
uint16_t NDEF_WriteText(NDEF_Text_info_t *text_info);
119119
uint16_t NDEF_ReadText(sRecordInfo_t *pRecordStruct, NDEF_Text_info_t *pText);
120120

121121
//lib_NDEF_URI
@@ -131,7 +131,7 @@ class NDEF {
131131
int NDEF_getVcardPicture(uint8_t *pPayload, uint32_t PayloadSize, uint8_t *pPict);
132132

133133
//lib_NDEF_Wifi
134-
uint16_t NDEF_ReadWifiToken(struct sRecordInfo *pRecordStruct, sWifiTokenInfo *pWifiTokenStruct);
134+
uint16_t NDEF_ReadWifiToken(sRecordInfo *pRecordStruct, sWifiTokenInfo *pWifiTokenStruct);
135135
uint16_t NDEF_WriteWifiToken(sWifiTokenInfo *pWifiTokenStruct);
136136

137137
//lib_wrapper
@@ -180,7 +180,7 @@ class NDEF {
180180

181181

182182
//Vcard static
183-
void NDEF_FillVcardStruct(uint8_t *pPayload, uint32_t PayloadSize, char *pKeyWord, uint32_t SizeOfKeyWord, uint8_t *pString);
183+
void NDEF_FillVcardStruct(uint8_t *pPayload, uint32_t PayloadSize, const char *pKeyWord, uint32_t SizeOfKeyWord, uint8_t *pString);
184184
void NDEF_ExtractVcard(sRecordInfo_t *pRecordStruct, sVcardInfo *pVcardStruct);
185185

186186
//Wifi static

src/libNDEF/default_config.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
#ifndef _DEFAULT_CONFIG_H_
3+
#define _DEFAULT_CONFIG_H_
4+
5+
6+
#define NDEF_MAX_SIZE (512)
7+
#define NDEF_RECORD_MAX_SIZE (100)
8+
9+
#define URI_PROTOCOL_MAX_SIZE (20)
10+
#define URI_MESSAGE_MAX_SIZE (100)
11+
#define URI_INFO_MAX_SIZE (20)
12+
13+
14+
#define TEXT_MAX_SIZE (100)
15+
#define TEXT_LANGUAGE_CODE_MAX_SIZE (10)
16+
17+
#define SMS_PHONE_MAX_SIZE (16)
18+
#define SMS_MESSAGE_MAX_SIZE (400)
19+
#define SMS_INFO_MAX_SIZE (400)
20+
21+
#define GEO_LATITUDE_MAX_SIZE (20)
22+
#define GEO_LONGITUDE_MAX_SIZE (20)
23+
#define GEO_INFO_MAX_SIZE (100)
24+
25+
#define EMAIL_ADDRESS_MAX_SIZE (64)
26+
#define EMAIL_SUBJECT_MAX_SIZE (100)
27+
#define EMAIL_MESSAGE_MAX_SIZE (2000)
28+
#define EMAIL_INFO_MAX_SIZE (400)
29+
30+
#endif

src/libNDEF/lib_NDEF.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@
4343
{goto Error;} else
4444
#endif
4545

46+
#if __has_include("custom_config.h")
47+
#include "custom_config.h"
48+
#else
49+
#include "default_config.h"
50+
#endif
51+
52+
4653
/* Error codes for Higher level */
4754
#define NDEF_OK RESULTOK
4855
#define NDEF_ERROR ERRORCODE_GENERIC
@@ -51,11 +58,6 @@
5158
#define NDEF_ERROR_LOCKED 4
5259
#define NDEF_ERROR_NOT_FORMATED 5
5360

54-
//#define NDEF_MAX_SIZE NFC_DEVICE_MAX_NDEFMEMORY
55-
//#define NDEF_RECORD_MAX_SIZE (512)
56-
#define NDEF_MAX_SIZE (100)
57-
#define NDEF_RECORD_MAX_SIZE (100)
58-
5961
#define NDEF_SIZE_OFFSET 0
6062
#define FIRST_RECORD_OFFSET 0
6163

src/libNDEF/lib_NDEF_Geo.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
#include "lib_NDEF.h"
3636

3737
typedef struct {
38-
char Latitude[20];
39-
char Longitude[20];
40-
char Information[100];
38+
char Latitude[GEO_LATITUDE_MAX_SIZE];
39+
char Longitude[GEO_LONGITUDE_MAX_SIZE];
40+
char Information[GEO_INFO_MAX_SIZE];
4141
} sGeoInfo;
4242

4343
#endif /* __LIB_NDEF_GEO_H */

src/libNDEF/lib_NDEF_SMS.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636

3737

3838
typedef struct {
39-
char PhoneNumber[16];
40-
char Message[400];
41-
char Information[400];
39+
char PhoneNumber[SMS_PHONE_MAX_SIZE];
40+
char Message[SMS_MESSAGE_MAX_SIZE];
41+
char Information[SMS_INFO_MAX_SIZE];
4242
} sSMSInfo;
4343

4444
#endif /* __LIB_NDEF_SMS_H */

0 commit comments

Comments
 (0)