![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /****************************************************************************** 00002 * WiMeMac * 00003 * This file is part of openWNS (open Wireless Network Simulator) 00004 * _____________________________________________________________________________ 00005 * 00006 * Copyright (C) 2004-2011 00007 * Chair of Communication Networks (ComNets) 00008 * Kopernikusstr. 5, D-52074 Aachen, Germany 00009 * phone: ++49-241-80-27910, 00010 * fax: ++49-241-80-22242 00011 * email: info@openwns.org 00012 * www: http://www.openwns.org 00013 * _____________________________________________________________________________ 00014 * 00015 * openWNS is free software; you can redistribute it and/or modify it under the 00016 * terms of the GNU Lesser General Public License version 2 as published by the 00017 * Free Software Foundation; 00018 * 00019 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00020 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00021 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00022 * details. 00023 * 00024 * You should have received a copy of the GNU Lesser General Public License 00025 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00026 * 00027 ******************************************************************************/ 00028 00029 #include <WIMEMAC/frame/BeaconCollector.hpp> 00030 00031 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00032 wimemac::frame::BeaconCollector, 00033 wns::ldk::FunctionalUnit, 00034 "wimemac.frame.BeaconCollector", 00035 wns::ldk::FUNConfigCreator ); 00036 00037 using namespace wimemac::frame; 00038 00039 BeaconCollector::BeaconCollector( wns::ldk::fun::FUN* fun, const wns::pyconfig::View& config ) : 00040 wns::ldk::fcf::CompoundCollector( config ), 00041 wns::ldk::CommandTypeSpecifier<wns::ldk::EmptyCommand>(fun), 00042 logger(config.get("logger")), 00043 duration(config.get<wns::simulator::Time>("duration")), 00044 gotWakeup(false), 00045 sending(false), 00046 managerName(config.get<std::string>("managerName")), 00047 BeaconSlot(config.get<int>("BeaconSlot")), 00048 BeaconSlotDuration(config.get<wns::simulator::Time>("BeaconSlotDuration")) 00049 00050 { 00051 00052 00053 } 00054 00055 void 00056 BeaconCollector::doOnData( const wns::ldk::CompoundPtr& compound ) 00057 { 00058 assure(mode==CompoundCollector::Sending,"BeaconCollector: received compound although not in receiving mode!"); 00059 getDeliverer()->getAcceptor( compound )->onData( compound ); 00060 } 00061 00062 bool 00063 BeaconCollector::doIsAccepting( const wns::ldk::CompoundPtr& ) const 00064 { 00065 MESSAGE_SINGLE(NORMAL, logger, "BeaconCollector: BeaconMode: " << CompoundCollector::getMode()); 00066 return (CompoundCollector::getMode() == CompoundCollector::Sending && sending == false); 00067 } 00068 00069 void 00070 BeaconCollector::doSendData( const wns::ldk::CompoundPtr& compound ) 00071 { 00072 assure(mode==CompoundCollector::Sending, "BeaconCollector: Got compound from above although not in sending mode!"); 00073 if(!getConnector()->hasAcceptor(compound)){ 00074 MESSAGE_SINGLE(NORMAL, logger, "BeaconCollector: can't send Beacon!"); 00075 gotWakeup = false; 00076 } 00077 else{ 00078 getConnector()->getAcceptor(compound)->sendData(compound); 00079 sending = true; 00080 MESSAGE_SINGLE(NORMAL, logger, "BeaconCollector: Beacon sent, waiting for Phy to finish!"); 00081 } 00082 } 00083 00084 00085 void 00086 BeaconCollector::doStart(int mode) 00087 { 00088 switch (mode) 00089 { 00090 case CompoundCollector::Sending: 00091 00092 MESSAGE_SINGLE(NORMAL, logger, "BeaconCollector: start: " << duration <<" BeaconSlot " << BeaconSlot); 00093 wns::simulator::getEventScheduler()->scheduleDelay(boost::bind(&BeaconCollector::TimeToTransmit, this), BeaconSlotDuration * BeaconSlot); 00094 00095 setTimeout(duration); 00096 BPStart = wns::simulator::getEventScheduler()->getTime(); 00097 friends.manager->setBPStartTime(BPStart); 00098 00099 break; 00100 case CompoundCollector::Receiving: 00101 00102 break; 00103 default: 00104 throw wns::Exception("Unknown mode in CompoundCollector"); 00105 } 00106 } 00107 00108 void 00109 BeaconCollector::onTimeout() 00110 { 00111 00112 if(sending) 00113 assure(gotWakeup, "Phy Layer is yet not done sending! Check frame config!"); 00114 00115 getFrameBuilder()->finishedPhase(this); 00116 CompoundCollector::mode = CompoundCollector::Pausing; 00117 sending = false; 00118 friends.beaconbuilder->BuildDTPmap(); 00119 MESSAGE_SINGLE(NORMAL, logger, "BeaconCollector: Beacon phase is over now!"); 00120 } 00121 00122 void 00123 BeaconCollector::onFUNCreated() 00124 { 00125 MESSAGE_SINGLE(NORMAL, logger, "BeaconCollector: created! duration: " << duration << " Mode: " << getMode()); 00126 getFUN()->findFriend<wns::ldk::fcf::FrameBuilder*>("FrameBuilder")->start(); 00127 00128 00129 friends.beaconbuilder = 00130 getFUN()->findFriend<wimemac::management::IBeaconBuilderServices*>("BeaconBuilder"); 00131 00132 friends.manager = 00133 getFUN()->findFriend<wimemac::lowerMAC::IManagerServices*>(managerName); 00134 00135 friends.beaconbuilder->SetBPDuration(duration); 00136 } 00137 00138 void 00139 BeaconCollector::doWakeup() 00140 { 00141 if(sending) 00142 { 00143 MESSAGE_SINGLE(NORMAL, logger, "BeaconCollector: Phy finished sending beacon!"); 00144 sending = false; 00145 } 00146 } 00147 00148 void 00149 BeaconCollector::TimeToTransmit() 00150 { 00151 MESSAGE_SINGLE(NORMAL, logger, "BeaconCollector: Time to transmit Beacon!"); 00152 this->getReceptor()->wakeup(); 00153 }
1.5.5