GNU Radio 3.6.5.1 C++ API
digital_framer_sink_1.h
Go to the documentation of this file.
1
/* -*- c++ -*- */
2
/*
3
* Copyright 2005,2006,2012 Free Software Foundation, Inc.
4
*
5
* This file is part of GNU Radio
6
*
7
* GNU Radio is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 3, or (at your option)
10
* any later version.
11
*
12
* GNU Radio is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License
18
* along with GNU Radio; see the file COPYING. If not, write to
19
* the Free Software Foundation, Inc., 51 Franklin Street,
20
* Boston, MA 02110-1301, USA.
21
*/
22
23
#ifndef INCLUDED_GR_FRAMER_SINK_1_H
24
#define INCLUDED_GR_FRAMER_SINK_1_H
25
26
#include <
digital_api.h
>
27
#include <
gr_sync_block.h
>
28
#include <
gr_msg_queue.h
>
29
30
class
digital_framer_sink_1
;
31
typedef
boost::shared_ptr<digital_framer_sink_1>
digital_framer_sink_1_sptr
;
32
33
DIGITAL_API
digital_framer_sink_1_sptr
34
digital_make_framer_sink_1
(
gr_msg_queue_sptr
target_queue);
35
36
/*!
37
* \brief Given a stream of bits and access_code flags, assemble packets.
38
* \ingroup packet_operators_blk
39
*
40
* \details
41
* input: stream of bytes from gr_correlate_access_code_bb
42
* output: none. Pushes assembled packet into target queue
43
*
44
* The framer expects a fixed length header of 2 16-bit shorts
45
* containing the payload length, followed by the payload. If the
46
* 2 16-bit shorts are not identical, this packet is ignored. Better
47
* algs are welcome.
48
*
49
* The input data consists of bytes that have two bits used.
50
* Bit 0, the LSB, contains the data bit.
51
* Bit 1 if set, indicates that the corresponding bit is the
52
* the first bit of the packet. That is, this bit is the first
53
* one after the access code.
54
*/
55
class
DIGITAL_API
digital_framer_sink_1
:
public
gr_sync_block
56
{
57
friend
DIGITAL_API
digital_framer_sink_1_sptr
58
digital_make_framer_sink_1
(
gr_msg_queue_sptr
target_queue);
59
60
private
:
61
enum
state_t {STATE_SYNC_SEARCH, STATE_HAVE_SYNC, STATE_HAVE_HEADER};
62
63
static
const
int
MAX_PKT_LEN = 4096;
64
static
const
int
HEADERBITLEN = 32;
65
66
gr_msg_queue_sptr
d_target_queue;
// where to send the packet when received
67
state_t d_state;
68
unsigned
int
d_header;
// header bits
69
int
d_headerbitlen_cnt;
// how many so far
70
71
unsigned
char
d_packet[MAX_PKT_LEN];
// assembled payload
72
unsigned
char
d_packet_byte;
// byte being assembled
73
int
d_packet_byte_index;
// which bit of d_packet_byte we're working on
74
int
d_packetlen;
// length of packet
75
int
d_packet_whitener_offset;
// offset into whitener string to use
76
int
d_packetlen_cnt;
// how many so far
77
78
protected
:
79
digital_framer_sink_1
(
gr_msg_queue_sptr
target_queue);
80
81
void
enter_search();
82
void
enter_have_sync();
83
void
enter_have_header(
int
payload_len,
int
whitener_offset);
84
85
bool
header_ok()
86
{
87
// confirm that two copies of header info are identical
88
return
((d_header >> 16) ^ (d_header & 0xffff)) == 0;
89
}
90
91
void
header_payload(
int
*len,
int
*offset)
92
{
93
// header consists of two 16-bit shorts in network byte order
94
// payload length is lower 12 bits
95
// whitener offset is upper 4 bits
96
*len = (d_header >> 16) & 0x0fff;
97
*offset = (d_header >> 28) & 0x000f;
98
}
99
100
public
:
101
~
digital_framer_sink_1
();
102
103
int
work
(
int
noutput_items,
104
gr_vector_const_void_star
&input_items,
105
gr_vector_void_star
&output_items);
106
};
107
108
#endif
/* INCLUDED_GR_FRAMER_SINK_1_H */
gr-digital
include
digital_framer_sink_1.h
Generated on Mon Aug 19 2013 15:37:30 for GNU Radio 3.6.5.1 C++ API by
1.8.1.2