| 1 | /**************************************************************************** |
|---|
| 2 | |
|---|
| 3 | Copyright 2007 Virginia Polytechnic Institute and State University |
|---|
| 4 | |
|---|
| 5 | This file is part of the OSSIE Packetizer. |
|---|
| 6 | |
|---|
| 7 | OSSIE Packetizer 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 2 of the License, or |
|---|
| 10 | (at your option) any later version. |
|---|
| 11 | |
|---|
| 12 | OSSIE Packetizer 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 OSSIE Packetizer; if not, write to the Free Software |
|---|
| 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | |
|---|
| 21 | ****************************************************************************/ |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | #ifndef PACKETIZERDSP_IMPL_H |
|---|
| 25 | #define PACKETIZERDSP_IMPL_H |
|---|
| 26 | |
|---|
| 27 | #include <stdlib.h> |
|---|
| 28 | #include "PNCodes.h" |
|---|
| 29 | #include "sigproc/SigProc.h" |
|---|
| 30 | |
|---|
| 31 | #define PN_SYNC_CODE_LENGTH 63 |
|---|
| 32 | #define PN_CONTROL_CODE_LENGTH 7 |
|---|
| 33 | #define NUM_CONTROL_CODES 4 |
|---|
| 34 | #define MAX_PACKET_SIZE 4096 |
|---|
| 35 | |
|---|
| 36 | extern "C" { |
|---|
| 37 | #include "binary_sequence.h" |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | /// Forward error correction scheme |
|---|
| 41 | enum FECScheme { |
|---|
| 42 | REPEAT_1, ///< Repeat code, rate 1/3 |
|---|
| 43 | RS_1, ///< Reed solomon, rate... |
|---|
| 44 | CONV_1 ///< Convolutional, rate..., K=... |
|---|
| 45 | }; |
|---|
| 46 | |
|---|
| 47 | /// Interleaving scheme |
|---|
| 48 | enum InterleavingScheme { |
|---|
| 49 | INT_1, ///< Interleaving depth... |
|---|
| 50 | INT_2 ///< Interleaving depth... |
|---|
| 51 | }; |
|---|
| 52 | |
|---|
| 53 | /// Cyclic redundancy check scheme |
|---|
| 54 | enum CRCScheme { |
|---|
| 55 | CRC_1, |
|---|
| 56 | CRC_2 |
|---|
| 57 | }; |
|---|
| 58 | |
|---|
| 59 | /// Packet type |
|---|
| 60 | enum PacketType { |
|---|
| 61 | ///\brief raw data packet with 400 bits input |
|---|
| 62 | // pn_sync 63 |
|---|
| 63 | // control 4x7 |
|---|
| 64 | // p_id 7x3 |
|---|
| 65 | // data 400 |
|---|
| 66 | // ------------- |
|---|
| 67 | // total: 512 |
|---|
| 68 | PACKET_RAW_400=0, |
|---|
| 69 | |
|---|
| 70 | ///\brief Simplified packet with low overhead |
|---|
| 71 | PACKET_LOW_OVERHEAD, |
|---|
| 72 | |
|---|
| 73 | ///\brief Fully-descriptive packet |
|---|
| 74 | PACKET_RELIABLE_DATA |
|---|
| 75 | }; |
|---|
| 76 | |
|---|
| 77 | /** \brief Basic packet functionality |
|---|
| 78 | |
|---|
| 79 | */ |
|---|
| 80 | class PacketizerDSP |
|---|
| 81 | { |
|---|
| 82 | public: |
|---|
| 83 | /// Initializing constructor |
|---|
| 84 | PacketizerDSP(); |
|---|
| 85 | |
|---|
| 86 | ///\todo implement this method; for now assume packet can be configured by |
|---|
| 87 | /// setting properties directly because SCA component wrapper inherits |
|---|
| 88 | /// from the PacketizerDSP class |
|---|
| 89 | void ConfigurePacket( |
|---|
| 90 | PacketType _type, |
|---|
| 91 | FECScheme _fec_inner, |
|---|
| 92 | FECScheme _fec_outer, |
|---|
| 93 | InterleavingScheme _int, |
|---|
| 94 | CRCScheme _crc); |
|---|
| 95 | |
|---|
| 96 | /// Returns the necessary buffer size for processing given the current |
|---|
| 97 | /// packet configuration |
|---|
| 98 | unsigned int RequiredBufferSize(unsigned int input_length); |
|---|
| 99 | |
|---|
| 100 | /// |
|---|
| 101 | void AssemblePacket( |
|---|
| 102 | char* input, |
|---|
| 103 | unsigned int input_length, |
|---|
| 104 | char* output, |
|---|
| 105 | unsigned int &output_length, |
|---|
| 106 | PacketType type); |
|---|
| 107 | |
|---|
| 108 | /// Extracts the P/N sync code from the header |
|---|
| 109 | bool ExtractPacketHeader( |
|---|
| 110 | char * input, |
|---|
| 111 | unsigned int input_length, |
|---|
| 112 | unsigned int &num_bits_read); |
|---|
| 113 | |
|---|
| 114 | /// Extracts the basic packet type from the header |
|---|
| 115 | bool ExtractPacketType( |
|---|
| 116 | char * input, |
|---|
| 117 | unsigned int input_length, |
|---|
| 118 | unsigned int &num_bits_read); |
|---|
| 119 | |
|---|
| 120 | /// Extracts properties from the subheader |
|---|
| 121 | bool ExtractPacketSubheader( |
|---|
| 122 | char * input, |
|---|
| 123 | unsigned int input_length, |
|---|
| 124 | unsigned int &num_bits_read); |
|---|
| 125 | |
|---|
| 126 | /// Extracts the remainder of the packet, decoding as necessary |
|---|
| 127 | bool ExtractPacketData( |
|---|
| 128 | char * input, |
|---|
| 129 | unsigned int input_length, |
|---|
| 130 | char * output, |
|---|
| 131 | unsigned int &output_length); |
|---|
| 132 | |
|---|
| 133 | void DecodePacket(); |
|---|
| 134 | |
|---|
| 135 | /// Destructor |
|---|
| 136 | ~PacketizerDSP(); |
|---|
| 137 | |
|---|
| 138 | protected: |
|---|
| 139 | PacketType packet_type; ///< packet type identifier |
|---|
| 140 | |
|---|
| 141 | bool dynamic_packet_size; |
|---|
| 142 | unsigned int packet_subheader_length; |
|---|
| 143 | unsigned int packet_data_length; |
|---|
| 144 | |
|---|
| 145 | // Physical layer definitions |
|---|
| 146 | char * pnSyncCode; ///< packet synchronization code |
|---|
| 147 | binary_sequence_t * pn_sync_code; ///< packet synchronization code shift register |
|---|
| 148 | |
|---|
| 149 | char * pnControlCode; ///< packet control code |
|---|
| 150 | binary_sequence_t * pn_control_code;///< packet control code shift register |
|---|
| 151 | |
|---|
| 152 | char * pnEOMCode; ///< packet EOM code |
|---|
| 153 | binary_sequence_t * pn_eom_code; ///< packet EOM code shift register |
|---|
| 154 | |
|---|
| 155 | // Media Access Control layer definitions |
|---|
| 156 | FECScheme fec_inner; |
|---|
| 157 | FECScheme fec_outer; |
|---|
| 158 | InterleavingScheme interleaving; |
|---|
| 159 | CRCScheme crc; |
|---|
| 160 | |
|---|
| 161 | // Network layer definitions |
|---|
| 162 | unsigned long src_id; ///< source identifier |
|---|
| 163 | unsigned long dst_id; ///< destination identifier |
|---|
| 164 | |
|---|
| 165 | // Transport layer definitions |
|---|
| 166 | unsigned long packet_id; ///< packet identifier |
|---|
| 167 | unsigned long port_id; ///< port identifier |
|---|
| 168 | |
|---|
| 169 | // Application layer definitions |
|---|
| 170 | // ... |
|---|
| 171 | |
|---|
| 172 | /// Array of control code pointers |
|---|
| 173 | char ** controlBlock; |
|---|
| 174 | |
|---|
| 175 | /// Configures control codes and other data based on packet type |
|---|
| 176 | void ConfigurePacketType( PacketType type ); |
|---|
| 177 | |
|---|
| 178 | // ------ Packetizer definitions ------ |
|---|
| 179 | |
|---|
| 180 | /// Sets pointers in controlBlock to appropriate control codes |
|---|
| 181 | void ConfigureControl( unsigned char id ); |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | // ------ Depacketizer definitions ------ |
|---|
| 185 | |
|---|
| 186 | /// |
|---|
| 187 | bool ExtractPacketDataDynamicLength( |
|---|
| 188 | char * input, |
|---|
| 189 | unsigned int input_length, |
|---|
| 190 | char * output, |
|---|
| 191 | unsigned int &output_length); |
|---|
| 192 | |
|---|
| 193 | /// |
|---|
| 194 | bool ExtractPacketDataFixedLength( |
|---|
| 195 | char * input, |
|---|
| 196 | unsigned int input_length, |
|---|
| 197 | char * output, |
|---|
| 198 | unsigned int &output_length); |
|---|
| 199 | |
|---|
| 200 | binary_sequence_t * pn_sync_buffer; ///< |
|---|
| 201 | binary_sequence_t * pn_control_buffer; ///< |
|---|
| 202 | binary_sequence_t * pn_eom_buffer; ///< |
|---|
| 203 | int rxy; ///< cross-correlator output |
|---|
| 204 | |
|---|
| 205 | unsigned int input_index; |
|---|
| 206 | unsigned int output_index; |
|---|
| 207 | |
|---|
| 208 | // |
|---|
| 209 | unsigned int num_control_codes_extracted; |
|---|
| 210 | unsigned int num_control_bits_read; |
|---|
| 211 | unsigned int new_packet_type; |
|---|
| 212 | |
|---|
| 213 | // |
|---|
| 214 | unsigned int num_subheader_bits_read; |
|---|
| 215 | |
|---|
| 216 | // |
|---|
| 217 | unsigned int num_packet_bits_read; |
|---|
| 218 | |
|---|
| 219 | bool invert_bits; |
|---|
| 220 | |
|---|
| 221 | private: |
|---|
| 222 | /// Disallow copy constructor |
|---|
| 223 | PacketizerDSP(PacketizerDSP&); |
|---|
| 224 | |
|---|
| 225 | }; |
|---|
| 226 | |
|---|
| 227 | #endif |
|---|
| 228 | |
|---|