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.
Dependencies: DigiLogger
Fork of XBeeLib_vs by
Diff: FrameHandlers/FH_AtCmdResp.cpp
- Revision:
- 0:fcaad0dfa051
- Child:
- 4:629712865107
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/FrameHandlers/FH_AtCmdResp.cpp Fri May 08 11:50:56 2015 +0200
@@ -0,0 +1,174 @@
+/**
+ * Copyright (c) 2015 Digi International Inc.,
+ * All rights not expressly granted are reserved.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
+ * =======================================================================
+ */
+
+#include "FrameHandlers/FH_AtCmdResp.h"
+#include "Frames/ApiFrame.h"
+
+using namespace XBeeLib;
+
+/** Class constructor */
+FH_AtCmdResp::FH_AtCmdResp() :
+ FrameHandler(ApiFrame::AtCmdResp), at_cmd_resp_cb(NULL)
+{
+}
+
+FH_AtCmdResp::FH_AtCmdResp(ApiFrame::ApiFrameType type) :
+ FrameHandler(type), at_cmd_resp_cb(NULL)
+{
+}
+
+/** Class destructor */
+FH_AtCmdResp::~FH_AtCmdResp()
+{
+}
+
+/** */
+void FH_AtCmdResp::register_at_cmd_resp_cb(at_cmd_resp_cb_t function)
+{
+ at_cmd_resp_cb = function;
+}
+
+/** */
+void FH_AtCmdResp::unregister_at_cmd_resp_cb()
+{
+ at_cmd_resp_cb = NULL;
+}
+
+void FH_AtCmdResp::process_frame_data(const ApiFrame * const frame)
+{
+ /* The caller checks that the type matches, so no need to check it here again */
+
+ if (at_cmd_resp_cb == NULL)
+ return;
+
+ at_cmd_resp_cb(frame->get_data(), frame->get_data_len());
+}
+
+
+/** Class constructor */
+FH_NodeDiscoveryZB::FH_NodeDiscoveryZB() :
+ FH_AtCmdResp(ApiFrame::AtCmdResp), node_discovery_cb(NULL)
+{
+}
+
+/** Class destructor */
+FH_NodeDiscoveryZB::~FH_NodeDiscoveryZB()
+{
+}
+
+/** */
+void FH_NodeDiscoveryZB::register_node_discovery_cb(node_discovery_zb_cb_t function)
+{
+ node_discovery_cb = function;
+}
+
+/** */
+void FH_NodeDiscoveryZB::unregister_node_discovery_cb()
+{
+ node_discovery_cb = NULL;
+}
+
+
+void FH_NodeDiscoveryZB::process_frame_data(const ApiFrame *const frame)
+{
+ /* The caller checks that the type matches, so no need to check it here again */
+
+ if (node_discovery_cb == NULL) {
+ return;
+ }
+
+ if (frame->get_data_at(ATCMD_RESP_CMD_LOW_OFFSET) != 'N' ||
+ frame->get_data_at(ATCMD_RESP_CMD_HIGH_OFFSET) != 'D') {
+ return;
+ }
+
+ if (frame->get_data_at(ATCMD_RESP_STATUS_OFFSET) != AtCmdFrame::AtCmdRespOk) {
+ return;
+ }
+
+ 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 */
+ const uint16_t addr16 = UINT16(data[ATCMD_RESP_NW_ADDR_H_OFFSET], data[ATCMD_RESP_NW_ADDR_L_OFFSET]);
+ const uint64_t addr64 = addr64_from_uint8_t(&data[ATCMD_RESP_SH_ADDR_L_OFFSET]);
+ const char * const node_id = (const char *)&data[ATCMD_RESP_NI_OFFSET];
+#if 0
+ const unsigned int node_id_len = strlen(node_id);
+ const unsigned int parent_addr16_offset = ATCMD_RESP_NI_OFFSET + node_id_len + sizeof "";
+ const uint16_t parent_addr16 = UINT16(data[parent_addr16_offset], data[parent_addr16_offset + 1]);
+ const NetworkRole network_role = (NetworkRole)(data[parent_addr16_offset + 2]);
+ const uint16_t profile_id = UINT16(data[parent_addr16_offset + 4], data[parent_addr16_offset + 5]);
+ const uint16_t manuf_id = UINT16(data[parent_addr16_offset + 6], data[parent_addr16_offset + 7]);
+#endif
+ RemoteXBeeZB remote = RemoteXBeeZB(addr64, addr16);
+
+ node_discovery_cb(remote, node_id);
+}
+
+
+
+/** Class constructor */
+FH_NodeDiscovery802::FH_NodeDiscovery802() :
+ FH_AtCmdResp(ApiFrame::AtCmdResp), node_discovery_cb(NULL)
+{
+}
+
+/** Class destructor */
+FH_NodeDiscovery802::~FH_NodeDiscovery802()
+{
+}
+
+/** */
+void FH_NodeDiscovery802::register_node_discovery_cb(node_discovery_802_cb_t function)
+{
+ node_discovery_cb = function;
+}
+
+/** */
+void FH_NodeDiscovery802::unregister_node_discovery_cb()
+{
+ node_discovery_cb = NULL;
+}
+
+
+void FH_NodeDiscovery802::process_frame_data(const ApiFrame *const frame)
+{
+ /* The caller checks that the type matches, so no need to check it here again */
+
+ if (node_discovery_cb == NULL) {
+ return;
+ }
+
+ if (frame->get_data_at(ATCMD_RESP_CMD_LOW_OFFSET) != 'N' ||
+ frame->get_data_at(ATCMD_RESP_CMD_HIGH_OFFSET) != 'D') {
+ return;
+ }
+
+ if (frame->get_data_at(ATCMD_RESP_STATUS_OFFSET) != AtCmdFrame::AtCmdRespOk) {
+ return;
+ }
+
+ const uint16_t min_atnd_response_with_data = 2 + 8 + 1;
+ if (frame->get_data_len() < min_atnd_response_with_data) {
+ /* Do not process the ATND "OK" response */
+ return;
+ }
+
+ const uint8_t * const data = frame->get_data();
+ const uint16_t addr16 = UINT16(data[ATCMD_RESP_NW_ADDR_H_OFFSET], data[ATCMD_RESP_NW_ADDR_L_OFFSET]);
+ const uint64_t addr64 = addr64_from_uint8_t(&data[ATCMD_RESP_SH_ADDR_L_OFFSET]);
+#if 0
+ const uint8_t signal_strength = data[ATCMD_802_RESP_SIGN_STR_OFFSET];
+#endif
+ const RemoteXBee802 remote = RemoteXBee802(addr64, addr16);
+ const char * const nodeid = (const char *)(&data[ATCMD_802_RESP_NI_OFFSET]);
+
+ node_discovery_cb(remote, nodeid);
+}
