/**************************************************************************** Copyright 2008 Virginia Polytechnic Institute and State University This file is part of the OSSIE DataStreamerSink. OSSIE DataStreamerSink is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. OSSIE DataStreamerSink is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OSSIE DataStreamerSink; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ****************************************************************************/ #include "DataStreamerSink.h" DataStreamerSink_i::DataStreamerSink_i(const char *uuid, omni_condition *condition) : Resource_impl(uuid), component_running(condition) { samplesOut = new standardInterfaces_i::complexShort_u("samples_out"); dataIn = new standardInterfaces_i::complexShort_p("data_in"); //Create the thread for the writer's processing function processing_thread = new omni_thread(Run, (void *) this); //Start the thread containing the writer's processing function processing_thread->start(); } DataStreamerSink_i::~DataStreamerSink_i(void) { delete samplesOut; delete dataIn; } // Static function for omni thread void DataStreamerSink_i::Run( void * data ) { ((DataStreamerSink_i*)data)->ProcessData(); } CORBA::Object_ptr DataStreamerSink_i::getPort( const char* portName ) throw ( CORBA::SystemException, CF::PortSupplier::UnknownPort) { DEBUG(3, DataStreamerSink, "getPort() invoked with " << portName) CORBA::Object_var p; p = samplesOut->getPort(portName); if (!CORBA::is_nil(p)) return p._retn(); p = dataIn->getPort(portName); if (!CORBA::is_nil(p)) return p._retn(); /*exception*/ throw CF::PortSupplier::UnknownPort(); } void DataStreamerSink_i::start() throw (CORBA::SystemException, CF::Resource::StartError) { DEBUG(3, DataStreamerSink, "start() invoked") } void DataStreamerSink_i::stop() throw (CORBA::SystemException, CF::Resource::StopError) { DEBUG(3, DataStreamerSink, "stop() invoked") } void DataStreamerSink_i::releaseObject() throw (CORBA::SystemException, CF::LifeCycle::ReleaseError) { DEBUG(3, DataStreamerSink, "releaseObject() invoked") component_running->signal(); } void DataStreamerSink_i::initialize() throw (CF::LifeCycle::InitializeError, CORBA::SystemException) { DEBUG(3, DataStreamerSink, "initialize() invoked") } void DataStreamerSink_i::configure(const CF::Properties& props) throw (CORBA::SystemException, CF::PropertySet::InvalidConfiguration, CF::PropertySet::PartialConfiguration) { DEBUG(3, DataStreamerSink, "configure() invoked") std::cout << "props length : " << props.length() << std::endl; for (unsigned int i = 0; i getData(I_in, Q_in); I_in_length = I_in->length(); Q_in_length = Q_in->length(); // define length of output I_out.length(frame_length); Q_out.length(frame_length); printf("DataStreamerSink got %u samples\n", I_in_length); for (i=0; i 0) binary_sequence_push(frame_header_buffer, 1); else binary_sequence_push(frame_header_buffer, 0); // correlate with header pn sequence rxy = binary_sequence_correlate( frame_header_buffer, frame_sync_code_sequence); if (abs(rxy) > frame_sync_code_threshold) { printf("HEADER FOUND! rxy=%f\n", (float)rxy / (float)(frame_sync_code.n)); printf("mf_i: %f, mf_q: %f\n", mf_i, mf_q); op_mode = EXTRACT_HEADER; num_symbols_extracted = 0; num_bit_errors = 0; // reset data source generator msequence_reset(&data_source); if (rxy < 0) { printf(" >> INVERTED HEADER\n"); // todo: adjust costas_loop_nco by pi } } break; case EXTRACT_HEADER: op_mode = EXTRACT_FRAME; case EXTRACT_FRAME: I_out[num_symbols_extracted] = (short) (mf_i * 10000); Q_out[num_symbols_extracted] = (short) (mf_q * 10000); // demodulate and count bit errors demodulate(demodulator, mf_i, mf_q, &s); s_gen = msequence_generate_symbol(&data_source, demodulator->m); num_bit_errors += count_bit_errors(s, s_gen); num_symbols_extracted++; if (num_symbols_extracted==frame_length) { printf(" FRAME EXTRACTED\n"); op_mode = SEEK_HEADER; samplesOut->pushPacket(I_out, Q_out); // print bit errors: printf(" bit errors: %u / %u\n\n", num_bit_errors, frame_length*(demodulator->m)); } break; default: printf("unexpected operational mode\n"); throw (0); } //------------------------------------------------ // Phase recovery (demodulation) //------------------------------------------------ //------------------------------------------------ // Frame header detect, extract //------------------------------------------------ //------------------------------------------------ // Count bit errors //------------------------------------------------ } } dataIn->bufferEmptied(); } // free up the memory free_binary_sequence(frame_sync_code_sequence); free_binary_sequence(frame_header_buffer); free_polyphase_filterbank(mf); free_polyphase_filterbank(dmf); }