Port of TI's CC3100 Websock camera demo. Using FreeRTOS, mbedTLS, also parts of Arducam for cams ov5642 and 0v2640. Can also use MT9D111. Work in progress. Be warned some parts maybe a bit flacky. This is for Seeed Arch max only, for an M3, see the demo for CM3 using the 0v5642 aducam mini.
HttpString.cpp
00001 //***************************************************************************** 00002 // Copyright (C) 2014 Texas Instruments Incorporated 00003 // 00004 // All rights reserved. Property of Texas Instruments Incorporated. 00005 // Restricted rights to use, duplicate or disclose this code are 00006 // granted through contract. 00007 // The program may not be used without the written permission of 00008 // Texas Instruments Incorporated or against the terms and conditions 00009 // stipulated in the agreement under which this program has been supplied, 00010 // and under no circumstances can it be used with non-TI connectivity device. 00011 // 00012 //***************************************************************************** 00013 00014 #include "string.h" 00015 #include <stdlib.h> 00016 #include "HttpString.h" 00017 #include "HttpDebug.h" 00018 //#include "HttpCore.h" 00019 00020 /** 00021 * @addtogroup HttpString 00022 * @{ 00023 */ 00024 00025 char digits[] = "0123456789"; 00026 char hexDigits[] = "0123456789abcdef"; 00027 00028 int HttpString_strcmp(struct HttpBlob first, struct HttpBlob second) 00029 { 00030 int min,res; 00031 if (first.uLength > second.uLength) 00032 min = second.uLength; 00033 else 00034 min = first.uLength; 00035 00036 // Compare a common length which might be equal 00037 res = memcmp(first.pData, second.pData, min); 00038 if (res != 0) 00039 return res; 00040 00041 // Common length is equal, so the longer blob is "larger" 00042 if (first.uLength > second.uLength) 00043 return 1; 00044 else if (first.uLength < second.uLength) 00045 return -1; 00046 else 00047 return 0; 00048 } 00049 00050 static void ToLower(char * str, UINT16 len) 00051 { 00052 int i; 00053 for (i=0 ; i<=len; i++) 00054 { 00055 if (str[i]>='A' && str[i]<='Z') 00056 str[i] = str[i] + 32; 00057 } 00058 } 00059 00060 UINT8* HttpString_nextToken(char* pToken, UINT16 uTokenLength, struct HttpBlob blob) 00061 { 00062 UINT8* pch = blob.pData; 00063 struct HttpBlob partialBlob; 00064 struct HttpBlob token; 00065 token.pData = (UINT8*)pToken; 00066 token.uLength = uTokenLength; 00067 00068 ToLower((char *)blob.pData, blob.uLength); 00069 00070 while (pch < blob.pData + blob.uLength) 00071 { 00072 // Calculate how many blob bytes we should search 00073 int nMaxCount = blob.uLength - (pch - blob.pData) - uTokenLength + 1; 00074 if (nMaxCount < 1){ 00075 return NULL; 00076 } 00077 // Search for the first character of the token 00078 pch = (UINT8*)memchr(pch, pToken[0], nMaxCount); 00079 if (pch==NULL){ 00080 return NULL; 00081 } 00082 // Found first character, now compare the rest 00083 partialBlob.pData = pch; 00084 partialBlob.uLength = uTokenLength; 00085 if (HttpString_strcmp(token, partialBlob)==0) 00086 return pch; 00087 00088 // Skip this byte, and look for the token in the rest of the blob 00089 ++pch; 00090 } 00091 return NULL; 00092 } 00093 00094 UINT8* HttpString_nextDelimiter(char* pToken, UINT16 uTokenLength, struct HttpBlob blob) 00095 { 00096 UINT8* pch = blob.pData; 00097 struct HttpBlob partialBlob; 00098 struct HttpBlob token; 00099 token.pData = (UINT8*)pToken; 00100 token.uLength = uTokenLength; 00101 00102 //ToLower((char *)blob.pData, blob.uLength); 00103 00104 while (pch < blob.pData + blob.uLength) 00105 { 00106 // Calculate how many blob bytes we should search 00107 int nMaxCount = blob.uLength - (pch - blob.pData) - uTokenLength + 1; 00108 if (nMaxCount < 1) 00109 return NULL; 00110 00111 // Search for the first character of the token 00112 pch = (UINT8*)memchr(pch, pToken[0], nMaxCount); 00113 if (pch==NULL) 00114 return NULL; 00115 00116 // Found first character, now compare the rest 00117 partialBlob.pData = pch; 00118 partialBlob.uLength = uTokenLength; 00119 if (HttpString_strcmp(token, partialBlob)==0) 00120 return pch; 00121 00122 // Skip this byte, and look for the token in the rest of the blob 00123 ++pch; 00124 } 00125 return NULL; 00126 } 00127 00128 UINT32 HttpString_atou(struct HttpBlob string) 00129 { 00130 return atoi((const char*)string.pData); 00131 } 00132 00133 void HttpString_utoa(UINT32 uNum, struct HttpBlob* pString) 00134 { 00135 char* ptr; 00136 UINT32 uTemp = uNum; 00137 00138 // value 0 is a special format 00139 if (uNum == 0) 00140 { 00141 pString->uLength = 1; 00142 *pString->pData = '0'; 00143 return; 00144 } 00145 00146 // Find out the length of the number, in decimal base 00147 pString->uLength = 0; 00148 while (uTemp > 0) 00149 { 00150 uTemp /= 10; 00151 pString->uLength++; 00152 } 00153 00154 // Do the actual formatting, right to left 00155 uTemp = uNum; 00156 ptr = (char*)pString->pData + pString->uLength; 00157 while (uTemp > 0) 00158 { 00159 --ptr; 00160 *ptr = digits[uTemp % 10]; 00161 uTemp /= 10; 00162 } 00163 } 00164 00165 void HttpString_htoa(UINT32 uNum, struct HttpBlob* pString, UINT8 bPadZero) 00166 { 00167 UINT8* ptr; 00168 UINT32 uTemp = uNum; 00169 00170 if (!bPadZero) 00171 { 00172 // value 0 is a special format 00173 if (uNum == 0) 00174 { 00175 pString->uLength = 1; 00176 *pString->pData = '0'; 00177 return; 00178 } 00179 00180 // Find out the length of the number, in hexadecimal base 00181 pString->uLength = 0; 00182 while (uTemp > 0) 00183 { 00184 uTemp /= 16; 00185 pString->uLength++; 00186 } 00187 } 00188 00189 // Do the actual formatting, right to left 00190 uTemp = uNum; 00191 ptr = pString->pData + pString->uLength; 00192 while (ptr > pString->pData) 00193 { 00194 --ptr; 00195 *ptr = (UINT8)hexDigits[uTemp % 16]; 00196 uTemp /= 16; 00197 } 00198 } 00199 00200 /// @} 00201
Generated on Tue Jul 12 2022 22:22:38 by 1.7.2