Compare commits

...

2 Commits

Author SHA1 Message Date
Oliver Smith
12b059ccc2 WIP: move comma_delimited_to_vector to Utils.cpp
Change-Id: If3f0f682ca453c2b0a06175ec9626567932cfce6
2018-12-12 16:55:33 +01:00
Oliver Smith
29189367db 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
2018-12-12 15:28:50 +01:00
10 changed files with 164 additions and 17 deletions

1
.gitignore vendored
View File

@@ -18,6 +18,7 @@ tests/CommonLibs/URLEncodeTest
tests/CommonLibs/VectorTest
tests/CommonLibs/PRBSTest
tests/Transceiver52M/convolve_test
tests/Transceiver52M/LMSDeviceTest
# automake/autoconf
*.in

View File

@@ -34,6 +34,7 @@ libcommon_la_SOURCES = \
Threads.cpp \
Timeval.cpp \
Logger.cpp \
Utils.cpp \
trx_vty.c \
debug.c
libcommon_la_LIBADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOCTRL_LIBS) $(LIBOSMOVTY_LIBS)
@@ -48,6 +49,7 @@ noinst_HEADERS = \
Timeval.h \
Vector.h \
Logger.h \
Utils.h \
trx_vty.h \
debug.h \
osmo_signal.h \

36
CommonLibs/Utils.cpp Normal file
View File

@@ -0,0 +1,36 @@
/*
* Copyright 2018 sysmocom - s.f.m.c. GmbH
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <vector>
#include <string>
#include <sstream>
std::vector<std::string> comma_delimited_to_vector(char* opt)
{
std::string str = std::string(opt);
std::vector<std::string> result;
std::stringstream ss(str);
while( ss.good() )
{
std::string substr;
getline(ss, substr, ',');
result.push_back(substr);
}
return result;
}

24
CommonLibs/Utils.h Normal file
View File

@@ -0,0 +1,24 @@
/*
* Copyright 2018 sysmocom - s.f.m.c. GmbH
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#pragma once
#include <vector>
#include <string>
std::vector<std::string> comma_delimited_to_vector(char* opt);

View File

@@ -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;

View File

@@ -22,6 +22,7 @@
#include "Transceiver.h"
#include "radioDevice.h"
#include "Utils.h"
#include <time.h>
#include <signal.h>
@@ -194,21 +195,6 @@ static void setup_signal_handlers()
osmo_init_ignore_signals();
}
static std::vector<std::string> comma_delimited_to_vector(char* opt)
{
std::string str = std::string(opt);
std::vector<std::string> result;
std::stringstream ss(str);
while( ss.good() )
{
std::string substr;
getline(ss, substr, ',');
result.push_back(substr);
}
return result;
}
static void print_help()
{
fprintf(stdout, "Options:\n"

BIN
tests/Transceiver52M/ConvolveTest Executable file

Binary file not shown.

View File

@@ -0,0 +1,45 @@
#include <stdio.h>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <lime/LimeSuite.h>
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;
}

View File

@@ -16,3 +16,12 @@ endif
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/.libs/LMSDevice.o \
$(COMMON_LA)
endif

View File

@@ -51,3 +51,9 @@ AT_SKIP_IF(true)
cat $abs_srcdir/Transceiver52M/convolve_test.ok > expout
AT_CHECK([$abs_top_builddir/tests/Transceiver52M/convolve_test], [], [expout], [])
AT_CLEANUP
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