« Return to Thread: digital_correlate_access_code_bb

Re: digital_correlate_access_code_bb

by Marcus D. Leech :: Rate this Message:

| View in Thread

On 04/09/2012 01:38 PM, Tom Rondeau wrote:

> On Sat, Apr 7, 2012 at 10:12 PM, Marcus D. Leech<mleech@...>  wrote:
>> Just looking at this function:
>>
>> correlate_access_code_bb
>>
>> In the method set_access_code, it takes a string.  Which should be ASCII '1'
>> and '0' characters to represent the binary sequence being
>>   correlated against.
>>
>> Here's a little beauty of a code snippet:
>>
>>   d_access_code = 0;
>>   for (unsigned i=0; i<  64; i++){
>>     d_access_code<<= 1;
>>     if (i<  len)
>>       d_access_code |= access_code[i]&  1;    // look at LSB only
>>   }
>>
>> This relies on the fact that ASCII '1' and '0' happen to have low-order bits
>> of the right "flavour".  This is insanely dirty and gross and I can't
>>   believe we let this nonsense in the code base.
>>
>> There's no reason not to do the right thing here.
>>
>>
>> --
>> Marcus Leech
>> Principal Investigator
>> Shirleys Bay Radio Astronomy Consortium
>> http://www.sbrac.org
>
> Want to submit a patch?
>
> Tom
>
>
Attached.



--
Marcus Leech
Principal Investigator
Shirleys Bay Radio Astronomy Consortium
http://www.sbrac.org


[correlate_access_code.diff]

diff --git a/gr-digital/lib/digital_correlate_access_code_bb.cc b/gr-digital/lib/digital_correlate_access_code_bb.cc
index f21b57d..79c7639 100644
--- a/gr-digital/lib/digital_correlate_access_code_bb.cc
+++ b/gr-digital/lib/digital_correlate_access_code_bb.cc
@@ -78,7 +78,20 @@ digital_correlate_access_code_bb::set_access_code(
   for (unsigned i=0; i < 64; i++){
     d_access_code <<= 1;
     if (i < len)
-      d_access_code |= access_code[i] & 1; // look at LSB only
+    {
+      if (access_code[i] == '1')
+      {
+  d_access_code |= 1;
+  }
+  else if (access_code[i] == '0')
+  {
+  d_access_code |= 0;
+  }
+  else
+  {
+  return false;
+  }
+    }
   }
 
   return true;


_______________________________________________
Discuss-gnuradio mailing list
Discuss-gnuradio@...
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio

 « Return to Thread: digital_correlate_access_code_bb