first draft
Dependencies: LMiC SX1272Libx mbed
Fork of LoRaWAN-lmic-app by
debug.cpp@10:497ef83ca19f, 2016-02-26 (annotated)
- Committer:
- tmulrooney
- Date:
- Fri Feb 26 13:27:54 2016 +0000
- Revision:
- 10:497ef83ca19f
- Parent:
- 9:0b63a0a90205
version 0.1
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 | |
tmulrooney | 8:0137acc9a6cd | 21 | void debug_led (u1_t val) |
tmulrooney | 8:0137acc9a6cd | 22 | { |
mluis | 1:60184eda0066 | 23 | debug_val( "LED = ", val ); |
mluis | 1:60184eda0066 | 24 | } |
mluis | 1:60184eda0066 | 25 | |
mluis | 1:60184eda0066 | 26 | void debug_char (u1_t c) { |
mluis | 1:60184eda0066 | 27 | fprintf(stderr, "%c", c ); |
mluis | 1:60184eda0066 | 28 | } |
mluis | 1:60184eda0066 | 29 | |
mluis | 1:60184eda0066 | 30 | void debug_hex (u1_t b) { |
mluis | 1:60184eda0066 | 31 | fprintf(stderr, "%02X", b ); |
mluis | 1:60184eda0066 | 32 | } |
mluis | 1:60184eda0066 | 33 | |
mluis | 1:60184eda0066 | 34 | void debug_buf (const u1_t* buf, u2_t len) { |
mluis | 1:60184eda0066 | 35 | while( len-- ) { |
mluis | 1:60184eda0066 | 36 | debug_hex( *buf++ ); |
mluis | 1:60184eda0066 | 37 | debug_char( ' ' ); |
mluis | 1:60184eda0066 | 38 | } |
mluis | 1:60184eda0066 | 39 | debug_char( '\r' ); |
mluis | 1:60184eda0066 | 40 | debug_char( '\n' ); |
mluis | 1:60184eda0066 | 41 | } |
mluis | 1:60184eda0066 | 42 | |
tmulrooney | 8:0137acc9a6cd | 43 | void debug_uint (u4_t v) |
tmulrooney | 8:0137acc9a6cd | 44 | { |
tmulrooney | 9:0b63a0a90205 | 45 | char str[20]; |
tmulrooney | 8:0137acc9a6cd | 46 | |
tmulrooney | 9:0b63a0a90205 | 47 | sprintf(str,"%d",v); |
tmulrooney | 9:0b63a0a90205 | 48 | debug_str((u1_t *)str); |
tmulrooney | 8:0137acc9a6cd | 49 | // for( s1_t n = 24; n >= 0; n -= 8 ) |
tmulrooney | 8:0137acc9a6cd | 50 | // { |
tmulrooney | 8:0137acc9a6cd | 51 | // debug_hex( v >> n ); |
tmulrooney | 8:0137acc9a6cd | 52 | // } |
mluis | 1:60184eda0066 | 53 | } |
mluis | 1:60184eda0066 | 54 | |
mluis | 1:60184eda0066 | 55 | void debug_str (const u1_t* str) { |
mluis | 1:60184eda0066 | 56 | while( *str ) { |
mluis | 1:60184eda0066 | 57 | debug_char( *str++ ); |
mluis | 1:60184eda0066 | 58 | } |
mluis | 1:60184eda0066 | 59 | } |
mluis | 1:60184eda0066 | 60 | |
mluis | 1:60184eda0066 | 61 | void debug_val (const u1_t* label, u4_t val) { |
tmulrooney | 10:497ef83ca19f | 62 | debug_uint(osticks2ms(hal_ticks())); |
tmulrooney | 10:497ef83ca19f | 63 | debug_str(" "); |
mluis | 1:60184eda0066 | 64 | debug_str( label ); |
mluis | 1:60184eda0066 | 65 | debug_uint( val ); |
mluis | 1:60184eda0066 | 66 | debug_char( '\r' ); |
mluis | 1:60184eda0066 | 67 | debug_char( '\n' ); |
mluis | 1:60184eda0066 | 68 | } |
mluis | 1:60184eda0066 | 69 | |
mluis | 1:60184eda0066 | 70 | void debug_event (int ev) { |
tmulrooney | 8:0137acc9a6cd | 71 | debug_val("onEvent ",ev); |
mluis | 1:60184eda0066 | 72 | static const u1_t* evnames[] = { |
mluis | 1:60184eda0066 | 73 | [EV_SCAN_TIMEOUT] = "SCAN_TIMEOUT", |
mluis | 1:60184eda0066 | 74 | [EV_BEACON_FOUND] = "BEACON_FOUND", |
mluis | 1:60184eda0066 | 75 | [EV_BEACON_MISSED] = "BEACON_MISSED", |
mluis | 1:60184eda0066 | 76 | [EV_BEACON_TRACKED] = "BEACON_TRACKED", |
mluis | 1:60184eda0066 | 77 | [EV_JOINING] = "JOINING", |
mluis | 1:60184eda0066 | 78 | [EV_JOINED] = "JOINED", |
mluis | 1:60184eda0066 | 79 | [EV_RFU1] = "RFU1", |
mluis | 1:60184eda0066 | 80 | [EV_JOIN_FAILED] = "JOIN_FAILED", |
mluis | 1:60184eda0066 | 81 | [EV_REJOIN_FAILED] = "REJOIN_FAILED", |
mluis | 1:60184eda0066 | 82 | [EV_TXCOMPLETE] = "TXCOMPLETE", |
mluis | 1:60184eda0066 | 83 | [EV_LOST_TSYNC] = "LOST_TSYNC", |
mluis | 1:60184eda0066 | 84 | [EV_RESET] = "RESET", |
mluis | 1:60184eda0066 | 85 | [EV_RXCOMPLETE] = "RXCOMPLETE", |
mluis | 1:60184eda0066 | 86 | [EV_LINK_DEAD] = "LINK_DEAD", |
mluis | 1:60184eda0066 | 87 | [EV_LINK_ALIVE] = "LINK_ALIVE", |
mluis | 1:60184eda0066 | 88 | }; |
tmulrooney | 10:497ef83ca19f | 89 | debug_uint(osticks2ms(hal_ticks())); |
tmulrooney | 10:497ef83ca19f | 90 | debug_str(" "); |
mluis | 1:60184eda0066 | 91 | debug_str(evnames[ev]); |
mluis | 1:60184eda0066 | 92 | debug_char('\r'); |
mluis | 1:60184eda0066 | 93 | debug_char('\n'); |
mluis | 1:60184eda0066 | 94 | } |