aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2015-10-09 21:32:37 +0100
committerFreeArtMan <dos21h@gmail.com>2015-10-09 21:32:37 +0100
commit54ac5a3d36b5fd68339a7f4753d862fd21af9389 (patch)
tree33b0c89c6e0acffdeae6413602787619f9337896
parent66c15af1113de0e864c5286ea255142b2cd53aca (diff)
downloadradiola-54ac5a3d36b5fd68339a7f4753d862fd21af9389.tar.gz
radiola-54ac5a3d36b5fd68339a7f4753d862fd21af9389.zip
Added dongle manager
-rw-r--r--hw/sdr.c298
-rw-r--r--hw/sdr.h66
-rw-r--r--test/.gitignore2
-rw-r--r--test/ui_gl_filter.c6
-rw-r--r--test/ui_gl_fm.c6
-rw-r--r--test/ui_gl_waterfall.c12
-rw-r--r--test/ui_tui_waterfall.c12
7 files changed, 375 insertions, 27 deletions
diff --git a/hw/sdr.c b/hw/sdr.c
index 05084b2..13f28c2 100644
--- a/hw/sdr.c
+++ b/hw/sdr.c
@@ -1 +1,297 @@
-#include "sdr.h" \ No newline at end of file
+#include "sdr.h"
+
+sdr_t* sdr_init()
+{
+ sdr_t *sdr=NULL;
+
+ sdr = malloc( sizeof(sdr_t) );
+ if (sdr == NULL)
+ return NULL;
+
+ memset( sdr, 0, sizeof(sdr_t) );
+
+ return sdr;
+}
+
+
+//index of device in oter list
+//return inner device list
+int sdr_open_device( sdr_t *sdr, int dev_index )
+{
+ int ret;
+ dongle_t *dng=NULL;
+ rtlsdr_dev_t *rtl=NULL;
+
+ //for now only one device will be supported
+ if (sdr == NULL)
+ return -1;
+
+ if (sdr->dongle != NULL)
+ return -1;
+
+ dng = malloc(sizeof(dongle_t));
+ memset(dng, 0, sizeof(dongle_t));
+ //set default values for dongle_t
+ DEF_DONGLE_VALUES(dng);
+
+ ret = hw_open( &rtl, (uint32_t)dev_index );
+ if ( ret < 0 )
+ {
+ printf("Cannot open device %02d\n", dev_index );
+ goto exit_dng_err;
+ }
+
+ ret = hw_reset_buffer( rtl );
+ if ( ret < 0 )
+ {
+ printf("Couldnt reset buffer\n");
+ goto exit_dng_err;
+ }
+
+ ret = hw_set_sample_rate( rtl, dng->rate );
+ if ( ret < 0 )
+ {
+ printf("Couldnt set sample rate to %d\n", dng->rate);
+ goto exit_dng_err;
+ }
+
+ ret = hw_set_center_freq( rtl, dng->freq );
+ if ( ret < 0 )
+ {
+ printf("Couldnt set frequency %d\n", dng->freq );
+ goto exit_dng_err;
+ }
+
+ ret = hw_set_tuner_gain_mode( rtl, dng->gain );
+ if ( ret < 0 )
+ {
+ printf("Cannot set autogain mode\n");
+ goto exit_dng_err;
+ }
+
+ ret = hw_set_agc_mode( rtl, 1 );
+ if ( ret < 0 )
+ {
+ printf("Cannot set agc mode\n");
+ goto exit_dng_err;
+ }
+
+ dng->dev_index = dev_index;
+ dng->dev = rtl;
+ sdr->dongle = dng;
+
+ return 0;
+
+exit_dng_err:
+ free( dng );
+
+ return -1;
+}
+
+
+//associate audio device that going to be used
+//int sdr_open_audio( sdr_t *sdr, int dev_index );//?should be just device from list or device name?
+
+
+//get device structure from sdr manager by pluged device num
+//dont try to free it muahaha
+dongle_t* sdr_get_device_id( sdr_t *sdr, int dev_index)
+{
+ dongle_t *dng=NULL;
+
+ if ( sdr == NULL )
+ return NULL;
+
+ if (sdr->dongle == NULL)
+ return NULL;
+
+ if (sdr->dongle->dev_index != dev_index)
+ {
+ printf("Cannot find device with such device ID\n");
+ return NULL;
+ }
+
+ return sdr->dongle;
+}
+
+
+
+//get index in list of devices of structure from outer device index
+//? do we need?
+//int sdr_get_dongle_idx( sdr_t *sdr, int idx );
+//close device by internal list index
+int sdr_close_device( sdr_t *sdr, int dev_index )
+{
+ if ( sdr == NULL )
+ return -1;
+
+ if ( sdr->dongle == NULL )
+ {
+ return -1;
+ }
+
+ if ( sdr->dongle->dev == NULL )
+ return -1;
+
+ if ( sdr->dongle->dev_index != dev_index )
+ return -1;
+
+ hw_close( sdr->dongle->dev );
+ free( sdr->dongle->dev );
+ sdr->dongle->dev = NULL;
+
+ free( sdr->dongle );
+ sdr->dongle = NULL;
+
+ return 0;
+}
+
+
+
+//close sdr
+//if there is opened audios then close
+//if there is opened devices then close
+int sdr_close( sdr_t *sdr )
+{
+ if ( sdr != NULL )
+ {
+ if ( sdr->dongle != NULL )
+ {
+ if ( sdr->dongle->dev == NULL )
+ {
+ hw_close( sdr->dongle->dev );
+ free( sdr->dongle->dev );
+ sdr->dongle->dev = NULL;
+ }
+ free( sdr->dongle );
+ sdr->dongle = NULL;
+ }
+ free(sdr);
+ sdr = NULL;
+ return 0;
+ }
+ return -1;
+}
+
+
+
+//stop any action that associated with dongle
+//not yet implemented
+int dongle_stop( dongle_t *dongle )
+{
+ return -1;
+}
+
+
+//int dongle_open( sdr_t *);
+//set dongle frequency
+int dongle_set_freq( dongle_t *dongle, uint32_t freq)
+{
+ int ret = 0;
+ if ( dongle == NULL )
+ return -1;
+
+ if ( dongle->dev == NULL )
+ return -1;
+
+ ret = hw_set_center_freq( dongle->dev, freq );
+ if ( ret < 0 )
+ {
+ printf("Cannot set device frequency to %ud\n", freq);
+ return -1;
+ }
+
+ return 0;
+}
+
+
+//set gain
+int dongle_set_gain( dongle_t *dongle, int gain)
+{
+
+ int ret;
+
+ if ( dongle == NULL )
+ return -1;
+
+ if ( dongle->dev == NULL )
+ return -1;
+
+ ret = hw_set_tuner_gain_mode( dongle->dev, gain );
+ if ( ret < 0 )
+ {
+ printf("Cannot set tunner gain level %d\n", gain );
+ return -1;
+ }
+
+ return 0;
+}
+
+
+//set dongle sample rate
+int dongle_set_sample_rate( dongle_t *dongle, uint32_t rate )
+{
+ int ret;
+
+ if ( dongle == NULL )
+ {
+ return -1;
+ }
+
+ if ( dongle->dev == NULL )
+ return -1;
+
+ ret = hw_set_sample_rate( dongle->dev, rate );
+ if ( ret < 0 )
+ {
+ printf("Cannot set sample rate %ud\n", rate);
+ return -1;
+ }
+
+ return 0;
+}
+
+int dongle_set_agc( dongle_t *dongle, int mode)
+{
+ int ret;
+
+ if ( dongle == NULL )
+ return -1;
+
+ if ( dongle->dev == NULL )
+ return -1;
+
+ //need mode check things
+ ret = hw_set_agc_mode( dongle->dev, mode );
+ if ( ret < 0 )
+ {
+ printf("Cannot set agc gain mode\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+
+uint32_t dongle_get_freq( dongle_t *dongle )
+{
+ return dongle->freq;
+}
+
+
+int dongle_get_gain( dongle_t *dongle )
+{
+ return dongle->gain;
+}
+
+
+uint32_t dongle_get_sample_rate( dongle_t *dongle )
+{
+ return dongle->rate;
+}
+
+
+int dongle_read_samples( dongle_t *dongle, uint8_t *buf, int len )
+{
+ return -1;
+} \ No newline at end of file
diff --git a/hw/sdr.h b/hw/sdr.h
index 81ec57f..5a83e8e 100644
--- a/hw/sdr.h
+++ b/hw/sdr.h
@@ -1,8 +1,15 @@
#ifndef __RADIOLA_HW_SDR_H
#define __RADIOLA_HW_SDR_H
+#include <string.h>
+
#include "hw.h"
+
+//list of supported devices RTLSDR is rtlsdr tunners,
+//AUDIO is just used audio cards
+//NET get or send some info to server/client
+//PTT usb connected with audio link radios, trought PTT things
typedef enum
{
DEVICE_NONE=0,
@@ -22,6 +29,18 @@ typedef struct dongle_t
int gain;
} dongle_t;
+#define DONGLE_SAMPLE_RATE 2048000
+#define DONGLE_CENTER_FREQ 100000000
+#define DONGLE_GAIN 1
+
+//dongle pointer to dongle_t
+#define DEF_DONGLE_VALUES(DONGLE)\
+{\
+(DONGLE)->freq=DONGLE_CENTER_FREQ;\
+(DONGLE)->rate=DONGLE_SAMPLE_RATE;\
+(DONGLE)->gain=DONGLE_GAIN;\
+}
+
typedef struct audio_t
{
@@ -30,32 +49,51 @@ typedef struct audio_t
typedef struct sdr_t
{
- sdr_device dev_type;
- dongle_t *dongle;
- uint32_t d_used;
- audio_t *audio;
- uint32_t a_used;
+ dongle_t *dongle; //list of rtlsdr devices
+ uint32_t d_used; //not yes used
+ audio_t *audio; //audio devices used
+ uint32_t a_used; //not yet used
} sdr_t;
+//init structure
+
+sdr_t* sdr_init();
//index of device in oter list
//return inner device list
int sdr_open_device( sdr_t *sdr, int dev_index );
+//associate audio device that going to be used
+//int sdr_open_audio( sdr_t *sdr, int dev_index );//?should be just device from list or device name?
+
+
+//get device structure from sdr manager
+dongle_t* sdr_get_device( sdr_t *sdr, int dev_index);
+
//get index in list of devices of structure from outer device index
//? do we need?
//int sdr_get_dongle_idx( sdr_t *sdr, int idx );
//close device by internal list index
int sdr_close_device( sdr_t *sdr, int idx );
-int dongle_stop( sdr_t *sdr, int idx );
+//close sdr
+//if there is opened audios then close
+//if there is opened devices then close
+int sdr_close( sdr_t *sdr );
+
+//stop any action that associated with dongle
+int dongle_stop( dongle_t *dongle );
//int dongle_open( sdr_t *);
-int dongle_set_freq( sdr_t *sdr, int idx, uint32_t freq);
-int dongle_set_gain( sdr_t *sdr, int idx, int gain);
-int dongle_set_sample_rate( sdr_t *sdr, int idx, uint32_t srate );
-
-uint32_t dongle_get_freq( sdr_t *sdr, int idx );
-int dongle_get_gain( sdr_t *sdr, int idx);
-uint32_t dongle_get_sample_rate( sdr_t *sdr, int idx );
-int dongle_get_samples( sdr_t *sdr, int idx, uint8_t *buf, int len );
+//set dongle frequency
+int dongle_set_freq( dongle_t *dongle, uint32_t freq);
+//set gain
+int dongle_set_gain( dongle_t *dongle, int gain);
+int dongle_set_agc( dongle_t *dongle, int mode);
+//set dongle sample rate
+int dongle_set_sample_rate( dongle_t *dongle, uint32_t rate );
+
+uint32_t dongle_get_freq( dongle_t *dongle );
+int dongle_get_gain( dongle_t *dongle );
+uint32_t dongle_get_sample_rate( dongle_t *dongle );
+int dongle_read_samples( dongle_t *dongle, uint8_t *buf, int len );
//int dongle_close();
#endif \ No newline at end of file
diff --git a/test/.gitignore b/test/.gitignore
index b4557b8..41c1670 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -3,4 +3,6 @@ read_samples
ui_tui_waterfall
ui_gl_waterfall
get_audo_list
+ui_gl_fm
+ui_gl_filter
*.o
diff --git a/test/ui_gl_filter.c b/test/ui_gl_filter.c
new file mode 100644
index 0000000..d9ad053
--- /dev/null
+++ b/test/ui_gl_filter.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+int main()
+{
+ return 0;
+} \ No newline at end of file
diff --git a/test/ui_gl_fm.c b/test/ui_gl_fm.c
new file mode 100644
index 0000000..d9ad053
--- /dev/null
+++ b/test/ui_gl_fm.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+int main()
+{
+ return 0;
+} \ No newline at end of file
diff --git a/test/ui_gl_waterfall.c b/test/ui_gl_waterfall.c
index 3c19aca..733f932 100644
--- a/test/ui_gl_waterfall.c
+++ b/test/ui_gl_waterfall.c
@@ -21,7 +21,7 @@ int16_t* Sinewave;
int N_WAVE, LOG2_N_WAVE;
double* power_table;
-int sdr_init()
+int dng_init()
{
int ret;
uint32_t dev_index = 0;
@@ -73,7 +73,7 @@ int sdr_init()
}
-int sdr_close()
+int dng_close()
{
//close tunner
if ( dev != NULL)
@@ -85,7 +85,7 @@ int sdr_close()
return -1;
}
-int sdr_get_samples( uint8_t *buf, int len )
+int dng_get_samples( uint8_t *buf, int len )
{
int ret, read_num;
@@ -266,7 +266,7 @@ int main()
glui_t *t = NULL;
glui_waterfall_t *w = NULL;
- if ( sdr_init() == -1 )
+ if ( dng_init() == -1 )
{
goto main_exit;
}
@@ -310,7 +310,7 @@ int main()
// sample_buf[j] = (uint8_t)((rand()&0xff));
//read some samples
- sdr_get_samples( sample_buf, sample_len );
+ dng_get_samples( sample_buf, sample_len );
//do fft
simple_fft( sample_buf, sample_len );
@@ -328,7 +328,7 @@ int main()
main_exit:
//close gui, restore terminal mode
glui_close( t );
- sdr_close();
+ dng_close();
return 0;
} \ No newline at end of file
diff --git a/test/ui_tui_waterfall.c b/test/ui_tui_waterfall.c
index 46445b0..6a8a3f8 100644
--- a/test/ui_tui_waterfall.c
+++ b/test/ui_tui_waterfall.c
@@ -22,7 +22,7 @@ int16_t* Sinewave;
int N_WAVE, LOG2_N_WAVE;
double* power_table;
-int sdr_init()
+int dng_init()
{
int ret;
uint32_t dev_index = 0;
@@ -74,7 +74,7 @@ int sdr_init()
}
-int sdr_close()
+int dng_close()
{
//close tunner
if ( dev != NULL)
@@ -86,7 +86,7 @@ int sdr_close()
return -1;
}
-int sdr_get_samples( uint8_t *buf, int len )
+int dng_get_samples( uint8_t *buf, int len )
{
int ret, read_num;
@@ -265,7 +265,7 @@ int main()
tui_t *t = NULL;
tui_waterfall_t *w = NULL;
- if ( sdr_init() == -1 )
+ if ( dng_init() == -1 )
{
goto main_exit;
}
@@ -316,7 +316,7 @@ int main()
// sample_buf[j] = (uint8_t)((rand()&0xff));
//read some samples
- sdr_get_samples( sample_buf, sample_len );
+ dng_get_samples( sample_buf, sample_len );
//do fft
simple_fft( sample_buf, sample_len );
@@ -335,7 +335,7 @@ int main()
main_exit:
//close gui, restore terminal mode
tui_close( t );
- sdr_close();
+ dng_close();
return 0;
}