aboutsummaryrefslogtreecommitdiffstats
path: root/Transceiver52M
diff options
context:
space:
mode:
authorOliver Smith <osmith@sysmocom.de>2018-12-10 17:10:36 +0100
committerOliver Smith <osmith@sysmocom.de>2018-12-12 15:28:50 +0100
commit29189367dbafd56f81bcf9b1287e52d35826c278 (patch)
treee9a4b4115bd2ff4b4643ecdc28efe3e93ad27ca6 /Transceiver52M
parentfe865f45d79801f679ecba5b2f65f1626910b95e (diff)
LMSDevice: make use of dev-args in osmo-trx.cfg
Allow selecting a specific LimeSDR device by setting dev-args in the config file. Split up the given dev-args address by comma and select the device where all substrings can be found. I could not test this with real hardware, but I have added a test case to make sure this works as expected. Related: OS#3654 Change-Id: Ib9aaa066a01bf9de3f78234d7ada884d6f28c852
Diffstat (limited to 'Transceiver52M')
-rw-r--r--Transceiver52M/device/lms/LMSDevice.cpp42
1 files changed, 40 insertions, 2 deletions
diff --git a/Transceiver52M/device/lms/LMSDevice.cpp b/Transceiver52M/device/lms/LMSDevice.cpp
index 5e21894..15e1041 100644
--- a/Transceiver52M/device/lms/LMSDevice.cpp
+++ b/Transceiver52M/device/lms/LMSDevice.cpp
@@ -22,6 +22,7 @@
#include "Threads.h"
#include "LMSDevice.h"
+#include <boost/algorithm/string.hpp>
#include <lime/LimeSuite.h>
#include <osmocom/core/utils.h>
@@ -95,6 +96,35 @@ static void print_range(const char* name, lms_range_t *range)
<< " Step=" << range->step;
}
+/*! Find the device string that matches all filters from \a args.
+ * \param[in] info_list device addresses found by LMS_GetDeviceList()
+ * \param[in] count length of info_list
+ * \param[in] args dev-args value from osmo-trx.cfg, containing comma separated key=value pairs
+ * \return index of first matching item or -1 (no match) */
+int info_list_find(lms_info_str_t* info_list, unsigned int count, const std::string &args)
+{
+ unsigned int i, j;
+ vector<string> filters;
+
+ boost::split(filters, args, boost::is_any_of(","));
+
+ /* iterate over device addresses */
+ for (i=0; i < count; i++) {
+ /* check if all filters match */
+ bool match = true;
+ for (j=0; j < filters.size(); j++) {
+ if (!strstr(info_list[i], filters[j].c_str())) {
+ match = false;
+ break;
+ }
+ }
+
+ if (match)
+ return i;
+ }
+ return -1;
+}
+
int LMSDevice::open(const std::string &args, int ref, bool swap_channels)
{
//lms_info_str_t dev_str;
@@ -103,7 +133,7 @@ int LMSDevice::open(const std::string &args, int ref, bool swap_channels)
float_type sr_host, sr_rf, lpfbw_rx, lpfbw_tx;
uint16_t dac_val;
unsigned int i, n;
- int rc;
+ int rc, dev_id;
LOGC(DDEV, INFO) << "Opening LMS device..";
@@ -123,7 +153,15 @@ int LMSDevice::open(const std::string &args, int ref, bool swap_channels)
for (i = 0; i < n; i++)
LOGC(DDEV, INFO) << "Device [" << i << "]: " << info_list[i];
- rc = LMS_Open(&m_lms_dev, info_list[0], NULL);
+ dev_id = info_list_find(info_list, n, args);
+ if (dev_id == -1) {
+ LOGC(DDEV, ERROR) << "No LMS device found with address '" << args << "'";
+ delete [] info_list;
+ return -1;
+ }
+
+ LOGC(DDEV, INFO) << "Using device: " << info_list[dev_id];
+ rc = LMS_Open(&m_lms_dev, info_list[dev_id], NULL);
if (rc != 0) {
LOGC(DDEV, ERROR) << "LMS_GetDeviceList() failed)";
delete [] info_list;