Skip to content

Commit 44cef14

Browse files
authored
Merge pull request steve-m#11 from rxseger/rpc_ir
Add rtl_rpcd for using librtlsdr remotely + IR control (rpc_ir)
2 parents 183245f + 2316a13 commit 44cef14

File tree

9 files changed

+3348
-3
lines changed

9 files changed

+3348
-3
lines changed

README.rtlsdr_rpc

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
This implementation of librtlsdr makes remote dongles
2+
appear to the local software as if they were on the
3+
same computer. It works by forwarding librtlsdr calls
4+
to the remote computer over TCP.
5+
6+
It allows one to use existing tools without modifying
7+
them. Also, it allows a developer to use the same API
8+
no matter weither the dongle is local or distant.
9+
10+
To use it, one must compile and install the library
11+
with CMAKE the usual way. Note that you may need to
12+
uninstall the existing librtlsdr, as people reported
13+
runtime errors due to conflicting installs.
14+
15+
Then, a server (called rtl_rpcd) must be run on the
16+
remote location.
17+
18+
In my case, the dongle is in a beagle bone black is
19+
at address 192.168.0.43:
20+
beagleboneblack #> ./rtl_rpcd
21+
22+
Then, the existing tool (for instance rtlizer) can be
23+
run on the local computer using:
24+
RTLSDR_RPC_IS_ENABLED=1 RTLSDR_RPC_SERV_ADDR=192.168.0.43 \
25+
rtlizer
26+
27+
This implementation still has some limitations, but
28+
works well in most cases. Please report any bug to
29+
30+
31+
Also, note that the latest version of libusb should be
32+
used as librtlsdr crashed when used with older version
33+
(esp. the rtlsdr_read_async routine):
34+
https://github.com/libusb/libusb.git
35+
36+
list of known working software:
37+
rtl_fm
38+
rtl_power
39+
rtlsdr-waterfall
40+
rtlizer
41+
gnuradio-companion
42+
cubicsdr
43+
gqrx

include/rtlsdr_rpc.h

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#ifndef RTLSDR_RPC_H_INCLUDED
2+
#define RTLSDR_RPC_H_INCLUDED
3+
4+
5+
#include <stdint.h>
6+
7+
8+
#ifdef __cplusplus
9+
extern "C" {
10+
#endif
11+
12+
typedef void (*rtlsdr_rpc_read_async_cb_t)
13+
(unsigned char*, uint32_t, void*);
14+
15+
uint32_t rtlsdr_rpc_get_device_count(void);
16+
17+
const char* rtlsdr_rpc_get_device_name
18+
(uint32_t nidex);
19+
20+
int rtlsdr_rpc_get_device_usb_strings
21+
(uint32_t index, char* manufact, char* product, char* serial);
22+
23+
int rtlsdr_rpc_get_index_by_serial
24+
(const char* serial);
25+
26+
int rtlsdr_rpc_open
27+
(void** dev, uint32_t index);
28+
29+
int rtlsdr_rpc_close
30+
(void* dev);
31+
32+
int rtlsdr_rpc_set_xtal_freq
33+
(void* dev, uint32_t rtl_freq, uint32_t tuner_freq);
34+
35+
int rtlsdr_rpc_get_xtal_freq
36+
(void* dev, uint32_t* rtl_freq, uint32_t* tuner_freq);
37+
38+
int rtlsdr_rpc_get_usb_strings
39+
(void* dev, char* manufact, char* product, char* serial);
40+
41+
int rtlsdr_rpc_write_eeprom
42+
(void* dev, uint8_t* data, uint8_t offset, uint16_t len);
43+
44+
int rtlsdr_rpc_read_eeprom
45+
(void* dev, uint8_t* data, uint8_t offset, uint16_t len);
46+
47+
int rtlsdr_rpc_set_center_freq
48+
(void* dev, uint32_t freq);
49+
50+
uint32_t rtlsdr_rpc_get_center_freq
51+
(void* dev);
52+
53+
int rtlsdr_rpc_set_freq_correction
54+
(void* dev, int ppm);
55+
56+
int rtlsdr_rpc_get_freq_correction
57+
(void *dev);
58+
59+
int rtlsdr_rpc_get_tuner_type
60+
(void* dev);
61+
62+
int rtlsdr_rpc_get_tuner_gains
63+
(void* dev, int* gainsp);
64+
65+
int rtlsdr_rpc_set_tuner_gain
66+
(void *dev, int gain);
67+
68+
int rtlsdr_rpc_get_tuner_gain
69+
(void* dev);
70+
71+
int rtlsdr_rpc_set_tuner_if_gain
72+
(void* dev, int stage, int gain);
73+
74+
int rtlsdr_rpc_set_tuner_gain_mode
75+
(void* dev, int manual);
76+
77+
int rtlsdr_rpc_set_sample_rate
78+
(void* dev, uint32_t rate);
79+
80+
uint32_t rtlsdr_rpc_get_sample_rate
81+
(void* dev);
82+
83+
int rtlsdr_rpc_set_testmode
84+
(void* dev, int on);
85+
86+
int rtlsdr_rpc_set_agc_mode
87+
(void* dev, int on);
88+
89+
int rtlsdr_rpc_set_direct_sampling
90+
(void* dev, int on);
91+
92+
int rtlsdr_rpc_get_direct_sampling
93+
(void* dev);
94+
95+
int rtlsdr_rpc_set_offset_tuning
96+
(void* dev, int on);
97+
98+
int rtlsdr_rpc_get_offset_tuning
99+
(void* dev);
100+
101+
int rtlsdr_rpc_reset_buffer
102+
(void* dev);
103+
104+
int rtlsdr_rpc_read_sync
105+
(void* dev, void* buf, int len, int* n_read);
106+
107+
int rtlsdr_rpc_wait_async
108+
(void* dev, rtlsdr_rpc_read_async_cb_t cb, void* ctx);
109+
110+
int rtlsdr_rpc_read_async
111+
(void* dev, rtlsdr_rpc_read_async_cb_t cb, void* ctx, uint32_t buf_num, uint32_t buf_len);
112+
113+
int rtlsdr_rpc_cancel_async
114+
(void* dev);
115+
116+
unsigned int rtlsdr_rpc_is_enabled(void);
117+
118+
#ifdef __cplusplus
119+
}
120+
#endif
121+
122+
123+
#endif /* RTLSDR_RPC_H_INCLUDED */

