Skip to content

Commit

Permalink
Updated from NO1D's repo (v1.5 -> v1.8) https://github.com/dtheriault…
Browse files Browse the repository at this point in the history
…/hydra

and fixed some INFO messages.
  • Loading branch information
n1gp committed Jan 16, 2018
1 parent 7d2303b commit 05e026f
Show file tree
Hide file tree
Showing 16 changed files with 3,156 additions and 1,424 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,17 @@ find_package(PkgConfig)
find_package(LibUSB)
set(THREADS_USE_PTHREADS_WIN32 true)
find_package(Threads)
find_package(FFTW3)

if(NOT LIBUSB_FOUND)
message(FATAL_ERROR "LibUSB 1.0 required to compile rtl-sdr")
endif()
if(NOT THREADS_FOUND)
message(FATAL_ERROR "pthreads(-win32) required to compile rtl-sdr")
endif()
if(NOT FFTW3_FOUND)
message(FATAL_ERROR "fftw3 (-win32) required to compile rtl-sdr")
endif()
########################################################################
# Setup the include and linker paths
########################################################################
Expand Down
97 changes: 97 additions & 0 deletions cal.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/bin/bash

freq=125000000 #upconvertor center freq
width=5000 #gap +- around center freq
itime=10 #iteration time for rtl_power
ntime=20 #length of each dongle cal
warmup=30 #warmup time to bring dongles to operating temp
xtal=-450 #how far off your upconvertor xtal is
fudge0=850 #fudge factor for problem child dongle 0
crop=80

count=`rtl_eeprom 2>&1 | egrep 'Found [0-9]' | cut -d' ' -f2`

killall -9 rtl_power > /dev/null 2>&1

echo "Found a total of $count dongles."
lcount=$(( count / 2 ))
zcount=$(( count - lcount ))
count=$(( count - 1 ))

echo "Warming up for $warmup seconds."
for i in `seq 0 $count`; do
rtl_test -d $i -b 8192 -S -s 250001 > /dev/null 2>&1 &
pid_array[$i]=$!
done
sleep $warmup

for i in `seq 0 $count`; do
kill ${pid_array[$i]} > /dev/null 2>&1
done

echo "Starting calibration on first $lcount dongles, this will take $ntime seconds."

fcount=$(( lcount - 1 ))
fstart=0

for i in `seq $fstart $fcount`; do
#echo "spawning $i"
rtl_power -F 9 -d $i -f $(( freq - width )):$(( freq + width )):1 -r 2048000 \
-o $freq -c $crop /dev/shm/rtl_$i -i $itime -e $ntime > /dev/null 2>&1 &
done

mtime=$ntime
while [ $mtime -ne 0 ]; do
echo $mtime left
sleep 10
mtime=$(( mtime - 10 ))
done

while true; do
ps -Af|grep ' rtl_power'|grep -v grep > /dev/null 2>&1
[ $? -ne 0 ] && break
sleep 1
#echo "Waiting for rtl_power to stop..."
done

fstart=$lcount

echo "Starting calibration on remaining $zcount dongles, this will take $ntime seconds."

for i in `seq $fstart $count`; do
#echo "spawning $i"
rtl_power -F 9 -d $i -f $(( freq - width )):$(( freq + width )):1 -r 2048000 \
-o $freq -c $crop /dev/shm/rtl_$i -i $itime -e $ntime > /dev/null 2>&1 &
done

mtime=$ntime
while [ $mtime -ne 0 ]; do
echo $mtime left
sleep 10
mtime=$(( mtime - 10 ))
done

echo "Calculating calibration values for dongles 0 - $count ..."
while true; do
ps -Af|grep ' rtl_power'|grep -v grep > /dev/null 2>&1
[ $? -ne 0 ] && break
sleep 1
#echo "Waiting for rtl_power to stop..."
done

echo -n "freq_offset "
for i in `seq 0 $count`; do
offset=0
loop=0
while read line; do
offset=$(( line + offset ))
loop=$(( loop + 1 ))
done < <(cat /dev/shm/rtl_$i | grep "offset =" | cut -d' ' -f13)

