root/ossiedev/branches/hvolos/packetwfrm/components/FrameAssembler/src/FrameAssembler.cpp @ 8831

Revision 8831, 11.9 KB (checked in by hvolos, 4 years ago)

remove metadata, add frame size properties

  • 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    frame_size_option=1;
35
36    //Create the thread for the writer's processing function
37    processing_thread = new omni_thread(Run, (void *) this);
38
39    //Start the thread containing the writer's processing function
40    processing_thread->start();
41
42}
43
44FrameAssembler_i::~FrameAssembler_i(void)
45{   
46    delete dataIn_0;
47    delete dataOut_0;
48}
49
50// Static function for omni thread
51void FrameAssembler_i::Run( void * data )
52{
53    ((FrameAssembler_i*)data)->ProcessData();
54}
55
56CORBA::Object_ptr FrameAssembler_i::getPort( const char* portName ) throw (
57    CORBA::SystemException, CF::PortSupplier::UnknownPort)
58{
59    DEBUG(3, FrameAssembler, "getPort() invoked with " << portName)
60   
61    CORBA::Object_var p;
62
63    p = dataIn_0->getPort(portName);
64
65    if (!CORBA::is_nil(p))
66        return p._retn();
67
68    p = dataOut_0->getPort(portName);
69
70    if (!CORBA::is_nil(p))
71        return p._retn();
72
73    // Requested port not recognized
74    throw CF::PortSupplier::UnknownPort();
75}
76
77void FrameAssembler_i::start() throw (CORBA::SystemException,
78    CF::Resource::StartError)
79{
80    DEBUG(3, FrameAssembler, "start() invoked")
81}
82
83void FrameAssembler_i::stop() throw (CORBA::SystemException, CF::Resource::StopError)
84
85    DEBUG(3, FrameAssembler, "stop() invoked")
86}
87
88void FrameAssembler_i::releaseObject() throw (CORBA::SystemException,
89    CF::LifeCycle::ReleaseError)
90{
91    DEBUG(3, FrameAssembler, "releaseObject() invoked")
92   
93    component_running->signal();
94}
95
96void FrameAssembler_i::initialize() throw (CF::LifeCycle::InitializeError,
97    CORBA::SystemException)
98{
99    DEBUG(3, FrameAssembler, "initialize() invoked")
100}
101
102void FrameAssembler_i::configure(const CF::Properties& props)
103throw (CORBA::SystemException,
104    CF::PropertySet::InvalidConfiguration,
105    CF::PropertySet::PartialConfiguration)
106{
107    DEBUG(3, FrameAssembler, "configure() invoked")
108   
109    std::cout << "props length : " << props.length() << std::endl;
110
111    for (unsigned int i = 0; i <props.length(); i++) {
112        std::cout << "Property id : " << props[i].id << std::endl;
113
114        if (strcmp(props[i].id, "DCE:a15e70e4-96e4-4cc8-b1f0-06cb301f6c2e") == 0) {
115            // Modulation type
116            const char * prop_str;
117            props[i].value >>= prop_str;
118
119            // Set appropriate modulation function
120            if ( strcmp(prop_str, "BPSK") == 0 ) {
121                ConfigureModulationScheme(SigProc::BPSK);
122            } else if ( strcmp(prop_str, "QPSK") == 0 ) {
123                ConfigureModulationScheme(SigProc::QPSK);
124            } else if ( strcmp(prop_str, "8PSK") == 0 ) {
125                ConfigureModulationScheme(SigProc::PSK8);
126            } else if ( strcmp(prop_str, "16QAM") == 0 ) {
127                ConfigureModulationScheme(SigProc::QAM16);
128            } else if ( strcmp(prop_str, "4PAM") == 0 ) {
129                ConfigureModulationScheme(SigProc::PAM4);
130            } else {
131                // unknown property
132                std::cerr << "ERROR: FrameAssembler::configure() unknown mod. scheme "
133                          << prop_str << std::endl;
134                throw CF::PropertySet::InvalidConfiguration();
135            }
136            ///\todo catch exception thrown by FrameAssemblerDSP::ConfigureModulationScheme()
137
138        } else if (strcmp(props[i].id, "DCE:96b798ba-5412-4bbe-bf0b-8ca665d25b83") == 0) {
139            // Frame size
140            CORBA::UShort simple_temp;
141            props[i].value >>= simple_temp;
142            frame_size_option=simple_temp;
143            ConfigureFrameSize(frame_size_option);
144            DEBUG(3, FrameAssembler, "Frame Size Option "<<frame_size_option<<" read and configured")
145        } else if (strcmp(props[i].id, "DCE:cdac2d50-214c-4c47-8a6d-d9ec453b3b3c") == 0) {
146            CORBA::UShort simple_temp;
147            props[i].value >>= simple_temp;
148            SetFrameSize(simple_temp,1);           
149        } else if (strcmp(props[i].id, "DCE:a6caa288-08d2-4f0e-b0f0-f34fa513ce3d") == 0) {
150            CORBA::UShort simple_temp;
151            props[i].value >>= simple_temp;
152            SetFrameSize(simple_temp,2);
153        } else if (strcmp(props[i].id, "DCE:bcf3ff9b-9f9d-4498-b29a-78f813678271") == 0) {
154            CORBA::UShort simple_temp;
155            props[i].value >>= simple_temp;
156            SetFrameSize(simple_temp,3);
157        } else if (strcmp(props[i].id, "DCE:34311a06-2055-4490-a949-478786cad4d4") == 0) {
158            CORBA::UShort simple_temp;
159            props[i].value >>= simple_temp;
160            SetFrameSize(simple_temp,4);
161
162        } else {
163            // unknown property
164            std::cerr << "ERROR: FrameAssembler::configure() unknown property" << std::endl;
165            throw CF::PropertySet::InvalidConfiguration();
166        }
167    }
168   
169    //Update frame size
170    ConfigureFrameSize(frame_size_option);
171    DEBUG(3, FrameAssembler, "Frame Size Option "<<frame_size_option<<" configured")
172
173}
174
175
176
177void FrameAssembler_i::ProcessData()
178{
179    DEBUG(3, FrameAssembler, "ProcessData() invoked")
180
181    PortTypes::ShortSequence I_out_header, Q_out_header;
182    PortTypes::ShortSequence I_out_data, Q_out_data;
183    PortTypes::ShortSequence I_out_0, Q_out_0;
184
185    PortTypes::ShortSequence *I_in_0(NULL), *Q_in_0(NULL);
186    unsigned int N_in(0);
187    unsigned int j(0);
188    unsigned int blockSize(512);
189
190    // Prepare preamble phasing pattern, ramp up/down
191    short * I_phasing_pattern = new short[512];
192    short * Q_phasing_pattern = new short[512];
193    PortTypes::ShortSequence I_out_phasing_pattern, Q_out_phasing_pattern;
194    I_out_phasing_pattern.length(256);
195    Q_out_phasing_pattern.length(256);
196    PortTypes::ShortSequence I_out_ramp_up, Q_out_ramp_up;
197    I_out_ramp_up.length(256);
198    Q_out_ramp_up.length(256);
199    PortTypes::ShortSequence I_out_ramp_down, Q_out_ramp_down;
200    I_out_ramp_down.length(256);
201    Q_out_ramp_down.length(256);
202
203    AssemblePhasingPattern(I_phasing_pattern, Q_phasing_pattern);
204    for (unsigned int i=0; i<256; i++) {
205        I_out_phasing_pattern[i] = I_phasing_pattern[i];
206        Q_out_phasing_pattern[i] = Q_phasing_pattern[i];
207       
208        I_out_ramp_up[i] = (short) (I_phasing_pattern[i] * (0.5 - 0.5*cos( PI*i/256 )));
209        Q_out_ramp_up[i] = (short) (Q_phasing_pattern[i] * (0.5 - 0.5*cos( PI*i/256 )));
210       
211        I_out_ramp_down[i] = 1 - I_out_ramp_up[i];
212        Q_out_ramp_down[i] = 1 - Q_out_ramp_up[i];
213    }
214
215    // control
216    PortTypes::ShortSequence I_out_control, Q_out_control;
217    I_out_control.length(1024);
218    Q_out_control.length(1024);
219    for (unsigned int i=0; i<256; i++) {
220        I_out_control[i] = (i%2 == 0) ? -BPSK_LEVEL : BPSK_LEVEL;
221        Q_out_control[i] = 0;
222    }
223
224    delete [] I_phasing_pattern;
225    delete [] Q_phasing_pattern;
226
227
228    short * I_header = new short[512];
229    short * Q_header = new short[512];
230
231    while( true ) {
232
233        numFrameSymbolsAssembled = 0;
234
235        while ( numFrameSymbolsAssembled < (frameSize-1) ) {
236            // Get data from port
237            dataIn_0->getData(I_in_0, Q_in_0);
238            // Read input data length
239            N_in = I_in_0->length();
240            DEBUG(1, FrameAssembler, "got " << N_in << " samples");
241
242
243/* HV
244
245                for (unsigned int i=0; i<N_in; i++) {
246                    I_out_control[i] = (*I_in_0)[i];
247                    Q_out_control[i] = (*Q_in_0)[i];
248                }
249                dataIn_0->bufferEmptied();
250                continue;
251            }
252*/
253
254            if ( numFrameSymbolsAssembled==0 ) {
255                // first packet
256                //ConfigureModulationScheme(SigProc::QPSK);
257               
258
259                 ConfigureFrameType(FRAME_TYPE_DATA);
260
261                ConfigureFrameSize(frame_size_option);
262                   
263
264                I_out_data.length(frameSize);
265                Q_out_data.length(frameSize);
266            }
267
268            DEBUG(1, FrameAssembler, "Assembling " << N_in << " symbols (max: " << frameSize);
269
270            for (unsigned int i=0; i<N_in; i++) {
271                //
272                I_out_data[numFrameSymbolsAssembled] = (*I_in_0)[i];
273                Q_out_data[numFrameSymbolsAssembled] = (*Q_in_0)[i];
274
275                numFrameSymbolsAssembled++;
276            }
277
278            // empty input buffer; release semaphore
279            dataIn_0->bufferEmptied();
280
281        }
282
283        // ASSEMBLE_PREAMBLE
284        DEBUG(4, FrameAssembler, "Assembling preamble")
285
286
287        // push ramp-up preamble phasing pattern
288        DEBUG(7, FrameAssembler, "pushing ramp up phasing " << I_out_ramp_up.length() << " frame samples")
289        dataOut_0->pushPacket(I_out_ramp_up, Q_out_ramp_up);
290
291        // push preamble
292        unsigned int phasing_pattern_length;
293           
294         phasing_pattern_length = 32;
295
296        for (unsigned int i=0; i<phasing_pattern_length; i++) {
297            DEBUG(7, FrameAssembler, "pushing phasing " << I_out_phasing_pattern.length() << " frame samples")
298            dataOut_0->pushPacket(I_out_phasing_pattern, Q_out_phasing_pattern);
299        }
300
301        // ASSEMBLE_HEADER
302        DEBUG(4, FrameAssembler, "Assembling header")
303        // copy header
304        I_out_header.length(512);
305        Q_out_header.length(512);
306        AssembleHeader( I_header, Q_header );
307        for (unsigned int i=0; i<512; i++) {
308            I_out_header[i] = I_header[i];
309            Q_out_header[i] = Q_header[i];
310        }
311
312        // push data
313        DEBUG(7, FrameAssembler, "pushing header " << I_out_header.length() << " frame samples")
314
315        dataOut_0->pushPacket(I_out_header, Q_out_header);
316
317
318        // ASSEMBLE_FRAME
319        // break output into smaller pieces
320       
321        I_out_0.length(blockSize);
322        Q_out_0.length(blockSize);
323
324        j = 0;
325        for ( unsigned int i=0; i<frameSize; i++ ) {
326            I_out_0[j] = I_out_data[i];
327            Q_out_0[j] = Q_out_data[i];
328            j++;
329           
330            if ( j==blockSize || i==(frameSize-1) ) {
331                I_out_0.length(j);
332                Q_out_0.length(j);
333                DEBUG(7, FrameAssembler, "pushing frame " << I_out_0.length() << " frame samples")
334                dataOut_0->pushPacket(I_out_0, Q_out_0);
335                j=0;
336            }
337        }
338
339        // ASSEMBLE_EOM_CODE:
340        // push phasing pattern
341        ///\todo push control packet (BPSK)
342        if (frameType != FRAME_TYPE_CONTROL) {
343            // No need to push additional control information as internal frame data
344            // are already control
345            DEBUG(7, FrameAssembler, "pushing control " << I_out_control.length() << " frame samples")
346
347      //no EOM      dataOut_0->pushPacket(I_out_control, Q_out_control);
348
349        }
350
351        // push ramp-down phasing pattern
352        DEBUG(7, FrameAssembler, "pushing ramp down phasing " << I_out_ramp_up.length() << " frame samples")
353
354        dataOut_0->pushPacket(I_out_ramp_down, Q_out_ramp_down);
355
356    }
357
358    delete [] I_header;
359    delete [] Q_header;
360}
361
362
Note: See TracBrowser for help on using the browser.