aboutsummaryrefslogtreecommitdiffstats
path: root/host/tests
diff options
context:
space:
mode:
authorSamuel O'Brien <sam.obrien@ni.com>2020-07-02 11:49:09 -0500
committerAaron Rossetto <aaron.rossetto@ni.com>2020-07-16 09:59:25 -0500
commit51bf7717e2fde33087055ff7c5649783e2260981 (patch)
tree99784f144d328731c2f43b3484be9e7278a1859f /host/tests
parent9a75dcf3a3c0f71b49b4d2a7a7f154d008979159 (diff)
downloaduhd-51bf7717e2fde33087055ff7c5649783e2260981.tar.gz
uhd-51bf7717e2fde33087055ff7c5649783e2260981.tar.bz2
uhd-51bf7717e2fde33087055ff7c5649783e2260981.zip
python: Add payload agnostic methods to CHDR API
In the c++ api, methods like chdr_packet#set_payload() and chdr_packet#get_payload() are templated over the payload type (payload_t). For methods like set_payload, they are overloaded by the type of an argument, so in pybind we can just explicitly instaniate the template for each payload_t and register it with pybind under the same name. At runtime, pybind looks at the type of the argument and decides which to call. The problem arose with methods like get_payload, which are overloaded by return type. In C++, the compiler can infer the template type by the type of the target at the call site. In python, there is no way for the pybind to determine which variant of get_payload to call, and it would crash. Previously, the workaround for this was to declare get_payload_ctrl, get_payload_mgmt, etc, but this was rather anti-pythonic. This commit utilizes the fact that python methods don't have a constrained return type to resolve this. Now, get_payload will call a python method which looks at the chdr_packet#header#pkt_type field to determine which variant of get_payload to call and returns that type of payload_t. Signed-off-by: Samuel O'Brien <sam.obrien@ni.com>
Diffstat (limited to 'host/tests')
-rw-r--r--host/tests/pychdr_parse_test.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/host/tests/pychdr_parse_test.py b/host/tests/pychdr_parse_test.py
index 34842ad28..0a6f17c23 100644
--- a/host/tests/pychdr_parse_test.py
+++ b/host/tests/pychdr_parse_test.py
@@ -8,7 +8,7 @@ Unit test for libpyuhd.chdr (CHDR Parsing API)
"""
import unittest
-from uhd.libpyuhd import chdr
+from uhd import chdr
from chdr_resource import hardcoded_packets
from chdr_resource import rfnoc_packets_data
from chdr_resource import rfnoc_packets_ctrl_mgmt