root/experimental/components/Conv_Enc/Conv_Enc.cpp @ 4179

Revision 4179, 12.3 KB (checked in by hvolos, 6 years ago)

Components updated, waveform execution is hit or miss, not sure were is the problem

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