Skip to content

Commit

Permalink
Hotfix release 1.2.6 (#61)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
laurentva authored Jan 22, 2019
1 parent b6c5b4c commit d6852e8
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pypozyx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"""

__version__ = '1.2.5'
__version__ = '1.2.6'

VERSION = __version__
version = __version__
Expand Down
4 changes: 2 additions & 2 deletions pypozyx/definitions/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pypozyx/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 5 additions & 4 deletions pypozyx/structures/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
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):
list_size = SingleRegister()
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)
Expand All @@ -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)


44 changes: 44 additions & 0 deletions pypozyx/tools/discovery.py
Original file line number Diff line number Diff line change
@@ -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)
1 change: 0 additions & 1 deletion pypozyx/tools/version_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import json
import pypozyx
import warnings
import time


class Version(object):
Expand Down
3 changes: 2 additions & 1 deletion useful/system_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit d6852e8

Please sign in to comment.