Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: NFC M2M_2016_STM32 MyongjiElec_capstone1 IDW01M1_Cloud_IBM ... more
Fork of NDefLib by
NDEF NFC library
This library provides an abstract API to create NDEF formatted messages and records and to read/write them from/to a Type4 NFC Tag.
Implementations
At the moment, the NDEF API is implemented by X_NUCLEO_NFC01A1 and X_NUCLEO_NFC02A1 Dynamic NFC Tag libraries respectively driving the X-NUCLEO-NFC01A1 and X-NUCLEO-NFC02A1 boards.
Revision 3:64bb6d5224dc, committed 2015-11-27
- Comitter:
- giovannivisentini
- Date:
- Fri Nov 27 15:09:55 2015 +0000
- Parent:
- 2:760e36ba9c23
- Child:
- 4:eaf6c49a86e4
- Commit message:
- create the Type4NFCTag class
Changed in this revision
| Type4NfcTag.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Type4NfcTag.h Fri Nov 27 15:09:55 2015 +0000
@@ -0,0 +1,67 @@
+/*
+ * Type4NfcTag.h
+ *
+ * Created on: Nov 5, 2015
+ * Author: giovanni visentini
+ */
+
+#ifndef TYPE4NFCTAG_H_
+#define TYPE4NFCTAG_H_
+
+#include "NDefLib/Message.h"
+
+namespace NDefLib {
+
+class Type4NfcTag {
+public:
+
+ virtual bool openSession(bool force = false)=0;
+ virtual bool closeSession()=0;
+
+ bool write(const Message &msg) {
+ const uint16_t length = msg.getByteLenght();
+ uint8_t *buffer = new uint8_t[length];
+ msg.write(buffer);
+ bool retValue = writeByte(buffer, length);
+ delete[] buffer;
+ return retValue;
+ }
+
+ bool read(Message *msg) {
+ uint16_t length = getMessageLength();
+ if (length == 0)
+ return false;
+ //else
+ uint8_t *buffer = new uint8_t[length];
+ bool retValue = readByte(2, length, buffer);
+ if (retValue) {
+ Message::parseMessage(buffer, length, msg);
+ }
+ delete[] buffer;
+ return retValue;
+ }
+
+ virtual ~Type4NfcTag() {
+ }
+ ;
+
+protected:
+ virtual bool writeByte(uint8_t *buffer, const uint16_t lenght)=0;
+ virtual bool readByte(const uint16_t byteOffset, const uint16_t byteLength,
+ uint8_t *buffer)=0;
+
+private:
+
+ uint16_t getMessageLength() {
+ uint8_t lenghtByte[2];
+ if (readByte(0, 2, lenghtByte))
+ return (((uint16_t) lenghtByte[0]) << 8 | lenghtByte[1]);
+ return 0;
+ } //getMessageLength
+
+};
+
+} /* namespace NDefLib */
+
+#endif /* TYPE4NFCTAG_H_ */
+
