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