Fork for the GitHub
lib_NDEF_Geo.cpp@0:de13951f30f6, 2019-11-14 (annotated)
- Committer:
- DiegoOstuni
- Date:
- Thu Nov 14 10:34:11 2019 +0000
- Revision:
- 0:de13951f30f6
Add files
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DiegoOstuni | 0:de13951f30f6 | 1 | /** |
DiegoOstuni | 0:de13951f30f6 | 2 | ****************************************************************************** |
DiegoOstuni | 0:de13951f30f6 | 3 | * @file lib_NDEF_Geo.c |
DiegoOstuni | 0:de13951f30f6 | 4 | * @author MMY Application Team |
DiegoOstuni | 0:de13951f30f6 | 5 | * @version $Revision: 2702 $ |
DiegoOstuni | 0:de13951f30f6 | 6 | * @date $Date: 2016-07-13 18:45:05 +0200 (Wed, 13 Jul 2016) $ |
DiegoOstuni | 0:de13951f30f6 | 7 | * @brief This file help to manage NDEF file that represent geolocation. |
DiegoOstuni | 0:de13951f30f6 | 8 | ****************************************************************************** |
DiegoOstuni | 0:de13951f30f6 | 9 | * @attention |
DiegoOstuni | 0:de13951f30f6 | 10 | * |
DiegoOstuni | 0:de13951f30f6 | 11 | * <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2> |
DiegoOstuni | 0:de13951f30f6 | 12 | * |
DiegoOstuni | 0:de13951f30f6 | 13 | * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); |
DiegoOstuni | 0:de13951f30f6 | 14 | * You may not use this file except in compliance with the License. |
DiegoOstuni | 0:de13951f30f6 | 15 | * You may obtain a copy of the License at: |
DiegoOstuni | 0:de13951f30f6 | 16 | * |
DiegoOstuni | 0:de13951f30f6 | 17 | * http://www.st.com/myliberty |
DiegoOstuni | 0:de13951f30f6 | 18 | * |
DiegoOstuni | 0:de13951f30f6 | 19 | * Unless required by applicable law or agreed to in writing, software |
DiegoOstuni | 0:de13951f30f6 | 20 | * distributed under the License is distributed on an "AS IS" BASIS, |
DiegoOstuni | 0:de13951f30f6 | 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, |
DiegoOstuni | 0:de13951f30f6 | 22 | * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, |
DiegoOstuni | 0:de13951f30f6 | 23 | * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. |
DiegoOstuni | 0:de13951f30f6 | 24 | * See the License for the specific language governing permissions and |
DiegoOstuni | 0:de13951f30f6 | 25 | * limitations under the License. |
DiegoOstuni | 0:de13951f30f6 | 26 | * |
DiegoOstuni | 0:de13951f30f6 | 27 | ****************************************************************************** |
DiegoOstuni | 0:de13951f30f6 | 28 | */ |
DiegoOstuni | 0:de13951f30f6 | 29 | |
DiegoOstuni | 0:de13951f30f6 | 30 | /* Includes ------------------------------------------------------------------*/ |
DiegoOstuni | 0:de13951f30f6 | 31 | #include "lib_NDEF_Geo.h" |
DiegoOstuni | 0:de13951f30f6 | 32 | |
DiegoOstuni | 0:de13951f30f6 | 33 | /** @addtogroup NFC_libraries |
DiegoOstuni | 0:de13951f30f6 | 34 | * @{ |
DiegoOstuni | 0:de13951f30f6 | 35 | * @brief <b>This is the library used to manage the content of the TAG (data) |
DiegoOstuni | 0:de13951f30f6 | 36 | * But also the specific feature of the tag, for instance |
DiegoOstuni | 0:de13951f30f6 | 37 | * password, gpo... </b> |
DiegoOstuni | 0:de13951f30f6 | 38 | */ |
DiegoOstuni | 0:de13951f30f6 | 39 | |
DiegoOstuni | 0:de13951f30f6 | 40 | |
DiegoOstuni | 0:de13951f30f6 | 41 | /** @addtogroup libNFC_FORUM |
DiegoOstuni | 0:de13951f30f6 | 42 | * @{ |
DiegoOstuni | 0:de13951f30f6 | 43 | * @brief This part of the library manage data which follow NFC forum organisation. |
DiegoOstuni | 0:de13951f30f6 | 44 | */ |
DiegoOstuni | 0:de13951f30f6 | 45 | |
DiegoOstuni | 0:de13951f30f6 | 46 | /** |
DiegoOstuni | 0:de13951f30f6 | 47 | * @brief This buffer contains the data send/received by TAG |
DiegoOstuni | 0:de13951f30f6 | 48 | */ |
DiegoOstuni | 0:de13951f30f6 | 49 | extern uint8_t NDEF_Buffer []; |
DiegoOstuni | 0:de13951f30f6 | 50 | |
DiegoOstuni | 0:de13951f30f6 | 51 | /** @defgroup libGeo_Private_Functions |
DiegoOstuni | 0:de13951f30f6 | 52 | * @{ |
DiegoOstuni | 0:de13951f30f6 | 53 | */ |
DiegoOstuni | 0:de13951f30f6 | 54 | |
DiegoOstuni | 0:de13951f30f6 | 55 | static void NDEF_FillGeoStruct( uint8_t* pPayload, uint32_t PayloadSize, sGeoInfo *pGeoStruct ); |
DiegoOstuni | 0:de13951f30f6 | 56 | static void NDEF_ReadURI_Geo( sRecordInfo_t *pRecordStruct, sGeoInfo *pGeoStruct ); |
DiegoOstuni | 0:de13951f30f6 | 57 | |
DiegoOstuni | 0:de13951f30f6 | 58 | /** |
DiegoOstuni | 0:de13951f30f6 | 59 | * @brief This function fill Geo structure with information of NDEF message. |
DiegoOstuni | 0:de13951f30f6 | 60 | * @param pPayload : pointer on the payload data of the NDEF message. |
DiegoOstuni | 0:de13951f30f6 | 61 | * @param PayloadSize : number of data in the payload. |
DiegoOstuni | 0:de13951f30f6 | 62 | * @param pGeoStruct : pointer on the structure to fill. |
DiegoOstuni | 0:de13951f30f6 | 63 | */ |
DiegoOstuni | 0:de13951f30f6 | 64 | static void NDEF_FillGeoStruct( uint8_t* pPayload, uint32_t PayloadSize, sGeoInfo *pGeoStruct ) |
DiegoOstuni | 0:de13951f30f6 | 65 | { |
DiegoOstuni | 0:de13951f30f6 | 66 | uint8_t* pLastByteAdd, *pLook4Word, *pEndString; |
DiegoOstuni | 0:de13951f30f6 | 67 | char* pKeyWord; |
DiegoOstuni | 0:de13951f30f6 | 68 | uint32_t SizeOfKeyWord; |
DiegoOstuni | 0:de13951f30f6 | 69 | pEndString = 0; |
DiegoOstuni | 0:de13951f30f6 | 70 | |
DiegoOstuni | 0:de13951f30f6 | 71 | pKeyWord = GEO_TYPE_STRING; |
DiegoOstuni | 0:de13951f30f6 | 72 | SizeOfKeyWord = GEO_TYPE_STRING_LENGTH; |
DiegoOstuni | 0:de13951f30f6 | 73 | |
DiegoOstuni | 0:de13951f30f6 | 74 | /* First character force to NULL in case not matching found */ |
DiegoOstuni | 0:de13951f30f6 | 75 | *pGeoStruct->Latitude = 0; |
DiegoOstuni | 0:de13951f30f6 | 76 | *pGeoStruct->Longitude = 0; |
DiegoOstuni | 0:de13951f30f6 | 77 | |
DiegoOstuni | 0:de13951f30f6 | 78 | /* Interresting information are stored before picture if any */ |
DiegoOstuni | 0:de13951f30f6 | 79 | /* Moreover picture is not used in this demonstration SW */ |
DiegoOstuni | 0:de13951f30f6 | 80 | pLastByteAdd = (uint8_t*)(pPayload + PayloadSize); |
DiegoOstuni | 0:de13951f30f6 | 81 | |
DiegoOstuni | 0:de13951f30f6 | 82 | pLook4Word = pPayload; |
DiegoOstuni | 0:de13951f30f6 | 83 | while( memcmp( pLook4Word, pKeyWord, SizeOfKeyWord ) && (pLook4Word < pLastByteAdd) ) |
DiegoOstuni | 0:de13951f30f6 | 84 | { |
DiegoOstuni | 0:de13951f30f6 | 85 | pLook4Word++; |
DiegoOstuni | 0:de13951f30f6 | 86 | } |
DiegoOstuni | 0:de13951f30f6 | 87 | |
DiegoOstuni | 0:de13951f30f6 | 88 | /* Retrieve phone number */ |
DiegoOstuni | 0:de13951f30f6 | 89 | if( pLook4Word != pLastByteAdd ) |
DiegoOstuni | 0:de13951f30f6 | 90 | { |
DiegoOstuni | 0:de13951f30f6 | 91 | pLook4Word += SizeOfKeyWord; |
DiegoOstuni | 0:de13951f30f6 | 92 | pEndString = pLook4Word; |
DiegoOstuni | 0:de13951f30f6 | 93 | while( memcmp( pEndString, URI_LATITUDE_END, URI_LATITUDE_END_LENGTH ) && (pEndString < pLastByteAdd) ) |
DiegoOstuni | 0:de13951f30f6 | 94 | { |
DiegoOstuni | 0:de13951f30f6 | 95 | pEndString++; |
DiegoOstuni | 0:de13951f30f6 | 96 | } |
DiegoOstuni | 0:de13951f30f6 | 97 | if( pEndString != pLastByteAdd ) |
DiegoOstuni | 0:de13951f30f6 | 98 | { |
DiegoOstuni | 0:de13951f30f6 | 99 | memcpy( pGeoStruct->Latitude, pLook4Word, pEndString-pLook4Word ); |
DiegoOstuni | 0:de13951f30f6 | 100 | /* add end of string character */ |
DiegoOstuni | 0:de13951f30f6 | 101 | pGeoStruct->Latitude[pEndString-pLook4Word] = 0; |
DiegoOstuni | 0:de13951f30f6 | 102 | } |
DiegoOstuni | 0:de13951f30f6 | 103 | } |
DiegoOstuni | 0:de13951f30f6 | 104 | pEndString += URI_LATITUDE_END_LENGTH; |
DiegoOstuni | 0:de13951f30f6 | 105 | pLook4Word = pEndString; |
DiegoOstuni | 0:de13951f30f6 | 106 | |
DiegoOstuni | 0:de13951f30f6 | 107 | memcpy( pGeoStruct->Longitude, pEndString, PayloadSize - (pEndString - pPayload) ); |
DiegoOstuni | 0:de13951f30f6 | 108 | /* add end of string character */ |
DiegoOstuni | 0:de13951f30f6 | 109 | pGeoStruct->Longitude[PayloadSize-(pEndString-pPayload)] = 0; |
DiegoOstuni | 0:de13951f30f6 | 110 | |
DiegoOstuni | 0:de13951f30f6 | 111 | } |
DiegoOstuni | 0:de13951f30f6 | 112 | |
DiegoOstuni | 0:de13951f30f6 | 113 | /** |
DiegoOstuni | 0:de13951f30f6 | 114 | * @brief This function read the geoloccation information and store data in a structure. |
DiegoOstuni | 0:de13951f30f6 | 115 | * @param pRecordStruct : Pointer on the record structure. |
DiegoOstuni | 0:de13951f30f6 | 116 | * @param pGeoStruct : pointer on the structure to fill. |
DiegoOstuni | 0:de13951f30f6 | 117 | */ |
DiegoOstuni | 0:de13951f30f6 | 118 | static void NDEF_ReadURI_Geo( sRecordInfo_t *pRecordStruct, sGeoInfo *pGeoStruct ) |
DiegoOstuni | 0:de13951f30f6 | 119 | { |
DiegoOstuni | 0:de13951f30f6 | 120 | uint8_t* pPayload; |
DiegoOstuni | 0:de13951f30f6 | 121 | uint32_t PayloadSize; |
DiegoOstuni | 0:de13951f30f6 | 122 | |
DiegoOstuni | 0:de13951f30f6 | 123 | PayloadSize = pRecordStruct->PayloadLength; |
DiegoOstuni | 0:de13951f30f6 | 124 | |
DiegoOstuni | 0:de13951f30f6 | 125 | /* Read record header */ |
DiegoOstuni | 0:de13951f30f6 | 126 | pPayload = (uint8_t*)(pRecordStruct->PayloadBufferAdd); |
DiegoOstuni | 0:de13951f30f6 | 127 | |
DiegoOstuni | 0:de13951f30f6 | 128 | if( pRecordStruct->NDEF_Type == URI_GEO_TYPE ) |
DiegoOstuni | 0:de13951f30f6 | 129 | NDEF_FillGeoStruct( pPayload , PayloadSize, pGeoStruct ); |
DiegoOstuni | 0:de13951f30f6 | 130 | |
DiegoOstuni | 0:de13951f30f6 | 131 | } |
DiegoOstuni | 0:de13951f30f6 | 132 | |
DiegoOstuni | 0:de13951f30f6 | 133 | /** |
DiegoOstuni | 0:de13951f30f6 | 134 | * @} |
DiegoOstuni | 0:de13951f30f6 | 135 | */ |
DiegoOstuni | 0:de13951f30f6 | 136 | |
DiegoOstuni | 0:de13951f30f6 | 137 | /** @defgroup libGeo_Public_Functions |
DiegoOstuni | 0:de13951f30f6 | 138 | * @{ |
DiegoOstuni | 0:de13951f30f6 | 139 | * @brief This file is used to manage geolocation (stored or loaded in tag) |
DiegoOstuni | 0:de13951f30f6 | 140 | */ |
DiegoOstuni | 0:de13951f30f6 | 141 | |
DiegoOstuni | 0:de13951f30f6 | 142 | /** |
DiegoOstuni | 0:de13951f30f6 | 143 | * @brief This function read NDEF and retrieve Geo information if any. |
DiegoOstuni | 0:de13951f30f6 | 144 | * @param pRecordStruct : Pointer on the record structure. |
DiegoOstuni | 0:de13951f30f6 | 145 | * @param pGeoStruct : pointer on the structure to fill . |
DiegoOstuni | 0:de13951f30f6 | 146 | * @retval NDEF_OK : Geolocation information from NDEF have been retrieved. |
DiegoOstuni | 0:de13951f30f6 | 147 | * @retval NDEF_ERROR : not able to read NDEF from tag. |
DiegoOstuni | 0:de13951f30f6 | 148 | */ |
DiegoOstuni | 0:de13951f30f6 | 149 | uint16_t NDEF_ReadGeo( sRecordInfo_t *pRecordStruct, sGeoInfo *pGeoStruct ) |
DiegoOstuni | 0:de13951f30f6 | 150 | { |
DiegoOstuni | 0:de13951f30f6 | 151 | uint16_t status = NDEF_ERROR; |
DiegoOstuni | 0:de13951f30f6 | 152 | sRecordInfo_t *pSPRecordStruct; |
DiegoOstuni | 0:de13951f30f6 | 153 | uint32_t PayloadSize, RecordPosition; |
DiegoOstuni | 0:de13951f30f6 | 154 | uint8_t* pData; |
DiegoOstuni | 0:de13951f30f6 | 155 | |
DiegoOstuni | 0:de13951f30f6 | 156 | if( pRecordStruct->NDEF_Type == URI_GEO_TYPE ) |
DiegoOstuni | 0:de13951f30f6 | 157 | { |
DiegoOstuni | 0:de13951f30f6 | 158 | NDEF_ReadURI_Geo( pRecordStruct, pGeoStruct ); |
DiegoOstuni | 0:de13951f30f6 | 159 | status = NDEF_OK; |
DiegoOstuni | 0:de13951f30f6 | 160 | } |
DiegoOstuni | 0:de13951f30f6 | 161 | else if( pRecordStruct->NDEF_Type == SMARTPOSTER_TYPE ) |
DiegoOstuni | 0:de13951f30f6 | 162 | { |
DiegoOstuni | 0:de13951f30f6 | 163 | for( RecordPosition = 0; RecordPosition < pRecordStruct->NbOfRecordInSPPayload; RecordPosition++ ) |
DiegoOstuni | 0:de13951f30f6 | 164 | { |
DiegoOstuni | 0:de13951f30f6 | 165 | pSPRecordStruct = pRecordStruct->SPRecordStructAdd[RecordPosition]; |
DiegoOstuni | 0:de13951f30f6 | 166 | if( pSPRecordStruct->NDEF_Type == URI_GEO_TYPE ) |
DiegoOstuni | 0:de13951f30f6 | 167 | { |
DiegoOstuni | 0:de13951f30f6 | 168 | NDEF_ReadURI_Geo( pSPRecordStruct, pGeoStruct ); |
DiegoOstuni | 0:de13951f30f6 | 169 | status = NDEF_OK; |
DiegoOstuni | 0:de13951f30f6 | 170 | } |
DiegoOstuni | 0:de13951f30f6 | 171 | if( pSPRecordStruct->NDEF_Type == TEXT_TYPE ) |
DiegoOstuni | 0:de13951f30f6 | 172 | { |
DiegoOstuni | 0:de13951f30f6 | 173 | PayloadSize = pSPRecordStruct->PayloadLength; |
DiegoOstuni | 0:de13951f30f6 | 174 | |
DiegoOstuni | 0:de13951f30f6 | 175 | /* The instruction content the UTF-8 language code that is not used here */ |
DiegoOstuni | 0:de13951f30f6 | 176 | pData = (uint8_t*)pSPRecordStruct->PayloadBufferAdd; |
DiegoOstuni | 0:de13951f30f6 | 177 | PayloadSize -= *pData + 1; /* remove not usefull data */ |
DiegoOstuni | 0:de13951f30f6 | 178 | pData += *pData + 1; /* set pointer on usefull data */ |
DiegoOstuni | 0:de13951f30f6 | 179 | |
DiegoOstuni | 0:de13951f30f6 | 180 | memcpy( pGeoStruct->Information, pData, PayloadSize ); |
DiegoOstuni | 0:de13951f30f6 | 181 | /* add end of string character */ |
DiegoOstuni | 0:de13951f30f6 | 182 | pGeoStruct->Information[PayloadSize] = 0; |
DiegoOstuni | 0:de13951f30f6 | 183 | } |
DiegoOstuni | 0:de13951f30f6 | 184 | } |
DiegoOstuni | 0:de13951f30f6 | 185 | } |
DiegoOstuni | 0:de13951f30f6 | 186 | |
DiegoOstuni | 0:de13951f30f6 | 187 | return status; |
DiegoOstuni | 0:de13951f30f6 | 188 | } |
DiegoOstuni | 0:de13951f30f6 | 189 | |
DiegoOstuni | 0:de13951f30f6 | 190 | /** |
DiegoOstuni | 0:de13951f30f6 | 191 | * @brief This function write the NDEF file with the geolocation data given in the structure. |
DiegoOstuni | 0:de13951f30f6 | 192 | * @param pGeoStruct : pointer on structure that contain the geolocation information. |
DiegoOstuni | 0:de13951f30f6 | 193 | * @retval NDEF_OK : the function is succesful. |
DiegoOstuni | 0:de13951f30f6 | 194 | * @retval NDEF_ERROR_MEMORY_INTERNAL : Cannot write to tag. |
DiegoOstuni | 0:de13951f30f6 | 195 | * @retval NDEF_ERROR_NOT_FORMATED : CCFile data not supported or not present. |
DiegoOstuni | 0:de13951f30f6 | 196 | * @retval NDEF_ERROR_MEMORY_TAG : Size not compatible with memory. |
DiegoOstuni | 0:de13951f30f6 | 197 | * @retval NDEF_ERROR_LOCKED : Tag locked, cannot be write. |
DiegoOstuni | 0:de13951f30f6 | 198 | */ |
DiegoOstuni | 0:de13951f30f6 | 199 | uint16_t NDEF_WriteGeo( sGeoInfo *pGeoStruct, I2C* mi2cChannel ) |
DiegoOstuni | 0:de13951f30f6 | 200 | { |
DiegoOstuni | 0:de13951f30f6 | 201 | uint16_t status = NDEF_ERROR,Offset = 0; |
DiegoOstuni | 0:de13951f30f6 | 202 | |
DiegoOstuni | 0:de13951f30f6 | 203 | NDEF_PrepareGeoMessage( pGeoStruct, NDEF_Buffer, &Offset ); |
DiegoOstuni | 0:de13951f30f6 | 204 | |
DiegoOstuni | 0:de13951f30f6 | 205 | status = NfcTag_WriteNDEF( Offset, NDEF_Buffer, mi2cChannel ); |
DiegoOstuni | 0:de13951f30f6 | 206 | |
DiegoOstuni | 0:de13951f30f6 | 207 | return status; |
DiegoOstuni | 0:de13951f30f6 | 208 | } |
DiegoOstuni | 0:de13951f30f6 | 209 | |
DiegoOstuni | 0:de13951f30f6 | 210 | /** |
DiegoOstuni | 0:de13951f30f6 | 211 | * @brief This function write the NDEF file with the geolocation data given in the structure. |
DiegoOstuni | 0:de13951f30f6 | 212 | * @param pGeoStruct : pointer on structure that contain the geolocation information. |
DiegoOstuni | 0:de13951f30f6 | 213 | * @param pNDEFMessage : pointer on the NDEF message. |
DiegoOstuni | 0:de13951f30f6 | 214 | * @param size : to store the size of the NDEF message generated. |
DiegoOstuni | 0:de13951f30f6 | 215 | */ |
DiegoOstuni | 0:de13951f30f6 | 216 | void NDEF_PrepareGeoMessage( sGeoInfo *pGeoStruct, uint8_t *pNDEFMessage, uint16_t *size ) |
DiegoOstuni | 0:de13951f30f6 | 217 | { |
DiegoOstuni | 0:de13951f30f6 | 218 | uint16_t Offset = 0; |
DiegoOstuni | 0:de13951f30f6 | 219 | uint32_t geoSize = 0; |
DiegoOstuni | 0:de13951f30f6 | 220 | uint32_t infoSize = 0; |
DiegoOstuni | 0:de13951f30f6 | 221 | uint32_t totalSize = 0; |
DiegoOstuni | 0:de13951f30f6 | 222 | |
DiegoOstuni | 0:de13951f30f6 | 223 | /* GEO is an URI but can be included in a smart poster to add text to give instruction to user for instance */ |
DiegoOstuni | 0:de13951f30f6 | 224 | |
DiegoOstuni | 0:de13951f30f6 | 225 | /* GEO (smart poster) Record Header */ |
DiegoOstuni | 0:de13951f30f6 | 226 | /************************************/ |
DiegoOstuni | 0:de13951f30f6 | 227 | /* 7 | 6 | 5 | 4 | 3 | 2 1 0 */ |
DiegoOstuni | 0:de13951f30f6 | 228 | /*----------------------------------*/ |
DiegoOstuni | 0:de13951f30f6 | 229 | /* MB ME CF SR IL TNF */ /* <---- CF=0, IL=0 and SR=1 TNF=1 NFC Forum Well-known type*/ |
DiegoOstuni | 0:de13951f30f6 | 230 | /*----------------------------------*/ |
DiegoOstuni | 0:de13951f30f6 | 231 | /* TYPE LENGTH */ |
DiegoOstuni | 0:de13951f30f6 | 232 | /*----------------------------------*/ |
DiegoOstuni | 0:de13951f30f6 | 233 | /* PAYLOAD LENGTH 3 */ /* <---- Used only if SR=0 */ |
DiegoOstuni | 0:de13951f30f6 | 234 | /*----------------------------------*/ |
DiegoOstuni | 0:de13951f30f6 | 235 | /* PAYLOAD LENGTH 2 */ /* <---- Used only if SR=0 */ |
DiegoOstuni | 0:de13951f30f6 | 236 | /*----------------------------------*/ |
DiegoOstuni | 0:de13951f30f6 | 237 | /* PAYLOAD LENGTH 1 */ /* <---- Used only if SR=0 */ |
DiegoOstuni | 0:de13951f30f6 | 238 | /*----------------------------------*/ |
DiegoOstuni | 0:de13951f30f6 | 239 | /* PAYLOAD LENGTH 0 */ |
DiegoOstuni | 0:de13951f30f6 | 240 | /*----------------------------------*/ |
DiegoOstuni | 0:de13951f30f6 | 241 | /* ID LENGTH */ /* <---- Not Used */ |
DiegoOstuni | 0:de13951f30f6 | 242 | /*----------------------------------*/ |
DiegoOstuni | 0:de13951f30f6 | 243 | /* TYPE */ |
DiegoOstuni | 0:de13951f30f6 | 244 | /*----------------------------------*/ |
DiegoOstuni | 0:de13951f30f6 | 245 | /* ID */ /* <---- Not Used */ |
DiegoOstuni | 0:de13951f30f6 | 246 | /************************************/ |
DiegoOstuni | 0:de13951f30f6 | 247 | |
DiegoOstuni | 0:de13951f30f6 | 248 | /* GEO : 1+geo:+latitude+1+longitude */ |
DiegoOstuni | 0:de13951f30f6 | 249 | geoSize = 1 + GEO_TYPE_STRING_LENGTH + strlen(pGeoStruct->Latitude) + URI_LATITUDE_END_LENGTH + strlen(pGeoStruct->Longitude); |
DiegoOstuni | 0:de13951f30f6 | 250 | |
DiegoOstuni | 0:de13951f30f6 | 251 | /* Check if a Smart poster is needed */ |
DiegoOstuni | 0:de13951f30f6 | 252 | if( pGeoStruct->Information[0] != '\0' ) |
DiegoOstuni | 0:de13951f30f6 | 253 | { |
DiegoOstuni | 0:de13951f30f6 | 254 | /* Info : 1+2+info */ |
DiegoOstuni | 0:de13951f30f6 | 255 | infoSize = 1 + ISO_ENGLISH_CODE_STRING_LENGTH + strlen(pGeoStruct->Information); |
DiegoOstuni | 0:de13951f30f6 | 256 | /* Total */ |
DiegoOstuni | 0:de13951f30f6 | 257 | totalSize = 4 + geoSize + 4 + infoSize; |
DiegoOstuni | 0:de13951f30f6 | 258 | if( geoSize > 255 ) totalSize += 3; /* Normal Geo size */ |
DiegoOstuni | 0:de13951f30f6 | 259 | if( infoSize > 255 ) totalSize += 3; /* Normal Info size */ |
DiegoOstuni | 0:de13951f30f6 | 260 | |
DiegoOstuni | 0:de13951f30f6 | 261 | /* SmartPoster header */ |
DiegoOstuni | 0:de13951f30f6 | 262 | if( totalSize > 255 ) |
DiegoOstuni | 0:de13951f30f6 | 263 | { |
DiegoOstuni | 0:de13951f30f6 | 264 | pNDEFMessage[Offset++] = 0xC1; |
DiegoOstuni | 0:de13951f30f6 | 265 | pNDEFMessage[Offset++] = SMART_POSTER_TYPE_STRING_LENGTH; |
DiegoOstuni | 0:de13951f30f6 | 266 | pNDEFMessage[Offset++] = (totalSize & 0xFF000000) >> 24; |
DiegoOstuni | 0:de13951f30f6 | 267 | pNDEFMessage[Offset++] = (totalSize & 0x00FF0000) >> 16; |
DiegoOstuni | 0:de13951f30f6 | 268 | pNDEFMessage[Offset++] = (totalSize & 0x0000FF00) >> 8; |
DiegoOstuni | 0:de13951f30f6 | 269 | pNDEFMessage[Offset++] = totalSize & 0x000000FF; |
DiegoOstuni | 0:de13951f30f6 | 270 | } |
DiegoOstuni | 0:de13951f30f6 | 271 | else |
DiegoOstuni | 0:de13951f30f6 | 272 | { |
DiegoOstuni | 0:de13951f30f6 | 273 | pNDEFMessage[Offset++] = 0xD1; |
DiegoOstuni | 0:de13951f30f6 | 274 | pNDEFMessage[Offset++] = SMART_POSTER_TYPE_STRING_LENGTH; |
DiegoOstuni | 0:de13951f30f6 | 275 | pNDEFMessage[Offset++] = (uint8_t)totalSize; |
DiegoOstuni | 0:de13951f30f6 | 276 | } |
DiegoOstuni | 0:de13951f30f6 | 277 | memcpy( &pNDEFMessage[Offset], SMART_POSTER_TYPE_STRING, SMART_POSTER_TYPE_STRING_LENGTH ); |
DiegoOstuni | 0:de13951f30f6 | 278 | Offset += SMART_POSTER_TYPE_STRING_LENGTH; |
DiegoOstuni | 0:de13951f30f6 | 279 | } |
DiegoOstuni | 0:de13951f30f6 | 280 | |
DiegoOstuni | 0:de13951f30f6 | 281 | /* GEO header */ |
DiegoOstuni | 0:de13951f30f6 | 282 | pNDEFMessage[Offset] = 0x81; |
DiegoOstuni | 0:de13951f30f6 | 283 | if( geoSize < 256 ) pNDEFMessage[Offset] |= 0x10; // Set the SR bit |
DiegoOstuni | 0:de13951f30f6 | 284 | if( pGeoStruct->Information[0] == '\0' ) pNDEFMessage[Offset] |= 0x40; // Set the ME bit |
DiegoOstuni | 0:de13951f30f6 | 285 | Offset++; |
DiegoOstuni | 0:de13951f30f6 | 286 | |
DiegoOstuni | 0:de13951f30f6 | 287 | pNDEFMessage[Offset++] = URI_TYPE_STRING_LENGTH; |
DiegoOstuni | 0:de13951f30f6 | 288 | if( geoSize > 255 ) |
DiegoOstuni | 0:de13951f30f6 | 289 | { |
DiegoOstuni | 0:de13951f30f6 | 290 | pNDEFMessage[Offset++] = (geoSize & 0xFF000000) >> 24; |
DiegoOstuni | 0:de13951f30f6 | 291 | pNDEFMessage[Offset++] = (geoSize & 0x00FF0000) >> 16; |
DiegoOstuni | 0:de13951f30f6 | 292 | pNDEFMessage[Offset++] = (geoSize & 0x0000FF00) >> 8; |
DiegoOstuni | 0:de13951f30f6 | 293 | pNDEFMessage[Offset++] = geoSize & 0x000000FF; |
DiegoOstuni | 0:de13951f30f6 | 294 | } |
DiegoOstuni | 0:de13951f30f6 | 295 | else |
DiegoOstuni | 0:de13951f30f6 | 296 | { |
DiegoOstuni | 0:de13951f30f6 | 297 | pNDEFMessage[Offset++] = (uint8_t)geoSize; |
DiegoOstuni | 0:de13951f30f6 | 298 | } |
DiegoOstuni | 0:de13951f30f6 | 299 | memcpy( &pNDEFMessage[Offset], URI_TYPE_STRING, URI_TYPE_STRING_LENGTH ); |
DiegoOstuni | 0:de13951f30f6 | 300 | Offset += URI_TYPE_STRING_LENGTH; |
DiegoOstuni | 0:de13951f30f6 | 301 | |
DiegoOstuni | 0:de13951f30f6 | 302 | /* GEO payload */ |
DiegoOstuni | 0:de13951f30f6 | 303 | pNDEFMessage[Offset++] = URI_ID_0x00; /* URI identifier no abbreviation */ |
DiegoOstuni | 0:de13951f30f6 | 304 | memcpy( &pNDEFMessage[Offset], GEO_TYPE_STRING, GEO_TYPE_STRING_LENGTH ); |
DiegoOstuni | 0:de13951f30f6 | 305 | Offset += GEO_TYPE_STRING_LENGTH; |
DiegoOstuni | 0:de13951f30f6 | 306 | memcpy( &pNDEFMessage[Offset], pGeoStruct->Latitude, strlen(pGeoStruct->Latitude) ); |
DiegoOstuni | 0:de13951f30f6 | 307 | Offset += strlen( pGeoStruct->Latitude ); |
DiegoOstuni | 0:de13951f30f6 | 308 | memcpy( &pNDEFMessage[Offset], URI_LATITUDE_END, URI_LATITUDE_END_LENGTH ); |
DiegoOstuni | 0:de13951f30f6 | 309 | Offset += URI_LATITUDE_END_LENGTH; |
DiegoOstuni | 0:de13951f30f6 | 310 | memcpy( &pNDEFMessage[Offset], pGeoStruct->Longitude, strlen(pGeoStruct->Longitude) ); |
DiegoOstuni | 0:de13951f30f6 | 311 | Offset += strlen( pGeoStruct->Longitude ); |
DiegoOstuni | 0:de13951f30f6 | 312 | |
DiegoOstuni | 0:de13951f30f6 | 313 | /* Information header */ |
DiegoOstuni | 0:de13951f30f6 | 314 | if( pGeoStruct->Information[0] != '\0' ) |
DiegoOstuni | 0:de13951f30f6 | 315 | { |
DiegoOstuni | 0:de13951f30f6 | 316 | if( infoSize > 255 ) |
DiegoOstuni | 0:de13951f30f6 | 317 | { |
DiegoOstuni | 0:de13951f30f6 | 318 | pNDEFMessage[Offset++] = 0x41; |
DiegoOstuni | 0:de13951f30f6 | 319 | pNDEFMessage[Offset++] = TEXT_TYPE_STRING_LENGTH; |
DiegoOstuni | 0:de13951f30f6 | 320 | pNDEFMessage[Offset++] = (infoSize & 0xFF000000) >> 24; |
DiegoOstuni | 0:de13951f30f6 | 321 | pNDEFMessage[Offset++] = (infoSize & 0x00FF0000) >> 16; |
DiegoOstuni | 0:de13951f30f6 | 322 | pNDEFMessage[Offset++] = (infoSize & 0x0000FF00) >> 8; |
DiegoOstuni | 0:de13951f30f6 | 323 | pNDEFMessage[Offset++] = infoSize & 0x000000FF; |
DiegoOstuni | 0:de13951f30f6 | 324 | } |
DiegoOstuni | 0:de13951f30f6 | 325 | else |
DiegoOstuni | 0:de13951f30f6 | 326 | { |
DiegoOstuni | 0:de13951f30f6 | 327 | pNDEFMessage[Offset++] = 0x51; |
DiegoOstuni | 0:de13951f30f6 | 328 | pNDEFMessage[Offset++] = TEXT_TYPE_STRING_LENGTH; |
DiegoOstuni | 0:de13951f30f6 | 329 | pNDEFMessage[Offset++] = (uint8_t)infoSize; |
DiegoOstuni | 0:de13951f30f6 | 330 | } |
DiegoOstuni | 0:de13951f30f6 | 331 | |
DiegoOstuni | 0:de13951f30f6 | 332 | memcpy( &pNDEFMessage[Offset], TEXT_TYPE_STRING, TEXT_TYPE_STRING_LENGTH ); |
DiegoOstuni | 0:de13951f30f6 | 333 | Offset += TEXT_TYPE_STRING_LENGTH; |
DiegoOstuni | 0:de13951f30f6 | 334 | pNDEFMessage[Offset++] = ISO_ENGLISH_CODE_STRING_LENGTH; /* UTF-8 with x byte language code */ |
DiegoOstuni | 0:de13951f30f6 | 335 | memcpy( &pNDEFMessage[Offset], ISO_ENGLISH_CODE_STRING, ISO_ENGLISH_CODE_STRING_LENGTH ); |
DiegoOstuni | 0:de13951f30f6 | 336 | Offset += ISO_ENGLISH_CODE_STRING_LENGTH; |
DiegoOstuni | 0:de13951f30f6 | 337 | |
DiegoOstuni | 0:de13951f30f6 | 338 | /* Information payload */ |
DiegoOstuni | 0:de13951f30f6 | 339 | memcpy( &pNDEFMessage[Offset], pGeoStruct->Information, strlen(pGeoStruct->Information) ); |
DiegoOstuni | 0:de13951f30f6 | 340 | Offset += strlen( pGeoStruct->Information ); |
DiegoOstuni | 0:de13951f30f6 | 341 | } |
DiegoOstuni | 0:de13951f30f6 | 342 | |
DiegoOstuni | 0:de13951f30f6 | 343 | *size = (uint16_t)(Offset); |
DiegoOstuni | 0:de13951f30f6 | 344 | } |
DiegoOstuni | 0:de13951f30f6 | 345 | |
DiegoOstuni | 0:de13951f30f6 | 346 | /** |
DiegoOstuni | 0:de13951f30f6 | 347 | * @} |
DiegoOstuni | 0:de13951f30f6 | 348 | */ |
DiegoOstuni | 0:de13951f30f6 | 349 | |
DiegoOstuni | 0:de13951f30f6 | 350 | /** |
DiegoOstuni | 0:de13951f30f6 | 351 | * @} |
DiegoOstuni | 0:de13951f30f6 | 352 | */ |
DiegoOstuni | 0:de13951f30f6 | 353 | |
DiegoOstuni | 0:de13951f30f6 | 354 | /** |
DiegoOstuni | 0:de13951f30f6 | 355 | * @} |
DiegoOstuni | 0:de13951f30f6 | 356 | */ |
DiegoOstuni | 0:de13951f30f6 | 357 | |
DiegoOstuni | 0:de13951f30f6 | 358 | /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/ |