📄 phylayersimple.cc
字号:
#include "PhyLayerSimple.h"#include "CoOrdinatorSimple.h"#include "MAC_802_11_Packet_m.h"#include "Phy_Packet_m.h"Define_Module_Like ( PhyLayerSimple , PhyLayerModule );PhyLayerSimple::PhyLayerSimple(const char *name, cModule *parentModule, unsigned stacksize) : PhyLayerBase(name, parentModule, stacksize){// printf("\n\t In constructor for PhyLayerSimple");}void PhyLayerSimple::initialize(){ //printf("\n\t In PhyLayerSimple::initialize()"); //ev << "\n\t In PhyLayerSimple::initialize()"; //printf("\n\t PhyLayerModule: Name of current module: %s", fullName()); cModule *pNode = parentModule(); pCoOrdinator = pNode->submodule("CoOrdinator"); return;}void PhyLayerSimple::handleMessage(cMessage *msg){ CoOrdinatorBase* cord=(CoOrdinatorBase*)pCoOrdinator; int arrivalGate = msg->arrivalGateId(); const int fromMACLayerGate = gate("fromTopLayer")->id(); const int fromWirelessChanGate = gate("fromBottomLayer")->id(); if (arrivalGate == fromMACLayerGate) { //printf( "PHYSICAL LAYER, MSG FROM MAC\n"); cPhy_Packet *pPHYMsg; cModule *pNode = parentModule(); int iNodeId = pNode->par("NodeId"); iNodeId =((CoOrdinatorBase*)pCoOrdinator)->getNodeId(); cModule *RadioMod=pNode->submodule("Radio"); cModule *pNetwork =pNode->parentModule(); cModule* wChan=pNetwork->submodule("WirelessChannel"); cGate* gateId=wChan->gate("fromSensorNode"); int iMsgKind = msg->kind(); int x =((CoOrdinatorBase*)pCoOrdinator)->getX(); int y =((CoOrdinatorBase*)pCoOrdinator)->getY(); char strLogMsg[MAX_NAME_LEN]; Create_Phy_Packet( msg , &pPHYMsg); if(!pPHYMsg->hasPar("xPos")) pPHYMsg->addPar("xPos"); pPHYMsg->par("xPos") = x;//pNode->par("xPos"); if(!pPHYMsg->hasPar("yPos")) pPHYMsg->addPar("yPos"); //pNode->par("yPos"); pPHYMsg->par("yPos")=y; if (-1 == pPHYMsg->findPar("RadioPower")) pPHYMsg->addPar("RadioPower") = RadioMod->par("RadioRadius"); else pPHYMsg->par("RadioPower") = RadioMod->par("RadioRadius"); // s802_11_MAC_Header* hdr=&((c802_11_Packet*)msg)->getHdr(); //int NodeId=hdr->SourceMACAddress; /* ADD PHYSICAL LAYER HEADER AND ADD THE SOURCE NODE ID FROM MAC PACKET sPhy_Header PHYHeader; PHYHeader.SourceNodeAddress = hdr->SourceMACAddress; PHYHeader.DestinationNodeAddress = hdr->DestinationMACAddress;*/ //int iMsgKind = msg->kind(); //Create_Phy_Packet( msg , &pPHYMsg); cGate *pToBottomGate = gate("toBottomLayer"); if (true == pToBottomGate->isConnected()) { //printf("%f message when sending to wchan %s \n",simTime(),pPHYMsg); cMessage* msg1=(cMessage*)pPHYMsg->dup(); int igate=iNodeId+2; sendDirect(msg1,0,wChan,"fromSensorNode"); delete pPHYMsg; } //else printf("error in gate .........................\n"); // cMessage* msg1=new cMessage(); // scheduleAt(simTime()+TRANSMIT_DELAY,msg1); } else if(arrivalGate == fromWirelessChanGate) { cModule *pNode = parentModule(); int iNodeId = pNode->par("NodeId"); // iNodeId=pNode->index();// printf("\n \t PhyLayerSimple::handleMessage Data................................\n"); iNodeId=((CoOrdinatorSimple *)pCoOrdinator)->getNodeId(); cGate *pTopGate = gate("toTopLayer"); cMessage *pMacMsg = (cMessage*)msg->getObject("Mac_Pkt"); cMessage *pDupMacMsg = (cMessage*) pMacMsg->dup(); int msgKind = pMacMsg->kind(); pDupMacMsg->setKind(msgKind); if (true == pTopGate->isConnected()) send(pDupMacMsg, "toTopLayer"); // cMessage* msg1=new cMessage(); // scheduleAt(simTime()+RECEIVE_DELAY,msg1); } //else //printf("\n\t PhyLayerSimple::handleMessage, Message Received but NOT of type TARGET");}bool PhyLayerSimple :: Create_Phy_Packet( cMessage *msg , cPhy_Packet **ppPHYMsg){*ppPHYMsg = new cPhy_Packet("PHY_MSG", PHY);//printf(" In create_PHY_Packet \n");s802_11_MAC_Header* hdr=&((c802_11_Packet*)msg)->getHdr();sPhy_Header PHYHeader;PHYHeader.SourceNodeAddress = hdr->SourceMACAddress;PHYHeader.DestinationNodeAddress = hdr->DestinationMACAddress; msg->setName("Mac_Pkt"); // Adding the mac pkst as an object to phy layer data frame(*ppPHYMsg)->takeOwnership(false);(*ppPHYMsg)->addObject(msg);(*ppPHYMsg)->setHdr(PHYHeader);//printf("In the end of create_PHY \n");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -