![]() |
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/DataCollector.hpp> 00030 00031 00032 using namespace wimemac::frame; 00033 00034 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00035 wimemac::frame::DataCollector, 00036 wns::ldk::FunctionalUnit, 00037 "wimemac.frame.DataCollector", 00038 wns::ldk::FUNConfigCreator ); 00039 00040 00041 DataCollector::DataCollector( wns::ldk::fun::FUN* fun, const wns::pyconfig::View& config ) : 00042 wns::ldk::fcf::CompoundCollector( config ), 00043 wns::ldk::CommandTypeSpecifier<wns::ldk::EmptyCommand>(fun), 00044 logger(config.get("logger")), 00045 duration(config.get<wns::simulator::Time>("duration")), 00046 _config(config), 00047 sending(false) 00048 00049 00050 { 00051 MESSAGE_SINGLE(NORMAL, logger, "DataCollector "); 00052 00053 } 00054 00055 void 00056 DataCollector::doOnData( const wns::ldk::CompoundPtr& compound ) 00057 { 00058 assure(mode==CompoundCollector::Sending,"DataCollector: received compound although not in receiving mode!"); 00059 getDeliverer()->getAcceptor( compound )->onData( compound ); 00060 } 00061 00062 bool 00063 DataCollector::doIsAccepting( const wns::ldk::CompoundPtr& ) const 00064 { 00065 MESSAGE_SINGLE(NORMAL, logger, "DataCollector: doIsAccepting? "); 00066 return (CompoundCollector::getMode() == CompoundCollector::Sending); 00067 00068 } 00069 00070 void 00071 DataCollector::doSendData( const wns::ldk::CompoundPtr& compound ) 00072 { 00073 assure(mode==CompoundCollector::Sending, "DataCollector: Got compound from above although not in sending mode!"); 00074 if(!getConnector()->hasAcceptor(compound)){ 00075 MESSAGE_SINGLE(NORMAL, logger, "DataCollector: can't send Data!"); 00076 assure(false, "DataCollector: compound is not accepted from the lower FUs even though in sending mode! A transmission may already be in progress"); 00077 } 00078 else{ 00079 getConnector()->getAcceptor(compound)->sendData(compound); 00080 MESSAGE_SINGLE(NORMAL, logger, "DataCollector: Data sent, waiting for Phy to finish!"); 00081 } 00082 } 00083 00084 00085 void 00086 DataCollector::doStart(int mode) 00087 { 00088 switch (mode) 00089 { 00090 case CompoundCollector::Sending: 00091 00092 MESSAGE_SINGLE(NORMAL, logger, "DataCollector: start: " << duration); 00093 setTimeout(duration); 00094 getReceptor()->wakeup(); 00095 sending = true; 00096 break; 00097 00098 case CompoundCollector::Receiving: 00099 break; 00100 default: 00101 throw wns::Exception("Unknown mode in CompoundCollector"); 00102 } 00103 } 00104 00105 void 00106 DataCollector::onTimeout() 00107 { 00108 00109 MESSAGE_SINGLE(NORMAL, logger, "DataCollector: Data phase is over now! "); 00110 getFrameBuilder()->finishedPhase(this); 00111 sending = false; 00112 CompoundCollector::mode = CompoundCollector::Pausing; 00113 00114 } 00115 00116 00117 void 00118 DataCollector::onFUNCreated() 00119 { 00120 MESSAGE_SINGLE(NORMAL, logger, "DataCollector: created! duration: " << duration << " Mode: " << getMode()); 00121 getFUN()->findFriend<wns::ldk::fcf::FrameBuilder*>("FrameBuilder")->start(); 00122 } 00123 00124 void 00125 DataCollector::doWakeup() 00126 { 00127 if(sending == true) 00128 { 00129 MESSAGE_SINGLE(NORMAL, logger, "DataCollector: Phy finished sending Data!"); 00130 getReceptor()->wakeup(); 00131 } 00132 else 00133 MESSAGE_SINGLE(NORMAL, logger, "DataCollector: doWakeup, but not in sending mode"); 00134 }
1.5.5