rect_spectral_mask.cc

00001 /*
00002  * Copyright (c) 2007 Regents of the SIGNET lab, University of Padova.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the University of Padova (SIGNET lab) nor the 
00014  *    names of its contributors may be used to endorse or promote products 
00015  *    derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00018  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
00019  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
00020  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
00021  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00022  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00023  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00024  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00025  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
00026  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00027  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include"rect_spectral_mask.h"
00031 
00032 #include<stdlib.h>
00033 #include <assert.h>
00034 #include<algorithm>
00035 
00036 static class RectSpectralMaskClass : public TclClass {
00037 public:
00038   RectSpectralMaskClass() : TclClass("MSpectralMask/Rect") {}
00039   TclObject* create(int, const char*const*) { return (new RectSpectralMask);  }
00040 } class_Rect_Spectral_Mask;
00041 
00042 
00043 
00044 RectSpectralMask::RectSpectralMask()
00045   : freq_(2.437e3),
00046     bandwidth_(22e6),
00047     c_(3e8)
00048 {
00049 
00050 }
00051 
00052 
00053 double RectSpectralMask::getFreq() 
00054 {
00055   return freq_;
00056 }
00057 
00058 void RectSpectralMask::setFreq(double f)
00059 {
00060   freq_ = f;
00061 }
00062 
00063 double RectSpectralMask::getPropagationSpeed()
00064 {
00065   return c_;
00066 }
00067 
00068 void RectSpectralMask::setPropagationSpeed(double s)
00069 {
00070   c_ = s;
00071 }
00072 
00073 double RectSpectralMask::getLambda() 
00074 {
00075   return (c_ / freq_);
00076 }
00077 
00078 double RectSpectralMask::getBandwidth() 
00079 {
00080   return bandwidth_;
00081 }
00082 
00083 void RectSpectralMask::setBandwidth(double b)
00084 {
00085   bandwidth_ = b;
00086 }
00087 
00088 
00089 
00090 int RectSpectralMask::command(int argc, const char*const* argv)
00091 {
00092   //printf("MPhy::command -- %s (%d)\n", argv[1], argc);
00093   Tcl& tcl = Tcl::instance();
00094 
00095   if(argc == 2)
00096     {
00097       if(strcasecmp(argv[1], "getFreq")==0)
00098         {
00099           tcl.resultf("%f",getFreq());
00100           return TCL_OK;
00101         }
00102 
00103       if(strcasecmp(argv[1], "getPropagationSpeed")==0)
00104         {
00105           tcl.resultf("%f",getPropagationSpeed());
00106           return TCL_OK;
00107         }
00108 
00109       if(strcasecmp(argv[1], "getLambda")==0)
00110         {
00111           tcl.resultf("%f",getLambda());
00112           return TCL_OK;
00113         }
00114 
00115       if(strcasecmp(argv[1], "getBandwidth")==0)
00116         {
00117           tcl.resultf("%f",getBandwidth());
00118           return TCL_OK;
00119         }
00120 
00121     }
00122   if(argc == 3)
00123     {
00124       if(strcasecmp(argv[1], "setFreq")==0)
00125         {
00126           setFreq(atof(argv[2]));
00127           return TCL_OK;
00128         }
00129 
00130       if(strcasecmp(argv[1], "setPropagationSpeed")==0)
00131         {
00132           setPropagationSpeed(atof(argv[2]));
00133           return TCL_OK;
00134         }
00135 
00136       if(strcasecmp(argv[1], "setBandwidth")==0)
00137         {         
00138           setBandwidth(atof(argv[2]));
00139           return TCL_OK;
00140         }
00141 
00142     }
00143 }
00144 
00145 
00146 double RectSpectralMask::getOverlap(MSpectralMask* msm, Packet*)
00147 {
00148   // we perform a dynamic cast so we can check if the object is of the correct type
00149   RectSpectralMask* tbm = dynamic_cast<RectSpectralMask *>(msm);
00150   assert(tbm);
00151 
00152   double hbw = bandwidth_/2;
00153   double hbw2 = (tbm->getBandwidth())/2;
00154 
00155   double overlap = std::min(tbm->getFreq() + hbw2, freq_ + hbw) - std::max(tbm->getFreq() - hbw2, freq_ - hbw);
00156   
00157   if (overlap > 0)
00158     return (overlap/bandwidth_);
00159   else
00160     return 0;
00161 
00162 }

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