GNU Radio 3.6.5 C++ API
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2005,2006,2012 Free Software Foundation, Inc. 00004 * 00005 * This file is part of GNU Radio 00006 * 00007 * GNU Radio is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 3, or (at your option) 00010 * any later version. 00011 * 00012 * GNU Radio is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with GNU Radio; see the file COPYING. If not, write to 00019 * the Free Software Foundation, Inc., 51 Franklin Street, 00020 * Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #ifndef INCLUDED_GR_FRAMER_SINK_1_H 00024 #define INCLUDED_GR_FRAMER_SINK_1_H 00025 00026 #include <digital_api.h> 00027 #include <gr_sync_block.h> 00028 #include <gr_msg_queue.h> 00029 00030 class digital_framer_sink_1; 00031 typedef boost::shared_ptr<digital_framer_sink_1> digital_framer_sink_1_sptr; 00032 00033 DIGITAL_API digital_framer_sink_1_sptr 00034 digital_make_framer_sink_1(gr_msg_queue_sptr target_queue); 00035 00036 /*! 00037 * \brief Given a stream of bits and access_code flags, assemble packets. 00038 * \ingroup packet_operators_blk 00039 * 00040 * \details 00041 * input: stream of bytes from gr_correlate_access_code_bb 00042 * output: none. Pushes assembled packet into target queue 00043 * 00044 * The framer expects a fixed length header of 2 16-bit shorts 00045 * containing the payload length, followed by the payload. If the 00046 * 2 16-bit shorts are not identical, this packet is ignored. Better 00047 * algs are welcome. 00048 * 00049 * The input data consists of bytes that have two bits used. 00050 * Bit 0, the LSB, contains the data bit. 00051 * Bit 1 if set, indicates that the corresponding bit is the 00052 * the first bit of the packet. That is, this bit is the first 00053 * one after the access code. 00054 */ 00055 class DIGITAL_API digital_framer_sink_1 : public gr_sync_block 00056 { 00057 friend DIGITAL_API digital_framer_sink_1_sptr 00058 digital_make_framer_sink_1(gr_msg_queue_sptr target_queue); 00059 00060 private: 00061 enum state_t {STATE_SYNC_SEARCH, STATE_HAVE_SYNC, STATE_HAVE_HEADER}; 00062 00063 static const int MAX_PKT_LEN = 4096; 00064 static const int HEADERBITLEN = 32; 00065 00066 gr_msg_queue_sptr d_target_queue; // where to send the packet when received 00067 state_t d_state; 00068 unsigned int d_header; // header bits 00069 int d_headerbitlen_cnt; // how many so far 00070 00071 unsigned char d_packet[MAX_PKT_LEN]; // assembled payload 00072 unsigned char d_packet_byte; // byte being assembled 00073 int d_packet_byte_index; // which bit of d_packet_byte we're working on 00074 int d_packetlen; // length of packet 00075 int d_packet_whitener_offset; // offset into whitener string to use 00076 int d_packetlen_cnt; // how many so far 00077 00078 protected: 00079 digital_framer_sink_1(gr_msg_queue_sptr target_queue); 00080 00081 void enter_search(); 00082 void enter_have_sync(); 00083 void enter_have_header(int payload_len, int whitener_offset); 00084 00085 bool header_ok() 00086 { 00087 // confirm that two copies of header info are identical 00088 return ((d_header >> 16) ^ (d_header & 0xffff)) == 0; 00089 } 00090 00091 void header_payload(int *len, int *offset) 00092 { 00093 // header consists of two 16-bit shorts in network byte order 00094 // payload length is lower 12 bits 00095 // whitener offset is upper 4 bits 00096 *len = (d_header >> 16) & 0x0fff; 00097 *offset = (d_header >> 28) & 0x000f; 00098 } 00099 00100 public: 00101 ~digital_framer_sink_1(); 00102 00103 int work(int noutput_items, 00104 gr_vector_const_void_star &input_items, 00105 gr_vector_void_star &output_items); 00106 }; 00107 00108 #endif /* INCLUDED_GR_FRAMER_SINK_1_H */