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/base64.cpp@0:400d8e75a8d0, 2015-09-06 (annotated)
- Committer:
- dflet
- Date:
- Sun Sep 06 15:19:36 2015 +0000
- Revision:
- 0:400d8e75a8d0
TI's websocket Camera demo, also uses Arducam mini 0v5642 camera.
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 | * @defgroup base64_api |
dflet | 0:400d8e75a8d0 | 16 | * |
dflet | 0:400d8e75a8d0 | 17 | * @{ |
dflet | 0:400d8e75a8d0 | 18 | */ |
dflet | 0:400d8e75a8d0 | 19 | #include "base64.h" |
dflet | 0:400d8e75a8d0 | 20 | |
dflet | 0:400d8e75a8d0 | 21 | static const char g_ccB64Tbl[65] = |
dflet | 0:400d8e75a8d0 | 22 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
dflet | 0:400d8e75a8d0 | 23 | |
dflet | 0:400d8e75a8d0 | 24 | |
dflet | 0:400d8e75a8d0 | 25 | void ConvertToBase64(char *pcOutStr, const char *pccInStr, int iLen) |
dflet | 0:400d8e75a8d0 | 26 | { |
dflet | 0:400d8e75a8d0 | 27 | const char* pccIn = (const char *)pccInStr; |
dflet | 0:400d8e75a8d0 | 28 | char* pcOut; |
dflet | 0:400d8e75a8d0 | 29 | int iCount; |
dflet | 0:400d8e75a8d0 | 30 | pcOut = pcOutStr; |
dflet | 0:400d8e75a8d0 | 31 | |
dflet | 0:400d8e75a8d0 | 32 | //Loop in for Multiple of 24Bits and Convert to Base 64 |
dflet | 0:400d8e75a8d0 | 33 | for (iCount = 0; iLen - iCount >=3 ; iCount += 3,pccIn += 3) |
dflet | 0:400d8e75a8d0 | 34 | { |
dflet | 0:400d8e75a8d0 | 35 | *pcOut++ = g_ccB64Tbl[pccIn[0] >> 2]; |
dflet | 0:400d8e75a8d0 | 36 | *pcOut++ = g_ccB64Tbl[((pccIn[0] & 0x03)<<4) | (pccIn[1] >> 4)]; |
dflet | 0:400d8e75a8d0 | 37 | *pcOut++ = g_ccB64Tbl[((pccIn[1] & 0x0F)<<2) | (pccIn[2] >> 6)]; |
dflet | 0:400d8e75a8d0 | 38 | *pcOut++ = g_ccB64Tbl[pccIn[2] & 0x3f]; |
dflet | 0:400d8e75a8d0 | 39 | |
dflet | 0:400d8e75a8d0 | 40 | } |
dflet | 0:400d8e75a8d0 | 41 | |
dflet | 0:400d8e75a8d0 | 42 | //Check if String is not multiple of 3 Bytes |
dflet | 0:400d8e75a8d0 | 43 | if (iCount != iLen) |
dflet | 0:400d8e75a8d0 | 44 | { |
dflet | 0:400d8e75a8d0 | 45 | |
dflet | 0:400d8e75a8d0 | 46 | unsigned char ucLastByte; |
dflet | 0:400d8e75a8d0 | 47 | |
dflet | 0:400d8e75a8d0 | 48 | *pcOut++ = g_ccB64Tbl[pccIn[0] >> 2]; |
dflet | 0:400d8e75a8d0 | 49 | ucLastByte = ((pccIn[0] & 0x03)<<4); |
dflet | 0:400d8e75a8d0 | 50 | |
dflet | 0:400d8e75a8d0 | 51 | |
dflet | 0:400d8e75a8d0 | 52 | if (iLen - iCount > 1) |
dflet | 0:400d8e75a8d0 | 53 | { |
dflet | 0:400d8e75a8d0 | 54 | //If there are 2 Extra Bytes |
dflet | 0:400d8e75a8d0 | 55 | ucLastByte |= (pccIn[1] >> 4); |
dflet | 0:400d8e75a8d0 | 56 | *pcOut++ = g_ccB64Tbl[ucLastByte]; |
dflet | 0:400d8e75a8d0 | 57 | *pcOut++ = g_ccB64Tbl[((pccIn[1] & 0x0F)<<2)]; |
dflet | 0:400d8e75a8d0 | 58 | } |
dflet | 0:400d8e75a8d0 | 59 | else |
dflet | 0:400d8e75a8d0 | 60 | { |
dflet | 0:400d8e75a8d0 | 61 | //If there is only 1 Extra Byte |
dflet | 0:400d8e75a8d0 | 62 | *pcOut++ = g_ccB64Tbl[ucLastByte]; |
dflet | 0:400d8e75a8d0 | 63 | *pcOut++ = '='; |
dflet | 0:400d8e75a8d0 | 64 | } |
dflet | 0:400d8e75a8d0 | 65 | |
dflet | 0:400d8e75a8d0 | 66 | *pcOut++ = '='; |
dflet | 0:400d8e75a8d0 | 67 | } |
dflet | 0:400d8e75a8d0 | 68 | |
dflet | 0:400d8e75a8d0 | 69 | *pcOut = '\0'; |
dflet | 0:400d8e75a8d0 | 70 | |
dflet | 0:400d8e75a8d0 | 71 | } |
dflet | 0:400d8e75a8d0 | 72 | |
dflet | 0:400d8e75a8d0 | 73 | /// @} |
dflet | 0:400d8e75a8d0 | 74 | |
dflet | 0:400d8e75a8d0 | 75 |