From a4c10650e03854a79f9b2244924f2a132c7c2e62 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 17 Apr 2008 13:48:57 +0100 Subject: lala --- gsm-tvoid/src/lib/Makefile.am | 2 + gsm-tvoid/src/lib/fire_crc.c | 179 ++++++++++++++++++++++++++++++++++++++++++ gsm-tvoid/src/lib/fire_crc.h | 65 +++++++++++++++ 3 files changed, 246 insertions(+) create mode 100644 gsm-tvoid/src/lib/fire_crc.c create mode 100644 gsm-tvoid/src/lib/fire_crc.h diff --git a/gsm-tvoid/src/lib/Makefile.am b/gsm-tvoid/src/lib/Makefile.am index 2d4d7f7..8a84086 100755 --- a/gsm-tvoid/src/lib/Makefile.am +++ b/gsm-tvoid/src/lib/Makefile.am @@ -38,6 +38,7 @@ ourlib_LTLIBRARIES = _gsm.la # These are the source files that go into the shared library _gsm_la_SOURCES = \ + fire_crc. \ gsmstack.c \ interleave.c \ conv.c \ @@ -63,6 +64,7 @@ gsm.cc gsm.py: $(LOCAL_IFILES) $(ALL_IFILES) # These headers get installed in ${prefix}/include/gnuradio grinclude_HEADERS = \ + fire_crc.h \ gsm_burst.h \ gsmstack.h \ interleave.h \ diff --git a/gsm-tvoid/src/lib/fire_crc.c b/gsm-tvoid/src/lib/fire_crc.c new file mode 100644 index 0000000..ea14bcb --- /dev/null +++ b/gsm-tvoid/src/lib/fire_crc.c @@ -0,0 +1,179 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "fire_crc.h" +#include +#include + +#define REM(x, y) (x) % (y) + +static int FC_syndrome_shift(FC_CTX *ctx, unsigned int bit); + +static int +outit(int *data, int len) +{ + for (int i = 0; i < len; i++) + printf("%d ", data[i]); + printf("\n"); +} + +int +FC_init(FC_CTX *ctx, unsigned int crc_size, unsigned int data_size) +{ + ctx->crc_size = crc_size; + ctx->data_size = data_size; + ctx->syn_start = 0; + + return 0; +} + +int +FC_check_crc(FC_CTX *ctx, unsigned char *input_bits, unsigned char *control_data) +{ + int j,error_count = 0, error_index = 0, success_flag = 0, syn_index = 0; + + ctx->syn_start = 0; + // reset the syndrome register + memset(ctx->syndrome_reg, 0, sizeof ctx->syndrome_reg); + // d_syndrome_reg.clear(); + //d_syndrome_reg.insert(d_syndrome_reg.begin(),40,0); + + // shift in the data bits + //for (unsigned int i=0; i < 1; i++) { + for (unsigned int i=0; i < ctx->data_size; i++) { + error_count = FC_syndrome_shift(ctx, input_bits[i]); + control_data[i] = input_bits[i]; + } + + // shift in the crc bits + for (unsigned int i=0; i < ctx->crc_size; i++) { + error_count = FC_syndrome_shift(ctx, 1-input_bits[i+ctx->data_size]); + } + + // Find position of error burst + if (error_count == 0) { + error_index = 0; + } + else { + error_index = 1; + error_count = FC_syndrome_shift(ctx, 0); + error_index += 1; + while (error_index < (ctx->data_size + ctx->crc_size) ) { + error_count = FC_syndrome_shift(ctx, 0); + error_index += 1; + if ( error_count == 0 ) break; + } + } + + // Test for correctable errors + //printf("error_index %d\n",error_index); + if (error_index == 224) success_flag = 0; + else { + + // correct index depending on the position of the error + if (error_index == 0) syn_index = error_index; + else syn_index = error_index - 1; + + // error burst lies within data bits + if (error_index < 184) { + //printf("error < bit 184,%d\n",error_index); + j = error_index; + while ( j < (error_index+12) ) { + if (j < 184) { + control_data[j] = control_data[j] ^ + ctx->syndrome_reg[REM(ctx->syn_start+39-j+syn_index,40)]; + } + else break; + j = j + 1; + } + } + else if ( error_index > 212 ) { + //printf("error > bit 212,%d\n",error_index); + j = 0; + while ( j < (error_index - 212) ) { + control_data[j] = control_data[j] ^ + ctx->syndrome_reg[REM(ctx->syn_start+39-j-224+syn_index,40)]; + j = j + 1; + } + } + // for 183 < error_index < 213 error in parity alone so ignore + success_flag = 1; + } + return success_flag; +} + +static int +FC_syndrome_shift(FC_CTX *ctx, unsigned int bit) +{ + int error_count = 0; + + if (ctx->syn_start == 0) + ctx->syn_start = 39; + else ctx->syn_start -= 1; + + int temp_syndrome_reg[sizeof ctx->syndrome_reg]; + + memcpy(temp_syndrome_reg, ctx->syndrome_reg, sizeof temp_syndrome_reg); + + //std::vector temp_syndrome_reg = ctx->syndrome_reg; + + temp_syndrome_reg[REM(ctx->syn_start+3,40)] = + ctx->syndrome_reg[REM(ctx->syn_start+3,40)] ^ + ctx->syndrome_reg[ctx->syn_start]; + temp_syndrome_reg[REM(ctx->syn_start+17,40)] = + ctx->syndrome_reg[REM(ctx->syn_start+17,40)] ^ + ctx->syndrome_reg[ctx->syn_start]; + temp_syndrome_reg[REM(ctx->syn_start+23,40)] = + ctx->syndrome_reg[REM(ctx->syn_start+23,40)] ^ + ctx->syndrome_reg[ctx->syn_start]; + temp_syndrome_reg[REM(ctx->syn_start+26,40)] = + ctx->syndrome_reg[REM(ctx->syn_start+26,40)] ^ + ctx->syndrome_reg[ctx->syn_start]; + + temp_syndrome_reg[REM(ctx->syn_start+4,40)] = + ctx->syndrome_reg[REM(ctx->syn_start+4,40)] ^ bit; + temp_syndrome_reg[REM(ctx->syn_start+6,40)] = + ctx->syndrome_reg[REM(ctx->syn_start+6,40)] ^ bit; + temp_syndrome_reg[REM(ctx->syn_start+10,40)] = + ctx->syndrome_reg[REM(ctx->syn_start+10,40)] ^ bit; + temp_syndrome_reg[REM(ctx->syn_start+16,40)] = + ctx->syndrome_reg[REM(ctx->syn_start+16,40)] ^ bit; + temp_syndrome_reg[REM(ctx->syn_start+27,40)] = + ctx->syndrome_reg[REM(ctx->syn_start+27,40)] ^ bit; + temp_syndrome_reg[REM(ctx->syn_start+29,40)] = + ctx->syndrome_reg[REM(ctx->syn_start+29,40)] ^ bit; + temp_syndrome_reg[REM(ctx->syn_start+33,40)] = + ctx->syndrome_reg[REM(ctx->syn_start+33,40)] ^ bit; + temp_syndrome_reg[REM(ctx->syn_start+39,40)] = + ctx->syndrome_reg[REM(ctx->syn_start+39,40)] ^ bit; + + temp_syndrome_reg[ctx->syn_start] = ctx->syndrome_reg[ctx->syn_start] ^ bit; + + memcpy(ctx->syndrome_reg, temp_syndrome_reg, sizeof ctx->syndrome_reg); + + for (unsigned int i = 0; i < 28; i++) { + error_count = error_count + ctx->syndrome_reg[REM(ctx->syn_start+i,40)]; + } + return error_count; +} + + diff --git a/gsm-tvoid/src/lib/fire_crc.h b/gsm-tvoid/src/lib/fire_crc.h new file mode 100644 index 0000000..91cdee3 --- /dev/null +++ b/gsm-tvoid/src/lib/fire_crc.h @@ -0,0 +1,65 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + +#ifndef INCLUDED_FIRE_CRC_H +#define INCLUDED_FIRE_CRC_H + +typedef struct +{ + unsigned int crc_size; + unsigned int data_size; + unsigned int syn_start; + int syndrome_reg[40]; +} FC_CTX; + +int FC_init(FC_CTX *ctx, unsigned int crc_size, unsigned int data_size); +int FC_check_crc(FC_CTX *ctx, unsigned char *input_bits, unsigned char *control_data); + +#if 0 +/*! + * \brief + * \ingroup + */ + +class fire_crc +{ +protected: + + unsigned int d_crc_size; + unsigned int d_data_size; + unsigned int d_syn_start; + std::vector d_syndrome_reg; + +public: + + fire_crc (unsigned int crc_size, unsigned int data_size); + ~fire_crc (); + int check_crc (const std::vector &input_bits, + std::vector &control_bits); + int syndrome_shift (unsigned int bit); + int rem (const int x, const int y); + +}; +#endif + +#endif -- cgit v1.2.3 From bec9447ae5f3547064d9cad493eee09ed2a26ad4 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 17 Apr 2008 13:49:09 +0100 Subject: lala fire code in! --- gsm-tvoid/src/lib/cch.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/gsm-tvoid/src/lib/cch.c b/gsm-tvoid/src/lib/cch.c index 8907a09..8070649 100644 --- a/gsm-tvoid/src/lib/cch.c +++ b/gsm-tvoid/src/lib/cch.c @@ -11,7 +11,7 @@ #include #include "burst_types.h" #include "cch.h" -//#include "fire_crc.h" +#include "fire_crc.h" /* * GSM SACCH -- Slow Associated Control Channel @@ -385,6 +385,7 @@ static unsigned char *decode_sacch(GS_CTX *ctx, unsigned char *burst, unsigned i int errors, len, data_size; unsigned char conv_data[CONV_SIZE], iBLOCK[BLOCKS][iBLOCK_SIZE], hl, hn, decoded_data[PARITY_OUTPUT_SIZE]; + FC_CTX fc_ctx; data_size = sizeof ctx->msg; if(datalen) @@ -410,13 +411,9 @@ static unsigned char *decode_sacch(GS_CTX *ctx, unsigned char *burst, unsigned i // If parity check error detected try to fix it. if (parity_check(decoded_data)) { - return NULL; - /* FIXME: impelment fire crc in C */ -#if 0 - fire_crc crc(40, 184); - // fprintf(stderr, "error: sacch: parity error (%d)\n", errors); + FC_init(&fc_ctx, 40, 184); unsigned char crc_result[224]; - if (crc.check_crc(decoded_data, crc_result) == 0) + if (FC_check_crc(&fc_ctx, decoded_data, crc_result) == 0) { errors = -1; DEBUGF("error: sacch: parity error (%d)\n", errors); @@ -425,7 +422,6 @@ static unsigned char *decode_sacch(GS_CTX *ctx, unsigned char *burst, unsigned i memcpy(decoded_data, crc_result, sizeof crc_result); errors = 0; } -#endif } if((len = compress_bits(ctx->msg, data_size, decoded_data, -- cgit v1.2.3 From 6e9a62d578312fcc05eda7a9efc90c1a83c6b8ce Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 17 Apr 2008 15:18:16 +0100 Subject: fire code fixup --- gsm-tvoid/src/lib/Makefile.am | 2 +- gsm-tvoid/src/lib/cch.c | 1 + gsm-tvoid/src/lib/fire_crc.c | 29 ++++++++++++++--------------- gsm-tvoid/src/lib/fire_crc.h | 31 ++++++------------------------- 4 files changed, 22 insertions(+), 41 deletions(-) diff --git a/gsm-tvoid/src/lib/Makefile.am b/gsm-tvoid/src/lib/Makefile.am index 8a84086..f4072d9 100755 --- a/gsm-tvoid/src/lib/Makefile.am +++ b/gsm-tvoid/src/lib/Makefile.am @@ -38,7 +38,7 @@ ourlib_LTLIBRARIES = _gsm.la # These are the source files that go into the shared library _gsm_la_SOURCES = \ - fire_crc. \ + fire_crc.c \ gsmstack.c \ interleave.c \ conv.c \ diff --git a/gsm-tvoid/src/lib/cch.c b/gsm-tvoid/src/lib/cch.c index 8070649..17ee4ee 100644 --- a/gsm-tvoid/src/lib/cch.c +++ b/gsm-tvoid/src/lib/cch.c @@ -419,6 +419,7 @@ static unsigned char *decode_sacch(GS_CTX *ctx, unsigned char *burst, unsigned i DEBUGF("error: sacch: parity error (%d)\n", errors); return NULL; } else { + DEBUGF("Successfully corrected parity bits!\n"); memcpy(decoded_data, crc_result, sizeof crc_result); errors = 0; } diff --git a/gsm-tvoid/src/lib/fire_crc.c b/gsm-tvoid/src/lib/fire_crc.c index ea14bcb..c9f0348 100644 --- a/gsm-tvoid/src/lib/fire_crc.c +++ b/gsm-tvoid/src/lib/fire_crc.c @@ -21,8 +21,8 @@ */ #include "fire_crc.h" -#include -#include +#include +#include #define REM(x, y) (x) % (y) @@ -31,7 +31,9 @@ static int FC_syndrome_shift(FC_CTX *ctx, unsigned int bit); static int outit(int *data, int len) { - for (int i = 0; i < len; i++) + int i; + + for (i = 0; i < len; i++) printf("%d ", data[i]); printf("\n"); } @@ -49,23 +51,21 @@ FC_init(FC_CTX *ctx, unsigned int crc_size, unsigned int data_size) int FC_check_crc(FC_CTX *ctx, unsigned char *input_bits, unsigned char *control_data) { - int j,error_count = 0, error_index = 0, success_flag = 0, syn_index = 0; + int j,error_count = 0, error_index = 0, success_flag = 0, syn_index = 0; + unsigned int i; - ctx->syn_start = 0; - // reset the syndrome register + ctx->syn_start = 0; + // reset the syndrome register memset(ctx->syndrome_reg, 0, sizeof ctx->syndrome_reg); - // d_syndrome_reg.clear(); - //d_syndrome_reg.insert(d_syndrome_reg.begin(),40,0); - // shift in the data bits - //for (unsigned int i=0; i < 1; i++) { - for (unsigned int i=0; i < ctx->data_size; i++) { + // shift in the data bits + for (i=0; i < ctx->data_size; i++) { error_count = FC_syndrome_shift(ctx, input_bits[i]); control_data[i] = input_bits[i]; } // shift in the crc bits - for (unsigned int i=0; i < ctx->crc_size; i++) { + for (i=0; i < ctx->crc_size; i++) { error_count = FC_syndrome_shift(ctx, 1-input_bits[i+ctx->data_size]); } @@ -125,6 +125,7 @@ static int FC_syndrome_shift(FC_CTX *ctx, unsigned int bit) { int error_count = 0; + unsigned int i; if (ctx->syn_start == 0) ctx->syn_start = 39; @@ -134,8 +135,6 @@ FC_syndrome_shift(FC_CTX *ctx, unsigned int bit) memcpy(temp_syndrome_reg, ctx->syndrome_reg, sizeof temp_syndrome_reg); - //std::vector temp_syndrome_reg = ctx->syndrome_reg; - temp_syndrome_reg[REM(ctx->syn_start+3,40)] = ctx->syndrome_reg[REM(ctx->syn_start+3,40)] ^ ctx->syndrome_reg[ctx->syn_start]; @@ -170,7 +169,7 @@ FC_syndrome_shift(FC_CTX *ctx, unsigned int bit) memcpy(ctx->syndrome_reg, temp_syndrome_reg, sizeof ctx->syndrome_reg); - for (unsigned int i = 0; i < 28; i++) { + for (i = 0; i < 28; i++) { error_count = error_count + ctx->syndrome_reg[REM(ctx->syn_start+i,40)]; } return error_count; diff --git a/gsm-tvoid/src/lib/fire_crc.h b/gsm-tvoid/src/lib/fire_crc.h index 91cdee3..15d5b81 100644 --- a/gsm-tvoid/src/lib/fire_crc.h +++ b/gsm-tvoid/src/lib/fire_crc.h @@ -24,6 +24,10 @@ #ifndef INCLUDED_FIRE_CRC_H #define INCLUDED_FIRE_CRC_H +#ifdef __cplusplus +extern "C" { +#endif + typedef struct { unsigned int crc_size; @@ -35,31 +39,8 @@ typedef struct int FC_init(FC_CTX *ctx, unsigned int crc_size, unsigned int data_size); int FC_check_crc(FC_CTX *ctx, unsigned char *input_bits, unsigned char *control_data); -#if 0 -/*! - * \brief - * \ingroup - */ - -class fire_crc -{ -protected: - - unsigned int d_crc_size; - unsigned int d_data_size; - unsigned int d_syn_start; - std::vector d_syndrome_reg; - -public: - - fire_crc (unsigned int crc_size, unsigned int data_size); - ~fire_crc (); - int check_crc (const std::vector &input_bits, - std::vector &control_bits); - int syndrome_shift (unsigned int bit); - int rem (const int x, const int y); - -}; +#ifdef __cplusplus +} #endif #endif -- cgit v1.2.3 From 2c893dfb32f9981e9cbd9295db4921500543277c Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 17 Apr 2008 15:18:39 +0100 Subject: channel hopping fixes. --- gsmdecode/src/common.h | 3 + gsmdecode/src/data_out.c | 381 +++++++++++++++++++++++++++++++++++------------ 2 files changed, 292 insertions(+), 92 deletions(-) diff --git a/gsmdecode/src/common.h b/gsmdecode/src/common.h index 8a3ae2e..61abc5f 100644 --- a/gsmdecode/src/common.h +++ b/gsmdecode/src/common.h @@ -22,6 +22,9 @@ # define DEBUGF(a...) #endif +/* True if bit at position 'pos' in 'data' is set */ +#define BIT(data, pos) ((data) >> (pos)) & 1 + # define HEXDUMPF(data, len, a...) do { \ printf("HEX %s:%d ", __func__, __LINE__); \ printf(a); \ diff --git a/gsmdecode/src/data_out.c b/gsmdecode/src/data_out.c index 9f35e37..b886edd 100644 --- a/gsmdecode/src/data_out.c +++ b/gsmdecode/src/data_out.c @@ -27,6 +27,10 @@ extern struct _opt opt; +/* Prototype helper functions */ +static unsigned int Bit_extract_val(unsigned char *data, int bit_pos, int numbits); + + static void l2_rrm(); static void l2_sms(); static void l2_cc(); @@ -118,6 +122,7 @@ static void simdatadownload(); static void LocationUpdateRequest(); static void MultiSupportTwo(); static void MeasurmentReport(); +static int CellAllocation(unsigned char format, char *str); static const unsigned char *start; static const unsigned char *data; @@ -572,6 +577,43 @@ l2_Bbis() /* GSM 04.07 11.2.3.2.1 */ } } +/* + * Extract up to 24 bit from a data field and return as integer. + */ +static unsigned int +Bit_extract_val(unsigned char *data, int bit_pos, int numbits) +{ + unsigned int ofs; + unsigned int val = 0; + unsigned int bit_ofs; + char len; + char overlap; + int i; + + ofs = bit_pos / 8; + bit_ofs = bit_pos % 8; + + len = ((7 - bit_ofs) + numbits + 7) / 8; + //OUTF("len = %u\n", len); + + i = 0; + while (i < len) + { + val = val << 8; + val = val | data[i + ofs]; + i++; + } + overlap = (numbits + (7 - bit_ofs)) % 8; + //OUTF("overlap = %u bit\n", overlap); + if (overlap != 0) + { + val = val >> (8 - overlap); + } + val = val & (((unsigned int)1 << numbits) - 1); + + return val; +} + /* * Broadcast Call Control (04.69) */ @@ -762,6 +804,10 @@ l2_rrm() data++; l2_RRsystemInfo13C(); break; + case 0x02: + OUTF("00000010 System Information Type 2bis\n"); + l2_RRsystemInfo2bis(); + break; case 0x06: OUTF("00000110 System Information Type 5ter\n"); data++; @@ -1015,11 +1061,15 @@ l2_MobileAllocation() int c = 64, pos; char *str = "Mobile allocation RF chann."; const unsigned char *thisend; + int len; if (data >= end) RETTRUNK(); OUTF("%s Length of Mobile Allocation: %d\n", BitRowFill(data[0], 0xff), data[0]); - thisend = data + data[0] + 1; + + len = data[0]; + + thisend = data + len + 1; if (thisend > end) { OUTF("xxxxxxxx ERROR: Packet to short or length to long\n"); @@ -1031,21 +1081,22 @@ l2_MobileAllocation() if (data >= thisend) return; + /* This is the index into the list of arfcn's */ + pos = 7; while (data < thisend) { - pos = 7; while (pos >= 0) { if ((data[0] >> pos) & 1) - OUTF("%s %s%d\n", BitRow(data[0], pos), str, c - (7 - pos)); - pos--; + { + OUTF("%s Mobile Allocation ARFCN #%d\n", BitRow(data[0], pos), 8 * len - (7 - pos)); + } + pos--; } - - c -= 8; + pos = 7; + len--; data++; - if (c <= 0) - break; } } @@ -1055,65 +1106,8 @@ l2_MobileAllocation() static void l2_BcchAllocation() { - int c, pos; - char *str = "BCCH alloc. RF chan.: "; - -#if 0 - /* goeller script for Info2 outputs channels 128 + 127 - * but opengpa outputs bitmap format for info2. - * We do what opengpa does. (correct?) - */ - if ((data[0] >> 7)) - OUTF("1------- %s%d\n", str, 128); - if ((data[0] >> 6) & 1) - OUTF("-1------ %s%d\n", str, 127); -#endif - if ((data[0] >> 6) == 0x00) - OUTF("00------ Bitmap format: 0\n"); - else { - OUTF("%s Bitmap format: UNKNOWN [FIXME]\n", BitRowFill(data[0], 0xc0)); - return; - } - - if ((data[0] & 0x8e) == 0x8e) - { - /* From System Information Type 5ter */ - OUTF("1---111- Variable Bitmap SI5ter [FIXME]\n"); - return; - } - - if ((data[0] >> 5) & 1) - OUTF("--1----- Extension Indicator: The IE carries only a part of the BA\n"); - else - OUTF("--0----- Extension Indicator: The IE carries the complete BA\n"); OUTF("---x---- BCCH alloc. seq. num: %d\n", (data[0] >> 4) & 1); - if ((data[0] >> 3) & 1) - OUTF("----1--- %s%d\n", str, 124); - if ((data[0] >> 2) & 1) - OUTF("-----1-- %s%d\n", str, 123); - if ((data[0] >> 1) & 1) - OUTF("------1- %s%d\n", str, 122); - if (data[0] & 1) - OUTF("-------1 %s%d\n", str, 121); - - data++; - c = 120; - while (data < end) - { - pos = 7; - while (pos >= 0) - { - if ((data[0] >> pos) & 1) - OUTF("%s %s%d\n", BitRow(data[0], pos), str, c - (7 - pos)); - pos--; - - } - - c -= 8; - data++; - if (c <= 0) - break; - } + CellAllocation(data[0], "BCCH Allocation : ARFCN"); } static void @@ -1163,31 +1157,18 @@ l2_RRimmediateAssTBFC() } static void -l2_RRsystemInfo1() +CellAllocationBitmapZero(char *str) { int ca; - if (data + 1 >= end) - return; - switch (data[0] >> 6) - { - case 0x00: - OUTF("00------ Bitmap 0 format\n"); - break; - case 0x01: - OUTF("10------ Bitmap format: (FIXME)\n"); - break; - default: - OUTF("%s Bitmap %d format (FIXME)\n", BitRowFill(data[0], 0xc0), data[0] >> 6); - } if ((data[0] >> 3) & 1) - OUTF("----1--- Cell Allocation : ARFCN 124\n"); + OUTF("----1--- %s 124\n", str); if ((data[0] >> 2) & 1) - OUTF("-----1-- Cell Allocation : ARFCN 123\n"); + OUTF("-----1-- %s 123\n", str); if ((data[0] >> 1) & 1) - OUTF("------1- Cell Allocation : ARFCN 122\n"); + OUTF("------1- %s 122\n", str); if (data[0] & 1) - OUTF("-------1 Cell Allocation : ARFCN 121\n"); + OUTF("-------1 %s 121\n", str); ca = 120; while (ca > 0) @@ -1196,26 +1177,228 @@ l2_RRsystemInfo1() if (data >= end) return; if ((data[0] >> 7) & 1) - OUTF("1------- Cell Allocation : ARFCN %d\n", ca); + OUTF("1------- %s %d\n", str, ca); if ((data[0] >> 6) & 1) - OUTF("-1------ Cell Allocation : ARFCN %d\n", ca - 1); + OUTF("-1------ %s %d\n", str, ca - 1); if ((data[0] >> 5) & 1) - OUTF("--1----- Cell Allocation : ARFCN %d\n", ca - 2); + OUTF("--1----- %s %d\n", str, ca - 2); if ((data[0] >> 4) & 1) - OUTF("---1---- Cell Allocation : ARFCN %d\n", ca - 3); + OUTF("---1---- %s %d\n", str, ca - 3); if ((data[0] >> 3) & 1) - OUTF("----1--- Cell Allocation : ARFCN %d\n", ca - 4); + OUTF("----1--- %s %d\n", str, ca - 4); if ((data[0] >> 2) & 1) - OUTF("-----1-- Cell Allocation : ARFCN %d\n", ca - 5); + OUTF("-----1-- %s %d\n", str, ca - 5); if ((data[0] >> 1) & 1) - OUTF("------1- Cell Allocation : ARFCN %d\n", ca - 6); + OUTF("------1- %s %d\n", str, ca - 6); if (data[0] & 1) - OUTF("-------1 Cell Allocation : ARFCN %d\n", ca - 7); + OUTF("-------1 %s %d\n", str, ca - 7); ca -= 8; } + data++; +} + +/* + * Return number of bits required to store val. + */ +static int +num_bits(unsigned int val) +{ + int i = 32; + + while (1) + { + i--; + if (i <= 0) + break; + if ((((unsigned int)1) << i) <= val) + break; + } + + return i + 1; +} +static int +Bitmap256_extract_frequency(unsigned short *w, int index) +{ + int j; + int n = w[index]; + + j = 1 << (num_bits(index) - 1); + //OUTF("j = %d\n", j); + while (index > 1) + { + if (2 * index < 3 * j) + { + index = index - j / 2; + n = (n + w[index] - 256 / j - 1) % (512 / j - 1) + 1; + } else { + index = index - j; + n = (n + w[index] - 1) % (512 / j - 1) + 1; + } + j = j / 2; + } + //OUTF("freq %d\n", (w[0] + n) % 1024); + + return (w[0] + n) % 1024; +} + + +static void +CellAllocationBitmap256(char *str) +{ + int arfcn = 0; + int i; + unsigned short w[30]; + int pos, len, border; + int ii; + + memset(w, 0, sizeof w); + + arfcn = (data[0] & 1) << 9; + data++; + arfcn |= (data[0] << 1); + data++; + arfcn |= (data[0] >> 7); + w[0] = arfcn; + +#if 0 + w[0] = 0xff; + w[1] = 0x00; + w[2] = 0xff; + w[3] = 0x00; + OUTF("XXX 6,8 254 %u\n", Bit_extract_val(w, 6, 8)); + OUTF("XXX 7,7 127 %u\n", Bit_extract_val(w, 7, 7)); + OUTF("XXX 7,8 255 %u\n", Bit_extract_val(w, 7, 8)); + OUTF("XXX 6,7 127 %u\n", Bit_extract_val(w, 6, 7)); + OUTF("XXX 0,8 128 %u\n", Bit_extract_val(w, 0, 8)); + OUTF("XXX 7,16 65280 %u\n", Bit_extract_val(w, 7, 16)); + OUTF("XXX 7,1 1 %u\n", Bit_extract_val(w, 7, 1)); + OUTF("XXX 8,1 0 %u\n", Bit_extract_val(w, 8, 1)); +#endif + + pos = 6; + len = 8; + border = 2; + for (i = 1; i <= 29; i++) + { + if (i == border) + { + border = border * 2; + len--; + if (len <= 0) + { + i--; + break; + } + } + w[i] = Bit_extract_val((unsigned char *)data, pos, len); + if (w[i] == 0) + break; + pos += len; + } + //OUTF("%d entries\n", i); + + OUTF("xxxxxxxx %s %d (original)\n", str, w[0]); + for (ii = 1; ii <= i; ii++) + { + OUTF("xxxxxxxx %s %d\n", str, Bitmap256_extract_frequency(w, ii)); + } + data += (pos + 7) / 8; + +} + +static void +CellAllocationBitmapVariable(char *str) +{ + int arfcn = 0; + int i; + const unsigned char *thisend; + + arfcn = (data[0] & 1) << 9; + data++; + arfcn |= (data[0] << 1); data++; + arfcn |= (data[0] >> 7); + + OUTF("........ %s %d (original)\n", str, arfcn); + + for (i = 1; i < 8; i++) + { + if (BIT(data[0], 7-i)) + OUTF("%s %s %d\n", BitRow(data[0], 7-i), str, (arfcn + i) % 1024); + } + data++; + + thisend = data + 13; + while (data < thisend) + { + for (i = 0; i < 8; i++) + { + if (BIT(data[0], 7 - i)) + OUTF("%s %s %d\n", BitRow(data[0], 7-i), str, (arfcn + (104 + i)) % 1024); + } + data++; + } +} + +/* + * Return 0 on success (e.g. caller continues processing). + * Cell Channel Description (for example SystemInformationType 1) + */ +static int +CellAllocation(unsigned char format, char *str) +{ + const unsigned char *orig_data = data; + + if ((format >> 6) == 0x00) + { + OUTF("00------ Bitmap 0 format\n"); + CellAllocationBitmapZero(str); + data = orig_data + 16; + return 0; + } + if (((format >> 3) & 1) == 0x00) + { + OUTF("-------- Bitmap format: 1024 Range (FIXME)\n"); + data = orig_data + 16; + return -1; + } + + switch ((format >> 1) & 0x07) + { + case 0x04: + OUTF("10--100- Bitmap format: 512 Range (FIXME)\n"); + data = orig_data + 16; + return -1; + case 0x05: + OUTF("10--101- Bitmap format: 256 Range\n"); + CellAllocationBitmap256(str); + data = orig_data + 16; + return 0; + case 0x06: + OUTF("10--110- Bitmap format: 128 Range (FIXME)\n"); + data = orig_data + 16; + return -1; + case 0x07: + OUTF("10--111- Bitmap format: Variable Range\n"); + CellAllocationBitmapVariable(str); + data = orig_data + 16; + return 0; + } + + return -1; +} + +static void +l2_RRsystemInfo1() +{ + + if (data + 1 >= end) + return; + + if (CellAllocation(data[0], "Cell Allocation : ARFCN") != 0) + return; l2_RachControlParameters(); if (data >= end) @@ -1381,6 +1564,7 @@ l2_RRsystemInfo2() if (data >= end) RETTRUNK(); +STOP HERE: laut 04.08 ist hier ne liste von ARFCN's. int c = 7; while (c >= 0) { @@ -1398,6 +1582,19 @@ l2_RRsystemInfo2() RETTRUNK(); } +static void +l2_RRsystemInfo2() +{ + if (data >= end) + RETTRUNK(); + + /* Extended BCCH Frequency List */ +STOP HERE: frequenz liste! + + l2_RachControlParameters(); +} + + #if 0 static void l2_RRsystemInfo2ter() -- cgit v1.2.3 From c45b8883df3f015baf6baf8f8c481faecf13847e Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 18 Apr 2008 00:52:33 +0100 Subject: updats --- gsmdecode/Makefile.am | 4 ++ gsmdecode/src/data_out.c | 155 +++++++++++++++++++++++++++++++++-------------- gsmdecode/src/gsm_desc.h | 1 + 3 files changed, 114 insertions(+), 46 deletions(-) diff --git a/gsmdecode/Makefile.am b/gsmdecode/Makefile.am index 9b3abbf..69fd6b1 100644 --- a/gsmdecode/Makefile.am +++ b/gsmdecode/Makefile.am @@ -1,2 +1,6 @@ SUBDIRS = src EXTRA_DIST = config VERSION bootstrap INSTALL example_sms2.xml + +test: + @echo "foobar" + diff --git a/gsmdecode/src/data_out.c b/gsmdecode/src/data_out.c index b886edd..1f69d2e 100644 --- a/gsmdecode/src/data_out.c +++ b/gsmdecode/src/data_out.c @@ -37,7 +37,8 @@ static void l2_cc(); static void l2_RRsystemInfo1(); static void l2_MccMncLac(); static void l2_RRsystemInfo2(); -//static void l2_RRsystemInfo2ter(); +static void l2_RRsystemInfo2bis(); +static void l2_RRsystemInfo2ter(); static void l2_RRsystemInfo3C(); static void l2_RRsystemInfo4C(); static void l2_RRsystemInfo6(); @@ -111,6 +112,7 @@ static void ProgressIndicator(); static void Cause(); static void SmsProtocolDataValidity(); static void BearerCap(); +static void Number(int len); static void BCDNumber(); static void AuthenticationRequest(); static void AuthenticationResponse(); @@ -123,6 +125,7 @@ static void LocationUpdateRequest(); static void MultiSupportTwo(); static void MeasurmentReport(); static int CellAllocation(unsigned char format, char *str); +static void ChannelMode(); static const unsigned char *start; static const unsigned char *data; @@ -806,8 +809,19 @@ l2_rrm() break; case 0x02: OUTF("00000010 System Information Type 2bis\n"); + data++; l2_RRsystemInfo2bis(); break; + case 0x03: + OUTF("00000011 System Information Type 2ter\n"); + data++; + l2_RRsystemInfo2ter(); + break; + case 0x05: + OUTF("00000101 System Information Type 5bis\n"); + data++; + l2_BcchAllocation(); + break; case 0x06: OUTF("00000110 System Information Type 5ter\n"); data++; @@ -1058,8 +1072,7 @@ l2_HoppingChannelC() static void l2_MobileAllocation() { - int c = 64, pos; - char *str = "Mobile allocation RF chann."; + int pos; const unsigned char *thisend; int len; @@ -1554,17 +1567,20 @@ BitRowFill(unsigned char c, unsigned char mask) return buf; } +/* + * GSM 04.08-9.1.32 + */ static void l2_RRsystemInfo2() { if (data >= end) RETTRUNK(); + /* Neighbour Cell Description. 16 octets */ l2_BcchAllocation(); if (data >= end) RETTRUNK(); -STOP HERE: laut 04.08 ist hier ne liste von ARFCN's. int c = 7; while (c >= 0) { @@ -1583,42 +1599,28 @@ STOP HERE: laut 04.08 ist hier ne liste von ARFCN's. } static void -l2_RRsystemInfo2() +l2_RRsystemInfo2bis() { if (data >= end) RETTRUNK(); - /* Extended BCCH Frequency List */ -STOP HERE: frequenz liste! + /* Extended BCCH Frequency List. 16 octets */ + /* Neighbour Cell Description. 10.5.2.22 */ + l2_BcchAllocation(); + /* 3 octets */ l2_RachControlParameters(); } - -#if 0 static void l2_RRsystemInfo2ter() { if (data >= end) - return; - if ((data[0] >> 7) == 0) - OUTF("%s Bitmap 0 format\n", BitRowFill(data[0], 0x8e)); - else { - /* 0x8e = 10001110 */ - if (((data[0] >> 1) & 0x07) == 0x04) - OUTF("1---100- 1024 range\nFIXME\n"); - else if (((data[0] >> 1) & 0x07) == 0x05) - OUTF("1---101- 512 range\nFIXME\n"); - else if (((data[0] >> 1) & 0x07) == 0x06) - OUTF("1---110- 128 range\nFIXME\n"); - else if (((data[0] >> 1) & 0x07) == 0x07) - OUTF("1---111- variable Bitmap\nFIXME\n"); - else - OUTF("1---xxx- UNKNOWN 0x%08x\n", data[0]); - } - OUTF("FIXME\n"); + RETTRUNK(); + + /* Neighbour Cell Description 2 */ + l2_BcchAllocation(); } -#endif /* @@ -1721,6 +1723,7 @@ l2_RRsystemInfo6() if (data >= end) RETTRUNK(); OUTF("%s Network Colour Code: %u\n", BitRowFill(data[0], 0xff), data[0]); + data++; } static void @@ -2403,10 +2406,10 @@ l2_sms() OUTF("00010000 Type: CP-ERROR\n"); else if (data[0] == 1) { OUTF("00000001 Type: CP-DATA\n"); - data++; cpData(); } else OUTF("%s UNKNOWN\n", BitRowFill(data[0], 0xff)); + data++; } static void @@ -2756,18 +2759,7 @@ TPAddress(const char *str) OUTF("%s\n", id_list_get(list_SMSCAddressType, (data[0] >> 4) & 0x07)); OUTF("%s\n", id_list_get(list_SMSCAddressNumberingPlan, data[0] & 0x0f)); data++; - - OUTF("-------- Number(%u): ", len); - while (len > 0) - { - if ((data[0] >> 4) == 0x0f) - OUT("%X", data[0] & 0x0f); - else - OUT("%X%X", data[0] & 0x0f, data[0] >> 4); - len -= 2; - data++; - } - OUT("\n"); + Number(len); } static void @@ -2833,6 +2825,9 @@ l2_RRpagingresponse() l2_MobId(); } +/* + * 04.08-9.1.2 + */ static void l2_RRassignCommand() { @@ -2841,6 +2836,11 @@ l2_RRassignCommand() RETTRUNK(); OUTF("%s Training seq. code: %d\n", BitRowFill(data[0], 0xe0), data[0] >> 5); + + /* Power Command 10.5.2.28 */ + /* Frequency List 10.5.2.13 */ + /* Cell Channel Description 10.5.2.1b */ + /* Multislot allocation... */ if (((data[0] >> 2) & 0x07) == 0x00) l2_SingleChannelAssCom(); else if (((data[0] >> 4) & 1) == 0x01) @@ -2870,6 +2870,13 @@ ChannelDescriptionTwo() data++; } +static void +PowerLevel() +{ + OUTF("%s Power Level: %u\n", BitRowFill(data[0], 0x1f), data[0] & 0x1f); + data++; +} + static void l2_SingleChannelAssCom() { @@ -2882,22 +2889,50 @@ l2_SingleChannelAssCom() OUTF("........ Absolute RF channel number: %u\n", freq); if (++data >= end) RETTRUNK(); - OUTF("%s Power Level: %u\n", BitRowFill(data[0], 0x1f), data[0] & 0x1f); - if (++data >= end) - RETTRUNK(); + PowerLevel(); if (data[0] != 0x63) return; if (++data >= end) RETTRUNK(); + ChannelMode(); +} + +static void +FrequencyList() +{ + /* Should be 16 */ + OUTF("%s Length: %d\n", BitRowFill(data[0], 0xff), data[0]); + data++; + CellAllocation(data[0], "Cell Allocation : ARFCN"); +} + +static void +ChannelMode() +{ OUTF("%s\n", id_list_get(list_ChannelMode, data[0])); + data++; } static void l2_HoppingChannelAssCom() { maio(); - OUTF("FIXME\n"); + PowerLevel(); + while (data < end) + { + if (data[0] == 0x05) + { + data++; + FrequencyList(); + } else if (data[0] == 0x63) { + data++; + ChannelMode(); + } else { + OUTF("UNKNOWN. FIXME\n"); + break; + } + } } static void @@ -2950,6 +2985,12 @@ CCsetup() OUTF("01011110 Called Party BCD Number\n"); data++; BCDNumber(); + } else if (data[0] == 0xa1) { + OUTF("10100001 CLIR supression\n"); + data++; + } else if (data[0] == 0xa2) { + OUTF("10100010 CLIR invocation\n"); + data++; } else { OUTF("%s FIXME\n", BitRowFill(data[0], 0xff)); break; @@ -3012,6 +3053,7 @@ MultiSupportTwo() data++; OUTF("%s Associated Radio capability 1 Power Class: %d\n", BitRowFill(data[0], 0xf), data[0] & 0xf); OUTF("%s Associated Radio capability 2 Power Class: %d\n", BitRowFill(data[0], 0xf0), data[0] >> 4); + data++; } static void @@ -3790,15 +3832,36 @@ MeasurmentReport() OUTF("FIXME\n"); } +static void +Number(int len) +{ + OUTF("-------- Number(%u): ", len); + while (len > 0) + { + if ((data[0] >> 4) == 0x0f) + OUT("%X", data[0] & 0x0f); + else + OUT("%X%X", data[0] & 0x0f, data[0] >> 4); + len -= 2; + data++; + } + OUT("\n"); +} + static void BCDNumber() { + int len; + if (data >= end) RETTRUNK(); + len = data[0]; OUTF("%s Length: %u\n", BitRowFill(data[0], 0xff), data[0]); data++; - OUTF("%s Type of number: %s\n", BitRowFill(data[0], 0x70), id_list_get(list_TypeNumber, data[0] & 0x70)); - //OUTF("%s Number plan: %s\n", BitRowFill(data[0], 0xf), id_list_get(list_data[0] & 0xf); + OUTF("%s Type of number: %s\n", BitRowFill(data[0], 0x70), id_list_get(list_TypeNumber, (data[0] & 0x70) >> 4)); + data++; + len--; + Number(len * 2); } diff --git a/gsmdecode/src/gsm_desc.h b/gsmdecode/src/gsm_desc.h index 570db19..ccaac17 100644 --- a/gsmdecode/src/gsm_desc.h +++ b/gsmdecode/src/gsm_desc.h @@ -259,3 +259,4 @@ struct _id_list list_TypeNumber[] = { {-1, NULL} }; + -- cgit v1.2.3 From 1160a9850752e6abb9a9a96ec4a3b7db6474dca0 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 18 Apr 2008 00:52:47 +0100 Subject: changes. --- gsm-tvoid/configure.ac | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gsm-tvoid/configure.ac b/gsm-tvoid/configure.ac index 37f8d49..ced8f31 100644 --- a/gsm-tvoid/configure.ac +++ b/gsm-tvoid/configure.ac @@ -80,7 +80,7 @@ AC_CHECK_FUNCS([]) dnl Check for Mingw support GR_PWIN32 -PKG_CHECK_MODULES(GNURADIO_CORE, gnuradio-core >= 2) +PKG_CHECK_MODULES(GNURADIO_CORE, gnuradio-core >= 3.1.2) LIBS="$LIBS $GNURADIO_CORE_LIBS" dnl Define where to find boost includes @@ -103,3 +103,8 @@ dnl run_tests is created from run_tests.in. Make it executable. AC_CONFIG_COMMANDS([run_tests], [chmod +x src/python/run_tests]) AC_OUTPUT +echo "#######################################################" +echo "Type 'make all'" +echo "See src/python/go.sh for an example." +echo "#######################################################" + -- cgit v1.2.3 From ae813e4258cddb8442aa64c097bbf94f9bb0671d Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 18 Apr 2008 00:53:39 +0100 Subject: patch 20080411 --- gsm-tvoid/src/lib/Makefile.am | 4 +- gsm-tvoid/src/lib/gsm.i | 25 +++++++-- gsm-tvoid/src/lib/gsm_burst.cc | 99 ++++++++++++++++++++++++++-------- gsm-tvoid/src/lib/gsm_burst.h | 54 ++++++++++++------- gsm-tvoid/src/lib/gsm_burst_cf.cc | 109 ++++++++++++++++++++------------------ gsm-tvoid/src/lib/gsm_burst_cf.h | 10 ++-- gsm-tvoid/src/lib/gsm_burst_ff.cc | 37 +++++++------ gsm-tvoid/src/lib/gsm_burst_ff.h | 6 +-- 8 files changed, 223 insertions(+), 121 deletions(-) diff --git a/gsm-tvoid/src/lib/Makefile.am b/gsm-tvoid/src/lib/Makefile.am index f4072d9..e8f093f 100755 --- a/gsm-tvoid/src/lib/Makefile.am +++ b/gsm-tvoid/src/lib/Makefile.am @@ -47,7 +47,8 @@ _gsm_la_SOURCES = \ gsm.cc \ gsm_burst.cc \ gsm_burst_ff.cc \ - gsm_burst_cf.cc + gsm_burst_cf.cc \ + gsm_burst_sink_c.cc # magic flags @@ -74,6 +75,7 @@ grinclude_HEADERS = \ system.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 %} @@ -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..c7f0acc 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(); @@ -194,7 +197,17 @@ void gsm_burst::print_burst(void) int print = 0; //fprintf(stderr,"p=%8.8X ", d_print_options); - + + if ( PRINT_GSM_DECODE & d_print_options ) { + + /* + * Pass information to GSM stack. GSM stack will try to extract + * information (fn, layer 2 messages, ...) + */ + diff_decode_burst(); + GS_process(&d_gs_ctx, d_ts, d_burst_type, d_decoded_burst); + } + if ( PRINT_EVERYTHING == d_print_options ) print = 1; else if ( (!d_ts) && (d_print_options & PRINT_TS0) ) @@ -221,18 +234,7 @@ void gsm_burst::print_burst(void) fprintf(stderr," "); } - - if ( PRINT_GSM_DECODE == d_print_options ) { - - /* - * Pass information to GSM stack. GSM stack will try to extract - * information (fn, layer 2 messages, ...) - */ - diff_decode_burst(); - GS_process(&d_gs_ctx, d_ts, d_burst_type, d_decoded_burst); - } - if (print) { fprintf(stderr,"%d/%d/%+d/%lu/%lu ", @@ -275,7 +277,7 @@ void gsm_burst::print_burst(void) break; } - fprintf(stderr,"\n"); + fprintf(stderr,"\n"); //print the correlation pattern for visual inspection @@ -348,14 +350,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 +469,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 +613,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 +650,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 +689,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 +702,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 -//#include //for callback testing #include #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 #include -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_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 #include -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_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 (); -- cgit v1.2.3 From b5a766ad3cf7ace8184a93912fcda3cbfb5c1279 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 18 Apr 2008 00:54:06 +0100 Subject: patch 20080411 --- gsm-tvoid/src/python/gsm_scan.py | 584 +++++++++++++++++++++++++-------------- 1 file changed, 369 insertions(+), 215 deletions(-) diff --git a/gsm-tvoid/src/python/gsm_scan.py b/gsm-tvoid/src/python/gsm_scan.py index 5d48ce5..5e3edfc 100755 --- a/gsm-tvoid/src/python/gsm_scan.py +++ b/gsm-tvoid/src/python/gsm_scan.py @@ -1,13 +1,14 @@ #!/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 import sys @@ -26,6 +27,64 @@ 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 >> sys.stderr, "burst_callback: Exception: ", e + + +#################### def pick_subdevice(u): if u.db[0][0].dbid() >= 0: return (0, 0) @@ -33,6 +92,7 @@ def pick_subdevice(u): return (1, 0) return (0, 0) +#################### def get_freq_from_arfcn(chan,region): #P/E/R-GSM 900 @@ -69,13 +129,36 @@ def get_freq_from_arfcn(chan,region): return freq * 1e6 +#################### class app_flow_graph(stdgui.gui_flow_graph): + def __init__(self, frame, panel, vbox, argv): stdgui.gui_flow_graph.__init__(self) self.frame = frame self.panel = panel + self.parse_options() + self.setup_flowgraph() + self.setup_print_options() + self._build_gui(vbox) + + #some non-gui wxwindows handlers + self.t1 = wx.Timer(self.frame) + 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) + #tune + self.set_channel(self.channel) + + #giddyup + self.status_msg = "Started." + + +#################### + def parse_options(self): parser = OptionParser(option_class=eng_option) #view options @@ -85,25 +168,26 @@ 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, he(x) burst data, \n" + + "Usefull (b)its, All TS (B)its, (C)orrelation bits, he(x) raw burst data, \n" + "(d)ecoded hex for gsmdecode") #decoder options 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]") - parser.add_option("-o", "--offset", type="eng_float", default=0.0, - 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="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 ") + parser.add_option("-o", "--offset", type="eng_float", default=0.0, + help="Tuning offset frequency") + #file options parser.add_option("-I", "--inputfile", type="string", default=None, help="Select a capture file to read") @@ -113,12 +197,23 @@ class app_flow_graph(stdgui.gui_flow_graph): help="Continuously loop data from input file") #usrp options + parser.add_option("-d", "--decim", type="int", default=112, + help="Set USRP decimation rate to DECIM [default=%default]") 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.") + parser.add_option("-C", "--clock-offset", type="eng_float", default=0.0, + help="Sample clock offset frequency") + #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]") @@ -129,27 +224,129 @@ class app_flow_graph(stdgui.gui_flow_graph): parser.print_help() sys.exit(1) +# if (options.inputfile and ( options.freq or options.rx_subdev_spec or options.gain)): +# print "datafile option cannot be used with USRP options." +# sys.exit(1) + + self.options = options self.scopes = options.scopes self.region = options.region self.channel = options.channel self.offset = options.offset - + +#################### + def setup_print_options(self): + options = self.options + self.print_status = options.print_console.count('s') - + if options.print_console.count('e'): self.print_status = 1 + + #console print options + popts = 0 + + if options.print_console.count('d'): + popts |= gsm.PRINT_GSM_DECODE + + if options.print_console.count('s'): + popts |= gsm.PRINT_STATE + + if options.print_console.count('e'): + popts |= gsm.PRINT_EVERYTHING + + if options.print_console.count('a'): + popts |= gsm.PRINT_ALL_TYPES + + if options.print_console.count('k'): + popts |= gsm.PRINT_KNOWN + + if options.print_console.count('u'): + popts |= gsm.PRINT_UNKNOWN + + if options.print_console.count('0'): + popts |= gsm.PRINT_TS0 + + if options.print_console.count('F'): + popts |= gsm.PRINT_FCCH + + if options.print_console.count('S'): + popts |= gsm.PRINT_SCH + + if options.print_console.count('N'): + popts |= gsm.PRINT_NORMAL + + if options.print_console.count('D'): + popts |= gsm.PRINT_DUMMY + + 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 + + print "Print flags: 0x%8.8x\n" %(popts) + + self.burst.d_print_options = popts + + +#################### + def setup_usrp(self): + options = self.options + + #set resonable defaults if no user prefs set + if options.realtime: + 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 >> sys.stderr, "fusb_block_size =", options.fusb_block_size + print >> sys.stderr, "fusb_nblocks =", options.fusb_nblocks + -# if (options.inputfile and ( options.freq or options.rx_subdev_spec or options.gain)): -# print "datafile option cannot be used with USRP options." -# sys.exit(1) + self.ursp = 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.ursp) + + self.ursp.set_mux(usrp.determine_rx_mux_value(self.ursp, options.rx_subdev_spec)) + + # determine the daughterboard subdevice + self.subdev = usrp.selected_subdev(self.ursp, options.rx_subdev_spec) + input_rate = self.ursp.adc_freq() / self.ursp.decim_rate() + # set initial values + if options.gain is None: + # if no gain was specified, use the mid-point in dB + g = self.subdev.gain_range() + options.gain = float(g[0]+g[1])/2 + + self.set_gain(options.gain) + + self.source = self.ursp - #adjust or caclulate sample clock +#################### + def setup_timing(self): + options = self.options clock_rate = 64e6 + if options.clock_offset: clock_rate = 64e6 + options.clock_offset elif options.channel: + #calculate actual clock rate based on frequency offset (assumes shared clock for sampling and tuning) f = get_freq_from_arfcn(options.channel,options.region) if f: percent_offset = options.offset / get_freq_from_arfcn(options.channel,options.region) @@ -157,39 +354,17 @@ class app_flow_graph(stdgui.gui_flow_graph): percent_offset = 0.0 clock_rate += clock_rate * percent_offset - print "% offset = ", percent_offset, "clock = ", clock_rate + print >> sys.stderr, "% offset = ", percent_offset, "clock = ", clock_rate - #set the default input rate, we will check with the USRP if it is being used - input_rate = clock_rate / options.decim - gsm_symb_rate = 1625000.0 / 6.0 - sps = input_rate/gsm_symb_rate - - # Build the flowgraph - # Setup our input source - if options.inputfile: - self.using_usrp = False - print "Reading data from: " + options.inputfile - 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) - 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)) - - # determine the daughterboard subdevice - self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) - input_rate = self.u.adc_freq() / self.u.decim_rate() - - # set initial values - if options.gain is None: - # if no gain was specified, use the mid-point in dB - g = self.subdev.gain_range() - options.gain = float(g[0]+g[1])/2 - - self.set_gain(options.gain) + self.clock_rate = clock_rate + self.input_rate = clock_rate / options.decim + self.gsm_symb_rate = 1625000.0 / 6.0 + self.sps = self.input_rate / self.gsm_symb_rate + +#################### + def setup_filter(self): + options = self.options - # configure the processing blocks # configure channel filter filter_cutoff = 145e3 #135,417Hz is GSM bandwidth filter_t_width = 10e3 @@ -201,79 +376,70 @@ class app_flow_graph(stdgui.gui_flow_graph): else: offset = 0.0 - 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) - - # Connect the blocks - if self.scopes.count("I"): - self.input_fft_scope = fftsink.fft_sink_c (self, panel, fft_size=1024, sample_rate=input_rate) + filter_taps = gr.firdes.low_pass(1.0, self.input_rate, filter_cutoff, filter_t_width, gr.firdes.WIN_HAMMING) + self.filter = gr.freq_xlating_fir_filter_ccf(1, filter_taps, offset, self.input_rate) - if options.inputfile: - self.connect(self.source, self.filter) - if self.scopes.count("I"): - self.connect(self.source, self.input_fft_scope) - else: - self.connect(self.u, self.filter) - if self.scopes.count("I"): - self.connect(self.u, self.input_fft_scope) + self.connect(self.source, self.filter) - # Setup flow based on decoder selection - if options.decoder.count("c"): - self.burst = gsm.burst_cf(input_rate) - self.connect(self.filter, self.burst) +#################### + def setup_f_flowgraph(self): + # configure demodulator + # adjust the phase gain for sampling rate + self.demod = gr.quadrature_demod_cf(self.sps); + + #configure clock recovery + gain_mu = 0.01 + gain_omega = .25 * gain_mu * gain_mu # critically damped + self.clocker = gr.clock_recovery_mm_ff( self.sps, + gain_omega, + 0.5, #mu + gain_mu, + 0.3) #omega_relative_limit, - elif options.decoder.count("f"): - # configure demodulator - # adjust the phase gain for sampling rate - self.demod = gr.quadrature_demod_cf(sps); + self.burst = gsm.burst_ff(self.burst_cb) + self.connect(self.filter, self.demod, self.clocker, self.burst) + +#################### + def setup_c_flowgraph(self): + #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) - #configure clock recovery - gain_mu = 0.01 - gain_omega = .25 * gain_mu * gain_mu # critically damped - self.clocker = gr.clock_recovery_mm_ff( sps, - gain_omega, - 0.5, #mu - gain_mu, - 0.3) #omega_relative_limit, - - self.burst = gsm.burst_ff() - self.connect(self.filter, self.demod, self.clocker, 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) - - 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, + self.connect(self.filter, self.burst) +#################### + def setup_scopes(self): + #Input FFT + if self.scopes.count("I"): + self.input_fft_scope = fftsink.fft_sink_c (self, self.panel, fft_size=1024, sample_rate=self.input_rate) + self.connect(self.source, self.input_fft_scope) - # configure demodulator - self.demod = gr.quadrature_demod_cf(1); - - self.burst = gsm.burst_ff() - self.connect(self.filter, self.clocker, self.demod, self.burst) + #Filter FFT + if self.scopes.count("F"): + self.filter_fft_scope = fftsink.fft_sink_c (self, self.panel, fft_size=1024, sample_rate=input_rate) + self.connect(self.filter, self.filter_fft_scope) + #Burst Scope + if self.scopes.count("b"): + self.burst_scope = scopesink.scope_sink_f(self, self.panel, sample_rate=self.gsm_symb_rate,v_scale=1) + self.connect(self.v2s, self.burst_scope) + + #burst_f options + if self.options.decoder.count("f"): if self.scopes.count("d"): - self.demod_scope = scopesink.scope_sink_f(self, panel, sample_rate=input_rate) + self.demod_scope = scopesink.scope_sink_f(self, self.panel, sample_rate=self.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.clocked_scope = scopesink.scope_sink_f(self, self.panel, sample_rate=self.gsm_symb_rate,v_scale=1) self.connect(self.clocker, self.clocked_scope) - - # setup decoder parameters +#################### + def configure_burst_decoder(self): + options = self.options + # equalizer eq_types = {'none': gsm.EQ_NONE, 'fixed-dfe': gsm.EQ_FIXED_DFE} self.burst.d_equalizer_type = eq_types[options.equalizer] @@ -292,101 +458,68 @@ class app_flow_graph(stdgui.gui_flow_graph): self.burst.d_clock_options = topts - #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 - - if options.print_console.count('a'): - popts |= gsm.PRINT_ALL_TYPES - - if options.print_console.count('k'): - popts |= gsm.PRINT_KNOWN - - if options.print_console.count('u'): - popts |= gsm.PRINT_UNKNOWN - - if options.print_console.count('0'): - popts |= gsm.PRINT_TS0 +#################### + def setup_flowgraph(self): - if options.print_console.count('F'): - popts |= gsm.PRINT_FCCH - - if options.print_console.count('S'): - popts |= gsm.PRINT_SCH - - if options.print_console.count('N'): - popts |= gsm.PRINT_NORMAL - - if options.print_console.count('D'): - popts |= gsm.PRINT_DUMMY - - if options.print_console.count('d'): - popts |= gsm.PRINT_GSM_DECODE + options = self.options - if options.print_console.count('C'): - popts |= gsm.PRINT_BITS | gsm.PRINT_CORR_BITS + # Attempt to enable realtime scheduling + if options.realtime: + r = gr.enable_realtime_scheduling() + if r == gr.RT_OK: + options.realtime = True + print >> sys.stderr, "Realtime scheduling ENABLED" + else: + options.realtime = False + print >> sys.stderr, "Realtime scheduling FAILED" - 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 + self.setup_timing() - elif options.print_console.count('b'): - popts |= gsm.PRINT_BITS + # Setup our input source + if options.inputfile: + self.using_usrp = False + print >> sys.stderr, "Reading data from: " + options.inputfile + self.source = gr.file_source(gr.sizeof_gr_complex, options.inputfile, options.fileloop) + else: + self.using_usrp = True + self.setup_usrp() - 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 - - ########################## - #set burst tuning callback - #self.tuner = gsm_tuner() - #self.burst.set_tuner_callback(self.tuner) + self.setup_filter() + + #create a tuner callback + self.mean_offset = 0.0 #this is set by tuner callback + self.burst_cb = burst_callback(self) + + # Setup flow based on decoder selection + if options.decoder.count("c"): + self.setup_c_flowgraph() + elif options.decoder.count("f"): + self.setup_f_flowgraph() + + self.configure_burst_decoder() - # 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) + #Hookup a vector-stream converter if we want 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) - # 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 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 + #Output file if options.outputfile: self.filesink = gr.file_sink(gr.sizeof_float, options.outputfile) self.connect(self.v2s, self.filesink) - - self._build_gui(vbox) - - self.set_channel(self.channel) - - self.t1 = wx.Timer(self.frame) - self.t1.Start(5000,0) - self.frame.Bind(wx.EVT_TIMER, self.on_tick) - + self.setup_scopes() - def _set_status_msg(self, msg): +#################### + def set_status_msg(self, msg): self.frame.GetStatusBar().SetStatusText(msg, 0) +#################### def _build_gui(self, vbox): if self.scopes.count("I"): @@ -428,24 +561,34 @@ 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 + if self.print_status: + print >> sys.stderr, "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) + r = self.ursp.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): if not self.using_usrp: @@ -453,49 +596,60 @@ class app_flow_graph(stdgui.gui_flow_graph): self.subdev.set_gain(gain) +#################### 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): + out = sys.stderr + 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 + print >> out, "======== STATS =========" + print >> out, 'freq_offset: ',self.offset + print >> out, 'mean_offset: ',self.mean_offset + print >> out, 'sync_loss_count:',self.burst.d_sync_loss_count + print >> out, 'total_bursts: ',n_total + print >> out, 'fcch_count: ',self.burst.d_fcch_count + print >> out, 'part_sch_count: ',self.burst.d_part_sch_count + print >> out, 'sch_count: ',self.burst.d_sch_count + print >> out, 'normal_count: ',self.burst.d_normal_count + print >> out, 'dummy_count: ',self.burst.d_dummy_count + print >> out, 'unknown_count: ',self.burst.d_unknown_count + print >> out, 'known_count: ',n_known if n_total: - print '%known: ', 100.0 * n_known / n_total - print "" + print >> out, '%known: ', 100.0 * n_known / n_total + print >> out, "" +#################### def on_tick(self, evt): - #if option.autotune - #tune offset if self.print_status: self.print_stats() - -def main (): + +#################### + 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() - +#################### if __name__ == '__main__': - main () + main() -- cgit v1.2.3 From fb9671bfc0f3d1e2fe81099e72ff0c09f07d9171 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 24 Apr 2008 02:25:11 +0100 Subject: initial --- gsm-tvoid/src/lib/gsm_burst_ff_single.cc | 118 ++++++++++++++++++++++++++ gsm-tvoid/src/lib/gsm_burst_ff_single.h | 31 +++++++ gsm-tvoid/src/lib/gsm_burst_sink_c.cc | 141 +++++++++++++++++++++++++++++++ gsm-tvoid/src/lib/gsm_burst_sink_c.h | 54 ++++++++++++ 4 files changed, 344 insertions(+) create mode 100644 gsm-tvoid/src/lib/gsm_burst_ff_single.cc create mode 100644 gsm-tvoid/src/lib/gsm_burst_ff_single.h create mode 100644 gsm-tvoid/src/lib/gsm_burst_sink_c.cc create mode 100644 gsm-tvoid/src/lib/gsm_burst_sink_c.h 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 100644 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 +#include +#include +#include +#include + +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 100644 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 +#include + +class gsm_burst_ff; + +typedef boost::shared_ptr 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 100644 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 +#include +#include +#include + +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 100644 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 +#include + +class gsm_burst_sink_c; + +typedef boost::shared_ptr 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 */ -- cgit v1.2.3 From 5c781454444452d2eb02081c10ab4fdb4f8ac7f9 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 24 Apr 2008 02:26:11 +0100 Subject: intiail --- gsm-tvoid/src/python/go.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 gsm-tvoid/src/python/go.sh diff --git a/gsm-tvoid/src/python/go.sh b/gsm-tvoid/src/python/go.sh new file mode 100755 index 0000000..85fbeb9 --- /dev/null +++ b/gsm-tvoid/src/python/go.sh @@ -0,0 +1,16 @@ +#! /bin/sh + +echo "go.sh [decim==112]" + +DECIM=$2 +FILE=$1 +if [ $FILE"x" = x ]; then + FILE="../../../resource/data/GSMSP_940.8Mhz_118.cfile" + DECIM=118 +fi + +if [ $DECIM"x" = x ]; then + DECIM=112 +fi + +./gsm_scan.py -SN -pd -d "$DECIM" -I "$FILE" | ../../../gsmdecode/src/gsmdecode -i -- cgit v1.2.3