00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef INCLUDED_GR_PACKET_SINK_H
00024 #define INCLUDED_GR_PACKET_SINK_H
00025
00026 #include <gr_sync_block.h>
00027 #include <gr_msg_queue.h>
00028
00029 class gr_packet_sink;
00030 typedef boost::shared_ptr<gr_packet_sink> gr_packet_sink_sptr;
00031
00032 gr_packet_sink_sptr
00033 gr_make_packet_sink (const std::vector<unsigned char>& sync_vector,
00034 gr_msg_queue_sptr target_queue,
00035 int threshold = -1
00036 );
00041 class gr_packet_sink : public gr_sync_block
00042 {
00043 friend gr_packet_sink_sptr
00044 gr_make_packet_sink (const std::vector<unsigned char>& sync_vector,
00045 gr_msg_queue_sptr target_queue,
00046 int threshold);
00047
00048 private:
00049 enum state_t {STATE_SYNC_SEARCH, STATE_HAVE_SYNC, STATE_HAVE_HEADER};
00050
00051 static const int MAX_PKT_LEN = 4096;
00052 static const int HEADERBITLEN = 32;
00053
00054 gr_msg_queue_sptr d_target_queue;
00055 unsigned long long d_sync_vector;
00056 unsigned int d_threshold;
00057
00058 state_t d_state;
00059
00060 unsigned long long d_shift_reg;
00061
00062 unsigned int d_header;
00063 int d_headerbitlen_cnt;
00064
00065 unsigned char d_packet[MAX_PKT_LEN];
00066 unsigned char d_packet_byte;
00067 int d_packet_byte_index;
00068 int d_packetlen;
00069 int d_packetlen_cnt;
00070
00071 protected:
00072 gr_packet_sink(const std::vector<unsigned char>& sync_vector,
00073 gr_msg_queue_sptr target_queue,
00074 int threshold);
00075
00076 void enter_search();
00077 void enter_have_sync();
00078 void enter_have_header(int payload_len);
00079
00080 int slice(float x) { return x > 0 ? 1 : 0; }
00081
00082 bool header_ok()
00083 {
00084
00085 return ((d_header >> 16) ^ (d_header & 0xffff)) == 0;
00086 }
00087
00088 int header_payload_len()
00089 {
00090
00091 int t = (d_header >> 16) & 0xffff;
00092 return t;
00093 }
00094
00095 public:
00096 ~gr_packet_sink();
00097
00098 int work(int noutput_items,
00099 gr_vector_const_void_star &input_items,
00100 gr_vector_void_star &output_items);
00101
00102
00104 bool carrier_sensed() const
00105 {
00106 return d_state != STATE_SYNC_SEARCH;
00107 }
00108
00109 };
00110
00111 #endif