Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added sync output mode #20

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions include/rtl-sdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,15 @@ RTLSDR_API int rtlsdr_get_tuner_gains(rtlsdr_dev_t *dev, int *gains);
*/
RTLSDR_API int rtlsdr_set_tuner_gain(rtlsdr_dev_t *dev, int gain);

/*!
* Set the bandwidth for the device.
*
* \param dev the device handle given by rtlsdr_open()
* \param bw bandwidth in Hz. Zero means automatic BW selection.
* \return 0 on success
*/
RTLSDR_API int rtlsdr_set_tuner_bandwidth(rtlsdr_dev_t *dev, uint32_t bw);

/*!
* Get actual gain the device is configured to.
*
Expand Down
1 change: 1 addition & 0 deletions include/tuner_r82xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,6 @@ int r82xx_standby(struct r82xx_priv *priv);
int r82xx_init(struct r82xx_priv *priv);
int r82xx_set_freq(struct r82xx_priv *priv, uint32_t freq);
int r82xx_set_gain(struct r82xx_priv *priv, int set_manual_gain, int gain);
int r82xx_set_bandwidth(struct r82xx_priv *priv, int bandwidth, uint32_t rate);

#endif
3 changes: 3 additions & 0 deletions rtl-sdr.rules
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ SUBSYSTEMS=="usb", ATTRS{idVendor}=="1554", ATTRS{idProduct}=="5020", MODE:="066
# Astrometa DVB-T/DVB-T2 (R828D)
SUBSYSTEMS=="usb", ATTRS{idVendor}=="15f4", ATTRS{idProduct}=="0131", MODE:="0666"

# HanfTek DAB+FM+DVB-T
SUBSYSTEMS=="usb", ATTRS{idVendor}=="15f4", ATTRS{idProduct}=="0133", MODE:="0666"

# Compro Videomate U620F (E4000)
SUBSYSTEMS=="usb", ATTRS{idVendor}=="185b", ATTRS{idProduct}=="0620", MODE:="0666"

Expand Down
62 changes: 36 additions & 26 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.

########################################################################
# Setup library
########################################################################
add_library(rtlsdr_shared SHARED
MACRO(RTLSDR_APPEND_SRCS)
LIST(APPEND rtlsdr_srcs ${ARGV})
ENDMACRO(RTLSDR_APPEND_SRCS)

RTLSDR_APPEND_SRCS(
librtlsdr.c
tuner_e4k.c
tuner_fc0012.c
Expand All @@ -29,24 +30,44 @@ add_library(rtlsdr_shared SHARED
tuner_r82xx.c
)

target_link_libraries(rtlsdr_shared
${LIBUSB_LIBRARIES}
)
########################################################################
# Set up Windows DLL resource files
########################################################################
IF(MSVC)
include(${CMAKE_SOURCE_DIR}/cmake/Modules/Version.cmake)

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/rtlsdr.rc.in
${CMAKE_CURRENT_BINARY_DIR}/rtlsdr.rc
@ONLY)

RTLSDR_APPEND_SRCS(${CMAKE_CURRENT_BINARY_DIR}/rtlsdr.rc)
ENDIF(MSVC)

########################################################################
# Setup shared library variant
########################################################################
add_library(rtlsdr_shared SHARED ${rtlsdr_srcs})
target_link_libraries(rtlsdr_shared ${LIBUSB_LIBRARIES})
set_target_properties(rtlsdr_shared PROPERTIES DEFINE_SYMBOL "rtlsdr_EXPORTS")
set_target_properties(rtlsdr_shared PROPERTIES OUTPUT_NAME rtlsdr)
set_target_properties(rtlsdr_shared PROPERTIES SOVERSION ${MAJOR_VERSION})
set_target_properties(rtlsdr_shared PROPERTIES VERSION ${LIBVER})

add_library(rtlsdr_static STATIC
librtlsdr.c
tuner_e4k.c
tuner_fc0012.c
tuner_fc0013.c
tuner_fc2580.c
tuner_r82xx.c
)
########################################################################
# Setup static library variant
########################################################################
add_library(rtlsdr_static STATIC ${rtlsdr_srcs})
target_link_libraries(rtlsdr_static ${LIBUSB_LIBRARIES})
set_property(TARGET rtlsdr_static APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
if(NOT WIN32)
# Force same library filename for static and shared variants of the library
set_target_properties(rtlsdr_static PROPERTIES OUTPUT_NAME rtlsdr)
endif()

########################################################################
# Setup libraries used in executables
########################################################################
add_library(convenience_static STATIC
convenience/convenience.c
)
Expand All @@ -60,17 +81,6 @@ target_link_libraries(convenience_static
)
endif()

target_link_libraries(rtlsdr_static
${LIBUSB_LIBRARIES}
)

set_property(TARGET rtlsdr_static APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )

if(NOT WIN32)
# Force same library filename for static and shared variants of the library
set_target_properties(rtlsdr_static PROPERTIES OUTPUT_NAME rtlsdr)
endif()

########################################################################
# Build utility
########################################################################
Expand Down
78 changes: 65 additions & 13 deletions src/librtlsdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ struct rtlsdr_dev {
rtlsdr_tuner_iface_t *tuner;
uint32_t tun_xtal; /* Hz */
uint32_t freq; /* Hz */
uint32_t bw;
uint32_t offs_freq; /* Hz */
int corr; /* ppm */
int gain; /* tenth dB */
Expand All @@ -126,6 +127,7 @@ struct rtlsdr_dev {
};

