平成24年中国四国技術職員研修用

Dependencies:   MSCUsbHost NetServices RPCInterface TextLCD mbed

Committer:
yueee_yt
Date:
Wed Aug 22 05:10:09 2012 +0000
Revision:
1:f2088fbce73f
Parent:
0:fd83f3540b1a
???????LM35??????WebServer

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yueee_yt 0:fd83f3540b1a 1
yueee_yt 0:fd83f3540b1a 2 /*
yueee_yt 0:fd83f3540b1a 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
yueee_yt 0:fd83f3540b1a 4
yueee_yt 0:fd83f3540b1a 5 Permission is hereby granted, free of charge, to any person obtaining a copy
yueee_yt 0:fd83f3540b1a 6 of this software and associated documentation files (the "Software"), to deal
yueee_yt 0:fd83f3540b1a 7 in the Software without restriction, including without limitation the rights
yueee_yt 0:fd83f3540b1a 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
yueee_yt 0:fd83f3540b1a 9 copies of the Software, and to permit persons to whom the Software is
yueee_yt 0:fd83f3540b1a 10 furnished to do so, subject to the following conditions:
yueee_yt 0:fd83f3540b1a 11
yueee_yt 0:fd83f3540b1a 12 The above copyright notice and this permission notice shall be included in
yueee_yt 0:fd83f3540b1a 13 all copies or substantial portions of the Software.
yueee_yt 0:fd83f3540b1a 14
yueee_yt 0:fd83f3540b1a 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
yueee_yt 0:fd83f3540b1a 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
yueee_yt 0:fd83f3540b1a 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
yueee_yt 0:fd83f3540b1a 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
yueee_yt 0:fd83f3540b1a 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
yueee_yt 0:fd83f3540b1a 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
yueee_yt 0:fd83f3540b1a 21 THE SOFTWARE.
yueee_yt 0:fd83f3540b1a 22 */
yueee_yt 0:fd83f3540b1a 23
yueee_yt 0:fd83f3540b1a 24 #include "base64.h"
yueee_yt 0:fd83f3540b1a 25 //Originaly from Rolf's iputil.c
yueee_yt 0:fd83f3540b1a 26
yueee_yt 0:fd83f3540b1a 27 #ifdef __cplusplus
yueee_yt 0:fd83f3540b1a 28 extern "C" {
yueee_yt 0:fd83f3540b1a 29 #endif
yueee_yt 0:fd83f3540b1a 30
yueee_yt 0:fd83f3540b1a 31 #include <string.h>
yueee_yt 0:fd83f3540b1a 32
yueee_yt 0:fd83f3540b1a 33 unsigned int base64enc_len(const char* str) {
yueee_yt 0:fd83f3540b1a 34 return (((strlen(str)-1)/3)+1)<<2;
yueee_yt 0:fd83f3540b1a 35 }
yueee_yt 0:fd83f3540b1a 36
yueee_yt 0:fd83f3540b1a 37 void base64enc(const char *input, unsigned int length, char *output) {
yueee_yt 0:fd83f3540b1a 38 static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
yueee_yt 0:fd83f3540b1a 39 unsigned int c, c1, c2, c3;
yueee_yt 0:fd83f3540b1a 40 for(unsigned int i = 0, j = 0; i<length; i+=3,j+=4) {
yueee_yt 0:fd83f3540b1a 41 c1 = ((((unsigned char)*((unsigned char *)&input[i]))));
yueee_yt 0:fd83f3540b1a 42 c2 = (length>i+1)?((((unsigned char)*((unsigned char *)&input[i+1])))):0;
yueee_yt 0:fd83f3540b1a 43 c3 = (length>i+2)?((((unsigned char)*((unsigned char *)&input[i+2])))):0;
yueee_yt 0:fd83f3540b1a 44
yueee_yt 0:fd83f3540b1a 45 c = ((c1 & 0xFC) >> 2);
yueee_yt 0:fd83f3540b1a 46 output[j+0] = base64[c];
yueee_yt 0:fd83f3540b1a 47 c = ((c1 & 0x03) << 4) | ((c2 & 0xF0) >> 4);
yueee_yt 0:fd83f3540b1a 48 output[j+1] = base64[c];
yueee_yt 0:fd83f3540b1a 49 c = ((c2 & 0x0F) << 2) | ((c3 & 0xC0) >> 6);
yueee_yt 0:fd83f3540b1a 50 output[j+2] = (length>i+1)?base64[c]:'=';
yueee_yt 0:fd83f3540b1a 51 c = (c3 & 0x3F);
yueee_yt 0:fd83f3540b1a 52 output[j+3] = (length>i+2)?base64[c]:'=';
yueee_yt 0:fd83f3540b1a 53 }
yueee_yt 0:fd83f3540b1a 54 output[(((length-1)/3)+1)<<2] = '\0';
yueee_yt 0:fd83f3540b1a 55 }
yueee_yt 0:fd83f3540b1a 56
yueee_yt 0:fd83f3540b1a 57 #ifdef __cplusplus
yueee_yt 0:fd83f3540b1a 58 }
yueee_yt 0:fd83f3540b1a 59 #endif
yueee_yt 0:fd83f3540b1a 60