root/ossiedev/branches/jeongo9/components/liquid-components/src/FlexframeGen.cpp @ 10634

Revision 10634, 12.5 KB (checked in by jeongo9, 2 years ago)

Updated components so that they will work with latest liquid-dsp(3a4fb0c3a627bc16b3745d3229bbac5f70a3f422)

Line 
1/****************************************************************************
2
3Copyright 2010 Virginia Polytechnic Institute and State University
4
5This file is part of the OSSIE FlexframeGen.
6
7OSSIE FlexframeGen 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 FlexframeGen 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 FlexframeGen; 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 <stdio.h>
27
28#include "config.h"
29#include "FlexframeGen.h"
30
31// include main.cpp (must define COMPONENT_OBJECT)
32#define  COMPONENT_OBJECT FlexframeGen_i
33#include "main.cpp"
34
35FlexframeGen_i::FlexframeGen_i(const char *uuid, omni_condition *condition) :
36    Resource_impl(uuid), component_running(condition)
37{
38    headerDataPortIn = new standardInterfaces_i::realChar_p("HeaderDataIn");
39    payloadDataPortIn = new standardInterfaces_i::realChar_p("PayloadDataIn");
40    frameDataPortOut = new standardInterfaces_i::complexFloat_u("FrameSamplesOut");
41
42    // create dsp objects
43    fgprops.rampup_len  = 16;
44    fgprops.phasing_len = 64;
45    fgprops.payload_len = 256;
46    fgprops.mod_scheme  = MOD_QAM;
47    fgprops.mod_bps     = 4;
48    fgprops.rampdn_len  = 16;
49    fgprops.check       = CRC_NONE;
50    fgprops.fec0        = FEC_NONE;
51    fgprops.fec1        = FEC_NONE;
52
53    fg = flexframegen_create(&fgprops);
54    std::cout << "flexframegen_create done" <<std::endl<<std::flush;
55    payload_len = 64;
56    payload = (unsigned char*) malloc(payload_len);
57
58    frame_len = 1024;
59    frame = (std::complex<float>*) malloc(frame_len);
60
61    // design rrc filter
62    unsigned int k=2;
63    unsigned int m=3;
64    float beta=0.7f;
65    float dt = 0;
66
67//    interp = interp_crcf_create_rrc(k,m,beta,dt);
68    interp = interp_crcf_create_rnyquist(LIQUID_RNYQUIST_RRC,k,m,beta,dt);
69    interp2 = resamp2_crcf_create(37,0,60);
70
71    std::cout << "interp and resamp create done" <<std::endl<<std::flush;
72}
73
74FlexframeGen_i::~FlexframeGen_i(void)
75{
76    delete headerDataPortIn;
77    delete payloadDataPortIn;
78    delete frameDataPortOut;
79
80    flexframegen_destroy(fg);
81    interp_crcf_destroy(interp);
82    resamp2_crcf_destroy(interp2);
83
84    free(payload);
85    free(frame);
86}
87
88// Static function for omni thread
89void FlexframeGen_i::Run( void * data )
90{
91    ((FlexframeGen_i*)data)->ProcessData();
92}
93
94CORBA::Object_ptr FlexframeGen_i::getPort( const char* portName ) throw (
95    CORBA::SystemException, CF::PortSupplier::UnknownPort)
96{
97    DEBUG(3, FlexframeGen, "getPort() invoked with " << portName)
98
99    CORBA::Object_var p;
100
101    p = headerDataPortIn->getPort(portName);
102
103    if (!CORBA::is_nil(p))
104        return p._retn();
105
106    p = payloadDataPortIn->getPort(portName);
107
108    if (!CORBA::is_nil(p))
109        return p._retn();
110
111    p = frameDataPortOut->getPort(portName);
112
113    if (!CORBA::is_nil(p))
114        return p._retn();
115
116    /*exception*/
117    throw CF::PortSupplier::UnknownPort();
118}
119
120void FlexframeGen_i::start() throw (CORBA::SystemException,
121    CF::Resource::StartError)
122{
123    DEBUG(3, FlexframeGen, "start() invoked")
124        omni_mutex_lock  l(processing_mutex);
125        if( false == thread_started )
126        {
127                thread_started = true;
128                // Create the thread for the writer's processing function
129                processing_thread = new omni_thread(Run, (void *) this);
130
131                // Start the thread containing the writer's processing function
132                processing_thread->start();
133        }
134}
135
136void FlexframeGen_i::stop() throw (CORBA::SystemException, CF::Resource::StopError)
137{
138    DEBUG(3, FlexframeGen, "stop() invoked")
139        omni_mutex_lock l(processing_mutex);
140        thread_started = false;
141}
142
143void FlexframeGen_i::releaseObject() throw (CORBA::SystemException,
144    CF::LifeCycle::ReleaseError)
145{
146    DEBUG(3, FlexframeGen, "releaseObject() invoked")
147
148    component_running->signal();
149}
150
151void FlexframeGen_i::initialize() throw (CF::LifeCycle::InitializeError,
152    CORBA::SystemException)
153{
154    DEBUG(3, FlexframeGen, "initialize() invoked")
155}
156
157void FlexframeGen_i::query( CF::Properties & configProperties ) throw (CORBA::SystemException, CF::UnknownProperties)
158{
159        if( configProperties.length() == 0 )
160        {
161                configProperties.length( propertySet.length() );
162                for(unsigned int i = 0; i < propertySet.length(); i++ )
163                {
164                        configProperties[i].id = CORBA::string_dup( propertySet[i].id );
165                        configProperties[i].value = propertySet[i].value;
166                }
167                return;
168        } else {
169                for( unsigned int i = 0; i < configProperties.length(); i++ ) {
170                        for( unsigned int j = 0; j < propertySet.length(); j++ ) {
171                                if( strcmp(configProperties[i].id, propertySet[j].id) == 0 ) {
172                                        configProperties[i].value = propertySet[j].value;
173                                }
174                        }
175                }
176        } // end if-else
177}
178
179void FlexframeGen_i::configure(const CF::Properties& props)
180throw (CORBA::SystemException,
181    CF::PropertySet::InvalidConfiguration,
182    CF::PropertySet::PartialConfiguration)
183{
184    DEBUG(3, FlexframeGen, "configure() invoked")
185
186    // not sure what the heck this is here for...
187    static int init = 0;
188    if( init == 0 ) {
189        if( props.length() == 0 ) {
190            std::cout << "configure called with invalid props.length - " << props.length() << std::endl;
191            return;
192        }
193        propertySet.length(props.length());
194        for( int j=0; j < props.length(); j++ ) {
195            propertySet[j].id = CORBA::string_dup(props[j].id);
196            propertySet[j].value = props[j].value;
197        }
198        init = 1;
199    }
200
201    std::cout << "props length : " << props.length() << std::endl;
202
203    unsigned int ms = fgprops.mod_scheme;
204    unsigned int bps = fgprops.mod_bps;
205
206    for ( unsigned int i = 0; i <props.length(); i++) {
207        std::cout << "Property id : " << props[i].id << std::endl;
208
209        if (strcmp(props[i].id, "DCE:5b852bf4-6d83-11df-80dc-001aa089d644") == 0) {
210            // verbose
211            CORBA::Boolean simple_temp;
212            props[i].value >>= simple_temp;
213        } else if (strcmp(props[i].id, "DCE:c1612e14-6d83-11df-8500-001aa089d644") == 0) {
214            // mod_scheme
215
216            const char * prop_str;
217            unsigned int M;
218            props[i].value >>= prop_str;
219            if (strcmp(prop_str,"bpsk")==0) {
220                ms = MOD_BPSK;
221                M = 2;
222            } else if (strcmp(prop_str,"qpsk")==0) {
223                ms = MOD_QPSK;
224                M = 4;
225            } else if (strcmp(prop_str,"arb16opt")==0) {
226                ms = MOD_ARB16OPT;
227                M = 16;
228            } else if (strcmp(prop_str,"arb64vt")==0) {
229                ms = MOD_ARB64VT;
230                M = 64;
231            } else if (strncmp(prop_str,"psk",3)==0) {
232                ms = MOD_PSK;
233                M = atoi(prop_str+3);
234            } else if (strncmp(prop_str,"dpsk",4)==0) {
235                ms = MOD_DPSK;
236                M = atoi(prop_str+4);
237            } else if (strncmp(prop_str,"qam",3)==0) {
238                ms = MOD_QAM;
239                M = atoi(prop_str+3);
240            } else if (strncmp(prop_str,"apsk",4)==0) {
241                ms = MOD_APSK;
242                M = atoi(prop_str+4);
243            } else if (strncmp(prop_str,"ask",3)==0) {
244                ms = MOD_ASK;
245                M = atoi(prop_str+3);
246            } else {
247                std::cerr << "error: invalid mod scheme: " << prop_str << std::endl;
248                throw (0);
249            }
250
251            // compute bits/symbol
252            switch (M) {
253            case 2:     bps = 1;    break;
254            case 4:     bps = 2;    break;
255            case 8:     bps = 3;    break;
256            case 16:    bps = 4;    break;
257            case 32:    bps = 5;    break;
258            case 64:    bps = 6;    break;
259            case 128:   bps = 7;    break;
260            case 256:   bps = 8;    break;
261            default:
262                std::cerr << "error: FlexFrameGen_i::configure(), invalid constellation size : " << M << std::endl;
263                std::cerr << "       Set mod_scheme to one of: bpsk, qpsk, psk<2..256>, dpsk<2..256>, qam<4..256>, apsk<4..128>, ask<2..256>, arb16opt, arb64vt" << std::endl;
264                throw (0);
265            }
266
267        } else if (strcmp(props[i].id, "DCE:d1ff6dee-6d83-11df-a93b-001aa089d644") == 0) {
268            // mod_depth
269            //CORBA::Short simple_temp;
270            //props[i].value >>= simple_temp;
271
272            std::cerr << "warning: mod_depth property ignored" << std::endl;
273        } else if (strcmp(props[i].id, "DCE:1ca10d80-6d84-11df-b66a-001aa089d644") == 0) {
274            // phasing_length
275            CORBA::Short simple_temp;
276            props[i].value >>= simple_temp;
277            std::cerr << "warning: phasing_length property ignored" << std::endl;
278        } else if (strcmp(props[i].id, "DCE:29b6bcc2-6d84-11df-bfd7-001aa089d644") == 0) {
279            // ramp_length
280            CORBA::Short simple_temp;
281            props[i].value >>= simple_temp;
282            std::cerr << "warning: ramp_length property ignored" << std::endl;
283        } else {
284            std::cerr << "error: unknown property" << std::endl;
285            throw (0);
286        }
287
288    }
289
290    // re-configure frame generator
291    fgprops.mod_scheme = ms;
292    fgprops.mod_bps    = bps;
293    flexframegen_setprops(fg,&fgprops);
294    std::cout << "flexframegen: setting props done" << std::endl << std::flush;
295}
296
297void FlexframeGen_i::ProcessData()
298{
299    DEBUG(3, FlexframeGen, "ProcessData() invoked")
300
301    PortTypes::FloatSequence I_out, Q_out;
302
303
304    // header data
305    PortTypes::CharSequence *headerData(NULL);
306    CORBA::UShort headerData_length;
307
308    // payload data
309    PortTypes::CharSequence *payloadData(NULL);
310    CORBA::UShort payloadData_length;
311
312    unsigned int i;
313
314    verbose = 1;
315    while(continue_processing()) {
316        std::cout << "flexframegen: inside loop" << std::endl << std::flush;
317        // get data from header port
318        headerDataPortIn->getData(headerData);
319        headerData_length = headerData->length();
320
321        payloadDataPortIn->getData(payloadData);
322        payloadData_length = payloadData->length();
323
324        // validate lengths
325        if (headerData_length != 8) {
326            std::cerr << "error: FlexframeGen header length must be 8 bytes" << std::endl;
327            throw(0);
328        }
329
330        // reallocate payload
331        payload_len = payloadData_length;
332        payload = (unsigned char*) realloc(payload, payload_len*sizeof(unsigned char));
333
334        // copy header, payload
335        for (i=0; i<8; i++)
336            header[i] = (*headerData)[i];
337        for (i=0; i<payload_len; i++)
338            payload[i] = (*payloadData)[i];
339
340        // configure fgprops on input data size
341        fgprops.payload_len = payload_len;
342        flexframegen_setprops(fg,&fgprops);
343
344        // compute frame length, reallocate memory
345        frame_len = flexframegen_getframelen(fg);
346        frame = (std::complex<float>*) realloc(frame, frame_len*sizeof(std::complex<float>));
347
348        I_out.length(4*frame_len); //must define length of output
349        Q_out.length(4*frame_len); //must define length of output
350
351        // generate the frame
352        flexframegen_execute(fg,header,payload,frame);
353
354        // run interpolator, store in output
355        std::complex<float> y[2];
356        std::complex<float> z[4];
357        for (i=0; i<frame_len; i++) {
358            // execute interpolator one sample at a time, storing in
359            // two-sample array y
360            interp_crcf_execute(interp, frame[i], &y[0]);
361
362#if 0
363            // write first interpolated sample
364            I_out[*i+0] = y[0].real();
365            Q_out[2*i+0] = y[0].imag();
366
367            // write second interpolated sample
368            I_out[2*i+1] = y[1].real();
369            Q_out[2*i+1] = y[1].imag();
370#else
371            resamp2_crcf_interp_execute(interp2, y[0], &z[0]);
372            resamp2_crcf_interp_execute(interp2, y[1], &z[2]);
373
374            unsigned int j;
375            for (j=0; j<4; j++) {
376                I_out[4*i+j] = z[j].real();
377                Q_out[4*i+j] = z[j].imag();
378            }
379#endif
380
381        }
382
383        // push output frame
384        frameDataPortOut->pushPacket(I_out, Q_out);
385        std::cout << "FlexframeGen" << std::endl;
386        // free input buffers
387        headerDataPortIn->bufferEmptied();
388        payloadDataPortIn->bufferEmptied();
389    }
390}
391
392bool FlexframeGen_i::continue_processing()
393{
394        omni_mutex_lock l(processing_mutex);
395        return thread_started;
396}
397
398
Note: See TracBrowser for help on using the browser.