Add center freq cli opt

This commit is contained in:
Jared Szechy 2021-01-17 19:37:00 -05:00
parent f0f067510f
commit 5324d53c47
3 changed files with 70 additions and 18 deletions

View File

@ -67,7 +67,6 @@
*/
static volatile int exitflag;
typedef struct
{
int onesymbol;
@ -89,9 +88,7 @@ typedef struct
#ifdef USE_PORTAUDIO
PaStream* audio_in_pa_stream;
#endif
#ifdef USE_RTLSDR
rtlsdr_dev_t *rtlSdrDev;
#endif
uint32_t rtlsdr_center_freq;
int audio_in_type; // 0 for device, 1 for file, 2 for portaudio, 3 for rtlsdr
char audio_out_dev[1024];
int audio_out_fd;
@ -324,10 +321,15 @@ void processDSTAR_HD (dsd_opts * opts, dsd_state * state);
short dmr_filter(short sample);
short nxdn_filter(short sample);
void open_rtlsdr_stream();
#ifdef __cplusplus
extern "C" {
#endif
void open_rtlsdr_stream(dsd_opts *opts);
void cleanup_rtlsdr_stream();
void get_rtlsdr_sample();
void get_rtlsdr_sample(int16_t *sample);
void rtlsdr_sighandler();
#ifdef __cplusplus
}
#endif
#endif // DSD_H

View File

@ -274,6 +274,7 @@ usage ()
printf (" -n Do not send synthesized speech to audio output device\n");
printf (" -w <file> Output synthesized speech to a .wav file\n");
printf (" -a Display port audio devices\n");
printf (" -c <hertz> RTL-SDR center frequency\n");
printf ("\n");
printf ("Scanner control options:\n");
printf (" -B <num> Serial port baud rate (default=115200)\n");
@ -331,7 +332,7 @@ liveScanner (dsd_opts * opts, dsd_state * state)
#ifdef USE_RTLSDR
if(opts->audio_in_type == 3)
{
open_rtlsdr_stream();
open_rtlsdr_stream(opts);
}
#endif
while (1)
@ -466,6 +467,32 @@ sigfun (int sig)
#endif
}
double atofs(char *s)
{
char last;
int len;
double suff = 1.0;
len = strlen(s);
last = s[len-1];
s[len-1] = '\0';
switch (last) {
case 'g':
case 'G':
suff *= 1e3;
case 'm':
case 'M':
suff *= 1e3;
case 'k':
case 'K':
suff *= 1e3;
suff *= atof(s);
s[len-1] = last;
return suff;
}
s[len-1] = last;
return atof(s);
}
int
main (int argc, char **argv)
{
@ -486,7 +513,7 @@ main (int argc, char **argv)
exitflag = 0;
signal (SIGINT, sigfun);
while ((c = getopt (argc, argv, "haep:qstv:z:i:o:d:g:nw:B:C:R:f:m:u:x:A:S:M:rl")) != -1)
while ((c = getopt (argc, argv, "haep:qstv:z:i:o:d:c:g:nw:B:C:R:f:m:u:x:A:S:M:rl")) != -1)
{
opterr = 0;
switch (c)
@ -568,6 +595,10 @@ main (int argc, char **argv)
opts.mbe_out_dir[1023] = '\0';
printf ("Writing mbe data files to directory %s\n", opts.mbe_out_dir);
break;
case 'c':
opts.rtlsdr_center_freq = (uint32_t)atofs(optarg);
printf("Using center freq: %i\n", opts.rtlsdr_center_freq);
break;
case 'g':
sscanf (optarg, "%f", &opts.audio_gain);
if (opts.audio_gain < (float) 0 )

View File

@ -29,6 +29,7 @@
#include <unistd.h>
#include <queue>
#include <rtl-sdr.h>
#include "dsd.h"
#define DEFAULT_SAMPLE_RATE 48000
#define DEFAULT_BUF_LENGTH (1 * 16384)
@ -39,10 +40,6 @@
#define FREQUENCIES_LIMIT 1000
extern "C" {
volatile int exitflag;
}
static int lcm_post[17] = {1,1,1,3,1,5,3,7,1,9,5,11,3,13,7,15,1};
static int ACTUAL_BUF_LENGTH;
@ -850,7 +847,7 @@ void output_cleanup(struct output_state *s)
void controller_init(struct controller_state *s)
{
s->freqs[0] = 451800000;
s->freqs[0] = 446000000;
s->freq_len = 0;
s->edge = 0;
s->wb_mode = 0;
@ -864,14 +861,32 @@ void controller_cleanup(struct controller_state *s)
pthread_mutex_destroy(&s->hop_m);
}
extern "C" {
void sanity_checks(void)
{
if (controller.freq_len == 0) {
fprintf(stderr, "Please specify a frequency.\n");
exit(1);
}
if (controller.freq_len >= FREQUENCIES_LIMIT) {
fprintf(stderr, "Too many channels, maximum %i.\n", FREQUENCIES_LIMIT);
exit(1);
}
if (controller.freq_len > 1 && demod.squelch_level == 0) {
fprintf(stderr, "Please specify a squelch level. Required for scanning multiple frequencies.\n");
exit(1);
}
}
void rtlsdr_sighandler()
{
fprintf(stderr, "Signal caught, exiting!\n");
rtlsdr_cancel_async(dongle.dev);
}
void open_rtlsdr_stream()
void open_rtlsdr_stream(dsd_opts *opts)
{
struct sigaction sigact;
int r;
@ -881,12 +896,17 @@ void open_rtlsdr_stream()
output_init(&output);
controller_init(&controller);
if (opts->rtlsdr_center_freq > 0) {
controller.freqs[controller.freq_len] = opts->rtlsdr_center_freq;
controller.freq_len++;
}
/* quadruple sample_rate to limit to Δθ to ±π/2 */
demod.rate_in *= demod.post_downsample;
if (!output.rate) output.rate = demod.rate_out;
// sanity_checks();
sanity_checks();
if (controller.freq_len > 1) demod.terminate_on_squelch = 0;
@ -960,4 +980,3 @@ void get_rtlsdr_sample(int16_t *sample)
output.queue.pop();
pthread_rwlock_unlock(&output.rw);
}
}