Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of XBeeZB_modem_status by
main.cpp@1:d69b2dcc284f, 2015-05-08 (annotated)
- Committer:
- spastor
- Date:
- Fri May 08 11:53:26 2015 +0200
- Revision:
- 1:d69b2dcc284f
- Parent:
- 0:0c8d070617b1
Automatic upload
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
spastor | 0:0c8d070617b1 | 1 | /** |
spastor | 1:d69b2dcc284f | 2 | * Copyright (c) 2015 Digi International Inc., |
spastor | 0:0c8d070617b1 | 3 | * All rights not expressly granted are reserved. |
spastor | 0:0c8d070617b1 | 4 | * |
spastor | 0:0c8d070617b1 | 5 | * This Source Code Form is subject to the terms of the Mozilla Public |
spastor | 0:0c8d070617b1 | 6 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
spastor | 0:0c8d070617b1 | 7 | * You can obtain one at http://mozilla.org/MPL/2.0/. |
spastor | 0:0c8d070617b1 | 8 | * |
spastor | 0:0c8d070617b1 | 9 | * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343 |
spastor | 0:0c8d070617b1 | 10 | * ======================================================================= |
spastor | 0:0c8d070617b1 | 11 | */ |
spastor | 0:0c8d070617b1 | 12 | |
spastor | 0:0c8d070617b1 | 13 | #include "mbed.h" |
spastor | 0:0c8d070617b1 | 14 | #include "XBeeLib.h" |
spastor | 0:0c8d070617b1 | 15 | #if defined(ENABLE_LOGGING) |
spastor | 0:0c8d070617b1 | 16 | #include "DigiLoggerMbedSerial.h" |
spastor | 0:0c8d070617b1 | 17 | using namespace DigiLog; |
spastor | 0:0c8d070617b1 | 18 | #endif |
spastor | 0:0c8d070617b1 | 19 | |
spastor | 0:0c8d070617b1 | 20 | using namespace XBeeLib; |
spastor | 0:0c8d070617b1 | 21 | |
spastor | 0:0c8d070617b1 | 22 | Serial *log_serial; |
spastor | 0:0c8d070617b1 | 23 | |
spastor | 0:0c8d070617b1 | 24 | /** Callback function, invoked at modem status reception */ |
spastor | 0:0c8d070617b1 | 25 | static void modem_status_cb(AtCmdFrame::ModemStatus status) |
spastor | 0:0c8d070617b1 | 26 | { |
spastor | 0:0c8d070617b1 | 27 | log_serial->printf("\r\nModem Status: 0x%x\r\n", status); |
spastor | 0:0c8d070617b1 | 28 | } |
spastor | 0:0c8d070617b1 | 29 | |
spastor | 0:0c8d070617b1 | 30 | int main() |
spastor | 0:0c8d070617b1 | 31 | { |
spastor | 0:0c8d070617b1 | 32 | log_serial = new Serial(DEBUG_TX, DEBUG_RX); |
spastor | 0:0c8d070617b1 | 33 | log_serial->baud(9600); |
spastor | 0:0c8d070617b1 | 34 | log_serial->printf("Sample application to demo how to receive modem status changes with the XBeeZB\r\n\r\n"); |
spastor | 0:0c8d070617b1 | 35 | log_serial->printf(XB_LIB_BANNER); |
spastor | 0:0c8d070617b1 | 36 | |
spastor | 0:0c8d070617b1 | 37 | #if defined(ENABLE_LOGGING) |
spastor | 0:0c8d070617b1 | 38 | new DigiLoggerMbedSerial(log_serial, LogLevelInfo); |
spastor | 0:0c8d070617b1 | 39 | #endif |
spastor | 0:0c8d070617b1 | 40 | |
spastor | 0:0c8d070617b1 | 41 | XBeeZB xbee = XBeeZB(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600); |
spastor | 0:0c8d070617b1 | 42 | |
spastor | 0:0c8d070617b1 | 43 | /* Register callbacks */ |
spastor | 0:0c8d070617b1 | 44 | xbee.register_modem_status_cb(&modem_status_cb); |
spastor | 0:0c8d070617b1 | 45 | |
spastor | 0:0c8d070617b1 | 46 | RadioStatus const radioStatus = xbee.init(); |
spastor | 0:0c8d070617b1 | 47 | MBED_ASSERT(radioStatus == Success); |
spastor | 0:0c8d070617b1 | 48 | |
spastor | 0:0c8d070617b1 | 49 | while (true) { |
spastor | 0:0c8d070617b1 | 50 | xbee.process_rx_frames(); |
spastor | 0:0c8d070617b1 | 51 | wait_ms(100); |
spastor | 0:0c8d070617b1 | 52 | log_serial->printf("."); |
spastor | 0:0c8d070617b1 | 53 | } |
spastor | 0:0c8d070617b1 | 54 | |
spastor | 0:0c8d070617b1 | 55 | delete(log_serial); |
spastor | 0:0c8d070617b1 | 56 | } |