GNU Radio's FRAMERS Package
hdlc_deframer.h
Go to the documentation of this file.
1 #include <vector>
2 #include <queue>
3 using std::vector;
4 using std::queue;
5 
6 
8 public:
9  // Constructor/Destructor
10  hdlc_deframer(int dlci);
12 
13  // This function should be called on each new bit
14  void hdlc_state_machine(const unsigned char next_bit);
15 
16  // Remove packet from the queue of valid packets
17  vector<unsigned char> get_packet();
18  bool empty();
19  // ******************
20  // Static functions
21  // ******************
22 
23  // Converts bit stream to byte stream (and removes inserted zeros)
24  int unstuff(const int bit_buf_size,
25  const unsigned char * bit_buf,
26  int * frame_buf_size,
27  unsigned char * frame_buf);
28 
29 
30  // Debugging helper function for printing an HDLC packet
31  static void print_packet(vector<unsigned char> packet);
32 
33  // Public statistics
34  float d_ber;
35 
36 private:
37  // CONSTANTS ------------------
38  static const int SUCCESS = 1;
39  static const int FAIL = 0;
40  static const int BIT_BUF_MAX = 78644; // Allow for up to 20% bitstuffing
41  static const int FRAME_BUF_MAX= 9831; // Allow for no stuffed bits
42  static const int FRAME_MAX = 8192;
43  static const unsigned char FLAG = 0x7E;
44  static const int HUNT = 0;
45  static const int IDLE = 1;
46  static const int FRAMING = 2;
47 
48  // Private Attributes ---------
49 
50  // Frame Relay's Data Link Channel Indicator
51  int d_dlci;
52 
53  // State machine state info
54  int d_state;
55  unsigned char d_byte; // Accumulator for building a flag byte from bits
56  int d_accumulated_bits; // Bit counter for d_byte
57  unsigned char d_bit_buf[BIT_BUF_MAX];
58  int d_bit_buf_size;
59  int d_consecutive_one_bits;
60 
61  // Data statistics
62  int d_flag_cnt;
63  int d_total_byte_cnt;
64  int d_good_frame_cnt;
65  int d_good_byte_cnt;
66  int d_good_dlci_cnt;
67  int d_unstuff_zero_cnt;
68  // Error statistics
69  int d_crc_err_cnt;
70  int d_err_byte_cnt;
71  int d_abort_cnt;
72  int d_seven_ones_cnt;
73  int d_non_align_cnt;
74  int d_giant_cnt;
75  int d_runt_cnt;
76 
77  // Private Functions
78 
79  unsigned short crc16(unsigned char *data_p,
80  unsigned short length);
81 
82  int crc_valid(int frame_size, unsigned char * frame);
83 
84  // This is the function that gets called when a valid packet is found
85  // It adds the valid packet to the list
86  virtual void route_packet(int hdlc_frame_size,
87  unsigned char * hdlc_frame);
88 
89  // Output
90  queue<vector<unsigned char > > d_packets;
91 
92 };
93 
static void print_packet(vector< unsigned char > packet)
hdlc_deframer(int dlci)
vector< unsigned char > get_packet()
Definition: hdlc_deframer.h:7
void hdlc_state_machine(const unsigned char next_bit)
float d_ber
Definition: hdlc_deframer.h:34
int unstuff(const int bit_buf_size, const unsigned char *bit_buf, int *frame_buf_size, unsigned char *frame_buf)