summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2015-10-09 23:11:31 +0100
committerFreeArtMan <dos21h@gmail.com>2015-10-09 23:11:31 +0100
commita58b75e38a7ec3ea48ccc6edcd8d8c0e135518b4 (patch)
tree4f506b096cd5166ceb9b9227a04a9e7b83a3f36f /test
parent54ac5a3d36b5fd68339a7f4753d862fd21af9389 (diff)
downloadradiola-a58b75e38a7ec3ea48ccc6edcd8d8c0e135518b4.tar.gz
radiola-a58b75e38a7ec3ea48ccc6edcd8d8c0e135518b4.zip
Moved dongle functionality to sdr_t from waterfall test examples
Diffstat (limited to 'test')
-rw-r--r--test/ui_gl_waterfall.c101
-rw-r--r--test/ui_tui_waterfall.c101
2 files changed, 39 insertions, 163 deletions
diff --git a/test/ui_gl_waterfall.c b/test/ui_gl_waterfall.c
index 733f932..85a2866 100644
--- a/test/ui_gl_waterfall.c
+++ b/test/ui_gl_waterfall.c
@@ -5,6 +5,7 @@
//radiola
#include <draw/glui.h>
#include <hw/hw.h>
+#include <hw/sdr.h>
#define SAMPLE_RATE 2048000
@@ -15,89 +16,11 @@
#define PRESCALE 8
#define POSTSCALE 2
-static rtlsdr_dev_t *dev = NULL;
-
int16_t* Sinewave;
int N_WAVE, LOG2_N_WAVE;
double* power_table;
-int dng_init()
-{
- int ret;
- uint32_t dev_index = 0;
-
- //open tunner
- ret = rtlsdr_open(&dev, (uint32_t)dev_index);
- if ( ret < 0 )
- {
- printf("Cannot open device %02d\n", dev_index );
- return -1;
- }
-
- ret = rtlsdr_reset_buffer(dev);
- if ( ret < 0 )
- {
- printf("Couldnt reset buffer\n");
- return -1;
- }
-
- ret = rtlsdr_set_sample_rate(dev, SAMPLE_RATE);
- if ( ret < 0 )
- {
- printf("Coulnt set sample rate to %d\n", SAMPLE_RATE);
- return -1;
- }
-
- ret = rtlsdr_set_center_freq( dev, CENTER_FREQ );
- if ( ret < 0 )
- {
- printf("Couldnt set freq %d\n", CENTER_FREQ);
- return -1;
- }
- ret = rtlsdr_set_tuner_gain_mode( dev, 1 );
- if ( ret < 0 )
- {
- printf("Cannot set auto gain mode\n");
- return -1;
- }
-
- ret = rtlsdr_set_agc_mode( dev, 1);
- if ( ret < 0 )
- {
- printf("Cannot set agc mode\n");
- return -1;
- }
-
- return 0;
-}
-
-
-int dng_close()
-{
- //close tunner
- if ( dev != NULL)
- {
- rtlsdr_close( dev );
- dev = NULL;
- return 0;
- }
- return -1;
-}
-
-int dng_get_samples( uint8_t *buf, int len )
-{
- int ret, read_num;
-
- ret = rtlsdr_read_sync( dev, buf, len, &read_num );
- if (ret < 0)
- {
- printf("sync read failed\n");
- return -1;
- }
-
- return 0;
-}
//better to have size size mod olen == 0
int normalise( uint8_t *ibuf, int ilen, uint8_t *obuf, int olen )
@@ -263,14 +186,28 @@ int main()
int buf_len, sample_len;
uint32_t dev_num;
+ sdr_t *sdr = NULL;
+ dongle_t *dongle = NULL;
+
+
glui_t *t = NULL;
glui_waterfall_t *w = NULL;
- if ( dng_init() == -1 )
+ if ( (sdr = sdr_init()) == NULL )
{
+ printf("Cannot init sdr manager\n");
goto main_exit;
}
+ if ( sdr_open_device( sdr, 0 ) != 0 )
+ {
+ printf("Cannot open dongle 0\n");
+ goto main_exit;
+ }
+ dongle = sdr_get_device_id( sdr, 0 );
+ dongle_set_freq( dongle, CENTER_FREQ );
+ dongle_set_sample_rate( dongle, SAMPLE_RATE );
+
sine_table( FFT_LEVEL );
@@ -289,12 +226,14 @@ int main()
return 1;
}
+ /*
dev_num = rtlsdr_get_device_count();
if ( dev_num < 1 )
{
printf( "Cannot find any device" );
goto main_exit;
}
+ */
//screen normilised buffer to draw
buf_len = sizeof(char)*w->w;
@@ -310,7 +249,7 @@ int main()
// sample_buf[j] = (uint8_t)((rand()&0xff));
//read some samples
- dng_get_samples( sample_buf, sample_len );
+ dongle_read_samples( dongle, sample_buf, sample_len );
//do fft
simple_fft( sample_buf, sample_len );
@@ -328,7 +267,7 @@ int main()
main_exit:
//close gui, restore terminal mode
glui_close( t );
- dng_close();
+ sdr_close( sdr );
return 0;
} \ No newline at end of file
diff --git a/test/ui_tui_waterfall.c b/test/ui_tui_waterfall.c
index 6a8a3f8..c322670 100644
--- a/test/ui_tui_waterfall.c
+++ b/test/ui_tui_waterfall.c
@@ -6,6 +6,7 @@
//radiola
#include <draw/tui.h>
#include <hw/hw.h>
+#include <hw/sdr.h>
#define SAMPLE_RATE 2048000
@@ -16,90 +17,11 @@
#define PRESCALE 8
#define POSTSCALE 2
-static rtlsdr_dev_t *dev = NULL;
int16_t* Sinewave;
int N_WAVE, LOG2_N_WAVE;
double* power_table;
-int dng_init()
-{
- int ret;
- uint32_t dev_index = 0;
-
- //open tunner
- ret = rtlsdr_open(&dev, (uint32_t)dev_index);
- if ( ret < 0 )
- {
- printf("Cannot open device %02d\n", dev_index );
- return -1;
- }
-
- ret = rtlsdr_reset_buffer(dev);
- if ( ret < 0 )
- {
- printf("Couldnt reset buffer\n");
- return -1;
- }
-
- ret = rtlsdr_set_sample_rate(dev, SAMPLE_RATE);
- if ( ret < 0 )
- {
- printf("Coulnt set sample rate to %d\n", SAMPLE_RATE);
- return -1;
- }
-
- ret = rtlsdr_set_center_freq( dev, CENTER_FREQ );
- if ( ret < 0 )
- {
- printf("Couldnt set freq %d\n", CENTER_FREQ);
- return -1;
- }
-
- ret = rtlsdr_set_tuner_gain_mode( dev, 1 );
- if ( ret < 0 )
- {
- printf("Cannot set auto gain mode\n");
- return -1;
- }
-
- ret = rtlsdr_set_agc_mode( dev, 1);
- if ( ret < 0 )
- {
- printf("Cannot set agc mode\n");
- return -1;
- }
-
- return 0;
-}
-
-
-int dng_close()
-{
- //close tunner
- if ( dev != NULL)
- {
- rtlsdr_close( dev );
- dev = NULL;
- return 0;
- }
- return -1;
-}
-
-int dng_get_samples( uint8_t *buf, int len )
-{
- int ret, read_num;
-
- ret = rtlsdr_read_sync( dev, buf, len, &read_num );
- if (ret < 0)
- {
- printf("sync read failed\n");
- return -1;
- }
-
- return 0;
-}
-
//better to have size size mod olen == 0
int normalise( uint8_t *ibuf, int ilen, uint8_t *obuf, int olen )
{
@@ -262,13 +184,26 @@ int main()
int buf_len, sample_len;
uint32_t dev_num;
+ sdr_t *sdr = NULL;
+ dongle_t *dongle = NULL;
+
tui_t *t = NULL;
tui_waterfall_t *w = NULL;
- if ( dng_init() == -1 )
+ if ( (sdr = sdr_init()) == NULL )
+ {
+ printf("Cannot init sdr manager\n");
+ goto main_exit;
+ }
+
+ if ( sdr_open_device( sdr, 0 ) != 0 )
{
+ printf("Cannot open dongle 0\n");
goto main_exit;
}
+ dongle = sdr_get_device_id( sdr, 0 );
+ dongle_set_freq( dongle, CENTER_FREQ );
+ dongle_set_sample_rate( dongle, SAMPLE_RATE );
sine_table( FFT_LEVEL );
@@ -294,12 +229,14 @@ int main()
return -1;
}
+ /*
dev_num = rtlsdr_get_device_count();
if ( dev_num < 1 )
{
printf( "Cannot find any device" );
goto main_exit;
}
+ */
@@ -316,7 +253,7 @@ int main()
// sample_buf[j] = (uint8_t)((rand()&0xff));
//read some samples
- dng_get_samples( sample_buf, sample_len );
+ dongle_read_samples( dongle, sample_buf, sample_len );
//do fft
simple_fft( sample_buf, sample_len );
@@ -335,7 +272,7 @@ int main()
main_exit:
//close gui, restore terminal mode
tui_close( t );
- dng_close();
+ sdr_close( sdr );
return 0;
}