Closed timburke closed 7 years ago
probe_required
is set and not setself.set_config('probe_required', True)
in its __init__
functionconnect_direct
since we now support scanning.The unit test should go into: https://github.com/iotile/coretools/blob/master/iotilecore/test/test_hw/test_virtualadapter.py
Observed: Master is passing all test cases. Branch is passing all test cases. Expected: Master should fail the new test case. Brach should pass all test cases.
Issue: When emulating master in virtual environment, the scan functionality does not work. I'm currently doing a very similar test to an existing one, only difference is I'm using connect instead of connect_direct.
realtime_scan_hw.connect('1')
realtime_scan_hw.enable_streaming()
reports = realtime_scan_hw.wait_reports(10)
stream1 = [x for x in reports if x.visible_readings[0].stream == 0x100a]
assert len(stream1) != 0
When you directly use a virtual device inside of HardwareManager, it does the following:
Create an AdapterStream object with a DeviceAdapter: https://github.com/iotile/coretools/blob/master/iotilecore/iotile/core/hw/hwmanager.py#L408 https://github.com/iotile/coretools/blob/master/iotilecore/iotile/core/hw/transport/adapterstream.py
This AdapterStream in turn registers itself with the DeviceAdapter to receive a callback when new IOTile devices are seen: https://github.com/iotile/coretools/blob/master/iotilecore/iotile/core/hw/transport/adapterstream.py#L35
However, the VirtualDeviceAdapter does not generate scan events on its own unless
periodic_callback
is called, which in this case it isn't until the user takes some action on HardwareManager: https://github.com/iotile/coretools/blob/master/iotilecore/iotile/core/hw/transport/virtualadapter.py#L409Previously, there wasn't a good way to fix this because when the user calls
HardwareManager.scan
, there was no way to actually pass the call down toVirtualDeviceAdapter
and get it to generate scan events.However, now we do support this behavior by calling a
probe_async
function on DeviceAdapter. To trigger this behavior, the VirtualDeviceAdapter needs to say that it requires probing when the user wants to scan by setting a config variableprobe_required
.See the AWS IOT DeviceAdapter for an example: https://github.com/iotile/coretools/blob/master/transport_plugins/awsiot/iotile_transport_awsiot/device_adapter.py#L75
TLDR: we need to call
self.set_config('probe_required', True)
in the__init__
function of VirtualDeviceAdapter so that scanning works correctly.