Skip to content

Commit 11138bc

Browse files
committed
devices: add BR property to AbstractXBeeDevice
SX devices require the BR value to correctly initialize the device protocol. This value can be read directly from the device when the communication interface is available, but in some scenarios the communication interface is busy and the BR value cannot be read, resulting in an error initializing the device. This commit adds the BR value as a new property that is cached in the device once it is read, allowing upper layers to retrieve it in order to initialize the device protocol when the communication interface is busy. Signed-off-by: Tatiana Leon <tatiana.leon@digi.com> Signed-off-by: David Escalona <david.escalona@digi.com>
1 parent a7ece2d commit 11138bc

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

digi/xbee/devices.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ def __init__(self, local_xbee_device=None, serial_port=None,
138138
self._protocol = None
139139
self._node_id = None
140140
self._role = Role.UNKNOWN
141+
self._br = None
141142

142143
self._packet_listener = None
143144
self._packet_sender = None
@@ -243,6 +244,18 @@ def update_device_data_from(self, device):
243244
if new_hw:
244245
self._hardware_version = new_hw
245246

247+
new_br = device.br
248+
if new_br != self._br:
249+
self._br = new_br
250+
# It is not necessary to set the 'updated' flag to 'True' because,
251+
# if the 'BR' change occurs between 0 and X or X and 0, it means
252+
# the device protocol has changed. When this happens in a remote
253+
# device, the device is removed from the network and if it happens
254+
# in a local device, the object is re-instantiated. In both cases,
255+
# this code is never reached. If the 'BR' change occurs between 1
256+
# and 2 or 2 and 1, the device protocol (Digi-Mesh) does not
257+
# change, thus it is not necessary to notify any relevant change.
258+
246259
if (isinstance(self, (ZigBeeDevice, RemoteZigBeeDevice))
247260
and isinstance(device, (ZigBeeDevice, RemoteZigBeeDevice))):
248261
new_parent = device.parent
@@ -723,14 +736,13 @@ def determine_protocol(self, hardware_version, firmware_version):
723736
:class:`.XBeeProtocol`: XBee protocol corresponding to the given
724737
hardware and firmware versions.
725738
"""
726-
br_value = None
727739
if hardware_version in (HardwareVersion.SX.code,
728740
HardwareVersion.SX_PRO.code,
729741
HardwareVersion.XB8X.code):
730-
br_value = self.get_parameter(ATStringCommand.BR, apply=False)[0]
742+
self._br = self.get_parameter(ATStringCommand.BR, apply=False)[0]
731743

732744
return XBeeProtocol.determine_protocol(
733-
hardware_version, firmware_version, br_value=br_value)
745+
hardware_version, firmware_version, br_value=self._br)
734746

735747
def is_device_info_complete(self):
736748
"""
@@ -2318,6 +2330,16 @@ def log(self):
23182330
"""
23192331
return self._log
23202332

2333+
@property
2334+
def br(self):
2335+
"""
2336+
Returns the BR value of the device.
2337+
2338+
Returns:
2339+
Integer: The BR value of the device.
2340+
"""
2341+
return self._br
2342+
23212343

23222344
class XBeeDevice(AbstractXBeeDevice):
23232345
"""
@@ -2493,8 +2515,10 @@ def _do_open(self):
24932515
self._operating_mode = OperatingMode.get(xbee_info[0])
24942516
self._hardware_version = HardwareVersion.get(xbee_info[1])
24952517
self._firmware_version = utils.int_to_bytes(xbee_info[2])
2496-
self._protocol = self.determine_protocol(
2497-
self._hardware_version.code, self._firmware_version)
2518+
self._br = xbee_info[7]
2519+
self._protocol = XBeeProtocol.determine_protocol(
2520+
self._hardware_version.code, self._firmware_version,
2521+
br_value=self._br)
24982522
self._64bit_addr = XBee64BitAddress.from_hex_string(xbee_info[3])
24992523
self._16bit_addr = XBee16BitAddress.from_hex_string(xbee_info[4])
25002524
self._node_id = xbee_info[5]

0 commit comments

Comments
 (0)