Vergil Cola
/
MQTTGatewayK64
Fork of my MQTTGateway
XbeeMonitor/XBeeLib/FrameHandlers/FH_IoDataSample802.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 "XBeeLib.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_IoDataSampe64b802::FH_IoDataSampe64b802() : FrameHandler(ApiFrame::Io64Bit), |
vpcola | 0:f1d3878b8dd9 | 19 | io_data_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_IoDataSampe64b802::~FH_IoDataSampe64b802() |
vpcola | 0:f1d3878b8dd9 | 25 | { |
vpcola | 0:f1d3878b8dd9 | 26 | |
vpcola | 0:f1d3878b8dd9 | 27 | } |
vpcola | 0:f1d3878b8dd9 | 28 | |
vpcola | 0:f1d3878b8dd9 | 29 | void FH_IoDataSampe64b802::register_io_data_cb(io_data_cb_802_t function) |
vpcola | 0:f1d3878b8dd9 | 30 | { |
vpcola | 0:f1d3878b8dd9 | 31 | io_data_cb = function; |
vpcola | 0:f1d3878b8dd9 | 32 | } |
vpcola | 0:f1d3878b8dd9 | 33 | |
vpcola | 0:f1d3878b8dd9 | 34 | void FH_IoDataSampe64b802::unregister_io_data_cb() |
vpcola | 0:f1d3878b8dd9 | 35 | { |
vpcola | 0:f1d3878b8dd9 | 36 | io_data_cb = NULL; |
vpcola | 0:f1d3878b8dd9 | 37 | } |
vpcola | 0:f1d3878b8dd9 | 38 | |
vpcola | 0:f1d3878b8dd9 | 39 | #define IO_SAMPLE_64_802_DATA_OFFSET 10 |
vpcola | 0:f1d3878b8dd9 | 40 | |
vpcola | 0:f1d3878b8dd9 | 41 | void FH_IoDataSampe64b802::process_frame_data(const ApiFrame *const frame) |
vpcola | 0:f1d3878b8dd9 | 42 | { |
vpcola | 0:f1d3878b8dd9 | 43 | const uint8_t * const datap = frame->get_data(); |
vpcola | 0:f1d3878b8dd9 | 44 | |
vpcola | 0:f1d3878b8dd9 | 45 | /* The caller checks that the type matches, so no need to check it here again */ |
vpcola | 0:f1d3878b8dd9 | 46 | if (io_data_cb == NULL) { |
vpcola | 0:f1d3878b8dd9 | 47 | return; |
vpcola | 0:f1d3878b8dd9 | 48 | } |
vpcola | 0:f1d3878b8dd9 | 49 | |
vpcola | 0:f1d3878b8dd9 | 50 | /* We got an IO packet, decode it... */ |
vpcola | 0:f1d3878b8dd9 | 51 | const uint64_t sender64 = addr64_from_uint8_t(datap); |
vpcola | 0:f1d3878b8dd9 | 52 | const RemoteXBee802 sender = RemoteXBee802(sender64); |
vpcola | 0:f1d3878b8dd9 | 53 | const IOSample802 ioSample = IOSample802(&datap[IO_SAMPLE_64_802_DATA_OFFSET], frame->get_data_len() - IO_SAMPLE_64_802_DATA_OFFSET); |
vpcola | 0:f1d3878b8dd9 | 54 | |
vpcola | 0:f1d3878b8dd9 | 55 | io_data_cb(sender, ioSample); |
vpcola | 0:f1d3878b8dd9 | 56 | } |
vpcola | 0:f1d3878b8dd9 | 57 | |
vpcola | 0:f1d3878b8dd9 | 58 | /** Class constructor */ |
vpcola | 0:f1d3878b8dd9 | 59 | FH_IoDataSampe16b802::FH_IoDataSampe16b802() : FrameHandler(ApiFrame::Io16Bit), |
vpcola | 0:f1d3878b8dd9 | 60 | io_data_cb(NULL) |
vpcola | 0:f1d3878b8dd9 | 61 | { |
vpcola | 0:f1d3878b8dd9 | 62 | } |
vpcola | 0:f1d3878b8dd9 | 63 | |
vpcola | 0:f1d3878b8dd9 | 64 | /** Class destructor */ |
vpcola | 0:f1d3878b8dd9 | 65 | FH_IoDataSampe16b802::~FH_IoDataSampe16b802() |
vpcola | 0:f1d3878b8dd9 | 66 | { |
vpcola | 0:f1d3878b8dd9 | 67 | } |
vpcola | 0:f1d3878b8dd9 | 68 | |
vpcola | 0:f1d3878b8dd9 | 69 | void FH_IoDataSampe16b802::register_io_data_cb(io_data_cb_802_t function) |
vpcola | 0:f1d3878b8dd9 | 70 | { |
vpcola | 0:f1d3878b8dd9 | 71 | io_data_cb = function; |
vpcola | 0:f1d3878b8dd9 | 72 | } |
vpcola | 0:f1d3878b8dd9 | 73 | |
vpcola | 0:f1d3878b8dd9 | 74 | void FH_IoDataSampe16b802::unregister_io_data_cb() |
vpcola | 0:f1d3878b8dd9 | 75 | { |
vpcola | 0:f1d3878b8dd9 | 76 | io_data_cb = NULL; |
vpcola | 0:f1d3878b8dd9 | 77 | } |
vpcola | 0:f1d3878b8dd9 | 78 | |
vpcola | 0:f1d3878b8dd9 | 79 | #define IO_SAMPLE_16_802_ADDR16_MSB_OFFSET 0 |
vpcola | 0:f1d3878b8dd9 | 80 | #define IO_SAMPLE_16_802_ADDR16_LSB_OFFSET 1 |
vpcola | 0:f1d3878b8dd9 | 81 | #define IO_SAMPLE_16_802_DATA_OFFSET 4 |
vpcola | 0:f1d3878b8dd9 | 82 | |
vpcola | 0:f1d3878b8dd9 | 83 | void FH_IoDataSampe16b802::process_frame_data(const ApiFrame *const frame) |
vpcola | 0:f1d3878b8dd9 | 84 | { |
vpcola | 0:f1d3878b8dd9 | 85 | const uint8_t * const datap = frame->get_data();; |
vpcola | 0:f1d3878b8dd9 | 86 | |
vpcola | 0:f1d3878b8dd9 | 87 | /* The caller checks that the type matches, so no need to check it here again */ |
vpcola | 0:f1d3878b8dd9 | 88 | if (io_data_cb == NULL) { |
vpcola | 0:f1d3878b8dd9 | 89 | return; |
vpcola | 0:f1d3878b8dd9 | 90 | } |
vpcola | 0:f1d3878b8dd9 | 91 | |
vpcola | 0:f1d3878b8dd9 | 92 | /* We got an IO packet, decode it... */ |
vpcola | 0:f1d3878b8dd9 | 93 | const uint16_t sender16 = ADDR16(datap[IO_SAMPLE_16_802_ADDR16_MSB_OFFSET], datap[IO_SAMPLE_16_802_ADDR16_LSB_OFFSET]); |
vpcola | 0:f1d3878b8dd9 | 94 | const RemoteXBee802 sender = RemoteXBee802(sender16); |
vpcola | 0:f1d3878b8dd9 | 95 | |
vpcola | 0:f1d3878b8dd9 | 96 | const IOSample802 ioSample = IOSample802(&datap[IO_SAMPLE_16_802_DATA_OFFSET], frame->get_data_len() - IO_SAMPLE_16_802_DATA_OFFSET); |
vpcola | 0:f1d3878b8dd9 | 97 | |
vpcola | 0:f1d3878b8dd9 | 98 | io_data_cb(sender, ioSample); |
vpcola | 0:f1d3878b8dd9 | 99 | } |