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.
strlib.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 00015 #include <stdlib.h> 00016 #include <stdio.h> 00017 #include <string.h> 00018 #include "strlib.h" 00019 00020 00021 /***************************************************************************** 00022 * 00023 * itoa 00024 * 00025 * \param n is the number to be converted to ASCII 00026 * s is a pointer to an array where the ASCII string will be placed 00027 * b is the base (10 for decimal) 00028 * 00029 * \return None 00030 * 00031 * \brief Integer to ASCII 00032 * 00033 *****************************************************************************/ 00034 char *itoa(int n, char *s, int b) { 00035 const char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz"; 00036 unsigned int i = 0; 00037 int sign; 00038 00039 if ((sign = n) < 0) 00040 n = -n; 00041 00042 do { 00043 s[i++] = digits[n % b]; 00044 } while ((n /= b) > 0); 00045 00046 if (sign < 0) 00047 s[i++] = '-'; 00048 s[i] = '\0'; 00049 00050 return strrev(s); 00051 } 00052 00053 /***************************************************************************** 00054 * 00055 * itoa 00056 * 00057 * \param str is a pointer to the string to be reversed 00058 * 00059 * \return None 00060 * 00061 * \brief Reverses a string 00062 * 00063 *****************************************************************************/ 00064 char *strrev(char *str) { 00065 char *p1, *p2; 00066 00067 if (!str || !*str) 00068 return str; 00069 00070 for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2) { 00071 *p1 ^= *p2; 00072 *p2 ^= *p1; 00073 *p1 ^= *p2; 00074 } 00075 00076 return str; 00077 } 00078 00079 /* Little endian format */ 00080 void WordToBytes(void *pBuff, void const*pvalue, unsigned int NumBytes) 00081 { 00082 unsigned char *pSource, *pDest; 00083 int byte = 0; 00084 00085 pSource = (unsigned char *)pvalue; 00086 pDest = (unsigned char *)pBuff; 00087 00088 for(byte = 0; byte < NumBytes; byte++) 00089 { 00090 *pDest++ = *pSource++; 00091 } 00092 } 00093 00094 int String_utoa(int uNum, char *pString) 00095 { 00096 char digits[] = "0123456789"; 00097 char* ptr; 00098 int uLength; 00099 int uTemp = uNum; 00100 00101 // value 0 is a special format 00102 if (uNum == 0) 00103 { 00104 uLength = 1; 00105 *pString = '0'; 00106 return uLength; 00107 } 00108 00109 // Find out the length of the number, in decimal base 00110 uLength = 0; 00111 while (uTemp > 0) 00112 { 00113 uTemp /= 10; 00114 uLength++; 00115 } 00116 00117 // Do the actual formatting, right to left 00118 uTemp = uNum; 00119 ptr = (char*)pString + uLength; 00120 while (uTemp > 0) 00121 { 00122 --ptr; 00123 *ptr = digits[uTemp % 10]; 00124 uTemp /= 10; 00125 } 00126 return uLength; 00127 } 00128 00129 int iptostring(unsigned char *ip, char *ipstring) 00130 { 00131 int temp,i, length, uLength; 00132 char *ptr; 00133 ip =ip +3; 00134 ptr = ipstring; 00135 uLength = 0; 00136 for (i=0; i<4; i++) 00137 { 00138 temp = *ip; 00139 length = String_utoa((unsigned long) temp, ptr); 00140 ptr = ptr + length; 00141 uLength += length; 00142 *ptr = '.'; 00143 ptr++; 00144 uLength++; 00145 ip--; 00146 } 00147 return (uLength-1); 00148 } 00149 00150
Generated on Tue Jul 12 2022 22:22:38 by
1.7.2