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.
main.cpp@9:b03553c8fbf5, 2016-03-31 (annotated)
- Committer:
- hbujanda
- Date:
- Thu Mar 31 11:39:40 2016 +0200
- Revision:
- 9:b03553c8fbf5
- Parent:
- 8:7b4771c9689c
- Child:
- 10:776b6cf3e506
Automatic upload
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| hbujanda | 6:193fc0aec946 | 1 | /** |
| hbujanda | 6:193fc0aec946 | 2 | * Copyright (c) 2015 Digi International Inc., |
| hbujanda | 6:193fc0aec946 | 3 | * All rights not expressly granted are reserved. |
| hbujanda | 6:193fc0aec946 | 4 | * |
| hbujanda | 6:193fc0aec946 | 5 | * This Source Code Form is subject to the terms of the Mozilla Public |
| hbujanda | 6:193fc0aec946 | 6 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
| hbujanda | 6:193fc0aec946 | 7 | * You can obtain one at http://mozilla.org/MPL/2.0/. |
| hbujanda | 6:193fc0aec946 | 8 | * |
| hbujanda | 6:193fc0aec946 | 9 | * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343 |
| hbujanda | 6:193fc0aec946 | 10 | * ======================================================================= |
| hbujanda | 6:193fc0aec946 | 11 | */ |
| hbujanda | 6:193fc0aec946 | 12 | |
| hbujanda | 6:193fc0aec946 | 13 | #include "mbed.h" |
| hbujanda | 6:193fc0aec946 | 14 | #include "XBeeLib.h" |
| hbujanda | 6:193fc0aec946 | 15 | #if defined(ENABLE_LOGGING) |
| hbujanda | 6:193fc0aec946 | 16 | #include "DigiLoggerMbedSerial.h" |
| hbujanda | 6:193fc0aec946 | 17 | using namespace DigiLog; |
| hbujanda | 6:193fc0aec946 | 18 | #endif |
| hbujanda | 6:193fc0aec946 | 19 | |
| hbujanda | 6:193fc0aec946 | 20 | #define REMOTE_NODE_ADDR64_MSB ((uint32_t)0x0013A200) |
| spastor | 8:7b4771c9689c | 21 | |
| hbujanda | 9:b03553c8fbf5 | 22 | //#error "Replace next define with the LSB of the remote module's 64-bit address (SL parameter)" |
| hbujanda | 9:b03553c8fbf5 | 23 | #define REMOTE_NODE_ADDR64_LSB ((uint32_t)0x40E465EB) |
| spastor | 8:7b4771c9689c | 24 | |
| hbujanda | 9:b03553c8fbf5 | 25 | //#error "Replace next define with the remote module's 16-bit address (MY parameter)" |
| hbujanda | 9:b03553c8fbf5 | 26 | #define REMOTE_NODE_ADDR16 ((uint16_t)0x0001) |
| hbujanda | 6:193fc0aec946 | 27 | |
| hbujanda | 6:193fc0aec946 | 28 | #define REMOTE_NODE_ADDR64 UINT64(REMOTE_NODE_ADDR64_MSB, REMOTE_NODE_ADDR64_LSB) |
| hbujanda | 6:193fc0aec946 | 29 | |
| hbujanda | 6:193fc0aec946 | 30 | using namespace XBeeLib; |
| hbujanda | 6:193fc0aec946 | 31 | |
| hbujanda | 6:193fc0aec946 | 32 | Serial *log_serial; |
| hbujanda | 6:193fc0aec946 | 33 | |
| hbujanda | 6:193fc0aec946 | 34 | int main() |
| hbujanda | 6:193fc0aec946 | 35 | { |
| hbujanda | 6:193fc0aec946 | 36 | log_serial = new Serial(DEBUG_TX, DEBUG_RX); |
| hbujanda | 6:193fc0aec946 | 37 | log_serial->baud(9600); |
| hbujanda | 6:193fc0aec946 | 38 | log_serial->printf("Sample application to demo how to read and set local and remote AT parameters with XBee802\r\n\r\n"); |
| hbujanda | 6:193fc0aec946 | 39 | log_serial->printf(XB_LIB_BANNER); |
| hbujanda | 6:193fc0aec946 | 40 | |
| hbujanda | 6:193fc0aec946 | 41 | #if defined(ENABLE_LOGGING) |
| hbujanda | 6:193fc0aec946 | 42 | new DigiLoggerMbedSerial(log_serial, LogLevelInfo); |
| hbujanda | 6:193fc0aec946 | 43 | #endif |
| hbujanda | 6:193fc0aec946 | 44 | |
| hbujanda | 6:193fc0aec946 | 45 | XBee802 xbee = XBee802(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600); |
| hbujanda | 6:193fc0aec946 | 46 | |
| hbujanda | 6:193fc0aec946 | 47 | RadioStatus radioStatus = xbee.init(); |
| hbujanda | 6:193fc0aec946 | 48 | MBED_ASSERT(radioStatus == Success); |
| hbujanda | 6:193fc0aec946 | 49 | |
| hbujanda | 6:193fc0aec946 | 50 | AtCmdFrame::AtCmdResp cmdresp; |
| hbujanda | 6:193fc0aec946 | 51 | uint32_t value; |
| hbujanda | 6:193fc0aec946 | 52 | |
| hbujanda | 6:193fc0aec946 | 53 | /* Read local device SL parameter */ |
| hbujanda | 6:193fc0aec946 | 54 | log_serial->printf("\r\nReading local device SL parameter:\r\n"); |
| hbujanda | 6:193fc0aec946 | 55 | cmdresp = xbee.get_param("SL", &value); |
| hbujanda | 6:193fc0aec946 | 56 | if (cmdresp == AtCmdFrame::AtCmdRespOk) { |
| hbujanda | 6:193fc0aec946 | 57 | log_serial->printf("OK. Local SL=%08x\r\n", value); |
| hbujanda | 6:193fc0aec946 | 58 | |
| hbujanda | 6:193fc0aec946 | 59 | /* Get the local device 64 bit address to compare */ |
| hbujanda | 6:193fc0aec946 | 60 | const uint64_t LocalDeviceAddr64 = xbee.get_addr64(); |
| hbujanda | 6:193fc0aec946 | 61 | |
| spastor | 8:7b4771c9689c | 62 | MBED_ASSERT(value == (LocalDeviceAddr64 & 0xFFFFFFFF)); |
| hbujanda | 6:193fc0aec946 | 63 | } else { |
| hbujanda | 6:193fc0aec946 | 64 | log_serial->printf("FAILED with %d\r\n", (int) cmdresp); |
| hbujanda | 6:193fc0aec946 | 65 | } |
| hbujanda | 6:193fc0aec946 | 66 | |
| hbujanda | 6:193fc0aec946 | 67 | /* Set local device NI parameter */ |
| spastor | 8:7b4771c9689c | 68 | char ni_local[] = "param config example"; |
| spastor | 8:7b4771c9689c | 69 | log_serial->printf("\r\nSetting local device NI parameter to '%s':\r\n", ni_local); |
| spastor | 8:7b4771c9689c | 70 | cmdresp = xbee.set_param("NI", (uint8_t*)ni_local, strlen(ni_local)); |
| hbujanda | 6:193fc0aec946 | 71 | if (cmdresp == AtCmdFrame::AtCmdRespOk) |
| hbujanda | 6:193fc0aec946 | 72 | log_serial->printf("OK\r\n"); |
| hbujanda | 6:193fc0aec946 | 73 | else |
| hbujanda | 6:193fc0aec946 | 74 | log_serial->printf("FAILED with %d\r\n", (int) cmdresp); |
| hbujanda | 6:193fc0aec946 | 75 | |
| spastor | 8:7b4771c9689c | 76 | const RemoteXBee802 remoteDevice64b = RemoteXBee802(REMOTE_NODE_ADDR64); |
| spastor | 8:7b4771c9689c | 77 | const RemoteXBee802 remoteDevice16b = RemoteXBee802(REMOTE_NODE_ADDR16); |
| spastor | 8:7b4771c9689c | 78 | |
| hbujanda | 6:193fc0aec946 | 79 | /* Read remote device SL parameter using 64b addressing */ |
| hbujanda | 6:193fc0aec946 | 80 | log_serial->printf("\r\nReading remote device SL parameter using 64b address:\r\n"); |
| hbujanda | 6:193fc0aec946 | 81 | cmdresp = xbee.get_param(remoteDevice64b, "SL", &value); |
| hbujanda | 6:193fc0aec946 | 82 | if (cmdresp == AtCmdFrame::AtCmdRespOk) { |
| hbujanda | 6:193fc0aec946 | 83 | log_serial->printf("OK. Remote SL=%08x\r\n", value); |
| hbujanda | 6:193fc0aec946 | 84 | MBED_ASSERT(value == REMOTE_NODE_ADDR64_LSB); |
| hbujanda | 6:193fc0aec946 | 85 | } else { |
| hbujanda | 6:193fc0aec946 | 86 | log_serial->printf("FAILED with %d\r\n", (int) cmdresp); |
| hbujanda | 6:193fc0aec946 | 87 | } |
| hbujanda | 6:193fc0aec946 | 88 | |
| hbujanda | 6:193fc0aec946 | 89 | /* Read remote device SL parameter using 16b addressing */ |
| hbujanda | 6:193fc0aec946 | 90 | log_serial->printf("\r\nReading remote device SL parameter using 16b address:\r\n"); |
| hbujanda | 6:193fc0aec946 | 91 | cmdresp = xbee.get_param(remoteDevice16b, "SL", &value); |
| hbujanda | 6:193fc0aec946 | 92 | if (cmdresp == AtCmdFrame::AtCmdRespOk) { |
| hbujanda | 6:193fc0aec946 | 93 | log_serial->printf("OK. Remote SL=%08x\r\n", value); |
| hbujanda | 6:193fc0aec946 | 94 | MBED_ASSERT(value == REMOTE_NODE_ADDR64_LSB); |
| hbujanda | 6:193fc0aec946 | 95 | } else { |
| hbujanda | 6:193fc0aec946 | 96 | log_serial->printf("FAILED with %d\r\n", (int) cmdresp); |
| hbujanda | 6:193fc0aec946 | 97 | } |
| hbujanda | 6:193fc0aec946 | 98 | |
| spastor | 8:7b4771c9689c | 99 | /* Set remote device NI parameter */ |
| spastor | 8:7b4771c9689c | 100 | char ni_remote[] = "ni_example_remote"; |
| spastor | 8:7b4771c9689c | 101 | log_serial->printf("\r\nSetting remote device NI parameter to '%s':\r\n", ni_remote); |
| spastor | 8:7b4771c9689c | 102 | cmdresp = xbee.set_param(remoteDevice64b, "NI", (uint8_t*)ni_remote, strlen(ni_remote)); |
| spastor | 8:7b4771c9689c | 103 | if (cmdresp == AtCmdFrame::AtCmdRespOk) { |
| spastor | 8:7b4771c9689c | 104 | log_serial->printf("OK\r\n"); |
| spastor | 8:7b4771c9689c | 105 | } else { |
| spastor | 8:7b4771c9689c | 106 | log_serial->printf("FAILED with %d\r\n", (int) cmdresp); |
| spastor | 8:7b4771c9689c | 107 | } |
| spastor | 8:7b4771c9689c | 108 | |
| hbujanda | 6:193fc0aec946 | 109 | delete(log_serial); |
| hbujanda | 6:193fc0aec946 | 110 | } |