channel-manager.cc

Go to the documentation of this file.
00001 /* -*-  Mode:C++ -*- */
00002 /*
00003  * Copyright (c) 2007 Regents of the SIGNET lab, University of Padova.
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. Neither the name of the University of Padova (SIGNET lab) nor the 
00015  *    names of its contributors may be used to endorse or promote products 
00016  *    derived from this software without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00019  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
00020  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
00021  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
00022  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00023  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00024  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00025  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00026  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
00027  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00028  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  */
00030 
00031 
00044 #include"channel-manager.h"
00045 #include<assert.h>
00046 #include<iostream>
00047 
00048 
00049 
00050 ChannelManager::ChannelManager()
00051 {
00052   bind("startFreq_", &startFreq);
00053   bind("endFreq_", &endFreq);
00054 }
00055 
00056 ChannelManager::~ChannelManager()
00057 {
00058 }
00059 
00060 
00061 static class ChannelManagerClass : public TclClass {
00062 public:
00063   ChannelManagerClass() : TclClass("ChannelManager") {}
00064   TclObject* create(int, const char*const*) { return (new ChannelManager);  }
00065 } class_ChannelManager;
00066 
00067 
00068 
00069 
00070 void ChannelManager::addChannel(MSpectralMask* sm)
00071 {
00072   chlist.push_back(sm);
00073   reallocateChannels();
00074 }
00075 
00076 
00077 
00078 void ChannelManager::reallocateChannels()
00079 {
00080   int numchs = chlist.size();
00081   double totbw = endFreq - startFreq; 
00082   assert(totbw>0);
00083   assert(numchs>0);
00084   double chbw = totbw / numchs;
00085 
00086   std::list<MSpectralMask*>::iterator iter = chlist.begin();
00087 
00088   // carrier frequency 
00089   double fc = startFreq + chbw/2;
00090 
00091   int chid = 0;
00092 
00093   while (iter != chlist.end())
00094     {
00095       MSpectralMask* sm = *iter;
00096       sm->setFreq(fc);
00097       sm->setBandwidth(chbw);
00098       fc += chbw;
00099       iter++;      
00100     }
00101 }
00102 
00103 int ChannelManager::command(int argc, const char*const* argv)
00104 { 
00105   Tcl& tcl = Tcl::instance();
00106 
00107   if(argc == 2)
00108     {
00109       if(strcasecmp(argv[1], "print")==0)
00110         {
00111           printChannels();
00112           return TCL_OK;
00113         }
00114     }
00115   
00116   if(argc == 3)
00117     {
00118       if(strcasecmp(argv[1], "addChannel")==0)
00119         {        
00120           MSpectralMask* msm = dynamic_cast<MSpectralMask*>(TclObject::lookup(argv[2]));
00121           if (!msm)
00122             return TCL_ERROR;
00123           addChannel(msm);
00124           return TCL_OK;
00125         }
00126     }
00127 
00128   return TclObject::command(argc, argv); 
00129 }
00130 
00131 
00132 void ChannelManager::printChannels()
00133 {
00134   int chid = 0;
00135   std::list<MSpectralMask*>::iterator iter = chlist.begin() ;
00136   while (iter != chlist.end())
00137     {
00138       chid++;
00139       std::cout << " Channel " << chid
00140                 << ":  freq " <<  (*iter)->getFreq()
00141                 << "   bw "   <<  (*iter)->getBandwidth()
00142                 << std::endl;
00143       iter++;      
00144     }
00145 }

Generated on Wed Nov 26 15:47:28 2008 for NS-MIRACLE library by  doxygen 1.5.2