Change in osmo-trx[master]: LMSDevice: make use of dev-args in osmo-trx.cfg

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Pau Espin Pedrol gerrit-no-reply at lists.osmocom.org
Thu Dec 13 11:13:05 UTC 2018


Pau Espin Pedrol has submitted this change and it was merged. ( https://gerrit.osmocom.org/12245 )

Change subject: LMSDevice: make use of dev-args in osmo-trx.cfg
......................................................................

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
---
M .gitignore
M Transceiver52M/device/lms/LMSDevice.cpp
A tests/Transceiver52M/LMSDeviceTest.cpp
M tests/Transceiver52M/Makefile.am
M tests/testsuite.at
5 files changed, 98 insertions(+), 2 deletions(-)

Approvals:
  Jenkins Builder: Verified
  Pau Espin Pedrol: Looks good to me, approved



diff --git a/.gitignore b/.gitignore
index ad4c4e3..f163fb6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,6 +18,7 @@
 tests/CommonLibs/VectorTest
 tests/CommonLibs/PRBSTest
 tests/Transceiver52M/convolve_test
+tests/Transceiver52M/LMSDeviceTest
 
 # automake/autoconf
 *.in
diff --git a/Transceiver52M/device/lms/LMSDevice.cpp b/Transceiver52M/device/lms/LMSDevice.cpp
index 5e21894..270bd4a 100644
--- a/Transceiver52M/device/lms/LMSDevice.cpp
+++ b/Transceiver52M/device/lms/LMSDevice.cpp
@@ -21,6 +21,7 @@
 #include "Logger.h"
 #include "Threads.h"
 #include "LMSDevice.h"
+#include "Utils.h"
 
 #include <lime/LimeSuite.h>
 
@@ -95,6 +96,35 @@
 		   << " 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 device 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;
+
+	filters = comma_delimited_to_vector(args.c_str());
+
+	/* 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 @@
 	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 @@
 	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[" << 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;
diff --git a/tests/Transceiver52M/LMSDeviceTest.cpp b/tests/Transceiver52M/LMSDeviceTest.cpp
new file mode 100644
index 0000000..d40a7ec
--- /dev/null
+++ b/tests/Transceiver52M/LMSDeviceTest.cpp
@@ -0,0 +1,41 @@
+#include <assert.h>
+#include <lime/LimeSuite.h>
+#include <string>
+
+extern "C"
+{
+size_t osmo_strlcpy(char *dst, const char *src, size_t siz);
+}
+
+int info_list_find(lms_info_str_t* info_list, unsigned int count, const std::string &args);
+
+using namespace std;
+
+int main(void)
+{
+	unsigned int count;
+	lms_info_str_t* info_list;
+	std::string args;
+
+	/* two fake entries for info_list */
+	count = 2;
+	info_list = new lms_info_str_t[count];
+	osmo_strlcpy(info_list[0], "LimeSDR Mini, addr=24607:1337, serial=FAKESERIAL0001", sizeof(lms_info_str_t));
+	osmo_strlcpy(info_list[1], "LimeSDR Mini, addr=24607:1338, serial=FAKESERIAL0002", sizeof(lms_info_str_t));
+
+	/* find second entry by args filter */
+	args = "serial=FAKESERIAL0002,LimeSDR Mini";
+	assert(info_list_find(info_list, count, args) == 1);
+
+	/* empty args -> first entry */
+	args = "";
+	assert(info_list_find(info_list, count, args) == 0);
+
+	/* not matching args -> -1 */
+	args = "serial=NOTMATCHING";
+	assert(info_list_find(info_list, count, args) == -1);
+
+	/* clean up */
+	delete[] info_list;
+	return 0;
+}
diff --git a/tests/Transceiver52M/Makefile.am b/tests/Transceiver52M/Makefile.am
index 06db5b0..df3ae57 100644
--- a/tests/Transceiver52M/Makefile.am
+++ b/tests/Transceiver52M/Makefile.am
@@ -16,3 +16,13 @@
 if HAVE_SSE4_1
 convolve_test_CFLAGS += $(SIMD_FLAGS)
 endif
+
+if DEVICE_LMS
+noinst_PROGRAMS += LMSDeviceTest
+LMSDeviceTest_SOURCES = LMSDeviceTest.cpp
+LMSDeviceTest_LDFLAGS = $(LIBOSMOCORE_LIBS) $(LMS_LIBS)
+LMSDeviceTest_LDADD = \
+	$(top_builddir)/Transceiver52M/device/lms/libdevice.la \
+	$(COMMON_LA)
+LMSDeviceTest_CPPFLAGS = $(AM_CPPFLAGS) $(LMS_CFLAGS)
+endif
diff --git a/tests/testsuite.at b/tests/testsuite.at
index f84225e..22de782 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -1,6 +1,12 @@
 AT_INIT
 AT_BANNER([Regression tests.])
 
+AT_SETUP([LMSDeviceTest])
+AT_KEYWORDS([LMSDeviceTest])
+AT_SKIP_IF([! test -e $abs_top_builddir/tests/Transceiver52M/LMSDeviceTest])
+AT_CHECK([$abs_top_builddir/tests/Transceiver52M/LMSDeviceTest], [], [], [])
+AT_CLEANUP
+
 AT_SETUP([BitVectorTest])
 AT_KEYWORDS([BitVectorTest])
 cat $abs_srcdir/CommonLibs/BitVectorTest.ok > expout

-- 
To view, visit https://gerrit.osmocom.org/12245
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib9aaa066a01bf9de3f78234d7ada884d6f28c852
Gerrit-Change-Number: 12245
Gerrit-PatchSet: 5
Gerrit-Owner: osmith <osmith at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>
Gerrit-Reviewer: osmith <osmith at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181213/78260311/attachment.htm>


More information about the gerrit-log mailing list