Skip to content

Commit a7ece2d

Browse files
committed
profile: fix protocol change after applying a profile in SX devices
In SX devices, protocol changes are not linked to the firmware file applied. SX devices can change the protocol by updating the value of the BR parameter. Checking whether the protocol has changed after applying the settings is mandatory to avoid future failures with XBee device class instances. This commit throws an exception if, after updating the profile settings of an SX device, the protocol of the device has changed, allowing upper layers to re-instantiate the correct XBee device class. Signed-off-by: David Escalona <david.escalona@digi.com>
1 parent e77a910 commit a7ece2d

File tree

1 file changed

+41
-8
lines changed

1 file changed

+41
-8
lines changed

digi/xbee/profile.py

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929

3030
from digi.xbee.firmware import UpdateConfigurer, EXTENSION_GBL, EXTENSION_XML, \
3131
EXTENSION_EBIN, EXTENSION_EHX2, EXTENSION_OTB, EXTENSION_OTA, \
32-
EXTENSION_EBL, update_local_firmware, update_remote_firmware
33-
from digi.xbee.devices import XBeeDevice, RemoteXBeeDevice, NetworkEventReason
32+
EXTENSION_EBL, update_local_firmware, update_remote_firmware, \
33+
SX_HW_VERSIONS
34+
from digi.xbee.devices import XBeeDevice, RemoteXBeeDevice, NetworkEventReason, \
35+
DigiMeshDevice, DigiPointDevice
3436
from digi.xbee.exception import XBeeException, FirmwareUpdateException, \
3537
InvalidOperatingModeException
3638
from digi.xbee.filesystem import LocalXBeeFileSystemManager, \
@@ -1670,6 +1672,10 @@ def _check_protocol_changed_by_fw(self):
16701672
Boolean: `True` if the protocol will change after the firmware
16711673
update, `False` otherwise.
16721674
"""
1675+
# SX devices cannot change the protocol by only updating the firmware.
1676+
if self._device_hw_version.code in SX_HW_VERSIONS:
1677+
return False
1678+
16731679
orig_protocol = self._xbee.get_protocol()
16741680
new_protocol = XBeeProtocol.determine_protocol(
16751681
self._profile.hardware_version,
@@ -1686,13 +1692,25 @@ def _check_protocol_changed_by_settings(self):
16861692
Boolean: `True` if the protocol will change after the application
16871693
of profiles settings, `False` otherwise.
16881694
"""
1689-
if self._profile.protocol is XBeeProtocol.DIGI_MESH:
1690-
self._profile.protocol = self._xbee.determine_protocol(
1691-
self._profile.hardware_version,
1692-
utils.int_to_bytes(self._profile.firmware_version))
1695+
if self._device_hw_version.code not in SX_HW_VERSIONS:
1696+
return False
16931697

1694-
return (self._xbee.get_protocol() != self._profile.protocol
1695-
and self._profile.flash_firmware_option.code < 2)
1698+
br_val = None
1699+
br_setting = self._profile.profile_settings.get(ATStringCommand.BR.command, None)
1700+
if br_setting:
1701+
br_val = br_setting.value
1702+
elif self._profile.reset_settings:
1703+
br_val = self._profile.get_setting_default_value(ATStringCommand.BR)
1704+
1705+
if not br_val:
1706+
return False
1707+
1708+
self._profile.protocol = XBeeProtocol.determine_protocol(
1709+
self._profile.hardware_version,
1710+
utils.int_to_bytes(self._profile.firmware_version),
1711+
br_value=int(br_val, base=16))
1712+
1713+
return self._xbee.get_protocol() != self._profile.protocol
16961714

16971715
def _update_device_settings(self):
16981716
"""
@@ -2098,6 +2116,21 @@ def update_profile(self):
20982116
self._update_file_system()
20992117
# Update the settings.
21002118
net_changed, _info_changed, port_settings = self._update_device_settings()
2119+
# In SX devices, protocol changes are not linked to the firmware file applied.
2120+
# SX devices can change the protocol by updating the value of the BR parameter.
2121+
# Checking whether the protocol has changed after applying the settings is
2122+
# mandatory to avoid future failures with XBee device class instances.
2123+
#
2124+
# BR setting value:
2125+
# - 0: DigiPoint (P2MP point to multi-point)
2126+
# - 1, 2: DigiMesh
2127+
#
2128+
# If the protocol has changed by the profile settings, raise an exception
2129+
# so upper layers can instantiate the correct XBee device class.
2130+
if self._device_hw_version.code in SX_HW_VERSIONS:
2131+
if (isinstance(self._xbee, (DigiMeshDevice, DigiPointDevice)) and
2132+
protocol_changed_by_settings):
2133+
raise UpdateProfileException("Check if you are using the appropriate device class.")
21012134
except UpdateProfileException as exc:
21022135
update_result = "Error: %s" % str(exc)
21032136
raise exc

0 commit comments

Comments
 (0)