|
INET Framework for OMNeT++/OMNEST
|
00001 /*************************************************************************** 00002 * file: BasicDecider.cc 00003 * 00004 * author: Marc Loebbers 00005 * 00006 * copyright: (C) 2004 Telecommunication Networks Group (TKN) at 00007 * Technische Universitaet Berlin, Germany. 00008 * 00009 * This program is free software; you can redistribute it 00010 * and/or modify it under the terms of the GNU General Public 00011 * License as published by the Free Software Foundation; either 00012 * version 2 of the License, or (at your option) any later 00013 * version. 00014 * For further information see file COPYING 00015 * in the top level directory 00016 *************************************************************************** 00017 * part of: framework implementation developed by tkn 00018 ***************************************************************************/ 00019 00020 00021 #include "BasicDecider.h" 00022 00023 00024 #define coreEV (ev.isDisabled()||!coreDebug) ? ev : ev << logName() << "::BasicDecider: " 00025 00026 Define_Module(BasicDecider); 00027 00036 void BasicDecider::initialize(int stage) 00037 { 00038 BasicModule::initialize(stage); 00039 00040 if (stage == 0) 00041 { 00042 uppergateOut = findGate("uppergateOut"); 00043 lowergateIn = findGate("lowergateIn"); 00044 numRcvd = 0; 00045 numSentUp = 0; 00046 WATCH(numRcvd); 00047 WATCH(numSentUp); 00048 } 00049 } 00050 00066 void BasicDecider::handleMessage(cMessage *msg) 00067 { 00068 if (msg->getArrivalGateId() == lowergateIn) 00069 { 00070 numRcvd++; 00071 00072 //remove the control info from the AirFrame 00073 SnrControlInfo *cInfo = static_cast<SnrControlInfo *>(msg->removeControlInfo()); 00074 00075 // read in the snrList from the control info 00076 handleLowerMsg(check_and_cast<AirFrame *>(msg), cInfo->getSnrList()); 00077 00078 // delete the control info 00079 delete cInfo; 00080 00081 } 00082 else if (msg->isSelfMessage()) 00083 { 00084 handleSelfMsg(msg); 00085 } 00086 } 00087 00093 void BasicDecider::sendUp(AirFrame * frame) 00094 { 00095 numSentUp++; 00096 cPacket *macMsg = frame->decapsulate(); 00097 send(macMsg, uppergateOut); 00098 coreEV << "sending up msg " << frame->getName() << endl; 00099 delete frame; 00100 } 00101 00113 void BasicDecider::handleLowerMsg(AirFrame * frame, SnrList& snrList) 00114 { 00115 00116 bool correct = true; 00117 //check the entries in the snrList if a level greater than the 00118 //acceptable minimum occured: 00119 double min = 0.0000000000000001; // just a senseless example 00120 00121 for (SnrList::iterator iter = snrList.begin(); iter != snrList.end(); iter++) 00122 { 00123 coreEV << "snr=" << iter->snr << "...\n"; 00124 if (iter->snr < min) 00125 correct = false; 00126 } 00127 00128 if (correct) 00129 { 00130 coreEV << "frame " << frame->getName() << " correct\n"; 00131 sendUp(frame); 00132 } 00133 else 00134 { 00135 coreEV << "frame " << frame->getName() << " corrupted -> delete\n"; 00136 delete frame; 00137 } 00138 }