netlayer.cc

来自「基于Oment++的无线传感器网络仿真」· CC 代码 · 共 79 行

CC
79
字号
#include "Gear_packet_m.h"#include "NetLayer.h"Define_Module_Like ( NetLayer , NetLayerModule );NetLayer::NetLayer(const char *name, cModule *parentModule, unsigned stacksize) :	NetLayerBase(name, parentModule, stacksize){//	printf("\n\t In constructor for NetLayerSimple");}void NetLayer::initialize(){//	printf("\n\t In NetLayerSimple::initialize()");//	ev << "\n\t In NetLayerSimple::initialize()";//	printf("\n\t NetLayerModule: Name of current module: %s", fullName());	cModule *pNode = parentModule();	pCoOrdinator = pNode->submodule("CoOrdinator");	return;}void NetLayer::handleMessage(cMessage *msg){//	printf("\n\t In NetLayerSimple::handleMessage");//	ev <<  "\n\t In NetLayerSimple::handleMessage";		 int arrivalGate = msg->arrivalGateId();        const int fromAppLayerGate = gate("fromTopLayer")->id();        const int fromMACLayerGate = gate("fromBottomLayer")->id();	        if (arrivalGate == fromAppLayerGate)        {                cModule *pNode = parentModule();                int iNodeId = pNode->par("NodeId");               // printf("\n\t NetLayerSimple::handleMessage for Node: %d, Message Received from TopNetLayer", iNodeId);					send(msg, "toBottomLayer");	}	else if (arrivalGate == fromMACLayerGate)        {                cModule *pNode = parentModule();                int iNodeId = pNode->par("NodeId");               // printf("\n\t NetLayerSimple::handleMessage for Node: %d, Message Received of type DATA from BottomNetLayer", iNodeId);                cGate *pTopGate = gate("toTopLayer");                if (true == pTopGate->isConnected())                        send(msg, "toTopLayer");		        }/*	if (TARGET == msg->kind())	{		cModule *pNode = parentModule();		int iNodeId = pNode->par("NodeId");		printf("\n\t NetLayerSimple::handleMessage for Node: %d, Message Received from TopNetLayer", iNodeId);		msg->par("xPos") = pNode->par("xPos");		msg->par("yPos") = pNode->par("yPos");		if (-1 == msg->findPar("RadioPower"))			msg->addPar("RadioPower") = 5;		send(msg, "toBottomLayer");	}	else if(DATA == msg->kind())	{		cModule *pNode = parentModule();		int iNodeId = pNode->par("NodeId");//		printf("\n\t NetLayerSimple::handleMessage for Node: %d, Message Received of type DATA from BottomNetLayer", iNodeId);		cGate *pTopGate = gate("toTopLayer");		if (true == pTopGate->isConnected())			send(msg, "toTopLayer");	}*/	else		printf("\n\t NetLayerSimple::handleMessage, Message Received but NOT of type TARGET");}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?