|
| 1 | +from pypozyx import PozyxConstants, UWBSettings, SingleRegister, DeviceList |
| 2 | + |
| 3 | + |
| 4 | +def all_discovery_uwb_settings(): |
| 5 | + for channel in PozyxConstants.ALL_UWB_CHANNELS: |
| 6 | + for bitrate in PozyxConstants.ALL_UWB_BITRATES: |
| 7 | + for prf in PozyxConstants.ALL_UWB_PRFS: |
| 8 | + for plen in PozyxConstants.ALL_UWB_PLENS: |
| 9 | + yield UWBSettings(channel, bitrate, prf, plen, 33) |
| 10 | + |
| 11 | + |
| 12 | +def get_device_list(pozyx): |
| 13 | + """""" |
| 14 | + device_list_size = SingleRegister() |
| 15 | + pozyx.getDeviceListSize(device_list_size) |
| 16 | + device_list = DeviceList(list_size=device_list_size[0]) |
| 17 | + pozyx.getDeviceIds(device_list) |
| 18 | + return device_list |
| 19 | + |
| 20 | + |
| 21 | +def discover_all_devices(pozyx): |
| 22 | + original_uwb_settings = UWBSettings() |
| 23 | + pozyx.getUWBSettings(original_uwb_settings) |
| 24 | + |
| 25 | + for uwb_settings in all_discovery_uwb_settings(): |
| 26 | + pozyx.setUWBSettings(uwb_settings) |
| 27 | + |
| 28 | + pozyx.clearDevices() |
| 29 | + pozyx.doDiscoveryAll(slots=3, slot_duration=0.1) |
| 30 | + |
| 31 | + device_list = get_device_list(pozyx) |
| 32 | + if device_list: |
| 33 | + print("Found on {}".format(uwb_settings)) |
| 34 | + for device_id in device_list: |
| 35 | + print("\t- {}".format(device_id)) |
| 36 | + |
| 37 | + pozyx.setUWBSettings(original_uwb_settings) |
| 38 | + |
| 39 | + |
| 40 | +if __name__ == '__main__': |
| 41 | + from pypozyx import PozyxSerial, get_first_pozyx_serial_port |
| 42 | + pozyx = PozyxSerial(get_first_pozyx_serial_port()) |
| 43 | + |
| 44 | + discover_all_devices(pozyx) |
0 commit comments