commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r3509 - in gnuradio/branches/developers/jcorgan/pager/


From: jcorgan
Subject: [Commit-gnuradio] r3509 - in gnuradio/branches/developers/jcorgan/pager/gr-pager/src: lib python
Date: Sat, 9 Sep 2006 10:15:29 -0600 (MDT)

Author: jcorgan
Date: 2006-09-09 10:15:29 -0600 (Sat, 09 Sep 2006)
New Revision: 3509

Added:
   
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/lib/pgr_flex_deframer.cc
   
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/lib/pgr_flex_deframer.h
Removed:
   gnuradio/branches/developers/jcorgan/pager/gr-pager/src/lib/pgr_flex_sync.cc
   gnuradio/branches/developers/jcorgan/pager/gr-pager/src/lib/pgr_flex_sync.h
Modified:
   gnuradio/branches/developers/jcorgan/pager/gr-pager/src/lib/Makefile.am
   gnuradio/branches/developers/jcorgan/pager/gr-pager/src/lib/pgr.i
   gnuradio/branches/developers/jcorgan/pager/gr-pager/src/python/flex_demod.py
Log:
Renamed flex_sync to flex_deframer.  It turns out deinterleaving is
easiest to handle at the same time as the sync/demodulation. So
deinterleaving will be added here and this block becomes a complete
deframer.  Output now will be FLEX codeword blocks ready for error
correction (when done.)


Modified: 
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/lib/Makefile.am
===================================================================
--- gnuradio/branches/developers/jcorgan/pager/gr-pager/src/lib/Makefile.am     
2006-09-09 00:51:00 UTC (rev 3508)
+++ gnuradio/branches/developers/jcorgan/pager/gr-pager/src/lib/Makefile.am     
2006-09-09 16:15:29 UTC (rev 3509)
@@ -63,7 +63,7 @@
     pgr.cc \
     pgr_slicer_fb.cc \
     pgr_flex_modes.cc \
-    pgr_flex_sync.cc
+    pgr_flex_deframer.cc
     # Additional source modules here
 
 # magic flags

Modified: gnuradio/branches/developers/jcorgan/pager/gr-pager/src/lib/pgr.i
===================================================================
--- gnuradio/branches/developers/jcorgan/pager/gr-pager/src/lib/pgr.i   
2006-09-09 00:51:00 UTC (rev 3508)
+++ gnuradio/branches/developers/jcorgan/pager/gr-pager/src/lib/pgr.i   
2006-09-09 16:15:29 UTC (rev 3509)
@@ -26,7 +26,7 @@
 %{
 #include "gnuradio_swig_bug_workaround.h"      // mandatory bug fix
 #include "pgr_slicer_fb.h"
-#include "pgr_flex_sync.h"
+#include "pgr_flex_deframer.h"
 #include <stdexcept>
 %}
 
@@ -46,14 +46,14 @@
 
 // ----------------------------------------------------------------
 
-GR_SWIG_BLOCK_MAGIC(pgr,flex_sync);
+GR_SWIG_BLOCK_MAGIC(pgr,flex_deframer);
 
-pgr_flex_sync_sptr pgr_make_flex_sync(int rate);
+pgr_flex_deframer_sptr pgr_make_flex_deframer(int rate);
 
-class pgr_flex_sync : public gr_block
+class pgr_flex_deframer : public gr_block
 {
 private:
-    pgr_flex_sync(int rate);
+    pgr_flex_deframer(int rate);
 
 public:
 };

Copied: 
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/lib/pgr_flex_deframer.cc
 (from rev 3508, 
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/lib/pgr_flex_sync.cc)
===================================================================
--- 
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/lib/pgr_flex_deframer.cc
                            (rev 0)
+++ 
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/lib/pgr_flex_deframer.cc
    2006-09-09 16:15:29 UTC (rev 3509)
