[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] gnuradio-core/src/lib/general gr_correlate_acce...
From: |
Thomas W. Rondeau |
Subject: |
[Commit-gnuradio] gnuradio-core/src/lib/general gr_correlate_acce... |
Date: |
Thu, 29 Jun 2006 20:26:54 +0000 |
CVSROOT: /sources/gnuradio
Module name: gnuradio-core
Changes by: Thomas W. Rondeau <trondeau1122> 06/06/29 20:26:54
Modified files:
src/lib/general: gr_correlate_access_code_bb.cc
gr_correlate_access_code_bb.h
Log message:
fixed branching issue and cleaned up code in
gr_correlate_access_code_bb.cc
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnuradio-core/src/lib/general/gr_correlate_access_code_bb.cc?cvsroot=gnuradio&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/gnuradio-core/src/lib/general/gr_correlate_access_code_bb.h?cvsroot=gnuradio&r1=1.2&r2=1.3
Patches:
Index: gr_correlate_access_code_bb.cc
===================================================================
RCS file:
/sources/gnuradio/gnuradio-core/src/lib/general/gr_correlate_access_code_bb.cc,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- gr_correlate_access_code_bb.cc 28 Jun 2006 18:30:38 -0000 1.4
+++ gr_correlate_access_code_bb.cc 29 Jun 2006 20:26:54 -0000 1.5
@@ -45,7 +45,7 @@
gr_make_io_signature (1, 1, sizeof(char)),
gr_make_io_signature (1, 1, sizeof(char))),
d_data_reg(0), d_flag_reg(0), d_flag_bit(0), d_mask(0),
- d_threshold(threshold), d_rotation(0)
+ d_threshold(threshold), d_flip(0)
{
if (!set_access_code(access_code)){
@@ -71,15 +71,13 @@
d_flag_bit = 1LL << (64 - len); // Where we or-in new flag values.
// new data always goes in
0x0000000000000001
- d_access_code[0] = 0;
+ d_access_code = 0;
for (unsigned i=0; i < 64; i++){
- d_access_code[0] <<= 1;
+ d_access_code <<= 1;
if (i < len)
- d_access_code[0] |= access_code[i] & 1; // look at LSB only
+ d_access_code |= access_code[i] & 1; // look at LSB only
}
- d_access_code[1] = ~d_access_code[0]; // used for non-differential BPSK
-
return true;
}
@@ -96,43 +94,33 @@
// compute output value
unsigned int t = 0;
- // data bit
- switch(d_rotation)
- {
- case(0):
- case(1): t |= ((d_data_reg >> 63) & 0x1) << 0; break;
- case(2): t |= !((d_data_reg >> 63) & 0x1) << 0; break;
- default: throw std::out_of_range ("Access code flag out of range");
- }
+ t |= d_flip ^ (((d_data_reg >> 63) & 0x1) << 0);
t |= ((d_flag_reg >> 63) & 0x1) << 1; // flag bit
out[i] = t;
// compute hamming distance between desired access code and current data
unsigned long long wrong_bits = 0;
- unsigned int nwrong = d_threshold+1, nwrong_temp = 0;
- int new_flag = 0, new_flag_temp = 0;
+ unsigned int nwrong = d_threshold+1;
+ int new_flag = 0;
- for(unsigned int j = 0; j < 2; j++)
- {
- wrong_bits = (d_data_reg ^ d_access_code[j]) & d_mask;
- nwrong_temp = gr_count_bits64(wrong_bits);
- new_flag_temp = nwrong_temp <= d_threshold;
- if(nwrong_temp < nwrong)
- nwrong = nwrong_temp;
- if(new_flag_temp)
- new_flag = j+1; // mark which access code correlated closest
- }
+ wrong_bits = (d_data_reg ^ d_access_code) & d_mask;
+ nwrong = gr_count_bits64(wrong_bits);
- //if(new_flag)
- // printf("%llx : %llx ==> %llx\n", d_access_code[0], d_access_code[1],
d_data_reg);
+ // test for access code with up to threshold errors or its compelement
+ new_flag = (nwrong <= d_threshold) || (nwrong >= (64-d_threshold));
+
+#if 0
+ if(new_flag) {
+ printf("%llx ==> %llx : d_flip=%u\n", d_access_code, d_data_reg,
d_flip);
+ }
+#endif
// shift in new data and new flag
d_data_reg = (d_data_reg << 1) | (in[i] & 0x1);
d_flag_reg = (d_flag_reg << 1);
if (new_flag) {
- d_rotation = new_flag;
d_flag_reg |= d_flag_bit;
- //printf("\nAccess Code Found, bad bits = %d\n", nwrong);
+ d_flip = nwrong >= (64-d_threshold); // flip bits if this is true
}
}
Index: gr_correlate_access_code_bb.h
===================================================================
RCS file:
/sources/gnuradio/gnuradio-core/src/lib/general/gr_correlate_access_code_bb.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- gr_correlate_access_code_bb.h 28 Jun 2006 18:30:38 -0000 1.2
+++ gr_correlate_access_code_bb.h 29 Jun 2006 20:26:54 -0000 1.3
@@ -54,7 +54,7 @@
friend gr_correlate_access_code_bb_sptr
gr_make_correlate_access_code_bb (const std::string &access_code, int
threshold);
private:
- unsigned long long d_access_code[2]; // access code to locate start of packet
+ unsigned long long d_access_code; // access code to locate start of packet
// access code is left justified in
the word
unsigned long long d_data_reg; // used to look for access_code
unsigned long long d_flag_reg; // keep track of decisions
@@ -62,7 +62,7 @@
unsigned long long d_mask; // masks access_code bits (top N bits
are set where
// N is the number of bits in the
access code)
unsigned int d_threshold; // how many bits may be wrong in sync
vector
- unsigned int d_rotation; // derotate the phase of the input
+ unsigned int d_flip; // flip bits if 180 degress out of sync
protected: