Temperature reading using NUCLEO-L152RE microcontroller and Grove – Temperature&Humidity Sensor Pro.

Dependencies:   DHT LMiC SX1276Lib mbed

Fork of LoRaWAN_send_text by Thomas Amberg

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     debug_val( "LED = ", val );
00023 }
00024 
00025 void debug_char (u1_t c) {
00026     fprintf(stderr, "%c", c );
00027 }
00028 
00029 void debug_hex (u1_t b) {
00030     fprintf(stderr, "%02X", b );
00031 }
00032 
00033 void debug_buf (const u1_t* buf, u2_t len) {
00034     while( len-- ) {
00035         debug_hex( *buf++ );
00036         debug_char( ' ' );
00037     }
00038     debug_char( '\r' );
00039     debug_char( '\n' );
00040 }
00041 
00042 void debug_uint (u4_t v) {
00043     for( s1_t n = 24; n >= 0; n -= 8 ) {
00044         debug_hex( v >> n );
00045     }
00046 }
00047 
00048 void debug_str (const u1_t* str) {
00049     while( *str ) {
00050         debug_char( *str++ );
00051     }
00052 }
00053 
00054 void debug_val (const u1_t* label, u4_t val) {
00055     debug_str( label );
00056     debug_uint( val );
00057     debug_char( '\r' );
00058     debug_char( '\n' );
00059 }
00060 
00061 void debug_event (int ev) {
00062     static const u1_t* evnames[] = {
00063         [EV_SCAN_TIMEOUT]   = "SCAN_TIMEOUT",
00064         [EV_BEACON_FOUND]   = "BEACON_FOUND",
00065         [EV_BEACON_MISSED]  = "BEACON_MISSED",
00066         [EV_BEACON_TRACKED] = "BEACON_TRACKED",
00067         [EV_JOINING]        = "JOINING",
00068         [EV_JOINED]         = "JOINED",
00069         [EV_RFU1]           = "RFU1",
00070         [EV_JOIN_FAILED]    = "JOIN_FAILED",
00071         [EV_REJOIN_FAILED]  = "REJOIN_FAILED",
00072         [EV_TXCOMPLETE]     = "TXCOMPLETE",
00073         [EV_LOST_TSYNC]     = "LOST_TSYNC",
00074         [EV_RESET]          = "RESET",
00075         [EV_RXCOMPLETE]     = "RXCOMPLETE",
00076         [EV_LINK_DEAD]      = "LINK_DEAD",
00077         [EV_LINK_ALIVE]     = "LINK_ALIVE",
00078     };
00079     debug_str(evnames[ev]);
00080     debug_char('\r');
00081     debug_char('\n');
00082 }