diff options
author | tvoid <tvoid@lesaige.com> | 2008-04-25 13:53:28 -0600 |
---|---|---|
committer | tvoid <tvoid@lesaige.com> | 2008-04-25 13:53:28 -0600 |
commit | 3f97e0be9f90c505f34afa8371c25a0ffa3e97c1 (patch) | |
tree | ed3d0d003578308b37f1012621dfa16429ee7c3a /gsm-tvoid | |
parent | e4e5a96c7b587439129d9ed35dc15017344cd250 (diff) | |
parent | 5c781454444452d2eb02081c10ab4fdb4f8ac7f9 (diff) |
Merge commit 'origin/HEAD' into 20080415
Conflicts:
gsm-tvoid/src/lib/Makefile.am
gsm-tvoid/src/lib/gsm.i
gsm-tvoid/src/lib/gsm_burst.cc
gsm-tvoid/src/lib/gsm_burst.h
gsm-tvoid/src/lib/gsm_burst_cf.cc
gsm-tvoid/src/lib/gsm_burst_cf.h
gsm-tvoid/src/python/gsm_scan.py
Diffstat (limited to 'gsm-tvoid')
-rw-r--r-- | gsm-tvoid/configure.ac | 7 | ||||
-rw-r--r-- | gsm-tvoid/src/lib/Makefile.am | 2 | ||||
-rw-r--r-- | gsm-tvoid/src/lib/cch.c | 13 | ||||
-rw-r--r-- | gsm-tvoid/src/lib/fire_crc.c | 178 | ||||
-rw-r--r-- | gsm-tvoid/src/lib/fire_crc.h | 46 | ||||
-rwxr-xr-x | gsm-tvoid/src/python/go.sh | 16 |
6 files changed, 253 insertions, 9 deletions
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 "#######################################################" + diff --git a/gsm-tvoid/src/lib/Makefile.am b/gsm-tvoid/src/lib/Makefile.am index 1854fc6..fa876b2 100644 --- 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.c \ gsmstack.c \ interleave.c \ conv.c \ @@ -66,6 +67,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/cch.c b/gsm-tvoid/src/lib/cch.c index 8907a09..17ee4ee 100644 --- a/gsm-tvoid/src/lib/cch.c +++ b/gsm-tvoid/src/lib/cch.c @@ -11,7 +11,7 @@ #include <math.h> #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,22 +411,18 @@ 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); return NULL; } else { + DEBUGF("Successfully corrected parity bits!\n"); memcpy(decoded_data, crc_result, sizeof crc_result); errors = 0; } -#endif } if((len = compress_bits(ctx->msg, data_size, decoded_data, diff --git a/gsm-tvoid/src/lib/fire_crc.c b/gsm-tvoid/src/lib/fire_crc.c new file mode 100644 index 0000000..c9f0348 --- /dev/null +++ b/gsm-tvoid/src/lib/fire_crc.c @@ -0,0 +1,178 @@ +/* -*- 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 <stdio.h> +#include <string.h> + +#define REM(x, y) (x) % (y) + +static int FC_syndrome_shift(FC_CTX *ctx, unsigned int bit); + +static int +outit(int *data, int len) +{ + int i; + + for (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; + unsigned int i; + + ctx->syn_start = 0; + // reset the syndrome register + memset(ctx->syndrome_reg, 0, sizeof ctx->syndrome_reg); + + // 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 (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; + unsigned int i; + + 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); + + 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 (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..15d5b81 --- /dev/null +++ b/gsm-tvoid/src/lib/fire_crc.h @@ -0,0 +1,46 @@ +/* -*- 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 + +#ifdef __cplusplus +extern "C" { +#endif + +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); + +#ifdef __cplusplus +} +#endif + +#endif 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 <file.cfile> [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 |