void rtlsdr_set_gpio_bit(rtlsdr_dev_t *dev, uint8_t gpio, int val);
static int rtlsdr_set_if_freq(rtlsdr_dev_t *dev, uint32_t freq);

/* generic tuner interface functions, shall be moved to the tuner implementations */
int e4000_init(void *dev) {
Expand Down Expand Up @@ -238,7 +240,20 @@ int r820t_set_freq(void *dev, uint32_t freq) {
rtlsdr_dev_t* devt = (rtlsdr_dev_t*)dev;
return r82xx_set_freq(&devt->r82xx_p, freq);
}
int r820t_set_bw(void *dev, int bw) { return 0; }

int r820t_set_bw(void *dev, int bw) {
int r;
rtlsdr_dev_t* devt = (rtlsdr_dev_t*)dev;

r = r82xx_set_bandwidth(&devt->r82xx_p, bw, devt->rate);
if(r < 0)
return r;
r = rtlsdr_set_if_freq(devt, r);
if (r)
return r;
return rtlsdr_set_center_freq(devt, devt->freq);
}

int r820t_set_gain(void *dev, int gain) {
rtlsdr_dev_t* devt = (rtlsdr_dev_t*)dev;
return r82xx_set_gain(&devt->r82xx_p, 1, gain);
Expand Down Expand Up @@ -314,6 +329,7 @@ static rtlsdr_dongle_t known_devices[] = {
{ 0x0ccd, 0x00e0, "Terratec NOXON DAB/DAB+ USB dongle (rev 2)" },
{ 0x1554, 0x5020, "PixelView PV-DT235U(RN)" },
{ 0x15f4, 0x0131, "Astrometa DVB-T/DVB-T2" },
{ 0x15f4, 0x0133, "HanfTek DAB+FM+DVB-T" },
{ 0x185b, 0x0620, "Compro Videomate U620F"},
{ 0x185b, 0x0650, "Compro Videomate U650F"},
{ 0x185b, 0x0680, "Compro Videomate U680F"},
Expand All @@ -338,7 +354,7 @@ static rtlsdr_dongle_t known_devices[] = {
{ 0x1f4d, 0xd803, "PROlectrix DV107669" },
};

#define DEFAULT_BUF_NUMBER 15
#define DEFAULT_BUF_NUMBER 1
#define DEFAULT_BUF_LENGTH (16 * 32 * 512)

#define DEF_RTL_XTAL_FREQ 28800000
Expand Down Expand Up @@ -670,7 +686,7 @@ int rtlsdr_deinit_baseband(rtlsdr_dev_t *dev)
return r;
}

int rtlsdr_set_if_freq(rtlsdr_dev_t *dev, uint32_t freq)
static int rtlsdr_set_if_freq(rtlsdr_dev_t *dev, uint32_t freq)
{
uint32_t rtl_xtal;
int32_t if_freq;
Expand Down Expand Up @@ -994,6 +1010,24 @@ int rtlsdr_get_tuner_gains(rtlsdr_dev_t *dev, int *gains)
}
}

int rtlsdr_set_tuner_bandwidth(rtlsdr_dev_t *dev, uint32_t bw)
{
int r = 0;

if (!dev || !dev->tuner)
return -1;

if (dev->tuner->set_bw) {
rtlsdr_set_i2c_repeater(dev, 1);
r = dev->tuner->set_bw(dev, bw > 0 ? bw : dev->rate);
rtlsdr_set_i2c_repeater(dev, 0);
if (r)
return r;
dev->bw = bw;
}
return r;
}

int rtlsdr_set_tuner_gain(rtlsdr_dev_t *dev, int gain)
{
int r = 0;
Expand Down Expand Up @@ -1081,14 +1115,14 @@ int rtlsdr_set_sample_rate(rtlsdr_dev_t *dev, uint32_t samp_rate)
if ( ((double)samp_rate) != real_rate )
fprintf(stderr, "Exact sample rate is: %f Hz\n", real_rate);

dev->rate = (uint32_t)real_rate;

if (dev->tuner && dev->tuner->set_bw) {
rtlsdr_set_i2c_repeater(dev, 1);
dev->tuner->set_bw(dev, (int)real_rate);
dev->tuner->set_bw(dev, dev->bw > 0 ? dev->bw : dev->rate);
rtlsdr_set_i2c_repeater(dev, 0);
}

dev->rate = (uint32_t)real_rate;

tmp = (rsamp_ratio >> 16);
r |= rtlsdr_demod_write_reg(dev, 1, 0x9f, tmp, 2);
tmp = rsamp_ratio & 0xffff;
Expand Down Expand Up @@ -1205,6 +1239,7 @@ int rtlsdr_get_direct_sampling(rtlsdr_dev_t *dev)
int rtlsdr_set_offset_tuning(rtlsdr_dev_t *dev, int on)
{
int r = 0;
int bw;

if (!dev)
return -1;
Expand All @@ -1222,7 +1257,14 @@ int rtlsdr_set_offset_tuning(rtlsdr_dev_t *dev, int on)

if (dev->tuner && dev->tuner->set_bw) {
rtlsdr_set_i2c_repeater(dev, 1);
dev->tuner->set_bw(dev, on ? (2 * dev->offs_freq) : dev->rate);
if (on) {
bw = 2 * dev->offs_freq;
} else if (dev->bw > 0) {
bw = dev->bw;
} else {
bw = dev->rate;
}
dev->tuner->set_bw(dev, bw);
rtlsdr_set_i2c_repeater(dev, 0);
}

Expand Down Expand Up @@ -1257,14 +1299,16 @@ static rtlsdr_dongle_t *find_known_device(uint16_t vid, uint16_t pid)

uint32_t rtlsdr_get_device_count(void)
{
int i;
int i,r;
libusb_context *ctx;
libusb_device **list;
uint32_t device_count = 0;
struct libusb_device_descriptor dd;
ssize_t cnt;

libusb_init(&ctx);
r = libusb_init(&ctx);
if(r < 0)
return 0;

cnt = libusb_get_device_list(ctx, &list);

Expand All @@ -1284,15 +1328,17 @@ uint32_t rtlsdr_get_device_count(void)

const char *rtlsdr_get_device_name(uint32_t index)
{
int i;
int i,r;
libusb_context *ctx;
libusb_device **list;
struct libusb_device_descriptor dd;
rtlsdr_dongle_t *device = NULL;
uint32_t device_count = 0;
ssize_t cnt;

libusb_init(&ctx);
r = libusb_init(&ctx);
if(r < 0)
return "";

cnt = libusb_get_device_list(ctx, &list);

Expand Down Expand Up @@ -1332,7 +1378,9 @@ int rtlsdr_get_device_usb_strings(uint32_t index, char *manufact,
uint32_t device_count = 0;
ssize_t cnt;

libusb_init(&ctx);
r = libusb_init(&ctx);
if(r < 0)
return r;

cnt = libusb_get_device_list(ctx, &list);

Expand Down Expand Up @@ -1406,7 +1454,11 @@ int rtlsdr_open(rtlsdr_dev_t **out_dev, uint32_t index)
memset(dev, 0, sizeof(rtlsdr_dev_t));
memcpy(dev->fir, fir_default, sizeof(fir_default));

libusb_init(&dev->ctx);
r = libusb_init(&dev->ctx);
if(r < 0){
free(dev);
return -1;
}

dev->dev_lost = 1;

Expand Down
2 changes: 2 additions & 0 deletions src/rtl_adsb.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@

#ifdef _WIN32
#define sleep Sleep
#if defined(_MSC_VER) && (_MSC_VER < 1800)
#define round(x) (x > 0.0 ? floor(x + 0.5): ceil(x - 0.5))
#endif
#endif

#define ADSB_RATE 2000000
#define ADSB_FREQ 1090000000
Expand Down
Loading