GNU Radio's FRAMERS Package
hdlc_framer.h
Go to the documentation of this file.
1 #include <vector>
2 
3 using std::vector;
4 #include <stdio.h>
5 class fifo_c
6 {
7 private:
8  static const int FIFO_SIZE = 76651; // (8192 x 8 x 1.2) + 7
9  unsigned char d_ring_buf[FIFO_SIZE];
10  int d_pop_index; // next position to pop from
11  int d_push_index; // next position to push to
12 public:
13 fifo_c():d_pop_index(0),d_push_index(0) {};
14  ~fifo_c() {};
15  void push(unsigned char c)
16  {
17  if (d_push_index-d_pop_index>500){
18  //printf("framer: push-pop %d\n",d_push_index-d_pop_index);
19  }
20  d_ring_buf[d_push_index] = c;
21  d_push_index = (d_push_index + 1) % FIFO_SIZE;
22  };
23  unsigned char pop()
24  {
25  unsigned char c;
26  c = d_ring_buf[d_pop_index];
27  d_pop_index = (d_pop_index + 1) % FIFO_SIZE;
28  return c;
29  };
30  int empty() { return d_pop_index==d_push_index; };
31  int full() { return (d_push_index+1)%FIFO_SIZE == d_pop_index; };
32  int space_left() { return FIFO_SIZE - 1 - (d_push_index - d_pop_index)%FIFO_SIZE; };
33 };
34 
35 
36 // Private CONSTANTS ------------------
37 static const int LINUX = 0;
38 static const int OSX = 1;
39 static const int FRAME_MAX = 8192;
40 static const int STR_MAX = 256; // Limit string lengths
41 static const unsigned char FLAG = 0x7E;
42 
43 
44 
45 
47 public:
48  hdlc_framer(int dlci);
49  ~hdlc_framer();
50  unsigned short crc16(unsigned char *data_p,
51  unsigned short length);
52 
53 
54  // Private Methods ----------
55 
56 
57  void encapsulate_incoming_packet(unsigned char * frame_buf,int packet_length);
58  vector<unsigned char> dump_buffer();
59 
60  // For debug only
61  void push_flag(void);
62  void bitstuff_byte(unsigned char byte);
63  void bitstuff_and_frame_packet(unsigned char * frame_buf,
64  int frame_size);
65 
66 private:
67  // Private CONSTANTS ------------------
68  static const int LINUX = 0;
69  static const int OSX = 1;
70  static const int FRAME_MAX = 8192;
71  static const int STR_MAX = 256; // Limit string lengths
72  static const unsigned char FLAG = 0x7E;
73 
74  // Private Attributes ---------
75 
76  // Frame Relay's Data Link Channel Indicator
77  int d_dlci;
78 
79  // MPoFR Header
80  unsigned char d_header[4];
81 
82 
83  // Bitstuffing state variable
84  int d_consecutive_one_bits;
85 
86  // File descriptor for tun device
87  int d_tun_fd;
88 
89  // Bitstream fifo
90  fifo_c d_fifo;
91 
92  // Data statistics
93  int d_flag_cnt;
94  int d_frame_cnt;
95  int d_byte_cnt;
96  int d_stuffed_zero_cnt;
97 
98 };
99 
100 
void push(unsigned char c)
Definition: hdlc_framer.h:15
int space_left()
Definition: hdlc_framer.h:32
hdlc_framer(int dlci)
Definition: hdlc_framer.h:5
fifo_c()
Definition: hdlc_framer.h:13
void encapsulate_incoming_packet(unsigned char *frame_buf, int packet_length)
unsigned char pop()
Definition: hdlc_framer.h:23
void push_flag(void)
static const int STR_MAX
Definition: hdlc_framer.h:40
static const int OSX
Definition: hdlc_framer.h:38
int empty()
Definition: hdlc_framer.h:30
static const int FRAME_MAX
Definition: hdlc_framer.h:39
void bitstuff_and_frame_packet(unsigned char *frame_buf, int frame_size)
Definition: hdlc_framer.h:46
~fifo_c()
Definition: hdlc_framer.h:14
void bitstuff_byte(unsigned char byte)
int full()
Definition: hdlc_framer.h:31
vector< unsigned char > dump_buffer()
unsigned short crc16(unsigned char *data_p, unsigned short length)
static const unsigned char FLAG
Definition: hdlc_framer.h:41
static const int LINUX
Definition: hdlc_framer.h:37