lel
Fork of XBeeLib by
Embed:
(wiki syntax)
Show/hide line numbers
FH_IoDataSample802.cpp
00001 /** 00002 * Copyright (c) 2015 Digi International Inc., 00003 * All rights not expressly granted are reserved. 00004 * 00005 * This Source Code Form is subject to the terms of the Mozilla Public 00006 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 00007 * You can obtain one at http://mozilla.org/MPL/2.0/. 00008 * 00009 * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343 00010 * ======================================================================= 00011 */ 00012 00013 #include "XBeeLib.h" 00014 00015 using namespace XBeeLib; 00016 00017 /** Class constructor */ 00018 FH_IoDataSampe64b802::FH_IoDataSampe64b802() : FrameHandler(ApiFrame::Io64Bit), 00019 io_data_cb(NULL) 00020 { 00021 } 00022 00023 /** Class destructor */ 00024 FH_IoDataSampe64b802::~FH_IoDataSampe64b802() 00025 { 00026 00027 } 00028 00029 void FH_IoDataSampe64b802::register_io_data_cb(io_data_cb_802_t function) 00030 { 00031 io_data_cb = function; 00032 } 00033 00034 void FH_IoDataSampe64b802::unregister_io_data_cb() 00035 { 00036 io_data_cb = NULL; 00037 } 00038 00039 #define IO_SAMPLE_64_802_DATA_OFFSET 10 00040 00041 void FH_IoDataSampe64b802::process_frame_data(const ApiFrame *const frame) 00042 { 00043 const uint8_t * const datap = frame->get_data(); 00044 00045 /* The caller checks that the type matches, so no need to check it here again */ 00046 if (io_data_cb == NULL) { 00047 return; 00048 } 00049 00050 /* We got an IO packet, decode it... */ 00051 const uint64_t sender64 = addr64_from_uint8_t(datap); 00052 const RemoteXBee802 sender = RemoteXBee802(sender64); 00053 const IOSample802 ioSample = IOSample802(&datap[IO_SAMPLE_64_802_DATA_OFFSET], frame->get_data_len() - IO_SAMPLE_64_802_DATA_OFFSET); 00054 00055 io_data_cb(sender, ioSample); 00056 } 00057 00058 /** Class constructor */ 00059 FH_IoDataSampe16b802::FH_IoDataSampe16b802() : FrameHandler(ApiFrame::Io16Bit), 00060 io_data_cb(NULL) 00061 { 00062 } 00063 00064 /** Class destructor */ 00065 FH_IoDataSampe16b802::~FH_IoDataSampe16b802() 00066 { 00067 } 00068 00069 void FH_IoDataSampe16b802::register_io_data_cb(io_data_cb_802_t function) 00070 { 00071 io_data_cb = function; 00072 } 00073 00074 void FH_IoDataSampe16b802::unregister_io_data_cb() 00075 { 00076 io_data_cb = NULL; 00077 } 00078 00079 #define IO_SAMPLE_16_802_ADDR16_MSB_OFFSET 0 00080 #define IO_SAMPLE_16_802_ADDR16_LSB_OFFSET 1 00081 #define IO_SAMPLE_16_802_DATA_OFFSET 4 00082 00083 void FH_IoDataSampe16b802::process_frame_data(const ApiFrame *const frame) 00084 { 00085 const uint8_t * const datap = frame->get_data();; 00086 00087 /* The caller checks that the type matches, so no need to check it here again */ 00088 if (io_data_cb == NULL) { 00089 return; 00090 } 00091 00092 /* We got an IO packet, decode it... */ 00093 const uint16_t sender16 = ADDR16(datap[IO_SAMPLE_16_802_ADDR16_MSB_OFFSET], datap[IO_SAMPLE_16_802_ADDR16_LSB_OFFSET]); 00094 const RemoteXBee802 sender = RemoteXBee802(sender16); 00095 00096 const IOSample802 ioSample = IOSample802(&datap[IO_SAMPLE_16_802_DATA_OFFSET], frame->get_data_len() - IO_SAMPLE_16_802_DATA_OFFSET); 00097 00098 io_data_cb(sender, ioSample); 00099 }
Generated on Sat Jul 16 2022 05:30:22 by 1.7.2