Digi International Inc. / Mbed 2 deprecated XBee802_IO_Sample_Callback

Dependencies:   XBeeLib mbed

Committer:
hbujanda
Date:
Wed Apr 29 17:57:56 2015 +0200
Revision:
0:e20fc9aeb09a
Child:
1:95a425d4fbd8
Automatic upload

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hbujanda 0:e20fc9aeb09a 1 /**
hbujanda 0:e20fc9aeb09a 2 * Copyright (c) 2015 Digi International Inc.,
hbujanda 0:e20fc9aeb09a 3 * All rights not expressly granted are reserved.
hbujanda 0:e20fc9aeb09a 4 *
hbujanda 0:e20fc9aeb09a 5 * This Source Code Form is subject to the terms of the Mozilla Public
hbujanda 0:e20fc9aeb09a 6 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
hbujanda 0:e20fc9aeb09a 7 * You can obtain one at http://mozilla.org/MPL/2.0/.
hbujanda 0:e20fc9aeb09a 8 *
hbujanda 0:e20fc9aeb09a 9 * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
hbujanda 0:e20fc9aeb09a 10 * =======================================================================
hbujanda 0:e20fc9aeb09a 11 */
hbujanda 0:e20fc9aeb09a 12
hbujanda 0:e20fc9aeb09a 13 #include "mbed.h"
hbujanda 0:e20fc9aeb09a 14 #include "XBeeLib.h"
hbujanda 0:e20fc9aeb09a 15 #if defined(ENABLE_LOGGING)
hbujanda 0:e20fc9aeb09a 16 #include "DigiLoggerMbedSerial.h"
hbujanda 0:e20fc9aeb09a 17 using namespace DigiLog;
hbujanda 0:e20fc9aeb09a 18 #endif
hbujanda 0:e20fc9aeb09a 19
hbujanda 0:e20fc9aeb09a 20 // TODO Replace with the MSB of the remote module's 64-bit address (SH parameter)
hbujanda 0:e20fc9aeb09a 21 #define REMOTE_NODE_ADDR64_MSB ((uint32_t)0x0013A200)
hbujanda 0:e20fc9aeb09a 22 // TODO Replace with the LSB of the remote module's 64-bit address (SL parameter)
hbujanda 0:e20fc9aeb09a 23 #define REMOTE_NODE_ADDR64_LSB ((uint32_t)0x40D2B03E)
hbujanda 0:e20fc9aeb09a 24
hbujanda 0:e20fc9aeb09a 25 using namespace XBeeLib;
hbujanda 0:e20fc9aeb09a 26
hbujanda 0:e20fc9aeb09a 27 Serial *log_serial;
hbujanda 0:e20fc9aeb09a 28
hbujanda 0:e20fc9aeb09a 29 static void io_data_cb(const RemoteXBee802& remote, const IOSample802& sample_data)
hbujanda 0:e20fc9aeb09a 30 {
hbujanda 0:e20fc9aeb09a 31 if (remote.is_valid_addr16b()) {
hbujanda 0:e20fc9aeb09a 32 uint16_t remote16;
hbujanda 0:e20fc9aeb09a 33 remote.get_addr(&remote16);
hbujanda 0:e20fc9aeb09a 34 log_serial->printf("\r\nGot a 16-bit IO Sample Data [%04x]\r\n", remote16);
hbujanda 0:e20fc9aeb09a 35 } else {
hbujanda 0:e20fc9aeb09a 36 Addr64 remote64;
hbujanda 0:e20fc9aeb09a 37 remote.get_addr(&remote64);
hbujanda 0:e20fc9aeb09a 38 log_serial->printf("\r\nGot a 64-bit IO Sample Data [%08x:%08x]\r\n", remote64.get_high32(), remote64.get_low32());
hbujanda 0:e20fc9aeb09a 39 }
hbujanda 0:e20fc9aeb09a 40
hbujanda 0:e20fc9aeb09a 41 RadioStatus radioStatus;
hbujanda 0:e20fc9aeb09a 42
hbujanda 0:e20fc9aeb09a 43 DioVal dio3;
hbujanda 0:e20fc9aeb09a 44 radioStatus = sample_data.get_dio(XBee802::DIO3_AD3, &dio3);
hbujanda 0:e20fc9aeb09a 45 if (radioStatus != Success) {
hbujanda 0:e20fc9aeb09a 46 log_serial->printf("sample_data.get_dio(XBee802::DIO3_AD3, &dio3) FAILED\r\n");
hbujanda 0:e20fc9aeb09a 47 } else {
hbujanda 0:e20fc9aeb09a 48 log_serial->printf("DIO3 Digital value %d\r\n", dio3);
hbujanda 0:e20fc9aeb09a 49 }
hbujanda 0:e20fc9aeb09a 50
hbujanda 0:e20fc9aeb09a 51 uint16_t ad2;
hbujanda 0:e20fc9aeb09a 52 radioStatus = sample_data.get_adc(XBee802::DIO2_AD2, &ad2);
hbujanda 0:e20fc9aeb09a 53 if (radioStatus != Success) {
hbujanda 0:e20fc9aeb09a 54 log_serial->printf("sample_data.get_adc(XBee802::DIO2_AD2, &ad2) FAILED\r\n");
hbujanda 0:e20fc9aeb09a 55 } else {
hbujanda 0:e20fc9aeb09a 56 log_serial->printf("AD2 Analog value %04x\r\n", ad2);
hbujanda 0:e20fc9aeb09a 57 }
hbujanda 0:e20fc9aeb09a 58 }
hbujanda 0:e20fc9aeb09a 59
hbujanda 0:e20fc9aeb09a 60 int main()
hbujanda 0:e20fc9aeb09a 61 {
hbujanda 0:e20fc9aeb09a 62 log_serial = new Serial(DEBUG_TX, DEBUG_RX);
hbujanda 0:e20fc9aeb09a 63 log_serial->baud(9600);
hbujanda 0:e20fc9aeb09a 64 log_serial->printf("Sample application to demo how to receive IO Sample Data from a RemoteXBee802 Node\r\n\r\n");
hbujanda 0:e20fc9aeb09a 65 log_serial->printf(XB_LIB_BANNER);
hbujanda 0:e20fc9aeb09a 66
hbujanda 0:e20fc9aeb09a 67 #if defined(ENABLE_LOGGING)
hbujanda 0:e20fc9aeb09a 68 new DigiLoggerMbedSerial(log_serial, LogLevelInfo);
hbujanda 0:e20fc9aeb09a 69 #endif
hbujanda 0:e20fc9aeb09a 70
hbujanda 0:e20fc9aeb09a 71 XBee802 xbee = XBee802(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600);
hbujanda 0:e20fc9aeb09a 72
hbujanda 0:e20fc9aeb09a 73 /* Register callback */
hbujanda 0:e20fc9aeb09a 74 xbee.register_io_sample_cb(&io_data_cb);
hbujanda 0:e20fc9aeb09a 75
hbujanda 0:e20fc9aeb09a 76 RadioStatus radioStatus;
hbujanda 0:e20fc9aeb09a 77 radioStatus = xbee.init();
hbujanda 0:e20fc9aeb09a 78 MBED_ASSERT(radioStatus == Success);
hbujanda 0:e20fc9aeb09a 79
hbujanda 0:e20fc9aeb09a 80 const RemoteXBee802 remoteDevice = RemoteXBee802(Addr64(REMOTE_NODE_ADDR64_MSB, REMOTE_NODE_ADDR64_LSB));
hbujanda 0:e20fc9aeb09a 81 log_serial->printf("Configuring remote Device (%08X:%08X) DIO3_AD3 as Input and DIO2_AD2 as ADC\r\n", REMOTE_NODE_ADDR64_MSB, REMOTE_NODE_ADDR64_LSB);
hbujanda 0:e20fc9aeb09a 82 radioStatus = xbee.set_pin_config(remoteDevice, XBee802::DIO3_AD3, DigitalInput);
hbujanda 0:e20fc9aeb09a 83 MBED_ASSERT(radioStatus == Success);
hbujanda 0:e20fc9aeb09a 84 radioStatus = xbee.set_pin_config(remoteDevice, XBee802::DIO2_AD2, Adc);
hbujanda 0:e20fc9aeb09a 85 MBED_ASSERT(radioStatus == Success);
hbujanda 0:e20fc9aeb09a 86
hbujanda 0:e20fc9aeb09a 87 log_serial->printf("Configuring remote Device (%08X:%08X) to send samples every 5 seconds\r\n", REMOTE_NODE_ADDR64_MSB, REMOTE_NODE_ADDR64_LSB);
hbujanda 0:e20fc9aeb09a 88 xbee.set_param(remoteDevice, "IR", (uint16_t)5000);
hbujanda 0:e20fc9aeb09a 89
hbujanda 0:e20fc9aeb09a 90 log_serial->printf("Configuring remote Device (%08X:%08X) to send samples to this device\r\n", REMOTE_NODE_ADDR64_MSB, REMOTE_NODE_ADDR64_LSB);
hbujanda 0:e20fc9aeb09a 91 Addr64 localAddr;
hbujanda 0:e20fc9aeb09a 92 xbee.get_addr(&localAddr);
hbujanda 0:e20fc9aeb09a 93 xbee.set_param(remoteDevice, "DH", localAddr.get_high32());
hbujanda 0:e20fc9aeb09a 94 xbee.set_param(remoteDevice, "DL", localAddr.get_low32());
hbujanda 0:e20fc9aeb09a 95
hbujanda 0:e20fc9aeb09a 96 while (true) {
hbujanda 0:e20fc9aeb09a 97 xbee.process_rx_frames();
hbujanda 0:e20fc9aeb09a 98 wait_ms(100);
hbujanda 0:e20fc9aeb09a 99 log_serial->printf(".");
hbujanda 0:e20fc9aeb09a 100 }
hbujanda 0:e20fc9aeb09a 101
hbujanda 0:e20fc9aeb09a 102 delete(log_serial);
hbujanda 0:e20fc9aeb09a 103 }