Skip to content

Commit 75a3e99

Browse files
committed
Merge pull request #1 from librtlsdr/BWChanges
Bandwidth Changes
2 parents cee5d10 + 6f1660d commit 75a3e99

File tree

10 files changed

+421
-244
lines changed

10 files changed

+421
-244
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,13 @@ CMakeFiles
4141
*.cmake
4242
build
4343

44+
**/*.o
45+
**/*.so*
46+
**/*.a
47+
src/rtl_adsb
48+
src/rtl_eeprom
49+
src/rtl_fm
50+
src/rtl_power
51+
src/rtl_test
52+
4453
debianize/*.deb

include/rtl-sdr.h

100644100755
+7-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ extern "C" {
2626

2727
#include <stdint.h>
2828
#include <rtl-sdr_export.h>
29+
#include <rtl_tcp.h>
2930

3031
typedef struct rtlsdr_dev rtlsdr_dev_t;
3132

@@ -220,9 +221,14 @@ RTLSDR_API int rtlsdr_set_tuner_gain(rtlsdr_dev_t *dev, int gain);
220221
*
221222
* \param dev the device handle given by rtlsdr_open()
222223
* \param bw bandwidth in Hz. Zero means automatic BW selection.
224+
* \param applied_bw is applied bandwidth in Hz, or 0 if unknown
225+
* \param apply_bw: 1 to really apply configure the tuner chip; 0 for just returning applied_bw
223226
* \return 0 on success
224227
*/
225-
RTLSDR_API int rtlsdr_set_tuner_bandwidth(rtlsdr_dev_t *dev, uint32_t bw);
228+
RTLSDR_API int rtlsdr_set_and_get_tuner_bandwidth(rtlsdr_dev_t *dev, uint32_t bw, uint32_t *applied_bw, int apply_bw );
229+
230+
RTLSDR_API int rtlsdr_set_tuner_bandwidth(rtlsdr_dev_t *dev, uint32_t bw );
231+
226232

227233
/*!
228234
* Get actual gain the device is configured to.

include/rtl_tcp.h

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* rtl-sdr, turns your Realtek RTL2832 based DVB dongle into a SDR receiver
3+
* Copyright (C) 2012-2013 by Steve Markgraf <[email protected]>
4+
* Copyright (C) 2012 by Dimitri Stolnikov <[email protected]>
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#ifndef __RTL_TCP_H
21+
#define __RTL_TCP_H
22+
23+
#ifdef __cplusplus
24+
extern "C" {
25+
#endif
26+
27+
/*!
28+
* This enum defines the possible commands in rtl_tcp
29+
*/
30+
enum RTL_TCP_COMMANDS {
31+
SET_FREQUENCY = 0x01,
32+
SET_SAMPLE_RATE = 0x02,
33+
SET_GAIN_MODE = 0x03,
34+
SET_GAIN = 0x04,
35+
SET_FREQUENCY_CORRECTION = 0x05,
36+
SET_IF_STAGE = 0x06,
37+
SET_TEST_MODE = 0x07,
38+
SET_AGC_MODE = 0x08,
39+
SET_DIRECT_SAMPLING = 0x09,
40+
SET_OFFSET_TUNING = 0x0A,
41+
SET_RTL_CRYSTAL = 0x0B,
42+
SET_TUNER_CRYSTAL = 0x0C,
43+
SET_TUNER_GAIN_BY_INDEX = 0x0D,
44+
SET_TUNER_BANDWIDTH = 0x0E
45+
};
46+
47+
#ifdef __cplusplus
48+
}
49+
#endif
50+
51+
#endif

include/tuner_r82xx.h

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,6 @@ int r82xx_set_freq(struct r82xx_priv *priv, uint32_t freq);
115115
//int r82xx_set_gain(struct r82xx_priv *priv, int set_manual_gain, int gain);
116116
int r82xx_set_gain(struct r82xx_priv *priv, int set_manual_gain, int gain, int extended_mode, int lna_gain, int mixer_gain, int vga_gain);
117117

118-
int r82xx_set_bandwidth(struct r82xx_priv *priv, int bandwidth, uint32_t rate);
118+
int r82xx_set_bandwidth(struct r82xx_priv *priv, int bandwidth, uint32_t rate, uint32_t * applied_bw, int apply);
119119

120120
#endif

src/convenience/convenience.c

100644100755
+16
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,22 @@ int verbose_set_sample_rate(rtlsdr_dev_t *dev, uint32_t samp_rate)
160160
return r;
161161
}
162162

163+
int verbose_set_bandwidth(rtlsdr_dev_t *dev, uint32_t bandwidth)
164+
{
165+
int r;
166+
uint32_t applied_bw = 0;
167+
/* r = rtlsdr_set_tuner_bandwidth(dev, bandwidth); */
168+
r = rtlsdr_set_and_get_tuner_bandwidth(dev, bandwidth, &applied_bw, 1 /* =apply_bw */);
169+
if (r < 0) {
170+
fprintf(stderr, "WARNING: Failed to set bandwidth.\n");
171+
} else if (bandwidth > 0) {
172+
fprintf(stderr, "Bandwidth set to %u Hz resulted in %u Hz.\n", bandwidth, applied_bw);
173+
} else {
174+
fprintf(stderr, "Bandwidth set to automatic resulted in %u Hz.\n", applied_bw);
175+
}
176+
return r;
177+
}
178+
163179
int verbose_direct_sampling(rtlsdr_dev_t *dev, int on)
164180
{
165181
int r;

src/convenience/convenience.h

+11
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ int verbose_set_frequency(rtlsdr_dev_t *dev, uint32_t frequency);
7777

7878
int verbose_set_sample_rate(rtlsdr_dev_t *dev, uint32_t samp_rate);
7979

80+
/*!
81+
* Set device bandwidth and report status on stderr
82+
*
83+
* \param dev the device handle given by rtlsdr_open()
84+
* \param frequency in Hz
85+
* \return 0 on success
86+
*/
87+
88+
int verbose_set_bandwidth(rtlsdr_dev_t *dev, uint32_t bandwidth);
89+
90+
8091
/*!
8192
* Enable or disable the direct sampling mode and report status on stderr
8293
*

0 commit comments

Comments
 (0)