wrapper of the mbed port of Cyassl. It's based of the work of Ashley Mills
Dependents: TLS_cyassl-Example TLS_cyassl-Example2 HTTPSClientExample2
Fork of TLS_cyassl by
Import programTLS_cyassl-Example
This program shows how to use TLS_cyassl to connect to mbed.org
Import programTLS_cyassl-Example2
This example show how to create a small TLS server using the TLS_cyassl library.
dbg.cpp@0:815067fd66c9, 2013-09-12 (annotated)
- Committer:
- feb11
- Date:
- Thu Sep 12 16:37:08 2013 +0000
- Revision:
- 0:815067fd66c9
initial import
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
feb11 | 0:815067fd66c9 | 1 | /* dbg.cpp */ |
feb11 | 0:815067fd66c9 | 2 | /* Copyright (C) 2012 mbed.org, MIT License |
feb11 | 0:815067fd66c9 | 3 | * |
feb11 | 0:815067fd66c9 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
feb11 | 0:815067fd66c9 | 5 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
feb11 | 0:815067fd66c9 | 6 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
feb11 | 0:815067fd66c9 | 7 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
feb11 | 0:815067fd66c9 | 8 | * furnished to do so, subject to the following conditions: |
feb11 | 0:815067fd66c9 | 9 | * |
feb11 | 0:815067fd66c9 | 10 | * The above copyright notice and this permission notice shall be included in all copies or |
feb11 | 0:815067fd66c9 | 11 | * substantial portions of the Software. |
feb11 | 0:815067fd66c9 | 12 | * |
feb11 | 0:815067fd66c9 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
feb11 | 0:815067fd66c9 | 14 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
feb11 | 0:815067fd66c9 | 15 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
feb11 | 0:815067fd66c9 | 16 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
feb11 | 0:815067fd66c9 | 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
feb11 | 0:815067fd66c9 | 18 | */ |
feb11 | 0:815067fd66c9 | 19 | |
feb11 | 0:815067fd66c9 | 20 | #include "dbg.h" |
feb11 | 0:815067fd66c9 | 21 | |
feb11 | 0:815067fd66c9 | 22 | #include "mbed.h" |
feb11 | 0:815067fd66c9 | 23 | #include "rtos.h" |
feb11 | 0:815067fd66c9 | 24 | |
feb11 | 0:815067fd66c9 | 25 | #include <cstdio> |
feb11 | 0:815067fd66c9 | 26 | #include <cstdarg> |
feb11 | 0:815067fd66c9 | 27 | |
feb11 | 0:815067fd66c9 | 28 | using namespace std; |
feb11 | 0:815067fd66c9 | 29 | |
feb11 | 0:815067fd66c9 | 30 | static Serial debug_pc(USBTX, USBRX); |
feb11 | 0:815067fd66c9 | 31 | |
feb11 | 0:815067fd66c9 | 32 | static char debug_newline[3]; |
feb11 | 0:815067fd66c9 | 33 | |
feb11 | 0:815067fd66c9 | 34 | static void debug_lock(bool set) |
feb11 | 0:815067fd66c9 | 35 | { |
feb11 | 0:815067fd66c9 | 36 | static Mutex* mtx = new Mutex(); //Singleton runtime initialisation to avoid static initialisation chaos problems |
feb11 | 0:815067fd66c9 | 37 | static bool init = false; |
feb11 | 0:815067fd66c9 | 38 | if(set) |
feb11 | 0:815067fd66c9 | 39 | { |
feb11 | 0:815067fd66c9 | 40 | mtx->lock(); |
feb11 | 0:815067fd66c9 | 41 | if(!init) |
feb11 | 0:815067fd66c9 | 42 | { |
feb11 | 0:815067fd66c9 | 43 | strncpy( debug_newline, "\n", 2 ); |
feb11 | 0:815067fd66c9 | 44 | printf("[START]\n"); |
feb11 | 0:815067fd66c9 | 45 | fflush(stdout); |
feb11 | 0:815067fd66c9 | 46 | init = true; |
feb11 | 0:815067fd66c9 | 47 | } |
feb11 | 0:815067fd66c9 | 48 | } |
feb11 | 0:815067fd66c9 | 49 | else |
feb11 | 0:815067fd66c9 | 50 | { |
feb11 | 0:815067fd66c9 | 51 | mtx->unlock(); |
feb11 | 0:815067fd66c9 | 52 | } |
feb11 | 0:815067fd66c9 | 53 | } |
feb11 | 0:815067fd66c9 | 54 | |
feb11 | 0:815067fd66c9 | 55 | void debug_init() |
feb11 | 0:815067fd66c9 | 56 | { |
feb11 | 0:815067fd66c9 | 57 | debug_lock(true); //Force init |
feb11 | 0:815067fd66c9 | 58 | debug_lock(false); |
feb11 | 0:815067fd66c9 | 59 | } |
feb11 | 0:815067fd66c9 | 60 | |
feb11 | 0:815067fd66c9 | 61 | void debug_set_newline(const char* newline) |
feb11 | 0:815067fd66c9 | 62 | { |
feb11 | 0:815067fd66c9 | 63 | debug_lock(true); |
feb11 | 0:815067fd66c9 | 64 | strncpy( debug_newline, newline, 2 ); |
feb11 | 0:815067fd66c9 | 65 | debug_newline[2] = '\0'; |
feb11 | 0:815067fd66c9 | 66 | debug_lock(false); |
feb11 | 0:815067fd66c9 | 67 | } |
feb11 | 0:815067fd66c9 | 68 | |
feb11 | 0:815067fd66c9 | 69 | void debug_set_speed(int speed) |
feb11 | 0:815067fd66c9 | 70 | { |
feb11 | 0:815067fd66c9 | 71 | debug_pc.baud(speed); |
feb11 | 0:815067fd66c9 | 72 | } |
feb11 | 0:815067fd66c9 | 73 | |
feb11 | 0:815067fd66c9 | 74 | void debug(int level, const char* module, int line, const char* fmt, ...) |
feb11 | 0:815067fd66c9 | 75 | { |
feb11 | 0:815067fd66c9 | 76 | debug_lock(true); |
feb11 | 0:815067fd66c9 | 77 | switch(level) |
feb11 | 0:815067fd66c9 | 78 | { |
feb11 | 0:815067fd66c9 | 79 | default: |
feb11 | 0:815067fd66c9 | 80 | case 1: |
feb11 | 0:815067fd66c9 | 81 | printf("[ERROR]"); |
feb11 | 0:815067fd66c9 | 82 | break; |
feb11 | 0:815067fd66c9 | 83 | case 2: |
feb11 | 0:815067fd66c9 | 84 | printf("[WARN]"); |
feb11 | 0:815067fd66c9 | 85 | break; |
feb11 | 0:815067fd66c9 | 86 | case 3: |
feb11 | 0:815067fd66c9 | 87 | printf("[INFO]"); |
feb11 | 0:815067fd66c9 | 88 | break; |
feb11 | 0:815067fd66c9 | 89 | case 4: |
feb11 | 0:815067fd66c9 | 90 | printf("[DBG]"); |
feb11 | 0:815067fd66c9 | 91 | break; |
feb11 | 0:815067fd66c9 | 92 | } |
feb11 | 0:815067fd66c9 | 93 | |
feb11 | 0:815067fd66c9 | 94 | printf(" Module %s - Line %d: ", module, line); |
feb11 | 0:815067fd66c9 | 95 | |
feb11 | 0:815067fd66c9 | 96 | va_list argp; |
feb11 | 0:815067fd66c9 | 97 | |
feb11 | 0:815067fd66c9 | 98 | va_start(argp, fmt); |
feb11 | 0:815067fd66c9 | 99 | vprintf(fmt, argp); |
feb11 | 0:815067fd66c9 | 100 | va_end(argp); |
feb11 | 0:815067fd66c9 | 101 | |
feb11 | 0:815067fd66c9 | 102 | printf(debug_newline); |
feb11 | 0:815067fd66c9 | 103 | |
feb11 | 0:815067fd66c9 | 104 | fflush(stdout); |
feb11 | 0:815067fd66c9 | 105 | |
feb11 | 0:815067fd66c9 | 106 | debug_lock(false); |
feb11 | 0:815067fd66c9 | 107 | |
feb11 | 0:815067fd66c9 | 108 | } |
feb11 | 0:815067fd66c9 | 109 | |
feb11 | 0:815067fd66c9 | 110 | void debug_error(const char* module, int line, int ret) |
feb11 | 0:815067fd66c9 | 111 | { |
feb11 | 0:815067fd66c9 | 112 | debug_lock(true); |
feb11 | 0:815067fd66c9 | 113 | printf("[RC] Module %s - Line %d : Error %d\n", module, line, ret); |
feb11 | 0:815067fd66c9 | 114 | fflush(stdout); |
feb11 | 0:815067fd66c9 | 115 | debug_lock(false); |
feb11 | 0:815067fd66c9 | 116 | } |
feb11 | 0:815067fd66c9 | 117 | |
feb11 | 0:815067fd66c9 | 118 | void debug_exact(const char* fmt, ...) |
feb11 | 0:815067fd66c9 | 119 | { |
feb11 | 0:815067fd66c9 | 120 | debug_lock(true); |
feb11 | 0:815067fd66c9 | 121 | va_list argp; |
feb11 | 0:815067fd66c9 | 122 | |
feb11 | 0:815067fd66c9 | 123 | va_start(argp, fmt); |
feb11 | 0:815067fd66c9 | 124 | vprintf(fmt, argp); |
feb11 | 0:815067fd66c9 | 125 | va_end(argp); |
feb11 | 0:815067fd66c9 | 126 | debug_lock(false); |
feb11 | 0:815067fd66c9 | 127 | } |