root/components/AutomaticGainControl/trunk/AutomaticGainControl/AutomaticGainControl.cpp @ 2411

Revision 2411, 6.2 KB (checked in by jgaeddert, 6 years ago)

added basic functionality; needs testing

Line 
1/****************************************************************************
2
3Copyright 2006 Virginia Polytechnic Institute and State University
4
5This file is part of the OSSIE AutomaticGainControl.
6
7OSSIE AutomaticGainControl 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 AutomaticGainControl 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 AutomaticGainControl; 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 "AutomaticGainControl.h"
27
28AutomaticGainControl_i::AutomaticGainControl_i(const char *uuid, omni_condition *condition) : Resource_impl(uuid), component_running(condition)
29{
30    dataOut_0 = new standardInterfaces_i::complexShort_u("data_out");
31    dataIn_0 = new standardInterfaces_i::complexShort_p("data_in");
32
33
34    //Create the thread for the writer's processing function
35    processing_thread = new omni_thread(process_data, (void *) this);
36
37
38    //Start the thread containing the writer's processing function
39    processing_thread->start();
40}
41
42AutomaticGainControl_i::~AutomaticGainControl_i(void)
43{   
44    delete dataOut_0;
45    delete dataIn_0;
46}
47
48CORBA::Object_ptr AutomaticGainControl_i::getPort( const char* portName ) throw (CORBA::SystemException, CF::PortSupplier::UnknownPort)
49{
50    std::cout << "AutomaticGainControl_i getPort called with : " << portName << std::endl;
51   
52    CORBA::Object_var p;
53
54    p = dataOut_0->getPort(portName);
55
56    if (!CORBA::is_nil(p))
57        return p._retn();
58
59    p = dataIn_0->getPort(portName);
60
61    if (!CORBA::is_nil(p))
62        return p._retn();
63
64    /*exception*/
65    throw CF::PortSupplier::UnknownPort();
66}
67
68void AutomaticGainControl_i::start() throw (CORBA::SystemException, CF::Resource::StartError)
69{
70    std::cout << "start called on AutomaticGainControl" << std::endl;
71}
72
73void AutomaticGainControl_i::stop() throw (CORBA::SystemException, CF::Resource::StopError)
74
75    std::cout << "stop called on AutomaticGainControl" << std::endl;
76}
77
78void AutomaticGainControl_i::releaseObject() throw (CORBA::SystemException, CF::LifeCycle::ReleaseError)
79{
80    std::cout << "releaseObject called on AutomaticGainControl" << std::endl;
81   
82    component_running->signal();
83}
84
85void AutomaticGainControl_i::initialize() throw (CF::LifeCycle::InitializeError, CORBA::SystemException)
86{
87    std::cout << "initialize called on AutomaticGainControl" << std::endl;
88}
89
90void AutomaticGainControl_i::configure(const CF::Properties& props) throw (CORBA::SystemException, CF::PropertySet::InvalidConfiguration, CF::PropertySet::PartialConfiguration)
91{
92    std::cout << "configure called on AutomaticGainControl" << std::endl;
93   
94    std::cout << "props length : " << props.length() << std::endl;
95
96    for (unsigned int i = 0; i <props.length(); i++)
97    {
98        std::cout << "Property id : " << props[i].id << std::endl;
99
100        if (strcmp(props[i].id, "DCE:aaf97fa0-d184-4d88-9954-3a1334c73d6d") == 0)
101        {
102            CORBA::Float simple_temp;
103            props[i].value >>= simple_temp;
104            simple_0_value = simple_temp;
105        }
106
107        if (strcmp(props[i].id, "DCE:346e17c9-6678-483a-bffb-1909c64bddc0") == 0)
108        {
109            CORBA::Float simple_temp;
110            props[i].value >>= simple_temp;
111            simple_1_value = simple_temp;
112        }
113
114        if (strcmp(props[i].id, "DCE:4608b943-4fe2-49df-91fb-afa287b609d4") == 0)
115        {
116            CORBA::Float simple_temp;
117            props[i].value >>= simple_temp;
118            simple_2_value = simple_temp;
119        }
120
121        if (strcmp(props[i].id, "DCE:491ec3de-ed45-48af-a6fc-ca2d6465e136") == 0)
122        {
123            CORBA::Float simple_temp;
124            props[i].value >>= simple_temp;
125            simple_3_value = simple_temp;
126        }
127
128        if (strcmp(props[i].id, "DCE:312f63fe-709a-4217-933b-c584c8d6a9bb") == 0)
129        {
130            CORBA::Float simple_temp;
131            props[i].value >>= simple_temp;
132            simple_4_value = simple_temp;
133        }
134
135        if (strcmp(props[i].id, "DCE:8357ee0d-2417-46d9-8475-2e5778d797e4") == 0)
136        {
137            CORBA::Float simple_temp;
138            props[i].value >>= simple_temp;
139            simple_5_value = simple_temp;
140        }
141
142    }
143}
144
145void process_data(void *data)
146{
147    std::cout << "AutomaticGainControl's process_data thread started" << std::endl;
148
149    AutomaticGainControl_i *mem = (AutomaticGainControl_i *) data;
150   
151    PortTypes::ShortSequence I_out, Q_out;
152   
153    PortTypes::ShortSequence *I_in(NULL), *Q_in(NULL);
154    //CORBA::UShort I_in_length, Q_in_length;
155
156    unsigned int i, N;
157    float gain(0.0f), energy(0.0f);
158
159    SigProc::agc * agc;
160
161    // override properties
162    mem->energy_lo = 4000.0f;
163    mem->energy_hi = 16000.0f;
164    mem->k_attack = 0.5f;
165    mem->k_release = 0.0f;
166    mem->g_max = 10.0f;
167    mem->g_min = 0.1f;
168
169    agc = new SigProc::agc(
170                 mem->energy_lo,
171                 mem->energy_hi,
172                 mem->k_attack,
173                 mem->k_release,
174                 mem->g_max,
175                 mem->g_min
176              );
177
178
179    while( true )
180    {
181        std::cout << "AGC waiting for data..." << std::endl;
182        mem->dataIn_0->getData(I_in, Q_in);
183        std::cout << "AGC got " << I_in->length() << " samples" << std::endl;
184       
185        N = I_in->length();
186
187        I_out.length(N); //must define length of output
188        Q_out.length(N); //must define length of output
189
190        for (i=0; i<N; i++)
191        {
192            I_out[i] = (*I_in)[i];
193            Q_out[i] = (*Q_in)[i];
194            agc->do_work(I_out[i], Q_out[i], gain, energy);
195        }
196        std::cout << "gain: " << gain << ", energy: " << energy << std::endl;
197
198        mem->dataIn_0->bufferEmptied();
199        mem->dataOut_0->pushPacket(I_out, Q_out);
200    }
201}
202
203   
Note: See TracBrowser for help on using the browser.