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

Rpc #17

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open

Rpc #17

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
43 changes: 43 additions & 0 deletions README.rtlsdr_rpc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
This implementation of librtlsdr makes remote dongles
appear to the local software as if they were on the
same computer. It works by forwarding librtlsdr calls
to the remote computer over TCP.

It allows one to use existing tools without modifying
them. Also, it allows a developer to use the same API
no matter weither the dongle is local or distant.

To use it, one must compile and install the library
with CMAKE the usual way. Note that you may need to
uninstall the existing librtlsdr, as people reported
runtime errors due to conflicting installs.

Then, a server (called rtl_rpcd) must be run on the
remote location.

In my case, the dongle is in a beagle bone black is
at address 192.168.0.43:
beagleboneblack #> ./rtl_rpcd

Then, the existing tool (for instance rtlizer) can be
run on the local computer using:
RTLSDR_RPC_IS_ENABLED=1 RTLSDR_RPC_SERV_ADDR=192.168.0.43 \
rtlizer

This implementation still has some limitations, but
works well in most cases. Please report any bug to
[email protected]

Also, note that the latest version of libusb should be
used as librtlsdr crashed when used with older version
(esp. the rtlsdr_read_async routine):
https://github.com/libusb/libusb.git

list of known working software:
rtl_fm
rtl_power
rtlsdr-waterfall
rtlizer
gnuradio-companion
cubicsdr
gqrx
123 changes: 123 additions & 0 deletions include/rtlsdr_rpc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#ifndef RTLSDR_RPC_H_INCLUDED
#define RTLSDR_RPC_H_INCLUDED


#include <stdint.h>


#ifdef __cplusplus
extern "C" {
#endif

typedef void (*rtlsdr_rpc_read_async_cb_t)
(unsigned char*, uint32_t, void*);

uint32_t rtlsdr_rpc_get_device_count(void);

const char* rtlsdr_rpc_get_device_name
(uint32_t nidex);

int rtlsdr_rpc_get_device_usb_strings
(uint32_t index, char* manufact, char* product, char* serial);

int rtlsdr_rpc_get_index_by_serial
(const char* serial);

int rtlsdr_rpc_open
(void** dev, uint32_t index);

int rtlsdr_rpc_close
(void* dev);

int rtlsdr_rpc_set_xtal_freq
(void* dev, uint32_t rtl_freq, uint32_t tuner_freq);

int rtlsdr_rpc_get_xtal_freq
(void* dev, uint32_t* rtl_freq, uint32_t* tuner_freq);

int rtlsdr_rpc_get_usb_strings
(void* dev, char* manufact, char* product, char* serial);

int rtlsdr_rpc_write_eeprom
(void* dev, uint8_t* data, uint8_t offset, uint16_t len);

int rtlsdr_rpc_read_eeprom
(void* dev, uint8_t* data, uint8_t offset, uint16_t len);

int rtlsdr_rpc_set_center_freq
(void* dev, uint32_t freq);

uint32_t rtlsdr_rpc_get_center_freq
(void* dev);

int rtlsdr_rpc_set_freq_correction
(void* dev, int ppm);

int rtlsdr_rpc_get_freq_correction
(void *dev);

int rtlsdr_rpc_get_tuner_type
(void* dev);

int rtlsdr_rpc_get_tuner_gains
(void* dev, int* gainsp);

int rtlsdr_rpc_set_tuner_gain
(void *dev, int gain);

int rtlsdr_rpc_get_tuner_gain
(void* dev);

int rtlsdr_rpc_set_tuner_if_gain
(void* dev, int stage, int gain);

int rtlsdr_rpc_set_tuner_gain_mode
(void* dev, int manual);

int rtlsdr_rpc_set_sample_rate
(void* dev, uint32_t rate);

uint32_t rtlsdr_rpc_get_sample_rate
(void* dev);

int rtlsdr_rpc_set_testmode
(void* dev, int on);

int rtlsdr_rpc_set_agc_mode
(void* dev, int on);

int rtlsdr_rpc_set_direct_sampling
(void* dev, int on);

int rtlsdr_rpc_get_direct_sampling
(void* dev);

int rtlsdr_rpc_set_offset_tuning
(void* dev, int on);

int rtlsdr_rpc_get_offset_tuning
(void* dev);

int rtlsdr_rpc_reset_buffer
(void* dev);

int rtlsdr_rpc_read_sync
(void* dev, void* buf, int len, int* n_read);

int rtlsdr_rpc_wait_async
(void* dev, rtlsdr_rpc_read_async_cb_t cb, void* ctx);

int rtlsdr_rpc_read_async
(void* dev, rtlsdr_rpc_read_async_cb_t cb, void* ctx, uint32_t buf_num, uint32_t buf_len);

int rtlsdr_rpc_cancel_async
(void* dev);

unsigned int rtlsdr_rpc_is_enabled(void);

#ifdef __cplusplus
}
#endif


