root/experimental/components/FrameAssembler/src/FrameAssembler.cpp @ 3961

Revision 3961, 8.0 KB (checked in by jgaeddert, 6 years ago)

adding phasing pattern to end of packet just for good measure

  • 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 FrameAssembler.
6
7OSSIE FrameAssembler 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 FrameAssembler 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 FrameAssembler; 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 "FrameAssembler.h"
27
28FrameAssembler_i::FrameAssembler_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::complexShort_u("FrameSymbolsOut");
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
42FrameAssembler_i::~FrameAssembler_i(void)
43{   
44    delete dataIn_0;
45    delete dataOut_0;
46}
47
48// Static function for omni thread
49void FrameAssembler_i::Run( void * data )
50{
51    ((FrameAssembler_i*)data)->ProcessData();
52}
53
54CORBA::Object_ptr FrameAssembler_i::getPort( const char* portName ) throw (
55    CORBA::SystemException, CF::PortSupplier::UnknownPort)
56{
57    DEBUG(3, FrameAssembler, "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 FrameAssembler_i::start() throw (CORBA::SystemException,
76    CF::Resource::StartError)
77{
78    DEBUG(3, FrameAssembler, "start() invoked")
79}
80
81void FrameAssembler_i::stop() throw (CORBA::SystemException, CF::Resource::StopError)
82
83    DEBUG(3, FrameAssembler, "stop() invoked")
84}
85
86void FrameAssembler_i::releaseObject() throw (CORBA::SystemException,
87    CF::LifeCycle::ReleaseError)
88{
89    DEBUG(3, FrameAssembler, "releaseObject() invoked")
90   
91    component_running->signal();
92}
93
94void FrameAssembler_i::initialize() throw (CF::LifeCycle::InitializeError,
95    CORBA::SystemException)
96{
97    DEBUG(3, FrameAssembler, "initialize() invoked")
98}
99
100void FrameAssembler_i::configure(const CF::Properties& props)
101throw (CORBA::SystemException,
102    CF::PropertySet::InvalidConfiguration,
103    CF::PropertySet::PartialConfiguration)
104{
105    DEBUG(3, FrameAssembler, "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:690f320c-5bee-4959-b93d-586dc3450aac") == 0) {
113            // Modulation type
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                ConfigureModulationScheme(BPSK);
120            } else if ( strcmp(prop_str, "QPSK") == 0 ) {
121                ConfigureModulationScheme(QPSK);
122            } else if ( strcmp(prop_str, "8PSK") == 0 ) {
123                ConfigureModulationScheme(PSK8);
124            } else if ( strcmp(prop_str, "16QAM") == 0 ) {
125                ConfigureModulationScheme(QAM16);
126            } else {
127                // unknown property
128                std::cerr << "ERROR: FrameAssembler::configure() unknown mod. scheme "
129                          << prop_str << std::endl;
130                throw CF::PropertySet::InvalidConfiguration();
131            }
132            ///\todo catch exception thrown by FrameAssemblerDSP::ConfigureModulationScheme()
133
134        } else if (strcmp(props[i].id, "DCE:25a1df92-7f22-43af-8720-ad37714a66db") == 0) {
135            // Frame size
136            CORBA::UShort simple_temp;
137            props[i].value >>= simple_temp;
138
139            ConfigureFrameSize(simple_temp);
140
141        } else {
142            // unknown property
143            std::cerr << "ERROR: FrameAssembler::configure() unknown property" << std::endl;
144            throw CF::PropertySet::InvalidConfiguration();
145        }
146    }
147
148}
149
150void FrameAssembler_i::ProcessData()
151{
152    DEBUG(3, FrameAssembler, "ProcessData() invoked")
153
154    PortTypes::ShortSequence I_out_0, Q_out_0;
155
156    PortTypes::ShortSequence *I_in_0(NULL), *Q_in_0(NULL);
157    unsigned int N_in(0);
158
159    // Prepare preamble phasing pattern
160    short * I_phasing_pattern = new short[512];
161    short * Q_phasing_pattern = new short[512];
162    PortTypes::ShortSequence I_out_phasing_pattern, Q_out_phasing_pattern;
163    I_out_phasing_pattern.length(512);
164    Q_out_phasing_pattern.length(512);
165
166    AssemblePhasingPattern(I_phasing_pattern, Q_phasing_pattern);
167    for (unsigned int i=0; i<512; i++) {
168        I_out_phasing_pattern[i] = I_phasing_pattern[i];
169        Q_out_phasing_pattern[i] = Q_phasing_pattern[i];
170    }
171    delete [] I_phasing_pattern;
172    delete [] Q_phasing_pattern;
173
174
175    short * I_header = new short[512];
176    short * Q_header = new short[512];
177
178    while( true ) {
179        // Get data from port
180        dataIn_0->getData(I_in_0, Q_in_0);
181
182        // Read input data length
183        N_in = I_in_0->length();
184
185        switch ( operationalMode ) {
186        case ASSEMBLE_PREAMBLE:
187            DEBUG(4, FrameAssembler, "Assembling preamble")
188
189            // push
190            dataOut_0->pushPacket(I_out_phasing_pattern, Q_out_phasing_pattern);
191
192            // do not break; continue to assemble header
193            operationalMode = ASSEMBLE_HEADER;
194
195        case ASSEMBLE_HEADER:
196            DEBUG(4, FrameAssembler, "Assembling header")
197            // copy header
198            I_out_0.length(512);
199            Q_out_0.length(512);
200            AssembleHeader( I_header, Q_header );
201            for (unsigned int i=0; i<512; i++) {
202                I_out_0[i] = I_header[i];
203                Q_out_0[i] = Q_header[i];
204            }
205
206            // push data
207            dataOut_0->pushPacket(I_out_0, Q_out_0);
208
209            // do not break; continue to assemble frame
210            operationalMode = ASSEMBLE_FRAME;
211
212            numFrameSymbolsAssembled = 0;
213
214        case ASSEMBLE_FRAME:
215            DEBUG(4, FrameAssembler, "Assembling frame (s=" << numFrameSymbolsAssembled << ")")
216            // copy data from input buffer to output
217           
218            I_out_0.length(N_in);
219            Q_out_0.length(N_in);
220
221            for (unsigned int i=0; i<N_in; i++) {
222                //
223                I_out_0[i] = (*I_in_0)[i];
224                Q_out_0[i] = (*Q_in_0)[i];
225
226                numFrameSymbolsAssembled++;
227            }
228
229            // empty input buffer; release semaphore
230            dataIn_0->bufferEmptied();
231
232            dataOut_0->pushPacket(I_out_0, Q_out_0);
233
234            if ( numFrameSymbolsAssembled == frameSize ) {
235                operationalMode = ASSEMBLE_EOM_CODE;
236            } else if ( numFrameSymbolsAssembled > frameSize ) {
237                operationalMode = ASSEMBLE_EOM_CODE;
238                std::cout << "WARNING: FrameAssembler pushing too many symbols in frame! "
239                          << std::endl;
240            } else {
241                break;
242            }
243
244        case ASSEMBLE_EOM_CODE:
245            // push phasing pattern
246            ///\todo assemble EOM code
247            dataOut_0->pushPacket(I_out_phasing_pattern, Q_out_phasing_pattern);
248
249            operationalMode = ASSEMBLE_PREAMBLE;
250            break;
251        }
252
253    }
254
255    delete [] I_header;
256    delete [] Q_header;
257}
258
259
Note: See TracBrowser for help on using the browser.