root/experimental/components/FrameAssembler/branches/FrameAssembler-metadata/src/FrameAssembler.cpp @ 5558

Revision 5558, 11.5 KB (checked in by jgaeddert, 6 years ago)

adding raised-cosine ramp up/down phasing pattern to reduce out-of-band interference due to key clicking

  • Property svn:eol-style set to native
Line 
1/****************************************************************************
2
3Copyright 2007 Virginia Polytechnic Institute and State University
4
5This file is part of the OSSIE FrameAssembler.
6
7OSSIE FrameAssembler 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 FrameAssembler 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 FrameAssembler; 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 "FrameAssembler.h"
27
28FrameAssembler_i::FrameAssembler_i(const char *uuid, omni_condition *condition) :
29    Resource_impl(uuid), component_running(condition)
30{
31    dataIn_0 = new standardInterfaces_i::complexShort_p("SymbolsIn");
32    dataOut_0 = new standardInterfaces_i::complexShort_u("FrameSymbolsOut");
33
34    //Create the thread for the writer's processing function
35    processing_thread = new omni_thread(Run, (void *) this);
36
37    //Start the thread containing the writer's processing function
38    processing_thread->start();
39
40}
41
42FrameAssembler_i::~FrameAssembler_i(void)
43{   
44    delete dataIn_0;
45    delete dataOut_0;
46}
47
48// Static function for omni thread
49void FrameAssembler_i::Run( void * data )
50{
51    ((FrameAssembler_i*)data)->ProcessData();
52}
53
54CORBA::Object_ptr FrameAssembler_i::getPort( const char* portName ) throw (
55    CORBA::SystemException, CF::PortSupplier::UnknownPort)
56{
57    DEBUG(3, FrameAssembler, "getPort() invoked with " << portName)
58   
59    CORBA::Object_var p;
60
61    p = dataIn_0->getPort(portName);
62
63    if (!CORBA::is_nil(p))
64        return p._retn();
65
66    p = dataOut_0->getPort(portName);
67
68    if (!CORBA::is_nil(p))
69        return p._retn();
70
71    // Requested port not recognized
72    throw CF::PortSupplier::UnknownPort();
73}
74
75void FrameAssembler_i::start() throw (CORBA::SystemException,
76    CF::Resource::StartError)
77{
78    DEBUG(3, FrameAssembler, "start() invoked")
79}
80
81void FrameAssembler_i::stop() throw (CORBA::SystemException, CF::Resource::StopError)
82
83    DEBUG(3, FrameAssembler, "stop() invoked")
84}
85
86void FrameAssembler_i::releaseObject() throw (CORBA::SystemException,
87    CF::LifeCycle::ReleaseError)
88{
89    DEBUG(3, FrameAssembler, "releaseObject() invoked")
90   
91    component_running->signal();
92}
93
94void FrameAssembler_i::initialize() throw (CF::LifeCycle::InitializeError,
95    CORBA::SystemException)
96{
97    DEBUG(3, FrameAssembler, "initialize() invoked")
98}
99
100void FrameAssembler_i::configure(const CF::Properties& props)
101throw (CORBA::SystemException,
102    CF::PropertySet::InvalidConfiguration,
103    CF::PropertySet::PartialConfiguration)
104{
105    DEBUG(3, FrameAssembler, "configure() invoked")
106   
107    std::cout << "props length : " << props.length() << std::endl;
108
109    for (unsigned int i = 0; i <props.length(); i++) {
110        std::cout << "Property id : " << props[i].id << std::endl;
111
112        if (strcmp(props[i].id, "DCE:690f320c-5bee-4959-b93d-586dc3450aac") == 0) {
113            // Modulation type
114            const char * prop_str;
115            props[i].value >>= prop_str;
116
117            // Set appropriate modulation function
118            if ( strcmp(prop_str, "BPSK") == 0 ) {
119                ConfigureModulationScheme(SigProc::BPSK);
120            } else if ( strcmp(prop_str, "QPSK") == 0 ) {
121                ConfigureModulationScheme(SigProc::QPSK);
122            } else if ( strcmp(prop_str, "8PSK") == 0 ) {
123                ConfigureModulationScheme(SigProc::PSK8);
124            } else if ( strcmp(prop_str, "16QAM") == 0 ) {
125                ConfigureModulationScheme(SigProc::QAM16);
126            } else if ( strcmp(prop_str, "4PAM") == 0 ) {
127                ConfigureModulationScheme(SigProc::PAM4);
128            } else {
129                // unknown property
130                std::cerr << "ERROR: FrameAssembler::configure() unknown mod. scheme "
131                          << prop_str << std::endl;
132                throw CF::PropertySet::InvalidConfiguration();
133            }
134            ///\todo catch exception thrown by FrameAssemblerDSP::ConfigureModulationScheme()
135
136        } else if (strcmp(props[i].id, "DCE:25a1df92-7f22-43af-8720-ad37714a66db") == 0) {
137            // Frame size
138            CORBA::UShort simple_temp;
139            props[i].value >>= simple_temp;
140
141            ConfigureFrameSize(simple_temp);
142
143        } else {
144            // unknown property
145            std::cerr << "ERROR: FrameAssembler::configure() unknown property" << std::endl;
146            throw CF::PropertySet::InvalidConfiguration();
147        }
148    }
149
150}
151
152void FrameAssembler_i::ConfigureModulationSchemeOnMetaData() {
153    switch (metadata->modulation_scheme.scheme) {
154    case standardInterfaces::ModulationScheme::PSK:
155        switch (metadata->modulation_scheme.M) {
156        case 2:
157            ConfigureModulationScheme(SigProc::BPSK);
158            DEBUG(5, FrameAssembler, "Frame mod set to BPSK");
159            break;
160        case 4:
161            ConfigureModulationScheme(SigProc::QPSK);
162            DEBUG(5, FrameAssembler, "Frame mod set to QPSK");
163            break;
164        case 8:
165            ConfigureModulationScheme(SigProc::PSK8);
166            DEBUG(5, FrameAssembler, "Frame mod set to 8PSK");
167            break;
168        default:
169            std::cerr << "FrameAssembler-metadata: Unsupported PSK modulation depth" << std::endl;
170            throw 0;
171        }
172        break;
173    case standardInterfaces::ModulationScheme::QAM:
174        switch (metadata->modulation_scheme.M) {
175        case 4:
176            ConfigureModulationScheme(SigProc::QPSK);
177            DEBUG(5, FrameAssembler, "Frame mod set to QPSK (4QAM)");
178            break;
179        case 16:
180            ConfigureModulationScheme(SigProc::QAM16);
181            DEBUG(5, FrameAssembler, "Frame mod set to 16QAM");
182            break;
183        default:
184            std::cerr << "FrameAssembler-metadata: Unsupported QAM modulation depth" << std::endl;
185            throw 0;
186        }
187        break;
188    case standardInterfaces::ModulationScheme::PAM:
189        switch (metadata->modulation_scheme.M) {
190        case 4:
191            ConfigureModulationScheme(SigProc::PAM4);
192            DEBUG(5, FrameAssembler, "Frame mod set to 4PAM");
193            break;
194        default:
195            std::cerr << "FrameAssembler-metadata: Unsupported PAM modulation depth" << std::endl;
196            throw 0;
197        }
198        break;
199    case standardInterfaces::ModulationScheme::UNKNOWN:
200    default:;
201    }
202}
203
204
205
206
207void FrameAssembler_i::ProcessData()
208{
209    DEBUG(3, FrameAssembler, "ProcessData() invoked")
210
211    PortTypes::ShortSequence I_out_header, Q_out_header;
212    PortTypes::ShortSequence I_out_data, Q_out_data;
213    PortTypes::ShortSequence I_out_0, Q_out_0;
214
215    PortTypes::ShortSequence *I_in_0(NULL), *Q_in_0(NULL);
216    unsigned int N_in(0);
217    unsigned int j(0);
218    unsigned int blockSize(512);
219
220    // Prepare preamble phasing pattern, ramp up/down
221    short * I_phasing_pattern = new short[512];
222    short * Q_phasing_pattern = new short[512];
223    PortTypes::ShortSequence I_out_phasing_pattern, Q_out_phasing_pattern;
224    I_out_phasing_pattern.length(512);
225    Q_out_phasing_pattern.length(512);
226    PortTypes::ShortSequence I_out_ramp_up, Q_out_ramp_up;
227    I_out_ramp_up.length(512);
228    Q_out_ramp_up.length(512);
229    PortTypes::ShortSequence I_out_ramp_down, Q_out_ramp_down;
230    I_out_ramp_down.length(512);
231    Q_out_ramp_down.length(512);
232
233    AssemblePhasingPattern(I_phasing_pattern, Q_phasing_pattern);
234    for (unsigned int i=0; i<512; i++) {
235        I_out_phasing_pattern[i] = I_phasing_pattern[i];
236        Q_out_phasing_pattern[i] = Q_phasing_pattern[i];
237       
238        I_out_ramp_up[i] = (short) (I_phasing_pattern[i] * (0.5 - 0.5*cos( PI*i/512 )));
239        Q_out_ramp_up[i] = (short) (Q_phasing_pattern[i] * (0.5 - 0.5*cos( PI*i/512 )));
240       
241        I_out_ramp_down[i] = 1 - I_out_ramp_up[i];
242        Q_out_ramp_down[i] = 1 - Q_out_ramp_up[i];
243    }
244    delete [] I_phasing_pattern;
245    delete [] Q_phasing_pattern;
246
247
248    short * I_header = new short[512];
249    short * Q_header = new short[512];
250
251    while( true ) {
252
253        numFrameSymbolsAssembled = 0;
254
255        while ( numFrameSymbolsAssembled < (frameSize-1) ) {
256            I_out_data.length(frameSize);
257            Q_out_data.length(frameSize);
258
259            // Get data from port
260            dataIn_0->getData(I_in_0, Q_in_0, metadata);
261
262            ConfigureModulationSchemeOnMetaData();
263
264            // Read input data length
265            N_in = I_in_0->length();
266
267            for (unsigned int i=0; i<N_in; i++) {
268                //
269                I_out_data[numFrameSymbolsAssembled] = (*I_in_0)[i];
270                Q_out_data[numFrameSymbolsAssembled] = (*Q_in_0)[i];
271
272                numFrameSymbolsAssembled++;
273            }
274
275            // empty input buffer; release semaphore
276            dataIn_0->bufferEmptied();
277
278        }
279
280        // ASSEMBLE_PREAMBLE
281        DEBUG(4, FrameAssembler, "Assembling preamble")
282
283        // push ramp-up preamble phasing pattern
284        DEBUG(7, FrameAssembler, "pushing ramp up phasing " << I_out_ramp_up.length() << " frame samples")
285        dataOut_0->pushPacket(I_out_ramp_up, Q_out_ramp_up, *metadata);
286
287        // push preamble
288        for (unsigned int i=0; i<2; i++) {
289            DEBUG(7, FrameAssembler, "pushing phasing " << I_out_phasing_pattern.length() << " frame samples")
290            dataOut_0->pushPacket(I_out_phasing_pattern, Q_out_phasing_pattern, *metadata);
291        }
292
293        // ASSEMBLE_HEADER
294        DEBUG(4, FrameAssembler, "Assembling header")
295        // copy header
296        I_out_header.length(512);
297        Q_out_header.length(512);
298        AssembleHeader( I_header, Q_header );
299        for (unsigned int i=0; i<512; i++) {
300            I_out_header[i] = I_header[i];
301            Q_out_header[i] = Q_header[i];
302        }
303
304        // push data
305        DEBUG(7, FrameAssembler, "pushing header " << I_out_header.length() << " frame samples")
306        dataOut_0->pushPacket(I_out_header, Q_out_header, *metadata);
307
308
309        // ASSEMBLE_FRAME
310        // break output into smaller pieces
311       
312        I_out_0.length(blockSize);
313        Q_out_0.length(blockSize);
314
315        j = 0;
316        for ( unsigned int i=0; i<frameSize; i++ ) {
317            I_out_0[j] = I_out_data[i];
318            Q_out_0[j] = Q_out_data[i];
319            j++;
320           
321            if ( j==blockSize || i==(frameSize-1) ) {
322                I_out_0.length(j);
323                Q_out_0.length(j);
324                DEBUG(7, FrameAssembler, "pushing frame " << I_out_0.length() << " frame samples")
325                dataOut_0->pushPacket(I_out_0, Q_out_0, *metadata);
326                j=0;
327            }
328        }
329
330        // ASSEMBLE_EOM_CODE:
331        // push phasing pattern
332        ///\todo assemble EOM code
333        // push preamble
334        for (unsigned int i=0; i<4; i++) {
335            DEBUG(7, FrameAssembler, "pushing tail " << I_out_phasing_pattern.length() << " frame samples")
336            dataOut_0->pushPacket(I_out_phasing_pattern, Q_out_phasing_pattern, *metadata);
337        }
338
339        // push ramp-down phasing pattern
340        DEBUG(7, FrameAssembler, "pushing ramp down phasing " << I_out_ramp_up.length() << " frame samples")
341        dataOut_0->pushPacket(I_out_ramp_down, Q_out_ramp_down, *metadata);
342    }
343
344    delete [] I_header;
345    delete [] Q_header;
346}
347
348
Note: See TracBrowser for help on using the browser.