#endif /* RTLSDR_RPC_H_INCLUDED */
94 changes: 94 additions & 0 deletions include/rtlsdr_rpc_msg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#ifndef RTLSDR_RPC_MSG_H_INCLUDED
#define RTLSDR_RPC_MSG_H_INCLUDED


#include <stdint.h>
#include <sys/types.h>

typedef enum
{
RTLSDR_RPC_OP_GET_DEVICE_COUNT = 0,
RTLSDR_RPC_OP_GET_DEVICE_NAME,
RTLSDR_RPC_OP_GET_DEVICE_USB_STRINGS,
RTLSDR_RPC_OP_GET_INDEX_BY_SERIAL,
RTLSDR_RPC_OP_OPEN,
RTLSDR_RPC_OP_CLOSE,
RTLSDR_RPC_OP_SET_XTAL_FREQ,
RTLSDR_RPC_OP_GET_XTAL_FREQ,
RTLSDR_RPC_OP_GET_USB_STRINGS,
RTLSDR_RPC_OP_WRITE_EEPROM,
RTLSDR_RPC_OP_READ_EEPROM,
RTLSDR_RPC_OP_SET_CENTER_FREQ,
RTLSDR_RPC_OP_GET_CENTER_FREQ,
RTLSDR_RPC_OP_SET_FREQ_CORRECTION,
RTLSDR_RPC_OP_GET_FREQ_CORRECTION,
RTLSDR_RPC_OP_GET_TUNER_TYPE,
RTLSDR_RPC_OP_GET_TUNER_GAINS,
RTLSDR_RPC_OP_SET_TUNER_GAIN,
RTLSDR_RPC_OP_GET_TUNER_GAIN,
RTLSDR_RPC_OP_SET_TUNER_IF_GAIN,
RTLSDR_RPC_OP_SET_TUNER_GAIN_MODE,
RTLSDR_RPC_OP_SET_SAMPLE_RATE,
RTLSDR_RPC_OP_GET_SAMPLE_RATE,
RTLSDR_RPC_OP_SET_TESTMODE,
RTLSDR_RPC_OP_SET_AGC_MODE,
RTLSDR_RPC_OP_SET_DIRECT_SAMPLING,
RTLSDR_RPC_OP_GET_DIRECT_SAMPLING,
RTLSDR_RPC_OP_SET_OFFSET_TUNING,
RTLSDR_RPC_OP_GET_OFFSET_TUNING,
RTLSDR_RPC_OP_RESET_BUFFER,
RTLSDR_RPC_OP_READ_SYNC,
RTLSDR_RPC_OP_WAIT_ASYNC,
RTLSDR_RPC_OP_READ_ASYNC,
RTLSDR_RPC_OP_CANCEL_ASYNC,

/* non api operations */
RTLSDR_RPC_OP_EVENT_STATE,

RTLSDR_RPC_OP_INVALID
} rtlsdr_rpc_op_t;

typedef struct
{
/* raw network format */
uint32_t size;
uint8_t op;
uint8_t id;
uint32_t err;
uint8_t data[1];
} __attribute__((packed)) rtlsdr_rpc_fmt_t;

typedef struct
{
size_t off;
size_t size;
uint8_t* fmt;
} rtlsdr_rpc_msg_t;

int rtlsdr_rpc_msg_init(rtlsdr_rpc_msg_t*, size_t);
int rtlsdr_rpc_msg_fini(rtlsdr_rpc_msg_t*);
void rtlsdr_rpc_msg_reset(rtlsdr_rpc_msg_t*);
int rtlsdr_rpc_msg_realloc(rtlsdr_rpc_msg_t*, size_t);

void rtlsdr_rpc_msg_set_size(rtlsdr_rpc_msg_t*, size_t);
size_t rtlsdr_rpc_msg_get_size(const rtlsdr_rpc_msg_t*);
void rtlsdr_rpc_msg_set_op(rtlsdr_rpc_msg_t*, rtlsdr_rpc_op_t);
rtlsdr_rpc_op_t rtlsdr_rpc_msg_get_op(const rtlsdr_rpc_msg_t*);
void rtlsdr_rpc_msg_set_id(rtlsdr_rpc_msg_t*, uint8_t);
uint8_t rtlsdr_rpc_msg_get_id(const rtlsdr_rpc_msg_t*);
void rtlsdr_rpc_msg_set_err(rtlsdr_rpc_msg_t*, int);
int rtlsdr_rpc_msg_get_err(const rtlsdr_rpc_msg_t*);

