root/ossiedev/branches/jgaeddert/0.8.0/components/src/FrameSync64.cpp @ 10089

Revision 10089, 7.4 KB (checked in by jgaeddert, 3 years ago)

updating signal processing objects to comply with liquid-dsp head revision

Line 
1/****************************************************************************
2
3Copyright 2010 by your_name_or_organization, all rights reserved.
4
5****************************************************************************/
6
7
8#include <cstdio>
9#include <string>
10#include <iostream>
11
12#include "config.h"
13#include "FrameSync64.h"
14
15// include main.cpp (must define COMPONENT_OBJECT)
16#define  COMPONENT_OBJECT FrameSync64_i
17#include "main.cpp"
18
19static int callback(unsigned char * _header,  int _header_valid,
20                    unsigned char * _payload, int _payload_valid,
21                    framesyncstats_s stats,
22                    void * _userdata);
23
24FrameSync64_i::FrameSync64_i(const char *uuid, omni_condition *condition) :
25    Resource_impl(uuid), component_running(condition)
26{
27    frameDataPortIn = new standardInterfaces_i::complexFloat_p("FrameSamplesIn");
28    headerDataPortOut = new standardInterfaces_i::realChar_u("HeaderDataOut");
29    payloadDataPortOut = new standardInterfaces_i::realChar_u("PayloadDataOut");
30
31    // create liquid dsp object(s)
32    verbose = true;
33    framesyncprops_init_default(&fsprops);
34    fs = framesync64_create(&fsprops,callback,(void*)this);
35}
36
37FrameSync64_i::~FrameSync64_i(void)
38{
39    delete frameDataPortIn;
40    delete headerDataPortOut;
41    delete payloadDataPortOut;
42
43    // delete liquid dsp object(s)
44    framesync64_destroy(fs);
45}
46
47// Static function for omni thread
48void FrameSync64_i::Run( void * data )
49{
50    ((FrameSync64_i*)data)->ProcessData();
51}
52
53CORBA::Object_ptr FrameSync64_i::getPort( const char* portName ) throw (
54    CORBA::SystemException, CF::PortSupplier::UnknownPort)
55{
56    DEBUG(3, FrameSync64, "getPort() invoked with " << portName)
57
58    CORBA::Object_var p;
59
60    p = frameDataPortIn->getPort(portName);
61
62    if (!CORBA::is_nil(p))
63        return p._retn();
64
65    p = headerDataPortOut->getPort(portName);
66
67    if (!CORBA::is_nil(p))
68        return p._retn();
69
70    p = payloadDataPortOut->getPort(portName);
71
72    if (!CORBA::is_nil(p))
73        return p._retn();
74
75    /*exception*/
76    throw CF::PortSupplier::UnknownPort();
77}
78
79void FrameSync64_i::start() throw (CORBA::SystemException,
80    CF::Resource::StartError)
81{
82    DEBUG(3, FrameSync64, "start() invoked")
83    omni_mutex_lock  l(processing_mutex);
84    if( false == thread_started )
85    {
86        thread_started = true;
87        // Create the thread for the writer's processing function
88        processing_thread = new omni_thread(Run, (void *) this);
89
90        // Start the thread containing the writer's processing function
91        processing_thread->start();
92    }
93}
94
95void FrameSync64_i::stop() throw (CORBA::SystemException, CF::Resource::StopError)
96{
97    DEBUG(3, FrameSync64, "stop() invoked")
98    omni_mutex_lock l(processing_mutex);
99    thread_started = false;
100}
101
102void FrameSync64_i::releaseObject() throw (CORBA::SystemException,
103    CF::LifeCycle::ReleaseError)
104{
105    DEBUG(3, FrameSync64, "releaseObject() invoked")
106
107    component_running->signal();
108}
109
110void FrameSync64_i::initialize() throw (CF::LifeCycle::InitializeError,
111    CORBA::SystemException)
112{
113    DEBUG(3, FrameSync64, "initialize() invoked")
114}
115
116void FrameSync64_i::query( CF::Properties & configProperties ) throw (CORBA::SystemException, CF::UnknownProperties)
117{
118    if( configProperties.length() == 0 )
119    {
120        configProperties.length( propertySet.length() );
121        for ( unsigned int i = 0; i < propertySet.length(); i++ )
122        {
123            configProperties[i].id = CORBA::string_dup( propertySet[i].id );
124            configProperties[i].value = propertySet[i].value;
125        }
126        return;
127    } else {
128        for( unsigned int i = 0; i < configProperties.length(); i++ ) {
129            for( unsigned int j = 0; j < propertySet.length(); j++ ) {
130                if( strcmp(configProperties[i].id, propertySet[i].id) == 0 ) {
131                    configProperties[i].value = propertySet[i].value;
132                }
133            }
134        }
135    } // end if-else
136}
137
138void FrameSync64_i::configure(const CF::Properties& props)
139throw (CORBA::SystemException,
140    CF::PropertySet::InvalidConfiguration,
141    CF::PropertySet::PartialConfiguration)
142{
143    DEBUG(3, FrameSync64, "configure() invoked")
144
145    static int init = 0;
146    if( init == 0 ) {
147        if( props.length() == 0 ) {
148            std::cout << "configure called with invalid props.length - " << props.length() << std::endl;
149            return;
150        }
151        propertySet.length(props.length());
152        for( unsigned int j=0; j < props.length(); j++ ) {
153            propertySet[j].id = CORBA::string_dup(props[j].id);
154            propertySet[j].value = props[j].value;
155        }
156        init = 1;
157    }
158
159    std::cout << "props length : " << props.length() << std::endl;
160
161    for ( unsigned int i = 0; i <props.length(); i++)
162    {
163        std::cout << "Property id : " << props[i].id << std::endl;
164
165        if (strcmp(props[i].id, "DCE:0a3620cc-0aa1-11df-baab-001aa089d644") == 0) {
166            // verbose
167            CORBA::Boolean tmp;
168            props[i].value >>= tmp;
169            verbose = tmp;
170        }
171    }
172}
173
174void FrameSync64_i::ProcessData()
175{
176    DEBUG(3, FrameSync64, "ProcessData() invoked")
177
178    PortTypes::FloatSequence *I_in(NULL), *Q_in(NULL);
179    CORBA::UShort I_in_length, Q_in_length;
180
181    unsigned int i;
182    std::complex<float> x;
183
184    while(continue_processing()) {
185        frameDataPortIn->getData(I_in, Q_in);
186
187        I_in_length = I_in->length();
188        Q_in_length = Q_in->length();
189
190        // operate one sample at a time
191        for (i=0; i<I_in_length; i++) {
192            // read separate I/Q streams and push into std::complex<float> type
193            x.real() = (*I_in)[i];
194            x.imag() = (*Q_in)[i];
195
196            // execute synchronizer on sample (callback will be invoked once
197            // frame has been received and decoded)
198            framesync64_execute(fs,&x,1);
199        }
200
201        // free input buffer
202        frameDataPortIn->bufferEmptied();
203    }
204
205    printf("************* destroying frame sync 64 object...\n");
206    framesync64_destroy(fs);
207}
208
209bool FrameSync64_i::continue_processing()
210{
211    omni_mutex_lock l(processing_mutex);
212    return thread_started;
213}
214
215static int callback(unsigned char * _header,  int _header_valid,
216                    unsigned char * _payload, int _payload_valid,
217                    framesyncstats_s _stats,
218                    void * _userdata)
219{
220    // type-cast
221    FrameSync64_i * fs_i = (FrameSync64_i*)_userdata;
222
223    if (fs_i->verbose) {
224        printf("callback invoked\n");
225
226        printf("  header crc          : %s\n", _header_valid ?  "pass" : "FAIL");
227        printf("  payload crc         : %s\n", _payload_valid ? "pass" : "FAIL");
228    }
229
230    if (_header_valid && _payload_valid) {
231        fs_i->PushHeaderData(_header);
232        fs_i->PushPayloadData(_payload);
233    }
234
235    return 0;
236}
237
238void FrameSync64_i::PushHeaderData(unsigned char * _header)
239{
240    // create output array and copy data
241    PortTypes::CharSequence headerDataOut;
242    headerDataOut.length(24);
243    for (unsigned int i=0; i<24; i++)
244        headerDataOut[i] = _header[i];
245
246    // invoke pushPacket on the port
247    headerDataPortOut->pushPacket(headerDataOut);
248}
249
250void FrameSync64_i::PushPayloadData(unsigned char * _payload)
251{
252    // create output array and copy data
253    PortTypes::CharSequence payloadDataOut;
254    payloadDataOut.length(64);
255    for (unsigned int i=0; i<64; i++)
256        payloadDataOut[i] = _payload[i];
257
258    // invoke pushPacket on the port
259    payloadDataPortOut->pushPacket(payloadDataOut);
260}
261
Note: See TracBrowser for help on using the browser.