diff options
author | Dieter Spaar <spaar@mirider.augusta.de> | 2012-10-08 21:36:03 +0200 |
---|---|---|
committer | Holger Hans Peter Freyther <zecke@selfish.org> | 2012-10-12 16:22:36 +0200 |
commit | 08c103251c6dee2b3276ea7d5b1519560c910cfe (patch) | |
tree | 859f89139578704483cb5ba3159dcaedd9834390 | |
parent | d72c478b06a4a418046ee203aeba6b5d6f0bc69e (diff) |
Make sure sync header was fully received
The sync header consists of 16 zero-bits followed by 1 one-bit. Before,
subchan_demux only tested for the 16 zero-bits. But if the previous
frame ended in one or more zero-bits these were then already counted as
belonging to the sync header, leading to a frame that was shifted by one
or more bits.
-rw-r--r-- | src/subchan_demux.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/subchan_demux.c b/src/subchan_demux.c index 8613c17..4cd6094 100644 --- a/src/subchan_demux.c +++ b/src/subchan_demux.c @@ -46,18 +46,18 @@ static inline void append_bit(struct demux_subch *sch, uint8_t bit) #define SYNC_HDR_BITS 16 static const uint8_t nullbytes[SYNC_HDR_BITS]; -/* check if we have just completed the 16 bit zero sync header, - * in accordance with GSM TS 08.60 Chapter 4.8.1 */ +/* check if we have just completed the 16 bit zero + 1 bit one sync + * header, in accordance with GSM TS 08.60 Chapter 4.8.1 */ static int sync_hdr_complete(struct demux_subch *sch, uint8_t bit) { if (bit == 0) sch->consecutive_zeros++; - else - sch->consecutive_zeros = 0; - - if (sch->consecutive_zeros >= SYNC_HDR_BITS) { + else { + if (sch->consecutive_zeros >= SYNC_HDR_BITS) { + sch->consecutive_zeros = 0; + return 1; + } sch->consecutive_zeros = 0; - return 1; } return 0; @@ -67,10 +67,11 @@ static int sync_hdr_complete(struct demux_subch *sch, uint8_t bit) static void resync_to_here(struct demux_subch *sch) { memset(sch->out_bitbuf, 0, SYNC_HDR_BITS); + sch->out_bitbuf[SYNC_HDR_BITS] = 1; /* set index in a way that we can continue receiving bits after * the end of the SYNC header */ - sch->out_idx = SYNC_HDR_BITS; + sch->out_idx = SYNC_HDR_BITS + 1; sch->in_sync = 1; } |