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.
Dependents: XBeeZB_Receive_Data
Fork of XBeeLib by
Revision 2:2ee1b6d51df2, committed 2015-05-14
- Comitter:
- hbujanda
- Date:
- Thu May 14 16:21:39 2015 +0200
- Parent:
- 1:794d1d3e4a08
- Child:
- 3:8662ebe83570
- Commit message:
- Automatic upload
Changed in this revision
--- a/DigiLogger.lib Mon May 11 17:58:00 2015 +0200 +++ b/DigiLogger.lib Thu May 14 16:21:39 2015 +0200 @@ -1,1 +1,1 @@ -http://developer.mbed.org/teams/Digi-International-Inc/code/DigiLogger/#1f16339607b7 +http://developer.mbed.org/teams/Digi-International-Inc/code/DigiLogger/#304026cffaf3
--- a/RemoteXBee/RemoteXBee.h Mon May 11 17:58:00 2015 +0200
+++ b/RemoteXBee/RemoteXBee.h Thu May 14 16:21:39 2015 +0200
@@ -115,6 +115,7 @@
protected:
friend FH_NodeDiscovery802;
+ friend class XBee802;
/** Class constructor for a 802.15.4 remote device (connected wirelessly) for which both the 64-bit and 16-bit addresses are known.
* This constructor is only used by FH_NodeDiscovery802 class.
--- a/Utils/Debug.h Mon May 11 17:58:00 2015 +0200
+++ b/Utils/Debug.h Thu May 14 16:21:39 2015 +0200
@@ -26,11 +26,13 @@
#if defined(ENABLE_ASSERTIONS)
#include "mbed.h"
+#if !(defined assert)
#define assert(expr) if (!(expr)) { \
digi_log(LogLevelNone, "Assertion failed: %s, file %s, line %d\n", \
#expr, __FILE__, __LINE__); \
mbed_die(); \
}
+#endif
#else
#define assert(expr)
#endif
--- a/Utils/Utils.cpp Mon May 11 17:58:00 2015 +0200
+++ b/Utils/Utils.cpp Thu May 14 16:21:39 2015 +0200
@@ -11,7 +11,7 @@
*/
#include "Utils.h"
-#include <cstring>
+#include <string.h>
void rmemcpy(uint8_t * const dest, const uint8_t * const src, uint16_t bytes)
{
--- a/Utils/Utils.h Mon May 11 17:58:00 2015 +0200 +++ b/Utils/Utils.h Thu May 14 16:21:39 2015 +0200 @@ -23,6 +23,8 @@ #define UINT64_HI32(u64) (uint32_t)((u64) >> 32) #define UINT64_LO32(u64) (uint32_t)((u64) & 0xFFFFFFFF) +#define UNUSED_PARAMETER(a) ((void)(a)) + /** rmemcpy - like memcpy but copies the bytes in reverse order * * @param dest pointer with the destination address
--- a/XBee/RadioConfig.cpp Mon May 11 17:58:00 2015 +0200
+++ b/XBee/RadioConfig.cpp Thu May 14 16:21:39 2015 +0200
@@ -176,6 +176,65 @@
return Success;
}
+void XBee::_get_remote_node_by_id(const char * const node_id, uint64_t * const addr64, uint16_t * const addr16)
+{
+ *addr64 = ADDR64_UNASSIGNED;
+ *addr16 = ADDR16_UNKNOWN;
+ if (node_id == NULL) {
+ return;
+ }
+ const size_t node_id_len = strlen(node_id);
+ if (node_id_len == 0 || node_id_len > MAX_NI_PARAM_LEN) {
+ return;
+ }
+
+ const uint16_t old_timeout = _timeout_ms;
+
+ uint32_t nd_timeout_100msec;
+ const AtCmdFrame::AtCmdResp nt_resp = get_param("NT", &nd_timeout_100msec);
+ if (nt_resp != AtCmdFrame::AtCmdRespOk) {
+ _timeout_ms = 10000;
+ } else {
+ _timeout_ms = (uint16_t)nd_timeout_100msec * 100 + 1000;
+ }
+
+ const AtCmdFrame::AtCmdResp cmdresp = set_param("ND", (const uint8_t *)node_id, strlen(node_id));
+ if (cmdresp != AtCmdFrame::AtCmdRespOk) {
+ _timeout_ms = old_timeout;
+ return;
+ }
+
+ const int nd_start_time = _timer.read_ms();
+ const int nd_end_time = nd_start_time + _timeout_ms;
+
+ AtCmdFrame atnd_frame = AtCmdFrame("ND", (const uint8_t *)node_id, strlen(node_id));
+ send_api_frame(&atnd_frame);
+
+ ApiFrame * const resp_frame = get_this_api_frame(atnd_frame.get_frame_id(), ApiFrame::AtCmdResp);
+ _timeout_ms = old_timeout;
+
+ while (_timer.read_ms() < nd_end_time) {
+ wait_ms(10);
+ }
+
+ if (resp_frame == NULL) {
+ digi_log(LogLevelWarning, "XBeeZB::get_remote_node_by_id timeout when waiting for ATND response");
+ return;
+ }
+
+ const AtCmdFrame::AtCmdResp resp = (AtCmdFrame::AtCmdResp)resp_frame->get_data_at(ATCMD_RESP_STATUS_OFFSET);
+ if (resp != AtCmdFrame::AtCmdRespOk) {
+ digi_log(LogLevelWarning, "send_at_cmd bad response: 0x%x\r\n", resp);
+ _framebuf.free_frame(resp_frame);
+ return;
+ }
+
+ rmemcpy((uint8_t *)addr16, resp_frame->get_data() + ATCMD_RESP_DATA_OFFSET, sizeof *addr16);
+ rmemcpy((uint8_t *)addr64, resp_frame->get_data() + ATCMD_RESP_DATA_OFFSET + sizeof *addr16, sizeof *addr64);
+ _framebuf.free_frame(resp_frame);
+ return;
+}
+
RadioStatus XBee::config_node_discovery(uint16_t timeout_ms, uint8_t options)
{
AtCmdFrame::AtCmdResp cmdresp;
--- a/XBee/XBee.cpp Mon May 11 17:58:00 2015 +0200
+++ b/XBee/XBee.cpp Thu May 14 16:21:39 2015 +0200
@@ -28,9 +28,43 @@
Timer XBee::_timer;
FrameBuffer XBee::_framebuf;
+#if defined(DEVICE_SERIAL_FC)
+bool XBee::check_radio_flow_control()
+{
+ AtCmdFrame::AtCmdResp cmdresp;
+ uint32_t value;
+
+ if (_serial_flow_type == SerialBase::RTSCTS || _serial_flow_type == SerialBase::CTS) {
+ cmdresp = get_param("D7", &value);
+ if (cmdresp != AtCmdFrame::AtCmdRespOk) {
+ digi_log(LogLevelError, "Could not read CTS configuration. Error %d\r\n", cmdresp);
+ return false;
+ }
+ else if (value != 1) {
+ digi_log(LogLevelError, "Bad CTS configuration. Radio 'D7' param is %d and should be 1\r\n", value);
+ return false;
+ }
+ }
+
+ if (_serial_flow_type == SerialBase::RTSCTS || _serial_flow_type == SerialBase::RTS) {
+ cmdresp = get_param("D6", &value);
+ if (cmdresp != AtCmdFrame::AtCmdRespOk) {
+ digi_log(LogLevelError, "Could not read RTS configuration. Error %d\r\n", cmdresp);
+ return false;
+ }
+ else if (value != 1) {
+ digi_log(LogLevelError, "Bad RTS configuration. Radio 'D6' param is %d and should be 1\r\n", value);
+ return false;
+ }
+ }
+
+ return true;
+}
+#endif
+
/* Class constructor */
XBee::XBee(PinName tx, PinName rx, PinName reset, PinName rts, PinName cts, int baud) :
- _mode(ModeUnknown), _type(Unknown), _timeout_ms(SYNC_OPS_TIMEOUT_MS), _hw_version(0), _fw_version(0), _dev_addr64(ADDR64_UNASSIGNED), _dev_addr16(ADDR16_UNKNOWN),
+ _mode(ModeUnknown), _type(Unknown), _hw_version(0), _fw_version(0), _timeout_ms(SYNC_OPS_TIMEOUT_MS), _dev_addr64(ADDR64_UNASSIGNED), _dev_addr16(ADDR16_UNKNOWN),
_reset(NULL), _tx_options(0), _bc_radius(0), _hw_reset_cnt(0), _wd_reset_cnt(0), _reset_timeout(0), _modem_status_handler(NULL), _modem_status(AtCmdFrame::HwReset), _initializing(true), _pm_mode(SleepDisabled)
{
@@ -48,13 +82,8 @@
_serial_flow_type = SerialBase::Disabled;
#if defined(DEVICE_SERIAL_FC)
if (rts != NC && cts != NC) {
-#if !(defined AVOID_USING_RTS)
_serial_flow_type = SerialBase::RTSCTS;
_uart->set_flow_control(_serial_flow_type, rts, cts);
-#else
- _serial_flow_type = SerialBase::CTS;
- _uart->set_flow_control(_serial_flow_type, cts);
-#endif
}
else if (rts != NC && cts == NC) {
_serial_flow_type = SerialBase::RTS;
@@ -142,6 +171,11 @@
digi_log(LogLevelInfo, "ADDR64: %08x:%08x\r\n", UINT64_HI32(_dev_addr64), UINT64_LO32(_dev_addr64));
digi_log(LogLevelInfo, "ADDR16: %04x\r\n", _dev_addr16);
+#if defined(DEVICE_SERIAL_FC)
+ bool valid_radio_fc = check_radio_flow_control();
+ assert(valid_radio_fc == true);
+#endif
+
_initializing = false;
if (_modem_status_handler != NULL) {
const ApiFrame frame = ApiFrame(ApiFrame::AtModemStatus, (uint8_t *)&_modem_status, sizeof(_modem_status));
@@ -304,6 +338,7 @@
* object has been completed and the virtual functions filled */
void XBee::radio_status_update(AtCmdFrame::ModemStatus modem_status)
{
+ UNUSED_PARAMETER(modem_status);
}
void XBee::set_timeout(uint16_t timeout_ms)
@@ -653,6 +688,8 @@
RadioStatus XBee::config_pm_timing(uint32_t before_sleep_ms, uint32_t total_sleep_period_ms)
{
+ UNUSED_PARAMETER(before_sleep_ms);
+ UNUSED_PARAMETER(total_sleep_period_ms);
return Success;
}
--- a/XBee/XBee.h Mon May 11 17:58:00 2015 +0200
+++ b/XBee/XBee.h Thu May 14 16:21:39 2015 +0200
@@ -403,13 +403,18 @@
*/
RadioStatus start_node_discovery();
+#define XBEEZB_ND_OPTION_APPEND_DD (1 << 0)
+#define XBEEZB_ND_OPTION_SELF_RESPONSE (1 << 1)
+#define XBEE802_ND_OPTION_SELF_RESPONSE (1 << 0)
+
/** config_node_discovery - configures the node discovery operation
*
* @param timeout_ms max allowed time for devices in the network to answer
* to the Node Discovery request
* @param options node discovery options (flags)
- * ND_OPTION_APPEND_DD - to append the DD value to the response
- * ND_OPTION_SELF_RESPONSE - to allow the module self responding
+ * XBEE802_ND_OPTION_SELF_RESPONSE - to allow the module self responding (802.15.4 only)
+ * XBEEZB_ND_OPTION_SELF_RESPONSE - to allow the module self responding (ZigBee only)
+ * XBEEZB_ND_OPTION_APPEND_DD - to append the DD value to the response (ZigBee only)
* @returns
* Success if the operation was successful,
* Failure otherwise
@@ -764,6 +769,15 @@
*/
RadioStatus get_iosample(const RemoteXBee& remote, uint8_t * const io_sample, uint16_t * const len);
+ void _get_remote_node_by_id(const char * const node_id, uint64_t * addr64, uint16_t * addr16);
+
+ /** check_radio_flow_control - checks that the radio has the CTS "D7" and RTS "D6" pins configured
+ * according to the serial hardware flow control selected by the user
+ *
+ * @returns true if check success.
+ */
+ bool check_radio_flow_control();
+
/** serial hardware flow control selected by the user (RTSCTS, RTS,CTS) */
SerialBase::Flow _serial_flow_type;
--- a/XBee802/XBee802.cpp Mon May 11 17:58:00 2015 +0200
+++ b/XBee802/XBee802.cpp Thu May 14 16:21:39 2015 +0200
@@ -160,16 +160,39 @@
return TxStatusInvalidAddr;
}
-TxStatus XBee802::send_data(uint64_t remote64, const uint8_t *const data, uint16_t len)
+TxStatus XBee802::send_data_asyncr(const RemoteXBee& remote, const uint8_t *const data, uint16_t len)
{
- TxFrame802 frame = TxFrame802(remote64, _tx_options, data, len);
- return send_data(&frame);
+ if (remote.is_valid_addr64b()) {
+ const uint64_t remote64 = remote.get_addr64();
+
+ digi_log(LogLevelDebug, "send_data ADDR64: %08x:%08x\r\n", UINT64_HI32(remote64), UINT64_LO32(remote64));
+
+ TxFrame802 frame = TxFrame802(remote64, _tx_options, data, len);
+
+ send_api_frame(&frame);
+ return TxStatusSuccess;
+ }
+
+ if (remote.is_valid_addr16b()) {
+ const uint16_t remote16 = remote.get_addr16();
+
+ digi_log(LogLevelDebug, "send_data ADDR16: %04x\r\n", remote16);
+
+ TxFrame802 frame = TxFrame802(remote16, _tx_options, data, len);
+
+ send_api_frame(&frame);
+ return TxStatusSuccess;
+ }
+
+ return TxStatusInvalidAddr;
}
-TxStatus XBee802::send_data(uint16_t addr16, const uint8_t *const data, uint16_t len)
+RemoteXBee802 XBee802::get_remote_node_by_id(const char * const node_id)
{
- TxFrame802 frame = TxFrame802(addr16, _tx_options, data, len);
- return send_data(&frame);
+ uint64_t addr64;
+ uint16_t addr16;
+ _get_remote_node_by_id(node_id, &addr64, &addr16);
+ return RemoteXBee802(addr64, addr16);
}
void XBee802::register_node_discovery_cb(node_discovery_802_cb_t function)
--- a/XBee802/XBee802.h Mon May 11 17:58:00 2015 +0200
+++ b/XBee802/XBee802.h Thu May 14 16:21:39 2015 +0200
@@ -153,29 +153,24 @@
*/
virtual TxStatus send_data(const RemoteXBee& remote, const uint8_t *const data, uint16_t len);
- /** send_data - sends data to a remote device waiting for the packet
- * answer with the result of the operation
+ /** send_data_asyncr - sends data to a remote device not waiting for the packet answer
*
- * @param remote64 64bit address of the remote device
+ * @param remote remote device
* @param data pointer to the data that will be sent
* @param len number of bytes that will be transmitted
* @returns the result of the data transfer
* TxStatusSuccess if the operation was successful,
* the error code otherwise
*/
- TxStatus send_data(uint64_t remote64, const uint8_t *const data, uint16_t len);
+ TxStatus send_data_asyncr(const RemoteXBee& remote, const uint8_t *const data, uint16_t len);
- /** send_data - sends data to a remote device waiting for the packet
- * answer with the result of the operation
+ /** get_remote_node_by_id - searches for a device in the network with the specified Node Identifier.
*
- * @param addr16 16bit address of the remote device
- * @param data pointer to the data that will be sent
- * @param len number of bytes that will be transmitted
- * @returns the result of the data transfer
- * TxStatusSuccess if the operation was successful,
- * the error code otherwise
+ * @param node_id node id of the device we are looking for
+ * @returns a RemoteXBee802 with the 16-bit and 64-bit address of the remote device whose node id matches with the parameter.
+ * If node is not found, the returned object will have invalid addresses (RemoteXBee802::is_valid() will return false).
*/
- TxStatus send_data(uint16_t addr16, const uint8_t *const data, uint16_t len);
+ RemoteXBee802 get_remote_node_by_id(const char * const node_id);
/* Allow using XBee::set_param() methods for local radio from this class */
using XBee::set_param;
--- a/XBeeZB/XBeeZB.cpp Mon May 11 17:58:00 2015 +0200
+++ b/XBeeZB/XBeeZB.cpp Thu May 14 16:21:39 2015 +0200
@@ -284,19 +284,19 @@
return send_data(&frame);
}
-TxStatus XBeeZB::send_data(uint64_t remote64, const uint8_t *const data, uint16_t len)
+TxStatus XBeeZB::send_data_asyncr(const RemoteXBee& remote, const uint8_t *const data, uint16_t len)
{
- TxFrameZB frame = TxFrameZB(remote64, ADDR16_UNKNOWN, _broadcast_radious,
- _tx_options, data, len);
- return send_data(&frame);
-}
+ if (!remote.is_valid_addr64b())
+ return TxStatusInvalidAddr;
-TxStatus XBeeZB::send_data(uint64_t remote64, uint16_t remote16,
- const uint8_t *const data, uint16_t len)
-{
+ const uint64_t remote64 = remote.get_addr64();
+ const uint16_t remote16 = remote.get_addr16();
+
TxFrameZB frame = TxFrameZB(remote64, remote16, _broadcast_radious,
_tx_options, data, len);
- return send_data(&frame);
+
+ send_api_frame(&frame);
+ return TxStatusSuccess;
}
TxStatus XBeeZB::send_data(const RemoteXBee& remote, uint8_t source_ep,
@@ -314,17 +314,7 @@
_tx_options, data, len);
return send_data(&frame);
}
-
-TxStatus XBeeZB::send_data(uint64_t remote64, uint16_t remote16, uint8_t source_ep,
- uint8_t dest_ep, uint16_t cluster_id, uint16_t profile_id,
- const uint8_t *const data, uint16_t len)
-{
- TxFrameZB frame = TxFrameZB(remote64, remote16, source_ep, dest_ep,
- cluster_id, profile_id, _broadcast_radious,
- _tx_options, data, len);
- return send_data(&frame);
-}
-
+
TxStatus XBeeZB::send_data_to_coordinator(const uint8_t *const data, uint16_t len)
{
const uint64_t remaddr = ADDR64_COORDINATOR;
@@ -334,6 +324,14 @@
return send_data(&frame);
}
+RemoteXBeeZB XBeeZB::get_remote_node_by_id(const char * const node_id)
+{
+ uint64_t addr64;
+ uint16_t addr16;
+ _get_remote_node_by_id(node_id, &addr64, &addr16);
+ return RemoteXBeeZB(addr64, addr16);
+}
+
NetworkRole XBeeZB::get_network_role()
{
return _nw_role;
@@ -401,37 +399,6 @@
}
}
-XBeeZB * XBeeZB::get_device_by_id(const char * const node_id)
-{
- return NULL;
-}
-
-RadioStatus XBeeZB::get_device_by_id(const char * const node_id, uint64_t * const dev_addr)
-{
- AtCmdFrame::AtCmdResp cmdresp;
- uint32_t dh, dl;
-
- if (strlen(node_id) > MAX_NI_PARAM_LEN)
- return Failure;
-
- cmdresp = set_param("DN", (const uint8_t *)node_id, strlen(node_id));
- if (cmdresp != AtCmdFrame::AtCmdRespOk)
- return Failure;
-
- /* Read the address of the remote device from the DH, DL parameters */
- cmdresp = get_param("DH", &dh);
- if (cmdresp != AtCmdFrame::AtCmdRespOk)
- return Failure;
-
- cmdresp = get_param("DL", &dl);
- if (cmdresp != AtCmdFrame::AtCmdRespOk)
- return Failure;
-
- *dev_addr = UINT64(dh, dl);
-
- return Success;
-}
-
AtCmdFrame::AtCmdResp XBeeZB::get_param(const RemoteXBee& remote, const char * const param, uint32_t * const data)
{
if (!remote.is_valid_addr64b())
--- a/XBeeZB/XBeeZB.h Mon May 11 17:58:00 2015 +0200
+++ b/XBeeZB/XBeeZB.h Thu May 14 16:21:39 2015 +0200
@@ -21,9 +21,6 @@
namespace XBeeLib {
-#define ND_OPTION_APPEND_DD (1 << 0)
-#define ND_OPTION_SELF_RESPONSE (1 << 1)
-
/** Class for XBee ZigBee modules, derived from XBee */
class XBeeZB : public XBee
{
@@ -255,33 +252,16 @@
*/
virtual TxStatus send_data(const RemoteXBee& remote, const uint8_t *const data, uint16_t len);
- /** send_data - sends data to a remote device waiting for the packet
- * answer with the result of the operation
+ /** send_data_asyncr - sends data to a remote device not waiting for the packet answer
*
- * @param remote64 64bit address of the remote device
+ * @param remote remote device
* @param data pointer to the data that will be sent
* @param len number of bytes that will be transmitted
* @returns the result of the data transfer
* TxStatusSuccess if the operation was successful,
* the error code otherwise
*/
- TxStatus send_data(uint64_t remote64, const uint8_t *const data, uint16_t len);
-
- /** send_data - sends data to a remote device waiting for the packet
- * answer with the result of the operation. The main difference
- * with the previous method is that includes the network address
- * being more effective, not being neccesary to discover it
- *
- * @param remote64 64bit address of the remote device
- * @param remote16 16bit network address of the remote device
- * @param data pointer to the data that will be sent
- * @param len number of bytes that will be transmitted
- * @returns the result of the data transfer
- * TxStatusSuccess if the operation was successful,
- * the error code otherwise
- */
- TxStatus send_data(uint64_t remote64, uint16_t remote16,
- const uint8_t *const data, uint16_t len);
+ TxStatus send_data_asyncr(const RemoteXBee& remote, const uint8_t *const data, uint16_t len);
/** send_data - sends data to a remote device waiting for the packet
* answer with the result of the operation. This method uses
@@ -303,27 +283,6 @@
uint8_t dest_ep, uint16_t cluster_id, uint16_t profile_id,
const uint8_t *const data, uint16_t len);
- /** send_data - sends data to a remote device waiting for the packet
- * answer with the result of the operation. This method uses
- * the explicit addressing frame, allowing to use source and
- * destination end points and cluster and profile IDs
- *
- * @param remote64 64bit address of the remote device
- * @param remote16 16bit network address of the remote device
- * @param source_ep source end point
- * @param dest_ep destination end point
- * @param cluster_id cluster ID
- * @param profile_id profile ID
- * @param data pointer to the data that will be sent
- * @param len number of bytes that will be transmitted
- * @returns the result of the data transfer
- * TxStatusSuccess if the operation was successful,
- * the error code otherwise
- */
- TxStatus send_data(uint64_t remote64, uint16_t remote16, uint8_t source_ep,
- uint8_t dest_ep, uint16_t cluster_id, uint16_t profile_id,
- const uint8_t *const data, uint16_t len);
-
/** send_data_to_coordinator - sends data to the ZigBee coordinator waiting for the
* packet answer with the result of the operation
*
@@ -340,23 +299,13 @@
*/
bool is_joined();
- /** get_device_by_id - finds and retrieves a pointer to the remote device in
- * the network whose device id matches with the parameter
+ /** get_remote_node_by_id - searches for a device in the network with the specified Node Identifier.
*
* @param node_id node id of the device we are looking for
- * @returns a pointer to the remote object device created or NULL if the device
- * was not found
+ * @returns a RemoteXBeeZB with the 16-bit and 64-bit address of the remote device whose node id matches with the parameter.
+ * If node is not found, the returned object will have invalid addresses (RemoteXBeeZB::is_valid() will return false).
*/
- XBeeZB * get_device_by_id(const char * const node_id);
-
- /** get_device_by_id - searches for a device in the network with the especified
- * node id, if found, returns its 64 bit address
- *
- * @param node_id node id of the device we are looking for
- * @returns an object with the 64 bit address of the remote device whose node id
- * matches with the parameter
- */
- RadioStatus get_device_by_id(const char * const node_id, uint64_t * const dev_addr);
+ RemoteXBeeZB get_remote_node_by_id(const char * const node_id);
/* Allow using XBee::set_param() methods for local radio from this class */
using XBee::set_param;
