[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r3502 - gnuradio/branches/developers/jcorgan/pager/gr-
From: |
jcorgan |
Subject: |
[Commit-gnuradio] r3502 - gnuradio/branches/developers/jcorgan/pager/gr-pager/src/lib |
Date: |
Thu, 7 Sep 2006 21:21:39 -0600 (MDT) |
Author: jcorgan
Date: 2006-09-07 21:21:39 -0600 (Thu, 07 Sep 2006)
New Revision: 3502
Modified:
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
Log:
Work-in-progress. Emits frame sync and frame information word. Ready
to handle collecting SYNC2 and DATA portion of frame.
Modified:
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.cc
2006-09-08 02:42:01 UTC (rev 3501)
+++
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/lib/pgr_flex_sync.cc
2006-09-08 03:21:39 UTC (rev 3502)
@@ -46,7 +46,7 @@
// FLEX sync block takes input from symbol stream with alphabet [0, 1, 2, 3]
// at specified channel rate and and outputs 32-bit FLEX code words
-// at 50 or 100 code words per second (based on detected mode in sync
+// at 50, 100, or 200 code words per second (based on detected mode in sync
// word).
pgr_flex_sync::pgr_flex_sync(int rate) :
@@ -56,18 +56,9 @@
d_shifters(rate/1600) // Maximum samples per baud
{
d_rate = rate;
- d_index = 0;
- d_baudrate = 1600;
- d_levels = 2;
- d_spb = rate/d_baudrate;
- d_state = ST_IDLE;
- d_mode = -1;
+ enter_idle();
}
-pgr_flex_sync::~pgr_flex_sync()
-{
-}
-
void pgr_flex_sync::forecast(int noutput_items, gr_vector_int &inputs_required)
{
// samples per bit X 32 bits * number of outputs needed
@@ -76,6 +67,15 @@
inputs_required[i] = items;
}
+int pgr_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 pgr_flex_sync::test_sync()
{
// 64-bit FLEX sync code:
@@ -116,60 +116,82 @@
return false;
}
-static inline int cog(int start, int end, int mod)
+void pgr_flex_sync::enter_idle()
{
- // modulo average
- if (start < end)
- return (end + start)/2;
- else
- return ((end + start)/2 + mod/2) % mod;
+ 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;
}
+void pgr_flex_sync::enter_syncing()
+{
+ d_start = d_index;
+ d_state = ST_SYNCING;
+}
+
+void pgr_flex_sync::enter_sync1()
+{
+ d_end = d_index;
+ d_center = index_avg(d_start, d_end);
+ d_state = ST_SYNC1;
+ d_count = 0;
+ printf("SYNC1=%08X COG=%2i ", flex_codes[d_mode], d_center);
+}
+
+void pgr_flex_sync::enter_sync2()
+{
+ d_state = ST_SYNC2;
+ // Shift baud rate here if needed
+}
+
int pgr_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];
- gr_int32 *out = (gr_int32 *) output_items[0];
+ gr_int32 *out = (gr_int32 *)output_items[0];
- int consumed = 0, produced = 0;
+ int i = 0, j = 0;
int ninputs = ninput_items[0];
- while (consumed++ < ninputs && produced < noutput_items) {
+ while (i++ < ninputs && j < noutput_items) {
d_shifters[d_index] = (d_shifters[d_index] << 1) | (*in++ < 2);
switch (d_state) {
case ST_IDLE:
- if (test_sync()) {
- d_start = d_index;
- d_state = ST_SYNCING;
- }
+ if (test_sync())
+ enter_syncing();
break;
case ST_SYNCING:
if (!test_sync()) {
- d_end = d_index;
- d_center = cog(d_start, d_end, d_spb);
- d_state = ST_SYNCED;
- printf("CODE=%08X SOG=%2i EOG=%2i COG=%2i\n",
flex_codes[d_mode], d_start, d_end, d_center);
+ enter_sync1();
+ // Output sync code
+ *out++ = flex_codes[d_mode]; j++;
}
break;
- case ST_SYNCED:
+ case ST_SYNC1:
if (d_index == d_center) {
- // Accumulate bits here
- // d_shifters[d_center] has good stuff in it
- // 'break' if not done collecting bits yet
+ // Skip 16 bits of dotting
+ if (++d_count == 48) {
+ gr_int32 fiw = (gr_int32)(d_shifters[d_center] &
0x00000000FFFFFFFFULL);
+ // Output frame information word
+ *out++ = fiw; j++;
+ printf("FIW=%08X\n", fiw);
+ enter_sync2();
+ }
}
+ break;
- // Fall through to here when done
- d_state = ST_IDLE;
-
- // TODO: make into a function call
- d_mode = -1;
- d_baudrate = 1600;
- d_spb = d_rate/d_baudrate;
+ case ST_SYNC2:
+ // Collect sync2 bits here
+ enter_idle();
break;
default:
@@ -181,10 +203,7 @@
d_index = 0;
}
- // For now pretend we output everything we could
- produced = noutput_items;
-
// Inform scheduler what we did;
- consume_each(in - (unsigned char *)input_items[0]);
- return produced;
+ consume_each(i-1);
+ return j;
}
Modified:
gnuradio/branches/developers/jcorgan/pager/gr-pager/src/lib/pgr_flex_sync.h
===================================================================
--- gnuradio/branches/developers/jcorgan/pager/gr-pager/src/lib/pgr_flex_sync.h
2006-09-08 02:42:01 UTC (rev 3501)
+++ gnuradio/branches/developers/jcorgan/pager/gr-pager/src/lib/pgr_flex_sync.h
2006-09-08 03:21:39 UTC (rev 3502)
@@ -38,24 +38,38 @@
class pgr_flex_sync : public gr_block
{
private:
+ // Constructors
friend pgr_flex_sync_sptr pgr_make_flex_sync(int rate);
pgr_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();
+
+ // Simple state machine
+ enum state_t { ST_IDLE, ST_SYNCING, ST_SYNC1, ST_SYNC2, ST_DATA };
+ state_t d_state;
- enum state_t { ST_IDLE, ST_SYNCING, ST_SYNCED };
-
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
- int d_start; // Start of good sync
- int d_end; // End of good sync
- int d_center; // Center of bit
- int d_mode; // Current packet mode
- state_t d_state;
- gr_int64_vector d_shifters;
+ gr_int64_vector d_shifters; // Trial synchronizers
+
public:
void forecast(int noutput_items, gr_vector_int &inputs_required);
@@ -63,8 +77,6 @@
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
-
- ~pgr_flex_sync(); // Needed?
};
#endif /* INCLUDED_PGR_FLEX_SYNC_H */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r3502 - gnuradio/branches/developers/jcorgan/pager/gr-pager/src/lib,
jcorgan <=