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 1:794d1d3e4a08, committed 2015-05-11
- Comitter:
- hbujanda
- Date:
- Mon May 11 17:58:00 2015 +0200
- Parent:
- 0:fcaad0dfa051
- Child:
- 2:2ee1b6d51df2
- Commit message:
- Automatic upload
Changed in this revision
--- a/DigiLogger.lib Fri May 08 11:50:56 2015 +0200 +++ b/DigiLogger.lib Mon May 11 17:58:00 2015 +0200 @@ -1,1 +1,1 @@ -http://developer.mbed.org/teams/Digi-International-Inc/code/DigiLogger/#79cea2b2eea6 +http://developer.mbed.org/teams/Digi-International-Inc/code/DigiLogger/#1f16339607b7
--- a/RemoteXBee/RemoteXBee.h Fri May 08 11:50:56 2015 +0200
+++ b/RemoteXBee/RemoteXBee.h Mon May 11 17:58:00 2015 +0200
@@ -115,7 +115,6 @@
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/Utils.h Fri May 08 11:50:56 2015 +0200 +++ b/Utils/Utils.h Mon May 11 17:58:00 2015 +0200 @@ -23,8 +23,6 @@ #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 Fri May 08 11:50:56 2015 +0200
+++ b/XBee/RadioConfig.cpp Mon May 11 17:58:00 2015 +0200
@@ -94,6 +94,7 @@
cmdresp = set_param("FR");
if (cmdresp != AtCmdFrame::AtCmdRespOk) {
+ digi_log(LogLevelError, "software_reset failed!\r\n");
return Failure;
}
@@ -175,65 +176,6 @@
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 Fri May 08 11:50:56 2015 +0200
+++ b/XBee/XBee.cpp Mon May 11 17:58:00 2015 +0200
@@ -30,12 +30,12 @@
/* Class constructor */
XBee::XBee(PinName tx, PinName rx, PinName reset, PinName rts, PinName cts, int baud) :
- _mode(ModeUnknown), _type(Unknown), _hw_version(0), _fw_version(0), _timeout_ms(SYNC_OPS_TIMEOUT_MS), _dev_addr64(ADDR64_UNASSIGNED), _dev_addr16(ADDR16_UNKNOWN),
+ _mode(ModeUnknown), _type(Unknown), _timeout_ms(SYNC_OPS_TIMEOUT_MS), _hw_version(0), _fw_version(0), _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)
{
if (reset != NC) {
- _reset = new DigitalOut(reset);
+ _reset = new DigitalOut(reset, 1);
}
#if defined(ENABLE_PM_SUPPORT)
_on_sleep = NULL;
@@ -44,9 +44,25 @@
_uart = new RawSerial(tx, rx);
_uart->baud(baud);
+
+ _serial_flow_type = SerialBase::Disabled;
#if defined(DEVICE_SERIAL_FC)
if (rts != NC && cts != NC) {
- _uart->set_flow_control(SerialBase::RTSCTS, rts, cts);
+#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;
+ _uart->set_flow_control(_serial_flow_type, rts);
+ }
+ else if (rts == NC && cts != NC) {
+ _serial_flow_type = SerialBase::CTS;
+ _uart->set_flow_control(_serial_flow_type, cts);
}
#endif
/* Enable the reception of bytes on the serial interface by providing a cb */
@@ -288,7 +304,6 @@
* 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)
@@ -638,8 +653,6 @@
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 Fri May 08 11:50:56 2015 +0200
+++ b/XBee/XBee.h Mon May 11 17:58:00 2015 +0200
@@ -403,18 +403,13 @@
*/
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)
- * 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)
+ * ND_OPTION_APPEND_DD - to append the DD value to the response
+ * ND_OPTION_SELF_RESPONSE - to allow the module self responding
* @returns
* Success if the operation was successful,
* Failure otherwise
@@ -769,7 +764,8 @@
*/
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);
+ /** serial hardware flow control selected by the user (RTSCTS, RTS,CTS) */
+ SerialBase::Flow _serial_flow_type;
/** Operating mode of the module (API1, API2,...) */
RadioMode _mode;
--- a/XBee802/XBee802.cpp Fri May 08 11:50:56 2015 +0200
+++ b/XBee802/XBee802.cpp Mon May 11 17:58:00 2015 +0200
@@ -160,12 +160,16 @@
return TxStatusInvalidAddr;
}
-RemoteXBee802 XBee802::get_remote_node_by_id(const char * const node_id)
+TxStatus XBee802::send_data(uint64_t remote64, const uint8_t *const data, uint16_t len)
{
- uint64_t addr64;
- uint16_t addr16;
- _get_remote_node_by_id(node_id, &addr64, &addr16);
- return RemoteXBee802(addr64, addr16);
+ TxFrame802 frame = TxFrame802(remote64, _tx_options, data, len);
+ return send_data(&frame);
+}
+
+TxStatus XBee802::send_data(uint16_t addr16, const uint8_t *const data, uint16_t len)
+{
+ TxFrame802 frame = TxFrame802(addr16, _tx_options, data, len);
+ return send_data(&frame);
}
void XBee802::register_node_discovery_cb(node_discovery_802_cb_t function)
--- a/XBee802/XBee802.h Fri May 08 11:50:56 2015 +0200
+++ b/XBee802/XBee802.h Mon May 11 17:58:00 2015 +0200
@@ -153,13 +153,29 @@
*/
virtual TxStatus send_data(const RemoteXBee& remote, const uint8_t *const data, uint16_t len);
- /** get_remote_node_by_id - searches for a device in the network with the specified Node Identifier.
+ /** send_data - sends data to a remote device waiting for the packet
+ * answer with the result of the operation
*
- * @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).
+ * @param remote64 64bit 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
*/
- RemoteXBee802 get_remote_node_by_id(const char * const node_id);
+ 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
+ *
+ * @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
+ */
+ TxStatus send_data(uint16_t addr16, const uint8_t *const data, uint16_t len);
/* Allow using XBee::set_param() methods for local radio from this class */
using XBee::set_param;
--- a/XBeeZB/XBeeZB.cpp Fri May 08 11:50:56 2015 +0200
+++ b/XBeeZB/XBeeZB.cpp Mon May 11 17:58:00 2015 +0200
@@ -334,14 +334,6 @@
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;
@@ -409,6 +401,37 @@
}
}
+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 Fri May 08 11:50:56 2015 +0200
+++ b/XBeeZB/XBeeZB.h Mon May 11 17:58:00 2015 +0200
@@ -21,6 +21,9 @@
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
{
@@ -337,13 +340,23 @@
*/
bool is_joined();
- /** get_remote_node_by_id - searches for a device in the network with the specified Node Identifier.
+ /** get_device_by_id - finds and retrieves a pointer to the remote device in
+ * the network whose device id matches with the parameter
*
* @param node_id node id of the device we are looking for
- * @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).
+ * @returns a pointer to the remote object device created or NULL if the device
+ * was not found
*/
- RemoteXBeeZB get_remote_node_by_id(const char * const node_id);
+ 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);
/* Allow using XBee::set_param() methods for local radio from this class */
using XBee::set_param;
