[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r3604 - gnuradio/branches/developers/jcorgan/pager/gr-
From: |
jcorgan |
Subject: |
[Commit-gnuradio] r3604 - gnuradio/branches/developers/jcorgan/pager/gr-pager/src |
Date: |
Thu, 21 Sep 2006 17:59:21 -0600 (MDT) |
Author: jcorgan
Date: 2006-09-21 17:59:21 -0600 (Thu, 21 Sep 2006)
New Revision: 3604
Added:
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/pager_flex_sync.cc
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/pager_flex_sync.h
Removed:
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/pager_flex_message.cc
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/pager_flex_message.h
Modified:
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/Makefile.am
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/flex_demod.py
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/pager.i
Log:
Work in progress refactoring FLEX sync block.
Modified: gnuradio/branches/developers/jcorgan/pager/gr-pager/src/Makefile.am
===================================================================
--- gnuradio/branches/developers/jcorgan/pager/gr-pager/src/Makefile.am
2006-09-21 21:54:16 UTC (rev 3603)
+++ gnuradio/branches/developers/jcorgan/pager/gr-pager/src/Makefile.am
2006-09-21 23:59:21 UTC (rev 3604)
@@ -75,8 +75,8 @@
_pager_swig_la_SOURCES = \
pager_swig.cc \
pager_slicer_fb.cc \
+ pager_flex_sync.cc \
pager_flex_deframer.cc \
- pager_flex_message.cc \
pageri_flex_modes.cc \
pageri_bch3221.cc
# Additional source modules here
@@ -96,8 +96,8 @@
# These headers get installed in ${prefix}/include/gnuradio
grinclude_HEADERS = \
pager_slicer_fb.h \
+ pager_flex_sync.h \
pager_flex_deframer.h \
- pager_flex_message.h \
pageri_flex_modes.h \
pageri_bch3221.h
# Additional header files here
Modified: gnuradio/branches/developers/jcorgan/pager/gr-pager/src/flex_demod.py
===================================================================
--- gnuradio/branches/developers/jcorgan/pager/gr-pager/src/flex_demod.py
2006-09-21 21:54:16 UTC (rev 3603)
+++ gnuradio/branches/developers/jcorgan/pager/gr-pager/src/flex_demod.py
2006-09-21 23:59:21 UTC (rev 3604)
@@ -50,9 +50,11 @@
taps = optfir.low_pass(1.0, channel_rate, 3200, 6400, 0.1, 60)
LPF = gr.fir_filter_fff(1, taps)
SLICER = pager_swig.slicer_fb(.001, .00001) # Attack, decay
- DEFRAMER = pager_swig.flex_deframer(channel_rate)
- MESSAGE = pager_swig.flex_message()
+ SYNC = pager_swig.flex_sync(channel_rate)
+
+# DEFRAMER = pager_swig.flex_deframer(channel_rate)
+# MESSAGE = pager_swig.flex_message()
- fg.connect(QUAD, LPF, SLICER, DEFRAMER, MESSAGE)
+ fg.connect(QUAD, LPF, SLICER, SYNC)
- gr.hier_block.__init__(self, fg, QUAD, MESSAGE)
+ gr.hier_block.__init__(self, fg, QUAD, SYNC)
Modified: gnuradio/branches/developers/jcorgan/pager/gr-pager/src/pager.i
===================================================================
--- gnuradio/branches/developers/jcorgan/pager/gr-pager/src/pager.i
2006-09-21 21:54:16 UTC (rev 3603)
+++ gnuradio/branches/developers/jcorgan/pager/gr-pager/src/pager.i
2006-09-21 23:59:21 UTC (rev 3604)
@@ -26,8 +26,8 @@
%{
#include "gnuradio_swig_bug_workaround.h" // mandatory bug fix
#include "pager_slicer_fb.h"
+#include "pager_flex_sync.h"
#include "pager_flex_deframer.h"
-#include "pager_flex_message.h"
#include <stdexcept>
%}
@@ -47,28 +47,28 @@
// ----------------------------------------------------------------
-GR_SWIG_BLOCK_MAGIC(pager,flex_deframer);
+GR_SWIG_BLOCK_MAGIC(pager,flex_sync);
-pager_flex_deframer_sptr pager_make_flex_deframer(int rate);
+pager_flex_sync_sptr pager_make_flex_sync(int rate);
-class pager_flex_deframer : public gr_block
+class pager_flex_sync : public gr_block
{
private:
- pager_flex_deframer(int rate);
+ pager_flex_sync(int rate);
public:
};
// ----------------------------------------------------------------
-GR_SWIG_BLOCK_MAGIC(pager,flex_message);
+GR_SWIG_BLOCK_MAGIC(pager,flex_deframer);
-pager_flex_message_sptr pager_make_flex_message();
+pager_flex_deframer_sptr pager_make_flex_deframer(int rate);
-class pager_flex_message : public gr_block
+class pager_flex_deframer : public gr_block
{
private:
- pager_flex_message();
+ pager_flex_deframer(int rate);
public:
};
Deleted:
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/pager_flex_message.cc
Deleted:
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/pager_flex_message.h
Added:
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/pager_flex_sync.cc
===================================================================
--- gnuradio/branches/developers/jcorgan/pager/gr-pager/src/pager_flex_sync.cc
(rev 0)
+++ gnuradio/branches/developers/jcorgan/pager/gr-pager/src/pager_flex_sync.cc
2006-09-21 23:59:21 UTC (rev 3604)
@@ -0,0 +1,263 @@
+/*
+ * 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., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pager_flex_sync.h>
+#include <pageri_flex_modes.h>
+#include <gr_io_signature.h>
+#include <gr_count_bits.h>
+
+pager_flex_sync_sptr pager_make_flex_sync(int rate)
+{
+ return pager_flex_sync_sptr(new pager_flex_sync(rate));
+}
+
+// FLEX sync block takes input from sliced baseband stream [0-3] at specified
+// channel rate. Symbol timing is establish based on receiving one of the
+// defined FLEX protocol synchronization words. The block outputs one FLEX
frame
+// worth of symbols [0-3] at either 1600 or 3200 bps as indicated by the type
+// of frame syncronized
+
+pager_flex_sync::pager_flex_sync(int rate) :
+ gr_block ("flex_sync",
+ gr_make_io_signature (1, 1, sizeof(unsigned char)),
+ gr_make_io_signature (1, 1, sizeof(unsigned char))),
+ d_sync(rate/1600) // Maximum samples per baud
+{
+ d_rate = rate;
+ enter_idle();
+}
+
+void pager_flex_sync::forecast(int noutput_items, gr_vector_int
&inputs_required)
+{
+ // samples per bit X number of outputs needed
+ int items = noutput_items*d_spb;
+ for (unsigned int i = 0; i < inputs_required.size(); i++)
+ inputs_required[i] = items;
+}
+
+int pager_flex_sync::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 pager_flex_sync::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 pager_flex_sync::enter_idle()
+{
+ d_state = ST_IDLE;
+ d_index = 0;
+ d_start = 0;
+ d_center = 0;
+ d_end = 0;
+ d_count = 0;
+ d_mode = 0;
+ d_baudrate = 1600;
+ d_levels = 2;
+ d_spb = d_rate/d_baudrate;
+}
+
+void pager_flex_sync::enter_syncing()
+{
+ d_start = d_index;
+ d_state = ST_SYNCING;
+}
+
+void pager_flex_sync::enter_sync1()
+{
+ d_state = ST_SYNC1;
+ d_end = d_index;
+ d_center = index_avg(d_start, d_end);
+ d_count = 0;
+ printf("SYNC1=%08X ", flex_modes[d_mode].sync);
+}
+
+void pager_flex_sync::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
+ }
+}
+
+void pager_flex_sync::enter_data()
+{
+ d_state = ST_DATA;
+ d_count = 0;
+}
+
+unsigned char reverse_bits8(unsigned char val)
+{
+ // This method was attributed to Rich Schroeppel in the Programming
+ // Hacks section of Beeler, M., Gosper, R. W., and Schroeppel, R.
+ // HAKMEM. MIT AI Memo 239, Feb. 29, 1972.
+ //
+ // Reverses 8 bits in 5 machine operations with 64 bit arch
+ return (val * 0x0202020202ULL & 0x010884422010ULL) % 1023;
+}
+
+void print_fiw(gr_int32 fiw)
+{
+ // Cycle is bits 27-24, reversed
+ int cycle = reverse_bits8((fiw >> 20) & 0xF0);
+
+ // Frame is bits 23-17, reversed
+ int frame = reverse_bits8((fiw >> 16) & 0xFE);
+
+ // Bits 16-11 are some sort of marker
+ int unknown1 = (fiw >> 11) & 0x3F;
+
+ // Bits 31-28 are frame number related, but unknown function
+ int unknown2 = reverse_bits8((fiw >> 24) & 0xF0);
+
+ printf("FIW=0x%08X CYC=%i FRM=%i UNK1=0x%02X UNK2=0x%02X\n",
+ fiw, cycle, frame, unknown1, unknown2);
+ fflush(stdout);
+}
+
+int pager_flex_sync::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];
+ unsigned char *out = (unsigned char *)output_items[0];
+
+ int i = 0, j = 0;
+ int ninputs = ninput_items[0];
+
+ while (i < ninputs && j < noutput_items) {
+ unsigned char sym = *in++; i++;
+ d_index = ++d_index % d_spb;
+
+ switch (d_state) {
+ case ST_IDLE:
+ if (test_sync(sym))
+ enter_syncing();
+ break;
+
+ case ST_SYNCING:
+ if (!test_sync(sym))
+ enter_sync1();
+ break;
+
+ case ST_SYNC1:
+ if (d_index == d_center) {
+ d_fiw = (d_fiw << 1) | (sym > 1);
+ // Skip 16 bits of dotting, then 32 bits FIW
+ if (++d_count == 48) {
+ print_fiw(d_fiw);
+ enter_sync2(); // May jump to 3200 bps now
+ }
+ }
+ break;
+
+ case ST_SYNC2:
+ if (d_index == d_center) {
+ // Skip 25 ms = 40 bits @ 1600 bps, 80 @ 3200 bps
+ if (++d_count == d_baudrate/40)
+ enter_data();
+ }
+ break;
+
+ case ST_DATA:
+ if (d_index == d_center) {
+ // Skip 1760 ms = 2816 bits @ 1600 bps, 5632 bits @ 3200 bps
+ if (++d_count == d_baudrate*1760/1000)
+ enter_idle();
+ }
+ break;
+
+ default:
+ assert(0); // memory corruption of d_state if ever gets here
+ break;
+ }
+ }
+
+ consume_each(i);
+ return j;
+}
+
+void pager_flex_sync::output_symbol(unsigned char *out, unsigned char sym)
+{
+ if (d_levels == 2) {
+ *out = (sym > 1) ? 3 : 0; // 2 levels
+ putchar((sym > 1) ? 0x31 : 0x30);
+ }
+ else {
+ *out = sym; // 4 levels
+ putchar(sym+0x30);
+ }
+}
Property changes on:
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/pager_flex_sync.cc
___________________________________________________________________
Name: svn:eol-style
+ native
Added: gnuradio/branches/developers/jcorgan/pager/gr-pager/src/pager_flex_sync.h
===================================================================
--- gnuradio/branches/developers/jcorgan/pager/gr-pager/src/pager_flex_sync.h
(rev 0)
+++ gnuradio/branches/developers/jcorgan/pager/gr-pager/src/pager_flex_sync.h
2006-09-21 23:59:21 UTC (rev 3604)
@@ -0,0 +1,85 @@
+/*
+ * 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., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_PAGER_FLEX_SYNC_H
+#define INCLUDED_PAGER_FLEX_SYNC_H
+
+#include <gr_block.h>
+
+class pager_flex_sync;
+typedef boost::shared_ptr<pager_flex_sync> pager_flex_sync_sptr;
+typedef std::vector<gr_int64> gr_int64_vector;
+
+pager_flex_sync_sptr pager_make_flex_sync(int rate);
+
+/*!
+ * \brief flex sync description
+ * \ingroup block
+ */
+
+class pager_flex_sync : public gr_block
+{
+private:
+ // Constructors
+ friend pager_flex_sync_sptr pager_make_flex_sync(int rate);
+ pager_flex_sync(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 output_symbol(unsigned char *out, 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
+
+ gr_int32 d_fiw; // Frame information word
+
+ gr_int64_vector d_sync; // Trial synchronizers
+
+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_PAGER_FLEX_SYNC_H */
Property changes on:
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/pager_flex_sync.h
___________________________________________________________________
Name: svn:eol-style
+ native
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r3604 - gnuradio/branches/developers/jcorgan/pager/gr-pager/src,
jcorgan <=