From 74c6bd69042470ff140a4fbd6feb7e2a1dd2299a Mon Sep 17 00:00:00 2001 From: Kumi Date: Sat, 17 Feb 2024 15:08:54 +0100 Subject: [PATCH 1/8] Removed commented out antenna selection code The outdated and unused code related to antenna selection has been purged. This cleanup simplifies `run_experiment` by removing the comments that printed available antenna names and selected an antenna port. The removal avoids confusion and potential maintenance issues associated with deprecated sections of code. Future antenna selection implementations should be designed with a more current context of the project. --- src/limedriver.cpp | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/limedriver.cpp b/src/limedriver.cpp index f6ee070..b3e34f0 100644 --- a/src/limedriver.cpp +++ b/src/limedriver.cpp @@ -834,20 +834,6 @@ int run_experiment(LimeConfig_t LimeCfg, if (LMS_Open(&device, list[0].c_str(), NULL)) error(); - /* - //print available antennae names - //select antenna port - lms_name_t antenna_list[10]; //large enough list for antenna names. - //Alternatively, NULL can be passed to LMS_GetAntennaList() to obtain - number of antennae if ((n = LMS_GetAntennaList(device, LMS_CH_RX, 0, - antenna_list)) < 0) error(); - - // get and print antenna index and name - if ((n = LMS_GetAntenna(device, LMS_CH_RX, 0)) < 0) error(); - cout << "Automatically selected RX LNA: " << n << ": " << - antenna_list[n] << endl; - */ - // Get number of channels int num_rx_channels, num_tx_channels; if ((num_rx_channels = LMS_GetNumChannels(device, LMS_CH_RX)) < 0) From aed72558013481cd03d1f94be15234686129630d Mon Sep 17 00:00:00 2001 From: Kumi Date: Sat, 17 Feb 2024 16:45:59 +0100 Subject: [PATCH 2/8] Implement auto-device selection and enhance channel handling Refactored code to improve usability and error handling by implementing automatic device selection when no device is explicitly specified. New functionalities include opening devices based on provided info, and a more robust way to retrieve and validate the number of RX and TX channels. These changes streamline the device and channel setup process, especially for systems with a single connected device. - Introduced `openDevice` to encapsulate device opening logic with fallback to the first available device. - Added `getDeviceChannels` and `getChannelsFromInfo` for retrieving channel information. - Ensured LimeConfig struct now includes a `device` field to store the selected device. - Modified experiment setup to automatically select a device if not configured and validate channel availability. - Updated HDF attribute population to include device information. These improvements should reduce the likelihood of user errors and simplify the configuration process when working with LimeSDR devices. --- src/limedriver.cpp | 79 ++++++++++++++++++++++++++++++++++++++++------ src/limedriver.h | 2 ++ 2 files changed, 71 insertions(+), 10 deletions(-) diff --git a/src/limedriver.cpp b/src/limedriver.cpp index b3e34f0..de9b255 100644 --- a/src/limedriver.cpp +++ b/src/limedriver.cpp @@ -114,6 +114,48 @@ std::vector getDeviceList() { return deviceList; } +lms_device_t *openDevice(const std::string &info) { + // Open the device with the given info string + + string info_string = info; + + if (info_string.empty()) { + std::vector deviceList = getDeviceList(); + if (deviceList.size() == 0) { + std::cout << "No devices found" << std::endl; + error(); + } + + info_string = deviceList[0]; + } + + lms_device_t *dev = NULL; + if (LMS_Open(&dev, info.c_str(), NULL)) { + error(); + } + + return dev; +} + +std::pair getDeviceChannels(lms_device_t *dev) { + // Get the number of RX and TX channels of the device + + lms_info_str_t list[10]; + int rx = LMS_GetNumChannels(dev, LMS_CH_RX); + int tx = LMS_GetNumChannels(dev, LMS_CH_TX); + + return std::make_pair(rx, tx); +} + +std::pair getChannelsFromInfo(const std::string &info) { + // Get the number of RX and TX channels from the device info string + lms_device_t *dev = openDevice(info); + std::pair values = getDeviceChannels(dev); + LMS_Close(dev); + return values; +} + + // Custom function to read back the gain of the RX/TX channels. The API function // GetGaindB has to be avoided, as it also modifies the gain, which is useless // and dangerous.. @@ -192,6 +234,9 @@ int GetGainRXTX(int *RXgain, int *TXgain) { std::vector getHDFAttributes(LimeConfig_t &LimeCfg) { std::vector HDFattr = { + {"dev", "Device", + H5::StrType(H5::PredType::C_S1, LimeCfg.device.length() + 1), + (void *)LimeCfg.device.c_str(), 1}, {"sra", "SampleRate [Hz]", H5::PredType::IEEE_F32LE, &LimeCfg.srate, 1}, {"chn", "Channel", H5::PredType::NATIVE_INT, &LimeCfg.channel, 1}, {"rmt", "RX Matching", H5::PredType::NATIVE_INT, &LimeCfg.RX_matching, 1}, @@ -400,6 +445,8 @@ LimeConfig_t initializeLimeConfig(int Npulses) { // Set all the DEFAULT parameters. Command line arguments allow for // modification! + LimeCfg.device = ""; + LimeCfg.srate = 30.72e6; // sample rate of the IF DAC/ADC LimeCfg.channel = 0; // channel to use, LimeCfg.RX_matching = 0; // RX matching network - 0 to use previous logic @@ -830,19 +877,33 @@ int run_experiment(LimeConfig_t LimeCfg, if (list.size() < 1) return -1; + if (LimeCfg.device == "") { + LimeCfg.device = list[0]; + cout << "Automatically selecting device: " << LimeCfg.device << endl; + } + // open the first device - if (LMS_Open(&device, list[0].c_str(), NULL)) + if (LMS_Open(&device, LimeCfg.device.c_str(), NULL)) error(); // Get number of channels - int num_rx_channels, num_tx_channels; - if ((num_rx_channels = LMS_GetNumChannels(device, LMS_CH_RX)) < 0) - error(); + std::pair num_channels = getDeviceChannels(device); + int num_rx_channels = num_channels.first; + int num_tx_channels = num_channels.second; cout << "Number of RX channels: " << num_rx_channels << endl; - if ((num_tx_channels = LMS_GetNumChannels(device, LMS_CH_TX)) < 0) - error(); cout << "Number of TX channels: " << num_tx_channels << endl; + if (num_rx_channels < 1 || num_tx_channels < 1) { + cout << "No RX or TX channels found!" << endl; + error(); + } + + // Check if the channel selected in the config is valid + if (LimeCfg.channel < 0 || LimeCfg.channel >= num_rx_channels) { + cout << "Invalid channel selected: " << LimeCfg.channel << endl; + error(); + } + // check if the settings are already there float_type frq_read; if (LMS_GetLOFrequency(device, LMS_CH_RX, LimeCfg.channel, &frq_read) != 0) @@ -1028,8 +1089,7 @@ DC_Q << endl; error(); // get and print antenna index and name - if ((rx_path = LMS_GetAntenna(device, LMS_CH_RX, LimeCfg.channel)) < - 0) + if ((rx_path = LMS_GetAntenna(device, LMS_CH_RX, LimeCfg.channel)) < 0) error(); cout << "Manually selected RX LNA: " << rx_path << ": " << antenna_list[rx_path] << endl; @@ -1060,8 +1120,7 @@ DC_Q << endl; error(); // get and print print antenna index and name - if ((tx_path = LMS_GetAntenna(device, LMS_CH_TX, LimeCfg.channel)) < - 0) + if ((tx_path = LMS_GetAntenna(device, LMS_CH_TX, LimeCfg.channel)) < 0) error(); cout << "Manually selected TX pathway: " << tx_path << ": " << antenna_list[tx_path] << endl; diff --git a/src/limedriver.h b/src/limedriver.h index 4ede4ef..63eb0a1 100644 --- a/src/limedriver.h +++ b/src/limedriver.h @@ -28,6 +28,8 @@ struct LimeConfig_t { + std::string device; + float srate; int channel; int RX_matching; From 2fa839fbb4ee6c6240c5b2a2d296877199e92667 Mon Sep 17 00:00:00 2001 From: Kumi Date: Sat, 17 Feb 2024 16:54:18 +0100 Subject: [PATCH 3/8] Version bump --- src/limedriver.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/limedriver.h b/src/limedriver.h index 63eb0a1..2d8f784 100644 --- a/src/limedriver.h +++ b/src/limedriver.h @@ -24,7 +24,7 @@ #include // _mkdir #endif -#define VERSION "0.3.0" +#define VERSION "0.4.0" struct LimeConfig_t { From 4c839fae5d8007aaaf6dcc375b62dc38671b5972 Mon Sep 17 00:00:00 2001 From: Kumi Date: Sat, 17 Feb 2024 17:03:42 +0100 Subject: [PATCH 4/8] Add getDeviceList function to LimeDriver header --- src/limedriver.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/limedriver.h b/src/limedriver.h index 2d8f784..53bf291 100644 --- a/src/limedriver.h +++ b/src/limedriver.h @@ -140,4 +140,6 @@ LimeConfig_t initializeLimeConfig(int Npulses); */ int run_experiment_from_LimeCfg(LimeConfig_t LimeCfg); +std::vector getDeviceList(); + #endif // LIMECONFIG_H \ No newline at end of file From 017742f56dc13758dcdab59ed0436f5be10560e5 Mon Sep 17 00:00:00 2001 From: Kumi Date: Sat, 17 Feb 2024 17:58:06 +0100 Subject: [PATCH 5/8] Add channel retrieval functions to LimeDriver Introduced new utility functions for obtaining channel information from LimeSDR devices. These enhancements allow users to retrieve a pair of integers representing the number of available RX and TX channels, either directly from a device instance or through a formatted information string. Addressing the need for more accessible device channel analytics contributes to improved configuration and debugging procedures. --- src/limedriver.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/limedriver.h b/src/limedriver.h index 53bf291..1f657a9 100644 --- a/src/limedriver.h +++ b/src/limedriver.h @@ -140,6 +140,9 @@ LimeConfig_t initializeLimeConfig(int Npulses); */ int run_experiment_from_LimeCfg(LimeConfig_t LimeCfg); +std::pair getDeviceChannels(lms_device_t *dev); +std::pair getChannelsFromInfo(const std::string &info); + std::vector getDeviceList(); #endif // LIMECONFIG_H \ No newline at end of file From a50192b675180b1e14db073b8245f04802251c2c Mon Sep 17 00:00:00 2001 From: Kumi Date: Sat, 17 Feb 2024 18:10:52 +0100 Subject: [PATCH 6/8] Added logging for device opening in LimeDriver The LimeDriver now outputs a message to standard output when attempting to open a device, offering real-time feedback on which device is being accessed. This aids in debugging and provides users with immediate visibility into driver actions. --- src/limedriver.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/limedriver.cpp b/src/limedriver.cpp index de9b255..4feda4d 100644 --- a/src/limedriver.cpp +++ b/src/limedriver.cpp @@ -15,6 +15,7 @@ h5c++ -shlib limedriver.cpp -std=c++11 -lLimeSuite -o limedriver #include "limedriver.h" #include +#include #include #include @@ -129,6 +130,8 @@ lms_device_t *openDevice(const std::string &info) { info_string = deviceList[0]; } + cout << "Opening device: " << info_string << endl; + lms_device_t *dev = NULL; if (LMS_Open(&dev, info.c_str(), NULL)) { error(); From 3e8294c4f1e63ac9bd70af635bbb50c579ced3a3 Mon Sep 17 00:00:00 2001 From: Kumi Date: Sat, 17 Feb 2024 18:14:01 +0100 Subject: [PATCH 7/8] Fix OpenDevice string usage for LMS driver Adjusted the OpenDevice function to utilize the 'info_string' variable instead of 'info' when calling LMS_Open. This resolves an inconsistency in variable usage that could potentially lead to device initialization errors. --- src/limedriver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/limedriver.cpp b/src/limedriver.cpp index 4feda4d..a7e450b 100644 --- a/src/limedriver.cpp +++ b/src/limedriver.cpp @@ -133,7 +133,7 @@ lms_device_t *openDevice(const std::string &info) { cout << "Opening device: " << info_string << endl; lms_device_t *dev = NULL; - if (LMS_Open(&dev, info.c_str(), NULL)) { + if (LMS_Open(&dev, info_string.c_str(), NULL)) { error(); } From c1525cb9e520634058d24bc326f75ca2f1339af3 Mon Sep 17 00:00:00 2001 From: Kumi Date: Sat, 17 Feb 2024 18:14:17 +0100 Subject: [PATCH 8/8] Removed debug output from device opening process Eliminated a console output line that displayed the device being opened. This cleans up the user interface by preventing unnecessary information from cluttering the output, leading to a more streamlined user experience when opening a device. --- src/limedriver.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/limedriver.cpp b/src/limedriver.cpp index a7e450b..19c5309 100644 --- a/src/limedriver.cpp +++ b/src/limedriver.cpp @@ -130,8 +130,6 @@ lms_device_t *openDevice(const std::string &info) { info_string = deviceList[0]; } - cout << "Opening device: " << info_string << endl; - lms_device_t *dev = NULL; if (LMS_Open(&dev, info_string.c_str(), NULL)) { error();