XRange-LoRaWAN-lmic-app
Dependencies: LMiC SX1272Lib XRange_mbed_src
Fork of LoRaWAN-lmic-app by
debug.cpp@1:60184eda0066, 2015-03-31 (annotated)
- Committer:
- mluis
- Date:
- Tue Mar 31 13:38:08 2015 +0000
- Revision:
- 1:60184eda0066
Updated main application.; Moved debug and hal files from LMiC to main application.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mluis | 1:60184eda0066 | 1 | /******************************************************************************* |
mluis | 1:60184eda0066 | 2 | * Copyright (c) 2014-2015 IBM Corporation. |
mluis | 1:60184eda0066 | 3 | * All rights reserved. This program and the accompanying materials |
mluis | 1:60184eda0066 | 4 | * are made available under the terms of the Eclipse Public License v1.0 |
mluis | 1:60184eda0066 | 5 | * which accompanies this distribution, and is available at |
mluis | 1:60184eda0066 | 6 | * http://www.eclipse.org/legal/epl-v10.html |
mluis | 1:60184eda0066 | 7 | * |
mluis | 1:60184eda0066 | 8 | * Contributors: |
mluis | 1:60184eda0066 | 9 | * IBM Zurich Research Lab - initial API, implementation and documentation |
mluis | 1:60184eda0066 | 10 | * Semtech Apps Team - Adapted for MBED |
mluis | 1:60184eda0066 | 11 | *******************************************************************************/ |
mluis | 1:60184eda0066 | 12 | #include <stdio.h> |
mluis | 1:60184eda0066 | 13 | #include "lmic.h" |
mluis | 1:60184eda0066 | 14 | #include "debug.h" |
mluis | 1:60184eda0066 | 15 | |
mluis | 1:60184eda0066 | 16 | void debug_init () { |
mluis | 1:60184eda0066 | 17 | // print banner |
mluis | 1:60184eda0066 | 18 | debug_str("\r\n============== DEBUG STARTED ==============\r\n"); |
mluis | 1:60184eda0066 | 19 | } |
mluis | 1:60184eda0066 | 20 | |
mluis | 1:60184eda0066 | 21 | void debug_led (u1_t val) { |
mluis | 1:60184eda0066 | 22 | debug_val( "LED = ", val ); |
mluis | 1:60184eda0066 | 23 | } |
mluis | 1:60184eda0066 | 24 | |
mluis | 1:60184eda0066 | 25 | void debug_char (u1_t c) { |
mluis | 1:60184eda0066 | 26 | fprintf(stderr, "%c", c ); |
mluis | 1:60184eda0066 | 27 | } |
mluis | 1:60184eda0066 | 28 | |
mluis | 1:60184eda0066 | 29 | void debug_hex (u1_t b) { |
mluis | 1:60184eda0066 | 30 | fprintf(stderr, "%02X", b ); |
mluis | 1:60184eda0066 | 31 | } |
mluis | 1:60184eda0066 | 32 | |
mluis | 1:60184eda0066 | 33 | void debug_buf (const u1_t* buf, u2_t len) { |
mluis | 1:60184eda0066 | 34 | while( len-- ) { |
mluis | 1:60184eda0066 | 35 | debug_hex( *buf++ ); |
mluis | 1:60184eda0066 | 36 | debug_char( ' ' ); |
mluis | 1:60184eda0066 | 37 | } |
mluis | 1:60184eda0066 | 38 | debug_char( '\r' ); |
mluis | 1:60184eda0066 | 39 | debug_char( '\n' ); |
mluis | 1:60184eda0066 | 40 | } |
mluis | 1:60184eda0066 | 41 | |
mluis | 1:60184eda0066 | 42 | void debug_uint (u4_t v) { |
mluis | 1:60184eda0066 | 43 | for( s1_t n = 24; n >= 0; n -= 8 ) { |
mluis | 1:60184eda0066 | 44 | debug_hex( v >> n ); |
mluis | 1:60184eda0066 | 45 | } |
mluis | 1:60184eda0066 | 46 | } |
mluis | 1:60184eda0066 | 47 | |
mluis | 1:60184eda0066 | 48 | void debug_str (const u1_t* str) { |
mluis | 1:60184eda0066 | 49 | while( *str ) { |
mluis | 1:60184eda0066 | 50 | debug_char( *str++ ); |
mluis | 1:60184eda0066 | 51 | } |
mluis | 1:60184eda0066 | 52 | } |
mluis | 1:60184eda0066 | 53 | |
mluis | 1:60184eda0066 | 54 | void debug_val (const u1_t* label, u4_t val) { |
mluis | 1:60184eda0066 | 55 | debug_str( label ); |
mluis | 1:60184eda0066 | 56 | debug_uint( val ); |
mluis | 1:60184eda0066 | 57 | debug_char( '\r' ); |
mluis | 1:60184eda0066 | 58 | debug_char( '\n' ); |
mluis | 1:60184eda0066 | 59 | } |
mluis | 1:60184eda0066 | 60 | |
mluis | 1:60184eda0066 | 61 | void debug_event (int ev) { |
mluis | 1:60184eda0066 | 62 | static const u1_t* evnames[] = { |
mluis | 1:60184eda0066 | 63 | [EV_SCAN_TIMEOUT] = "SCAN_TIMEOUT", |
mluis | 1:60184eda0066 | 64 | [EV_BEACON_FOUND] = "BEACON_FOUND", |
mluis | 1:60184eda0066 | 65 | [EV_BEACON_MISSED] = "BEACON_MISSED", |
mluis | 1:60184eda0066 | 66 | [EV_BEACON_TRACKED] = "BEACON_TRACKED", |
mluis | 1:60184eda0066 | 67 | [EV_JOINING] = "JOINING", |
mluis | 1:60184eda0066 | 68 | [EV_JOINED] = "JOINED", |
mluis | 1:60184eda0066 | 69 | [EV_RFU1] = "RFU1", |
mluis | 1:60184eda0066 | 70 | [EV_JOIN_FAILED] = "JOIN_FAILED", |
mluis | 1:60184eda0066 | 71 | [EV_REJOIN_FAILED] = "REJOIN_FAILED", |
mluis | 1:60184eda0066 | 72 | [EV_TXCOMPLETE] = "TXCOMPLETE", |
mluis | 1:60184eda0066 | 73 | [EV_LOST_TSYNC] = "LOST_TSYNC", |
mluis | 1:60184eda0066 | 74 | [EV_RESET] = "RESET", |
mluis | 1:60184eda0066 | 75 | [EV_RXCOMPLETE] = "RXCOMPLETE", |
mluis | 1:60184eda0066 | 76 | [EV_LINK_DEAD] = "LINK_DEAD", |
mluis | 1:60184eda0066 | 77 | [EV_LINK_ALIVE] = "LINK_ALIVE", |
mluis | 1:60184eda0066 | 78 | }; |
mluis | 1:60184eda0066 | 79 | debug_str(evnames[ev]); |
mluis | 1:60184eda0066 | 80 | debug_char('\r'); |
mluis | 1:60184eda0066 | 81 | debug_char('\n'); |
mluis | 1:60184eda0066 | 82 | } |