int rtlsdr_rpc_msg_push_int32(rtlsdr_rpc_msg_t*, int32_t);
int rtlsdr_rpc_msg_push_uint32(rtlsdr_rpc_msg_t*, uint32_t);
void rtlsdr_rpc_msg_push_uint32_safe(rtlsdr_rpc_msg_t*, uint32_t);
int rtlsdr_rpc_msg_push_str(rtlsdr_rpc_msg_t*, const char*);
int rtlsdr_rpc_msg_push_buf(rtlsdr_rpc_msg_t*, const uint8_t*, size_t);
void rtlsdr_rpc_msg_skip_safe(rtlsdr_rpc_msg_t*, size_t);
int rtlsdr_rpc_msg_pop_int32(rtlsdr_rpc_msg_t*, int32_t*);
int rtlsdr_rpc_msg_pop_uint32(rtlsdr_rpc_msg_t*, uint32_t*);
int rtlsdr_rpc_msg_pop_str(rtlsdr_rpc_msg_t*, const char**);
int rtlsdr_rpc_msg_pop_buf(rtlsdr_rpc_msg_t*, const uint8_t**, size_t*);


#endif /* RTLSDR_RPC_MSG_H_INCLUDED */
11 changes: 10 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ RTLSDR_APPEND_SRCS(
tuner_fc0013.c
tuner_fc2580.c
tuner_r82xx.c
rtlsdr_rpc.c
rtlsdr_rpc_msg.c
)

########################################################################
Expand Down Expand Up @@ -91,7 +93,8 @@ add_executable(rtl_fm rtl_fm.c)
add_executable(rtl_eeprom rtl_eeprom.c)
add_executable(rtl_adsb rtl_adsb.c)
add_executable(rtl_power rtl_power.c)
set(INSTALL_TARGETS rtlsdr_shared rtlsdr_static rtl_sdr rtl_tcp rtl_test rtl_fm rtl_eeprom rtl_adsb rtl_power)
add_executable(rtl_rpcd rtl_rpcd.c rtlsdr_rpc_msg.c)
set(INSTALL_TARGETS rtlsdr_shared rtlsdr_static rtl_sdr rtl_tcp rtl_test rtl_fm rtl_eeprom rtl_adsb rtl_power rtl_rpcd)

target_link_libraries(rtl_sdr rtlsdr_shared convenience_static
${LIBUSB_LIBRARIES}
Expand Down Expand Up @@ -121,6 +124,10 @@ target_link_libraries(rtl_power rtlsdr_shared convenience_static
${LIBUSB_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
target_link_libraries(rtl_rpcd rtlsdr_shared convenience_static
${LIBUSB_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
if(UNIX)
target_link_libraries(rtl_fm m)
target_link_libraries(rtl_adsb m)
Expand All @@ -140,13 +147,15 @@ target_link_libraries(rtl_fm libgetopt_static)
target_link_libraries(rtl_eeprom libgetopt_static)
target_link_libraries(rtl_adsb libgetopt_static)
target_link_libraries(rtl_power libgetopt_static)
target_link_libraries(rtl_rpcd ws2_32 libgetopt_static)
set_property(TARGET rtl_sdr APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
set_property(TARGET rtl_tcp APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
set_property(TARGET rtl_test APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
set_property(TARGET rtl_fm APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
set_property(TARGET rtl_eeprom APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
set_property(TARGET rtl_adsb APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
set_property(TARGET rtl_power APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
set_property(TARGET rtl_rpcd APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
endif()
########################################################################
# Install built library files & utilities
Expand Down
7 changes: 5 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ AM_CFLAGS = ${CFLAGS} -fPIC ${SYMBOL_VISIBILITY}

lib_LTLIBRARIES = librtlsdr.la

librtlsdr_la_SOURCES = librtlsdr.c tuner_e4k.c tuner_fc0012.c tuner_fc0013.c tuner_fc2580.c tuner_r82xx.c
librtlsdr_la_SOURCES = librtlsdr.c tuner_e4k.c tuner_fc0012.c tuner_fc0013.c tuner_fc2580.c tuner_r82xx.c rtlsdr_rpc.c rtlsdr_rpc_msg.c
librtlsdr_la_LDFLAGS = -version-info $(LIBVERSION)

bin_PROGRAMS = rtl_sdr rtl_tcp rtl_test rtl_fm rtl_eeprom rtl_adsb rtl_power
bin_PROGRAMS = rtl_sdr rtl_tcp rtl_test rtl_fm rtl_eeprom rtl_adsb rtl_power rtl_rpcd

rtl_sdr_SOURCES = rtl_sdr.c convenience/convenience.c
rtl_sdr_LDADD = librtlsdr.la
Expand All @@ -34,3 +34,6 @@ rtl_adsb_LDADD = librtlsdr.la $(LIBM)

rtl_power_SOURCES = rtl_power.c convenience/convenience.c
rtl_power_LDADD = librtlsdr.la $(LIBM)

rtl_rpcd_SOURCES = rtl_rpcd.c rtlsdr_rpc_msg.c convenience/convenience.c
rtl_rpcd_LDADD = librtlsdr.la
Loading