Library to easily communicate with XBee modules.

Fork of XBeeLib by Digi International Inc.

Committer:
basvuyk
Date:
Mon Mar 26 13:45:24 2018 +0000
Revision:
10:055802660f2e
Parent:
6:06522f3a6642
xbee changes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hbujanda 6:06522f3a6642 1 /**
hbujanda 6:06522f3a6642 2 * Copyright (c) 2015 Digi International Inc.,
hbujanda 6:06522f3a6642 3 * All rights not expressly granted are reserved.
hbujanda 6:06522f3a6642 4 *
hbujanda 6:06522f3a6642 5 * This Source Code Form is subject to the terms of the Mozilla Public
hbujanda 6:06522f3a6642 6 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
hbujanda 6:06522f3a6642 7 * You can obtain one at http://mozilla.org/MPL/2.0/.
hbujanda 6:06522f3a6642 8 *
hbujanda 6:06522f3a6642 9 * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
hbujanda 6:06522f3a6642 10 * =======================================================================
hbujanda 6:06522f3a6642 11 */
hbujanda 6:06522f3a6642 12
hbujanda 6:06522f3a6642 13 #include "FH_RxPacketDM.h"
hbujanda 6:06522f3a6642 14
hbujanda 6:06522f3a6642 15 using namespace XBeeLib;
hbujanda 6:06522f3a6642 16
hbujanda 6:06522f3a6642 17 /** Class constructor */
hbujanda 6:06522f3a6642 18 FH_RxPacketDM::FH_RxPacketDM() : FrameHandler(ApiFrame::RxPacketAO0), receive_cb(NULL)
hbujanda 6:06522f3a6642 19 {
hbujanda 6:06522f3a6642 20 }
hbujanda 6:06522f3a6642 21
hbujanda 6:06522f3a6642 22 /** Class destructor */
hbujanda 6:06522f3a6642 23 FH_RxPacketDM::~FH_RxPacketDM()
hbujanda 6:06522f3a6642 24 {
hbujanda 6:06522f3a6642 25 }
hbujanda 6:06522f3a6642 26
hbujanda 6:06522f3a6642 27 void FH_RxPacketDM::register_receive_cb(receive_dm_cb_t function)
hbujanda 6:06522f3a6642 28 {
hbujanda 6:06522f3a6642 29 receive_cb = function;
hbujanda 6:06522f3a6642 30 }
hbujanda 6:06522f3a6642 31
hbujanda 6:06522f3a6642 32 void FH_RxPacketDM::unregister_receive_cb(void)
hbujanda 6:06522f3a6642 33 {
hbujanda 6:06522f3a6642 34 receive_cb = NULL;
hbujanda 6:06522f3a6642 35 }
hbujanda 6:06522f3a6642 36
hbujanda 6:06522f3a6642 37 /* DM RX packet offsets */
hbujanda 6:06522f3a6642 38 #define DM_RX_OPTIONS_OFFSET 10
hbujanda 6:06522f3a6642 39 #define DM_RX_DATA_OFFSET 11
hbujanda 6:06522f3a6642 40 #define DM_RX_OVERHEAD (8+2+1)
hbujanda 6:06522f3a6642 41
hbujanda 6:06522f3a6642 42 #define BROADCAST_PACKET 0x02
hbujanda 6:06522f3a6642 43
hbujanda 6:06522f3a6642 44 void FH_RxPacketDM::process_frame_data(const ApiFrame *const frame)
hbujanda 6:06522f3a6642 45 {
hbujanda 6:06522f3a6642 46 /* The caller checks that the type matches, so no need to check it here again */
hbujanda 6:06522f3a6642 47
hbujanda 6:06522f3a6642 48 if (receive_cb == NULL) {
hbujanda 6:06522f3a6642 49 return;
hbujanda 6:06522f3a6642 50 }
hbujanda 6:06522f3a6642 51
hbujanda 6:06522f3a6642 52 /* We got a rx packet, decode it... */
hbujanda 6:06522f3a6642 53 const uint8_t *datap = frame->get_data();
hbujanda 6:06522f3a6642 54 const uint64_t sender64 = addr64_from_uint8_t(datap);
hbujanda 6:06522f3a6642 55 const uint8_t rx_options = datap[DM_RX_OPTIONS_OFFSET];
hbujanda 6:06522f3a6642 56 const RemoteXBeeDM sender = RemoteXBeeDM(sender64);
hbujanda 6:06522f3a6642 57
hbujanda 6:06522f3a6642 58 receive_cb(sender, rx_options & BROADCAST_PACKET, &datap[DM_RX_DATA_OFFSET], frame->get_data_len() - DM_RX_OVERHEAD);
hbujanda 6:06522f3a6642 59 }