Lora OTA device for Everynet

Dependencies:   LMiCLibOTADeviceEverynet SX1276Lib X_NUCLEO_IKS01A1 cantcoap lwip mbed-rtos mbed

Fork of LoRaWAN-test-10secs by Alcatel-Lucent IoT Development

Committer:
pnysten
Date:
Fri Sep 23 09:18:35 2016 +0000
Revision:
14:3821b54ff94b
Parent:
4:5e274bf85bf0
Lora OTA device for Everynet

Who changed what in which revision?

UserRevisionLine numberNew 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
pnysten 4:5e274bf85bf0 16 #include "mbed.h"
pnysten 4:5e274bf85bf0 17 Serial pc(USBTX, USBRX);
pnysten 4:5e274bf85bf0 18
mluis 1:60184eda0066 19 void debug_init () {
pnysten 4:5e274bf85bf0 20 pc.baud(9600);
mluis 1:60184eda0066 21 // print banner
mluis 1:60184eda0066 22 debug_str("\r\n============== DEBUG STARTED ==============\r\n");
mluis 1:60184eda0066 23 }
pnysten 4:5e274bf85bf0 24
mluis 1:60184eda0066 25 void debug_led (u1_t val) {
mluis 1:60184eda0066 26 debug_val( "LED = ", val );
mluis 1:60184eda0066 27 }
pnysten 4:5e274bf85bf0 28
mluis 1:60184eda0066 29 void debug_char (u1_t c) {
pnysten 4:5e274bf85bf0 30 pc.printf("%c", c );
mluis 1:60184eda0066 31 }
pnysten 4:5e274bf85bf0 32
mluis 1:60184eda0066 33 void debug_hex (u1_t b) {
pnysten 4:5e274bf85bf0 34 pc.printf("%02X", b );
mluis 1:60184eda0066 35 }
pnysten 4:5e274bf85bf0 36
mluis 1:60184eda0066 37 void debug_buf (const u1_t* buf, u2_t len) {
mluis 1:60184eda0066 38 while( len-- ) {
mluis 1:60184eda0066 39 debug_hex( *buf++ );
mluis 1:60184eda0066 40 debug_char( ' ' );
mluis 1:60184eda0066 41 }
mluis 1:60184eda0066 42 debug_char( '\r' );
mluis 1:60184eda0066 43 debug_char( '\n' );
mluis 1:60184eda0066 44 }
pnysten 4:5e274bf85bf0 45
mluis 1:60184eda0066 46 void debug_uint (u4_t v) {
mluis 1:60184eda0066 47 for( s1_t n = 24; n >= 0; n -= 8 ) {
mluis 1:60184eda0066 48 debug_hex( v >> n );
mluis 1:60184eda0066 49 }
mluis 1:60184eda0066 50 }
pnysten 4:5e274bf85bf0 51
pnysten 4:5e274bf85bf0 52 void debug_str (const char* str) {
pnysten 4:5e274bf85bf0 53 /*while( *str ) {
pnysten 4:5e274bf85bf0 54 debug_char( *str++ );
pnysten 4:5e274bf85bf0 55 }*/
pnysten 4:5e274bf85bf0 56 pc.printf(str);
pnysten 4:5e274bf85bf0 57 }
mluis 1:60184eda0066 58
mluis 1:60184eda0066 59 void debug_str (const u1_t* str) {
mluis 1:60184eda0066 60 while( *str ) {
mluis 1:60184eda0066 61 debug_char( *str++ );
mluis 1:60184eda0066 62 }
mluis 1:60184eda0066 63 }
pnysten 4:5e274bf85bf0 64
pnysten 4:5e274bf85bf0 65 void debug_val (const char* label, u4_t val) {
pnysten 4:5e274bf85bf0 66 debug_str( label );
pnysten 4:5e274bf85bf0 67 debug_uint( val );
pnysten 4:5e274bf85bf0 68 debug_char( '\r' );
pnysten 4:5e274bf85bf0 69 debug_char( '\n' );
pnysten 4:5e274bf85bf0 70 }
mluis 1:60184eda0066 71
mluis 1:60184eda0066 72 void debug_val (const u1_t* label, u4_t val) {
mluis 1:60184eda0066 73 debug_str( label );
mluis 1:60184eda0066 74 debug_uint( val );
mluis 1:60184eda0066 75 debug_char( '\r' );
mluis 1:60184eda0066 76 debug_char( '\n' );
mluis 1:60184eda0066 77 }
pnysten 4:5e274bf85bf0 78
mluis 1:60184eda0066 79 void debug_event (int ev) {
pnysten 4:5e274bf85bf0 80 static const char* evnames[] = {
mluis 1:60184eda0066 81 [EV_SCAN_TIMEOUT] = "SCAN_TIMEOUT",
mluis 1:60184eda0066 82 [EV_BEACON_FOUND] = "BEACON_FOUND",
mluis 1:60184eda0066 83 [EV_BEACON_MISSED] = "BEACON_MISSED",
mluis 1:60184eda0066 84 [EV_BEACON_TRACKED] = "BEACON_TRACKED",
mluis 1:60184eda0066 85 [EV_JOINING] = "JOINING",
mluis 1:60184eda0066 86 [EV_JOINED] = "JOINED",
mluis 1:60184eda0066 87 [EV_RFU1] = "RFU1",
mluis 1:60184eda0066 88 [EV_JOIN_FAILED] = "JOIN_FAILED",
mluis 1:60184eda0066 89 [EV_REJOIN_FAILED] = "REJOIN_FAILED",
mluis 1:60184eda0066 90 [EV_TXCOMPLETE] = "TXCOMPLETE",
mluis 1:60184eda0066 91 [EV_LOST_TSYNC] = "LOST_TSYNC",
mluis 1:60184eda0066 92 [EV_RESET] = "RESET",
mluis 1:60184eda0066 93 [EV_RXCOMPLETE] = "RXCOMPLETE",
mluis 1:60184eda0066 94 [EV_LINK_DEAD] = "LINK_DEAD",
mluis 1:60184eda0066 95 [EV_LINK_ALIVE] = "LINK_ALIVE",
mluis 1:60184eda0066 96 };
mluis 1:60184eda0066 97 debug_str(evnames[ev]);
mluis 1:60184eda0066 98 debug_char('\r');
mluis 1:60184eda0066 99 debug_char('\n');
pnysten 4:5e274bf85bf0 100 }