diff options
-rw-r--r--[-rwxr-xr-x] | gsm-tvoid/src/lib/Makefile.am | 20 | ||||
-rwxr-xr-x | gsm-tvoid/src/lib/gsm.i | 25 | ||||
-rwxr-xr-x | gsm-tvoid/src/lib/gsm_burst.cc | 74 | ||||
-rwxr-xr-x | gsm-tvoid/src/lib/gsm_burst.h | 54 | ||||
-rwxr-xr-x | gsm-tvoid/src/lib/gsm_burst_cf.cc | 109 | ||||
-rwxr-xr-x | gsm-tvoid/src/lib/gsm_burst_cf.h | 10 | ||||
-rwxr-xr-x | gsm-tvoid/src/lib/gsm_burst_ff.cc | 37 | ||||
-rwxr-xr-x | gsm-tvoid/src/lib/gsm_burst_ff.h | 6 | ||||
-rwxr-xr-x | gsm-tvoid/src/lib/gsm_burst_ff_single.cc | 118 | ||||
-rwxr-xr-x | gsm-tvoid/src/lib/gsm_burst_ff_single.h | 31 | ||||
-rwxr-xr-x | gsm-tvoid/src/lib/gsm_burst_sink_c.cc | 141 | ||||
-rwxr-xr-x | gsm-tvoid/src/lib/gsm_burst_sink_c.h | 54 | ||||
-rw-r--r--[-rwxr-xr-x] | gsm-tvoid/src/lib/gsm_constants.h | 0 | ||||
-rwxr-xr-x | gsm-tvoid/src/python/gsm_scan.py | 205 |
14 files changed, 714 insertions, 170 deletions
diff --git a/gsm-tvoid/src/lib/Makefile.am b/gsm-tvoid/src/lib/Makefile.am index 2d4d7f7..88b8faa 100755..100644 --- a/gsm-tvoid/src/lib/Makefile.am +++ b/gsm-tvoid/src/lib/Makefile.am @@ -37,16 +37,17 @@ ourpython_PYTHON = \ ourlib_LTLIBRARIES = _gsm.la # These are the source files that go into the shared library -_gsm_la_SOURCES = \ +_gsm_la_SOURCES = \ gsmstack.c \ - interleave.c \ + interleave.c \ conv.c \ sch.c \ cch.c \ gsm.cc \ - gsm_burst.cc \ - gsm_burst_ff.cc \ - gsm_burst_cf.cc + gsm_burst.cc \ + gsm_burst_ff.cc \ + gsm_burst_cf.cc \ + gsm_burst_sink_c.cc # magic flags @@ -62,16 +63,17 @@ gsm.cc gsm.py: $(LOCAL_IFILES) $(ALL_IFILES) $(SWIG) $(SWIGPYTHONARGS) -module gsm -o gsm.cc $(LOCAL_IFILES) # These headers get installed in ${prefix}/include/gnuradio -grinclude_HEADERS = \ +grinclude_HEADERS = \ gsm_burst.h \ gsmstack.h \ - interleave.h \ + interleave.h \ conv.h \ sch.h \ cch.h \ system.h \ - gsm_burst_ff.h \ - gsm_burst_cf.h \ + gsm_burst_ff.h \ + gsm_burst_cf.h \ + gsm_burst_sink_c.h \ gsm_constants.h diff --git a/gsm-tvoid/src/lib/gsm.i b/gsm-tvoid/src/lib/gsm.i index d990e8b..106e378 100755 --- a/gsm-tvoid/src/lib/gsm.i +++ b/gsm-tvoid/src/lib/gsm.i @@ -9,6 +9,7 @@ //#include "gsm_burst.h" #include "gsm_burst_ff.h" #include "gsm_burst_cf.h" +#include "gsm_burst_sink_c.h" //#include <stdexcept> %} @@ -43,6 +44,10 @@ #define CLK_CORR_TRACK 0x00000010 //adjust timing based on correlation offsets +#define BURST_CB_SYNC_OFFSET 1 +#define BURST_CB_ADJ_OFFSET 2 +#define BURST_CB_TUNE 3 + //EQ options enum EQ_TYPE { EQ_NONE, @@ -73,6 +78,8 @@ public: long d_unknown_count; long d_total_count; + long next_arfcn; + int sync_state(); float last_freq_offset(void); double mean_freq_offset(void); @@ -81,24 +88,32 @@ public: void full_reset(void); protected: - gsm_burst(); + gsm_burst(gr_feval_ll *); }; GR_SWIG_BLOCK_MAGIC(gsm,burst_ff); -gsm_burst_ff_sptr gsm_make_burst_ff (); +gsm_burst_ff_sptr gsm_make_burst_ff (gr_feval_ll *); class gsm_burst_ff : public gr_block, public gsm_burst { private: - gsm_burst_ff (); + gsm_burst_ff (gr_feval_ll *); }; GR_SWIG_BLOCK_MAGIC(gsm,burst_cf); -gsm_burst_cf_sptr gsm_make_burst_cf (float); +gsm_burst_cf_sptr gsm_make_burst_cf (gr_feval_ll *,float); class gsm_burst_cf : public gr_block, public gsm_burst { private: - gsm_burst_cf (float); + gsm_burst_cf (gr_feval_ll *,float); +}; + +GR_SWIG_BLOCK_MAGIC(gsm,burst_sink_c); +gsm_burst_sink_c_sptr gsm_make_burst_sink_c(gr_feval_ll *,float); + +class gsm_burst_sink_c : public gr_sync_block, public gsm_burst { +private: + gsm_burst_sink_c (gr_feval_ll *,float); }; diff --git a/gsm-tvoid/src/lib/gsm_burst.cc b/gsm-tvoid/src/lib/gsm_burst.cc index b862d69..14950c6 100755 --- a/gsm-tvoid/src/lib/gsm_burst.cc +++ b/gsm-tvoid/src/lib/gsm_burst.cc @@ -13,12 +13,15 @@ #include "gsmstack.h" -gsm_burst::gsm_burst () : +gsm_burst::gsm_burst (gr_feval_ll *t) : + p_tuner(t), d_clock_options(DEFAULT_CLK_OPTS), d_print_options(0), d_equalizer_type(EQ_FIXED_DFE) { +// fprintf(stderr,"gsm_burst: enter constructor (t=%8.8x)\n",(unsigned int)t); + // M_PI = M_PI; //4.0 * atan(1.0); full_reset(); @@ -348,14 +351,15 @@ void gsm_burst::shift_burst(int shift_bits) //of the mean phase from pi/2. void gsm_burst::calc_freq_offset(void) { - int start = d_burst_start + 10; - int end = d_burst_start + USEFUL_BITS - 10; + const int padding = 20; + int start = d_burst_start + padding; + int end = d_burst_start + USEFUL_BITS - padding; float sum = 0.0; for (int j = start; j <= end; j++) { sum += d_burst_buffer[j]; } - float mean = sum / ((float)USEFUL_BITS - 20.0); + float mean = sum / ((float)USEFUL_BITS - (2.0 * (float)padding) ); float p_off = mean - (M_PI / 2); d_freq_offset = p_off * 1625000.0 / (12.0 * M_PI); @@ -466,7 +470,8 @@ float gsm_burst::correlate_pattern(const float *pattern,const int pat_size,const corr = 0.0; for (int i = 1; i < pat_size; i++) { //Start a 1 to skip first bit due to diff encoding //d_corr[j+distance] += d_burst_buffer[center+i+j] * pattern[i]; - corr += SIGNUM(d_burst_buffer[center+i+j]) * pattern[i]; //binary corr/sliced + //corr += SIGNUM(d_burst_buffer[center+i+j]) * pattern[i]; //binary corr/sliced + corr += d_burst_buffer[center+i+j] * pattern[i]; } corr /= pat_size - 1; //normalize, -1 for skipped first bit if (corr > d_corr_max) { @@ -609,8 +614,9 @@ int gsm_burst::get_burst(void) case PARTIAL_SCH: d_sync_state = WAIT_SCH; break; - case SCH: - d_sync_state = SYNCHRONIZED; + //case SCH: + //let the burst type switch handle this so it knows if new or old sync + // d_sync_state = SYNCHRONIZED; break; default: break; @@ -645,6 +651,18 @@ int gsm_burst::get_burst(void) d_ts = 0; //TODO: check this break; case SCH: +#ifndef TEST_TUNE_TIMING + //TODO: it would be better to adjust tuning on first FCCH (for better SCH detection), + // but tuning can run away with false FCCHs + // Some logic to retune back to original offset on false FCCH might work + if (p_tuner) { + if (SYNCHRONIZED == d_sync_state) + p_tuner->calleval(BURST_CB_ADJ_OFFSET); + else + p_tuner->calleval(BURST_CB_SYNC_OFFSET); + + } +#endif d_burst_count++; d_sch_count++; d_last_sch = d_burst_count; @@ -672,7 +690,6 @@ int gsm_burst::get_burst(void) d_last_good = d_burst_count; } - //Check for loss of sync int bursts_since_good = d_burst_count - d_last_good; if (bursts_since_good > MAX_SYNC_WAIT) { @@ -686,6 +703,47 @@ int gsm_burst::get_burst(void) //print info print_burst(); + ///////////////////// + //start tune testing +#ifdef TEST_TUNE_TIMING + + static int good_count = -1; //-1: wait sch, >=0: got sch, counting + static int wait_count = 0; + + if (UNKNOWN == d_burst_type) { + if (good_count >= 0) { + fprintf(stdout,"good_count: %d\n",good_count); + + if (p_tuner) { + next_arfcn = TEST_TUNE_GOOD_ARFCN; + p_tuner->calleval(BURST_CB_TUNE); + } + } + good_count = -1; // start again at resync + + } else { + + if (good_count >= 0 ) { + good_count++; + } + + if (SCH == d_burst_type) { + if ((good_count < 0) && (++wait_count > 20)) { // get some good syncs before trying again + fprintf(stdout,"restarting good_count\n"); + good_count = wait_count = 0; + //tune away + if (p_tuner) { + next_arfcn = TEST_TUNE_EMPTY_ARFCN; + p_tuner->calleval(BURST_CB_TUNE); + } + } + } + } +#endif + //end tune testing + ///////////////////// + + //Adjust the buffer write position to align on MAX_CORR_DIST if ( d_clock_options & CLK_CORR_TRACK ) d_bbuf_pos += MAX_CORR_DIST - d_burst_start; diff --git a/gsm-tvoid/src/lib/gsm_burst.h b/gsm-tvoid/src/lib/gsm_burst.h index def20e0..48fafac 100755 --- a/gsm-tvoid/src/lib/gsm_burst.h +++ b/gsm-tvoid/src/lib/gsm_burst.h @@ -8,10 +8,15 @@ #include "gsm_constants.h" #include <gr_math.h> -//#include <Python.h> //for callback testing #include <gr_feval.h> #include "gsmstack.h" +//Testing Modes +//Tune test measures hopping latency by hopping between good and empty ARFCNs +#undef TEST_TUNE_TIMING +#define TEST_TUNE_GOOD_ARFCN 658 +#define TEST_TUNE_EMPTY_ARFCN 655 + //Console printing options #define PRINT_NOTHING 0x00000000 @@ -73,13 +78,18 @@ enum EQ_TYPE { EQ_VITERBI }; +#define BURST_CB_SYNC_OFFSET 1 +#define BURST_CB_ADJ_OFFSET 2 +#define BURST_CB_TUNE 3 + + class gsm_burst; class gsm_burst { protected: - gsm_burst(); + gsm_burst(gr_feval_ll *t); //Burst Buffer: Storage for burst data float d_burst_buffer[BBUF_SIZE]; @@ -116,30 +126,33 @@ protected: double d_freq_off_sum; double d_freq_off_weight; + gr_feval_ll *p_tuner; + //////// Methods int get_burst(void); BURST_TYPE get_fcch_burst(void); BURST_TYPE get_sch_burst(void); BURST_TYPE get_norm_burst(void); - void shift_burst(int); - void calc_freq_offset(void); - void equalize(void); - float correlate_pattern(const float *,const int,const int,const int); - void diff_decode_burst(void); + virtual void shift_burst(int); + void calc_freq_offset(void); + virtual void equalize(void); + float correlate_pattern(const float *,const int,const int,const int); + void diff_decode_burst(void); - void sync_reset(void); + void sync_reset(void); - void print_bits(const float *data,int length); - void print_hex(const unsigned char *data,int length); - void soft2hardbit(char *dst, const float *data, int len); - void print_burst(void); + void print_bits(const float *data,int length); + void print_hex(const unsigned char *data,int length); - void diff_encode(const float *in,float *out,int length,float lastbit = 1.0); - void diff_decode(const float *in,float *out,int length,float lastbit = 1.0); +// void soft2hardbit(char *dst, const float *data, int len); //need this? + void print_burst(void); + + void diff_encode(const float *in,float *out,int length,float lastbit = 1.0); + void diff_decode(const float *in,float *out,int length,float lastbit = 1.0); public: - ~gsm_burst (); + virtual ~gsm_burst (); ////// General Stats //TODO: Maybe there should be a burst_stats class? @@ -157,12 +170,17 @@ public: unsigned long d_print_options; EQ_TYPE d_equalizer_type; - int sync_state() { return d_sync_state;} - float last_freq_offset() {return d_freq_offset;} - double mean_freq_offset(void); //Methods void full_reset(void); + + int sync_state() { return d_sync_state;} + + //Frequency + float last_freq_offset() {return d_freq_offset;} + double mean_freq_offset(void); + + long next_arfcn; }; diff --git a/gsm-tvoid/src/lib/gsm_burst_cf.cc b/gsm-tvoid/src/lib/gsm_burst_cf.cc index a91c569..a584cd6 100755 --- a/gsm-tvoid/src/lib/gsm_burst_cf.cc +++ b/gsm-tvoid/src/lib/gsm_burst_cf.cc @@ -9,21 +9,23 @@ #include <stdio.h> #include <gri_mmse_fir_interpolator_cc.h> -gsm_burst_cf_sptr gsm_make_burst_cf (float sample_rate) +gsm_burst_cf_sptr gsm_make_burst_cf (gr_feval_ll *t,float sample_rate) { - return gsm_burst_cf_sptr (new gsm_burst_cf (sample_rate)); + return gsm_burst_cf_sptr (new gsm_burst_cf (t,sample_rate)); } static const int MIN_IN = 1; // minimum number of input streams static const int MAX_IN = 1; // maximum number of input streams -static const int MIN_OUT = 1; // minimum number of output streams +static const int MIN_OUT = 0; // minimum number of output streams static const int MAX_OUT = 1; // maximum number of output streams -gsm_burst_cf::gsm_burst_cf (float sample_rate) : +gsm_burst_cf::gsm_burst_cf (gr_feval_ll *t, float sample_rate) : + gsm_burst(t), gr_block ( "burst_cf", gr_make_io_signature (MIN_IN, MAX_IN, sizeof (gr_complex)), gr_make_io_signature (MIN_OUT, MAX_OUT, USEFUL_BITS * sizeof (float))), d_clock_counter(0.0), + d_mu(0.5), d_last_sample(0.0,0.0), d_interp(new gri_mmse_fir_interpolator_cc()) @@ -36,7 +38,7 @@ gsm_burst_cf::gsm_burst_cf (float sample_rate) : fprintf(stderr,"Sample interval : %e\n",d_sample_interval); fprintf(stderr,"Relative sample rate : %g\n",d_relative_sample_rate); - set_history(4); + set_history(4); //need history for interpolator } @@ -63,41 +65,39 @@ int gsm_burst_cf::general_work (int noutput_items, int ii=0; int rval = 0; //default to no output + int do_output = output_items.size() > 0 ? 1 : 0; int ninput = ninput_items[0]; //fprintf(stderr,"#i=%d/#o=%d",n_input,noutput_items); - int ni = ninput - d_interp->ntaps(); // interpolator need -4/+3 samples NTAPS = 8 + int ni = ninput - d_interp->ntaps() - 16; // interpolator need -4/+3 samples NTAPS = 8 , - 16 for safety margin while (( rval < noutput_items) && ( ii < ni ) ) { //clock symbols //TODO: this is very basic and can be improved. Need tracking... //TODO: use burst_start offsets as timing feedback //TODO: save complex samples for Viterbi EQ - if ( d_clock_counter >= GSM_SYMBOL_PERIOD) { - - d_clock_counter -= GSM_SYMBOL_PERIOD; //reset clock for next sample, keep the remainder - - //float mu = 1.0 - d_clock_counter / GSM_SYMBOL_PERIOD; - float mu = d_clock_counter / GSM_SYMBOL_PERIOD; - gr_complex sample = d_interp->interpolate (&in[ii], mu); //FIXME: this seems noisy, make sure it is being used correctly + + //from m&m + gr_complex sample = d_interp->interpolate (&in[ii], d_mu); //FIXME: this seems noisy, make sure it is being used correctly + + gr_complex conjprod = sample * conj(d_last_sample); + float diff_angle = gr_fast_atan2f(imag(conjprod), real(conjprod)); - gr_complex conjprod = sample * conj(d_last_sample); - float diff_angle = gr_fast_atan2f(imag(conjprod), real(conjprod)); + d_last_sample = sample; - d_last_sample = sample; - - assert(d_bbuf_pos <= BBUF_SIZE ); - - if (d_bbuf_pos >= 0) //could be negative offset from burst alignment. TODO: perhaps better just to add some padding to the buffer - d_burst_buffer[d_bbuf_pos] = diff_angle; - - d_bbuf_pos++; - - if ( d_bbuf_pos >= BBUF_SIZE ) { - - if (get_burst()) { - //found a burst, send to output + assert(d_bbuf_pos <= BBUF_SIZE ); + + if (d_bbuf_pos >= 0) //could be negative offset from burst alignment. TODO: perhaps better just to add some padding to the buffer + d_burst_buffer[d_bbuf_pos] = diff_angle; + + d_bbuf_pos++; + + if ( d_bbuf_pos >= BBUF_SIZE ) { + + if (get_burst()) { + //found a burst, send to output + if (do_output) { //ensure that output data is in range int b = d_burst_start; if (b < 0) @@ -106,31 +106,36 @@ int gsm_burst_cf::general_work (int noutput_items, b = 2 * MAX_CORR_DIST - 1; memcpy(out+rval*USEFUL_BITS, d_burst_buffer + b, USEFUL_BITS*sizeof(float)); - rval++; - - switch ( d_clock_options & QB_MASK ) { - case QB_QUARTER: //extra 1/4 bit each burst - d_clock_counter -= GSM_SYMBOL_PERIOD / 4.0; - break; - case QB_FULL04: //extra bit on timeslot 0 & 4 - if (!(d_ts%4)) - d_clock_counter -= GSM_SYMBOL_PERIOD; - break; - case QB_NONE: //don't adjust for quarter bits at all - default: - break; - } - - d_last_burst_s_count = d_sample_count; - - //fprintf(stderr,"clock: %f, pos: %d\n",d_clock_counter,d_bbuf_pos); } - } - } - - d_clock_counter += d_sample_interval; - d_sample_count++; - ii++; + rval++; + + switch ( d_clock_options & QB_MASK ) { + case QB_QUARTER: //extra 1/4 bit each burst + d_mu -= d_relative_sample_rate / 4.0; + //d_clock_counter -= GSM_SYMBOL_PERIOD / 4.0; + break; + case QB_FULL04: //extra bit on timeslot 0 & 4 + if (!(d_ts%4)) + d_mu -= d_relative_sample_rate; + //d_clock_counter -= GSM_SYMBOL_PERIOD; + break; + case QB_NONE: //don't adjust for quarter bits at all + default: + break; + } + + d_last_burst_s_count = d_sample_count; + + //fprintf(stderr,"clock: %f, pos: %d\n",d_clock_counter,d_bbuf_pos); + } + } + + //TODO: timing adjust + //d_mu = d_mu + d_omega + d_gain_mu * mm_val; + d_mu += d_relative_sample_rate; + ii += (int)floor(d_mu); + d_sample_count += (int)floor(d_mu); + d_mu -= floor(d_mu); } //fprintf(stderr,"/ii=%d/rval=%d\n",ii,rval); diff --git a/gsm-tvoid/src/lib/gsm_burst_cf.h b/gsm-tvoid/src/lib/gsm_burst_cf.h index 33f61f6..40ccc83 100755 --- a/gsm-tvoid/src/lib/gsm_burst_cf.h +++ b/gsm-tvoid/src/lib/gsm_burst_cf.h @@ -8,7 +8,7 @@ class gsm_burst_cf; typedef boost::shared_ptr<gsm_burst_cf> gsm_burst_cf_sptr; -gsm_burst_cf_sptr gsm_make_burst_cf(float); +gsm_burst_cf_sptr gsm_make_burst_cf(gr_feval_ll *,float); class gri_mmse_fir_interpolator_cc; @@ -16,15 +16,17 @@ class gsm_burst_cf : public gr_block, public gsm_burst { private: - friend gsm_burst_cf_sptr gsm_make_burst_cf(float); - gsm_burst_cf(float); + friend gsm_burst_cf_sptr gsm_make_burst_cf(gr_feval_ll *,float); + gsm_burst_cf(gr_feval_ll *,float); //clocking parameters - float d_relative_sample_rate; double d_sample_interval; double d_clock_counter; gr_complex d_last_sample; + float d_relative_sample_rate; //omega + float d_mu; + gri_mmse_fir_interpolator_cc *d_interp; //sub-sample interpolator from GR public: diff --git a/gsm-tvoid/src/lib/gsm_burst_ff.cc b/gsm-tvoid/src/lib/gsm_burst_ff.cc index 2980829..dd449f1 100755 --- a/gsm-tvoid/src/lib/gsm_burst_ff.cc +++ b/gsm-tvoid/src/lib/gsm_burst_ff.cc @@ -9,17 +9,18 @@ #include <stdio.h> #include <gri_mmse_fir_interpolator_cc.h> -gsm_burst_ff_sptr gsm_make_burst_ff () +gsm_burst_ff_sptr gsm_make_burst_ff (gr_feval_ll *t) { - return gsm_burst_ff_sptr (new gsm_burst_ff()); + return gsm_burst_ff_sptr (new gsm_burst_ff(t)); } static const int MIN_IN = 1; // minimum number of input streams static const int MAX_IN = 1; // maximum number of input streams -static const int MIN_OUT = 1; // minimum number of output streams +static const int MIN_OUT = 0; // minimum number of output streams static const int MAX_OUT = 1; // maximum number of output streams -gsm_burst_ff::gsm_burst_ff () : +gsm_burst_ff::gsm_burst_ff (gr_feval_ll *t) : + gsm_burst(t), gr_block( "burst_ff", gr_make_io_signature (MIN_IN, MAX_IN, sizeof (float)), gr_make_io_signature (MIN_OUT, MAX_OUT, USEFUL_BITS * sizeof (float))) @@ -37,7 +38,7 @@ void gsm_burst_ff::forecast (int noutput_items, gr_vector_int &ninput_items_requ { unsigned ninputs = ninput_items_required.size (); for (unsigned i = 0; i < ninputs; i++) - ninput_items_required[i] = noutput_items * BBUF_SIZE + history(); + ninput_items_required[i] = noutput_items * BBUF_SIZE; } @@ -51,9 +52,10 @@ int gsm_burst_ff::general_work (int noutput_items, int ii=0; int rval = 0; //default to no output - + int do_output = output_items.size() > 0 ? 1 : 0; + int n_input = ninput_items[0]; - //fprintf(stderr,"#i=%d/#o=%d",n_input,noutput_items); +// fprintf(stderr,"out=%8.8x/#i=%d/#o=%d",(unsigned)out,n_input,noutput_items); while (( rval < noutput_items) && ( ii < n_input ) ) { @@ -68,15 +70,16 @@ int gsm_burst_ff::general_work (int noutput_items, if (get_burst()) { //found a burst, send to output - - //ensure that output data is in range - int b = d_burst_start; - if (b < 0) - b = 0; - else if (b >= 2 * MAX_CORR_DIST) - b = 2 * MAX_CORR_DIST - 1; - - memcpy(out+rval*USEFUL_BITS, d_burst_buffer + b, USEFUL_BITS*sizeof(float)); + if (do_output) { + //ensure that output data is in range + int b = d_burst_start; + if (b < 0) + b = 0; + else if (b >= 2 * MAX_CORR_DIST) + b = 2 * MAX_CORR_DIST - 1; + + memcpy(out+rval*USEFUL_BITS, d_burst_buffer + b, USEFUL_BITS*sizeof(float)); + } rval++; switch ( d_clock_options & QB_MASK ) { @@ -98,7 +101,7 @@ int gsm_burst_ff::general_work (int noutput_items, ii++; } - //fprintf(stderr,"/ii=%d/rval=%d\n",ii,rval); +// fprintf(stderr,"/ii=%d/rval=%d\n",ii,rval); consume_each (ii); diff --git a/gsm-tvoid/src/lib/gsm_burst_ff.h b/gsm-tvoid/src/lib/gsm_burst_ff.h index 30c10dc..8ca61ef 100755 --- a/gsm-tvoid/src/lib/gsm_burst_ff.h +++ b/gsm-tvoid/src/lib/gsm_burst_ff.h @@ -8,14 +8,14 @@ class gsm_burst_ff; typedef boost::shared_ptr<gsm_burst_ff> gsm_burst_ff_sptr; -gsm_burst_ff_sptr gsm_make_burst_ff(); +gsm_burst_ff_sptr gsm_make_burst_ff(gr_feval_ll *); class gsm_burst_ff : public gr_block, public gsm_burst { private: - friend gsm_burst_ff_sptr gsm_make_burst_ff(); - gsm_burst_ff(); + friend gsm_burst_ff_sptr gsm_make_burst_ff(gr_feval_ll *); + gsm_burst_ff(gr_feval_ll *t); public: ~gsm_burst_ff (); diff --git a/gsm-tvoid/src/lib/gsm_burst_ff_single.cc b/gsm-tvoid/src/lib/gsm_burst_ff_single.cc new file mode 100755 index 0000000..ff6c354 --- /dev/null +++ b/gsm-tvoid/src/lib/gsm_burst_ff_single.cc @@ -0,0 +1,118 @@ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gsm_burst_ff.h> +#include <gr_io_signature.h> +#include <gr_math.h> +#include <stdio.h> +#include <gri_mmse_fir_interpolator_cc.h> + +gsm_burst_ff_sptr gsm_make_burst_ff (gr_feval_ll *t) +{ + return gsm_burst_ff_sptr (new gsm_burst_ff(t)); +} + +static const int MIN_IN = 1; // minimum number of input streams +static const int MAX_IN = 1; // maximum number of input streams +static const int MIN_OUT = 0; // minimum number of output streams +static const int MAX_OUT = 1; // maximum number of output streams + +gsm_burst_ff::gsm_burst_ff (gr_feval_ll *t) : + gsm_burst(t), + gr_block( "burst_ff", + gr_make_io_signature (MIN_IN, MAX_IN, sizeof (float)), +// gr_make_io_signature (MIN_OUT, MAX_OUT, USEFUL_BITS * sizeof (float))) + gr_make_io_signature (0, 0, 0)) +// gr_make_io_signature (MIN_OUT, MAX_OUT, sizeof (float))) +{ + + set_history(1); + +} + +gsm_burst_ff::~gsm_burst_ff () +{ +} + +/* +void gsm_burst_ff::forecast (int noutput_items, gr_vector_int &ninput_items_required) +{ + unsigned ninputs = ninput_items_required.size (); + for (unsigned i = 0; i < ninputs; i++) + ninput_items_required[i] = noutput_items * BBUF_SIZE + history(); +} +*/ + +int gsm_burst_ff::general_work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const float *in = (const float *) input_items[0]; + float *out = (float *) output_items[0]; + + int ii=0; + //int rval = 0; //default to no output + int rval = noutput_items; //default to no output + + //int do_output = output_items.size() > 0 ? 1 : 0; + int do_output = 0; + + int n_input = ninput_items[0]; +// fprintf(stderr,"out=%8.8x/#i=%d/#o=%d",(unsigned)out,n_input,noutput_items); +// fprintf(stderr,"#i=%d/#o=%d",n_input,noutput_items); + +// while (( rval < noutput_items) && ( ii < n_input ) ) { + while ( ii < n_input ) { + + assert(d_bbuf_pos <= BBUF_SIZE ); + + if (d_bbuf_pos >= 0) //could have been offset negative. TODO: perhaps better just to add some slack to the buffer + d_burst_buffer[d_bbuf_pos] = in[ii]; + + d_bbuf_pos++; + + if ( d_bbuf_pos >= BBUF_SIZE ) { + + if (get_burst()) { + //found a burst, send to output + if (do_output) { + //ensure that output data is in range + int b = d_burst_start; + if (b < 0) + b = 0; + else if (b >= 2 * MAX_CORR_DIST) + b = 2 * MAX_CORR_DIST - 1; + + memcpy(out+rval*USEFUL_BITS, d_burst_buffer + b, USEFUL_BITS*sizeof(float)); + } + //rval++; + //rval += USEFUL_BITS*sizeof(float); + + switch ( d_clock_options & QB_MASK ) { + case QB_QUARTER: //Can't do this in the FF version + case QB_FULL04: //extra bit on timeslot 0 & 4 + if (!(d_ts%4)) + d_bbuf_pos--; + break; + case QB_NONE: //don't adjust for quarter bits at all + default: + break; + } + + d_last_burst_s_count = d_sample_count; + + } + } + d_sample_count++; + ii++; + } + +// fprintf(stderr,"/ii=%d/rval=%d\n",ii,rval); + + consume_each (ii); + + return rval; +} diff --git a/gsm-tvoid/src/lib/gsm_burst_ff_single.h b/gsm-tvoid/src/lib/gsm_burst_ff_single.h new file mode 100755 index 0000000..553fe65 --- /dev/null +++ b/gsm-tvoid/src/lib/gsm_burst_ff_single.h @@ -0,0 +1,31 @@ +#ifndef INCLUDED_GSM_BURST_FF_H +#define INCLUDED_GSM_BURST_FF_H + +#include <gr_block.h> +#include <gsm_burst.h> + +class gsm_burst_ff; + +typedef boost::shared_ptr<gsm_burst_ff> gsm_burst_ff_sptr; + +gsm_burst_ff_sptr gsm_make_burst_ff(gr_feval_ll *); + +class gsm_burst_ff : public gr_block, public gsm_burst +{ +private: + + friend gsm_burst_ff_sptr gsm_make_burst_ff(gr_feval_ll *); + gsm_burst_ff(gr_feval_ll *t); + +public: + ~gsm_burst_ff (); + +// void forecast (int noutput_items, gr_vector_int &ninput_items_required); + + int general_work ( int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif /* INCLUDED_GSM_BURST_FF_H */ diff --git a/gsm-tvoid/src/lib/gsm_burst_sink_c.cc b/gsm-tvoid/src/lib/gsm_burst_sink_c.cc new file mode 100755 index 0000000..58787bb --- /dev/null +++ b/gsm-tvoid/src/lib/gsm_burst_sink_c.cc @@ -0,0 +1,141 @@ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "gsm_burst_sink_c.h" +#include <gr_io_signature.h> +#include <gr_math.h> +#include <stdio.h> +#include <gri_mmse_fir_interpolator_cc.h> + +gsm_burst_sink_c_sptr gsm_make_burst_sink_c (gr_feval_ll *t,float sample_rate) +{ + return gsm_burst_sink_c_sptr (new gsm_burst_sink_c(t,sample_rate)); +} + +static const int MIN_IN = 1; // minimum number of input streams +static const int MAX_IN = 1; // maximum number of input streams + +gsm_burst_sink_c::gsm_burst_sink_c (gr_feval_ll *t, float sample_rate) : + gsm_burst(t), + gr_sync_block ( "burst_sink_c", + gr_make_io_signature (MIN_IN, MAX_IN, sizeof (gr_complex)), + gr_make_io_signature (0,0,0) + ), + d_clock_counter(0.0), + d_mu(0.5), + d_last_sample(0.0,0.0), + d_ii(0), + d_interp(new gri_mmse_fir_interpolator_cc()) + +{ + + //clocking parameters + d_sample_interval = 1.0 / sample_rate; + d_relative_sample_rate = sample_rate / GSM_SYMBOL_RATE; + + fprintf(stderr,"Sample interval : %e\n",d_sample_interval); + fprintf(stderr,"Relative sample rate : %g\n",d_relative_sample_rate); + + //we need history for interpolator taps and some saftey relative to relative rate + int hist = d_interp->ntaps(); // + 16; // interpolator need -4/+3 samples NTAPS = 8 , 16 for safety margin + set_history(hist); //need history for interpolator + +} + +gsm_burst_sink_c::~gsm_burst_sink_c () +{ + delete d_interp; +} + +void gsm_burst_sink_c::shift_burst(int shift_bits) +{ + //fprintf(stderr,"sft:%d\n",shift_bits); + + assert(shift_bits >= 0); + assert(shift_bits < BBUF_SIZE ); + + gr_complex *p_src = d_complex_burst + shift_bits; + gr_complex *p_dst = d_complex_burst; + int num = BBUF_SIZE - shift_bits; + + memmove(p_dst,p_src,num * sizeof(gr_complex)); //need memmove because of overlap + + //DON'T adjust the buffer positions, the superclass method will do that... + //d_bbuf_pos -= shift_bits; + //call the parent method to shift the float version + gsm_burst::shift_burst(shift_bits); +} + +//TODO: put everything but GR stuff in a common complex type class (share w/ gsm_burst_cf) +int gsm_burst_sink_c::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + +{ + const gr_complex *in = (const gr_complex *) input_items[0]; + +// fprintf(stderr,"#o=%d",noutput_items); + + assert( d_ii >= 0 ); + + while ( d_ii < noutput_items ) { + //clock symbols + + gr_complex sample = d_interp->interpolate (&in[d_ii], d_mu); + + gr_complex conjprod = sample * conj(d_last_sample); + float diff_angle = gr_fast_atan2f(imag(conjprod), real(conjprod)); + + d_last_sample = sample; + +#if 1 + assert(d_bbuf_pos <= BBUF_SIZE ); + + if (d_bbuf_pos >= 0) { //could be negative offset from burst alignment. TODO: perhaps better just to add some padding to the buffer + d_burst_buffer[d_bbuf_pos] = diff_angle; + d_complex_burst[d_bbuf_pos] = sample; + } + + d_bbuf_pos++; + + if ( d_bbuf_pos >= BBUF_SIZE ) { + if (get_burst()) { + //adjust timing + //TODO: generate timing error from burst buffer (phase & freq) + + switch ( d_clock_options & QB_MASK ) { + case QB_QUARTER: //extra 1/4 bit each burst + d_mu -= d_relative_sample_rate / 4.0; + break; + case QB_FULL04: //extra bit on timeslot 0 & 4 + if (!(d_ts%4)) + d_mu -= d_relative_sample_rate; + break; + case QB_NONE: //don't adjust for quarter bits at all + default: + break; + } + + d_last_burst_s_count = d_sample_count; + + //fprintf(stderr,"clock: %f, pos: %d\n",d_clock_counter,d_bbuf_pos); + } + } +#endif + + d_mu += d_relative_sample_rate; + d_ii += (int)floor(d_mu); + //d_sample_count += (int)floor(d_mu); //TODO: outside loop? + d_mu -= floor(d_mu); + } + + //reset d_ii, accounting for advance + d_ii -= noutput_items; + +// fprintf(stderr,"/mu=%f",d_mu); +// fprintf(stderr,"/ii=%d\n",d_ii); + + return noutput_items; +} diff --git a/gsm-tvoid/src/lib/gsm_burst_sink_c.h b/gsm-tvoid/src/lib/gsm_burst_sink_c.h new file mode 100755 index 0000000..1197a2c --- /dev/null +++ b/gsm-tvoid/src/lib/gsm_burst_sink_c.h @@ -0,0 +1,54 @@ +#ifndef INCLUDED_gsm_burst_sink_c_H +#define INCLUDED_gsm_burst_sink_c_H + +#include <gr_sync_block.h> +#include <gsm_burst.h> + +class gsm_burst_sink_c; + +typedef boost::shared_ptr<gsm_burst_sink_c> gsm_burst_sink_c_sptr; + +gsm_burst_sink_c_sptr gsm_make_burst_sink_c(gr_feval_ll *,float); + +class gri_mmse_fir_interpolator_cc; + +//class gsm_burst_sink_c : public gr_block, public gsm_burst +class gsm_burst_sink_c : public gr_sync_block, public gsm_burst +{ +private: + + friend gsm_burst_sink_c_sptr gsm_make_burst_sink_c(gr_feval_ll *,float); + gsm_burst_sink_c(gr_feval_ll *,float); + + //clocking parameters + double d_sample_interval; + double d_clock_counter; + gr_complex d_last_sample; + + float d_relative_sample_rate; //omega + float d_mu; + int d_ii; //save index between work calls for interp advance + + gri_mmse_fir_interpolator_cc *d_interp; //sub-sample interpolator from GR + + gr_complex d_complex_burst[BBUF_SIZE]; + + void shift_burst(int shift_bits); + +public: + ~gsm_burst_sink_c (); + +// void forecast (int noutput_items, gr_vector_int &ninput_items_required); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + +/* int general_work ( int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +*/ +}; + +#endif /* INCLUDED_gsm_burst_sink_c_H */ diff --git a/gsm-tvoid/src/lib/gsm_constants.h b/gsm-tvoid/src/lib/gsm_constants.h index c404b57..c404b57 100755..100644 --- a/gsm-tvoid/src/lib/gsm_constants.h +++ b/gsm-tvoid/src/lib/gsm_constants.h diff --git a/gsm-tvoid/src/python/gsm_scan.py b/gsm-tvoid/src/python/gsm_scan.py index 5d48ce5..6d25fd3 100755 --- a/gsm-tvoid/src/python/gsm_scan.py +++ b/gsm-tvoid/src/python/gsm_scan.py @@ -1,13 +1,15 @@ #!/usr/bin/env python # TODO: -# * Adjust offset by PPM -# * Auto-tune offset (add option to enable) # * Add status info to window (frequency, offset, etc) # * Put direct frequency tuning back # * Add rate-limited file reads (throttle?) # * Make console only version # * Reset burst_stats on retune # * Add better option checking +# * Wideband (multi-channel) processing (usrp and/or file input) +# * Automatic beacon scan (quick scan RSSI, then check for BCCH) +# * AGC +# * Refactor, this is too messy import sys @@ -26,6 +28,62 @@ from math import pi import wx import gsm + +class burst_callback(gr.feval_ll): + def __init__(self, fg): + gr.feval_ll.__init__(self) + self.fg = fg + self.offset_mean_num = 10 #number of FCCH offsets to average + self.offset_vals = [] + + def eval(self, x): + #print "burst_callback: eval(",x,")\n"; + try: + #TODO: rework so this will work on file input + if gsm.BURST_CB_SYNC_OFFSET == x: + #print "burst_callback: SYNC_OFFSET\n"; + if self.fg.options.tuning.count("o"): + last_offset = self.fg.burst.last_freq_offset() + self.fg.offset -= last_offset + #print "burst_callback: SYNC_OFFSET:", last_offset, " ARFCN: ", self.fg.channel, "\n"; + self.fg.set_channel(self.fg.channel) + + elif gsm.BURST_CB_ADJ_OFFSET == x: + last_offset = self.fg.burst.last_freq_offset() + + self.offset_vals.append(last_offset) + count = len(self.offset_vals) + #print "burst_callback: ADJ_OFFSET:", last_offset, ", count=",count,"\n"; + + if count >= self.offset_mean_num: + sum = 0.0 + while len(self.offset_vals): + sum += self.offset_vals.pop(0) + + self.fg.mean_offset = sum / self.offset_mean_num + + #print "burst_callback: mean offset:", self.fg.mean_offset, "\n"; + + #retune if greater than 100 Hz + if abs(self.fg.mean_offset) > 100.0: + #print "burst_callback: mean offset adjust:", self.fg.mean_offset, "\n"; + if self.fg.options.tuning.count("o"): + #print "burst_callback: tuning.\n"; + self.fg.offset -= self.fg.mean_offset + self.fg.set_channel(self.fg.channel) + + elif gsm.BURST_CB_TUNE == x and self.fg.options.tuning.count("h"): + #print "burst_callback: BURST_CB_TUNE: ARFCN: ", self.fg.burst.next_arfcn, "\n"; + if self.fg.options.tuning.count("h"): + #print "burst_callback: tuning.\n"; + self.fg.set_channel(self.fg.burst.next_arfcn) + + return 0 + + except Exception, e: + print "burst_callback: Exception: ", e + + def pick_subdevice(u): if u.db[0][0].dbid() >= 0: return (0, 0) @@ -73,6 +131,9 @@ class app_flow_graph(stdgui.gui_flow_graph): def __init__(self, frame, panel, vbox, argv): stdgui.gui_flow_graph.__init__(self) + #testing + self.status_msg = "Started." + self.frame = frame self.panel = panel @@ -100,10 +161,15 @@ class app_flow_graph(stdgui.gui_flow_graph): help="Sample clock offset frequency") parser.add_option("-E", "--equalizer", type="string", default="none", help="Type of equalizer to use. none, fixed-dfe [default=%default]") - parser.add_option("-t", "--timing", type="string", default="cq", + parser.add_option("-t", "--timing", type="string", default="cn", help="Type of timing techniques to use. [default=%default] \n" + "(n)one, (c)orrelation track, (q)uarter bit, (f)ull04 ") + #tuning options + parser.add_option("-T", "--tuning", type="string", default="oh", + help="Type of tuning to perform. [default=%default] \n" + + "(n)one, (o)ffset adjustment, (h)opping ") + #file options parser.add_option("-I", "--inputfile", type="string", default=None, help="Select a capture file to read") @@ -115,10 +181,17 @@ class app_flow_graph(stdgui.gui_flow_graph): #usrp options parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None, help="Select USRP Rx side A or B (default=first one with a daughterboard)") + parser.add_option("--fusb-block-size", type="int", default=0, + help="Set USRP blocksize") + parser.add_option("--fusb-nblocks", type="int", default=0, + help="Set USRP block buffers") + parser.add_option("--realtime",action="store_true", dest="realtime", + help="Use realtime scheduling.") + #FIXME: gain not working? parser.add_option("-g", "--gain", type="eng_float", default=None, help="Set gain in dB (default is midpoint)") - parser.add_option("-c", "--channel", type="int", default=None, + parser.add_option("-c", "--channel", type="int", default=1, help="Tune to GSM ARFCN. Overrides --freq") parser.add_option("-r", "--region", type="string", default="u", help="Frequency bands to use for channels. (u)s or (e)urope [default=%default]") @@ -134,6 +207,8 @@ class app_flow_graph(stdgui.gui_flow_graph): self.region = options.region self.channel = options.channel self.offset = options.offset + + self.mean_offset = 0.0 #this is relative averaged freq offset self.print_status = options.print_console.count('s') @@ -164,6 +239,31 @@ class app_flow_graph(stdgui.gui_flow_graph): gsm_symb_rate = 1625000.0 / 6.0 sps = input_rate/gsm_symb_rate + # Attempt to enable realtime scheduling + if options.realtime: + r = gr.enable_realtime_scheduling() + if r == gr.RT_OK: + realtime = True + print "Realtime scheduling ENABLED" + else: + realtime = False + print "Realtime scheduling FAILED" + + #set resonable defaults if no user prefs set + if options.realtime: # be more aggressive + if options.fusb_block_size == 0: + options.fusb_block_size = gr.prefs().get_long('fusb', 'rt_block_size', 1024) + if options.fusb_nblocks == 0: + options.fusb_nblocks = gr.prefs().get_long('fusb', 'rt_nblocks', 16) + else: + if options.fusb_block_size == 0: + options.fusb_block_size = gr.prefs().get_long('fusb', 'block_size', 4096) + if options.fusb_nblocks == 0: + options.fusb_nblocks = gr.prefs().get_long('fusb', 'nblocks', 16) + + print "fusb_block_size =", options.fusb_block_size + print "fusb_nblocks =", options.fusb_nblocks + # Build the flowgraph # Setup our input source if options.inputfile: @@ -172,7 +272,8 @@ class app_flow_graph(stdgui.gui_flow_graph): self.source = gr.file_source(gr.sizeof_gr_complex, options.inputfile, options.fileloop) else: self.using_usrp = True - self.u = usrp.source_c(decim_rate=options.decim) + self.u = usrp.source_c(decim_rate=options.decim,fusb_block_size=options.fusb_block_size,fusb_nblocks=options.fusb_nblocks) + if options.rx_subdev_spec is None: options.rx_subdev_spec = pick_subdevice(self.u) self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) @@ -201,6 +302,7 @@ class app_flow_graph(stdgui.gui_flow_graph): else: offset = 0.0 + #TODO: try a differnet filter for latency (and CPU) filter_taps = gr.firdes.low_pass(1.0, input_rate, filter_cutoff, filter_t_width, gr.firdes.WIN_HAMMING) self.filter = gr.freq_xlating_fir_filter_ccf(1, filter_taps, offset, input_rate) @@ -217,9 +319,17 @@ class app_flow_graph(stdgui.gui_flow_graph): if self.scopes.count("I"): self.connect(self.u, self.input_fft_scope) + #create a tuner callback + self.burst_cb = burst_callback(self) + # Setup flow based on decoder selection if options.decoder.count("c"): - self.burst = gsm.burst_cf(input_rate) + #use the sink version if burst scope not selected + if self.scopes.count("b"): + self.burst = gsm.burst_cf(self.burst_cb,input_rate) + else: + self.burst = gsm.burst_sink_c(self.burst_cb,input_rate) + self.connect(self.filter, self.burst) elif options.decoder.count("f"): @@ -236,7 +346,7 @@ class app_flow_graph(stdgui.gui_flow_graph): gain_mu, 0.3) #omega_relative_limit, - self.burst = gsm.burst_ff() + self.burst = gsm.burst_ff(self.burst_cb) self.connect(self.filter, self.demod, self.clocker, self.burst) if self.scopes.count("d"): @@ -247,31 +357,6 @@ class app_flow_graph(stdgui.gui_flow_graph): self.clocked_scope = scopesink.scope_sink_f(self, panel, sample_rate=gsm_symb_rate,v_scale=1) self.connect(self.clocker, self.clocked_scope) - elif options.decoder.count("F"): - #configure clock recovery - gain_mu = 0.01 - gain_omega = .25 * gain_mu * gain_mu # critically damped - self.clocker = gr.clock_recovery_mm_cc( sps, - gain_omega, - 0.5, #mu - gain_mu, - 0.3) #omega_relative_limit, - - - # configure demodulator - self.demod = gr.quadrature_demod_cf(1); - - self.burst = gsm.burst_ff() - self.connect(self.filter, self.clocker, self.demod, self.burst) - - if self.scopes.count("d"): - self.demod_scope = scopesink.scope_sink_f(self, panel, sample_rate=input_rate) - self.connect(self.demod, self.demod_scope) - - if self.scopes.count("c"): - self.clocked_scope = scopesink.scope_sink_f(self, panel, sample_rate=gsm_symb_rate,v_scale=1) - self.connect(self.clocker, self.clocked_scope) - # setup decoder parameters # equalizer @@ -344,30 +429,26 @@ class app_flow_graph(stdgui.gui_flow_graph): popts |= gsm.PRINT_GSM_DECODE #TODO: should warn if PRINT_GSM_DECODE is combined with other flags (will corrupt output for gsmdecode) - self.burst.d_print_options = popts - ########################## - #set burst tuning callback - #self.tuner = gsm_tuner() - #self.burst.set_tuner_callback(self.tuner) - - # connect the primary path after source - self.v2s = gr.vector_to_stream(gr.sizeof_float,142) #burst output is 142 (USEFUL_BITS) - self.connect(self.burst, self.v2s) # create and connect the scopes that apply to all decoders if self.scopes.count("F"): self.filter_fft_scope = fftsink.fft_sink_c (self, panel, fft_size=1024, sample_rate=input_rate) self.connect(self.filter, self.filter_fft_scope) + # connect the burst output + if self.scopes.count("b") or options.outputfile: + self.v2s = gr.vector_to_stream(gr.sizeof_float,142) #burst output is 142 (USEFUL_BITS) + self.connect(self.burst, self.v2s) +# else: +# self.burst_sink = gr.null_sink(gr.sizeof_float) +# self.connect(self.v2s, self.burst_sink) + #Connect output sinks if self.scopes.count("b"): self.burst_scope = scopesink.scope_sink_f(self, panel, sample_rate=gsm_symb_rate,v_scale=1) self.connect(self.v2s, self.burst_scope) - elif not options.outputfile: - self.burst_sink = gr.null_sink(gr.sizeof_float) - self.connect(self.v2s, self.burst_sink) # setup & connect output file if options.outputfile: @@ -383,6 +464,9 @@ class app_flow_graph(stdgui.gui_flow_graph): self.t1.Start(5000,0) self.frame.Bind(wx.EVT_TIMER, self.on_tick) + #bind the idle routing for message_queue processing + self.frame.Bind(wx.EVT_IDLE, self.on_idle) + def _set_status_msg(self, msg): self.frame.GetStatusBar().SetStatusText(msg, 0) @@ -428,22 +512,28 @@ class app_flow_graph(stdgui.gui_flow_graph): callback=self.set_channel) vbox.Add(hbox, 0, wx.EXPAND) - + def set_freq(self, freq): - + #TODO: for wideband processing, determine if the desired freq is within our current sample range. + # If so, use the frequency translator to tune. Tune the USRP otherwise. + # Maybe have a flag to force tuning the USRP? + if not self.using_usrp: - return False + #if reading from file just adjust for offset in the freq translator + print "Setting filter center freq to offset: ", self.offset, "\n" + self.filter.set_center_freq(self.offset) + return True freq = freq - self.offset r = self.u.tune(0, self.subdev, freq) if r: - self._set_status_msg('%f' % (freq/1e6)) + self.status_msg = '%f' % (freq/1e6) return True else: - self._set_status_msg("Failed to set frequency (%f)" % (freq/1e6)) + self.status_msg = "Failed to set frequency (%f)" % (freq/1e6) return False def set_gain(self, gain): @@ -455,23 +545,24 @@ class app_flow_graph(stdgui.gui_flow_graph): def set_channel(self, chan): - if not self.using_usrp: - return False + self.chan = chan freq = get_freq_from_arfcn(chan,self.region) if freq: self.set_freq(freq) else: - self._set_status_msg("Invalid Channel") + self.status_msg = "Invalid Channel" def print_stats(self): + n_total = self.burst.d_total_count n_unknown = self.burst.d_unknown_count n_known = n_total - n_unknown print "======== STATS =========" - print 'freq_offset: ',self.burst.mean_freq_offset() + print 'freq_offset: ',self.offset + print 'mean_offset: ',self.mean_offset print 'sync_loss_count:',self.burst.d_sync_loss_count print 'total_bursts: ',n_total print 'fcch_count: ',self.burst.d_fcch_count @@ -491,7 +582,13 @@ class app_flow_graph(stdgui.gui_flow_graph): if self.print_status: self.print_stats() - + + def on_idle(self, event): + #We can't update this while in the tune functions since they can be invoked by callbaks and the GUI croaks... + #FIXME: This is icky. + self._set_status_msg(self.status_msg) + #print "Idle.\n"; + def main (): app = stdgui.stdapp(app_flow_graph, "GSM Scanner", nstatus=1) app.MainLoop() |