From d6852e8d84e92ff68b56990afd1996bf8e3d307f Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 22 Jan 2019 16:32:46 +0100 Subject: [PATCH] Hotfix release 1.2.6 (#61) * Fix switch of operation modes values (closes #48) The Operation mode registry (0x22) contains 0 when the jumper sets the device as a Tag and contains 1 when the jumper sets the device as an anchor. Therefore, the constants are switched in the library to match the behavior of the device. * Hotfix/filter data (#60) * Fix data storing FilterData always returns 0 when reading data from reg due to improper self.data initialization. * Fix improper method name in call * Fix bit operation priority The + operator is called prior to the shift operator wich produce invalid result * Added full discovery as tool, version bump, structured tools a bit --- pypozyx/__init__.py | 2 +- pypozyx/definitions/constants.py | 4 +- pypozyx/lib.py | 2 +- pypozyx/structures/device.py | 9 ++-- ...discover_all_devices.py => device_list.py} | 12 ++--- pypozyx/tools/discovery.py | 44 +++++++++++++++++++ pypozyx/tools/version_check.py | 1 - useful/system_analysis.py | 3 +- 8 files changed, 58 insertions(+), 19 deletions(-) rename pypozyx/tools/{discover_all_devices.py => device_list.py} (54%) create mode 100644 pypozyx/tools/discovery.py diff --git a/pypozyx/__init__.py b/pypozyx/__init__.py index 59be722..9956122 100755 --- a/pypozyx/__init__.py +++ b/pypozyx/__init__.py @@ -72,7 +72,7 @@ """ -__version__ = '1.2.5' +__version__ = '1.2.6' VERSION = __version__ version = __version__ diff --git a/pypozyx/definitions/constants.py b/pypozyx/definitions/constants.py index 3d0eca9..0c0214d 100755 --- a/pypozyx/definitions/constants.py +++ b/pypozyx/definitions/constants.py @@ -55,8 +55,8 @@ class PozyxConstants: LED_OFF = False # Pozyx device modes - ANCHOR_MODE = 0 - TAG_MODE = 1 + TAG_MODE = 0 + ANCHOR_MODE = 1 # The GPIO modes GPIO_DIGITAL_INPUT = 0 diff --git a/pypozyx/lib.py b/pypozyx/lib.py index 2103a1f..07d2cf3 100755 --- a/pypozyx/lib.py +++ b/pypozyx/lib.py @@ -852,7 +852,7 @@ def getPositionFilterStrength(self, remote_id=None): POZYX_SUCCESS, POZYX_FAILURE, POZYX_TIMEOUT """ filter_data = FilterData() - status = self.getPositionFilter(filter_data, remote_id=remote_id) + status = self.getPositionFilterData(filter_data, remote_id=remote_id) if status != POZYX_SUCCESS: warn("Wasn't able to get filter data, returning -1 as strength") diff --git a/pypozyx/structures/device.py b/pypozyx/structures/device.py index c726799..4961cb9 100755 --- a/pypozyx/structures/device.py +++ b/pypozyx/structures/device.py @@ -308,15 +308,16 @@ def __init__(self, filter_type=0, filter_strength=0): self.filter_strength = filter_strength # TODO add type validation? - self.value = self.filter_type + self.filter_strength << 4 + self.value = self.filter_type + (self.filter_strength << 4) self.load([self.value]) - def load(self, data=None, convert=False): - self.data = [0] if data is None else data + def load(self, data=[0], convert=False): + self.data = data + self.value = data[0] + self.update_data() self.filter_type = self.data[0] & 0xF self.filter_strength = self.data[0] >> 4 - self.value = self.filter_type + self.filter_strength << 4 def update_data(self): try: diff --git a/pypozyx/tools/discover_all_devices.py b/pypozyx/tools/device_list.py similarity index 54% rename from pypozyx/tools/discover_all_devices.py rename to pypozyx/tools/device_list.py index 719f1c8..c07fc09 100644 --- a/pypozyx/tools/discover_all_devices.py +++ b/pypozyx/tools/device_list.py @@ -1,12 +1,4 @@ -from pypozyx import PozyxConstants, UWBSettings, SingleRegister, DeviceList, DeviceCoordinates, Coordinates - - -def all_discovery_uwb_settings(): - for channel in PozyxConstants.ALL_UWB_CHANNELS: - for bitrate in PozyxConstants.ALL_UWB_BITRATES: - for prf in PozyxConstants.ALL_UWB_PRFS: - for plen in [PozyxConstants.UWB_PLEN_64, PozyxConstants.UWB_PLEN_1536]: - yield UWBSettings(channel, bitrate, prf, plen, 33) +from pypozyx import SingleRegister, DeviceList, DeviceCoordinates, Coordinates def all_device_coordinates_in_device_list(pozyx, remote_id=None): @@ -14,6 +6,7 @@ def all_device_coordinates_in_device_list(pozyx, remote_id=None): status = pozyx.getDeviceListSize(list_size, remote_id=remote_id) if list_size.value == 0: + # TODO investigate if valid? return device_list = DeviceList(list_size=list_size.value) @@ -24,3 +17,4 @@ def all_device_coordinates_in_device_list(pozyx, remote_id=None): pozyx.getDeviceCoordinates(device_id, coordinates, remote_id=remote_id) yield DeviceCoordinates(device_id, 0, pos=coordinates) + diff --git a/pypozyx/tools/discovery.py b/pypozyx/tools/discovery.py new file mode 100644 index 0000000..d6385f5 --- /dev/null +++ b/pypozyx/tools/discovery.py @@ -0,0 +1,44 @@ +from pypozyx import PozyxConstants, UWBSettings, SingleRegister, DeviceList + + +def all_discovery_uwb_settings(): + for channel in PozyxConstants.ALL_UWB_CHANNELS: + for bitrate in PozyxConstants.ALL_UWB_BITRATES: + for prf in PozyxConstants.ALL_UWB_PRFS: + for plen in PozyxConstants.ALL_UWB_PLENS: + yield UWBSettings(channel, bitrate, prf, plen, 33) + + +def get_device_list(pozyx): + """""" + device_list_size = SingleRegister() + pozyx.getDeviceListSize(device_list_size) + device_list = DeviceList(list_size=device_list_size[0]) + pozyx.getDeviceIds(device_list) + return device_list + + +def discover_all_devices(pozyx): + original_uwb_settings = UWBSettings() + pozyx.getUWBSettings(original_uwb_settings) + + for uwb_settings in all_discovery_uwb_settings(): + pozyx.setUWBSettings(uwb_settings) + + pozyx.clearDevices() + pozyx.doDiscoveryAll(slots=3, slot_duration=0.1) + + device_list = get_device_list(pozyx) + if device_list: + print("Found on {}".format(uwb_settings)) + for device_id in device_list: + print("\t- {}".format(device_id)) + + pozyx.setUWBSettings(original_uwb_settings) + + +if __name__ == '__main__': + from pypozyx import PozyxSerial, get_first_pozyx_serial_port + pozyx = PozyxSerial(get_first_pozyx_serial_port()) + + discover_all_devices(pozyx) diff --git a/pypozyx/tools/version_check.py b/pypozyx/tools/version_check.py index 9150fb5..0efc60b 100644 --- a/pypozyx/tools/version_check.py +++ b/pypozyx/tools/version_check.py @@ -2,7 +2,6 @@ import json import pypozyx import warnings -import time class Version(object): diff --git a/useful/system_analysis.py b/useful/system_analysis.py index 9bc7937..6ba50c0 100644 --- a/useful/system_analysis.py +++ b/useful/system_analysis.py @@ -10,7 +10,8 @@ from pypozyx import PozyxSerial, get_first_pozyx_serial_port, PozyxConstants, POZYX_SUCCESS, UWBSettings, PozyxRegisters from pypozyx.structures.device_information import DeviceDetails -from pypozyx.tools.discover_all_devices import all_discovery_uwb_settings, all_device_coordinates_in_device_list +from pypozyx.tools.discovery import all_discovery_uwb_settings +from pypozyx.tools.device_list import all_device_coordinates_in_device_list class Device(object):