Library to easily communicate with XBee modules.

Fork of XBeeLib by Digi International Inc.

Committer:
basvuyk
Date:
Tue Mar 27 14:13:12 2018 +0000
Revision:
10:273032d9299a
Parent:
6:06522f3a6642
Slave V1.0

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 "XBeeLib.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_IoDataSampeDM::FH_IoDataSampeDM() : FrameHandler(ApiFrame::IoSampleRxZBDM),
hbujanda 6:06522f3a6642 19 io_data_cb(NULL)
hbujanda 6:06522f3a6642 20 {
hbujanda 6:06522f3a6642 21 }
hbujanda 6:06522f3a6642 22
hbujanda 6:06522f3a6642 23 /** Class destructor */
hbujanda 6:06522f3a6642 24 FH_IoDataSampeDM::~FH_IoDataSampeDM()
hbujanda 6:06522f3a6642 25 {
hbujanda 6:06522f3a6642 26 }
hbujanda 6:06522f3a6642 27
hbujanda 6:06522f3a6642 28 void FH_IoDataSampeDM::register_io_data_cb(io_data_cb_dm_t function)
hbujanda 6:06522f3a6642 29 {
hbujanda 6:06522f3a6642 30 io_data_cb = function;
hbujanda 6:06522f3a6642 31 }
hbujanda 6:06522f3a6642 32
hbujanda 6:06522f3a6642 33 void FH_IoDataSampeDM::unregister_io_data_cb()
hbujanda 6:06522f3a6642 34 {
hbujanda 6:06522f3a6642 35 io_data_cb = NULL;
hbujanda 6:06522f3a6642 36 }
hbujanda 6:06522f3a6642 37
hbujanda 6:06522f3a6642 38 /* DM RX packet offsets */
hbujanda 6:06522f3a6642 39 #define DM_IO_SAMPLE_DATA_OFFSET 11
hbujanda 6:06522f3a6642 40
hbujanda 6:06522f3a6642 41 void FH_IoDataSampeDM::process_frame_data(const ApiFrame *const frame)
hbujanda 6:06522f3a6642 42 {
hbujanda 6:06522f3a6642 43 const uint8_t * const datap = frame->get_data();;
hbujanda 6:06522f3a6642 44
hbujanda 6:06522f3a6642 45 /* The caller checks that the type matches, so no need to check it here again */
hbujanda 6:06522f3a6642 46 if (io_data_cb == NULL) {
hbujanda 6:06522f3a6642 47 return;
hbujanda 6:06522f3a6642 48 }
hbujanda 6:06522f3a6642 49
hbujanda 6:06522f3a6642 50 /* We got an IO packet, decode it... */
hbujanda 6:06522f3a6642 51 const uint64_t sender64 = addr64_from_uint8_t(datap);
hbujanda 6:06522f3a6642 52 const RemoteXBeeDM sender = RemoteXBeeDM(sender64);
hbujanda 6:06522f3a6642 53 const IOSampleDM ioSample = IOSampleDM(&datap[DM_IO_SAMPLE_DATA_OFFSET], frame->get_data_len() - DM_IO_SAMPLE_DATA_OFFSET);
hbujanda 6:06522f3a6642 54
hbujanda 6:06522f3a6642 55 io_data_cb(sender, ioSample);
hbujanda 6:06522f3a6642 56 }