@@ -0,0 +1,280 @@
+/*
+ * Copyright 2004,2006 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pgr_flex_deframer.h>
+#include <pgr_flex_modes.h>
+#include <gr_io_signature.h>
+#include <gr_count_bits.h>
+
+pgr_flex_deframer_sptr pgr_make_flex_deframer(int rate)
+{
+    return pgr_flex_deframer_sptr(new pgr_flex_deframer(rate));
+}
+
+// FLEX deframer block takes input from symbol stream with alphabet [0, 1, 2, 
3]
+// at specified channel rate and and outputs deinterleaved 32-bit FLEX code 
words 
+// at 50, 100, or 200 code words per second (based on detected mode in sync
+// word).
+
+pgr_flex_deframer::pgr_flex_deframer(int rate) :
+    gr_block ("flex_deframer",
+              gr_make_io_signature (1, 1, sizeof(unsigned char)),
+              gr_make_io_signature (1, 1, sizeof(gr_int32))),
+    d_sync(rate/1600) // Maximum samples per baud
+{
+    d_rate = rate;
+    enter_idle();
+}
+
+void pgr_flex_deframer::forecast(int noutput_items, gr_vector_int 
&inputs_required)
+{
+    // samples per bit X 32 bits * number of outputs needed
+    int items = noutput_items*sizeof(gr_int32)*8*d_spb;
+    for (unsigned int i = 0; i < inputs_required.size(); i++)
+        inputs_required[i] = items;
+}
+
+int pgr_flex_deframer::index_avg(int start, int end)
+{
+    // modulo average
+    if (start < end)
+        return (end + start)/2;
+    else
+        return ((end + start)/2 + d_spb/2) % d_spb;
+}
+
+bool pgr_flex_deframer::test_sync(unsigned char sym)
+{
+    // 64-bit FLEX sync code:
+    // AAAA:BBBBBBBB:CCCC
+    //
+    // Where BBBBBBBB is always 0xA6C6AAAA
+    // and AAAA^CCCC is 0xFFFF
+    // 
+    // Specific values of AAAA determine what bps and encoding the
+    // packet is beyond the frame information word
+    //
+    // First we match on the marker field with a hamming distance < 4
+    // Then we match on the outer code with a hamming distance < 4
+
+    d_sync[d_index] = (d_sync[d_index] << 1) | (sym < 2);
+    gr_int64 val = d_sync[d_index];
+    gr_int32 marker = ((val & 0x0000FFFFFFFF0000ULL)) >> 16;
+
+    if (gr_count_bits32(marker^FLEX_SYNC_MARKER) < 4) {
+        gr_int32 code = ((val & 0xFFFF000000000000ULL) >> 32) |
+                         (val & 0x000000000000FFFFULL);
+
+        for (int i = 0; i < num_flex_modes; i++) {
+            if (gr_count_bits32(code^flex_modes[i].sync) < 4) {
+                d_mode = i;
+                return true;
+            }
+        }
+
+        // Marker received but doesn't match known codes
+        // All codes have high word inverted to low word
+        unsigned short high = (code & 0xFFFF0000) >> 16;
+        unsigned short low = code & 0x0000FFFF;
+        unsigned short syn = high^low;
+        if (syn == 0xFFFF)
+            fprintf(stderr, "Unknown sync code detected: %08X\n", code);
+    }
+
+    return false;
+}
+
+void pgr_flex_deframer::enter_idle()
+{
+    d_state = ST_IDLE;
+    d_mode = 0;
+    d_baudrate = 1600;
+    d_levels = 2;
+    d_spb = d_rate/d_baudrate;
+    d_index = 0;
+    d_count = 0;
+    d_center = 0;
+}
+
+void pgr_flex_deframer::enter_syncing()
+{
+    d_start = d_index;
+    d_state = ST_SYNCING;
+}
+
+void pgr_flex_deframer::enter_sync1()
+{
+    d_end = d_index;
+    d_center = index_avg(d_start, d_end);
+    d_state = ST_SYNC1;
+    d_count = 0;
+    fprintf(stderr, "SYNC1=%08X\n", flex_modes[d_mode].sync);
+}
+
+void pgr_flex_deframer::enter_sync2()
+{
+    d_state = ST_SYNC2;
+    d_count = 0;
+
+    d_baudrate = flex_modes[d_mode].baud;
+    d_levels = flex_modes[d_mode].levels;
+    d_spb = d_rate/d_baudrate;
+
+    if (d_baudrate == 3200) {
+        // Oversampling buffer just got halved
+        d_center = d_center/2;
+        d_index = d_index/2-d_spb/2; // We're here at the center of a 1600 
baud bit
+        d_count = -1;                // So this hack gets us in the right 
place for 3200
+        d_hibit = false;
+    }
+}
+
+void pgr_flex_deframer::enter_data()
+{
+    d_state = ST_DATA;
+    d_count = 0;
+}
+
+void pgr_flex_deframer::do_multiphase_shift(unsigned char sym)
+{
+    // Bits are encoded with 2-bit gray code 
+    // 
+    // SYM      Bit1 Bit2
+    // ---      ---- ----
+    //  0         1    1
+    //  1         1    0
+    //  2         0    0
+    //  3         0    1
+
+    if (d_baudrate == 1600) {
+        d_phase_a = (d_phase_a << 1) | (sym < 2);
+        if (d_levels == 4) 
+            d_phase_b = (d_phase_b << 1) | (sym == 0 || sym == 3);
+    }
+    else { // baudrate == 3200, multiplex alternating bits
+        if (!d_hibit) {
+            d_phase_a = (d_phase_a << 1) | (sym < 2);
+            if (d_levels == 4)
+                d_phase_b = (d_phase_b << 1) | (sym == 0 || sym == 3);
+            d_hibit = true;
+        }
+        else {
+            d_phase_c = (d_phase_a << 1) | (sym < 2);
+            if (d_levels == 4)
+                d_phase_d = (d_phase_b << 1) | (sym == 0 || sym == 3);
+            d_hibit = false;
+        }
+    }
+}
+
+int pgr_flex_deframer::general_work(int noutput_items,
+    gr_vector_int &ninput_items,
+    gr_vector_const_void_star &input_items,
+       gr_vector_void_star &output_items)
+{
+    const unsigned char *in = (const unsigned char *)input_items[0];
+    gr_int32 *out = (gr_int32 *)output_items[0];
+
+    int i = 0, j = 0;
+    int ninputs = ninput_items[0];
+
+    while (i++ < ninputs && j < noutput_items) {
+        unsigned char sym = *in++;
+        switch (d_state) {
+            case ST_IDLE:
+                if (test_sync(sym))
+                    enter_syncing();
+                break;
+
+            case ST_SYNCING:
+                if (!test_sync(sym)) {
+                    enter_sync1();
+                    // Output sync code
+                    *out++ = flex_modes[d_mode].sync; j++;
+                }
+                break;
+
+            case ST_SYNC1:
+                if (d_index == d_center) {
+                    do_multiphase_shift(sym);
+                    if (++d_count == 48) { // Skip 16 bits of dotting
+                        // Output frame information word
+                        *out++ = d_phase_a; j++;
+                        enter_sync2();
+                    }
+                }
+                break;
+
+            case ST_SYNC2:
+                if (d_index == d_center) {
+                    do_multiphase_shift(sym);
+                    // Skip 25 ms = 40 bits @ 1600 bps, 80 @ 3200 bps
+                    if (++d_count == d_baudrate/40) {
+                        enter_data();
+                        break;
+                    }
+                }
+                break;
+
+            case ST_DATA:
+                if (d_index == d_center) {
+                    do_multiphase_shift(sym);
+                    d_count++;
+
+                    // Send 32-bit code words for each defined phase
+                    if (d_count % (d_baudrate/50) == 0) {
+                        if (flex_modes[d_mode].phase_a) {
+                            *out++ = d_phase_a; j++;
+                        }
+                        if (flex_modes[d_mode].phase_b) {
+                            *out++ = d_phase_b; j++;
+                        }
+                        if (flex_modes[d_mode].phase_c) {
+                            *out++ = d_phase_c; j++;
+                        }
+                        if (flex_modes[d_mode].phase_d) {
+                            *out++ = d_phase_d; j++;
+                        }
+                    }
+
+                    // Data portion of frame is 1.76 sec. at either baud rate
+                    if (d_count == d_baudrate*1760/1000)
+                        enter_idle();
+                }
+                break;
+
+            default:
+                assert(0); // memory corruption of d_state if ever gets here
+                break;
+        }
+
+        if (++d_index >= d_spb)
+            d_index = 0;
+    }
+
+    // Inform scheduler what we did;
+    consume_each(i-1);
+    return j;
+}

Copied: 
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/lib/pgr_flex_deframer.h 
(from rev 3508, 
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/lib/pgr_flex_sync.h)
===================================================================
--- 
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/lib/pgr_flex_deframer.h 
                            (rev 0)
+++ 
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/lib/pgr_flex_deframer.h 
    2006-09-09 16:15:29 UTC (rev 3509)
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2006 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_PGR_FLEX_DEFRAMER_H
+#define INCLUDED_PGR_FLEX_DEFRAMER_H
+
+#include <gr_block.h>
+
+class pgr_flex_deframer;
+typedef boost::shared_ptr<pgr_flex_deframer> pgr_flex_deframer_sptr;
+typedef std::vector<gr_int64> gr_int64_vector;
+
+pgr_flex_deframer_sptr pgr_make_flex_deframer(int rate);
+
+/*!
+ * \brief flex deframer description
+ * \ingroup block
+ */
+
+class pgr_flex_deframer : public gr_block
+{
+private:
+    // Constructors
+    friend pgr_flex_deframer_sptr pgr_make_flex_deframer(int rate);
+    pgr_flex_deframer(int rate);
+   
+    // State machine transitions
+    void enter_idle();
+    void enter_syncing();
+    void enter_sync1();
+    void enter_sync2();
+    void enter_data();
+
+    int index_avg(int start, int end);
+    bool test_sync(unsigned char sym);
+    void do_multiphase_shift(unsigned char sym);
+    
+    // Simple state machine
+    enum state_t { ST_IDLE, ST_SYNCING, ST_SYNC1, ST_SYNC2, ST_DATA };
+    state_t d_state;     
+
+    int d_rate;     // Incoming sample rate
+    int d_index;    // Index into current baud
+    int d_start;    // Start of good sync 
+    int d_center;   // Center of bit
+    int d_end;      // End of good sync
+    int d_count;    // Bit counter
+
+    int d_mode;     // Current packet mode
+    int d_baudrate; // Current decoding baud rate
+    int d_levels;   // Current decoding levels
+    int d_spb;      // Current samples per baud
+    bool d_hibit;   // Current bit is high bit when 3200 baud
+
+    gr_int64_vector d_sync; // Trial synchronizers
+    gr_int32 d_phase_a;     // PHASEA accumulator
+    gr_int32 d_phase_b;     // PHASEB accumulator
+    gr_int32 d_phase_c;     // PHASEB accumulator
+    gr_int32 d_phase_d;     // PHASEB accumulator
+
+public:
+    void forecast(int noutput_items, gr_vector_int &inputs_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_PGR_FLEX_DEFRAMER_H */

Deleted: 
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/lib/pgr_flex_sync.cc

Deleted: 
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/lib/pgr_flex_sync.h

Modified: 
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/python/flex_demod.py
===================================================================
--- 
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/python/flex_demod.py    
    2006-09-09 00:51:00 UTC (rev 3508)
+++ 
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/python/flex_demod.py    
    2006-09-09 16:15:29 UTC (rev 3509)
@@ -32,10 +32,10 @@
 
     Flow graph (so far):
 
-    QUAD   - Quadrature demodulator converts FSK to baseband amplitudes  
-    LPF    - Low pass filter to remove noise prior to slicer
-    SLICER - Converts input to one of four symbols (0, 1, 2, 3)
-    SYNC   - Syncronizes symbol stream and outputs FLEX codewords
+    QUAD     - Quadrature demodulator converts FSK to baseband amplitudes  
+    LPF      - Low pass filter to remove noise prior to slicer
+    SLICER   - Converts input to one of four symbols (0, 1, 2, 3)
+    DEFRAMER - Syncronizes symbol stream and outputs FLEX codewords
     ---
 
     @param fg: flowgraph
@@ -49,9 +49,9 @@
 
         taps = optfir.low_pass(1.0, channel_rate, 3200, 6400, 0.1, 60)
         LPF = gr.fir_filter_fff(1, taps)
-       SLICER = pgr.slicer_fb(.001, .00001) # Attack, decay
-       SYNC = pgr.flex_sync(channel_rate)
+        SLICER = pgr.slicer_fb(.001, .00001) # Attack, decay
+        DEFRAMER = pgr.flex_deframer(channel_rate)
        
-        fg.connect(QUAD, LPF, SLICER, SYNC)
+        fg.connect(QUAD, LPF, SLICER, DEFRAMER)
 
-        gr.hier_block.__init__(self, fg, QUAD, SYNC)
+        gr.hier_block.__init__(self, fg, QUAD, DEFRAMER)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]