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.
Dependencies: M24SR NDefLib mbed
WriteUriCallbacks.h
00001 /** 00002 ****************************************************************************** 00003 * @file WriteUriCallbacks.h 00004 * @date 12/07/2017 00005 * @brief Class to write a URI tag. 00006 ****************************************************************************** 00007 * 00008 * COPYRIGHT(c) 2017 STMicroelectronics 00009 * 00010 * Redistribution and use in source and binary forms, with or without modification, 00011 * are permitted provided that the following conditions are met: 00012 * 1. Redistributions of source code must retain the above copyright notice, 00013 * this list of conditions and the following disclaimer. 00014 * 2. Redistributions in binary form must reproduce the above copyright notice, 00015 * this list of conditions and the following disclaimer in the documentation 00016 * and/or other materials provided with the distribution. 00017 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00018 * may be used to endorse or promote products derived from this software 00019 * without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00022 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00023 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00024 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00025 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00026 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00027 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00028 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00029 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00030 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 * 00032 ****************************************************************************** 00033 */ 00034 00035 #include "mbed.h" 00036 #include "NDefLib/RecordType/RecordURI.h" 00037 00038 /** 00039 * Chain of callback that will crate a Uri record and write it. 00040 * After each operation the class will switch on a led 00041 */ 00042 class WriteUriCallbacks : public NDefLib::NDefNfcTag::Callbacks { 00043 00044 DigitalOut &mOnOpenSession; 00045 DigitalOut &mOnWrite; 00046 DigitalOut &mOnCloseSession; 00047 NDefLib::Message *mMsg; 00048 00049 public: 00050 00051 /** 00052 * create the callback chain 00053 * @param onOpenSession led to switch on when the session open 00054 * @param onWrite led to switch on when the write end 00055 * @param onCloseSession led to switch on when the session end 00056 */ 00057 WriteUriCallbacks(DigitalOut &onOpenSession,DigitalOut &onWrite, 00058 DigitalOut &onCloseSession):mOnOpenSession(onOpenSession), 00059 mOnWrite(onWrite),mOnCloseSession(onCloseSession){}; 00060 00061 /** 00062 * crate the new message and write it 00063 * @param tag tag where write the message 00064 * @param success true if the session correctly open 00065 */ 00066 virtual void on_session_open(NDefLib::NDefNfcTag *tag,bool success) { 00067 if (!success) { 00068 printf("Error opening the session\r\n"); 00069 }//else 00070 printf("Session opened\r\n"); 00071 //ask to have an interrupt when the command finish 00072 mOnOpenSession=1; 00073 mOnCloseSession=0; 00074 00075 NDefLib::RecordURI *rUri = new NDefLib::RecordURI(NDefLib::RecordURI::HTTP_WWW,"http://www.st.com"); 00076 mMsg = new NDefLib::Message(); 00077 mMsg->add_record(rUri); 00078 00079 tag->write(*mMsg); 00080 } 00081 00082 /** 00083 * request to close the session 00084 * @param tag tag where close the session 00085 * @param success true if the message is correctly wrote 00086 * @param message wrote 00087 */ 00088 virtual void on_message_write(NDefLib::NDefNfcTag *tag,bool success) { 00089 00090 if (!success) { 00091 printf("Error writing tag!\r\n"); 00092 } else { 00093 printf("Tag written!\r\n"); 00094 mOnWrite=1; 00095 }//if-else 00096 00097 NDefLib::Message::remove_and_delete_all_record(*mMsg); 00098 delete mMsg; 00099 tag->close_session(); 00100 } 00101 00102 /** 00103 * switch on the led 00104 * @param tag where the session is closed 00105 * @param success true if the session is correctly close 00106 */ 00107 virtual void on_session_close(NDefLib::NDefNfcTag*, bool success) { 00108 if (success) { 00109 printf("Session closed\r\n"); 00110 mOnCloseSession=1; 00111 mOnOpenSession=0; 00112 mOnWrite=0; 00113 } else { 00114 printf("Error closing the session\r\n"); 00115 } 00116 } 00117 };
Generated on Mon Jul 18 2022 12:47:12 by
1.7.2