offset=$(( offset / loop ))
[ $i -eq 0 ] && offset=$(( offset + fudge0 ))

echo -n "$(( freq + offset + xtal ))"
[ $i -ne $count ] && echo -n ","
done
echo
64 changes: 63 additions & 1 deletion include/rtl-sdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,29 @@ RTLSDR_API int rtlsdr_get_tuner_gains(rtlsdr_dev_t *dev, int *gains);
*/
RTLSDR_API int rtlsdr_set_tuner_gain(rtlsdr_dev_t *dev, int gain);

/*!
* Get a list of bandwidths supported by the tuner.
*
* NOTE: The bandwidths argument must be preallocated by the caller. If NULL is
* being given instead, the number of available bandwidth values will be returned.
*
* \param dev the device handle given by rtlsdr_open()
* \param bandwidths array of bandwidth values in Hz.
* \return <= 0 on error, number of available (returned) gain values otherwise
*/
RTLSDR_API int rtlsdr_get_tuner_bandwidths(rtlsdr_dev_t *dev, int *bandwidths);

/*!
* Set the bandwidth for the device.
*
* Valid bandwidth values may be queried with \ref rtlsdr_get_tuner_bandwidths function.
*
* \param dev the device handle given by rtlsdr_open()
* \param bandwidth in Hz.
* \return 0 on success
*/
RTLSDR_API int rtlsdr_set_tuner_bandwidth(rtlsdr_dev_t *dev, int bandwidth);

/*!
* Get actual gain the device is configured to.
*
Expand All @@ -233,13 +256,52 @@ RTLSDR_API int rtlsdr_get_tuner_gain(rtlsdr_dev_t *dev);
*/
RTLSDR_API int rtlsdr_set_tuner_if_gain(rtlsdr_dev_t *dev, int stage, int gain);

/*!
* Get a list of gains and description of the gain stages supported by the tuner.
* NOTE: The gains argument must be preallocated by the caller. If NULL is
* being given instead, the number of available gain settings will be returned.
*
* \param dev the device handle given by rtlsdr_open()
* \param stage the stage to get the array of gain settings. If no such
* stage exists, return error
* \gains array to hold the different gain settings for this stage
* - use NULL to get the size of the array returned by the function
* \param description the textual description of the respective stage
* is copied into this string (description max. 256 chars)
* Optional: can be NULL
* \return <= 0 on error, number of available (returned) gain values otherwise
* \def DESCRIPTION_MAXLEN description max. 256 chars
*/
#define DESCRIPTION_MAXLEN 256
RTLSDR_API int rtlsdr_get_tuner_stage_gains(rtlsdr_dev_t *dev, uint8_t stage, int32_t *gains, char *description);

/*!
* Set the gain of a stage in the tuner
*
* \param dev the device handle given by rtlsdr_open()
* \param stage the stage to set gain for
* \param in tenths of a dB, e.g. -30 means -3.0 dB.
* \return <= 0 on error, 0 on success
*/
RTLSDR_API int rtlsdr_set_tuner_stage_gain(rtlsdr_dev_t *dev, uint8_t stage, int32_t gain);

enum rtl_sdr_gain_mode {
GAIN_MODE_AGC=0,
GAIN_MODE_MANUAL=1,
GAIN_MODE_LINEARITY=2,
GAIN_MODE_SENSITIVITY=3
};

/*!
* Set the gain mode (automatic/manual) for the device.
* Manual gain mode must be enabled for the gain setter function to work.
*
* Advanced gain modes can be enabled. If not implemented, the mode with
* the highest number will be set
* \param dev the device handle given by rtlsdr_open()
* \param manual gain mode, 1 means manual gain mode shall be enabled.
* \return 0 on success
* \return <= 0 on error, 0 on success for GAIN_MODE_AGC and GAIN_MODE_MANUAL (compatiblity),
* \return the mode supplied on success or the highest mode supported
*/
RTLSDR_API int rtlsdr_set_tuner_gain_mode(rtlsdr_dev_t *dev, int manual);

Expand Down
80 changes: 45 additions & 35 deletions include/rtl_hpsdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <netdb.h>
#include <fcntl.h>
#include <ifaddrs.h>
#include <fftw3.h>
#else
#include <winsock2.h>
#include <windows.h>
Expand All @@ -59,32 +60,29 @@
#include <xmmintrin.h>
#endif

#define PRG_VERSION "1.5" // see ChangeLog for history
#define PRG_VERSION "1.8" // see ChangeLog for history

#define HERMES_FW_VER 26 //2.5
#define HERMES_FW_VER 26 //2.6
#define PORT 1024
#define MAX_BUFFER_LEN 2048
#define HPSDR_FRAME_LEN 1032
#define IQ_FRAME_DATA_LEN 63
#define RTL_BANDWIDTH 300000 // Tuner set to 400 Khz IF BW
#define DOWNSAMPLE_192 8 // downsample value used to get 192khz
#define RTL_SAMPLE_RATE (192000 * DOWNSAMPLE_192)
#define RTL_READ_COUNT (2048 * DOWNSAMPLE_192)
#define RTL_READ_COUNT (16384 * DOWNSAMPLE_192)
#define MAX_RCVRS 8 // cuSDR64 limits this to 7
#define IQ_FRAME_DATA_LEN 63
#define MAXSTR 64

#define COEFF3072_H_16_LENGTH 16
#define COEFF1536_H_32_LENGTH 32
#define COEFF1536_H_64_LENGTH 64
float coeff3072_768_H_16[COEFF3072_H_16_LENGTH];
float coeff1536_384_H_32[COEFF1536_H_32_LENGTH];
float coeff1536_192_H_32[COEFF1536_H_32_LENGTH];
float coeff1536_96_H_32[COEFF1536_H_32_LENGTH];
float coeff1536_48_H_32[COEFF1536_H_32_LENGTH];
float coeff1536_384_H_64[COEFF1536_H_64_LENGTH];
float coeff1536_192_H_64[COEFF1536_H_64_LENGTH];
float coeff1536_96_H_64[COEFF1536_H_64_LENGTH];
float coeff1536_48_H_64[COEFF1536_H_64_LENGTH];
#define MAXSTR 128
#define FFT_SIZE 65536
#define CAL_STATE_EXIT MAX_RCVRS
#define CAL_STATE_0 -1
#define CAL_STATE_1 -2
#define CAL_STATE_2 -3
#define CAL_STATE_3 -4

#define RTL_MODE_SKIMMER 0
#define RTL_MODE_WSPR 1

struct main_cb {
int total_num_rcvrs;
Expand All @@ -94,38 +92,50 @@ struct main_cb {
int frame_offset1;
int frame_offset2;
int output_rate;
int length_fir;
char sound_dev[32];
char ip_addr[32];
int up_xtal;
char sound_dev[MAXSTR];
char ip_addr[MAXSTR];
char serialstr[MAXSTR];

// the last array member is used to remember last settings
int agc_mode[MAX_RCVRS + 1];
int direct_mode[MAX_RCVRS + 1];
int gain[MAX_RCVRS + 1];
int freq_offset[MAX_RCVRS + 1];
int center_freq[MAX_RCVRS + 1];
int if_bw[MAX_RCVRS + 1];
int gain_mode[MAX_RCVRS + 1];

// Added to handle dynamic config file updates
int last_agc_mode[MAX_RCVRS + 1];
int last_direct_mode[MAX_RCVRS + 1];
int last_gain[MAX_RCVRS + 1];
int last_freq_offset[MAX_RCVRS + 1];
int last_center_freq[MAX_RCVRS + 1];
int last_if_bw[MAX_RCVRS + 1];
int last_gain_mode[MAX_RCVRS + 1];


int rcvr_order[MAX_RCVRS + 1];
int signal_multiplier[MAX_RCVRS + 1];
int signal_multiplier;
int cal_state;
int calibrate;
int rtl_mode;

struct timeb freq_ltime[MAX_RCVRS];
struct timeb freq_ttime[MAX_RCVRS];

// filter coefficient table pointers
float* align1536_48_H;
float* align1536_96_H;
float* align1536_192_H;
float* align1536_384_H;
float* align3072_768_H;
float* coeff_48;
float* coeff_96;
float* coeff_192;
float* coeff_384;
float* coeff_768;
fftw_complex fftIn[sizeof(fftw_complex) * FFT_SIZE];
fftw_complex fftOut[sizeof(fftw_complex) * FFT_SIZE];
fftw_plan fftPlan;
float fft_averaged[FFT_SIZE * sizeof(float)];

struct rcvr_cb {
float dest[4] __attribute__((aligned(16)));

int rcvr_num;
int new_freq;
int curr_freq;
int output_rate;
u_int rcvr_mask;
rtlsdr_dev_t* rtldev;
struct main_cb* mcb;
Expand All @@ -136,9 +146,8 @@ struct main_cb {
int iqSamples_remaining;
float iqSamples[(RTL_READ_COUNT + (IQ_FRAME_DATA_LEN * 2))];

u_char rtl_buf[RTL_READ_COUNT];
float rtl_buf[RTL_READ_COUNT];
float* iq_buf;
float* iq_buf_final;
} rcb[MAX_RCVRS];
};

Expand All @@ -149,6 +158,7 @@ void load_packet(struct rcvr_cb* rcb);
void rtl_sighandler(int signum);
int get_addr(int sock);
void hpsdrsim_reveal(void);
int parse_config(char* conf_file);

pthread_t hpsdrsim_thread_id;
void* hpsdrsim_thread(void* arg);
Expand Down
5 changes: 5 additions & 0 deletions include/tuner_e4k.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ struct e4k_state {
uint8_t i2c_addr;
enum e4k_band band;
struct e4k_pll_params vco;
int gain_mode;
void *rtl_dev;
};

Expand All @@ -216,7 +217,11 @@ int e4k_manual_dc_offset(struct e4k_state *e4k, int8_t iofs, int8_t irange, int8
int e4k_dc_offset_calibrate(struct e4k_state *e4k);
int e4k_dc_offset_gen_table(struct e4k_state *e4k);

int e4k_get_tuner_gains(struct e4k_state *e4k, const int **ptr, int *len);
int e4k_set_lna_gain(struct e4k_state *e4k, int32_t gain);
int e4k_set_lna_mixer_if_gain(struct e4k_state *e4k, int32_t gain);
int e4k_get_tuner_stage_gains(struct e4k_state *e4k, uint8_t stage, const int32_t **gains, const char **description);
int e4k_set_tuner_stage_gain(struct e4k_state *e4k, uint8_t stage, int32_t gain);
int e4k_enable_manual_gain(struct e4k_state *e4k, uint8_t manual);
int e4k_set_enh_gain(struct e4k_state *e4k, int32_t gain);
#endif /* _E4K_TUNER_H */
12 changes: 11 additions & 1 deletion include/tuner_r82xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ struct r82xx_priv {
enum r82xx_tuner_type type;

uint32_t bw; /* in MHz */
int gain_mode;
int bw_index;

void *rtl_dev;
};
Expand All @@ -114,6 +116,14 @@ enum r82xx_delivery_system {
int r82xx_standby(struct r82xx_priv *priv);
int r82xx_init(struct r82xx_priv *priv);
int r82xx_set_freq(struct r82xx_priv *priv, uint32_t freq);
int r82xx_set_gain(struct r82xx_priv *priv, int set_manual_gain, int gain);
int r82xx_set_gain(struct r82xx_priv *priv, int gain);

int r82xx_enable_manual_gain(struct r82xx_priv *priv, uint8_t manual);
int r82xx_get_tuner_gains(struct r82xx_priv *priv, const int **ptr, int *len);

int r82xx_get_tuner_stage_gains(struct r82xx_priv *priv, uint8_t stage, const int32_t **gains, const char **description);
int r82xx_set_tuner_stage_gain(struct r82xx_priv *priv, uint8_t stage, int32_t gain);

int r82xx_set_bandwidth(struct r82xx_priv *priv, int bandwidth, uint32_t rate);
int r82xx_get_tuner_bandwidths(struct r82xx_priv *priv, const int **ptr, int *len);
#endif
Loading

0 comments on commit 05e026f

Please sign in to comment.