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

Revision 10685, 8.0 KB (checked in by jgaeddert, 2 years ago)

FrameSync?64: adding squelch_enabled and squelch_threshold properties

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        std::cout << "Property id : " << props[i].id << std::endl;
163
164        if (strcmp(props[i].id, "DCE:0a3620cc-0aa1-11df-baab-001aa089d644") == 0) {
165            // verbose
166            props[i].value >>= verbose;
167        } else if (strcmp(props[i].id, "DCE:5b2083b8-fac1-4ed9-becf-80ca7ab08329") == 0) {
168            // squelch_enabled
169            CORBA::Boolean simple_tmp;
170            props[i].value >>= simple_tmp;
171            fsprops.squelch_enabled = (simple_tmp == false) ? 0 : 1;
172            framesync64_setprops(fs,&fsprops);
173        } else if (strcmp(props[i].id, "DCE:f6729dae-185f-4438-9202-6adaff95e20e") == 0) {
174            // squelch_threshold
175            props[i].value >>= fsprops.squelch_threshold;
176            framesync64_setprops(fs,&fsprops);
177        } else {
178            fprintf(stderr,"error: FrameSync64::configure(), invalid property\n");
179            throw (0);
180        }
181    }
182}
183
184void FrameSync64_i::ProcessData()
185{
186    DEBUG(3, FrameSync64, "ProcessData() invoked")
187
188    PortTypes::FloatSequence *I_in(NULL), *Q_in(NULL);
189    CORBA::UShort I_in_length, Q_in_length;
190
191    unsigned int i;
192    std::complex<float> x;
193
194    while(continue_processing()) {
195        frameDataPortIn->getData(I_in, Q_in);
196
197        I_in_length = I_in->length();
198        Q_in_length = Q_in->length();
199
200        // operate one sample at a time
201        for (i=0; i<I_in_length; i++) {
202            // read separate I/Q streams and push into std::complex<float> type
203            x.real() = (*I_in)[i];
204            x.imag() = (*Q_in)[i];
205
206            // execute synchronizer on sample (callback will be invoked once
207            // frame has been received and decoded)
208            framesync64_execute(fs,&x,1);
209        }
210
211        // free input buffer
212        frameDataPortIn->bufferEmptied();
213    }
214
215    printf("************* destroying frame sync 64 object...\n");
216    framesync64_destroy(fs);
217}
218
219bool FrameSync64_i::continue_processing()
220{
221    omni_mutex_lock l(processing_mutex);
222    return thread_started;
223}
224
225static int callback(unsigned char * _header,  int _header_valid,
226                    unsigned char * _payload, int _payload_valid,
227                    framesyncstats_s _stats,
228                    void * _userdata)
229{
230    // type-cast
231    FrameSync64_i * fs_i = (FrameSync64_i*)_userdata;
232
233    if (fs_i->verbose) {
234        printf("callback invoked\n");
235
236        printf("  header crc          : %s\n", _header_valid ?  "pass" : "FAIL");
237        printf("  payload crc         : %s\n", _payload_valid ? "pass" : "FAIL");
238    }
239
240    if (_header_valid && _payload_valid) {
241        fs_i->PushHeaderData(_header);
242        fs_i->PushPayloadData(_payload);
243    }
244
245    return 0;
246}
247
248void FrameSync64_i::PushHeaderData(unsigned char * _header)
249{
250    // create output array and copy data
251    PortTypes::CharSequence headerDataOut;
252    headerDataOut.length(24);
253    for (unsigned int i=0; i<24; i++)
254        headerDataOut[i] = _header[i];
255
256    // invoke pushPacket on the port
257    headerDataPortOut->pushPacket(headerDataOut);
258}
259
260void FrameSync64_i::PushPayloadData(unsigned char * _payload)
261{
262    // create output array and copy data
263    PortTypes::CharSequence payloadDataOut;
264    payloadDataOut.length(64);
265    for (unsigned int i=0; i<64; i++)
266        payloadDataOut[i] = _payload[i];
267
268    // invoke pushPacket on the port
269    payloadDataPortOut->pushPacket(payloadDataOut);
270}
271
Note: See TracBrowser for help on using the browser.