root/experimental/components/SymbolSyncPoly/SymbolSyncPoly.cpp @ 3656

Revision 3656, 8.7 KB (checked in by jgaeddert, 6 years ago)

making component functional; needs testing

  • 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 SymbolSyncPoly.
6
7OSSIE SymbolSyncPoly 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 SymbolSyncPoly 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 SymbolSyncPoly; 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 "SymbolSyncPoly.h"
27
28SymbolSyncPoly_i::SymbolSyncPoly_i(const char *uuid, omni_condition *condition) :
29    Resource_impl(uuid), component_running(condition)
30{
31    dataIn_0 = new standardInterfaces_i::complexShort_p("baseband_in");
32    dataOut_0 = new standardInterfaces_i::complexShort_u("symbols_out");
33
34
35    //Create the thread for the writer's processing function
36    processing_thread = new omni_thread(Run, (void *) this);
37
38    //Start the thread containing the writer's processing function
39    processing_thread->start();
40
41    isConfigured_pulseShape = true;
42    isConfigured_k          = false;
43    isConfigured_m          = false;
44    isConfigured_beta       = false;
45    isConfigured_Npfb       = false;
46
47}
48
49SymbolSyncPoly_i::~SymbolSyncPoly_i(void)
50{   
51    delete dataIn_0;
52    delete dataOut_0;
53}
54
55// Static function for omni thread
56void SymbolSyncPoly_i::Run( void * data )
57{
58    ((SymbolSyncPoly_i*)data)->ProcessData();
59}
60
61CORBA::Object_ptr SymbolSyncPoly_i::getPort( const char* portName ) throw (
62    CORBA::SystemException, CF::PortSupplier::UnknownPort)
63{
64    DEBUG(3, SymbolSyncPoly, "getPort() invoked with " << portName)
65   
66    CORBA::Object_var p;
67
68    p = dataIn_0->getPort(portName);
69
70    if (!CORBA::is_nil(p))
71        return p._retn();
72
73    p = dataOut_0->getPort(portName);
74
75    if (!CORBA::is_nil(p))
76        return p._retn();
77
78    /*exception*/
79    throw CF::PortSupplier::UnknownPort();
80}
81
82void SymbolSyncPoly_i::start() throw (CORBA::SystemException,
83    CF::Resource::StartError)
84{
85    DEBUG(3, SymbolSyncPoly, "start() invoked")
86}
87
88void SymbolSyncPoly_i::stop() throw (CORBA::SystemException, CF::Resource::StopError)
89
90    DEBUG(3, SymbolSyncPoly, "stop() invoked")
91}
92
93void SymbolSyncPoly_i::releaseObject() throw (CORBA::SystemException,
94    CF::LifeCycle::ReleaseError)
95{
96    DEBUG(3, SymbolSyncPoly, "releaseObject() invoked")
97   
98    component_running->signal();
99}
100
101void SymbolSyncPoly_i::initialize() throw (CF::LifeCycle::InitializeError,
102    CORBA::SystemException)
103{
104    DEBUG(3, SymbolSyncPoly, "initialize() invoked")
105}
106
107void SymbolSyncPoly_i::configure(const CF::Properties& props)
108throw (CORBA::SystemException,
109    CF::PropertySet::InvalidConfiguration,
110    CF::PropertySet::PartialConfiguration)
111{
112    DEBUG(3, SymbolSyncPoly, "configure() invoked")
113   
114    std::cout << "props length : " << props.length() << std::endl;
115
116    for (unsigned int i = 0; i <props.length(); i++) {
117        std::cout << "Property id : " << props[i].id << std::endl;
118
119        if (strcmp(props[i].id, "DCE:41366fe0-e44e-11db-93b3-00123f63025f") == 0) {
120            // pulse shape
121            //CORBA::String simple_temp;
122            //props[i].value >>= simple_temp;
123            //simple_0_value = simple_temp;
124        } else if (strcmp(props[i].id, "DCE:6911ce74-e44e-11db-be33-00123f63025f") == 0) {
125            // k : samples per symbol
126            CORBA::UShort simple_temp;
127            props[i].value >>= simple_temp;
128            _k = simple_temp;
129            isConfigured_k = true;
130        } else if (strcmp(props[i].id, "DCE:99bf718e-e44e-11db-99e4-00123f63025f") == 0) {
131            // m : symbol delay
132            CORBA::UShort simple_temp;
133            props[i].value >>= simple_temp;
134            _m = simple_temp;
135            isConfigured_m = true;
136        } else if (strcmp(props[i].id, "DCE:afc47b82-e44e-11db-b1f3-00123f63025f") == 0) {
137            // beta : excess bandwidth factor
138            CORBA::Float simple_temp;
139            props[i].value >>= simple_temp;
140            _beta = simple_temp;
141            isConfigured_beta = true;
142        } else if (strcmp(props[i].id, "DCE:bea3b19a-e44e-11db-a3dd-00123f63025f") == 0) {
143            // Npfb : number of filters in bank
144            CORBA::UShort simple_temp;
145            props[i].value >>= simple_temp;
146            _Npfb = simple_temp;
147            isConfigured_Npfb = true;
148        } else {
149            // unknown property
150            std::cerr << "ERROR: SymbolSyncPoly::configure() unknown property \""
151               << props[i].id << "\"" << std::endl;
152            throw CF::PropertySet::InvalidConfiguration();
153        }
154    }
155
156    /// \todo configure filter bank type
157    ///
158    /// Once all properties have been configured, create the filter bank
159    if ( isConfigured_k     &&
160         isConfigured_m     &&
161         isConfigured_beta  &&
162         isConfigured_Npfb )
163    {
164        DEBUG(5, SymbolSyncPoly, "configuring filter bank for " <<
165              "rrcos" << ", k=" << _k << ", m=" << _m << ", beta=" << _beta << ", Npfb=" << _Npfb)
166        ConfigureFilterBank("rrcos", _k, _m, _beta, _Npfb);
167    }
168}
169
170void SymbolSyncPoly_i::ProcessData()
171{
172    DEBUG(3, SymbolSyncPoly, "ProcessData() invoked")
173
174    PortTypes::ShortSequence I_out_0, Q_out_0;
175
176    PortTypes::ShortSequence *I_in_0(NULL), *Q_in_0(NULL);
177    unsigned int I_in_0_length, Q_in_0_length, N_in(0), N_out(0);
178    short * I_in(NULL);
179    short * Q_in(NULL);
180    short * I_out(NULL);
181    short * Q_out(NULL);
182
183    while( true )
184    {
185        DEBUG(7, SymbolSyncPoly, "iterating loop...")
186
187        // Get data from port
188        dataIn_0->getData(I_in_0, Q_in_0);
189
190        DEBUG(7, SymbolSyncPoly, "Got " << I_in_0->length() << " samples")
191
192        // Read input data length
193        I_in_0_length = I_in_0->length();
194        Q_in_0_length = Q_in_0->length();
195
196        if ( I_in_0_length != Q_in_0_length ) {
197            // Not sure how to handle multiple-length inputs
198            std::cerr << "ERROR: SymbolSyncPoly_i::ProcessData()" << std::endl
199                      << "  => Not sure how to handle multiple-length inputs" << std::endl;
200            throw 0;
201        } else {
202            N_in = I_in_0_length;
203        }
204
205        /// \todo Initialize I_in and Q_in from CORBA sequence instead
206        /// of copying values in loop
207        DEBUG(7, SymbolSyncPoly, "Copying data from CORBA sequence...")
208        /// \todo This is incredibly inefficient; need to manage memory better
209        I_in = new short[N_in];
210        Q_in = new short[N_in];
211        for (unsigned int ii=0; ii<N_in; ii++) {
212            I_in[ii] = (*I_in_0)[ii];
213            Q_in[ii] = (*Q_in_0)[ii];
214        }
215
216        // Configure output data length
217        if ( I_out == NULL ) {
218            // Memory was never allocated; do so now
219            I_out = new short[2*N_in/k];
220            Q_out = new short[2*N_in/k];
221            N_out = 2*N_in/k;
222        } else if ( N_out < (2*N_in/k) ) {
223            // Too little memory was allocated; renew
224            delete [] I_out;
225            delete [] Q_out;
226            I_out = new short[2*N_in/k];
227            Q_out = new short[2*N_in/k];
228            N_out = 2*N_in/k;
229        } else {
230            // Memory is ok; do nothing
231        }
232
233        // Main signal processing algorithm
234        DEBUG(7, SymbolSyncPoly, "Attempting to synchronize and decimate...")
235        SynchronizeAndDecimate(
236            I_in, Q_in, N_in,
237            I_out, Q_out, N_out);
238
239        DEBUG(7, SymbolSyncPoly, "Setting output length...")
240        I_out_0.length(N_out);
241        Q_out_0.length(N_out);
242
243        /// \todo Initialize I_out_0 and Q_out_0 from array instead
244        /// of copying values in loop
245        DEBUG(7, SymbolSyncPoly, "Copying data to CORBA sequence...")
246        for (unsigned int ii=0; ii<N_out; ii++) {
247            I_out_0[ii] = I_out[ii];
248            Q_out_0[ii] = Q_out[ii];
249        }
250
251        DEBUG(7, SymbolSyncPoly, "Emptying port buffer...")
252        dataIn_0->bufferEmptied();
253
254        DEBUG(7, SymbolSyncPoly, "calling pushPacket()...")
255        dataOut_0->pushPacket(I_out_0, Q_out_0);
256
257        /// \todo This is incredibly inefficient; need to manage memory better
258        DEBUG(7, SymbolSyncPoly, "Deleting temp buffers...")
259        delete [] I_in;
260        delete [] Q_in;
261    }
262
263    // Free the memory
264    if ( I_out == NULL ) {
265        delete [] I_out;
266        delete [] Q_out;
267    }
268}
269
270
Note: See TracBrowser for help on using the browser.