Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of XBeeLib by
FH_AtCmdResp.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 "FrameHandlers/FH_AtCmdResp.h" 00014 #include "Frames/ApiFrame.h" 00015 00016 using namespace XBeeLib; 00017 00018 /** Class constructor */ 00019 FH_AtCmdResp::FH_AtCmdResp() : 00020 FrameHandler(ApiFrame::AtCmdResp), at_cmd_resp_cb(NULL) 00021 { 00022 } 00023 00024 FH_AtCmdResp::FH_AtCmdResp(ApiFrame::ApiFrameType type) : 00025 FrameHandler(type), at_cmd_resp_cb(NULL) 00026 { 00027 } 00028 00029 /** Class destructor */ 00030 FH_AtCmdResp::~FH_AtCmdResp() 00031 { 00032 } 00033 00034 void FH_AtCmdResp::register_at_cmd_resp_cb(at_cmd_resp_cb_t function) 00035 { 00036 at_cmd_resp_cb = function; 00037 } 00038 00039 void FH_AtCmdResp::unregister_at_cmd_resp_cb() 00040 { 00041 at_cmd_resp_cb = NULL; 00042 } 00043 00044 void FH_AtCmdResp::process_frame_data(const ApiFrame * const frame) 00045 { 00046 /* The caller checks that the type matches, so no need to check it here again */ 00047 00048 if (at_cmd_resp_cb == NULL) { 00049 return; 00050 } 00051 00052 at_cmd_resp_cb(frame->get_data(), frame->get_data_len()); 00053 } 00054 00055 00056 /** Class constructor */ 00057 FH_NodeDiscoveryZB::FH_NodeDiscoveryZB() : 00058 FH_AtCmdResp(ApiFrame::AtCmdResp), node_discovery_cb(NULL) 00059 { 00060 } 00061 00062 /** Class destructor */ 00063 FH_NodeDiscoveryZB::~FH_NodeDiscoveryZB() 00064 { 00065 } 00066 00067 void FH_NodeDiscoveryZB::register_node_discovery_cb(node_discovery_zb_cb_t function) 00068 { 00069 node_discovery_cb = function; 00070 } 00071 00072 void FH_NodeDiscoveryZB::unregister_node_discovery_cb() 00073 { 00074 node_discovery_cb = NULL; 00075 } 00076 00077 00078 void FH_NodeDiscoveryZB::process_frame_data(const ApiFrame *const frame) 00079 { 00080 /* The caller checks that the type matches, so no need to check it here again */ 00081 00082 if (node_discovery_cb == NULL) { 00083 return; 00084 } 00085 00086 if (frame->get_data_at(ATCMD_RESP_CMD_LOW_OFFSET) != 'N' || 00087 frame->get_data_at(ATCMD_RESP_CMD_HIGH_OFFSET) != 'D') { 00088 return; 00089 } 00090 00091 if (frame->get_data_at(ATCMD_RESP_STATUS_OFFSET) != AtCmdFrame::AtCmdRespOk) { 00092 return; 00093 } 00094 00095 const uint8_t * const data = frame->get_data(); /* The data payload we get here is the full AT command response payload, excluding the frameid. Keep that in mind for the offsets */ 00096 const uint16_t addr16 = UINT16(data[ATCMD_RESP_NW_ADDR_H_OFFSET], data[ATCMD_RESP_NW_ADDR_L_OFFSET]); 00097 const uint64_t addr64 = addr64_from_uint8_t(&data[ATCMD_RESP_SH_ADDR_L_OFFSET]); 00098 const char * const node_id = (const char *)&data[ATCMD_RESP_NI_OFFSET]; 00099 RemoteXBeeZB remote = RemoteXBeeZB(addr64, addr16); 00100 00101 node_discovery_cb(remote, node_id); 00102 } 00103 00104 00105 00106 /** Class constructor */ 00107 FH_NodeDiscovery802::FH_NodeDiscovery802() : 00108 FH_AtCmdResp(ApiFrame::AtCmdResp), node_discovery_cb(NULL) 00109 { 00110 } 00111 00112 /** Class destructor */ 00113 FH_NodeDiscovery802::~FH_NodeDiscovery802() 00114 { 00115 } 00116 00117 void FH_NodeDiscovery802::register_node_discovery_cb(node_discovery_802_cb_t function) 00118 { 00119 node_discovery_cb = function; 00120 } 00121 00122 void FH_NodeDiscovery802::unregister_node_discovery_cb() 00123 { 00124 node_discovery_cb = NULL; 00125 } 00126 00127 00128 void FH_NodeDiscovery802::process_frame_data(const ApiFrame *const frame) 00129 { 00130 /* The caller checks that the type matches, so no need to check it here again */ 00131 00132 if (node_discovery_cb == NULL) { 00133 return; 00134 } 00135 00136 if (frame->get_data_at(ATCMD_RESP_CMD_LOW_OFFSET) != 'N' || 00137 frame->get_data_at(ATCMD_RESP_CMD_HIGH_OFFSET) != 'D') { 00138 return; 00139 } 00140 00141 if (frame->get_data_at(ATCMD_RESP_STATUS_OFFSET) != AtCmdFrame::AtCmdRespOk) { 00142 return; 00143 } 00144 00145 const uint16_t min_atnd_response_with_data = sizeof (uint16_t) + sizeof(uint64_t); 00146 if (frame->get_data_len() < min_atnd_response_with_data) { 00147 /* Do not process the ATND "OK" response */ 00148 return; 00149 } 00150 00151 const uint8_t * const data = frame->get_data(); 00152 const uint16_t addr16 = UINT16(data[ATCMD_RESP_NW_ADDR_H_OFFSET], data[ATCMD_RESP_NW_ADDR_L_OFFSET]); 00153 const uint64_t addr64 = addr64_from_uint8_t(&data[ATCMD_RESP_SH_ADDR_L_OFFSET]); 00154 #if 0 00155 const uint8_t signal_strength = data[ATCMD_802_RESP_SIGN_STR_OFFSET]; 00156 #endif 00157 const RemoteXBee802 remote = RemoteXBee802(addr64, addr16); 00158 const char * const nodeid = (const char *)(&data[ATCMD_802_RESP_NI_OFFSET]); 00159 00160 node_discovery_cb(remote, nodeid); 00161 } 00162 00163 /** Class constructor */ 00164 FH_NodeDiscoveryDM::FH_NodeDiscoveryDM() : 00165 FH_AtCmdResp(ApiFrame::AtCmdResp), node_discovery_cb(NULL) 00166 { 00167 } 00168 00169 /** Class destructor */ 00170 FH_NodeDiscoveryDM::~FH_NodeDiscoveryDM() 00171 { 00172 } 00173 00174 void FH_NodeDiscoveryDM::register_node_discovery_cb(node_discovery_dm_cb_t function) 00175 { 00176 node_discovery_cb = function; 00177 } 00178 00179 void FH_NodeDiscoveryDM::unregister_node_discovery_cb() 00180 { 00181 node_discovery_cb = NULL; 00182 } 00183 00184 00185 void FH_NodeDiscoveryDM::process_frame_data(const ApiFrame *const frame) 00186 { 00187 /* The caller checks that the type matches, so no need to check it here again */ 00188 00189 if (node_discovery_cb == NULL) { 00190 return; 00191 } 00192 00193 if (frame->get_data_at(ATCMD_RESP_CMD_LOW_OFFSET) != 'N' || 00194 frame->get_data_at(ATCMD_RESP_CMD_HIGH_OFFSET) != 'D') { 00195 return; 00196 } 00197 00198 if (frame->get_data_at(ATCMD_RESP_STATUS_OFFSET) != AtCmdFrame::AtCmdRespOk) { 00199 return; 00200 } 00201 00202 const uint8_t * const data = frame->get_data(); /* The data payload we get here is the full AT command response payload, excluding the frameid. Keep that in mind for the offsets */ 00203 const uint64_t addr64 = addr64_from_uint8_t(&data[ATCMD_RESP_SH_ADDR_L_OFFSET]); 00204 const char * const node_id = (const char *)&data[ATCMD_RESP_NI_OFFSET]; 00205 RemoteXBeeDM remote = RemoteXBeeDM(addr64); 00206 00207 node_discovery_cb(remote, node_id); 00208 }
Generated on Tue Jul 12 2022 20:40:23 by
