TI's CC3100 websocket camera demo with Arducam mini ov5642 and freertos. Should work with other M3's. Work in progress test demo.
http/server/strlib.cpp@1:e448e81c416f, 2015-09-11 (annotated)
- Committer:
- dflet
- Date:
- Fri Sep 11 15:38:33 2015 +0000
- Revision:
- 1:e448e81c416f
- Parent:
- 0:400d8e75a8d0
Removed some debud.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dflet | 0:400d8e75a8d0 | 1 | //***************************************************************************** |
dflet | 0:400d8e75a8d0 | 2 | // Copyright (C) 2014 Texas Instruments Incorporated |
dflet | 0:400d8e75a8d0 | 3 | // |
dflet | 0:400d8e75a8d0 | 4 | // All rights reserved. Property of Texas Instruments Incorporated. |
dflet | 0:400d8e75a8d0 | 5 | // Restricted rights to use, duplicate or disclose this code are |
dflet | 0:400d8e75a8d0 | 6 | // granted through contract. |
dflet | 0:400d8e75a8d0 | 7 | // The program may not be used without the written permission of |
dflet | 0:400d8e75a8d0 | 8 | // Texas Instruments Incorporated or against the terms and conditions |
dflet | 0:400d8e75a8d0 | 9 | // stipulated in the agreement under which this program has been supplied, |
dflet | 0:400d8e75a8d0 | 10 | // and under no circumstances can it be used with non-TI connectivity device. |
dflet | 0:400d8e75a8d0 | 11 | // |
dflet | 0:400d8e75a8d0 | 12 | //***************************************************************************** |
dflet | 0:400d8e75a8d0 | 13 | |
dflet | 0:400d8e75a8d0 | 14 | |
dflet | 0:400d8e75a8d0 | 15 | #include <stdlib.h> |
dflet | 0:400d8e75a8d0 | 16 | #include <stdio.h> |
dflet | 0:400d8e75a8d0 | 17 | #include <string.h> |
dflet | 0:400d8e75a8d0 | 18 | #include "strlib.h" |
dflet | 0:400d8e75a8d0 | 19 | |
dflet | 0:400d8e75a8d0 | 20 | |
dflet | 0:400d8e75a8d0 | 21 | /***************************************************************************** |
dflet | 0:400d8e75a8d0 | 22 | * |
dflet | 0:400d8e75a8d0 | 23 | * itoa |
dflet | 0:400d8e75a8d0 | 24 | * |
dflet | 0:400d8e75a8d0 | 25 | * \param n is the number to be converted to ASCII |
dflet | 0:400d8e75a8d0 | 26 | * s is a pointer to an array where the ASCII string will be placed |
dflet | 0:400d8e75a8d0 | 27 | * b is the base (10 for decimal) |
dflet | 0:400d8e75a8d0 | 28 | * |
dflet | 0:400d8e75a8d0 | 29 | * \return None |
dflet | 0:400d8e75a8d0 | 30 | * |
dflet | 0:400d8e75a8d0 | 31 | * \brief Integer to ASCII |
dflet | 0:400d8e75a8d0 | 32 | * |
dflet | 0:400d8e75a8d0 | 33 | *****************************************************************************/ |
dflet | 0:400d8e75a8d0 | 34 | char *itoa(int n, char *s, int b) { |
dflet | 0:400d8e75a8d0 | 35 | const char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz"; |
dflet | 0:400d8e75a8d0 | 36 | unsigned int i = 0; |
dflet | 0:400d8e75a8d0 | 37 | int sign; |
dflet | 0:400d8e75a8d0 | 38 | |
dflet | 0:400d8e75a8d0 | 39 | if ((sign = n) < 0) |
dflet | 0:400d8e75a8d0 | 40 | n = -n; |
dflet | 0:400d8e75a8d0 | 41 | |
dflet | 0:400d8e75a8d0 | 42 | do { |
dflet | 0:400d8e75a8d0 | 43 | s[i++] = digits[n % b]; |
dflet | 0:400d8e75a8d0 | 44 | } while ((n /= b) > 0); |
dflet | 0:400d8e75a8d0 | 45 | |
dflet | 0:400d8e75a8d0 | 46 | if (sign < 0) |
dflet | 0:400d8e75a8d0 | 47 | s[i++] = '-'; |
dflet | 0:400d8e75a8d0 | 48 | s[i] = '\0'; |
dflet | 0:400d8e75a8d0 | 49 | |
dflet | 0:400d8e75a8d0 | 50 | return strrev(s); |
dflet | 0:400d8e75a8d0 | 51 | } |
dflet | 0:400d8e75a8d0 | 52 | |
dflet | 0:400d8e75a8d0 | 53 | /***************************************************************************** |
dflet | 0:400d8e75a8d0 | 54 | * |
dflet | 0:400d8e75a8d0 | 55 | * itoa |
dflet | 0:400d8e75a8d0 | 56 | * |
dflet | 0:400d8e75a8d0 | 57 | * \param str is a pointer to the string to be reversed |
dflet | 0:400d8e75a8d0 | 58 | * |
dflet | 0:400d8e75a8d0 | 59 | * \return None |
dflet | 0:400d8e75a8d0 | 60 | * |
dflet | 0:400d8e75a8d0 | 61 | * \brief Reverses a string |
dflet | 0:400d8e75a8d0 | 62 | * |
dflet | 0:400d8e75a8d0 | 63 | *****************************************************************************/ |
dflet | 0:400d8e75a8d0 | 64 | char *strrev(char *str) { |
dflet | 0:400d8e75a8d0 | 65 | char *p1, *p2; |
dflet | 0:400d8e75a8d0 | 66 | |
dflet | 0:400d8e75a8d0 | 67 | if (!str || !*str) |
dflet | 0:400d8e75a8d0 | 68 | return str; |
dflet | 0:400d8e75a8d0 | 69 | |
dflet | 0:400d8e75a8d0 | 70 | for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2) { |
dflet | 0:400d8e75a8d0 | 71 | *p1 ^= *p2; |
dflet | 0:400d8e75a8d0 | 72 | *p2 ^= *p1; |
dflet | 0:400d8e75a8d0 | 73 | *p1 ^= *p2; |
dflet | 0:400d8e75a8d0 | 74 | } |
dflet | 0:400d8e75a8d0 | 75 | |
dflet | 0:400d8e75a8d0 | 76 | return str; |
dflet | 0:400d8e75a8d0 | 77 | } |
dflet | 0:400d8e75a8d0 | 78 | |
dflet | 0:400d8e75a8d0 | 79 | /* Little endian format */ |
dflet | 0:400d8e75a8d0 | 80 | void WordToBytes(void *pBuff, void const*pvalue, unsigned int NumBytes) |
dflet | 0:400d8e75a8d0 | 81 | { |
dflet | 0:400d8e75a8d0 | 82 | unsigned char *pSource, *pDest; |
dflet | 0:400d8e75a8d0 | 83 | int byte = 0; |
dflet | 0:400d8e75a8d0 | 84 | |
dflet | 0:400d8e75a8d0 | 85 | pSource = (unsigned char *)pvalue; |
dflet | 0:400d8e75a8d0 | 86 | pDest = (unsigned char *)pBuff; |
dflet | 0:400d8e75a8d0 | 87 | |
dflet | 0:400d8e75a8d0 | 88 | for(byte = 0; byte < NumBytes; byte++) |
dflet | 0:400d8e75a8d0 | 89 | { |
dflet | 0:400d8e75a8d0 | 90 | *pDest++ = *pSource++; |
dflet | 0:400d8e75a8d0 | 91 | } |
dflet | 0:400d8e75a8d0 | 92 | } |
dflet | 0:400d8e75a8d0 | 93 | |
dflet | 0:400d8e75a8d0 | 94 | int String_utoa(int uNum, char *pString) |
dflet | 0:400d8e75a8d0 | 95 | { |
dflet | 0:400d8e75a8d0 | 96 | char digits[] = "0123456789"; |
dflet | 0:400d8e75a8d0 | 97 | char* ptr; |
dflet | 0:400d8e75a8d0 | 98 | int uLength; |
dflet | 0:400d8e75a8d0 | 99 | int uTemp = uNum; |
dflet | 0:400d8e75a8d0 | 100 | |
dflet | 0:400d8e75a8d0 | 101 | // value 0 is a special format |
dflet | 0:400d8e75a8d0 | 102 | if (uNum == 0) |
dflet | 0:400d8e75a8d0 | 103 | { |
dflet | 0:400d8e75a8d0 | 104 | uLength = 1; |
dflet | 0:400d8e75a8d0 | 105 | *pString = '0'; |
dflet | 0:400d8e75a8d0 | 106 | return uLength; |
dflet | 0:400d8e75a8d0 | 107 | } |
dflet | 0:400d8e75a8d0 | 108 | |
dflet | 0:400d8e75a8d0 | 109 | // Find out the length of the number, in decimal base |
dflet | 0:400d8e75a8d0 | 110 | uLength = 0; |
dflet | 0:400d8e75a8d0 | 111 | while (uTemp > 0) |
dflet | 0:400d8e75a8d0 | 112 | { |
dflet | 0:400d8e75a8d0 | 113 | uTemp /= 10; |
dflet | 0:400d8e75a8d0 | 114 | uLength++; |
dflet | 0:400d8e75a8d0 | 115 | } |
dflet | 0:400d8e75a8d0 | 116 | |
dflet | 0:400d8e75a8d0 | 117 | // Do the actual formatting, right to left |
dflet | 0:400d8e75a8d0 | 118 | uTemp = uNum; |
dflet | 0:400d8e75a8d0 | 119 | ptr = (char*)pString + uLength; |
dflet | 0:400d8e75a8d0 | 120 | while (uTemp > 0) |
dflet | 0:400d8e75a8d0 | 121 | { |
dflet | 0:400d8e75a8d0 | 122 | --ptr; |
dflet | 0:400d8e75a8d0 | 123 | *ptr = digits[uTemp % 10]; |
dflet | 0:400d8e75a8d0 | 124 | uTemp /= 10; |
dflet | 0:400d8e75a8d0 | 125 | } |
dflet | 0:400d8e75a8d0 | 126 | return uLength; |
dflet | 0:400d8e75a8d0 | 127 | } |
dflet | 0:400d8e75a8d0 | 128 | |
dflet | 0:400d8e75a8d0 | 129 | int iptostring(unsigned char *ip, char *ipstring) |
dflet | 0:400d8e75a8d0 | 130 | { |
dflet | 0:400d8e75a8d0 | 131 | int temp,i, length, uLength; |
dflet | 0:400d8e75a8d0 | 132 | char *ptr; |
dflet | 0:400d8e75a8d0 | 133 | ip =ip +3; |
dflet | 0:400d8e75a8d0 | 134 | ptr = ipstring; |
dflet | 0:400d8e75a8d0 | 135 | uLength = 0; |
dflet | 0:400d8e75a8d0 | 136 | for (i=0; i<4; i++) |
dflet | 0:400d8e75a8d0 | 137 | { |
dflet | 0:400d8e75a8d0 | 138 | temp = *ip; |
dflet | 0:400d8e75a8d0 | 139 | length = String_utoa((unsigned long) temp, ptr); |
dflet | 0:400d8e75a8d0 | 140 | ptr = ptr + length; |
dflet | 0:400d8e75a8d0 | 141 | uLength += length; |
dflet | 0:400d8e75a8d0 | 142 | *ptr = '.'; |
dflet | 0:400d8e75a8d0 | 143 | ptr++; |
dflet | 0:400d8e75a8d0 | 144 | uLength++; |
dflet | 0:400d8e75a8d0 | 145 | ip--; |
dflet | 0:400d8e75a8d0 | 146 | } |
dflet | 0:400d8e75a8d0 | 147 | return (uLength-1); |
dflet | 0:400d8e75a8d0 | 148 | } |
dflet | 0:400d8e75a8d0 | 149 | |
dflet | 0:400d8e75a8d0 | 150 |