PIR + LoRa

Dependencies:   BLE_API LMiC SX1276Lib mbed nRF51822 nrf51_rtc

Fork of BLE_PhysicalWeb by Bluetooth Low Energy

Committer:
janjongboom
Date:
Thu Sep 24 08:32:32 2015 +0000
Revision:
12:940eb88a2104
Parent:
11:bbe4157401e2
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
janjongboom 11:bbe4157401e2 1 /*******************************************************************************
janjongboom 11:bbe4157401e2 2 * Copyright (c) 2014-2015 IBM Corporation.
janjongboom 11:bbe4157401e2 3 * All rights reserved. This program and the accompanying materials
janjongboom 11:bbe4157401e2 4 * are made available under the terms of the Eclipse Public License v1.0
janjongboom 11:bbe4157401e2 5 * which accompanies this distribution, and is available at
janjongboom 11:bbe4157401e2 6 * http://www.eclipse.org/legal/epl-v10.html
janjongboom 11:bbe4157401e2 7 *
janjongboom 11:bbe4157401e2 8 * Contributors:
janjongboom 11:bbe4157401e2 9 * IBM Zurich Research Lab - initial API, implementation and documentation
janjongboom 11:bbe4157401e2 10 * Semtech Apps Team - Adapted for MBED
janjongboom 11:bbe4157401e2 11 *******************************************************************************/
janjongboom 11:bbe4157401e2 12 #include <stdio.h>
janjongboom 11:bbe4157401e2 13 #include "mbed.h"
janjongboom 11:bbe4157401e2 14 #include "lmic.h"
janjongboom 11:bbe4157401e2 15 #include "debug.h"
janjongboom 11:bbe4157401e2 16
janjongboom 11:bbe4157401e2 17 Serial pc2(USBTX, USBRX); // tx, rx
janjongboom 11:bbe4157401e2 18
janjongboom 11:bbe4157401e2 19 void debug_init () {
janjongboom 11:bbe4157401e2 20 // print banner
janjongboom 11:bbe4157401e2 21 debug_str("\r\n============== DEBUG STARTED ==============\r\n");
janjongboom 11:bbe4157401e2 22 }
janjongboom 11:bbe4157401e2 23
janjongboom 11:bbe4157401e2 24 void debug_led (u1_t val) {
janjongboom 11:bbe4157401e2 25 debug_val( "LED = ", val );
janjongboom 11:bbe4157401e2 26 }
janjongboom 11:bbe4157401e2 27
janjongboom 11:bbe4157401e2 28 void debug_char (u1_t c) {
janjongboom 11:bbe4157401e2 29 pc2.printf("%c", c );
janjongboom 11:bbe4157401e2 30 }
janjongboom 11:bbe4157401e2 31
janjongboom 11:bbe4157401e2 32 void debug_hex (u1_t b) {
janjongboom 11:bbe4157401e2 33 pc2.printf("%02X", b );
janjongboom 11:bbe4157401e2 34 }
janjongboom 11:bbe4157401e2 35
janjongboom 11:bbe4157401e2 36 void debug_buf (const u1_t* buf, u2_t len) {
janjongboom 11:bbe4157401e2 37 while( len-- ) {
janjongboom 11:bbe4157401e2 38 debug_hex( *buf++ );
janjongboom 11:bbe4157401e2 39 debug_char( ' ' );
janjongboom 11:bbe4157401e2 40 }
janjongboom 11:bbe4157401e2 41 debug_char( '\r' );
janjongboom 11:bbe4157401e2 42 debug_char( '\n' );
janjongboom 11:bbe4157401e2 43 }
janjongboom 11:bbe4157401e2 44
janjongboom 11:bbe4157401e2 45 void debug_uint (u4_t v) {
janjongboom 11:bbe4157401e2 46 for( s1_t n = 24; n >= 0; n -= 8 ) {
janjongboom 11:bbe4157401e2 47 debug_hex( v >> n );
janjongboom 11:bbe4157401e2 48 }
janjongboom 11:bbe4157401e2 49 }
janjongboom 11:bbe4157401e2 50
janjongboom 11:bbe4157401e2 51 void debug_str (const u1_t* str) {
janjongboom 11:bbe4157401e2 52 while( *str ) {
janjongboom 11:bbe4157401e2 53 debug_char( *str++ );
janjongboom 11:bbe4157401e2 54 }
janjongboom 11:bbe4157401e2 55 }
janjongboom 11:bbe4157401e2 56
janjongboom 11:bbe4157401e2 57 void debug_val (const u1_t* label, u4_t val) {
janjongboom 11:bbe4157401e2 58 debug_str( label );
janjongboom 11:bbe4157401e2 59 debug_uint( val );
janjongboom 11:bbe4157401e2 60 debug_char( '\r' );
janjongboom 11:bbe4157401e2 61 debug_char( '\n' );
janjongboom 11:bbe4157401e2 62 }
janjongboom 11:bbe4157401e2 63
janjongboom 11:bbe4157401e2 64 void debug_event (int ev) {
janjongboom 11:bbe4157401e2 65 static const u1_t* evnames[] = {
janjongboom 11:bbe4157401e2 66 [EV_SCAN_TIMEOUT] = "SCAN_TIMEOUT",
janjongboom 11:bbe4157401e2 67 [EV_BEACON_FOUND] = "BEACON_FOUND",
janjongboom 11:bbe4157401e2 68 [EV_BEACON_MISSED] = "BEACON_MISSED",
janjongboom 11:bbe4157401e2 69 [EV_BEACON_TRACKED] = "BEACON_TRACKED",
janjongboom 11:bbe4157401e2 70 [EV_JOINING] = "JOINING",
janjongboom 11:bbe4157401e2 71 [EV_JOINED] = "JOINED",
janjongboom 11:bbe4157401e2 72 [EV_RFU1] = "RFU1",
janjongboom 11:bbe4157401e2 73 [EV_JOIN_FAILED] = "JOIN_FAILED",
janjongboom 11:bbe4157401e2 74 [EV_REJOIN_FAILED] = "REJOIN_FAILED",
janjongboom 11:bbe4157401e2 75 [EV_TXCOMPLETE] = "TXCOMPLETE",
janjongboom 11:bbe4157401e2 76 [EV_LOST_TSYNC] = "LOST_TSYNC",
janjongboom 11:bbe4157401e2 77 [EV_RESET] = "RESET",
janjongboom 11:bbe4157401e2 78 [EV_RXCOMPLETE] = "RXCOMPLETE",
janjongboom 11:bbe4157401e2 79 [EV_LINK_DEAD] = "LINK_DEAD",
janjongboom 11:bbe4157401e2 80 [EV_LINK_ALIVE] = "LINK_ALIVE",
janjongboom 11:bbe4157401e2 81 };
janjongboom 11:bbe4157401e2 82 debug_str(evnames[ev]);
janjongboom 11:bbe4157401e2 83 debug_char('\r');
janjongboom 11:bbe4157401e2 84 debug_char('\n');
janjongboom 11:bbe4157401e2 85 }