diff options
author | Lane Kolbly <lane.kolbly@ni.com> | 2020-04-06 11:17:29 -0500 |
---|---|---|
committer | Aaron Rossetto <aaron.rossetto@ni.com> | 2020-04-08 15:13:53 -0500 |
commit | abf025f0a5c537f0b2ab07da933ffb82f62418ef (patch) | |
tree | bd877c33a6264794c2b92d96970d2984b25c7cba /host/lib/include/uhdlib/utils | |
parent | d398fe465724a3c2efb6abb1c720fc9f3a037701 (diff) | |
download | uhd-abf025f0a5c537f0b2ab07da933ffb82f62418ef.tar.gz uhd-abf025f0a5c537f0b2ab07da933ffb82f62418ef.tar.bz2 uhd-abf025f0a5c537f0b2ab07da933ffb82f62418ef.zip |
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".
Diffstat (limited to 'host/lib/include/uhdlib/utils')
-rw-r--r-- | host/lib/include/uhdlib/utils/serial_number.hpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/host/lib/include/uhdlib/utils/serial_number.hpp b/host/lib/include/uhdlib/utils/serial_number.hpp new file mode 100644 index 000000000..230f9657d --- /dev/null +++ b/host/lib/include/uhdlib/utils/serial_number.hpp @@ -0,0 +1,29 @@ +// +// Copyright 2020 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#ifndef INCLUDED_UHDLIB_UTILS_SERIAL_NUMBER_HPP +# define INCLUDED_UHDLIB_UTILS_SERIAL_NUMBER_HPP + +#include <string> + +namespace uhd { namespace utils { + +/*! Convenience function to determine whether two serial numbers refer to the + * same device. Serial numbers are case-insensitive and ignore leading zeros, + * so e.g. the strings "0123abcd" and "123ABCD" are considered the same serial + * number. + * + * Serial numbers cannot be longer than 8 characters or have characters outside + * the range 0-9a-fA-F. + * + * \param serial_a The first serial number to compare + * \param serial_b The second serial number to compare + */ +bool serial_numbers_match(const std::string& serial_a, const std::string& serial_b); + +}} + +#endif /* INCLUDED_UHDLIB_UTILS_SERIAL_NUMBER_HPP */ |