maclayersimple.cc

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

CC
68
字号
#include "MACLayerSimple.h"Define_Module_Like ( MACLayerSimple , MACLayerModule );MACLayerSimple::MACLayerSimple(const char *name, cModule *parentModule, unsigned stacksize) :	MACLayerBase(name, parentModule, stacksize){	//printf("\n\t In constructor for MACLayerSimple");}void MACLayerSimple::initialize(){	//printf("\n\t In MACLayerSimple::initialize()");//	ev << "\n\t In MACLayerSimple::initialize()";	//printf("\n\t MACLayerModule: Name of current module: %s", fullName());	cModule *pNode = parentModule();	pCoOrdinator = pNode->submodule("CoOrdinator");	return;}void MACLayerSimple::handleMessage(cMessage *msg){	//printf("\n\t In MACLayerSimple::handleMessage");	ev <<  "\n\t In MACLayerSimple::handleMessage";	if (TARGET == msg->kind())	{		cModule *pNode = parentModule();		int iNodeId = pNode->par("NodeId");		//printf("\n\t MACLayerSimple::handleMessage for Node: %d, Message Received from TopMACLayer", 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 MACLayerSimple::handleMessage for Node: %d, Message Received of type DATA from BottomMACLayer", iNodeId);		cGate *pTopGate = gate("toTopLayer");		if (true == pTopGate->isConnected())			send(msg, "toTopLayer");	}*/	else		{			const int fromApplnLayerGate = gate("fromTopLayer")->id();			const int fromNetLayerGate = gate("fromBottomLayer")->id();            int arrivalGate = msg->arrivalGateId();			if(fromApplnLayerGate == arrivalGate)				send(msg, "toBottomLayer");			else if (fromNetLayerGate == arrivalGate)			{		//	    printf("MACLayerSimple::sending msg to top layer");				send(msg, "toTopLayer");			}		//	else		//		printf("\n\t Invalid sender of the message.");		}										   		//printf("\n\t MACLayerSimple::handleMessage, Message Received but NOT of type TARGET");		}

⌨️ 快捷键说明

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