diff options
author | ahmed.salman <ahmed.salman@ni.com> | 2024-02-21 14:22:43 +0100 |
---|---|---|
committer | joergho <48011876+joergho@users.noreply.github.com> | 2024-03-06 08:11:41 +0100 |
commit | 68eb97c44f47ef3b48a31f1160779bc917632e6f (patch) | |
tree | e050268a2984de1fb18e1d1e399919a874a6b9e1 /host | |
parent | fpga: x400: zbx: Improve Lattice make flow (diff) | |
download | uhd-68eb97c44f47ef3b48a31f1160779bc917632e6f.tar.xz uhd-68eb97c44f47ef3b48a31f1160779bc917632e6f.zip |
examples: fix rx_samples_to_file fail for multichannel fullpath
Fix for the issue where the example rx_samples_to_file fails in the case
when samples from multiple channels are to be taken and a full path is
given for the data files to be stored.
The example source code used to put a channel number in front of the
filename which caused the code to not be able to find the path.
Now the channel number is added at the end of the filename and before the
extension if it exists in the file argument given by the user.
Diffstat (limited to 'host')
-rw-r--r-- | host/examples/rx_samples_to_file.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/host/examples/rx_samples_to_file.cpp b/host/examples/rx_samples_to_file.cpp index 159af133c..b4da023d0 100644 --- a/host/examples/rx_samples_to_file.cpp +++ b/host/examples/rx_samples_to_file.cpp @@ -175,12 +175,23 @@ void recv_to_file(uhd::usrp::multi_usrp::sptr usrp, } std::vector<std::ofstream> outfiles(rx_stream->get_num_channels()); + std::string filename; for (size_t ch = 0; ch < rx_stream->get_num_channels(); ch++) { if (not null) { - std::string filename = - rx_stream->get_num_channels() == 1 - ? file - : "ch" + std::to_string(channel_nums[ch]) + "_" + file; + if (rx_stream->get_num_channels() == 1) { // single channel + filename = file; + } else { // multiple channels + // check if file extension exists + if (file.find('.') != std::string::npos) { + const std::string base_name = file.substr(0, file.find_last_of('.')); + const std::string extension = file.substr(file.find_last_of('.')); + filename = base_name + "_" + "ch" + std::to_string(channel_nums[ch]) + + extension; + } else { + // file extension does not exist + filename = file + "_" + "ch" + std::to_string(channel_nums[ch]); + } + } outfiles[ch].open(filename.c_str(), std::ofstream::binary); } } |