root/experimental/components/Packetizer/trunk/Packetizer-metadata/src/Depacketizer.cpp @ 5182

Revision 5182, 7.1 KB (checked in by jgaeddert, 6 years ago)

adding binary_sequence functions for efficient correlator computation

  • Property svn:eol-style set to native
Line 
1/****************************************************************************
2
3Copyright 2006 Virginia Polytechnic Institute and State University
4
5This file is part of the OSSIE Depacketizer.
6
7OSSIE Depacketizer 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 Depacketizer 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 Depacketizer; 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 <fstream>
27#include "Depacketizer.h"
28
29#undef LOGGING
30
31#ifdef LOGGING
32#define LOG_SIZE_MAX 5000
33#endif
34
35#define BIT0 0
36#define BIT1 1
37
38Depacketizer_i::Depacketizer_i(const char *uuid, omni_condition *condition) : Resource_impl(uuid), component_running(condition)
39{
40    dataIn = new standardInterfaces_i::realChar_p("bitsIn");
41    dataOut = new standardInterfaces_i::realChar_u("bitsOut");
42
43    pnSyncCodeThreshold = PN_SYNC_CODE_LENGTH - 13;
44    operationalMode = EXTRACT_PN_SYNC_CODE;
45   
46    //Create the thread for the writer's processing function
47    processing_thread = new omni_thread(run, (void *) this);
48   
49    //Start the thread containing the writer's processing function
50    processing_thread->start();
51
52}
53
54Depacketizer_i::~Depacketizer_i(void)
55{   
56    delete dataIn;
57    delete dataOut;
58}
59
60void Depacketizer_i::run( void * data )
61{
62    ((Depacketizer_i*) data)->run_loop();
63}
64
65CORBA::Object_ptr Depacketizer_i::getPort( const char* portName ) throw (CORBA::SystemException, CF::PortSupplier::UnknownPort)
66{
67    DEBUG(3, Depacketizer, "getPort() invoked with : " << portName)
68   
69    CORBA::Object_var p;
70
71    p = dataIn->getPort(portName);
72
73    if (!CORBA::is_nil(p))
74        return p._retn();
75
76    p = dataOut->getPort(portName);
77
78    if (!CORBA::is_nil(p))
79        return p._retn();
80
81    /*exception*/
82    throw CF::PortSupplier::UnknownPort();
83}
84
85void Depacketizer_i::start() throw (CORBA::SystemException, CF::Resource::StartError)
86{
87    DEBUG(3, Depacketizer, "start() invoked")
88}
89
90void Depacketizer_i::stop() throw (CORBA::SystemException, CF::Resource::StopError)
91
92    DEBUG(3, Depacketizer, "stop() invoked")
93}
94
95void Depacketizer_i::releaseObject() throw (CORBA::SystemException, CF::LifeCycle::ReleaseError)
96{
97    DEBUG(3, Depacketizer, "releaseObject() invoked")
98   
99    component_running->signal();
100}
101
102void Depacketizer_i::initialize() throw (CF::LifeCycle::InitializeError, CORBA::SystemException)
103{
104    DEBUG(3, Depacketizer, "initialize() invoked")
105}
106
107void Depacketizer_i::configure(const CF::Properties& props) throw (CORBA::SystemException, CF::PropertySet::InvalidConfiguration, CF::PropertySet::PartialConfiguration)
108{
109    DEBUG(3, Depacketizer, "configure() invoked")
110   
111    DEBUG(3, Depacketizer, "props length : " << props.length())
112}
113
114
115void Depacketizer_i::run_loop()
116{
117    DEBUG(3, Depacketizer, "run_loop() thread started")
118
119#if 0
120
121#ifdef LOGGING
122    std::ofstream output_bits_log;
123    output_bits_log.open("output_bits_log.dat");
124    unsigned long log_size_counter(0);
125#endif
126
127    PortTypes::CharSequence data_block_out;
128    data_block_out.length( DATA_BLOCK_LENGTH );
129   
130    PortTypes::CharSequence *bits_in(NULL);
131   
132    unsigned int N;  // CORBA input block length
133    unsigned int i;  // counter
134
135    while( true ) {
136
137        // Read input from provides port
138        dataIn->getData(bits_in, metadata);
139        N = bits_in->length();
140        DEBUG(7, Depacketizer, "got " << N << " samples")
141           
142#ifdef LOGGING
143        for (i=0; i<N; i++) {
144            if (log_size_counter < LOG_SIZE_MAX )
145                output_bits_log << (int) (*bits_in)[i] << " ";
146            log_size_counter++;
147        }
148#endif
149
150        for (i=0; i<N; i++) {
151
152            switch ( operationalMode ) {
153            case EXTRACT_PN_SYNC_CODE:
154                //
155                inputBuffer.Push( (*bits_in)[i] );
156                rxy = CorrelateSequence( pnSyncCode, PN_SYNC_CODE_LENGTH );
157                if ( abs(rxy) > pnSyncCodeThreshold ) {
158                    invertBits = ( rxy < 0 ) ? true : false;
159                    DEBUG(5, Depacketizer, "SYNC CODE FOUND, inversion: " << invertBits)
160                    DEBUG(5, Depacketizer, "  sync rxy = " << rxy)
161                    operationalMode = EXTRACT_CONTROL_CODES;
162                    inputBuffer.Release();
163                }
164                break;
165            case EXTRACT_CONTROL_CODES:
166                //
167                inputBuffer.Push( (*bits_in)[i] );
168                numBitsExtracted++;
169
170                if ( numBitsExtracted == PN_CONTROL_CODE_LENGTH ) {
171                    DEBUG(5, Depacketizer, "Extracting control code " << numControlCodesExtracted)
172                    rxy = CorrelateSequence( pnCtrlCode, PN_CONTROL_CODE_LENGTH );
173                    controlSequence[numControlCodesExtracted] = invertBits ? -rxy : rxy;
174                    DEBUG(5, Depacketizer, "  rxy = " << controlSequence[numControlCodesExtracted])
175                    numControlCodesExtracted++;
176                    numBitsExtracted = 0;
177                    inputBuffer.Release();
178
179                    if ( numControlCodesExtracted == NUM_CONTROL_CODES ) {
180                        DEBUG(5, Depacketizer, "CONTROL CODES EXTRACTED");
181                        DecodeControlSequence();
182                        DEBUG(5, Depacketizer, "Packet ID: " << controlOutput)
183
184                        // Set mode to extract data block
185                        numBitsExtracted = 0;
186                        inputBuffer.Release();
187                        operationalMode = EXTRACT_DATA_BLOCK;
188                    }
189                }
190                break;
191            case EXTRACT_DATA_BLOCK:
192                //
193                data_block_out[numBitsExtracted++] = invertBits ? 1-(*bits_in)[i] : (*bits_in)[i];
194
195                if ( numBitsExtracted == DATA_BLOCK_LENGTH ) {
196                    DEBUG(1, Depacketizer, "DATA BLOCK EXTRACTED!");
197                   
198                    DEBUG(1, Depacketizer, "pushing " << data_block_out.length() << " data samples")
199                    metadata->packet_id = (unsigned int) controlOutput;
200                    dataOut->pushPacket( data_block_out, *metadata );
201
202                    // Reset counter variables
203                    numControlCodesExtracted = 0;
204                    numBitsExtracted = 0;
205                    operationalMode = EXTRACT_PN_SYNC_CODE;
206                    for (unsigned int j=0; j<PN_SYNC_CODE_LENGTH; j++)
207                        inputBuffer.Push( 0 );
208                }
209                break;
210            }
211        }
212
213        // Release input buffer
214        dataIn->bufferEmptied();
215
216
217    }
218    DEBUG(3, Depacketizer, "run_loop() has ended")
219#ifdef LOGGING
220    output_bits_log.close();
221#endif
222
223#endif // 0
224}
225
226   
Note: See TracBrowser for help on using the browser.