include/rtlsdr_rpc_msg.h

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#ifndef RTLSDR_RPC_MSG_H_INCLUDED
2+
#define RTLSDR_RPC_MSG_H_INCLUDED
3+
4+
5+
#include <stdint.h>
6+
#include <sys/types.h>
7+
8+
typedef enum
9+
{
10+
RTLSDR_RPC_OP_GET_DEVICE_COUNT = 0,
11+
RTLSDR_RPC_OP_GET_DEVICE_NAME,
12+
RTLSDR_RPC_OP_GET_DEVICE_USB_STRINGS,
13+
RTLSDR_RPC_OP_GET_INDEX_BY_SERIAL,
14+
RTLSDR_RPC_OP_OPEN,
15+
RTLSDR_RPC_OP_CLOSE,
16+
RTLSDR_RPC_OP_SET_XTAL_FREQ,
17+
RTLSDR_RPC_OP_GET_XTAL_FREQ,
18+
RTLSDR_RPC_OP_GET_USB_STRINGS,
19+
RTLSDR_RPC_OP_WRITE_EEPROM,
20+
RTLSDR_RPC_OP_READ_EEPROM,
21+
RTLSDR_RPC_OP_SET_CENTER_FREQ,
22+
RTLSDR_RPC_OP_GET_CENTER_FREQ,
23+
RTLSDR_RPC_OP_SET_FREQ_CORRECTION,
24+
RTLSDR_RPC_OP_GET_FREQ_CORRECTION,
25+
RTLSDR_RPC_OP_GET_TUNER_TYPE,
26+
RTLSDR_RPC_OP_GET_TUNER_GAINS,
27+
RTLSDR_RPC_OP_SET_TUNER_GAIN,
28+
RTLSDR_RPC_OP_GET_TUNER_GAIN,
29+
RTLSDR_RPC_OP_SET_TUNER_IF_GAIN,
30+
RTLSDR_RPC_OP_SET_TUNER_GAIN_MODE,
31+
RTLSDR_RPC_OP_SET_SAMPLE_RATE,
32+
RTLSDR_RPC_OP_GET_SAMPLE_RATE,
33+
RTLSDR_RPC_OP_SET_TESTMODE,
34+
RTLSDR_RPC_OP_SET_AGC_MODE,
35+
RTLSDR_RPC_OP_SET_DIRECT_SAMPLING,
36+
RTLSDR_RPC_OP_GET_DIRECT_SAMPLING,
37+
RTLSDR_RPC_OP_SET_OFFSET_TUNING,
38+
RTLSDR_RPC_OP_GET_OFFSET_TUNING,
39+
RTLSDR_RPC_OP_RESET_BUFFER,
40+
RTLSDR_RPC_OP_READ_SYNC,
41+
RTLSDR_RPC_OP_WAIT_ASYNC,
42+
RTLSDR_RPC_OP_READ_ASYNC,
43+
RTLSDR_RPC_OP_CANCEL_ASYNC,
44+
45+
/* non api operations */
46+
RTLSDR_RPC_OP_EVENT_STATE,
47+
48+
RTLSDR_RPC_OP_INVALID
49+
} rtlsdr_rpc_op_t;
50+
51+
typedef struct
52+
{
53+
/* raw network format */
54+
uint32_t size;
55+
uint8_t op;
56+
uint8_t id;
57+
uint32_t err;
58+
uint8_t data[1];
59+
} __attribute__((packed)) rtlsdr_rpc_fmt_t;
60+
61+
typedef struct
62+
{
63+
size_t off;
64+
size_t size;
65+
uint8_t* fmt;
66+
} rtlsdr_rpc_msg_t;
67+
68+
int rtlsdr_rpc_msg_init(rtlsdr_rpc_msg_t*, size_t);
69+
int rtlsdr_rpc_msg_fini(rtlsdr_rpc_msg_t*);
70+
void rtlsdr_rpc_msg_reset(rtlsdr_rpc_msg_t*);
71+
int rtlsdr_rpc_msg_realloc(rtlsdr_rpc_msg_t*, size_t);
72+
73+
void rtlsdr_rpc_msg_set_size(rtlsdr_rpc_msg_t*, size_t);
74+
size_t rtlsdr_rpc_msg_get_size(const rtlsdr_rpc_msg_t*);
75+
void rtlsdr_rpc_msg_set_op(rtlsdr_rpc_msg_t*, rtlsdr_rpc_op_t);
76+
rtlsdr_rpc_op_t rtlsdr_rpc_msg_get_op(const rtlsdr_rpc_msg_t*);
77+
void rtlsdr_rpc_msg_set_id(rtlsdr_rpc_msg_t*, uint8_t);
78+
uint8_t rtlsdr_rpc_msg_get_id(const rtlsdr_rpc_msg_t*);
79+
void rtlsdr_rpc_msg_set_err(rtlsdr_rpc_msg_t*, int);
80+
int rtlsdr_rpc_msg_get_err(const rtlsdr_rpc_msg_t*);
81+
82+
int rtlsdr_rpc_msg_push_int32(rtlsdr_rpc_msg_t*, int32_t);
83+
int rtlsdr_rpc_msg_push_uint32(rtlsdr_rpc_msg_t*, uint32_t);
84+
void rtlsdr_rpc_msg_push_uint32_safe(rtlsdr_rpc_msg_t*, uint32_t);
85+
int rtlsdr_rpc_msg_push_str(rtlsdr_rpc_msg_t*, const char*);
86+
int rtlsdr_rpc_msg_push_buf(rtlsdr_rpc_msg_t*, const uint8_t*, size_t);
87+
void rtlsdr_rpc_msg_skip_safe(rtlsdr_rpc_msg_t*, size_t);
88+
int rtlsdr_rpc_msg_pop_int32(rtlsdr_rpc_msg_t*, int32_t*);
89+
int rtlsdr_rpc_msg_pop_uint32(rtlsdr_rpc_msg_t*, uint32_t*);
90+
int rtlsdr_rpc_msg_pop_str(rtlsdr_rpc_msg_t*, const char**);
91+
int rtlsdr_rpc_msg_pop_buf(rtlsdr_rpc_msg_t*, const uint8_t**, size_t*);
92+
93+
94+
#endif /* RTLSDR_RPC_MSG_H_INCLUDED */

