CSMA802154.cc

00001 //
00002 // This program is free software: you can redistribute it and/or modify
00003 // it under the terms of the GNU Lesser General Public License as published by
00004 // the Free Software Foundation, either version 3 of the License, or
00005 // (at your option) any later version.
00006 //
00007 // This program is distributed in the hope that it will be useful,
00008 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00009 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010 // GNU Lesser General Public License for more details.
00011 //
00012 // You should have received a copy of the GNU Lesser General Public License
00013 // along with this program.  If not, see http://www.gnu.org/licenses/.
00014 //
00015 
00016 #include "CSMA802154.h"
00017 #include <DeciderResult802154Narrow.h>
00018 #include <PhyToMacControlInfo.h>
00019 #include <MacToNetwControlInfo.h>
00020 
00021 Define_Module(CSMA802154);
00022 
00023 
00024 void CSMA802154::initialize(int stage)
00025 {
00026   csma::initialize(stage);
00027 }
00028 
00029 cPacket *CSMA802154::decapsMsg(MacPkt * macPkt) {
00030 
00031   cPacket * msg = csma::decapsMsg(macPkt);
00032 
00033   // get bit error rate
00034   PhyToMacControlInfo* cinfo = static_cast<PhyToMacControlInfo*> (macPkt->getControlInfo());
00035   const DeciderResult802154Narrow* result = static_cast<const DeciderResult802154Narrow*> (cinfo->getDeciderResult());
00036   double ber = result->getBER();
00037   double rssi = result->getRSSI();
00038 
00039   //get control info attached by base class decapsMsg method
00040   //and set its rssi and ber
00041   assert(dynamic_cast<MacToNetwControlInfo*>(msg->getControlInfo()));
00042   MacToNetwControlInfo* cInfo = static_cast<MacToNetwControlInfo*>(msg->getControlInfo());
00043   cInfo->setBitErrorRate(ber);
00044   cInfo->setRSSI(rssi);
00045 
00046   return msg;
00047 }