![]() |
User Manual, Developers Guide and API Documentation |
![]() |
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 * phone: ++49-241-80-27910, 00009 * fax: ++49-241-80-22242 00010 * email: info@openwns.org 00011 * www: http://www.openwns.org 00012 * _____________________________________________________________________________ 00013 * 00014 * openWNS is free software; you can redistribute it and/or modify it under the 00015 * terms of the GNU Lesser General Public License version 2 as published by the 00016 * Free Software Foundation; 00017 * 00018 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00019 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00020 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00021 * details. 00022 * 00023 * You should have received a copy of the GNU Lesser General Public License 00024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00025 * 00026 ******************************************************************************/ 00027 00028 #include <COPPER/Receiver.hpp> 00029 #include <COPPER/Wire.hpp> 00030 #include <COPPER/Transmission.hpp> 00031 #include <WNS/events/MemberFunction.hpp> 00032 #include <string> 00033 00034 using namespace copper; 00035 00036 Receiver::Receiver(const wns::pyconfig::View& _pyco, WireInterface* _wire) : 00037 macAddress(), 00038 wire(_wire), 00039 berDist(NULL), 00040 sensingTime(_pyco.get<simTimeType>("sensingTime")), 00041 logger(_pyco.get("logger")) 00042 { 00043 wns::pyconfig::View distConfig = _pyco.get("ber"); 00044 wns::distribution::DistributionCreator* dc = 00045 wns::distribution::DistributionFactory::creator(distConfig.get<std::string>("__plugin__")); 00046 this->berDist = dc->create(distConfig); 00047 } 00048 00049 Receiver::~Receiver() 00050 { 00051 } 00052 00053 bool 00054 Receiver::onData(const UnicastTransmissionPtr& transmission) 00055 { 00056 if (this->macAddress == transmission->target) 00057 { 00058 double ber = (*berDist)(); 00059 MESSAGE_SINGLE(NORMAL, this->logger, "Received unicast data with BER: " << ber); 00060 this->wns::Subject<Handler>::forEachObserver( 00061 OnData(transmission->pdu, ber, transmission->collision)); 00062 return true; 00063 } 00064 else 00065 { 00066 return false; 00067 } 00068 } 00069 00070 bool 00071 Receiver::onData(const BroadcastTransmissionPtr& transmission) 00072 { 00073 double ber = (*berDist)(); 00074 MESSAGE_SINGLE(NORMAL, this->logger, "Received broadcast data with BER: " << ber); 00075 this->wns::Subject<Handler>::forEachObserver( 00076 OnData(transmission->pdu, ber, transmission->collision)); 00077 return true; 00078 } 00079 00080 void 00081 Receiver::onCopperFree() 00082 { 00083 this->wns::Subject<CarrierSensing>::forEachObserver( 00084 wns::events::DelayedMemberFunction<CarrierSensing>( 00085 &CarrierSensing::onCarrierIdle, 00086 this->sensingTime)); 00087 } 00088 00089 void 00090 Receiver::onCopperBusy() 00091 { 00092 this->wns::Subject<CarrierSensing>::forEachObserver( 00093 wns::events::DelayedMemberFunction<CarrierSensing>( 00094 &CarrierSensing::onCarrierBusy, 00095 this->sensingTime)); 00096 } 00097 00098 void 00099 Receiver::onCollision() 00100 { 00101 this->wns::Subject<CarrierSensing>::forEachObserver( 00102 wns::events::DelayedMemberFunction<CarrierSensing>( 00103 &CarrierSensing::onCollision, 00104 this->sensingTime)); 00105 } 00106 00107 void 00108 Receiver::setDLLUnicastAddress(const wns::service::dll::UnicastAddress& _macAddress) 00109 { 00110 assure(this->macAddress.isValid() == false, "MAC address may only be set once!"); 00111 assure(_macAddress.isValid() == true, "Provided invalid MAC address!"); 00112 00113 this->macAddress = _macAddress; 00114 this->wire->addReceiver(this, this->macAddress); 00115 } 00116 00117
1.5.5