root/experimental/components/Demodulator/src/Demodulator.cpp @ 4005

Revision 4005, 5.7 KB (checked in by jgaeddert, 6 years ago)

Functionalizing component wrapper for Demodulator component

  • 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 Demodulator.
6
7OSSIE Demodulator 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 Demodulator 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 Demodulator; 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 "Demodulator.h"
27
28Demodulator_i::Demodulator_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::realChar_u("DataBitsOut");
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
42Demodulator_i::~Demodulator_i(void)
43{   
44    delete dataIn_0;
45    delete dataOut_0;
46}
47
48// Static function for omni thread
49void Demodulator_i::Run( void * data )
50{
51    ((Demodulator_i*)data)->ProcessData();
52}
53
54CORBA::Object_ptr Demodulator_i::getPort( const char* portName ) throw (
55    CORBA::SystemException, CF::PortSupplier::UnknownPort)
56{
57    DEBUG(3, Demodulator, "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 Demodulator_i::start() throw (CORBA::SystemException,
76    CF::Resource::StartError)
77{
78    DEBUG(3, Demodulator, "start() invoked")
79}
80
81void Demodulator_i::stop() throw (CORBA::SystemException, CF::Resource::StopError)
82
83    DEBUG(3, Demodulator, "stop() invoked")
84}
85
86void Demodulator_i::releaseObject() throw (CORBA::SystemException,
87    CF::LifeCycle::ReleaseError)
88{
89    DEBUG(3, Demodulator, "releaseObject() invoked")
90   
91    component_running->signal();
92}
93
94void Demodulator_i::initialize() throw (CF::LifeCycle::InitializeError,
95    CORBA::SystemException)
96{
97    DEBUG(3, Demodulator, "initialize() invoked")
98}
99
100void Demodulator_i::configure(const CF::Properties& props)
101throw (CORBA::SystemException,
102    CF::PropertySet::InvalidConfiguration,
103    CF::PropertySet::PartialConfiguration)
104{
105    DEBUG(3, Demodulator, "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:df4641d3-5c25-47d4-8d0b-89a069ac0248") == 0) {
113            // Demodulation scheme
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                SetModulationScheme( MOD_BPSK );
120            } else if ( strcmp(prop_str, "QPSK") == 0 ) {
121                SetModulationScheme( MOD_QPSK );
122            } else if ( strcmp(prop_str, "8PSK") == 0 ) {
123                SetModulationScheme( MOD_8PSK );
124            } else if ( strcmp(prop_str, "16QAM") == 0 ) {
125                SetModulationScheme( MOD_16QAM );
126            } else if ( strcmp(prop_str, "4PAM") == 0 ) {
127                SetModulationScheme( MOD_4PAM );
128            } else {
129                // unknown property
130                std::cerr << "ERROR: Demodulator::configure() unknown mod. scheme "
131                          << prop_str << std::endl;
132                throw CF::PropertySet::InvalidConfiguration();
133            }
134            ///\todo catch exception thrown by DemodulatorDSP::ConfigureModulationScheme()
135
136        } else {
137            // unknown property
138            std::cerr << "ERROR: Demodulator::configure() unknown property" << std::endl;
139            throw CF::PropertySet::InvalidConfiguration();
140        }
141    }
142
143}
144
145void Demodulator_i::ProcessData()
146{
147    DEBUG(3, Demodulator, "ProcessData() invoked")
148
149    PortTypes::CharSequence bits_out;
150
151    PortTypes::ShortSequence *I_in(NULL), *Q_in(NULL);
152    unsigned int N_in(0), N_out(0);
153
154    unsigned int i;
155    char * b(NULL);
156    short * I(NULL), * Q(NULL);
157
158    while( true ) {
159        // Get data from port
160        dataIn_0->getData(I_in, Q_in);
161
162        // Read input data length
163        N_in = I_in->length();
164        N_out = N_in * bitsPerSymbol;
165
166        // Configure output data length
167        bits_out.length(N_out);
168
169        // Copy data
170        ///\todo Copying data is incredibly inefficient; need to initialize
171        /// CORBA array on buffer and vise versa
172        b = new char[N_out];
173        I = new short[N_in];
174        Q = new short[N_in];
175
176        for (i=0; i<N_in; i++) {
177            I[i] = (*I_in)[i];
178            Q[i] = (*Q_in)[i];
179        }
180
181        // Signal processing goes here
182        DemodulateSequence(I, Q, N_in, b);
183
184        for (i=0; i<N_out; i++) {
185            bits_out[i] = b[i];
186        }
187
188        dataIn_0->bufferEmptied();
189        dataOut_0->pushPacket(bits_out);
190    }
191
192    delete [] b;
193    delete [] I;
194    delete [] Q;
195
196}
197
198
Note: See TracBrowser for help on using the browser.