src/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ RTLSDR_APPEND_SRCS(
2828
tuner_fc0013.c
2929
tuner_fc2580.c
3030
tuner_r82xx.c
31+
rtlsdr_rpc.c
32+
rtlsdr_rpc_msg.c
3133
)
3234

3335
########################################################################
@@ -92,7 +94,8 @@ add_executable(rtl_ir rtl_ir.c)
9294
add_executable(rtl_eeprom rtl_eeprom.c)
9395
add_executable(rtl_adsb rtl_adsb.c)
9496
add_executable(rtl_power rtl_power.c)
95-
set(INSTALL_TARGETS rtlsdr_shared rtlsdr_static rtl_sdr rtl_tcp rtl_test rtl_fm rtl_ir rtl_eeprom rtl_adsb rtl_power)
97+
add_executable(rtl_rpcd rtl_rpcd.c rtlsdr_rpc_msg.c)
98+
set(INSTALL_TARGETS rtlsdr_shared rtlsdr_static rtl_sdr rtl_tcp rtl_test rtl_fm rtl_ir rtl_eeprom rtl_adsb rtl_power rtl_rpcd)
9699

97100
target_link_libraries(rtl_sdr rtlsdr_shared convenience_static
98101
${LIBUSB_LIBRARIES}
@@ -126,6 +129,10 @@ target_link_libraries(rtl_power rtlsdr_shared convenience_static
126129
${LIBUSB_LIBRARIES}
127130
${CMAKE_THREAD_LIBS_INIT}
128131
)
132+
target_link_libraries(rtl_rpcd rtlsdr_shared convenience_static
133+
${LIBUSB_LIBRARIES}
134+
${CMAKE_THREAD_LIBS_INIT}
135+
)
129136
if(UNIX)
130137
target_link_libraries(rtl_fm m)
131138
target_link_libraries(rtl_ir m)
@@ -147,6 +154,7 @@ target_link_libraries(rtl_ir libgetopt_static)
147154
target_link_libraries(rtl_eeprom libgetopt_static)
148155
target_link_libraries(rtl_adsb libgetopt_static)
149156
target_link_libraries(rtl_power libgetopt_static)
157+
target_link_libraries(rtl_rpcd ws2_32 libgetopt_static)
150158
set_property(TARGET rtl_sdr APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
151159
set_property(TARGET rtl_tcp APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
152160
set_property(TARGET rtl_test APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
@@ -155,6 +163,7 @@ set_property(TARGET rtl_ir APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
155163
set_property(TARGET rtl_eeprom APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
156164
set_property(TARGET rtl_adsb APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
157165
set_property(TARGET rtl_power APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
166+
set_property(TARGET rtl_rpcd APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
158167
endif()
159168
########################################################################
160169
# Install built library files & utilities

src/Makefile.am

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ AM_CFLAGS = ${CFLAGS} -fPIC ${SYMBOL_VISIBILITY}
99

1010
lib_LTLIBRARIES = librtlsdr.la
1111

12-
librtlsdr_la_SOURCES = librtlsdr.c tuner_e4k.c tuner_fc0012.c tuner_fc0013.c tuner_fc2580.c tuner_r82xx.c
12+
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
1313
librtlsdr_la_LDFLAGS = -version-info $(LIBVERSION)
1414

15-
bin_PROGRAMS = rtl_sdr rtl_tcp rtl_test rtl_fm rtl_ir rtl_eeprom rtl_adsb rtl_power
15+
bin_PROGRAMS = rtl_sdr rtl_tcp rtl_test rtl_fm rtl_ir rtl_eeprom rtl_adsb rtl_power rtl_rpcd
1616

1717
rtl_sdr_SOURCES = rtl_sdr.c convenience/convenience.c
1818
rtl_sdr_LDADD = librtlsdr.la
@@ -37,3 +37,6 @@ rtl_adsb_LDADD = librtlsdr.la $(LIBM)
3737

3838
rtl_power_SOURCES = rtl_power.c convenience/convenience.c
3939
rtl_power_LDADD = librtlsdr.la $(LIBM)
40+
41+
rtl_rpcd_SOURCES = rtl_rpcd.c rtlsdr_rpc_msg.c convenience/convenience.c
42+
rtl_rpcd_LDADD = librtlsdr.la

0 commit comments

Comments
 (0)