📄 newphylayer.cc
字号:
#include "NewPhyLayer.h"#include "CoOrdinatorSimple.h"#include "MAC_802_11_Packet_m.h"Define_Module_Like ( NewPhyLayer, NewPhyLayerModule );NewPhyLayer::NewPhyLayer(const char *name, cModule *parentModule, unsigned stacksize) : PhyLayerBase(name, parentModule, stacksize){ //printf("\n\t In constructor for PhyLayerSimple");}void NewPhyLayer::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 NewPhyLayer::handleMessage(cMessage *msg){ // printf("\n\t In PhyLayerSimple::handleMessage %f %d ",simTime(),((CoOrdinatorBase*)pCoOrdinator)->getNodeId());// ev << "\n\t In PhyLayerSimple::handleMessage"; CoOrdinatorBase* cord=(CoOrdinatorBase*)pCoOrdinator; int arrivalGate = msg->arrivalGateId(); const int fromMACLayerGate = gate("fromTopLayer")->id(); const int fromWirelessChanGate = gate("fromBottomLayer")->id();// printf(" from top %d from wireless %d to top %d to wireless %d \n",fromMACLayerGate,fromWirelessChanGate,gate("toTopLayer")->id(),gate("toBottomLayer")->id());/* if(msg->isSelfMessage()) {// printf("RADIO changed to IDLE\n"); cord->SetRadioState(IDLE); delete msg; } else*/ if (arrivalGate == fromMACLayerGate) { 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"); // printf(" isVector %d \n",gateId->isVector()); // printf(" gateId= %d\n",gateId+iNodeId); int x =((CoOrdinatorBase*)pCoOrdinator)->getX(); int y =((CoOrdinatorBase*)pCoOrdinator)->getY(); char strLogMsg[MAX_NAME_LEN]; //sprintf(strLogMsg,"\n\t PhyLayerSimple::handleMessage with Message Kind %d for Node: %d, Message Received from TopPhyLayer from coordinator xx=%d,yy= %d\n\n............", msg->kind(),iNodeId,x,y); //recordScalar("MAC MESSAGE", strLogMsg); if(!msg->hasPar("xPos")) msg->addPar("xPos"); msg->par("xPos") = x;//pNode->par("xPos"); if(!msg->hasPar("yPos")) msg->addPar("yPos"); //pNode->par("yPos"); msg->par("yPos")=y; // printf("\n\t PhyLayerSimple::handleMessage for Node: %d, Message Received from TopPhyLayer position xpos=%d ypox=%d", iNodeId,(int)msg->par("xPos"), (int)msg->par("yPos") ); if (-1 == msg->findPar("RadioPower")) msg->addPar("RadioPower") = RadioMod->par("RadioRadius"); else msg->par("RadioPower") = RadioMod->par("RadioRadius"); s802_11_MAC_Header* hdr=&((c802_11_Packet*)msg)->getHdr(); //Header* hdr=&((GearPacket*)msg)->getHdr(); int NodeId=hdr->SourceMACAddress; int iMsgKind = msg->kind(); //printf("%f RADIO changed to TRANSMIT MYNODEID = %d SOURCEMACID =%d destination =%d MsgKIND= %d \n",simTime(),iNodeId,NodeId,hdr->DestinationMACAddress,iMsgKind); // cord->SetRadioState(TRANSMIT); cGate *pToBottomGate = gate("toBottomLayer"); // printf(" Gate id of Node %d is %d \n",iNodeId,pToBottomGate->toGate()->id()); // printf(" towireless ch gate id for node %d is %d \n", iNodeId,pNode->gate("toWirelessChannel")->isConnectedOutside() ); if (true == pToBottomGate->isConnected()) { //printf("%f message check Null %s \n",simTime(),msg); cMessage* msg1=(cMessage*)msg->dup(); int igate=iNodeId+2; //if (NULL !=pToBottomGate->destinationGate()) //{ //if(pToBottomGate->destinationGate()->id()!=0) //send(msg1, "toBottomLayer"); //gate); //"toBottomLayer"); sendDirect(msg1,0,wChan,"fromSensorNode");// "toBottomLayer"); //gate); //"toBottomLayer"); //printf("%f message sent %d \n",simTime(),iNodeId); //} delete msg; } //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();// printf("\n\t PhyLayerSimple::handleMessage for Node: %d, Message Received of type %d from BottomPhyLayer",iNodeId, msg->kind()); //char strLogMsg[MAX_NAME_LEN]; //sprintf(strLogMsg, "PhyLayerSimple::handleMessage for Node: %d, Message Received of type %d from BottomPhyLayer",msg->kind(), iNodeId ); //recordScalar("DATA MESSAGE", strLogMsg); cGate *pTopGate = gate("toTopLayer"); // printf("%.20f RADIO changed to RECEIVE for Node %d message kind = %d \n",simTime(),iNodeId,msg->kind());// cord->SetRadioState(RECEIVE); if (true == pTopGate->isConnected()) send(msg, "toTopLayer"); // cMessage* msg1=new cMessage(); // scheduleAt(simTime()+RECEIVE_DELAY,msg1); } //else //printf("\n\t PhyLayerSimple::handleMessage, Message Received but NOT of type TARGET");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -