Commit graph

239 commits

Author SHA1 Message Date
Martin Braun
725c410d6d python: Add get_pkg_(data_)path() APIs
This extends the Python API with the same C++ APIs added in 45a58b4.
2024-12-09 10:11:29 +01:00
Martin Braun
45a58b4541 lib: Purge all hard-coded references the share/uhd
- Add a new public API call get_pkg_data_path() which returns the
  location of the "share" data. On a Unix system, this will typically
  return "/usr/share/uhd" when doing a regular system install.
- Purge all references to this path in UHD, and use the new API call
  instead.
- Add --pkg-data-path as an option to uhd_config_info.
2024-12-05 09:12:36 +01:00
Martin Braun
ee09e4dd9a lib: Add uhd::find_uhd_command()
This a non-public API call we can use to identify paths to UHD commands.
It replaces the manual creation of paths to such commands that rely on
`get_pkg_path()`, which is a function with an unclear name.

In this implementation, the newly created function does the exact same
as was happening at call sites, but it can now be more easily improved
to also contain things like checks for if an executable even exists.
2024-12-05 09:12:36 +01:00
Martin Braun
981eafb492 lib: Add module.d support
This extends the module-loading subsystem by a module.d method. Like
with the $prefix/share/uhd/modules and $prefix/lib/uhd/modules
directories, we will now read a modules.d/ directory from the same
location. Instead of placing the actual DLLs in this directory, we can
simply reference DLLs by name in files placed in this directory. For
example, assume we have a file like this:

$ cat $PREFIX/share/uhd/modules.d/rfnoc-gain
librfnoc-gain.so

In other words, there exists a file called `rfnoc-gain` which contains
the name `librfnoc-gain.so`. Then upon loading of UHD, we shall load
`librfnoc-gain.so` from the usual locations (full paths may also be
provided in these files).

Lines starting with '#' in these files are ignored.
2024-09-27 15:35:37 +02:00
Lars Amsel
3a6d4ef1d7 host: remove superfluous usage of const in return values
Returning a const value does not ensure value constness. Instead,
it prevent move semantics (see C++ core guidelines F.49).
2024-06-25 16:59:56 +02:00
Martin Anderseck
7f6e8e3276 fbx: Add guided mode for X440
Since X440 is special in terms of operation in different Nyquist zones
users may stumble upon unexpected RF performance compared to other
devices if frequencies are chosen close to a Nyquist boundary. The
guided mode provides more information about the Nyquist zone in which
the chosen frequency is located in the info log. For disabling the
guided mode, `guided_mode=false` can be added to the UHD config file
in the "Global" section.
2024-06-11 10:20:08 +02:00
Martin Braun
21ac37c737 lib: Fix issue with undefined HOME or XDG_CONFIG_HOME
The path-search algorithms of UHD were incorrectly assuming the presence
of either a XDG_CONFIG_HOME or HOME, as well as XDG_CONFIG_DATA
environment variables.

This fixes the issue: If no such variables exist (e.g., because UHD is
being run as part of a system process, where no user is defined) then it
simply ignores them.
2023-12-04 11:40:51 -06:00
Martin Braun
ebd5dd03cf Apply clang-formatting to all C/C++ files
- Used clang-format version 14
- Ran ./tools/clang-formatter.sh apply
2023-08-07 15:35:56 -05:00
Paul R. Tagliamonte
2b3c2008be Add in OpenBSD support to uhd::path_expandvars
OpenBSD has explicitly declined[1] to support 'wordexp' on their platform,
which just leaves glob(3) for expanding strings according to shell-like rules.
The API is similar, but -- notably -- does not support environment variable
expansion (for instance, the string "/home/${USER_NAME}/" will be left
unchanged, whereas wordexp(3) would expand it).

However, OpenBSD supports the well understood but non-POSIX extension to glob,
'GLOB_TILDE', which will allow for user directory expansion, such as
'~user/.ssh/authorized_keys' or '~/bin/*.sh'.

This is a fairly large difference between OpenBSD and other supported
platforms, but one that will at least enable libuhd to be built, but users
may need to be careful with filepaths, since they'll behave slightly
differently on OpenBSD than Windows, Linux or OSX.

```
sugartoad# uhd_find_devices
[INFO] [UHD] OpenBSD 1; Clang version 13.0.0 ; Boost_108000; UHD_4.4.0.0-68-g02558b69
[INFO] [B200] Loading firmware image: /usr/local/share/uhd/images/usrp_b200_fw.hex...
--------------------------------------------------
-- UHD Device 0
--------------------------------------------------
Device Address:
    serial: XXXXXXX
    name: MyB210
    product: B210
    type: b200
```

[1]: https://www.mail-archive.com/tech@openbsd.org/msg02325.html
2023-04-25 17:08:17 -05:00
Sam James
3acf784e98 Fix build with GCC 13 (add missing <cstdint> include)
GCC 13 (as usual for new compiler releases) shuffles around some
internal includes and so <cstdint> is no longer transitively included.

Explicitly include <cstdint> for uint8_t.

```
/var/tmp/portage/net-wireless/uhd-4.3.0.0/work/uhd-4.3.0.0/host/include/uhd/rfnoc/defaults.hpp:43:14: error: 'uint32_t' does not name a type
   43 | static const uint32_t DEFAULT_NOC_ID  = 0xFFFFFFFF;
      |              ^~~~~~~~
/var/tmp/portage/net-wireless/uhd-4.3.0.0/work/uhd-4.3.0.0/host/include/uhd/rfnoc/defaults.hpp:1:1: note: 'uint32_t' is defined in header '<cstdint>'; did you forget to '#include <cstdint>'?
  +++ |+#include <cstdint>
    1 | //
```

Signed-off-by: Sam James <sam@gentoo.org>
2023-01-12 17:52:12 -08:00
Michael Dickens
5a12365632 uhd: update to uniform SPDX license identifier 2022-09-01 14:16:30 -05:00
Steven Koo
9a15dcb61d utils: Check install-prefix for images
On some installs, pkg-path and install-prefix aren't equivalent. Since
uhd_images_downloader defaults to installing into
$CMAKE_INSTALL_PREFIX/share/uhd/images, we should look there too.

Signed-off-by: Steven Koo <steven.koo@ni.com>
2022-04-19 09:38:47 -07:00
mattprost
acc731eeb7 log: Add DPDK version to system info
Log installed DPDK version on boot.

Signed-off-by: mattprost <matt.prost@ni.com>
2022-04-01 13:26:09 -07:00
Lane Kolbly
7484b4f095 host: test: Add UHD_UNITTEST_LOG_LEVEL override 2022-03-11 09:10:04 -06:00
Martin Braun
0f15704cb9 rfnoc: graph_utils: Add ability to declare back-edges
rfnoc::connect_through_blocks(), unlike rfnoc_graph::connect(), did not
have an argument to declare a back-edge. This patch remedies this
situation by adding a skip_property_propagation argument that works
exactly as with rfnoc_graph::connect().
2022-02-24 13:39:41 -06:00
Martin Braun
c1e26b4a26 uhd: rfnoc: Let connect_through_blocks() return edge list
This changes the return value of connect_through_blocks() from void to
a list of edges. If the connection can be made, then it will now return
the list of connections between the source block and port.
2022-02-04 13:13:59 -06:00
Martin Braun
5fd7feca0a uhd: Demote WARNING on minor compat mismatch to DEBUG
When the minor FPGA compat number on the device is ahead of what MPM
expects, we no longer print a warning. That's because by definition, the
FPGA is still compatible with the software in this case.

If UHD requires a certain minor compat number to enable a feature,
the appropriate behaviour would be to print a warning only for that
case.

This is the equivalent change to the MPM-only change in 88d28481.
2022-01-25 13:11:13 -06:00
Martin Braun
bc6b453963 rfnoc: Fix issue in uhd::rfnoc::connect_through_blocks()
When connect_through_blocks() was called on blocks within a single
chain, there was a bug where the chain was incorrectly cropped. In
a standard FPGA image, say one was to use this API call to connect the
radio to the DDC. It would generate a chain of blocks hanging off the
radio as such:

Radio -> DDC -> SEP

What the code should do, and what this fix provides, is that the chain
gets cropped after the DDC, to look like this:

Radio -> DDC

With the current bug, it would assume the chain has a dangling edge, and
incorrectly throw an exception.
Note that this bug would not appear when source and destination block
are on separate chains (i.e., both have an SEP in their chain).

This patch includes minor logging and comment improvements around the
offending lines of code.
2021-12-01 13:34:35 -08:00
A. Maitland Bottoms
81ac62f791 uhd: Fix spelling errors
Thanks to Mait for pointing these out!
2021-10-22 06:35:44 -07:00
Martin Braun
b6119e581e uhd: Replace Boost mutexes and locks with standard options
This is a very mechanical task that could almost have been done with
sed. Boost versions of mutexes and locks were removed, and replaced with
std:: versions. The replacement tables are as follows:

== Mutexes ==
- boost::mutex -> std::mutex
- boost::recursive_mutex -> std::recursive_mutex

Mutexes behave identically between Boost and std:: and have the same
API.

== Locks ==
C++11 has only two types of lock that we use/need in UHD:
- std::lock_guard: Identical to boost::lock_guard
- std::unique_lock: Identical to boost::unique_lock

Boost also has boost::mutex::scoped_lock, which is a typedef for
boost::unique_lock<>. However, we often have used scoped_lock where we
meant to use lock_guard<>. The name is a bit misleading, "scoped lock"
sounding a bit like an RAII mechanism. Therefore, some previous
boost::mutex::scoped_lock are now std::lock_guard<>.

std::unique_lock is required when doing more than RAII locking (i.e.,
unlocking, relocking, usage with condition variables, etc.).

== Condition Variables ==
Condition variables were out of the scope of this lock/mutex change, but
in UHD, we inconsistently use boost::condition vs.
boost::condition_variable. The former is a templated version of the
latter, and thus works fine with std::mutex'es. Therefore, some
boost::condition_variable where changed to boost::condition.

All locks and mutexes use `#include <mutex>`. The corresponding Boost
includes were removed. In some cases, this exposed issues with implicit
Boost includes elsewhere. The missing explicit includes were added.
2021-10-19 12:21:33 -07:00
Martin Braun
2680025c1b cmake: Add check for libatomic linking requirement
Some archs require linking against libatomic, others don't. We add some
CMake code that checks for libatomic.so requirement if:
- We are not on MSVC, AND
- Compiling std::atomics code would cause a linker error.

We then check for the existence of libatomic.so, and fail if we can't
find it.
2021-08-27 15:28:20 -05:00
Martin Braun
8697826604 uhd: Remove Boost version checks for Boost 1.61
UHD requires Boost 1.65, so checks for Boost 1.61 will always be
satisfied.
2021-08-24 15:19:54 -05:00
Martin Braun
04a83b6e76 uhd: Replace boost:🧵:id with std:🧵:id
The Boost version is identical to the std:: version (which is available
since C++11) and thus is no longer needed.

Because of implicit includes, this breaks compilation in other parts.
Appropriate includes were added there also.
2021-07-14 16:19:08 -05:00
Michael Dickens
91a56d083a cmake: remove redundant include 2021-07-06 04:29:55 -07:00
Michael Dickens
d922ad3d61 cmake: correctly set and unset any CMAKE_REQUIRED variables 2021-07-06 04:29:55 -07:00
Martin Braun
107a49c0c2 host: Update code base using clang-tidy
The checks from the new clang-tidy file are applied to the source tree
using:

$ find . -name "*.cpp" | sort -u | xargs \
    --max-procs 8 --max-args 1 clang-tidy --format-style=file \
    --fix -p /path/to/compile_commands.json
2021-03-04 08:07:26 -06:00
Martin Braun
ea0ecfcaf7 chdr: Fix u64_to_host vs. u64_from_host usage 2021-01-11 12:40:20 -06:00
Steven Koo
b975885de2 lib: graph_utils: Error on single SEP edge
It could be possible that we only find one SEP connected edge, which
should be invalid.
2020-09-25 11:21:10 -05:00
Martin Braun
05a6b351d7 lib: graph_utils: Fix formatting and compiler warnings
The conditional setting of some variables lead the compiler to assume
they might be used uninitialized. Circumventing compiler warning by
initializing variables to a default value, even if that's not the right
value (they will get set later).

Also applied clang-format to the same code section.

This fixes da1aeaeccc.
2020-09-25 11:21:10 -05:00
Steven Koo
da1aeaeccc rfnoc: enable SEPs with connect_through_blocks
Calling on connect with SEPs in the path is not supported. This change
enables connect_through_blocks to find SEPs in the connection chain
and link the src and dest blocks directly.

Signed-off-by: Steven Koo <steven.koo@ni.com>
2020-08-28 12:28:08 -05:00
Samuel O'Brien
919a147afc python: Add bindings for C++ CHDR Parser
This commit adds pybind11 glue code for the userland chdr parsing code
introduced in the uhd::utils::chdr namespace. Additionally, it moves
some pybind11 adapter code to a common pybind_adaptors.hpp file which
originally existed in the cal_python.hpp file.

This commit also adds unit tests for the python bindings using a
captured wireshark trace which is located in rfnoc_packets_*.py and some
handwritten packets in hardcoded_packets.py

Signed-off-by: Samuel O'Brien <sam.obrien@ni.com>
2020-07-16 09:59:25 -05:00
Samuel O'Brien
297d5855ca utils: Expose CHDR Parsing API
This commit introduces a new public api in uhd::utils which allows serializing
and deserializing chdr packets.

As far as testing, this commit adds the chdr_parse_test test. It uses a
wireshark trace located in rfnoc_packets_*.cpp as well as hand coded
packets from hardcoded_packets.cpp to test the serialization and
deserialization process

Signed-off-by: Samuel O'Brien <sam.obrien@ni.com>
2020-07-13 15:21:52 -05:00
Ryan Volz
14d9452a15 utils: Fix prefix determination in get_lib_path()
get_lib_path() uses the libuhd location on disk to dynamically
determine the installation prefix at runtime. This fix normalizes the
libuhd path before any path operations are done to extract the library
directory and then prefix directory.

Previously, using a non-normalized library path, the returned prefix
directory would be incorrect in some cases (e.g. when loaded through
GNU Radio). In these error cases, the libuhd path would be
  $PREFIX/lib/./libuhd.so
(with a no-op /. inserted) which would result in a technically correct
library directory of `$PREFIX/lib/.` but an incorrect prefix directory
of `$PREFIX/lib`.

With the normalization fix, the libuhd path is corrected to
  $PREFIX/lib/libuhd.so
and the subsequent path manipulation to get the library and prefix
directories will work as intended.
2020-07-13 13:06:04 -07:00
Matthew Crymble
9318323b76 uhd: improved handling of empty serial number hints
This allows device::find() calls to proceed even when encountering an empty/invalid
serial number or serial number device argument hint.
2020-06-26 14:31:14 -05:00
mattprost
9d6d26ca35 utils: log: fix logging race condition
It was possible that output to cout would become interleaved inside of the
uhd log messages.

Signed-off-by: mattprost <matt.prost@ni.com>
2020-04-14 10:30:04 -05:00
mattprost
722e944323 fixup! uhd: Add fuzzy serial number checking 2020-04-09 09:58:20 -05:00
Lane Kolbly
abf025f0a5 uhd: Add fuzzy serial number checking
We have integer 32-bit serial numbers for MPM devices, for example
"1234abcd". For serial numbers which have less than eight digits,
e.g. "123abcd", a user may feel inclined to prefix this number with
a 0 when they are searching for devices, e.g. "0123abcd". This change
makes it so that specifying "0123abcd" will match a device with serial
number "123ABCD".
2020-04-08 15:13:53 -05:00
Martin Braun
1383fde345 uhd: paths: Harmonize around XDG Base Directory specification
Up until now, we completely ignore the XDG specification.

This commit does the following to change that:

- It uses XDG_DATA_HOME and XDG_CONFIG_HOME for cal and config data,
  respectively.
- If config data is in ~/.uhd/uhd.conf, that is still accepted, but if
  it conflicts with $XDG_CONFIG_HOME/uhd.conf, it is ignored and a
  warning is displayed
- The default location for cal data is thus ${HOME}/.local/share/uhd/cal
  on Unix, and %LOCALAPPDATA%\uhd\cal on Windows. This is a change in
  location!
- The UHD_CONFIG_DIR environment variable was confusingly named and is
  now removed. It provided an alternative location than the home
  directory. The same purpose is now much better served by XDG_DATA_HOME
  and XDG_CONFIG_HOME.

The specification can be found here:
specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
2020-04-02 12:36:20 -05:00
Martin Braun
a1f9619469 uhd: cal: Use usrp::cal::database instead of CSV files
Now that we have cal::iq_cal and cal::database, there's no need to
manually wrangle CSV files for calibration data. This commit replaces
all CSV operations with cal::database calls and uses cal::iq_cal as
a container.

CSV files can still be read, but are considered deprecated.
2020-04-02 11:55:17 -05:00
Martin Braun
8055879242 uhd: paths: Add get_cal_data_path() API call
This points to the location where cal data is stored.
2020-03-26 07:46:03 -05:00
Aaron Rossetto
b12c3b2037 utils: Add bool specialization to cast::from_str()
This adds a specialization to `uhd::cast::from_str()` to handle `bool`
as a target type and interpret strings like 'y', 'Y', 'n', 'No', 'True',
'False', etc. as Boolean values, as well as the traditional '0' and '1'
(which also work).
2020-03-18 07:43:20 -05:00
Martin Braun
e806238b27 python: Export UHD paths utility functions
All of the functions defined in uhd/utils/paths.hpp are now available in
Python, with the exception of get_module_paths().

    #!/usr/bin/env python3
    import uhd
    print(uhd.get_lib_path()) # Prints location of libuhd
2020-03-12 07:27:46 -05:00
Martin Braun
38d52121f9 lib: gain_group: Remove spurious logs
Whenever gains where set through a gain_group, it would output spurious
log messages that must stem from someone's debug code, since the log
messages are not very useful by themselves.
2020-03-12 07:27:46 -05:00
Martin Braun
876d4150aa uhd: Apply clang-format against all .cpp and .hpp files in host/
Note: template_lvbitx.{cpp,hpp} need to be excluded from the list of
files that clang-format gets applied against.
2020-03-03 08:51:32 -06:00
Martin Braun
931f304592 thread: Fix formatting in thread utilities
- Apply clang-format
- Remove unnecessary boost::format
2020-02-10 10:19:26 -06:00
Ryan Volz
965ad05279 lib: utils: Don't use hard-coded path constants
This replaces the package path constant with a runtime library path
lookup. The package path is taken to be the parent directory of the
library directory.

When boost >= 1.61 is not available, this maintains the current behavior
of using CMake to set path contants.

Runtime path determination is preferable for making a relocatable
library so that it is not necessary to do string substitution on
relocated binaries (as with, for example, building a conda package).
2020-02-07 09:12:56 -06:00
Martin Braun
25b434ae85 log: Remove LOG statement from _get_log_level()
_get_log_level() is an internal function that only gets called during
setup, so the logger isn't ready yet. It thus now logs to stderr instead
of the logger.
2020-01-29 08:47:50 -06:00
Martin Braun
4d1afc53be utils: log: Name all threads
Logging creates two threads, one for regular logging, and one for
fastpath logging. Now these threads are named using
uhd::set_thread_name()
2020-01-29 08:47:50 -06:00
Martin Braun
45c67acf8f thread: Remove log messages for set_thread_name() when not supported
On systems like Windows, set_thread_name() is not supported, and would
previously log an error message telling the user that it can't set the
thread name. However, that prevents set_thread_name() to be called
before the logger is being set up, and the logger would like to use this
function.

Since it is obvious to the user if threads can be named or not, the log
message is considered redundant and is removed.
2020-01-29 08:47:50 -06:00
Aaron Rossetto
8fab267ea6 prefs: Output debug trace when config file cannot be located or loaded 2019-12-17 11:24:15 -08:00