Skip to content

Commit c5bb3c6

Browse files
authored
SoapySDR: Allow channel selection by using the subdev device argument (#416)
Add SoapySDR argument for selecting explicit streaming channel indexes
1 parent b39cb61 commit c5bb3c6

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

SoapyLMS7/Streaming.cpp

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,17 @@ SoapySDR::ArgInfoList SoapyLMS7::getStreamArgsInfo(const int direction, const si
106106
argInfos.push_back(info);
107107
}
108108

109+
// channel selection
110+
{
111+
SoapySDR::ArgInfo info;
112+
info.value = "0";
113+
info.key = "channel";
114+
info.name = "Channel";
115+
info.description = "List of channels to use, separated by spaces. Defaults to 0.";
116+
info.type = SoapySDR::ArgInfo::INT;
117+
argInfos.push_back(info);
118+
}
119+
109120
//align phase of Rx channels
110121
{
111122
SoapySDR::ArgInfo info;
@@ -143,8 +154,41 @@ SoapySDR::Stream *SoapyLMS7::setupStream(
143154
config.performanceLatency = 0.5;
144155
config.bufferLength = 0; //auto
145156

146-
//default to channel 0, if none were specified
147-
const std::vector<size_t> &channelIDs = channels.empty() ? std::vector<size_t>{0} : channels;
157+
std::vector<size_t> chans = {};
158+
159+
/* Try to use the channels passed in the `channel` device argument */
160+
if (_deviceArgs.count("channel")) {
161+
const std::string channelstr = _deviceArgs.at("channel");
162+
163+
size_t num;
164+
std::stringstream ss(channelstr);
165+
166+
while (ss >> num) {
167+
chans.push_back(num);
168+
}
169+
170+
if (chans.empty()) {
171+
SoapySDR::logf(SOAPY_SDR_ERROR, "Couldn't parse 'channels' string '%s': it should be a list of integers separated by spaces.", channelstr.c_str());
172+
}
173+
}
174+
175+
if (chans.empty()) {
176+
/* If `channel` was not present, or was not a valid string, try to use channels
177+
* passed as an argument to this function, or default to using channel 0. */
178+
if (channels.empty()) {
179+
/* No channels specified, default to 0. */
180+
chans = std::vector<size_t>{0};
181+
} else {
182+
/* Use the channels from the function argument. */
183+
chans = channels;
184+
}
185+
}
186+
187+
for (auto &ch : chans) {
188+
SoapySDR::logf(SOAPY_SDR_INFO, "Using channel %zu", ch);
189+
}
190+
191+
const std::vector<size_t> &channelIDs = chans;
148192
for(size_t i=0; i<channelIDs.size(); ++i)
149193
{
150194
config.channelID = channelIDs[i];

0 commit comments

Comments
 (0)