| 1 | /**************************************************************************** |
|---|
| 2 | |
|---|
| 3 | Copyright 2007 Virginia Polytechnic Institute and State University |
|---|
| 4 | |
|---|
| 5 | This file is part of the OSSIE Conv_Enc. |
|---|
| 6 | |
|---|
| 7 | OSSIE Conv_Enc 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 Conv_Enc 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 Conv_Enc; 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 | #include <string> |
|---|
| 25 | #include <iostream> |
|---|
| 26 | #include "Conv_Enc.h" |
|---|
| 27 | |
|---|
| 28 | Conv_Enc_i::Conv_Enc_i(const char *uuid, omni_condition *condition) : |
|---|
| 29 | Resource_impl(uuid), component_running(condition) |
|---|
| 30 | { |
|---|
| 31 | dataOut_0 = new standardInterfaces_i::realChar_u("encoded_bits"); |
|---|
| 32 | dataIn_0 = new standardInterfaces_i::realChar_p("bits_to_enc_in"); |
|---|
| 33 | |
|---|
| 34 | inputGeneratorPolynomialsLength = 2; |
|---|
| 35 | inputGeneratorPolynomials = new unsigned int[inputGeneratorPolynomialsLength]; |
|---|
| 36 | inputGeneratorPolynomials[0]=0; |
|---|
| 37 | inputGeneratorPolynomials[1]=0; |
|---|
| 38 | encoder=new SigProc::fec_conv_encoder(); |
|---|
| 39 | configured=false; |
|---|
| 40 | //Create the thread for the writer's processing function |
|---|
| 41 | processing_thread = new omni_thread(Run, (void *) this); |
|---|
| 42 | |
|---|
| 43 | //Start the thread containing the writer's processing function |
|---|
| 44 | processing_thread->start(); |
|---|
| 45 | |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | Conv_Enc_i::~Conv_Enc_i(void) |
|---|
| 49 | { |
|---|
| 50 | delete dataOut_0; |
|---|
| 51 | delete dataIn_0; |
|---|
| 52 | delete []inputGeneratorPolynomials; |
|---|
| 53 | delete trellisTables; |
|---|
| 54 | delete encoder; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | // Static function for omni thread |
|---|
| 58 | void Conv_Enc_i::Run( void * data ) |
|---|
| 59 | { |
|---|
| 60 | ((Conv_Enc_i*)data)->ProcessData(); |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | CORBA::Object_ptr Conv_Enc_i::getPort( const char* portName ) throw ( |
|---|
| 64 | CORBA::SystemException, CF::PortSupplier::UnknownPort) |
|---|
| 65 | { |
|---|
| 66 | DEBUG(3, Conv_Enc, "getPort() invoked with " << portName) |
|---|
| 67 | |
|---|
| 68 | CORBA::Object_var p; |
|---|
| 69 | |
|---|
| 70 | p = dataOut_0->getPort(portName); |
|---|
| 71 | |
|---|
| 72 | if (!CORBA::is_nil(p)) |
|---|
| 73 | return p._retn(); |
|---|
| 74 | |
|---|
| 75 | p = dataIn_0->getPort(portName); |
|---|
| 76 | |
|---|
| 77 | if (!CORBA::is_nil(p)) |
|---|
| 78 | return p._retn(); |
|---|
| 79 | |
|---|
| 80 | /*exception*/ |
|---|
| 81 | throw CF::PortSupplier::UnknownPort(); |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | void Conv_Enc_i::start() throw (CORBA::SystemException, |
|---|
| 85 | CF::Resource::StartError) |
|---|
| 86 | { |
|---|
| 87 | DEBUG(3, Conv_Enc, "start() invoked") |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | void Conv_Enc_i::stop() throw (CORBA::SystemException, CF::Resource::StopError) |
|---|
| 91 | { |
|---|
| 92 | DEBUG(3, Conv_Enc, "stop() invoked") |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | void Conv_Enc_i::releaseObject() throw (CORBA::SystemException, |
|---|
| 96 | CF::LifeCycle::ReleaseError) |
|---|
| 97 | { |
|---|
| 98 | DEBUG(3, Conv_Enc, "releaseObject() invoked") |
|---|
| 99 | |
|---|
| 100 | component_running->signal(); |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | void Conv_Enc_i::initialize() throw (CF::LifeCycle::InitializeError, |
|---|
| 104 | CORBA::SystemException) |
|---|
| 105 | { |
|---|
| 106 | DEBUG(3, Conv_Enc, "initialize() invoked") |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | void Conv_Enc_i::configure(const CF::Properties& props) |
|---|
| 110 | throw (CORBA::SystemException, |
|---|
| 111 | CF::PropertySet::InvalidConfiguration, |
|---|
| 112 | CF::PropertySet::PartialConfiguration) |
|---|
| 113 | { |
|---|
| 114 | DEBUG(3, Conv_Enc, "configure() invoked") |
|---|
| 115 | |
|---|
| 116 | std::cout << "props length : " << props.length() << std::endl; |
|---|
| 117 | |
|---|
| 118 | for (unsigned int i = 0; i <props.length(); i++) |
|---|
| 119 | { |
|---|
| 120 | std::cout << "Property id : " << props[i].id << std::endl; |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | if (strcmp(props[i].id, "DCE:345df262-1611-11dc-a219-0016769e497b") == 0) |
|---|
| 124 | { |
|---|
| 125 | CORBA::Short simple_temp; |
|---|
| 126 | props[i].value >>= simple_temp; |
|---|
| 127 | rate_index = simple_temp; |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | if (strcmp(props[i].id, "DCE:7be7e584-1611-11dc-b945-0016769e497b") == 0) |
|---|
| 131 | { |
|---|
| 132 | CORBA::Short simple_temp; |
|---|
| 133 | props[i].value >>= simple_temp; |
|---|
| 134 | mode = simple_temp; |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | if (strcmp(props[i].id, "DCE:d2ee004a-18ee-11dc-8925-0016769e497b") == 0) |
|---|
| 138 | { |
|---|
| 139 | CORBA::Short simple_temp; |
|---|
| 140 | props[i].value >>= simple_temp; |
|---|
| 141 | k = simple_temp; |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | if (strcmp(props[i].id, "DCE:04aaa5ac-18ef-11dc-83ea-0016769e497b") == 0) |
|---|
| 145 | { |
|---|
| 146 | CORBA::Short simple_temp; |
|---|
| 147 | props[i].value >>= simple_temp; |
|---|
| 148 | K = simple_temp; |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | if (strcmp(props[i].id, "DCE:2d17e716-18ef-11dc-bf5c-0016769e497b") == 0) |
|---|
| 152 | { |
|---|
| 153 | CORBA::Short simple_temp; |
|---|
| 154 | props[i].value >>= simple_temp; |
|---|
| 155 | n = simple_temp; |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | if (strcmp(props[i].id, "DCE:4ef1b3b0-18f1-11dc-99b1-0016769e497b") == 0) |
|---|
| 159 | { |
|---|
| 160 | CORBA::ShortSeq *simplesequence; |
|---|
| 161 | props[i].value >>= simplesequence; |
|---|
| 162 | inputGeneratorPolynomialsLength = simplesequence->length(); |
|---|
| 163 | std::cout << "inputGeneratorPolynomials has length : " << |
|---|
| 164 | inputGeneratorPolynomialsLength << std::endl; |
|---|
| 165 | |
|---|
| 166 | delete []inputGeneratorPolynomials; |
|---|
| 167 | |
|---|
| 168 | DEBUG(4, Conv_Enc, "does delete fails?") |
|---|
| 169 | inputGeneratorPolynomials = new unsigned int [inputGeneratorPolynomialsLength]; |
|---|
| 170 | |
|---|
| 171 | DEBUG(4, Conv_Enc, "the new?") |
|---|
| 172 | |
|---|
| 173 | for (unsigned int j = 0; j < inputGeneratorPolynomialsLength; j++) |
|---|
| 174 | { |
|---|
| 175 | DEBUG(3, Conv_Enc, "get the input from the simplesequence") |
|---|
| 176 | inputGeneratorPolynomials[j] = (*simplesequence)[j]; |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | } |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | DEBUG(3, Conv_Enc, "Configure is done, generate the trellis etc") |
|---|
| 184 | |
|---|
| 185 | switch (rate_index){ |
|---|
| 186 | unsigned int genPoly[10]; |
|---|
| 187 | case 0: |
|---|
| 188 | trellisTables=new SigProc::trellisTable(inputGeneratorPolynomials, |
|---|
| 189 | (short unsigned int)k, |
|---|
| 190 | (short unsigned int)n, |
|---|
| 191 | (short unsigned int)K); |
|---|
| 192 | |
|---|
| 193 | DEBUG(3, Conv_Enc, "custom trellis table generated") |
|---|
| 194 | break; |
|---|
| 195 | case 1: |
|---|
| 196 | //Rate 1, no trellis needed; |
|---|
| 197 | DEBUG(3, Conv_Enc, "Pass through mode") |
|---|
| 198 | break; |
|---|
| 199 | case 2: |
|---|
| 200 | //4/5 |
|---|
| 201 | genPoly[0]=159; |
|---|
| 202 | genPoly[1]=188; |
|---|
| 203 | genPoly[2]=110; |
|---|
| 204 | genPoly[3]=173; |
|---|
| 205 | genPoly[4]=223; |
|---|
| 206 | trellisTables=new SigProc::trellisTable(genPoly, |
|---|
| 207 | (short unsigned int)4, |
|---|
| 208 | (short unsigned int)5, |
|---|
| 209 | (short unsigned int)2); |
|---|
| 210 | DEBUG(3, Conv_Enc, "4/5 trellis table generated") |
|---|
| 211 | break; |
|---|
| 212 | case 3: |
|---|
| 213 | //2/3 |
|---|
| 214 | genPoly[0]=158; |
|---|
| 215 | genPoly[1]=109; |
|---|
| 216 | genPoly[2]=223; |
|---|
| 217 | trellisTables=new SigProc::trellisTable(genPoly, |
|---|
| 218 | (short unsigned int)2, |
|---|
| 219 | (short unsigned int)3, |
|---|
| 220 | (short unsigned int)4); |
|---|
| 221 | DEBUG(3, Conv_Enc, "2/3 trellis table generated") |
|---|
| 222 | break; |
|---|
| 223 | case 4: |
|---|
| 224 | //1/2 |
|---|
| 225 | genPoly[0]=91; |
|---|
| 226 | genPoly[1]=121; |
|---|
| 227 | trellisTables=new SigProc::trellisTable(genPoly, |
|---|
| 228 | (short unsigned int)1, |
|---|
| 229 | (short unsigned int)2, |
|---|
| 230 | (short unsigned int)7); |
|---|
| 231 | DEBUG(3, Conv_Enc, "1/2 trellis table generated") |
|---|
| 232 | break; |
|---|
| 233 | case 5: |
|---|
| 234 | //1/3 |
|---|
| 235 | genPoly[0]=91; |
|---|
| 236 | genPoly[1]=101; |
|---|
| 237 | genPoly[2]=125; |
|---|
| 238 | trellisTables=new SigProc::trellisTable(genPoly, |
|---|
| 239 | (short unsigned int)1, |
|---|
| 240 | (short unsigned int)3, |
|---|
| 241 | (short unsigned int)7); |
|---|
| 242 | DEBUG(3, Conv_Enc, "1/3 trellis table generated") |
|---|
| 243 | break; |
|---|
| 244 | case 6: |
|---|
| 245 | //1/4 |
|---|
| 246 | genPoly[0]=93; |
|---|
| 247 | genPoly[1]=93; |
|---|
| 248 | genPoly[2]=103; |
|---|
| 249 | genPoly[3]=115; |
|---|
| 250 | trellisTables=new SigProc::trellisTable(genPoly, |
|---|
| 251 | (short unsigned int)1, |
|---|
| 252 | (short unsigned int)4, |
|---|
| 253 | (short unsigned int)7); |
|---|
| 254 | DEBUG(3, Conv_Enc, "1/4 trellis table generated") |
|---|
| 255 | break; |
|---|
| 256 | case 7: |
|---|
| 257 | //1/5 |
|---|
| 258 | genPoly[0]=125; |
|---|
| 259 | genPoly[1]=89; |
|---|
| 260 | genPoly[2]=93; |
|---|
| 261 | genPoly[3]=93; |
|---|
| 262 | genPoly[4]=103; |
|---|
| 263 | |
|---|
| 264 | trellisTables=new SigProc::trellisTable(genPoly, |
|---|
| 265 | (short unsigned int)1, |
|---|
| 266 | (short unsigned int)5, |
|---|
| 267 | (short unsigned int)7); |
|---|
| 268 | DEBUG(3, Conv_Enc, "1/5 trellis table generated") |
|---|
| 269 | break; |
|---|
| 270 | case 8: |
|---|
| 271 | //1/6 |
|---|
| 272 | genPoly[0]=123; |
|---|
| 273 | genPoly[1]=105; |
|---|
| 274 | genPoly[2]=93; |
|---|
| 275 | genPoly[3]=93; |
|---|
| 276 | genPoly[4]=115; |
|---|
| 277 | genPoly[5]=95; |
|---|
| 278 | |
|---|
| 279 | trellisTables=new SigProc::trellisTable(genPoly, |
|---|
| 280 | (short unsigned int)1, |
|---|
| 281 | (short unsigned int)6, |
|---|
| 282 | (short unsigned int)7); |
|---|
| 283 | DEBUG(3, Conv_Enc, "1/6 trellis table generated") |
|---|
| 284 | break; |
|---|
| 285 | case 9: |
|---|
| 286 | //1/7 |
|---|
| 287 | genPoly[0]=117; |
|---|
| 288 | genPoly[1]=101; |
|---|
| 289 | genPoly[2]=123; |
|---|
| 290 | genPoly[3]=93; |
|---|
| 291 | genPoly[4]=93; |
|---|
| 292 | genPoly[5]=103; |
|---|
| 293 | genPoly[6]=95; |
|---|
| 294 | |
|---|
| 295 | trellisTables=new SigProc::trellisTable(genPoly, |
|---|
| 296 | (short unsigned int)1, |
|---|
| 297 | (short unsigned int)7, |
|---|
| 298 | (short unsigned int)7); |
|---|
| 299 | DEBUG(3, Conv_Enc, "1/7 trellis table generated") |
|---|
| 300 | break; |
|---|
| 301 | case 10: |
|---|
| 302 | //1/8 |
|---|
| 303 | genPoly[0]=107; |
|---|
| 304 | genPoly[1]=73; |
|---|
| 305 | genPoly[2]=117; |
|---|
| 306 | genPoly[3]=123; |
|---|
| 307 | genPoly[4]=93; |
|---|
| 308 | genPoly[5]=93; |
|---|
| 309 | genPoly[6]=103; |
|---|
| 310 | genPoly[7]=95; |
|---|
| 311 | trellisTables=new SigProc::trellisTable(genPoly, |
|---|
| 312 | (short unsigned int)1, |
|---|
| 313 | (short unsigned int)8, |
|---|
| 314 | (short unsigned int)7); |
|---|
| 315 | DEBUG(3, Conv_Enc, "1/8 trellis table generated") |
|---|
| 316 | break; |
|---|
| 317 | default: |
|---|
| 318 | //Unknown rate |
|---|
| 319 | throw 0; |
|---|
| 320 | }; |
|---|
| 321 | if (rate_index!=1) { |
|---|
| 322 | encoder->SetTrellisTable(trellisTables); |
|---|
| 323 | |
|---|
| 324 | DEBUG(4, Conv_Enc, "the trellis was sent to the encoder") |
|---|
| 325 | } |
|---|
| 326 | configured=true; |
|---|
| 327 | |
|---|
| 328 | } |
|---|
| 329 | |
|---|
| 330 | void Conv_Enc_i::ProcessData() |
|---|
| 331 | { |
|---|
| 332 | DEBUG(3, Conv_Enc, "ProcessData() invoked") |
|---|
| 333 | |
|---|
| 334 | PortTypes::CharSequence I_out_0; |
|---|
| 335 | |
|---|
| 336 | |
|---|
| 337 | PortTypes::CharSequence *I_in_0(NULL); |
|---|
| 338 | CORBA::UShort I_in_0_length; |
|---|
| 339 | unsigned short int data2Enc[20],encData[20],noOfSymbols; |
|---|
| 340 | signed short int tmp; |
|---|
| 341 | unsigned short int numberOfBits; |
|---|
| 342 | SigProc::trellisTable *theTrellisTable; |
|---|
| 343 | |
|---|
| 344 | |
|---|
| 345 | |
|---|
| 346 | while(1) |
|---|
| 347 | { |
|---|
| 348 | |
|---|
| 349 | dataIn_0->getData(I_in_0); |
|---|
| 350 | |
|---|
| 351 | |
|---|
| 352 | if (!configured) throw 0; |
|---|
| 353 | |
|---|
| 354 | I_in_0_length = I_in_0->length(); |
|---|
| 355 | |
|---|
| 356 | numberOfBits=I_in_0_length; |
|---|
| 357 | |
|---|
| 358 | if (rate_index==1){ |
|---|
| 359 | I_out_0.length(I_in_0_length); |
|---|
| 360 | for (unsigned int i=0;i<I_in_0_length;i++) { |
|---|
| 361 | I_out_0[i]=(*I_in_0)[i]; |
|---|
| 362 | }; |
|---|
| 363 | DEBUG(4, Conv_Enc, "Pass through mode, no encoding will done") |
|---|
| 364 | }else { |
|---|
| 365 | |
|---|
| 366 | DEBUG(4, Conv_Enc, numberOfBits<<" bits received") |
|---|
| 367 | theTrellisTable=trellisTables; |
|---|
| 368 | noOfSymbols=numberOfBits/theTrellisTable->k; |
|---|
| 369 | I_out_0.length(noOfSymbols*theTrellisTable->n); |
|---|
| 370 | DEBUG(6, Conv_Enc, " Output length set to:"<<noOfSymbols*theTrellisTable->n) |
|---|
| 371 | encoder->ResetState(); |
|---|
| 372 | DEBUG(6, Conv_Enc, " Encoder state was reset") |
|---|
| 373 | /*insert code here to do work*/ |
|---|
| 374 | for (unsigned int i=0;i<noOfSymbols;i++){ |
|---|
| 375 | for (unsigned int j=0;j<theTrellisTable->k;j++){ |
|---|
| 376 | data2Enc[j]=(*I_in_0)[i*theTrellisTable->k +j]; |
|---|
| 377 | } |
|---|
| 378 | DEBUG(11, Conv_Enc, i+1<<" symbol to be encoded") |
|---|
| 379 | |
|---|
| 380 | encoder->Encode(data2Enc,encData); |
|---|
| 381 | |
|---|
| 382 | for (int j=0;j<theTrellisTable->n;j++){ |
|---|
| 383 | tmp=(short int )encData[j]; |
|---|
| 384 | I_out_0[i*theTrellisTable->n+j]=tmp; |
|---|
| 385 | } |
|---|
| 386 | DEBUG(11, Conv_Enc, i+1<<" symbol encoded") |
|---|
| 387 | } |
|---|
| 388 | |
|---|
| 389 | } |
|---|
| 390 | |
|---|
| 391 | DEBUG(6, Conv_Enc, "Trying to push packet") |
|---|
| 392 | dataOut_0->pushPacket(I_out_0); |
|---|
| 393 | |
|---|
| 394 | DEBUG(6, Conv_Enc, "Now trying to empty the buffer") |
|---|
| 395 | dataIn_0->bufferEmptied(); |
|---|
| 396 | |
|---|
| 397 | DEBUG(6, Conv_Enc, "buffer emptied") |
|---|
| 398 | |
|---|
| 399 | if (rate_index!=1){ |
|---|
| 400 | DEBUG(4, Conv_Enc, noOfSymbols*theTrellisTable->n<<" Bits sent to the next component") |
|---|
| 401 | |
|---|
| 402 | } else { |
|---|
| 403 | DEBUG(4, Conv_Enc, numberOfBits<<" Bits sent to the next component") |
|---|
| 404 | } |
|---|
| 405 | } |
|---|
| 406 | } |
|---|
| 407 | |
|---|
| 408 | |
|---|