Fork of my MQTTGateway

Dependencies:   mbed-http

Committer:
vpcola
Date:
Sat Apr 08 14:45:51 2017 +0000
Revision:
0:f1d3878b8dd9
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew 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_RxPacket802.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_RxPacket64b802::FH_RxPacket64b802() : FrameHandler(ApiFrame::RxPacket64Bit),
vpcola 0:f1d3878b8dd9 19 receive_cb(NULL)
vpcola 0:f1d3878b8dd9 20 {
vpcola 0:f1d3878b8dd9 21 }
vpcola 0:f1d3878b8dd9 22
vpcola 0:f1d3878b8dd9 23 /** Class destructor */
vpcola 0:f1d3878b8dd9 24 FH_RxPacket64b802::~FH_RxPacket64b802()
vpcola 0:f1d3878b8dd9 25 {
vpcola 0:f1d3878b8dd9 26 }
vpcola 0:f1d3878b8dd9 27
vpcola 0:f1d3878b8dd9 28 void FH_RxPacket64b802::register_receive_cb(receive_802_cb_t function)
vpcola 0:f1d3878b8dd9 29 {
vpcola 0:f1d3878b8dd9 30 receive_cb = function;
vpcola 0:f1d3878b8dd9 31 }
vpcola 0:f1d3878b8dd9 32
vpcola 0:f1d3878b8dd9 33 void FH_RxPacket64b802::unregister_receive_cb(void)
vpcola 0:f1d3878b8dd9 34 {
vpcola 0:f1d3878b8dd9 35 receive_cb = NULL;
vpcola 0:f1d3878b8dd9 36 }
vpcola 0:f1d3878b8dd9 37
vpcola 0:f1d3878b8dd9 38 /* 802.15.4 RX packet offsets */
vpcola 0:f1d3878b8dd9 39 #define RX_802_RSSI_OFFSET 8
vpcola 0:f1d3878b8dd9 40 #define RX_802_OPTIONS_OFFSET 9
vpcola 0:f1d3878b8dd9 41 #define RX_802_DATA_OFFSET 10
vpcola 0:f1d3878b8dd9 42 #define RX_802_OVERHEAD (8+1+1)
vpcola 0:f1d3878b8dd9 43
vpcola 0:f1d3878b8dd9 44 #define BROADCAST_PACKET 0x02
vpcola 0:f1d3878b8dd9 45
vpcola 0:f1d3878b8dd9 46 void FH_RxPacket64b802::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 uint8_t rx_options = datap[RX_802_OPTIONS_OFFSET];
vpcola 0:f1d3878b8dd9 58 const RemoteXBee802 sender = RemoteXBee802(sender64);
vpcola 0:f1d3878b8dd9 59
vpcola 0:f1d3878b8dd9 60 receive_cb(sender, rx_options & BROADCAST_PACKET, &datap[RX_802_DATA_OFFSET], frame->get_data_len() - RX_802_OVERHEAD);
vpcola 0:f1d3878b8dd9 61 }
vpcola 0:f1d3878b8dd9 62
vpcola 0:f1d3878b8dd9 63
vpcola 0:f1d3878b8dd9 64 /** Class constructor */
vpcola 0:f1d3878b8dd9 65 FH_RxPacket16b802::FH_RxPacket16b802() : FrameHandler(ApiFrame::RxPacket16Bit),
vpcola 0:f1d3878b8dd9 66 receive_cb(NULL)
vpcola 0:f1d3878b8dd9 67 {
vpcola 0:f1d3878b8dd9 68 }
vpcola 0:f1d3878b8dd9 69
vpcola 0:f1d3878b8dd9 70 /** Class destructor */
vpcola 0:f1d3878b8dd9 71 FH_RxPacket16b802::~FH_RxPacket16b802()
vpcola 0:f1d3878b8dd9 72 {
vpcola 0:f1d3878b8dd9 73 }
vpcola 0:f1d3878b8dd9 74
vpcola 0:f1d3878b8dd9 75 void FH_RxPacket16b802::register_receive_cb(receive_802_cb_t function)
vpcola 0:f1d3878b8dd9 76 {
vpcola 0:f1d3878b8dd9 77 receive_cb = function;
vpcola 0:f1d3878b8dd9 78 }
vpcola 0:f1d3878b8dd9 79
vpcola 0:f1d3878b8dd9 80 void FH_RxPacket16b802::unregister_receive_cb(void)
vpcola 0:f1d3878b8dd9 81 {
vpcola 0:f1d3878b8dd9 82 receive_cb = NULL;
vpcola 0:f1d3878b8dd9 83 }
vpcola 0:f1d3878b8dd9 84
vpcola 0:f1d3878b8dd9 85 /* 802.15.4 RX packet offsets */
vpcola 0:f1d3878b8dd9 86 #define RX_802_ADDR16_MSB_OFFSET 0
vpcola 0:f1d3878b8dd9 87 #define RX_802_ADDR16_LSB_OFFSET 1
vpcola 0:f1d3878b8dd9 88 #define RX_802_RSSI_OFFSET2 2
vpcola 0:f1d3878b8dd9 89 #define RX_802_OPTIONS_OFFSET2 3
vpcola 0:f1d3878b8dd9 90 #define RX_802_DATA_OFFSET2 4
vpcola 0:f1d3878b8dd9 91 #define RX_802_OVERHEAD2 (2+1+1)
vpcola 0:f1d3878b8dd9 92
vpcola 0:f1d3878b8dd9 93 void FH_RxPacket16b802::process_frame_data(const ApiFrame *const frame)
vpcola 0:f1d3878b8dd9 94 {
vpcola 0:f1d3878b8dd9 95 /* The caller checks that the type matches, so no need to check it here again */
vpcola 0:f1d3878b8dd9 96
vpcola 0:f1d3878b8dd9 97 if (receive_cb == NULL) {
vpcola 0:f1d3878b8dd9 98 return;
vpcola 0:f1d3878b8dd9 99 }
vpcola 0:f1d3878b8dd9 100
vpcola 0:f1d3878b8dd9 101 /* We got a rx packet, decode it... */
vpcola 0:f1d3878b8dd9 102 const uint8_t *datap = frame->get_data();
vpcola 0:f1d3878b8dd9 103 const uint16_t sender16 = ADDR16(datap[RX_802_ADDR16_MSB_OFFSET], datap[RX_802_ADDR16_LSB_OFFSET]);
vpcola 0:f1d3878b8dd9 104 const uint8_t rx_options = datap[RX_802_OPTIONS_OFFSET2];
vpcola 0:f1d3878b8dd9 105 const RemoteXBee802 sender = RemoteXBee802(sender16);
vpcola 0:f1d3878b8dd9 106
vpcola 0:f1d3878b8dd9 107 receive_cb(sender, rx_options & BROADCAST_PACKET, &datap[RX_802_DATA_OFFSET2], frame->get_data_len() - RX_802_OVERHEAD2);
vpcola 0:f1d3878b8dd9 108 }