summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDimitri Stolnikov <horiz0n@gmx.net>2012-06-02 01:14:31 +0200
committerDimitri Stolnikov <horiz0n@gmx.net>2012-06-02 01:41:04 +0200
commit292a9868301e364f27412d0348bbeb3714e89b05 (patch)
tree3c6a64135a094a7be87c712132efcb8e63ae4c1f
parenta2382d66d8a85c13783cfdf782aab16d79c11802 (diff)
introduce getters for tuner parameters (gain, type)
-rw-r--r--software/libosmosdr/include/osmosdr.h14
-rw-r--r--software/libosmosdr/src/libosmosdr.c19
-rw-r--r--software/libosmosdr/src/osmo_sdr.c10
3 files changed, 43 insertions, 0 deletions
diff --git a/software/libosmosdr/include/osmosdr.h b/software/libosmosdr/include/osmosdr.h
index 396fe36..e80a2f8 100644
--- a/software/libosmosdr/include/osmosdr.h
+++ b/software/libosmosdr/include/osmosdr.h
@@ -110,6 +110,18 @@ OSMOSDR_API int osmosdr_set_center_freq(osmosdr_dev_t *dev, uint32_t freq);
OSMOSDR_API uint32_t osmosdr_get_center_freq(osmosdr_dev_t *dev);
/*!
+ * Get a list of gains supported by the tuner.
+ *
+ * NOTE: The gains argument must be preallocated by the caller. If NULL is
+ * being given instead, the number of available gain values will be returned.
+ *
+ * \param dev the device handle given by osmosdr_open()
+ * \param gains array of gain values. In tenths of a dB, 115 means 11.5 dB.
+ * \return <= 0 on error, number of available (returned) gain values otherwise
+ */
+OSMOSDR_API int osmosdr_get_tuner_gains(osmosdr_dev_t *dev, int *gains);
+
+/*!
* Set the gain for the device.
* Manual gain mode must be enabled for this to work.
*
@@ -117,6 +129,8 @@ OSMOSDR_API uint32_t osmosdr_get_center_freq(osmosdr_dev_t *dev);
* -10, 15, 40, 65, 90, 115, 140, 165, 190,
* 215, 240, 290, 340, 420, 430, 450, 470, 490
*
+ * Valid gain values may be queried with \ref osmosdr_get_tuner_gains function.
+ *
* \param dev the device handle given by osmosdr_open()
* \param gain in tenths of a dB, 115 means 11.5 dB.
* \return 0 on success
diff --git a/software/libosmosdr/src/libosmosdr.c b/software/libosmosdr/src/libosmosdr.c
index f4329b5..4bc57b3 100644
--- a/software/libosmosdr/src/libosmosdr.c
+++ b/software/libosmosdr/src/libosmosdr.c
@@ -332,6 +332,25 @@ uint32_t osmosdr_get_center_freq(osmosdr_dev_t *dev)
return dev->freq;
}
+int osmosdr_get_tuner_gains(osmosdr_dev_t *dev, int *gains)
+{
+ const int e4k_gains[] = { -10, 15, 40, 65, 90, 115, 140, 165, 190, 215,
+ 240, 290, 340, 420, 430, 450, 470, 490 };
+ int len = sizeof(e4k_gains);
+
+ if (!dev)
+ return -1;
+
+ if (!gains) { /* no buffer provided, just return the count */
+ return len / sizeof(int);
+ } else {
+ if (len)
+ memcpy(gains, e4k_gains, len);
+
+ return len / sizeof(int);
+ }
+}
+
int osmosdr_set_tuner_gain(osmosdr_dev_t *dev, int gain)
{
int r = 0;
diff --git a/software/libosmosdr/src/osmo_sdr.c b/software/libosmosdr/src/osmo_sdr.c
index b5e510b..f3eb8f6 100644
--- a/software/libosmosdr/src/osmo_sdr.c
+++ b/software/libosmosdr/src/osmo_sdr.c
@@ -108,6 +108,9 @@ int main(int argc, char **argv)
uint32_t out_block_size = DEFAULT_BUF_LENGTH;
int device_count;
char vendor[256] = { 0 }, product[256] = { 0 }, serial[256] = { 0 };
+ int count;
+ int gains[100];
+
#ifndef _WIN32
while ((opt = getopt(argc, argv, "d:f:g:s:b:S::")) != -1) {
switch (opt) {
@@ -194,6 +197,13 @@ int main(int argc, char **argv)
#else
SetConsoleCtrlHandler( (PHANDLER_ROUTINE) sighandler, TRUE );
#endif
+ count = osmosdr_get_tuner_gains(dev, NULL);
+ fprintf(stderr, "Supported gain values (%d): ", count);
+
+ count = osmosdr_get_tuner_gains(dev, gains);
+ for (i = 0; i < count; i++)
+ fprintf(stderr, "%.1f ", gains[i] / 10.0);
+ fprintf(stderr, "\n");
r = osmosdr_get_usb_strings(dev, vendor, product, serial);
if (r < 0)