This application provides a set of demos with X-NUCLEO-NFC01A1 expansion board.
Dependencies: NDefLib X_NUCLEO_NFC01A1 mbed
Fork of X-MBED-NFC1 by
This application provides a set of demos with X-NUCLEO-NFC01A1 expansion board.
The available demos are:
- SAMPLE_WRITE_URL: write a tag with the ST home page URL
- SAMPLE_COUNT_CLICK: create a custom tag to count and report the user button clicks.
- SAMPLE_WRITE_AND_CHANGE_ALL: write a tag with all the supported records and update the tag contents when the user button is pressed.
- SAMPLE_LOCK_TAG_CONTENT: use the M24SR component API to set the NFC tag as read-only.
To enable the different demos comment/uncomment the SAMPLE_* macros provided in main.cpp .
Diff: Type4NfcTagSTM24SR.h
- Revision:
- 2:0648c1561eb2
- Parent:
- 1:6d202b62ed68
--- a/Type4NfcTagSTM24SR.h Fri Nov 27 15:10:25 2015 +0000
+++ b/Type4NfcTagSTM24SR.h Tue Dec 01 08:30:54 2015 +0000
@@ -12,26 +12,36 @@
#include "NDefLib/Type4NfcTag.h"
+/**
+ * implement the abstract method for use the NDefLib
+ */
class Type4NfcTagSTM24SR: public NDefLib::Type4NfcTag {
public:
+ /**
+ *
+ * @param device device where write the Ndef tags
+ */
Type4NfcTagSTM24SR(M24SR &device) :
- mDevice(device), mSessionIsOpen(false), mMaxReadBytes(0xFF), mMaxWriteBytes(
+ mDevice(device), mMaxReadBytes(0xFF), mMaxWriteBytes(
0xFF) {
}
+
virtual bool openSession(bool force = false);
virtual bool closeSession();
+ /**
+ * close the open session
+ */
virtual ~Type4NfcTagSTM24SR() {
- if (mSessionIsOpen)
+ if(isSessionOpen())
closeSession();
- }
- ;
+ }//~Type4NfcTagSTM24SR
bool enableReadPassword(const uint8_t* pCurrentWritePassword,
const uint8_t* pNewPassword) {
- if (!mSessionIsOpen)
+ if (!isSessionOpen())
return false;
if (mDevice.Verify(M24SR::WritePwd, 0x10, pCurrentWritePassword)
@@ -48,7 +58,7 @@
}
bool disableReadPassword(const uint8_t* pCurrentWritePassword) {
- if (!mSessionIsOpen)
+ if (!isSessionOpen())
return false;
if (mDevice.Verify(M24SR::WritePwd, 0x10, pCurrentWritePassword)
@@ -64,7 +74,7 @@
bool enableWritePassword(const uint8_t* pCurrentWritePassword,
uint8_t* pNewPassword) {
- if (!mSessionIsOpen)
+ if (!isSessionOpen())
return false;
/* check we have the good password */
@@ -73,7 +83,6 @@
/* Set new password */
if (mDevice.ChangeReferenceData(M24SR::WritePwd, pNewPassword)
== NFC_SUCCESS)
- ;
return mDevice.EnableVerificationRequirement(M24SR::WritePwd)
== NFC_SUCCESS;
}
@@ -81,7 +90,7 @@
}
bool disableWritePassword(const uint8_t* pCurrentWritePassword) {
- if (!mSessionIsOpen)
+ if (!isSessionOpen())
return false;
if (mDevice.Verify(M24SR::WritePwd, 0x10, pCurrentWritePassword)
@@ -98,7 +107,7 @@
* @retval ERROR : operation does not complete
*/
bool disableAllPassword(const uint8_t* pSuperUserPassword) {
- if (!mSessionIsOpen)
+ if (!isSessionOpen())
return false;
if (mDevice.Verify(M24SR::WritePwd, 0x10, pSuperUserPassword)
@@ -124,7 +133,7 @@
* @retval ERROR : operation does not complete
*/
bool enableReadOnly(const uint8_t* pCurrentWritePassword) {
- if (!mSessionIsOpen)
+ if (!isSessionOpen())
return false;
if (mDevice.Verify(M24SR::WritePwd, 0x10, pCurrentWritePassword)
@@ -142,7 +151,7 @@
* @retval ERROR : operation does not complete
*/
bool disableReadOnly() {
- if (!mSessionIsOpen)
+ if (!isSessionOpen())
return false;
if (mDevice.Verify(M24SR::I2CPwd, 0x10, M24SR::DEFAULT_PASSWORD)
@@ -162,7 +171,7 @@
* @retval ERROR : operation does not complete
*/
bool enableWriteOnly(const uint8_t* pCurrentWritePassword) {
- if (!mSessionIsOpen)
+ if (!isSessionOpen())
return false;
if (mDevice.Verify(M24SR::WritePwd, 0x10, pCurrentWritePassword)
@@ -180,7 +189,7 @@
* @retval ERROR : operation does not complete
*/
bool disableWriteOnly() {
- if (!mSessionIsOpen)
+ if (!isSessionOpen())
return false;
if (mDevice.Verify(M24SR::I2CPwd, 0x10, M24SR::DEFAULT_PASSWORD)
@@ -194,15 +203,22 @@
}
protected:
- virtual bool writeByte(uint8_t *buffer, const uint16_t lenght);
+ virtual bool writeByte(const uint8_t *buffer, const uint16_t length, uint16_t offset);
virtual bool readByte(const uint16_t byteOffset, const uint16_t byteLength,
uint8_t *buffer);
private:
M24SR &mDevice;
- bool mSessionIsOpen;
+
+ /**
+ * max length for a read operation
+ */
uint16_t mMaxReadBytes;
+
+ /**
+ * max length for a write operation
+ */
uint16_t mMaxWriteBytes;
};
