mirror of
https://github.com/rtlsdrblog/rtl-sdr-blog.git
synced 2025-02-05 14:54:58 +01:00
make win32 build actually work
Signed-off-by: Steve Markgraf <steve@steve-m.de>
This commit is contained in:
parent
65ac467941
commit
0bc846c34c
@ -47,7 +47,7 @@ target_link_libraries(rtlsdr_static
|
|||||||
${LIBUSB_LIBRARIES}
|
${LIBUSB_LIBRARIES}
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties(rtlsdr_static PROPERTIES DEFINE_SYMBOL "rtlsdr_STATIC")
|
set_property(TARGET rtlsdr_static APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
|
||||||
|
|
||||||
if(NOT WIN32)
|
if(NOT WIN32)
|
||||||
# Force same library filename for static and shared variants of the library
|
# Force same library filename for static and shared variants of the library
|
||||||
@ -63,6 +63,9 @@ target_link_libraries(rtl_sdr rtlsdr_static
|
|||||||
${CMAKE_THREAD_LIBS_INIT}
|
${CMAKE_THREAD_LIBS_INIT}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
set_property(TARGET rtl_sdr APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
|
||||||
|
endif()
|
||||||
########################################################################
|
########################################################################
|
||||||
# Install built library files & utilities
|
# Install built library files & utilities
|
||||||
########################################################################
|
########################################################################
|
||||||
|
42
src/main.c
42
src/main.c
@ -22,7 +22,12 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#else
|
||||||
|
#include <Windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "rtl-sdr.h"
|
#include "rtl-sdr.h"
|
||||||
|
|
||||||
@ -37,6 +42,11 @@ static rtlsdr_dev_t *dev = NULL;
|
|||||||
|
|
||||||
void usage(void)
|
void usage(void)
|
||||||
{
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
fprintf(stderr,"rtl-sdr, an I/Q recorder for RTL2832 based USB-sticks\n\n"
|
||||||
|
"Usage:\t rtl-sdr-win.exe [device_index] [samplerate in kHz] "
|
||||||
|
"[gain] [frequency in hz] [filename]\n");
|
||||||
|
#else
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"rtl-sdr, an I/Q recorder for RTL2832 based DVB-T receivers\n\n"
|
"rtl-sdr, an I/Q recorder for RTL2832 based DVB-T receivers\n\n"
|
||||||
"Usage:\t -f frequency_to_tune_to [Hz]\n"
|
"Usage:\t -f frequency_to_tune_to [Hz]\n"
|
||||||
@ -46,11 +56,18 @@ void usage(void)
|
|||||||
"\t[-b output_block_size (default: 16 * 16384)]\n"
|
"\t[-b output_block_size (default: 16 * 16384)]\n"
|
||||||
"\t[-S force sync output (default: async)]\n"
|
"\t[-S force sync output (default: async)]\n"
|
||||||
"\toutput_filename (a '-' dumps samples to stdout)\n\n");
|
"\toutput_filename (a '-' dumps samples to stdout)\n\n");
|
||||||
|
#endif
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sighandler(int signum)
|
#ifdef _WIN32
|
||||||
|
BOOL WINAPI
|
||||||
|
#else
|
||||||
|
static void
|
||||||
|
#endif
|
||||||
|
sighandler(int signum)
|
||||||
{
|
{
|
||||||
|
fprintf(stderr, "Signal caught, exiting!\n");
|
||||||
do_exit = 1;
|
do_exit = 1;
|
||||||
rtlsdr_cancel_async(dev);
|
rtlsdr_cancel_async(dev);
|
||||||
}
|
}
|
||||||
@ -67,7 +84,9 @@ static void rtlsdr_callback(unsigned char *buf, uint32_t len, void *ctx)
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
#ifndef _WIN32
|
||||||
struct sigaction sigact;
|
struct sigaction sigact;
|
||||||
|
#endif
|
||||||
char *filename = NULL;
|
char *filename = NULL;
|
||||||
int n_read;
|
int n_read;
|
||||||
int r, opt;
|
int r, opt;
|
||||||
@ -79,7 +98,8 @@ int main(int argc, char **argv)
|
|||||||
uint32_t frequency = 0;
|
uint32_t frequency = 0;
|
||||||
uint32_t samp_rate = DEFAULT_SAMPLE_RATE;
|
uint32_t samp_rate = DEFAULT_SAMPLE_RATE;
|
||||||
uint32_t out_block_size = DEFAULT_BUF_LENGTH;
|
uint32_t out_block_size = DEFAULT_BUF_LENGTH;
|
||||||
|
int device_count;
|
||||||
|
#ifndef _WIN32
|
||||||
while ((opt = getopt(argc, argv, "d:f:g:s:b:S::")) != -1) {
|
while ((opt = getopt(argc, argv, "d:f:g:s:b:S::")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'd':
|
case 'd':
|
||||||
@ -111,7 +131,15 @@ int main(int argc, char **argv)
|
|||||||
} else {
|
} else {
|
||||||
filename = argv[optind];
|
filename = argv[optind];
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
if(argc <5)
|
||||||
|
usage();
|
||||||
|
dev_index = atoi(argv[1]);
|
||||||
|
samp_rate = atoi(argv[2])*1000;
|
||||||
|
gain=atoi(argv[3]);
|
||||||
|
frequency = atoi(argv[4]);
|
||||||
|
filename = argv[5];
|
||||||
|
#endif
|
||||||
if(out_block_size < MINIMAL_BUF_LENGTH ||
|
if(out_block_size < MINIMAL_BUF_LENGTH ||
|
||||||
out_block_size > MAXIMAL_BUF_LENGTH ){
|
out_block_size > MAXIMAL_BUF_LENGTH ){
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
@ -125,7 +153,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
buffer = malloc(out_block_size * sizeof(uint8_t));
|
buffer = malloc(out_block_size * sizeof(uint8_t));
|
||||||
|
|
||||||
int device_count = rtlsdr_get_device_count();
|
device_count = rtlsdr_get_device_count();
|
||||||
if (!device_count) {
|
if (!device_count) {
|
||||||
fprintf(stderr, "No supported devices found.\n");
|
fprintf(stderr, "No supported devices found.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -145,7 +173,7 @@ int main(int argc, char **argv)
|
|||||||
fprintf(stderr, "Failed to open rtlsdr device #%d.\n", dev_index);
|
fprintf(stderr, "Failed to open rtlsdr device #%d.\n", dev_index);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
#ifndef _WIN32
|
||||||
sigact.sa_handler = sighandler;
|
sigact.sa_handler = sighandler;
|
||||||
sigemptyset(&sigact.sa_mask);
|
sigemptyset(&sigact.sa_mask);
|
||||||
sigact.sa_flags = 0;
|
sigact.sa_flags = 0;
|
||||||
@ -153,7 +181,9 @@ int main(int argc, char **argv)
|
|||||||
sigaction(SIGTERM, &sigact, NULL);
|
sigaction(SIGTERM, &sigact, NULL);
|
||||||
sigaction(SIGQUIT, &sigact, NULL);
|
sigaction(SIGQUIT, &sigact, NULL);
|
||||||
sigaction(SIGPIPE, &sigact, NULL);
|
sigaction(SIGPIPE, &sigact, NULL);
|
||||||
|
#else
|
||||||
|
SetConsoleCtrlHandler( (PHANDLER_ROUTINE) sighandler, TRUE );
|
||||||
|
#endif
|
||||||
/* Set the sample rate */
|
/* Set the sample rate */
|
||||||
r = rtlsdr_set_sample_rate(dev, samp_rate);
|
r = rtlsdr_set_sample_rate(dev, samp_rate);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user