Vergil Cola
/
MQTTGatewayK64
Fork of my MQTTGateway
XbeeMonitor/XBeeLib/FrameHandlers/FH_RxPacketZB.cpp@0:f1d3878b8dd9, 2017-04-08 (annotated)
- Committer:
- vpcola
- Date:
- Sat Apr 08 14:45:51 2017 +0000
- Revision:
- 0:f1d3878b8dd9
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vpcola | 0:f1d3878b8dd9 | 1 | /** |
vpcola | 0:f1d3878b8dd9 | 2 | * Copyright (c) 2015 Digi International Inc., |
vpcola | 0:f1d3878b8dd9 | 3 | * All rights not expressly granted are reserved. |
vpcola | 0:f1d3878b8dd9 | 4 | * |
vpcola | 0:f1d3878b8dd9 | 5 | * This Source Code Form is subject to the terms of the Mozilla Public |
vpcola | 0:f1d3878b8dd9 | 6 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
vpcola | 0:f1d3878b8dd9 | 7 | * You can obtain one at http://mozilla.org/MPL/2.0/. |
vpcola | 0:f1d3878b8dd9 | 8 | * |
vpcola | 0:f1d3878b8dd9 | 9 | * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343 |
vpcola | 0:f1d3878b8dd9 | 10 | * ======================================================================= |
vpcola | 0:f1d3878b8dd9 | 11 | */ |
vpcola | 0:f1d3878b8dd9 | 12 | |
vpcola | 0:f1d3878b8dd9 | 13 | #include "FH_RxPacketZB.h" |
vpcola | 0:f1d3878b8dd9 | 14 | |
vpcola | 0:f1d3878b8dd9 | 15 | using namespace XBeeLib; |
vpcola | 0:f1d3878b8dd9 | 16 | |
vpcola | 0:f1d3878b8dd9 | 17 | /** Class constructor */ |
vpcola | 0:f1d3878b8dd9 | 18 | FH_RxPacketZB::FH_RxPacketZB() : FrameHandler(ApiFrame::RxPacketAO0), receive_cb(NULL) |
vpcola | 0:f1d3878b8dd9 | 19 | { |
vpcola | 0:f1d3878b8dd9 | 20 | } |
vpcola | 0:f1d3878b8dd9 | 21 | |
vpcola | 0:f1d3878b8dd9 | 22 | /** Class destructor */ |
vpcola | 0:f1d3878b8dd9 | 23 | FH_RxPacketZB::~FH_RxPacketZB() |
vpcola | 0:f1d3878b8dd9 | 24 | { |
vpcola | 0:f1d3878b8dd9 | 25 | } |
vpcola | 0:f1d3878b8dd9 | 26 | |
vpcola | 0:f1d3878b8dd9 | 27 | void FH_RxPacketZB::register_receive_cb(receive_zb_cb_t function) |
vpcola | 0:f1d3878b8dd9 | 28 | { |
vpcola | 0:f1d3878b8dd9 | 29 | receive_cb = function; |
vpcola | 0:f1d3878b8dd9 | 30 | } |
vpcola | 0:f1d3878b8dd9 | 31 | |
vpcola | 0:f1d3878b8dd9 | 32 | void FH_RxPacketZB::unregister_receive_cb(void) |
vpcola | 0:f1d3878b8dd9 | 33 | { |
vpcola | 0:f1d3878b8dd9 | 34 | receive_cb = NULL; |
vpcola | 0:f1d3878b8dd9 | 35 | } |
vpcola | 0:f1d3878b8dd9 | 36 | |
vpcola | 0:f1d3878b8dd9 | 37 | /* ZB RX packet offsets */ |
vpcola | 0:f1d3878b8dd9 | 38 | #define ZB_RX_ADDR16_MSB_OFFSET 8 |
vpcola | 0:f1d3878b8dd9 | 39 | #define ZB_RX_ADDR16_LSB_OFFSET 9 |
vpcola | 0:f1d3878b8dd9 | 40 | #define ZB_RX_OPTIONS_OFFSET 10 |
vpcola | 0:f1d3878b8dd9 | 41 | #define ZB_RX_DATA_OFFSET 11 |
vpcola | 0:f1d3878b8dd9 | 42 | #define ZB_RX_OVERHEAD (8+2+1) |
vpcola | 0:f1d3878b8dd9 | 43 | |
vpcola | 0:f1d3878b8dd9 | 44 | #define BROADCAST_PACKET 0x02 |
vpcola | 0:f1d3878b8dd9 | 45 | |
vpcola | 0:f1d3878b8dd9 | 46 | void FH_RxPacketZB::process_frame_data(const ApiFrame *const frame) |
vpcola | 0:f1d3878b8dd9 | 47 | { |
vpcola | 0:f1d3878b8dd9 | 48 | /* The caller checks that the type matches, so no need to check it here again */ |
vpcola | 0:f1d3878b8dd9 | 49 | |
vpcola | 0:f1d3878b8dd9 | 50 | if (receive_cb == NULL) { |
vpcola | 0:f1d3878b8dd9 | 51 | return; |
vpcola | 0:f1d3878b8dd9 | 52 | } |
vpcola | 0:f1d3878b8dd9 | 53 | |
vpcola | 0:f1d3878b8dd9 | 54 | /* We got a rx packet, decode it... */ |
vpcola | 0:f1d3878b8dd9 | 55 | const uint8_t *datap = frame->get_data(); |
vpcola | 0:f1d3878b8dd9 | 56 | const uint64_t sender64 = addr64_from_uint8_t(datap); |
vpcola | 0:f1d3878b8dd9 | 57 | const uint16_t sender16 = ADDR16(datap[ZB_RX_ADDR16_MSB_OFFSET], datap[ZB_RX_ADDR16_LSB_OFFSET]); |
vpcola | 0:f1d3878b8dd9 | 58 | const uint8_t rx_options = datap[ZB_RX_OPTIONS_OFFSET]; |
vpcola | 0:f1d3878b8dd9 | 59 | const RemoteXBeeZB sender = RemoteXBeeZB(sender64, sender16); |
vpcola | 0:f1d3878b8dd9 | 60 | |
vpcola | 0:f1d3878b8dd9 | 61 | receive_cb(sender, rx_options & BROADCAST_PACKET, &datap[ZB_RX_DATA_OFFSET], frame->get_data_len() - ZB_RX_OVERHEAD); |
vpcola | 0:f1d3878b8dd9 | 62 | } |