MBED code for Xbee unit running on chase car
Fork of XBee802_Receive_Data by
main.cpp
00001 /** 00002 * Copyright (c) 2015 Digi International Inc., 00003 * All rights not expressly granted are reserved. 00004 * 00005 * This Source Code Form is subject to the terms of the Mozilla Public 00006 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 00007 * You can obtain one at http://mozilla.org/MPL/2.0/. 00008 * 00009 * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343 00010 * ======================================================================= 00011 */ 00012 00013 #include "mbed.h" 00014 #include "XBeeLib.h" 00015 #if defined(ENABLE_LOGGING) 00016 #include "DigiLoggerMbedSerial.h" 00017 using namespace DigiLog; 00018 #endif 00019 00020 using namespace XBeeLib; 00021 00022 Serial *log_serial; 00023 00024 static void receive_cb(const RemoteXBee802& remote, bool broadcast, const uint8_t *const data, uint16_t len) 00025 { 00026 if (remote.is_valid_addr16b()) { 00027 log_serial->printf("\r\nGot a %s 16-bit RX packet [%04x], len %d\r\nData: ", broadcast ? "BROADCAST" : "UNICAST", remote.get_addr16(), len); 00028 } else { 00029 log_serial->printf("\r\nGot a %s 64-bit RX packet [%08x:%08x], len %d\r\nData: ", broadcast ? "BROADCAST" : "UNICAST", remote.get_addr64(), len); 00030 } 00031 00032 for (int i = 0; i < len; i++) 00033 log_serial->printf("%02x", data[i]); 00034 00035 log_serial->printf("\r\n"); 00036 } 00037 00038 int main() 00039 { 00040 log_serial = new Serial(DEBUG_TX, DEBUG_RX); 00041 log_serial->baud(9600); 00042 log_serial->printf("Sample application to demo how to receive unicast and broadcast data with the XBee802\r\n\r\n"); 00043 log_serial->printf(XB_LIB_BANNER); 00044 00045 #if defined(ENABLE_LOGGING) 00046 new DigiLoggerMbedSerial(log_serial, LogLevelInfo); 00047 #endif 00048 00049 XBee802 xbee = XBee802(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600); 00050 00051 /* Register callback */ 00052 xbee.register_receive_cb(&receive_cb); 00053 00054 RadioStatus const radioStatus = xbee.init(); 00055 MBED_ASSERT(radioStatus == Success); 00056 00057 while (true) { 00058 xbee.process_rx_frames(); 00059 wait_ms(100); 00060 log_serial->printf("."); 00061 } 00062 00063 delete(log_serial); 00064 }
Generated on Sun Jul 17 2022 01:51:32 by 1.7.2