User Manual, Developers Guide and API Documentation

SpaceTimeSectorizationRegistryProxy.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of openWNS (open Wireless Network Simulator)
00003  * _____________________________________________________________________________
00004  *
00005  * Copyright (C) 2004-2009
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 5, D-52074 Aachen, Germany
00008  * email: info@openwns.org
00009  * www: http://www.openwns.org
00010  * _____________________________________________________________________________
00011  *
00012  * openWNS is free software; you can redistribute it and/or modify it under the
00013  * terms of the GNU Lesser General Public License version 2 as published by the
00014  * Free Software Foundation;
00015  *
00016  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00017  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00018  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00019  * details.
00020  *
00021  * You should have received a copy of the GNU Lesser General Public License
00022  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00023  *
00024  ******************************************************************************/
00025 
00026 
00027 #include <WIMAC/scheduler/SpaceTimeSectorizationRegistryProxy.hpp>
00028 #include <WIMAC/scheduler/RegistryProxyWiMAC.hpp>
00029 
00030 #include <WIMAC/PhyUser.hpp>
00031 
00032 #include <cmath>
00033 
00034 using namespace wimac;
00035 using namespace wimac::scheduler;
00036 
00037 STATIC_FACTORY_REGISTER_WITH_CREATOR(
00038     SpaceTimeSectorizationRegistryProxy,
00039     wns::scheduler::RegistryProxyInterface,
00040     "SpaceTimeSectorizationRegistryProxy",
00041     wns::ldk::FUNConfigCreator);
00042 
00043 SpaceTimeSectorizationRegistryProxy::SpaceTimeSectorizationRegistryProxy(wns::ldk::fun::FUN* fun, const wns::pyconfig::View& pyConfig)
00044     : RegistryProxyWiMAC(fun, pyConfig),
00045       ofdmaProvider(NULL),
00046       logger(pyConfig.get("logger")),
00047       numberOfSectors(pyConfig.get<int>("numberOfSectors")),
00048       numberOfSubsectors(pyConfig.get<int>("numberOfSubsectors")),
00049       mutualAngleOfSubsectors(-1)
00050     //mutualAngleBetweenSubsectors(pyConfig.get<double>("angelBetweenSubsectors"))
00051 {
00052 
00053     assure(numberOfSectors >= 1,"invalid value of numberOfSectors, must be  >= 1");
00054     assure(numberOfSubsectors >= 1,"invalid value of numberOfSubsectors, must be  >= 1");
00055     //assure(angelBetweenSubsectors <= 2 * M_PI , "angelBetweenSubsectors exceeded pi");
00056 
00057 }
00058 
00059 wns::scheduler::UserSet
00060 SpaceTimeSectorizationRegistryProxy::filterReachable( wns::scheduler::UserSet users )
00061 {
00062     wns::scheduler::UserSet filteredUsers;
00063     filteredUsers.clear();
00064 
00065     wns::simulator::Time frameDuration = frameBuilder->getFrameDuration();
00066     wns::simulator::Time currentTime = wns::simulator::getEventScheduler()->getTime();
00067 
00068     //A 'group' corresponds to SSs residing in the same sector.
00069     //example: if 'numberOfSectors' equals 2, 'group' can be {0, 1}
00070     //with corresponding DoA {0...179, 180...359}
00071     int group;
00072     group = static_cast<int>(std::floor(currentTime / frameDuration)) % numberOfSectors;
00073 
00074     //MESSAGE_BEGIN(NORMAL, logger, m, "filterReachable ");
00075     //m << "Getting DoA estimates for the following users (current time: " << currentTime
00076     //  << " , frame: " << int(currentTime / frameDuration) << ", Group " << group << "): \n";
00077     //MESSAGE_END();
00078 
00079     for (wns::scheduler::UserSet::const_iterator iter = users.begin(); iter != users.end(); ++iter)
00080     {
00081         wns::scheduler::UserID user = *iter;
00082 
00083         double doa = ofdmaProvider->estimateDoA(user.getNode());
00084         if (doa < 0.0)
00085         {
00086             doa += 2.0 * M_PI;
00087         }
00088         assure(doa >= 0.0, "Invalid DoA");
00089         assure(doa <= 2.0 * M_PI, "Invalid DoA");
00090 
00091         MESSAGE_BEGIN(NORMAL, logger, m, "filterReachable at ");
00092         m << getNameForUser(getMyUserID());
00093         m << " - User " << getNameForUser(user) << " @ "
00094           << doa * 180.0 / M_PI << " degrees\n";
00095         MESSAGE_END();
00096 
00097         if( isUserinActiveGroup(doa, group) )
00098         {
00099             MESSAGE_BEGIN(NORMAL, logger, m, "filterReachable at ");
00100             m << getNameForUser(getMyUserID()) << " - User belonging to group" << group <<": " << getNameForUser(user) << "\n";
00101             MESSAGE_END();
00102 
00103             filteredUsers.insert(user);
00104         }
00105     }
00106 
00107     return filteredUsers;
00108 }
00109 
00110 bool
00111 SpaceTimeSectorizationRegistryProxy::isUserinActiveGroup(double doa, int group) const
00112 {
00113     bool ret = false;
00114     if(numberOfSectors == 1)
00115     {
00116         ret = true;
00117     }
00118     else if ((numberOfSectors > 1) && (numberOfSubsectors == 1))
00119     {
00120         double minAngleOfSector = (2.0 * M_PI / numberOfSectors) * group;
00121         assure(minAngleOfSector <= (2.0 * M_PI), "lower sector edge exceeded 2 pi");
00122 
00123         const double sectorWidth = (2.0 * M_PI / numberOfSectors);
00124         assure((minAngleOfSector + sectorWidth) <= (2.0 * M_PI), "upper sector edge exceeded 2 pi");
00125 
00126         if((doa >= minAngleOfSector) && (doa < minAngleOfSector + sectorWidth))
00127         {
00128             ret = true;
00129         }
00130     }
00131     else if ((numberOfSectors > 1) && (numberOfSubsectors > 1))
00132     {
00133         double subsectorWidth = (2.0 * M_PI / (numberOfSectors * numberOfSubsectors));
00134         double minAngleOfSector = subsectorWidth * group;
00135         double angleBetweenSectors = subsectorWidth * numberOfSectors;
00136 
00137         assure(minAngleOfSector <= (2.0 * M_PI), "lower sector edge exceeds 2 pi");
00138         assure(minAngleOfSector + subsectorWidth <= (2.0 * M_PI), "upper sector edge exceeds 2 pi");
00139         assure(angleBetweenSectors <= (2.0 * M_PI), "angle between sectors exceeds 2 pi");
00140 
00141         double subsectorBegin = 0.0;
00142         double subsectorEnd = 0.0;
00143         for(int i = 0; i < numberOfSubsectors; i++)
00144         {
00145             subsectorBegin = minAngleOfSector + (i*angleBetweenSectors);
00146             subsectorEnd = subsectorBegin + subsectorWidth;
00147             if((doa >= subsectorBegin) && (doa < subsectorEnd))
00148             {
00149                 ret = true;
00150             }
00151         }
00152     }
00153     return ret;
00154 }
00155 
00156 void
00157 SpaceTimeSectorizationRegistryProxy::setFUN(const wns::ldk::fun::FUN* _fun) 
00158 {
00159     fun = const_cast<wns::ldk::fun::FUN*>(_fun);
00160     assure(fun, "SpaceTimeSectorizationRegistryProxy needs a FUN");
00161 
00162     LOG_INFO("SpaceTimeSectorizationRegistryProxy::setFUN called in station ", fun->getName(), " ");
00163 
00164     wimac::PhyUser* phyUser = fun->findFriend<wimac::PhyUser*>("phyUser");
00165     assure(phyUser, "Could not get PhyUser");
00166 
00167     ofdmaProvider = phyUser->getDataTransmissionService();
00168     assure(ofdmaProvider, "Could not get DataTransmissionService");
00169 
00170     frameBuilder = fun->findFriend<wns::ldk::fcf::FrameBuilder*>("frameBuilder");
00171 
00172 
00173     // call the super class function
00174     RegistryProxyWiMAC::setFUN(fun);
00175 }
00176 
00177 

Generated on Fri May 25 03:32:15 2012 for openWNS by  doxygen 1.5.5