| 1 | /**************************************************************************** |
|---|
| 2 | |
|---|
| 3 | Copyright 2007 Virginia Polytechnic Institute and State University |
|---|
| 4 | |
|---|
| 5 | This file is part of the OSSIE SymbolSyncPoly. |
|---|
| 6 | |
|---|
| 7 | OSSIE SymbolSyncPoly is free software; you can redistribute it and/or modify |
|---|
| 8 | it under the terms of the GNU General Public License as published by |
|---|
| 9 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | (at your option) any later version. |
|---|
| 11 | |
|---|
| 12 | OSSIE SymbolSyncPoly is distributed in the hope that it will be useful, |
|---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | GNU General Public License for more details. |
|---|
| 16 | |
|---|
| 17 | You should have received a copy of the GNU General Public License |
|---|
| 18 | along with OSSIE SymbolSyncPoly; if not, write to the Free Software |
|---|
| 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | |
|---|
| 21 | ****************************************************************************/ |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | #include <string> |
|---|
| 25 | #include <iostream> |
|---|
| 26 | #include "SymbolSyncPoly.h" |
|---|
| 27 | |
|---|
| 28 | SymbolSyncPoly_i::SymbolSyncPoly_i(const char *uuid, omni_condition *condition) : |
|---|
| 29 | Resource_impl(uuid), component_running(condition) |
|---|
| 30 | { |
|---|
| 31 | dataIn_0 = new standardInterfaces_i::complexShort_p("baseband_in"); |
|---|
| 32 | dataOut_0 = new standardInterfaces_i::complexShort_u("symbols_out"); |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | //Create the thread for the writer's processing function |
|---|
| 36 | processing_thread = new omni_thread(Run, (void *) this); |
|---|
| 37 | |
|---|
| 38 | //Start the thread containing the writer's processing function |
|---|
| 39 | processing_thread->start(); |
|---|
| 40 | |
|---|
| 41 | isConfigured_pulseShape = true; |
|---|
| 42 | isConfigured_k = false; |
|---|
| 43 | isConfigured_m = false; |
|---|
| 44 | isConfigured_beta = false; |
|---|
| 45 | isConfigured_Npfb = false; |
|---|
| 46 | |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | SymbolSyncPoly_i::~SymbolSyncPoly_i(void) |
|---|
| 50 | { |
|---|
| 51 | delete dataIn_0; |
|---|
| 52 | delete dataOut_0; |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | // Static function for omni thread |
|---|
| 56 | void SymbolSyncPoly_i::Run( void * data ) |
|---|
| 57 | { |
|---|
| 58 | ((SymbolSyncPoly_i*)data)->ProcessData(); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | CORBA::Object_ptr SymbolSyncPoly_i::getPort( const char* portName ) throw ( |
|---|
| 62 | CORBA::SystemException, CF::PortSupplier::UnknownPort) |
|---|
| 63 | { |
|---|
| 64 | DEBUG(3, SymbolSyncPoly, "getPort() invoked with " << portName) |
|---|
| 65 | |
|---|
| 66 | CORBA::Object_var p; |
|---|
| 67 | |
|---|
| 68 | p = dataIn_0->getPort(portName); |
|---|
| 69 | |
|---|
| 70 | if (!CORBA::is_nil(p)) |
|---|
| 71 | return p._retn(); |
|---|
| 72 | |
|---|
| 73 | p = dataOut_0->getPort(portName); |
|---|
| 74 | |
|---|
| 75 | if (!CORBA::is_nil(p)) |
|---|
| 76 | return p._retn(); |
|---|
| 77 | |
|---|
| 78 | /*exception*/ |
|---|
| 79 | throw CF::PortSupplier::UnknownPort(); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | void SymbolSyncPoly_i::start() throw (CORBA::SystemException, |
|---|
| 83 | CF::Resource::StartError) |
|---|
| 84 | { |
|---|
| 85 | DEBUG(3, SymbolSyncPoly, "start() invoked") |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | void SymbolSyncPoly_i::stop() throw (CORBA::SystemException, CF::Resource::StopError) |
|---|
| 89 | { |
|---|
| 90 | DEBUG(3, SymbolSyncPoly, "stop() invoked") |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | void SymbolSyncPoly_i::releaseObject() throw (CORBA::SystemException, |
|---|
| 94 | CF::LifeCycle::ReleaseError) |
|---|
| 95 | { |
|---|
| 96 | DEBUG(3, SymbolSyncPoly, "releaseObject() invoked") |
|---|
| 97 | |
|---|
| 98 | component_running->signal(); |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | void SymbolSyncPoly_i::initialize() throw (CF::LifeCycle::InitializeError, |
|---|
| 102 | CORBA::SystemException) |
|---|
| 103 | { |
|---|
| 104 | DEBUG(3, SymbolSyncPoly, "initialize() invoked") |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | void SymbolSyncPoly_i::configure(const CF::Properties& props) |
|---|
| 108 | throw (CORBA::SystemException, |
|---|
| 109 | CF::PropertySet::InvalidConfiguration, |
|---|
| 110 | CF::PropertySet::PartialConfiguration) |
|---|
| 111 | { |
|---|
| 112 | DEBUG(3, SymbolSyncPoly, "configure() invoked") |
|---|
| 113 | |
|---|
| 114 | std::cout << "props length : " << props.length() << std::endl; |
|---|
| 115 | |
|---|
| 116 | for (unsigned int i = 0; i <props.length(); i++) { |
|---|
| 117 | std::cout << "Property id : " << props[i].id << std::endl; |
|---|
| 118 | |
|---|
| 119 | if (strcmp(props[i].id, "DCE:41366fe0-e44e-11db-93b3-00123f63025f") == 0) { |
|---|
| 120 | // pulse shape |
|---|
| 121 | //CORBA::String simple_temp; |
|---|
| 122 | //props[i].value >>= simple_temp; |
|---|
| 123 | //simple_0_value = simple_temp; |
|---|
| 124 | } else if (strcmp(props[i].id, "DCE:6911ce74-e44e-11db-be33-00123f63025f") == 0) { |
|---|
| 125 | // k : samples per symbol |
|---|
| 126 | CORBA::UShort simple_temp; |
|---|
| 127 | props[i].value >>= simple_temp; |
|---|
| 128 | _k = simple_temp; |
|---|
| 129 | isConfigured_k = true; |
|---|
| 130 | } else if (strcmp(props[i].id, "DCE:99bf718e-e44e-11db-99e4-00123f63025f") == 0) { |
|---|
| 131 | // m : symbol delay |
|---|
| 132 | CORBA::UShort simple_temp; |
|---|
| 133 | props[i].value >>= simple_temp; |
|---|
| 134 | _m = simple_temp; |
|---|
| 135 | isConfigured_m = true; |
|---|
| 136 | } else if (strcmp(props[i].id, "DCE:afc47b82-e44e-11db-b1f3-00123f63025f") == 0) { |
|---|
| 137 | // beta : excess bandwidth factor |
|---|
| 138 | CORBA::Float simple_temp; |
|---|
| 139 | props[i].value >>= simple_temp; |
|---|
| 140 | _beta = simple_temp; |
|---|
| 141 | isConfigured_beta = true; |
|---|
| 142 | } else if (strcmp(props[i].id, "DCE:bea3b19a-e44e-11db-a3dd-00123f63025f") == 0) { |
|---|
| 143 | // Npfb : number of filters in bank |
|---|
| 144 | CORBA::UShort simple_temp; |
|---|
| 145 | props[i].value >>= simple_temp; |
|---|
| 146 | _Npfb = simple_temp; |
|---|
| 147 | isConfigured_Npfb = true; |
|---|
| 148 | } else { |
|---|
| 149 | // unknown property |
|---|
| 150 | std::cerr << "ERROR: SymbolSyncPoly::configure() unknown property \"" |
|---|
| 151 | << props[i].id << "\"" << std::endl; |
|---|
| 152 | throw CF::PropertySet::InvalidConfiguration(); |
|---|
| 153 | } |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | /// \todo configure filter bank type |
|---|
| 157 | /// |
|---|
| 158 | /// Once all properties have been configured, create the filter bank |
|---|
| 159 | if ( isConfigured_k && |
|---|
| 160 | isConfigured_m && |
|---|
| 161 | isConfigured_beta && |
|---|
| 162 | isConfigured_Npfb ) |
|---|
| 163 | { |
|---|
| 164 | DEBUG(5, SymbolSyncPoly, "configuring filter bank for " << |
|---|
| 165 | "rrcos" << ", k=" << _k << ", m=" << _m << ", beta=" << _beta << ", Npfb=" << Npfb) |
|---|
| 166 | ConfigureFilterBank("rrcos", _k, _m, _beta, _Npfb); |
|---|
| 167 | } |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | void SymbolSyncPoly_i::ProcessData() |
|---|
| 171 | { |
|---|
| 172 | DEBUG(3, SymbolSyncPoly, "ProcessData() invoked") |
|---|
| 173 | |
|---|
| 174 | PortTypes::ShortSequence I_out_0, Q_out_0; |
|---|
| 175 | |
|---|
| 176 | PortTypes::ShortSequence *I_in_0(NULL), *Q_in_0(NULL); |
|---|
| 177 | unsigned int I_in_0_length, Q_in_0_length, N_in(0), N_out(0); |
|---|
| 178 | short * I_in(NULL); |
|---|
| 179 | short * Q_in(NULL); |
|---|
| 180 | short * I_out(NULL); |
|---|
| 181 | short * Q_out(NULL); |
|---|
| 182 | |
|---|
| 183 | while( true ) |
|---|
| 184 | { |
|---|
| 185 | // Get data from port |
|---|
| 186 | dataIn_0->getData(I_in_0, Q_in_0); |
|---|
| 187 | |
|---|
| 188 | // Read input data length |
|---|
| 189 | I_in_0_length = I_in_0->length(); |
|---|
| 190 | Q_in_0_length = Q_in_0->length(); |
|---|
| 191 | |
|---|
| 192 | if ( I_in_0_length != Q_in_0_length ) { |
|---|
| 193 | // Not sure how to handle multiple-length inputs |
|---|
| 194 | std::cerr << "ERROR: SymbolSyncPoly_i::ProcessData()" << std::endl |
|---|
| 195 | << " => Not sure how to handle multiple-length inputs" << std::endl; |
|---|
| 196 | throw 0; |
|---|
| 197 | } else { |
|---|
| 198 | N_in = I_in_0_length; |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | // Configure output data length |
|---|
| 202 | if ( I_out == NULL ) { |
|---|
| 203 | // Memory was never allocated; do so now |
|---|
| 204 | I_out = new short[2*N_in/k]; |
|---|
| 205 | Q_out = new short[2*N_in/k]; |
|---|
| 206 | N_out = 2*N_in/k; |
|---|
| 207 | } else if ( N_out < (2*N_in/k) ) { |
|---|
| 208 | // Too little memory was allocated; renew |
|---|
| 209 | delete [] I_out; |
|---|
| 210 | delete [] Q_out; |
|---|
| 211 | I_out = new short[2*N_in/k]; |
|---|
| 212 | Q_out = new short[2*N_in/k]; |
|---|
| 213 | N_out = 2*N_in/k; |
|---|
| 214 | } else { |
|---|
| 215 | // Memory is ok; do nothing |
|---|
| 216 | } |
|---|
| 217 | |
|---|
| 218 | // Main signal processing algorithm |
|---|
| 219 | SynchronizeAndDecimate( |
|---|
| 220 | I_in, Q_in, N_in, |
|---|
| 221 | I_out, Q_out, N_out); |
|---|
| 222 | |
|---|
| 223 | I_out_0.length(N_out); |
|---|
| 224 | Q_out_0.length(N_out); |
|---|
| 225 | |
|---|
| 226 | /// \todo Initialize I_out_0 and Q_out_0 from array instead |
|---|
| 227 | /// of copying values in loop |
|---|
| 228 | for (unsigned int ii=0; ii<N_out; ii++) { |
|---|
| 229 | I_out_0[ii] = I_out[ii]; |
|---|
| 230 | Q_out_0[ii] = Q_out[ii]; |
|---|
| 231 | } |
|---|
| 232 | |
|---|
| 233 | dataIn_0->bufferEmptied(); |
|---|
| 234 | dataOut_0->pushPacket(I_out_0, Q_out_0); |
|---|
| 235 | } |
|---|
| 236 | |
|---|
| 237 | // Free the memory |
|---|
| 238 | if ( I_out == NULL ) { |
|---|
| 239 | delete [] I_out; |
|---|
| 240 | delete [] Q_out; |
|---|
| 241 | } |
|---|
| 242 | } |
|---|
| 243 | |
|---|
| 244 | |
|---|