使用OMNET++仿真DV—Hop定位算法核心部分的参考源代码.docVIP

  • 22
  • 0
  • 约 6页
  • 2016-11-02 发布于天津
  • 举报

使用OMNET++仿真DV—Hop定位算法核心部分的参考源代码.doc

使用OMNET仿真DV—Hop定位算法核心部分的参考源代码

使用OMNET++仿真DV—Hop定位算法核心部分的参考源代码如下: #include application.h Define_Module( application ); void application::initialize() { last_seen_id = -1; msgcount = 0; TTL=0; } void application::finish() { int i; double tmp; evNode ID position, px=PX; py=PY\n; for(i=0;iNUM_ANC;i++) { evleast hops to anchor[i]is hopto[i]\n; evlen to anchor[i] is lento[i]\n; } if(ID=NUM_ANC) { commatrix(); tmp=sqrt((PX-rp.rx)*(PX-rp.rx)+(PY-rp.ry)*(PY-rp.ry)); evwe get the position px=rp.rx, py=rp.ry\n; evcha=tmp\n; } else evwe get the position px=PX, py=PY\n; ev\n\n; } void application::handleMessage(cMessage *msg) { switch(msg-kind()) { case M_LOWHIGH: { if (strcmp(msg-name(),FLOOD)==0) { processFlood(msg); return; } if(strcmp(msg-name(),GGHOPS)==0) { processHops(msg); return; } ev unknown message received from another node.\n; endSimulation(); } case M_START: { cMessage *msgnew = new cMessage(FLOOD); msgnew-setKind(M_HIGHLOW); msgnew-addPar(flood_id) = ++last_seen_id; msgnew-addPar(source)=ID; //set source for the message msgnew-addPar(hops)=0; msgnew-addPar(spx)=PX; msgnew-addPar(spy)=PY; send(msgnew,lowergate_out); UPDATECOLOR(msgcount+2); msgcount++; break; } case M_S2: { if(strcmp(msg-name(),GGHOPS)==0) { double hopsize=comhopsize(); TTL=INTTL; cMessage *hopsmsg=new cMessage(GGHOPS); hopsmsg-setKind(M_HIGHLOW); hopsmsg-addPar(source)=ID; hopsmsg-addPar(hopsize)=hopsize; hopsmsg-addPar(ttl)=INTTL; sendDelayed(hopsmsg,RETRANSMITDELAY,lowergate_out); seens[ID]=true; UPDATECOLOR(ID+2); break; } } default: ev unknown message received\n; endSimulation(); } } void application::processFlood(cMessage *msg) { int flood_id = (int)msg-par(flood_id); if (flood_id = last_seen_id) { delete msg; return; } int source =msg-par(so

文档评论(0)

1亿VIP精品文档

相关文档