Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Committer:
uci1
Date:
Fri Jul 20 19:04:02 2012 +0000
Revision:
1:e392595b4b76
Child:
3:24c5f0f50bf1
many features checked and working. afar implemented. sending of data not yet tested. contains many debug prints

Who changed what in which revision?

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