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: TYBLE16_simple_data_logger TYBLE16_MP3_Air
NFCNDEFCapable.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2018 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #include "NFCNDEFCapable.h" 00018 00019 #include "acore/ac_buffer.h" 00020 #include "acore/ac_buffer_reader.h" 00021 #include "acore/ac_buffer_builder.h" 00022 00023 #include "ndef/ndef.h" 00024 00025 using namespace mbed; 00026 using namespace mbed::nfc; 00027 00028 NFCNDEFCapable::NFCNDEFCapable(const Span<uint8_t> &buffer) 00029 { 00030 ndef_msg_init(&_ndef_message, s_ndef_encode, s_ndef_decode, buffer.data(), buffer.size(), this); 00031 } 00032 00033 void NFCNDEFCapable::parse_ndef_message(const ac_buffer_t &buffer) 00034 { 00035 ac_buffer_t reader; 00036 ac_buffer_dup(&reader, &buffer); 00037 00038 Delegate *delegate = ndef_capable_delegate(); 00039 if (delegate != NULL) { 00040 delegate->parse_ndef_message(make_const_Span(ac_buffer_reader_current_buffer_pointer(&reader), ac_buffer_reader_current_buffer_length(&reader))); 00041 } 00042 } 00043 00044 void NFCNDEFCapable::build_ndef_message(ac_buffer_builder_t &buffer_builder) 00045 { 00046 Delegate *delegate = ndef_capable_delegate(); 00047 if (delegate != NULL) { 00048 size_t count = delegate->build_ndef_message(make_Span(ac_buffer_builder_write_position(&buffer_builder), ac_buffer_builder_writable(&buffer_builder))); 00049 ac_buffer_builder_write_n_skip(&buffer_builder, count); 00050 } 00051 } 00052 00053 nfc_err_t NFCNDEFCapable::s_ndef_encode(ndef_msg_t *pTag, ac_buffer_builder_t *pBufferBldr, void *pUserData) 00054 { 00055 NFCNDEFCapable *self = (NFCNDEFCapable *)pUserData; 00056 return self->ndef_encode(pBufferBldr); 00057 } 00058 00059 nfc_err_t NFCNDEFCapable::s_ndef_decode(ndef_msg_t *pTag, ac_buffer_t *pBuffer, void *pUserData) 00060 { 00061 NFCNDEFCapable *self = (NFCNDEFCapable *)pUserData; 00062 return self->ndef_decode(pBuffer); 00063 } 00064 00065 nfc_err_t NFCNDEFCapable::ndef_encode(ac_buffer_builder_t *pBufferBldr) 00066 { 00067 build_ndef_message(*pBufferBldr); 00068 return NFC_OK; 00069 } 00070 00071 nfc_err_t NFCNDEFCapable::ndef_decode(ac_buffer_t *pBuffer) 00072 { 00073 parse_ndef_message(*pBuffer); 00074 return NFC_OK; 00075 } 00076 00077 ndef_msg_t *NFCNDEFCapable::ndef_message() 00078 { 00079 return &_ndef_message; 00080 } 00081 00082 NFCNDEFCapable::Delegate *NFCNDEFCapable::ndef_capable_delegate() 00083 { 00084 return NULL; 00085 }
Generated on Tue Jul 12 2022 13:54:38 by
