📄 manager.cc
字号:
#include"manager.h"
#include<string>
#include<fstream>
void manager::initialize()
{
int i,j;
if((int)this->parentModule()->par("NNODES")!=NNODES)
{
ev<<"manager::initialize() error:parameter NNODES is different in.ini and in.h files\n";
endSimulation();
}
if((int)this->parentModule()->par("MAXCONN")!=MAXCONN)
{
ev<<"manager::initialize()error:parameter MAXCONN is different in.ini and i.h files\n";
endSimulation();
}
//初始化所有节点
for(i=0;i<NNODES;i++)
{
for(j=0;j<NNODES;j++)
{
cm[i][j]=false;
}
}
// hide the manager from the display 隐藏显示
setDisplayString("p=-100,-100,exact");
int dist=distance((int)this->parentModule()->par("SSTRENGTH"));
//形成随机位置
nodepos_t pos[NNODES];
for(i=0;i<NNODES;i++)
{
pos[i].x=intrand(SPACEX);
pos[i].y=intrand(SPACEY);
//在屏幕上显示节点
char tempstring[30];
sprintf(tempstring,"p=%d,%d,exact;i=snode_%d-%d",pos[i].x+MX,pos[i].y+my,1,2);
this->parentModule()->submodule("snode",i)->setDisplayString(tempstring);
//连接这个模型 在传送范围之类
for(j=0;j<i;j++)
{ //若两个节点之间可先相互监听 连接他们
if(dist *dist>=((pos[i].x-pos[j].x)*(pos[i].x-pos[j].x)+(pos[i].y-pos[j].y)*(pos[i].y-pos[j].y)))
{
cModule *modl,*mod2;
modl=this->parentModule()->submodule("snode",i);
mod2=this->parentModule()->submodule("snode",j);
cGate *gate1=NULL;
cGate *gate2=NULL;
int cnt1,cnt2;
// find the first empty gate on source 从源来找到第一个空的们
for(cnt1=0;cnt1<MAXCONN;cnt1++)
{
gate1=mod1->gate("in",cnt1);
if(!gate1->isConnected())
break;
}
if(cnt1==MAXCONN)
{
ev<<"error :maximum connettivtiy reached(1)\n";
endSimulation();
}
//find the first enpty gate on destination
for(cnt2=0;cnt2<MAXCONN;cnt2++)
{
gate2=mod2->gate("out",cnt2);
if(!gate2->isConnected())
break;
}
if(cnt2==MAXCONN)
{
ev<<"error maximum connecttivity reached 2 \n";
endSimulation
}
//connect the gates 连接门
gate1->setFrom(gate2);
gate2->setTo(gate1);
gate1->setDisplaySting("m=m,50,50,50,50;o=#AAA,1;",false);
gate2->setDisplaySting("m=m,50,50,50,50;o=#AAA,1;",false);
//connect the reverse link连接返回线路
gate1=mod1->gate("out",cnt1);
gate2=mod2->gate("in",cnt2);
gate1->setTo(gate2);
gate2->setFrom(gate1);
gate1->setDisplaySting("m=m,50,50,50,50;o=#AAA,1;",false);
gate2->setDisplaySting("m=m,50,50,50,50;o=#AAA,1;",false);
//更新数据结构
cm[i][j]=ture;
cm[j][i]=ture;
}
}
//update each module data structure
for(i=0;i<NNODES;i++)
{
cModule *mod=this->parentModule()->submodule("snode",i);
mod->par("PX")=pos[i].x;
mod->par("PY")=pos[i].y;
}
}
void manager::activity()
{
//main loop 主循环
while(1)
{
cMessage *msg;
msg=receive();
switch(msg->kind())
{
case M_UPDSSTRENGTH://signal strength update by a node
updateSignalStrength(msg);
delete msg;
break;
default:
ev<<"manager::handleMessage()error:unknown message received by manager\n";
endSimulation();
}
}
}
void manager::updateSignalStrength(cMessage *msg)
{
}
int manager::distance(int sstrength)
{
/** right now by signal strength i understand the range a node can communicate any other
interpretations of the signal strength and conversions to distance can be performed here
*/
int res;
res=sstrength;
return res;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -