From c8a37f2e8ad0ec719cda1ee6a0e50e7731502cee Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 21 Feb 2008 02:37:14 +0000 Subject: tvoid's patch 0001 - 0005 --- gsm-tvoid/src/lib/gsm.i | 45 +++--- gsm-tvoid/src/lib/gsm_burst.cc | 279 +++++++++++++++++++++++++++----------- gsm-tvoid/src/lib/gsm_burst.h | 37 +++-- gsm-tvoid/src/lib/gsm_burst_cf.cc | 3 +- gsm-tvoid/src/lib/gsm_burst_ff.cc | 6 +- gsm-tvoid/src/lib/gsm_burst_ff.h | 4 +- gsm-tvoid/src/lib/gsm_constants.h | 1 + 7 files changed, 257 insertions(+), 118 deletions(-) (limited to 'gsm-tvoid/src') diff --git a/gsm-tvoid/src/lib/gsm.i b/gsm-tvoid/src/lib/gsm.i index cb4db43..d990e8b 100755 --- a/gsm-tvoid/src/lib/gsm.i +++ b/gsm-tvoid/src/lib/gsm.i @@ -1,17 +1,15 @@ /* -*- c++ -*- */ - -%feature("autodoc", "1"); // generate python docstrings - -%include "exception.i" +//%feature("autodoc", "1"); // generate python docstrings +//%include "exception.i" %import "gnuradio.i" // the common stuff %{ #include "gnuradio_swig_bug_workaround.h" // mandatory bug fix -#include "gsm_constants.h" -#include "gsm_burst.h" +//#include "gsm_constants.h" +//#include "gsm_burst.h" #include "gsm_burst_ff.h" #include "gsm_burst_cf.h" -#include +//#include %} @@ -22,9 +20,10 @@ #define PRINT_BITS 0x00000001 #define PRINT_ALL_BITS 0x00000002 #define PRINT_CORR_BITS 0x00000004 +#define PRINT_STATE 0x00000008 #define PRINT_ALL_TYPES 0x00000FF0 -#define PRINT_KNOWN 0x00000008 +#define PRINT_KNOWN 0x00000FE0 #define PRINT_UNKNOWN 0x00000010 #define PRINT_TS0 0x00000020 #define PRINT_FCCH 0x00000040 @@ -32,6 +31,9 @@ #define PRINT_DUMMY 0x00000100 #define PRINT_NORMAL 0x00000200 +#define PRINT_GSM_DECODE 0x00000400 + +#define PRINT_HEX 0x00001000 //Timing/clock options #define QB_NONE 0x00000000 @@ -51,8 +53,9 @@ enum EQ_TYPE { EQ_VITERBI }; -class gsm_burst -{ +//GR_SWIG_BLOCK_MAGIC(gsm,burst); + +class gsm_burst { public: ~gsm_burst (); @@ -68,35 +71,37 @@ public: long d_normal_count; long d_dummy_count; long d_unknown_count; + long d_total_count; int sync_state(); - float freq_offset(); + float last_freq_offset(void); + double mean_freq_offset(void); + + //Methods + void full_reset(void); protected: gsm_burst(); }; -GR_SWIG_BLOCK_MAGIC(gsm,burst_ff); +GR_SWIG_BLOCK_MAGIC(gsm,burst_ff); gsm_burst_ff_sptr gsm_make_burst_ff (); -class gsm_burst_ff : public gr_block, public gsm_burst -{ -//public: +class gsm_burst_ff : public gr_block, public gsm_burst { private: gsm_burst_ff (); }; - GR_SWIG_BLOCK_MAGIC(gsm,burst_cf); - gsm_burst_cf_sptr gsm_make_burst_cf (float); -class gsm_burst_cf : public gr_block, public gsm_burst -{ -//public: +class gsm_burst_cf : public gr_block, public gsm_burst { private: gsm_burst_cf (float); }; + + + diff --git a/gsm-tvoid/src/lib/gsm_burst.cc b/gsm-tvoid/src/lib/gsm_burst.cc index 5415b2f..67d0886 100755 --- a/gsm-tvoid/src/lib/gsm_burst.cc +++ b/gsm-tvoid/src/lib/gsm_burst.cc @@ -3,44 +3,26 @@ #include "config.h" #endif +#include "gsm_burst.h" #include #include #include #include -#include #include #include "system.h" #include "gsmstack.h" -gsm_burst::gsm_burst (void) : - d_bbuf_pos(0), - d_burst_start(MAX_CORR_DIST), - d_sample_count(0), - d_last_burst_s_count(0), - d_corr_pattern(0), - d_corr_pat_size(0), - d_corr_max(0.0), - d_corr_maxpos(0), - d_corr_center(0), - d_sync_state(WAIT_FCCH), - d_ts(0), - d_burst_count(0), - d_freq_offset(0.0), - d_sync_loss_count(0), - d_fcch_count(0), - d_part_sch_count(0), - d_sch_count(0), - d_normal_count(0), - d_dummy_count(0), - d_unknown_count(0), + +gsm_burst::gsm_burst () : d_clock_options(DEFAULT_CLK_OPTS), d_print_options(0), d_equalizer_type(EQ_FIXED_DFE) - { - + // M_PI = M_PI; //4.0 * atan(1.0); + full_reset(); + //encode sync bits float tsync[N_SYNC_BITS]; @@ -48,14 +30,14 @@ gsm_burst::gsm_burst (void) : tsync[i] = 2.0*SYNC_BITS[i] - 1.0; } - fprintf(stdout," Sync: "); + fprintf(stderr," Sync: "); print_bits(tsync,N_SYNC_BITS); - fprintf(stdout,"\n"); + fprintf(stderr,"\n"); diff_encode(tsync,corr_sync,N_SYNC_BITS); - fprintf(stdout,"DSync: "); + fprintf(stderr,"DSync: "); print_bits(corr_sync,N_SYNC_BITS); - fprintf(stdout,"\n\n"); + fprintf(stderr,"\n\n"); for (int i=0; i < 10; i++) { @@ -64,9 +46,9 @@ gsm_burst::gsm_burst (void) : } diff_encode(tsync,corr_train_seq[i],N_TRAIN_BITS); - fprintf(stdout,"TSC%d: ",i); + fprintf(stderr,"TSC%d: ",i); print_bits(corr_train_seq[i],N_TRAIN_BITS); - fprintf(stdout,"\n"); + fprintf(stderr,"\n"); } /* Initialize GSM Stack */ @@ -77,6 +59,55 @@ gsm_burst::~gsm_burst () { } +void gsm_burst::sync_reset(void) +{ + d_sync_state = WAIT_FCCH; + d_last_good = 0; + d_last_sch = 0; + d_burst_count = 0; +} + +//TODO: check this for thread safeness +void gsm_burst::full_reset(void) +{ + sync_reset(); + + d_sync_loss_count=0; + d_fcch_count=0; + d_part_sch_count=0; + d_sch_count=0; + d_normal_count=0; + d_dummy_count=0; + d_unknown_count=0; + d_total_count=0; + + d_freq_offset=0.0; + d_freq_off_sum=0.0; + d_freq_off_weight=0; + + d_ts=0; + + d_bbuf_pos=0; + d_burst_start=MAX_CORR_DIST; + d_sample_count=0; + d_last_burst_s_count=0; + d_corr_pattern=0; + d_corr_pat_size=0; + d_corr_max=0.0; + d_corr_maxpos=0; + d_corr_center=0; + d_last_sync_state=WAIT_FCCH; + +} + +double gsm_burst::mean_freq_offset(void) +{ + if (d_freq_off_weight) + return d_freq_off_sum / d_freq_off_weight; + else + return 0.0; +} + void gsm_burst::diff_encode(const float *in,float *out,int length,float lastbit) { for (int i=0; i < length; i++) { @@ -94,15 +125,55 @@ void gsm_burst::diff_decode(const float *in,float *out,int length,float lastbit) } } +void gsm_burst::diff_decode_burst(void) { + char lastbit = 0; + + //slice + for (int i = 0; i < USEFUL_BITS; i++) { + d_decoded_burst[i] = d_burst_buffer[d_burst_start + i] > 0 ? 0 : 1; + } + + //diff decode + for (int i=0; i < USEFUL_BITS; i++) { + d_decoded_burst[i] ^= lastbit; + lastbit = d_decoded_burst[i]; + } + +} + +void gsm_burst::print_hex(const unsigned char *data,int length) +{ + unsigned char tbyte; + int i,bitpos=0; + + assert(data); + assert(length >= 0); + + + + while (bitpos < length) { + tbyte = 0; + for (i=0; (i < 8) && (bitpos < length); i++) { + tbyte <<= 1; + tbyte |= data[bitpos++]; + } + if (i<8) + tbyte <<= 8 - i; + + fprintf(stdout,"%2.2X ",tbyte); + } +} + void gsm_burst::print_bits(const float *data,int length) { assert(data); assert(length >= 0); for (int i=0; i < length; i++) - data[i] < 0 ? fprintf(stdout,"+") : fprintf(stdout,"."); + data[i] < 0 ? fprintf(stderr,"+") : fprintf(stderr,"."); } + void gsm_burst::soft2hardbit(char *dst, const float *data, int len) { for (int i=0; i < len; i++) @@ -120,7 +191,7 @@ void gsm_burst::print_burst(void) int print = 0; - //fprintf(stdout,"p=%8.8X ", d_print_options); + //fprintf(stderr,"p=%8.8X ", d_print_options); if ( PRINT_EVERYTHING == d_print_options ) print = 1; @@ -146,28 +217,32 @@ void gsm_burst::print_burst(void) print_bits(d_burst_buffer + d_burst_start,USEFUL_BITS); } - fprintf(stdout," "); + fprintf(stderr," "); } - /* - * Pass information to GSM stack. GSM stack will try to extract - * information (fn, layer 2 messages, ...) - */ - - char buf[156]; - /* In hardbits include the 3 trial bits */ - /* FIXME: access burst has 8 trail bits? what is d_burst_start - * set to? make sure we start at the right position here. - */ - soft2hardbit(buf, d_burst_buffer + d_burst_start - 3, 156); - /* GS_process will differentially decode the data and then - * extract SCH infos (and later bcch infos). - */ - GS_process(&d_gs_ctx, d_ts, d_burst_type, buf); + if ( PRINT_GSM_DECODE == d_print_options ) { + + /* + * Pass information to GSM stack. GSM stack will try to extract + * information (fn, layer 2 messages, ...) + */ + + char buf[156]; + /* In hardbits include the 3 trial bits */ + /* FIXME: access burst has 8 trail bits? what is d_burst_start + * set to? make sure we start at the right position here. + */ + soft2hardbit(buf, d_burst_buffer + d_burst_start - 3, 156); + /* GS_process will differentially decode the data and then + * extract SCH infos (and later bcch infos). + */ + GS_process(&d_gs_ctx, d_ts, d_burst_type, buf); + } + if (print) { - fprintf(stdout,"%d/%d/%+d/%lu/%lu ", + fprintf(stderr,"%d/%d/%+d/%lu/%lu ", d_sync_state, d_ts, d_burst_start - MAX_CORR_DIST, @@ -176,38 +251,38 @@ void gsm_burst::print_burst(void) switch (d_burst_type) { case FCCH: - fprintf(stdout,"[FCCH] foff:%g cnt:%lu",d_freq_offset,d_fcch_count); + fprintf(stderr,"[FCCH] foff:%g cnt:%lu",d_freq_offset,d_fcch_count); break; case PARTIAL_SCH: bursts_since_sch = d_burst_count - d_last_sch; - fprintf(stdout,"[P-SCH] cor:%.2f last:%d cnt: %lu", + fprintf(stderr,"[P-SCH] cor:%.2f last:%d cnt: %lu", d_corr_max,bursts_since_sch,d_sch_count); break; case SCH: bursts_since_sch = d_burst_count - d_last_sch; - fprintf(stdout,"[SCH] cor:%.2f last:%d cnt: %lu", + fprintf(stderr,"[SCH] cor:%.2f last:%d cnt: %lu", d_corr_max,bursts_since_sch,d_sch_count); break; case DUMMY: - fprintf(stdout,"[DUMMY] cor:%.2f",d_corr_max); + fprintf(stderr,"[DUMMY] cor:%.2f",d_corr_max); break; case ACCESS: - fprintf(stdout,"[ACCESS]"); //We don't detect this yet + fprintf(stderr,"[ACCESS]"); //We don't detect this yet break; case NORMAL: - fprintf(stdout,"[NORM] clr:%d cor:%.2f",d_color_code,d_corr_max); + fprintf(stderr,"[NORM] clr:%d cor:%.2f",d_color_code,d_corr_max); break; case UNKNOWN: - fprintf(stdout,"[?]"); + fprintf(stderr,"[?]"); break; default: - fprintf(stdout,"[oops! default]"); + fprintf(stderr,"[oops! default]"); break; } - fprintf(stdout,"\n"); + fprintf(stderr,"\n"); //print the correlation pattern for visual inspection @@ -224,20 +299,39 @@ void gsm_burst::print_burst(void) pat_indent = d_corr_center - MAX_CORR_DIST; //useful bits will already be offset for (int i = 0; i < pat_indent; i++) - fprintf(stdout," "); + fprintf(stderr," "); - fprintf(stdout," "); //extra space for skipped bit + fprintf(stderr," "); //extra space for skipped bit print_bits(d_corr_pattern+1,d_corr_pat_size-1); //skip first bit (diff encoding) - fprintf(stdout,"\t\toffset:%d, max: %.2f \n",d_corr_maxpos,d_corr_max); + fprintf(stderr,"\t\toffset:%d, max: %.2f \n",d_corr_maxpos,d_corr_max); } } + + //Print Burst data in hex + if ( d_print_options & PRINT_HEX ) { + fprintf(stdout,"%d,%d,",d_ts,d_burst_type); + diff_decode_burst(); + print_hex(d_decoded_burst,USEFUL_BITS); + fprintf(stdout,"\n"); + } + + //Print State related messages + if ( d_print_options & PRINT_STATE ) { + if ( (SYNCHRONIZED == d_sync_state) && (SYNCHRONIZED != d_last_sync_state) ) { + fprintf(stderr,"====== SYNC GAINED (FOff: %g Corr: %.2f, Color: %d ) ======\n",d_freq_offset,d_corr_max,d_color_code); + } + else if ( (SYNCHRONIZED != d_sync_state) && (SYNCHRONIZED == d_last_sync_state) ) { + fprintf(stderr,"====== SYNC LOST (%ld) ======\n",d_sync_loss_count); + } + } + } void gsm_burst::shift_burst(int shift_bits) { - //fprintf(stdout,"sft:%d\n",shift_bits); + //fprintf(stderr,"sft:%d\n",shift_bits); assert(shift_bits >= 0); assert(shift_bits < BBUF_SIZE ); @@ -273,6 +367,14 @@ void gsm_burst::calc_freq_offset(void) float p_off = mean - (M_PI / 2); d_freq_offset = p_off * 1625000.0 / (12.0 * M_PI); + + //maintain a 100 weight mean + if (d_freq_off_weight < 100) + d_freq_off_weight++; + else + d_freq_off_sum *= 99.0/100.0; + + d_freq_off_sum += d_freq_offset; } // This will look for a series of positive phase differences comprising @@ -292,10 +394,12 @@ BURST_TYPE gsm_burst::get_fcch_burst(void) if (d_burst_buffer[i] > 0) { if ( ! hit_count++ ) start_pos = i; - } else { + } + else { if (hit_count >= FCCH_HITS_NEEDED) { break; - } else if ( ++miss_count > FCCH_MAX_MISSES ) { + } + else if ( ++miss_count > FCCH_MAX_MISSES ) { start_pos = -1; hit_count = miss_count = 0; } @@ -310,11 +414,13 @@ BURST_TYPE gsm_burst::get_fcch_burst(void) d_bbuf_pos = 0; //load buffer from start return FCCH; - } else { + } + else { //TODO: don't shift a tiny amount shift_burst(start_pos - MAX_CORR_DIST); } - } else { + } + else { //Didn't find anything d_burst_start = MAX_CORR_DIST; d_bbuf_pos = 0; //load buffer from start @@ -344,7 +450,7 @@ void gsm_burst::equalize(void) } break; default: - fprintf(stdout,"!EQ"); + fprintf(stderr,"!EQ"); case EQ_NONE: break; } @@ -408,7 +514,8 @@ BURST_TYPE gsm_burst::get_sch_burst(void) } else { type = SCH; } - } else { + } + else { d_burst_start = MAX_CORR_DIST; } @@ -434,7 +541,8 @@ BURST_TYPE gsm_burst::get_norm_burst(void) d_burst_start = MAX_CORR_DIST; d_corr_maxpos = 0; //we don't want to affect timing - } else { + } + else { equalize(); eq=1; @@ -451,7 +559,8 @@ BURST_TYPE gsm_burst::get_norm_burst(void) if ( NORM_CORR_THRESHOLD < correlate_pattern(corr_train_seq[TS_DUMMY],N_TRAIN_BITS,MAX_CORR_DIST+TRAIN_POS,MAX_CORR_DIST) ) { type = DUMMY; - } else { + } + else { //Match normal training sequences //TODO: start with current color code for (int i=0; i < 8; i++) { @@ -493,7 +602,8 @@ int gsm_burst::get_burst(void) d_sync_state = WAIT_SCH_ALIGN; d_bbuf_pos = 0; //load buffer from start - } else { + } + else { got_burst = 0; } @@ -565,7 +675,21 @@ int gsm_burst::get_burst(void) break; } + if (UNKNOWN != d_burst_type) { + 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) { + d_sync_loss_count++; + sync_reset(); + } + if (got_burst) { + d_total_count++; + //print info print_burst(); @@ -574,19 +698,10 @@ int gsm_burst::get_burst(void) d_bbuf_pos += MAX_CORR_DIST - d_burst_start; } - //Check for loss of sync - int bursts_since_sch = d_burst_count - d_last_sch; - if (bursts_since_sch > MAX_SYNC_WAIT) { - d_sync_loss_count++; - d_sync_state = WAIT_FCCH; - d_last_sch = 0; - d_burst_count = 0; - fprintf(stdout,"====== SYNC LOST (%ld) ======\n",d_sync_loss_count); //TODO: move this to the print routine - } - + d_last_sync_state = d_sync_state; + d_ts = (++d_ts)%8; //next TS return got_burst; } - diff --git a/gsm-tvoid/src/lib/gsm_burst.h b/gsm-tvoid/src/lib/gsm_burst.h index 951cef2..def20e0 100755 --- a/gsm-tvoid/src/lib/gsm_burst.h +++ b/gsm-tvoid/src/lib/gsm_burst.h @@ -6,19 +6,23 @@ // everything but I/O & clocking & sync_state? // What about handling complex&diff&bin data? -#include +#include "gsm_constants.h" #include +//#include //for callback testing +#include #include "gsmstack.h" + //Console printing options #define PRINT_NOTHING 0x00000000 #define PRINT_EVERYTHING 0x7FFFFFFF //7 for SWIG overflow check work around #define PRINT_BITS 0x00000001 #define PRINT_ALL_BITS 0x00000002 #define PRINT_CORR_BITS 0x00000004 +#define PRINT_STATE 0x00000008 #define PRINT_ALL_TYPES 0x00000FF0 -#define PRINT_KNOWN 0x00000008 +#define PRINT_KNOWN 0x00000FE0 #define PRINT_UNKNOWN 0x00000010 #define PRINT_TS0 0x00000020 #define PRINT_FCCH 0x00000040 @@ -26,6 +30,10 @@ #define PRINT_DUMMY 0x00000100 #define PRINT_NORMAL 0x00000200 +#define PRINT_GSM_DECODE 0x00000400 + +#define PRINT_HEX 0x00001000 + //Timing/clock options #define QB_NONE 0x00000000 #define QB_QUARTER 0x00000001 //only for internal clocked versions @@ -46,7 +54,7 @@ // G T D1 TS D2 T G // Start ^ -#define MAX_SYNC_WAIT 176 //Bursts between SCH before reverting to WAIT_FCCH. (TODO: 88 should be max?) +#define MAX_SYNC_WAIT 32 //Number of missed bursts before reverting to WAIT_FCCH. #define MAX_CORR_DIST 7 // 4 + 3 = 1/2 GUARD + TAIL #define SCH_CORR_THRESHOLD 0.80 @@ -80,11 +88,11 @@ protected: unsigned long d_sample_count; //sample count at end (TODO:beginning) of BBUF (bit count if external clock) unsigned long d_last_burst_s_count; //sample count from previous burst + unsigned char d_decoded_burst[USEFUL_BITS]; //Differentially Decoded burst buffer {0,1} + ///// Sync/training sequence correlation - //TODO: need all sync patterns float corr_sync[N_SYNC_BITS]; //encoded sync bits for correlation float corr_train_seq[10][N_TRAIN_BITS]; -// float d_corr[50]; const float *d_corr_pattern; int d_corr_pat_size; float d_corr_max; @@ -96,13 +104,18 @@ protected: ///// Burst information SYNC_STATE d_sync_state; + SYNC_STATE d_last_sync_state; BURST_TYPE d_burst_type; unsigned d_ts; //timeslot 0-7 + unsigned long d_last_good; //Burst count of last good burst unsigned long d_burst_count; //Bursts received starting w/ initial FCCH reset after lost sync unsigned long d_last_sch; //Burst count of last SCH - float d_freq_offset; int d_color_code; + float d_freq_offset; + double d_freq_off_sum; + double d_freq_off_weight; + //////// Methods int get_burst(void); BURST_TYPE get_fcch_burst(void); @@ -113,15 +126,18 @@ protected: void calc_freq_offset(void); void equalize(void); float correlate_pattern(const float *,const int,const int,const int); + void diff_decode_burst(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 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 (); @@ -134,6 +150,7 @@ public: long d_normal_count; long d_dummy_count; long d_unknown_count; + long d_total_count; ////// Options unsigned long d_clock_options; @@ -141,11 +158,11 @@ public: EQ_TYPE d_equalizer_type; int sync_state() { return d_sync_state;} - float freq_offset() {return d_freq_offset;} + float last_freq_offset() {return d_freq_offset;} + double mean_freq_offset(void); //Methods - //TODO: reset state (e.g. channel change) - //void reset(void); + void full_reset(void); }; diff --git a/gsm-tvoid/src/lib/gsm_burst_cf.cc b/gsm-tvoid/src/lib/gsm_burst_cf.cc index 8954b3f..a91c569 100755 --- a/gsm-tvoid/src/lib/gsm_burst_cf.cc +++ b/gsm-tvoid/src/lib/gsm_burst_cf.cc @@ -78,7 +78,8 @@ int gsm_burst_cf::general_work (int noutput_items, 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 = 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 gr_complex conjprod = sample * conj(d_last_sample); diff --git a/gsm-tvoid/src/lib/gsm_burst_ff.cc b/gsm-tvoid/src/lib/gsm_burst_ff.cc index e31b3a9..2980829 100755 --- a/gsm-tvoid/src/lib/gsm_burst_ff.cc +++ b/gsm-tvoid/src/lib/gsm_burst_ff.cc @@ -9,9 +9,9 @@ #include #include -gsm_burst_ff_sptr gsm_make_burst_ff (void) +gsm_burst_ff_sptr gsm_make_burst_ff () { - return gsm_burst_ff_sptr (new gsm_burst_ff ); + return gsm_burst_ff_sptr (new gsm_burst_ff()); } static const int MIN_IN = 1; // minimum number of input streams @@ -20,7 +20,7 @@ static const int MIN_OUT = 1; // minimum number of output streams static const int MAX_OUT = 1; // maximum number of output streams gsm_burst_ff::gsm_burst_ff () : - gr_block ( "burst_ff", + 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))) { diff --git a/gsm-tvoid/src/lib/gsm_burst_ff.h b/gsm-tvoid/src/lib/gsm_burst_ff.h index c9a05f4..30c10dc 100755 --- a/gsm-tvoid/src/lib/gsm_burst_ff.h +++ b/gsm-tvoid/src/lib/gsm_burst_ff.h @@ -8,13 +8,13 @@ class gsm_burst_ff; typedef boost::shared_ptr gsm_burst_ff_sptr; -gsm_burst_ff_sptr gsm_make_burst_ff(void); +gsm_burst_ff_sptr gsm_make_burst_ff(); class gsm_burst_ff : public gr_block, public gsm_burst { private: - friend gsm_burst_ff_sptr gsm_make_burst_ff(void); + friend gsm_burst_ff_sptr gsm_make_burst_ff(); gsm_burst_ff(); public: diff --git a/gsm-tvoid/src/lib/gsm_constants.h b/gsm-tvoid/src/lib/gsm_constants.h index 3cc771e..c404b57 100755 --- a/gsm-tvoid/src/lib/gsm_constants.h +++ b/gsm-tvoid/src/lib/gsm_constants.h @@ -90,6 +90,7 @@ static const unsigned char train_seq[10][N_TRAIN_BITS] = { {0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1} // DUMMY }; +//Dummy burst 0xFB 76 0A 4E 09 10 1F 1C 5C 5C 57 4A 33 39 E9 F1 2F A8 static const unsigned char dummy_burst[] = { 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, -- cgit v1.2.3 From 5634262d43aaba54a56078334e21688a3d5345b4 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 21 Feb 2008 02:37:31 +0000 Subject: tvoids pathc 0001 - 0005 --- gsm-tvoid/src/python/gsm_scan.py | 87 ++++++++++++++++++++++++++++++---------- 1 file changed, 65 insertions(+), 22 deletions(-) (limited to 'gsm-tvoid/src') diff --git a/gsm-tvoid/src/python/gsm_scan.py b/gsm-tvoid/src/python/gsm_scan.py index 42f7944..5d48ce5 100755 --- a/gsm-tvoid/src/python/gsm_scan.py +++ b/gsm-tvoid/src/python/gsm_scan.py @@ -1,9 +1,13 @@ #!/usr/bin/env python # TODO: -# * Auto-tune offset +# * 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 of file reads (Fix throttle?) +# * Add rate-limited file reads (throttle?) +# * Make console only version +# * Reset burst_stats on retune +# * Add better option checking import sys @@ -81,11 +85,12 @@ class app_flow_graph(stdgui.gui_flow_graph): help="What to print on console. [default=%default]\n" + "(n)othing, (e)verything, (s)tatus, (a)ll Types, (k)nown, (u)nknown, \n" + "TS(0), (F)CCH, (S)CH, (N)ormal, (D)ummy\n" + - "Usefull (b)its, All TS (B)its, (C)orrelation bits") + "Usefull (b)its, All TS (B)its, (C)orrelation bits, he(x) burst data, \n" + + "(d)ecoded hex for gsmdecode") #decoder options - parser.add_option("-D", "--decoder", type="string", default="c", + parser.add_option("-D", "--decoder", type="string", default="f", help="Select decoder block to use. (c)omplex,(f)loat [default=%default]") parser.add_option("-d", "--decim", type="int", default=112, help="Set fgpa decimation rate to DECIM [default=%default]") @@ -93,7 +98,7 @@ class app_flow_graph(stdgui.gui_flow_graph): help="Tuning offset frequency") parser.add_option("-C", "--clock-offset", type="eng_float", default=0.0, help="Sample clock offset frequency") - parser.add_option("-E", "--equalizer", type="string", default="fixed-dfe", + 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", help="Type of timing techniques to use. [default=%default] \n" + @@ -110,6 +115,7 @@ 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)") + #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, @@ -144,7 +150,12 @@ class app_flow_graph(stdgui.gui_flow_graph): if options.clock_offset: clock_rate = 64e6 + options.clock_offset elif options.channel: - percent_offset = options.offset / get_freq_from_arfcn(options.channel,options.region) + f = get_freq_from_arfcn(options.channel,options.region) + if f: + percent_offset = options.offset / get_freq_from_arfcn(options.channel,options.region) + else: + percent_offset = 0.0 + clock_rate += clock_rate * percent_offset print "% offset = ", percent_offset, "clock = ", clock_rate @@ -284,6 +295,9 @@ class app_flow_graph(stdgui.gui_flow_graph): #console print options popts = 0 + if options.print_console.count('s'): + popts |= gsm.PRINT_STATE + if options.print_console.count('e'): popts |= gsm.PRINT_EVERYTHING @@ -306,21 +320,37 @@ class app_flow_graph(stdgui.gui_flow_graph): popts |= gsm.PRINT_SCH if options.print_console.count('N'): - popts |= gsm.PRINT_SCH + popts |= gsm.PRINT_NORMAL if options.print_console.count('D'): - popts |= gsm.PRINT_SCH + popts |= gsm.PRINT_DUMMY + + if options.print_console.count('d'): + popts |= gsm.PRINT_GSM_DECODE if options.print_console.count('C'): popts |= gsm.PRINT_BITS | gsm.PRINT_CORR_BITS + + if options.print_console.count('x'): + popts |= gsm.PRINT_BITS | gsm.PRINT_HEX if options.print_console.count('B'): popts |= gsm.PRINT_BITS | gsm.PRINT_ALL_BITS elif options.print_console.count('b'): popts |= gsm.PRINT_BITS + + if options.print_console.count('d'): + 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 + 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) @@ -434,21 +464,34 @@ class app_flow_graph(stdgui.gui_flow_graph): self.set_freq(freq) else: self._set_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 'sync_loss_count:',self.burst.d_sync_loss_count + print 'total_bursts: ',n_total + print 'fcch_count: ',self.burst.d_fcch_count + print 'part_sch_count: ',self.burst.d_part_sch_count + print 'sch_count: ',self.burst.d_sch_count + print 'normal_count: ',self.burst.d_normal_count + print 'dummy_count: ',self.burst.d_dummy_count + print 'unknown_count: ',self.burst.d_unknown_count + print 'known_count: ',n_known + if n_total: + print '%known: ', 100.0 * n_known / n_total + print "" + def on_tick(self, evt): + #if option.autotune + #tune offset + if self.print_status: - #TODO: def print_stats: - print "======== STATS =========" - print 'freq_offset:',self.burst.freq_offset() - print 'sync_loss_count:',self.burst.d_sync_loss_count - print 'fcch_count:',self.burst.d_fcch_count - print 'part_sch_count:',self.burst.d_part_sch_count - print 'sch_count:',self.burst.d_sch_count - print 'normal_count:',self.burst.d_normal_count - print 'dummy_count:',self.burst.d_dummy_count - print 'unknown_count:',self.burst.d_unknown_count - print "" - + self.print_stats() + def main (): app = stdgui.stdapp(app_flow_graph, "GSM Scanner", nstatus=1) app.MainLoop() -- cgit v1.2.3 From 21aadd29384bfa45639940fc904592b8a7a5a073 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 21 Feb 2008 02:55:05 +0000 Subject: tvoid's suggested cleanup. --- gsm-tvoid/src/lib/gsm_burst.cc | 15 ++++----------- gsm-tvoid/src/lib/gsmstack.c | 15 +++++++-------- gsm-tvoid/src/lib/gsmstack.h | 2 +- gsm-tvoid/src/lib/sch.c | 8 ++++---- 4 files changed, 16 insertions(+), 24 deletions(-) (limited to 'gsm-tvoid/src') diff --git a/gsm-tvoid/src/lib/gsm_burst.cc b/gsm-tvoid/src/lib/gsm_burst.cc index 67d0886..b862d69 100755 --- a/gsm-tvoid/src/lib/gsm_burst.cc +++ b/gsm-tvoid/src/lib/gsm_burst.cc @@ -174,6 +174,7 @@ void gsm_burst::print_bits(const float *data,int length) } +#if 0 void gsm_burst::soft2hardbit(char *dst, const float *data, int len) { for (int i=0; i < len; i++) @@ -184,6 +185,7 @@ void gsm_burst::soft2hardbit(char *dst, const float *data, int len) dst[i] = 1; } } +#endif void gsm_burst::print_burst(void) { @@ -227,17 +229,8 @@ void gsm_burst::print_burst(void) * Pass information to GSM stack. GSM stack will try to extract * information (fn, layer 2 messages, ...) */ - - char buf[156]; - /* In hardbits include the 3 trial bits */ - /* FIXME: access burst has 8 trail bits? what is d_burst_start - * set to? make sure we start at the right position here. - */ - soft2hardbit(buf, d_burst_buffer + d_burst_start - 3, 156); - /* GS_process will differentially decode the data and then - * extract SCH infos (and later bcch infos). - */ - GS_process(&d_gs_ctx, d_ts, d_burst_type, buf); + diff_decode_burst(); + GS_process(&d_gs_ctx, d_ts, d_burst_type, d_decoded_burst); } if (print) { diff --git a/gsm-tvoid/src/lib/gsmstack.c b/gsm-tvoid/src/lib/gsmstack.c index a38ffcb..22fa170 100644 --- a/gsm-tvoid/src/lib/gsmstack.c +++ b/gsm-tvoid/src/lib/gsmstack.c @@ -14,6 +14,7 @@ static void out_gsmdecode(char type, int arfcn, int ts, int fn, char *data, int len); +#if 0 static void diff_decode(char *dst, char *src, int len) { @@ -33,6 +34,7 @@ diff_decode(char *dst, char *src, int len) dst++; } } +#endif /* * Initialize a new GSMSTACK context. @@ -49,26 +51,23 @@ GS_new(GS_CTX *ctx) } /* - * 156 bit + * 142 bit */ int -GS_process(GS_CTX *ctx, int ts, int type, char *src) +GS_process(GS_CTX *ctx, int ts, int type, const unsigned char *src) { int fn; int bsic; int ret; - char buf[156]; unsigned char *data; int len; if (ts != 0) return; - diff_decode(buf, src, 156); - if (type == SCH) { - ret = decode_sch(buf, &fn, &bsic); + ret = decode_sch(src, &fn, &bsic); if (ret != 0) return 0; if ((ctx->bsic > 0) && (bsic != ctx->bsic)) @@ -94,8 +93,8 @@ GS_process(GS_CTX *ctx, int ts, int type, char *src) */ /* Copy content data into new array */ //DEBUGF("burst count %d\n", ctx->burst_count); - memcpy(ctx->burst + (116 * ctx->burst_count), buf + 3, 58); - memcpy(ctx->burst + (116 * ctx->burst_count) + 58, buf + 3 + 58 + 26, 58); + memcpy(ctx->burst + (116 * ctx->burst_count), src, 58); + memcpy(ctx->burst + (116 * ctx->burst_count) + 58, src + 58 + 26, 58); ctx->burst_count++; /* Return if not enough bursts for a full gsm message */ if (ctx->burst_count < 4) diff --git a/gsm-tvoid/src/lib/gsmstack.h b/gsm-tvoid/src/lib/gsmstack.h index fa858ba..d79a40f 100644 --- a/gsm-tvoid/src/lib/gsmstack.h +++ b/gsm-tvoid/src/lib/gsmstack.h @@ -22,7 +22,7 @@ typedef struct } GS_CTX; int GS_new(GS_CTX *ctx); -int GS_process(GS_CTX *ctx, int ts, int type, char *data); +int GS_process(GS_CTX *ctx, int ts, int type, const unsigned char *src); #ifdef __cplusplus } diff --git a/gsm-tvoid/src/lib/sch.c b/gsm-tvoid/src/lib/sch.c index c01d7bb..d311371 100644 --- a/gsm-tvoid/src/lib/sch.c +++ b/gsm-tvoid/src/lib/sch.c @@ -243,10 +243,10 @@ int decode_sch(const unsigned char *buf, int *fn_o, int *bsic_o) { unsigned char data[CONV_SIZE], decoded_data[PARITY_OUTPUT_SIZE]; // extract encoded data from synchronization burst - /* buf + 3, 39 bit */ - /* buf + 3 + 39 + 64 = 106, 39 */ - memcpy(data, buf + SB_EDATA_OS_1, SB_EDATA_LEN_1); - memcpy(data + SB_EDATA_LEN_1, buf + SB_EDATA_OS_2, SB_EDATA_LEN_2); + /* buf, 39 bit */ + /* buf + 39 + 64 = 103, 39 */ + memcpy(data, buf, SB_EDATA_LEN_1); + memcpy(data + SB_EDATA_LEN_1, buf + SB_EDATA_LEN_1 + N_SYNC_BITS, SB_EDATA_LEN_2); // Viterbi decode if(errors = conv_decode(data, decoded_data)) { -- cgit v1.2.3