first draft

Dependencies:   LMiC SX1272Libx mbed

Fork of LoRaWAN-lmic-app by Semtech

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers debug.cpp Source File

debug.cpp

00001 /*******************************************************************************
00002  * Copyright (c) 2014-2015 IBM Corporation.
00003  * All rights reserved. This program and the accompanying materials
00004  * are made available under the terms of the Eclipse Public License v1.0
00005  * which accompanies this distribution, and is available at
00006  * http://www.eclipse.org/legal/epl-v10.html
00007  *
00008  * Contributors:
00009  *    IBM Zurich Research Lab - initial API, implementation and documentation
00010  *    Semtech Apps Team       - Adapted for MBED
00011  *******************************************************************************/
00012 #include <stdio.h>
00013 #include "lmic.h"
00014 #include "debug.h"
00015 
00016 void debug_init () {
00017     // print banner
00018     debug_str("\r\n============== DEBUG STARTED ==============\r\n");
00019 }
00020 
00021 void debug_led (u1_t val) 
00022 {
00023     debug_val( "LED = ", val );
00024 }
00025 
00026 void debug_char (u1_t c) {
00027     fprintf(stderr, "%c", c );
00028 }
00029 
00030 void debug_hex (u1_t b) {
00031     fprintf(stderr, "%02X", b );
00032 }
00033 
00034 void debug_buf (const u1_t* buf, u2_t len) {
00035     while( len-- ) {
00036         debug_hex( *buf++ );
00037         debug_char( ' ' );
00038     }
00039     debug_char( '\r' );
00040     debug_char( '\n' );
00041 }
00042 
00043 void debug_uint (u4_t v) 
00044 {
00045     char str[20];
00046     
00047     sprintf(str,"%d",v);
00048     debug_str((u1_t *)str);
00049 //    for( s1_t n = 24; n >= 0; n -= 8 ) 
00050 //    {
00051 //        debug_hex( v >> n );
00052 //    }
00053 }
00054 
00055 void debug_str (const u1_t* str) {
00056     while( *str ) {
00057         debug_char( *str++ );
00058     }
00059 }
00060 
00061 void debug_val (const u1_t* label, u4_t val) {
00062     debug_uint(osticks2ms(hal_ticks()));
00063     debug_str(" ");
00064     debug_str( label );
00065     debug_uint( val );
00066     debug_char( '\r' );
00067     debug_char( '\n' );
00068 }
00069 
00070 void debug_event (int ev) {
00071     debug_val("onEvent ",ev);
00072     static const u1_t* evnames[] = {
00073         [EV_SCAN_TIMEOUT]   = "SCAN_TIMEOUT",
00074         [EV_BEACON_FOUND]   = "BEACON_FOUND",
00075         [EV_BEACON_MISSED]  = "BEACON_MISSED",
00076         [EV_BEACON_TRACKED] = "BEACON_TRACKED",
00077         [EV_JOINING]        = "JOINING",
00078         [EV_JOINED]         = "JOINED",
00079         [EV_RFU1]           = "RFU1",
00080         [EV_JOIN_FAILED]    = "JOIN_FAILED",
00081         [EV_REJOIN_FAILED]  = "REJOIN_FAILED",
00082         [EV_TXCOMPLETE]     = "TXCOMPLETE",
00083         [EV_LOST_TSYNC]     = "LOST_TSYNC",
00084         [EV_RESET]          = "RESET",
00085         [EV_RXCOMPLETE]     = "RXCOMPLETE",
00086         [EV_LINK_DEAD]      = "LINK_DEAD",
00087         [EV_LINK_ALIVE]     = "LINK_ALIVE",
00088     };
00089     debug_uint(osticks2ms(hal_ticks()));
00090     debug_str(" ");
00091     debug_str(evnames[ev]);
00092     debug_char('\r');
00093     debug_char('\n');
00094 }